From 88e47403d88897f40e2361dbdce861dcc055bf38 Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Wed, 31 Jul 2024 16:17:49 +0200 Subject: [PATCH] Replace datalist with fluentui menu --- .../Tabs/DocumentsTabV2/DocumentsTabV2.tsx | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx index 10909f1a8..841dded17 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx @@ -1,5 +1,17 @@ import { Item, ItemDefinition, PartitionKey, PartitionKeyDefinition, QueryIterator, Resource } from "@azure/cosmos"; -import { Button, FluentProvider, Input, TableRowId } from "@fluentui/react-components"; +import { + Button, + FluentProvider, + Input, + Menu, + MenuItem, + MenuList, + MenuPopover, + MenuProps, + PositioningImperativeRef, + TableRowId, + useRestoreFocusTarget, +} from "@fluentui/react-components"; import { ArrowClockwise16Filled, Dismiss16Filled } from "@fluentui/react-icons"; import Split from "@uiw/react-split"; import { KeyCodes, QueryCopilotSampleContainerId, QueryCopilotSampleDatabaseId } from "Common/Constants"; @@ -1338,6 +1350,26 @@ export const DocumentsTabComponent: React.FunctionComponent resizeObserver.disconnect(); // clean up }, []); + const [filterMenuOpen, setFilterMenuOpen] = React.useState(false); + const onFilterMenuOpenChange: MenuProps["onOpenChange"] = (e, data) => { + // do not close menu as an outside click if clicking on the custom trigger/target + // this prevents it from closing & immediately re-opening when clicking custom triggers + if (data.type === "clickOutside" && (e.target === filterInput.current || e.target === inputRef.current)) { + return; + } + setFilterMenuOpen(data.open); + }; + const inputRef = React.useRef(null); + const positioningRef = React.useRef(null); + + React.useEffect(() => { + if (filterInput.current) { + positioningRef.current?.setTarget(filterInput.current); + } + }, [filterInput, positioningRef]); + + const restoreFocusTargetAttribute = useRestoreFocusTarget(); + const columnHeaders = { idHeader: isPreferredApiMongoDB ? "_id" : "id", partitionKeyHeaders: (showPartitionKey(_collection, isPreferredApiMongoDB) && partitionKeyPropertyHeaders) || [], @@ -1756,6 +1788,8 @@ export const DocumentsTabComponent: React.FunctionComponent setFilterContent(e.target.value)} + onChange={(e) => { + setFilterContent(e.target.value); + setFilterMenuOpen(true); + }} onBlur={() => setIsFilterFocused(false)} /> - - + + + + {addStringsNoDuplicate( + lastFilterContents, + isPreferredApiMongoDB ? defaultMongoFilters : defaultSqlFilters, + ).map((filter) => ( + {filter} + ))} + + + + {/* {addStringsNoDuplicate( lastFilterContents, isPreferredApiMongoDB ? defaultMongoFilters : defaultSqlFilters, ).map((filter) => ( + */}