From a4fcf17d9c6f4122655ae755aad5bd018e44097f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez?= Date: Thu, 18 Jan 2024 12:55:40 +0100 Subject: [PATCH] features: allows filtering by tag in inventory panel --- .../project/sidebar/header/title/index.tsx | 11 ++- .../components/inventory-table/index.tsx | 2 + .../inventory-table/row-item/index.tsx | 12 +++- .../inventory-table/row-item/types.ts | 1 + .../components/inventory-table/types.ts | 1 + .../inventory-panel/features/index.tsx | 68 +++++++++++++++++-- .../sidebar/project/inventory-panel/index.tsx | 2 +- .../grid-setup/features/target-spf/index.tsx | 9 ++- .../targets-spf-table/row-item/index.tsx | 2 +- 9 files changed, 90 insertions(+), 18 deletions(-) diff --git a/app/layout/project/sidebar/header/title/index.tsx b/app/layout/project/sidebar/header/title/index.tsx index be3c4d88a0..45f07b409a 100644 --- a/app/layout/project/sidebar/header/title/index.tsx +++ b/app/layout/project/sidebar/header/title/index.tsx @@ -190,8 +190,13 @@ const EditableTitle = ({ name="description"> {({ input }) => (
-
-
+
+ <>

{input.value}

@@ -218,7 +223,7 @@ const EditableTitle = ({ } }} /> -
+

{input.value}

diff --git a/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/index.tsx b/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/index.tsx index 8bec94292d..56e506228b 100644 --- a/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/index.tsx @@ -18,6 +18,7 @@ const InventoryTable = ({ onToggleSeeOnMap, onSelectRow, onSelectAll, + onSelectTag, ActionsComponent, }: InventoryTable): JSX.Element => { const noData = !loading && data?.length === 0; @@ -77,6 +78,7 @@ const InventoryTable = ({ selectedIds={selectedIds} onSelectRow={onSelectRow} onToggleSeeOnMap={onToggleSeeOnMap} + onSelectTag={onSelectTag} ActionsComponent={ActionsComponent} /> ))} diff --git a/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/row-item/index.tsx b/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/row-item/index.tsx index 4a6b6b67a9..dcdc4a33ab 100644 --- a/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/row-item/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/row-item/index.tsx @@ -17,6 +17,7 @@ const RowItem = ({ selectedIds, onSelectRow, onToggleSeeOnMap, + onSelectTag, ActionsComponent, }: RowItem) => { const { id, name, scenarios, tag, isVisibleOnMap, isCustom } = item; @@ -60,9 +61,16 @@ const RowItem = ({ {tag && (
- +
)} diff --git a/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/row-item/types.ts b/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/row-item/types.ts index e077c5c856..a0265b06c8 100644 --- a/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/row-item/types.ts +++ b/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/row-item/types.ts @@ -7,6 +7,7 @@ export type RowItem = { selectedIds: string[]; onSelectRow: (evt: ChangeEvent) => void; onToggleSeeOnMap: (id: string) => void; + onSelectTag?: (tag: DataItem['tag']) => void; ActionsComponent: ({ item, onDismissMenu, diff --git a/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/types.ts b/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/types.ts index af0dce50a0..04d197df81 100644 --- a/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/types.ts +++ b/app/layout/project/sidebar/project/inventory-panel/components/inventory-table/types.ts @@ -27,5 +27,6 @@ export type InventoryTable = { onToggleSeeOnMap: (id: string) => void; onSelectRow: (evt: ChangeEvent) => void; onSelectAll: (evt: ChangeEvent) => void; + onSelectTag?: (tag: DataItem['tag']) => void; ActionsComponent: ({ item }) => JSX.Element; }; diff --git a/app/layout/project/sidebar/project/inventory-panel/features/index.tsx b/app/layout/project/sidebar/project/inventory-panel/features/index.tsx index b73dc1f8c8..843182267a 100644 --- a/app/layout/project/sidebar/project/inventory-panel/features/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/features/index.tsx @@ -1,4 +1,4 @@ -import { useCallback, useState, ChangeEvent, useEffect } from 'react'; +import { useCallback, useState, ChangeEvent, useEffect, ComponentProps, useMemo } from 'react'; import { useRouter } from 'next/router'; @@ -9,12 +9,17 @@ import { setLayerSettings, } from 'store/slices/projects/[id]'; +import Fuse from 'fuse.js'; + import { useAllFeatures, useColorFeatures } from 'hooks/features'; +import Icon from 'components/icon'; import ActionsMenu from 'layout/project/sidebar/project/inventory-panel/features/actions-menu'; import FeaturesBulkActionMenu from 'layout/project/sidebar/project/inventory-panel/features/bulk-action-menu'; import { Feature } from 'types/api/feature'; +import CLOSE_SVG from 'svgs/ui/close.svg?sprite'; + import InventoryTable, { type DataItem } from '../components/inventory-table'; const FEATURES_TABLE_COLUMNS = [ @@ -31,6 +36,7 @@ const FEATURES_TABLE_COLUMNS = [ const InventoryPanelFeatures = ({ noData: noDataMessage }: { noData: string }): JSX.Element => { const dispatch = useAppDispatch(); + const [selectedTag, setSelectedTag] = useState(null); const { selectedFeatures: visibleFeatures, @@ -166,12 +172,39 @@ const InventoryPanelFeatures = ({ noData: noDataMessage }: { noData: string }): [dispatch, visibleFeatures, allFeaturesQuery.data, selectedContinuousFeatures] ); + const handleSelectTag = useCallback( + (tag: Parameters['onSelectTag']>[0]) => { + setSelectedTag(tag); + setSelectedFeaturesIds([]); + }, + [] + ); + + const clearTag = useCallback(() => { + setSelectedTag(null); + }, []); + const displayBulkActions = selectedFeaturesIds.length > 0; - const data: DataItem[] = allFeaturesQuery.data?.map((feature) => ({ - ...feature, - isVisibleOnMap: layerSettings[feature.id]?.visibility ?? false, - })); + const data: DataItem[] = useMemo(() => { + let d = allFeaturesQuery.data?.map((feature) => ({ + ...feature, + isVisibleOnMap: layerSettings[feature.id]?.visibility ?? false, + })); + + if (selectedTag) { + const fuse = new Fuse(d, { + keys: ['tag'], + threshold: 0.25, + }); + + d = fuse.search(selectedTag).map((f) => { + return f.item; + }); + } + + return d; + }, [allFeaturesQuery.data, layerSettings, selectedTag]); useEffect(() => { if (allFeaturesQuery.isRefetching) { @@ -180,7 +213,29 @@ const InventoryPanelFeatures = ({ noData: noDataMessage }: { noData: string }): }, [allFeaturesQuery.isRefetching]); return ( -
+
+ {selectedTag && ( + + Filtering by: + + + + )}
diff --git a/app/layout/project/sidebar/project/inventory-panel/index.tsx b/app/layout/project/sidebar/project/inventory-panel/index.tsx index 08221580a4..96d3421f67 100644 --- a/app/layout/project/sidebar/project/inventory-panel/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/index.tsx @@ -62,7 +62,7 @@ const InventoryPanel = (): JSX.Element => { } = panel; return ( -
+
Inventory Panel diff --git a/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/index.tsx b/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/index.tsx index 784e482433..ee59efb353 100644 --- a/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/index.tsx +++ b/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/index.tsx @@ -85,7 +85,6 @@ const TargetAndSPFFeatures = (): JSX.Element => { const targetedFeatures = useMemo(() => { let parsedData = []; - console.log({ featureValues }); selectedFeaturesQuery.data?.forEach((feature) => { if (feature.splitFeaturesSelected?.length > 0) { const featureMetadata = allFeaturesQuery.data?.find(({ id }) => id === feature.id); @@ -457,11 +456,11 @@ const TargetAndSPFFeatures = (): JSX.Element => { /> {filters.type && (
- + Filtering by:
diff --git a/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/targets-spf-table/row-item/index.tsx b/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/targets-spf-table/row-item/index.tsx index 5a4f3a477c..6b58eb3206 100644 --- a/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/targets-spf-table/row-item/index.tsx +++ b/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/targets-spf-table/row-item/index.tsx @@ -95,7 +95,7 @@ const RowItem = ({