diff --git a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/actions-menu/index.tsx b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/actions-menu/index.tsx new file mode 100644 index 0000000000..a1180eecec --- /dev/null +++ b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/actions-menu/index.tsx @@ -0,0 +1,97 @@ +import { useCallback, useState } from 'react'; + +import Icon from 'components/icon'; +import Modal from 'components/modal/component'; +import DeleteModal from 'layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/delete'; +import EditModal from 'layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/edit'; +import { cn } from 'utils/cn'; + +import DELETE_SVG from 'svgs/ui/new-layout/delete.svg?sprite'; +import TAG_SVG from 'svgs/ui/tag.svg?sprite'; + +const BUTTON_CLASSES = + 'flex items-center px-4 py-2 w-full text-sm cursor-pointer bg-gray-700 hover:bg-gray-500 transition transition-colors space-x-2 group'; + +const ICON_CLASSES = 'h-5 w-5 text-gray-400 group-hover:text-white'; + +const ActionsMenu = ({ + item, +}: { + item: { + id: string; + name: string; + scenarios: number; + tag: string; + custom: boolean; + }; +}): JSX.Element => { + const isDeletable = !item.custom && !item.scenarios; + + // item.isCustom && !item.scenarioUsageCount + const [modalState, setModalState] = useState<{ edit: boolean; delete: boolean }>({ + edit: false, + delete: false, + }); + + const handleModal = useCallback((modalKey: keyof typeof modalState, isVisible: boolean) => { + setModalState((prevState) => ({ ...prevState, [modalKey]: isVisible })); + }, []); + + return ( + + ); +}; + +export default ActionsMenu; diff --git a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/index.tsx b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/index.tsx index ccd27241ba..616cdb7ad5 100644 --- a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/index.tsx @@ -7,8 +7,8 @@ import { setSelectedCostSurfaces as setVisibleCostSurfaces } from 'store/slices/ import { useProjectCostSurfaces } from 'hooks/cost-surface'; +import ActionsMenu from 'layout/project/sidebar/project/inventory-panel/cost-surfaces/actions-menu'; import CostSurfacesBulkActionMenu from 'layout/project/sidebar/project/inventory-panel/cost-surfaces/bulk-action-menu'; -import ActionsMenu from 'layout/project/sidebar/project/inventory-panel/features/actions-menu'; import { CostSurface } from 'types/api/cost-surface'; import InventoryTable, { type DataItem } from '../components/inventory-table'; diff --git a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/delete/index.tsx b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/delete/index.tsx index 095c5bc7c4..0fad5ab67a 100644 --- a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/delete/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/delete/index.tsx @@ -39,15 +39,15 @@ const DeleteModal = ({ }, [allProjectCostSurfacesQuery.data, selectedCostSurfacesIds]); const costSurfaceNames = selectedCostSurfaces.map(({ name }) => name); - // ? the user will be able to delete the features only if they are not being used by any scenario. + // ? the user will be able to delete the cost surfaces only if they are not being used by any scenario. const haveScenarioAssociated = selectedCostSurfaces.some(({ scenarioUsageCount }) => Boolean(scenarioUsageCount) ); const handleBulkDelete = useCallback(() => { - const deletableFeatureIds = selectedCostSurfaces.map(({ id }) => id); + const deletableCostSurfaceIds = selectedCostSurfaces.map(({ id }) => id); - bulkDeleteCostSurfaceFromProject(pid, deletableFeatureIds, session) + bulkDeleteCostSurfaceFromProject(pid, deletableCostSurfaceIds, session) .then(async () => { await queryClient.invalidateQueries(['cost-surfaces', pid]); @@ -57,7 +57,7 @@ const DeleteModal = ({ 'delete-bulk-project-cost-surfaces', <>

Success

-

The features were deleted successfully.

+

The cost surfaces were deleted successfully.

, { level: 'success', diff --git a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/edit/index.tsx b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/edit/index.tsx index 2596baaf40..4ae20ca706 100644 --- a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/edit/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/modals/edit/index.tsx @@ -45,29 +45,12 @@ const EditModal = ({ const { pid } = query as { pid: string }; const formRef = useRef['form']>(null); - const tagsSectionRef = useRef>(null); - const [tagsMenuOpen, setTagsMenuOpen] = useState(false); - const [tagIsDone, setTagIsDone] = useState(false); - - const tagsQuery = useProjectTags(pid); const featureQuery = useProjectFeatures(pid, featureId); const editFeatureTagMutation = useEditFeatureTag(); const deleteFeatureTagMutation = useDeleteFeatureTag(); const editFeatureMutation = useEditFeature(); - useEffect(() => { - const handleClickOutside = (event) => { - if (tagsSectionRef.current && !tagsSectionRef.current.contains(event.target)) { - setTagsMenuOpen(false); - } - }; - document.addEventListener('click', handleClickOutside, true); - return () => { - document.removeEventListener('click', handleClickOutside, true); - }; - }, []); - const onEditSubmit = useCallback( (values: FormValues) => { const { featureClassName, tag } = values; @@ -136,32 +119,20 @@ const EditModal = ({ ] ); - const handleKeyPress = useCallback( - (event: Parameters['onKeyDown']>[0]) => { - if (event.key === 'Enter') { - setTagIsDone(true); - formRef.current.change('tag', event.currentTarget.value); - setTagsMenuOpen(false); - } - }, - [formRef] - ); - return ( initialValues={{ featureClassName: featureQuery.data?.[0]?.featureClassName, - tag: featureQuery.data?.[0]?.tag, }} ref={formRef} onSubmit={onEditSubmit} - render={({ form, handleSubmit, values }) => { + render={({ form, handleSubmit }) => { formRef.current = form; return (
-

Edit feature

+

Edit cost surface

@@ -185,77 +156,6 @@ const EditModal = ({
-
- name="tag"> - {(fprops) => ( - - - {(!values.tag || !tagIsDone) && ( -
- { - setTagsMenuOpen(true); - form.change('tag', ''); - }} - onBlur={() => setTagIsDone(true)} - onKeyDown={handleKeyPress} - /> - - {tagsMenuOpen && ( -
-
Recent:
-
- {tagsQuery.data?.map((tag) => ( - - ))} -
-
- )} -
- )} - - {values.tag && tagIsDone && ( -
-
-

{values.tag}

-
- -
- )} -
- )} - -
-