From 93f70c4bff1ab1832de4ce2249397d3311ee06c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez?= Date: Wed, 24 Jan 2024 17:16:51 +0100 Subject: [PATCH 1/2] allows editing target/spf of custom selection --- app/hooks/features/index.ts | 5 - app/hooks/gap-analysis/index.ts | 21 +- .../target-spf/bulk-action-menu/index.tsx | 32 ++- .../bulk-action-menu/modals/edit/index.tsx | 258 ++++++++++++++++++ .../grid-setup/features/target-spf/index.tsx | 1 + .../scenarios/edit/status/actions/done.tsx | 1 + 6 files changed, 296 insertions(+), 22 deletions(-) create mode 100644 app/layout/project/sidebar/scenario/grid-setup/features/target-spf/bulk-action-menu/modals/edit/index.tsx diff --git a/app/hooks/features/index.ts b/app/hooks/features/index.ts index 5f5527cbcc..6444404175 100644 --- a/app/hooks/features/index.ts +++ b/app/hooks/features/index.ts @@ -181,11 +181,6 @@ export function useSelectedFeatures( const { data: session } = useSession(); const { search } = filters; - const queryClient = useQueryClient(); - - // const featureColorQueryState = - // queryClient.getQueryState<{ id: Feature['id']; color: string }[]>('feature-colors'); - const featureColors = useColorFeatures(pid, sid); const fetchFeatures = () => diff --git a/app/hooks/gap-analysis/index.ts b/app/hooks/gap-analysis/index.ts index fae3adbca5..e64458adff 100644 --- a/app/hooks/gap-analysis/index.ts +++ b/app/hooks/gap-analysis/index.ts @@ -1,6 +1,5 @@ import { useQuery } from 'react-query'; -import { sortBy } from 'lodash'; import { useSession } from 'next-auth/react'; import { ItemProps as RawItemProps } from 'components/gap-analysis/item/component'; @@ -70,18 +69,9 @@ export function usePreGapAnalysis(sId: Scenario['id'], options: UseFeaturesOptio return useQuery(['pre-gap-analysis', sId, JSON.stringify(options)], fetchFeatures, { select: ({ data }) => - sortBy( - data.map((d): AllItemProps => { - const { - id, - name, - featureClassName, - met, - metArea, - coverageTarget, - coverageTargetArea, - onTarget, - } = d; + data + .map((d): AllItemProps => { + const { id, name, featureClassName, met, metArea, coverageTarget, onTarget } = d; return { id, @@ -94,9 +84,8 @@ export function usePreGapAnalysis(sId: Scenario['id'], options: UseFeaturesOptio percent: coverageTarget / 100, }, }; - }), - ['name'] - ), + }) + .sort((a, b) => a['name']?.localeCompare(b['name'])), }); } diff --git a/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/bulk-action-menu/index.tsx b/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/bulk-action-menu/index.tsx index d3741c8961..f0dd99dd02 100644 --- a/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/bulk-action-menu/index.tsx +++ b/app/layout/project/sidebar/scenario/grid-setup/features/target-spf/bulk-action-menu/index.tsx @@ -9,9 +9,11 @@ import Icon from 'components/icon'; import Modal from 'components/modal/component'; import { Feature } from 'types/api/feature'; +import EDIT_SVG from 'svgs/ui/edit.svg?sprite'; import DELETE_SVG from 'svgs/ui/new-layout/delete.svg?sprite'; import DeleteModal from './modals/delete'; +import EditModal from './modals/edit'; const BUTTON_CLASSES = 'col-span-1 flex items-center space-x-2 rounded-lg bg-gray-800 px-4 text-xs text-gray-100'; @@ -40,7 +42,7 @@ const SplitFeaturesBulkActionMenu = ({ return ( <> -
+
{selectedFeatureIds.length} @@ -48,6 +50,16 @@ const SplitFeaturesBulkActionMenu = ({ Selected + + + + +
+
+ + ); + }} + /> + ); +}; + +export default EditModal; 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 9c617ec405..921e5cfbe4 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 @@ -407,6 +407,7 @@ const TargetAndSPFFeatures = (): JSX.Element => { onSuccess: async () => { await queryClient.invalidateQueries(['selected-features', sid]); await queryClient.invalidateQueries(['targeted-features', sid]); + await queryClient.invalidateQueries(['pre-gap-analysis', sid]); }, } ); diff --git a/app/layout/scenarios/edit/status/actions/done.tsx b/app/layout/scenarios/edit/status/actions/done.tsx index 5f7a1b07e1..2b167a04a1 100644 --- a/app/layout/scenarios/edit/status/actions/done.tsx +++ b/app/layout/scenarios/edit/status/actions/done.tsx @@ -154,6 +154,7 @@ export const useScenarioActionsDone = () => { dispatch(setJob(null)); dispatch(setCache(Date.now())); dispatch(setSubTab(null)); + await queryClient.invalidateQueries(['all-features', pid]); await queryClient.invalidateQueries(['selected-features', sid]); await queryClient.invalidateQueries(['targeted-features', sid]); await queryClient.invalidateQueries(['pre-gap-analysis', sid]); From e65a975a2bc5b9cc1698f5b09611a672b528442a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez?= Date: Thu, 25 Jan 2024 13:28:18 +0100 Subject: [PATCH 2/2] disables applying target/spf values to all features --- .../grid-setup/features/target-spf/index.tsx | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 921e5cfbe4..f5b239e472 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 @@ -27,7 +27,7 @@ import { Feature } from 'types/api/feature'; import CLOSE_SVG from 'svgs/ui/close.svg?sprite'; -import AllTargetsSelector from './all-targets'; +// import AllTargetsSelector from './all-targets'; import FeaturesBulkActionMenu from './bulk-action-menu'; const TARGET_SPF_TABLE_COLUMNS = [ @@ -191,19 +191,19 @@ const TargetAndSPFFeatures = (): JSX.Element => { })); }, []); - const handleChangeAllTargets = useCallback( - (target: Parameters['onChangeAllTargets']>[0]) => { - setConfirmationTarget(target); - }, - [] - ); + // const handleChangeAllTargets = useCallback( + // (target: Parameters['onChangeAllTargets']>[0]) => { + // setConfirmationTarget(target); + // }, + // [] + // ); - const handleChangeAllSPF = useCallback( - (spf: Parameters['onChangeAllSPF']>[0]) => { - setConfirmationFPF(spf); - }, - [] - ); + // const handleChangeAllSPF = useCallback( + // (spf: Parameters['onChangeAllSPF']>[0]) => { + // setConfirmationFPF(spf); + // }, + // [] + // ); const toggleSeeOnMap = useCallback( (id: Feature['id']) => { @@ -467,10 +467,10 @@ const TargetAndSPFFeatures = (): JSX.Element => { )} {/* set target/spf all features */} - + /> */}