From bacb8f21d0fc663c46ba235563aae46385aba6f5 Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:31:40 +0200 Subject: [PATCH] fix: reset selected toggle after archive or revive --- frontend/package.json | 2 +- .../archive/ArchiveTable/ArchiveBatchActions.tsx | 3 +++ .../src/component/archive/ArchiveTable/ArchiveTable.tsx | 3 +++ .../ProjectFeatureToggles/ProjectFeatureToggles.tsx | 2 ++ .../ProjectFeaturesBatchActions/ArchiveButton.tsx | 7 +++++-- .../ProjectFeaturesBatchActions.tsx | 4 +++- frontend/yarn.lock | 8 ++++---- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 93cc482ee228..833e698df9cf 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -54,7 +54,7 @@ "@types/react-dom": "17.0.20", "@types/react-linkify": "1.0.1", "@types/react-router-dom": "5.3.3", - "@types/react-table": "7.7.14", + "@types/react-table": "7.7.15", "@types/react-test-renderer": "17.0.2", "@types/react-timeago": "4.1.3", "@types/semver": "7.5.0", diff --git a/frontend/src/component/archive/ArchiveTable/ArchiveBatchActions.tsx b/frontend/src/component/archive/ArchiveTable/ArchiveBatchActions.tsx index 1c31abf1e67e..983e5af0f6e9 100644 --- a/frontend/src/component/archive/ArchiveTable/ArchiveBatchActions.tsx +++ b/frontend/src/component/archive/ArchiveTable/ArchiveBatchActions.tsx @@ -16,11 +16,13 @@ import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; interface IArchiveBatchActionsProps { selectedIds: string[]; projectId: string; + onReviveConfirm?: () => void; } export const ArchiveBatchActions: FC = ({ selectedIds, projectId, + onReviveConfirm, }) => { const { reviveFeatures } = useProjectApi(); const { setToastData, setToastApiError } = useToast(); @@ -31,6 +33,7 @@ export const ArchiveBatchActions: FC = ({ const onRevive = async () => { try { await reviveFeatures(projectId, selectedIds); + onReviveConfirm?.(); await refetchArchived(); setToastData({ type: 'success', diff --git a/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx b/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx index 3390682dbea1..6aeb5d99ec79 100644 --- a/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx +++ b/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx @@ -243,6 +243,8 @@ export const ArchiveTable = ({ state: { sortBy, selectedRowIds }, prepareRow, setHiddenColumns, + toggleAllRowsSelected, + toggleRowSelected, } = useTable( { columns: columns as any[], // TODO: fix after `react-table` v8 update @@ -360,6 +362,7 @@ export const ArchiveTable = ({ toggleAllRowsSelected(false)} /> } diff --git a/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeatureToggles.tsx b/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeatureToggles.tsx index 0d1ce1261b24..03dabcbf0d10 100644 --- a/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeatureToggles.tsx +++ b/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeatureToggles.tsx @@ -462,6 +462,7 @@ export const ProjectFeatureToggles = ({ state: { selectedRowIds, sortBy, hiddenColumns }, prepareRow, setHiddenColumns, + toggleAllRowsSelected, } = useTable( { columns: columns as any[], // TODO: fix after `react-table` v8 update @@ -705,6 +706,7 @@ export const ProjectFeatureToggles = ({ selectedIds={Object.keys(selectedRowIds)} data={features} projectId={projectId} + onResetSelection={() => toggleAllRowsSelected(false)} /> diff --git a/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ArchiveButton.tsx b/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ArchiveButton.tsx index f057cd519b21..0497c9d9f086 100644 --- a/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ArchiveButton.tsx +++ b/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ArchiveButton.tsx @@ -12,6 +12,7 @@ interface IArchiveButtonProps { projectId: string; featureIds: string[]; features: FeatureSchema[]; + onConfirm?: () => void; } const DEFAULT_USAGE_THRESHOLD_DAYS = 7; @@ -29,6 +30,7 @@ export const ArchiveButton: VFC = ({ projectId, featureIds, features, + onConfirm, }) => { const { refetch } = useProject(projectId); const [isDialogOpen, setIsDialogOpen] = useState(false); @@ -41,8 +43,9 @@ export const ArchiveButton: VFC = ({ }); }, [JSON.stringify(features), featureIds]); - const onConfirm = async () => { + const onArchive = async () => { setIsDialogOpen(false); + onConfirm?.(); await refetch(); trackEvent('batch_operations', { props: { @@ -69,7 +72,7 @@ export const ArchiveButton: VFC = ({ projectId={projectId} featureIds={featureIds} featuresWithUsage={featuresWithUsage} - onConfirm={onConfirm} + onConfirm={onArchive} isOpen={isDialogOpen} onClose={() => setIsDialogOpen(false)} /> diff --git a/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ProjectFeaturesBatchActions.tsx b/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ProjectFeaturesBatchActions.tsx index 80ac294bcdc7..724141ae1525 100644 --- a/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ProjectFeaturesBatchActions.tsx +++ b/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ProjectFeaturesBatchActions.tsx @@ -15,11 +15,12 @@ interface IProjectFeaturesBatchActionsProps { selectedIds: string[]; data: FeatureSchema[]; projectId: string; + onResetSelection: () => void; } export const ProjectFeaturesBatchActions: FC< IProjectFeaturesBatchActionsProps -> = ({ selectedIds, data, projectId }) => { +> = ({ selectedIds, data, projectId, onResetSelection }) => { const { uiConfig } = useUiConfig(); const [showExportDialog, setShowExportDialog] = useState(false); const [showBulkEnableDialog, setShowBulkEnableDialog] = useState(false); @@ -92,6 +93,7 @@ export const ProjectFeaturesBatchActions: FC< projectId={projectId} featureIds={selectedIds} features={data} + onConfirm={onResetSelection} />