diff --git a/frontend/app/components/shared/Filters/FilterAutoComplete/AutocompleteModal.tsx b/frontend/app/components/shared/Filters/FilterAutoComplete/AutocompleteModal.tsx index c8c106fee..22ce83d01 100644 --- a/frontend/app/components/shared/Filters/FilterAutoComplete/AutocompleteModal.tsx +++ b/frontend/app/components/shared/Filters/FilterAutoComplete/AutocompleteModal.tsx @@ -3,10 +3,15 @@ import { Button, Checkbox, Input, Tooltip } from 'antd'; import { RedoOutlined, CloseCircleFilled } from '@ant-design/icons'; import cn from 'classnames'; import { Loader } from 'UI'; -import OutsideClickDetectingDiv from '../../OutsideClickDetectingDiv'; +import OutsideClickDetectingDiv from 'Shared/OutsideClickDetectingDiv'; - -function TruncatedText({ text, maxWidth }: { text?: string; maxWidth?: string;}) { +function TruncatedText({ + text, + maxWidth, +}: { + text?: string; + maxWidth?: string; +}) { const textRef = useRef(null); const [isTruncated, setIsTruncated] = useState(false); @@ -34,7 +39,6 @@ function TruncatedText({ text, maxWidth }: { text?: string; maxWidth?: string;}) ); } - export function AutocompleteModal({ onClose, onApply, @@ -45,6 +49,7 @@ export function AutocompleteModal({ isLoading, placeholder, commaQuery, + isOpen, }: { values: string[]; onClose: () => void; @@ -55,7 +60,9 @@ export function AutocompleteModal({ placeholder?: string; isLoading?: boolean; commaQuery?: boolean; + isOpen?: boolean; }) { + const modalRef = useRef(null); const [query, setQuery] = React.useState(''); const [selectedValues, setSelectedValues] = React.useState( values.filter((i) => i && i.length > 0) @@ -118,79 +125,101 @@ export function AutocompleteModal({ return str; }, [query]); + React.useEffect(() => { + if (modalRef.current) { + const modalRect = modalRef.current.getBoundingClientRect(); + const viewportWidth = window.innerWidth; + if (modalRect.right > viewportWidth) { + modalRef.current.style.left = `unset`; + modalRef.current.style.right = `0`; + } + } + }, [isOpen]); + return ( { onClose(); }} > - handleInputChange(e.target.value)} - placeholder={placeholder} - className="rounded-lg" - autoFocus - allowClear - /> - - <> -
- {sortedOptions.map((item) => ( -
onSelectOption(item)} - className={ - 'cursor-pointer w-full py-1 hover:bg-active-blue rounded px-2' - } - > - {item.label} -
- ))} -
- {query.length ? ( -
-
- Apply {queryStr} -
+
+ handleInputChange(e.target.value)} + placeholder={placeholder} + className="rounded-lg" + autoFocus + allowClear + /> + + <> +
+ {sortedOptions.map((item) => ( +
onSelectOption(item)} + className={ + 'cursor-pointer w-full py-1 hover:bg-active-blue rounded px-2' + } + > + {item.label} +
+ ))}
- ) : null} - -
-
-
- + {query.length ? ( +
+
+ Apply {queryStr} +
+
+ ) : null} + + +
+
+ +
+ + + +
- - - - -
); } - interface Props { value: string[]; params?: any; @@ -201,7 +230,6 @@ interface Props { mapValues?: (value: string) => string; } - export function AutoCompleteContainer(props: Props) { const filterValueContainer = useRef(null); const [showValueModal, setShowValueModal] = useState(false); @@ -213,20 +241,19 @@ export function AutoCompleteContainer(props: Props) { props.onApplyValues(values); setShowValueModal(false); }, 100); - console.log("closed on apply"); }; - const onClearClick = (event: React.MouseEvent) => { - event.stopPropagation(); - props.onApplyValues([]); + event.stopPropagation(); + props.onApplyValues([]); setShowValueModal(false); - console.log("closed clear click"); }; const handleContainerClick = (event: React.MouseEvent) => { - if (event.target === event.currentTarget || - event.currentTarget.contains(event.target as Node)) { + if ( + event.target === event.currentTarget || + event.currentTarget.contains(event.target as Node) + ) { setShowValueModal(true); } }; @@ -249,14 +276,22 @@ export function AutoCompleteContainer(props: Props) { {!isEmpty ? ( <> {props.value.length > 1 && ( <> or {props.value.length > 2 && ( @@ -274,13 +309,13 @@ export function AutoCompleteContainer(props: Props) {
)} {!isEmpty && hovered && ( -
- -
- )} +
+ +
+ )}
{showValueModal ? ( ) : null}
); -} \ No newline at end of file +} diff --git a/frontend/app/components/shared/Filters/FilterSelection/FilterSelection.tsx b/frontend/app/components/shared/Filters/FilterSelection/FilterSelection.tsx index de6cdbaa5..3e12c4c76 100644 --- a/frontend/app/components/shared/Filters/FilterSelection/FilterSelection.tsx +++ b/frontend/app/components/shared/Filters/FilterSelection/FilterSelection.tsx @@ -37,12 +37,25 @@ function FilterSelection(props: Props) { isLive, } = props; const [showModal, setShowModal] = useState(false); + const modalRef = React.useRef(null); const onAddFilter = (filter: any) => { onFilterClick(filter); setShowModal(false); } + React.useEffect(() => { + if (showModal && modalRef.current) { + const modalRect = modalRef.current.getBoundingClientRect(); + const viewportWidth = window.innerWidth; + if (modalRect.right > viewportWidth) { + modalRef.current.style.left = `unset`; + modalRef.current.style.right = `-280px`; + } + } + }, [showModal]); + + const label = filter?.category === 'Issue' ? 'Issue' : filter?.label; return (
@@ -84,7 +97,10 @@ function FilterSelection(props: Props) {
)} {showModal && ( -
+