From 9b948c687fb77657c3e332187d8f67264bd91105 Mon Sep 17 00:00:00 2001 From: anamontiaga Date: Thu, 3 Aug 2023 18:08:22 +0200 Subject: [PATCH] reove old specific component --- .../list/{item => }/actions/index.tsx | 0 .../inventory-panel/features/list/index.tsx | 2 +- .../features/list/item/index.tsx | 180 ------------------ .../inventory-panel/item-list/index.tsx | 4 +- 4 files changed, 3 insertions(+), 183 deletions(-) rename app/layout/project/sidebar/project/inventory-panel/features/list/{item => }/actions/index.tsx (100%) delete mode 100644 app/layout/project/sidebar/project/inventory-panel/features/list/item/index.tsx diff --git a/app/layout/project/sidebar/project/inventory-panel/features/list/item/actions/index.tsx b/app/layout/project/sidebar/project/inventory-panel/features/list/actions/index.tsx similarity index 100% rename from app/layout/project/sidebar/project/inventory-panel/features/list/item/actions/index.tsx rename to app/layout/project/sidebar/project/inventory-panel/features/list/actions/index.tsx diff --git a/app/layout/project/sidebar/project/inventory-panel/features/list/index.tsx b/app/layout/project/sidebar/project/inventory-panel/features/list/index.tsx index 721c4fd45a..db981c9fbf 100644 --- a/app/layout/project/sidebar/project/inventory-panel/features/list/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/features/list/index.tsx @@ -185,7 +185,7 @@ export const ProjectFeatureList = (): JSX.Element => { projectId={pid} onSelectFeature={handleSelectFeature} isSelected={selectedFeaturesIds.includes(feature.id)} - id="features" + id="feature" /> ))} diff --git a/app/layout/project/sidebar/project/inventory-panel/features/list/item/index.tsx b/app/layout/project/sidebar/project/inventory-panel/features/list/item/index.tsx deleted file mode 100644 index 2814ef947c..0000000000 --- a/app/layout/project/sidebar/project/inventory-panel/features/list/item/index.tsx +++ /dev/null @@ -1,180 +0,0 @@ -import { useCallback, useState, ChangeEvent, useRef, InputHTMLAttributes } from 'react'; - -import { useQueryClient } from 'react-query'; -import { useDispatch, useSelector } from 'react-redux'; - -import { setSelectedFeatures as setVisibleFeatures } from 'store/slices/projects/[id]'; - -import { MoreHorizontal } from 'lucide-react'; - -import { useEditFeature } from 'hooks/features'; -import { useToasts } from 'hooks/toast'; - -import Checkbox from 'components/forms/checkbox'; -import Icon from 'components/icon'; -import { Popover, PopoverContent, PopoverTrigger } from 'components/popover'; -import Tag from 'components/tag'; -import { Feature } from 'types/api/feature'; -import { Project } from 'types/api/project'; -import { cn } from 'utils/cn'; - -import HIDE_SVG from 'svgs/ui/hide.svg?sprite'; -import SHOW_SVG from 'svgs/ui/show.svg?sprite'; - -import FeatureActions from './actions'; - -const FeatureItemList = ({ - feature, - projectId, - isSelected, - onSelectFeature, -}: { - feature: Feature; - projectId: Project['id']; - isSelected: boolean; - onSelectFeature: (evt: ChangeEvent) => void; -}): JSX.Element => { - const queryClient = useQueryClient(); - const { addToast } = useToasts(); - const dispatch = useDispatch(); - const { selectedFeatures: visibleFeatures } = useSelector((state) => state['/projects/[id]']); - const [isEditable, setEditable] = useState(false); - const nameInputRef = useRef(null); - const { mutate: editFeature } = useEditFeature(); - - const handleRename = useCallback(() => { - setEditable(true); - nameInputRef.current?.focus(); - }, [nameInputRef]); - - const handleNameChanges = useCallback( - (evt: Parameters['onKeyDown']>[0]) => { - if (evt.key === 'Enter') { - setEditable(false); - nameInputRef.current?.blur(); - - editFeature( - { - fid: feature.id, - body: { - featureClassName: evt.currentTarget.value, - }, - }, - { - onSuccess: async () => { - await queryClient.invalidateQueries(['all-features', projectId]); - - addToast( - 'edit-project-features', - <> -

Success

-

The feature was updated successfully.

- , - { - level: 'success', - } - ); - }, - onError: () => { - addToast( - 'edit-project-features', - <> -

Error

-

Something went wrong editing the feature.

- , - { - level: 'error', - } - ); - }, - } - ); - } - }, - [nameInputRef, projectId, feature.id, editFeature, addToast, queryClient] - ); - - const toggleSeeOnMap = useCallback( - (featureId: Feature['id']) => { - const newSelectedFeatures = [...visibleFeatures]; - - if (!newSelectedFeatures.includes(featureId)) { - newSelectedFeatures.push(featureId); - } else { - const i = newSelectedFeatures.indexOf(featureId); - newSelectedFeatures.splice(i, 1); - } - dispatch(setVisibleFeatures(newSelectedFeatures)); - }, - [dispatch, visibleFeatures] - ); - - return ( - <> -
- -
- - {Boolean(feature.scenarioUsageCount) && ( - - Currently in use in - - {feature.scenarioUsageCount} - - scenarios. - - )} -
-
-
- {feature.tag && ( - - {feature.tag} - - )} -
-
- - - - - - - - - -
- - ); -}; - -export default FeatureItemList; diff --git a/app/layout/project/sidebar/project/inventory-panel/item-list/index.tsx b/app/layout/project/sidebar/project/inventory-panel/item-list/index.tsx index fde702fd1b..78cf2eb176 100644 --- a/app/layout/project/sidebar/project/inventory-panel/item-list/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/item-list/index.tsx @@ -14,7 +14,7 @@ import Checkbox from 'components/forms/checkbox'; import Icon from 'components/icon'; import { Popover, PopoverContent, PopoverTrigger } from 'components/popover'; import Tag from 'components/tag'; -import FeatureActions from 'layout/project/sidebar/project/inventory-panel/features/list/item/actions'; +import FeatureActions from 'layout/project/sidebar/project/inventory-panel/features/list/actions'; import { Feature } from 'types/api/feature'; import { Project } from 'types/api/project'; import { cn } from 'utils/cn'; @@ -166,7 +166,7 @@ const ItemList = ({ sideOffset={5} align="start" > - {id === 'features' && ( + {id === 'feature' && (