From 076768215e8f0042883d1c521e2a1afa36d94b86 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Tue, 21 Mar 2023 10:45:02 +0200 Subject: [PATCH] feat: delete features FE (#3350) --- .../ArchiveTable/ArchiveBatchActions.tsx | 33 +++++++++++++++- .../archive/ArchiveTable/ArchiveTable.tsx | 3 +- .../ArchivedFeatureDeleteConfirm.tsx | 38 +++++++++++-------- .../actions/useProjectApi/useProjectApi.ts | 11 ++++++ 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/frontend/src/component/archive/ArchiveTable/ArchiveBatchActions.tsx b/frontend/src/component/archive/ArchiveTable/ArchiveBatchActions.tsx index 0e8420a5a8..f58ef75995 100644 --- a/frontend/src/component/archive/ArchiveTable/ArchiveBatchActions.tsx +++ b/frontend/src/component/archive/ArchiveTable/ArchiveBatchActions.tsx @@ -1,12 +1,16 @@ -import { FC } from 'react'; +import { FC, useState } from 'react'; import { Button } from '@mui/material'; import { Undo } from '@mui/icons-material'; -import { UPDATE_FEATURE } from 'component/providers/AccessProvider/permissions'; +import { + DELETE_FEATURE, + UPDATE_FEATURE, +} from 'component/providers/AccessProvider/permissions'; import { PermissionHOC } from 'component/common/PermissionHOC/PermissionHOC'; import useProjectApi from 'hooks/api/actions/useProjectApi/useProjectApi'; import { formatUnknownError } from 'utils/formatUnknownError'; import { useFeaturesArchive } from 'hooks/api/getters/useFeaturesArchive/useFeaturesArchive'; import useToast from 'hooks/useToast'; +import { ArchivedFeatureDeleteConfirm } from './ArchivedFeatureActionCell/ArchivedFeatureDeleteConfirm/ArchivedFeatureDeleteConfirm'; interface IArchiveBatchActionsProps { selectedIds: string[]; @@ -20,6 +24,7 @@ export const ArchiveBatchActions: FC = ({ const { reviveFeatures } = useProjectApi(); const { setToastData, setToastApiError } = useToast(); const { refetchArchived } = useFeaturesArchive(projectId); + const [deleteModalOpen, setDeleteModalOpen] = useState(false); const onRevive = async () => { try { @@ -34,6 +39,10 @@ export const ArchiveBatchActions: FC = ({ setToastApiError(formatUnknownError(error)); } }; + + const onDelete = async () => { + setDeleteModalOpen(true); + }; return ( <> @@ -49,6 +58,26 @@ export const ArchiveBatchActions: FC = ({ )} + + {({ hasAccess }) => ( + + )} + + ); }; diff --git a/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx b/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx index 7735e1e0a9..39a360230f 100644 --- a/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx +++ b/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx @@ -341,7 +341,8 @@ export const ArchiveTable = ({ )} /> >; refetch: () => void; @@ -23,27 +23,32 @@ const StyledFormInput = styled(Input)(({ theme }) => ({ width: '100%', })); +const confirmationText = 'I want to delete'; + export const ArchivedFeatureDeleteConfirm = ({ - deletedFeature, + deletedFeatures, + projectId, open, setOpen, refetch, }: IArchivedFeatureDeleteConfirmProps) => { const [confirmName, setConfirmName] = useState(''); const { setToastData, setToastApiError } = useToast(); - const { deleteFeature } = useFeatureArchiveApi(); + const { deleteFeatures } = useProjectApi(); const onDeleteFeatureToggle = async () => { try { - if (!deletedFeature) { + if (deletedFeatures.length === 0) { return; } - await deleteFeature(deletedFeature.name); + await deleteFeatures(projectId, deletedFeatures); await refetch(); setToastData({ type: 'success', - title: 'Feature toggle deleted', - text: `You have successfully deleted the ${deletedFeature.name} feature toggle.`, + title: 'Feature toggles deleted', + text: `You have successfully deleted following features toggles: ${deletedFeatures.join( + ', ' + )}.`, }); } catch (error: unknown) { setToastApiError(formatUnknownError(error)); @@ -61,13 +66,13 @@ export const ArchivedFeatureDeleteConfirm = ({ return ( @@ -78,8 +83,9 @@ export const ArchivedFeatureDeleteConfirm = ({ - In order to delete this feature toggle, please enter its name in - the text field below: {deletedFeature?.name} + In order to delete feature toggles, please enter the following + confirmation text in the text field below:{' '} + I want to delete
@@ -89,8 +95,8 @@ export const ArchivedFeatureDeleteConfirm = ({ setConfirmName(e.currentTarget.value); }} value={confirmName} - placeholder="" - label="Feature toggle name" + placeholder="" + label="Deletetion confirmation" />
diff --git a/frontend/src/hooks/api/actions/useProjectApi/useProjectApi.ts b/frontend/src/hooks/api/actions/useProjectApi/useProjectApi.ts index defca69ff6..12063a895c 100644 --- a/frontend/src/hooks/api/actions/useProjectApi/useProjectApi.ts +++ b/frontend/src/hooks/api/actions/useProjectApi/useProjectApi.ts @@ -223,6 +223,16 @@ const useProjectApi = () => { return makeRequest(req.caller, req.id); }; + const deleteFeatures = async (projectId: string, featureIds: string[]) => { + const path = `api/admin/projects/${projectId}/delete`; + const req = createRequest(path, { + method: 'POST', + body: JSON.stringify({ features: featureIds }), + }); + + return makeRequest(req.caller, req.id); + }; + const staleFeatures = async ( projectId: string, featureIds: string[], @@ -257,6 +267,7 @@ const useProjectApi = () => { archiveFeatures, reviveFeatures, staleFeatures, + deleteFeatures, searchProjectUser, errors, loading,