Skip to content

Commit

Permalink
fix: reset selected toggle after archive or revive (#4606)
Browse files Browse the repository at this point in the history
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
When archiving or reviving feature toggles, when toggles disappear from
table, actions bar should also disappear.

<!-- Does it close an issue? Multiple? -->
Closes
https://linear.app/unleash/issue/1-1293/bulk-revive-modal-doesnt-go-away
  • Loading branch information
Tymek authored Sep 5, 2023
1 parent d5edcc3 commit c19bd61
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
interface IArchiveBatchActionsProps {
selectedIds: string[];
projectId: string;
onReviveConfirm?: () => void;
}

export const ArchiveBatchActions: FC<IArchiveBatchActionsProps> = ({
selectedIds,
projectId,
onReviveConfirm,
}) => {
const { reviveFeatures } = useProjectApi();
const { setToastData, setToastApiError } = useToast();
Expand All @@ -31,6 +33,7 @@ export const ArchiveBatchActions: FC<IArchiveBatchActionsProps> = ({
const onRevive = async () => {
try {
await reviveFeatures(projectId, selectedIds);
onReviveConfirm?.();
await refetchArchived();
setToastData({
type: 'success',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -360,6 +362,7 @@ export const ArchiveTable = ({
<ArchiveBatchActions
selectedIds={Object.keys(selectedRowIds)}
projectId={projectId!}
onReviveConfirm={() => toggleAllRowsSelected(false)}
/>
</BatchSelectionActionsBar>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -705,6 +706,7 @@ export const ProjectFeatureToggles = ({
selectedIds={Object.keys(selectedRowIds)}
data={features}
projectId={projectId}
onResetSelection={() => toggleAllRowsSelected(false)}
/>
</BatchSelectionActionsBar>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface IArchiveButtonProps {
projectId: string;
featureIds: string[];
features: FeatureSchema[];
onConfirm?: () => void;
}

const DEFAULT_USAGE_THRESHOLD_DAYS = 7;
Expand All @@ -29,6 +30,7 @@ export const ArchiveButton: VFC<IArchiveButtonProps> = ({
projectId,
featureIds,
features,
onConfirm,
}) => {
const { refetch } = useProject(projectId);
const [isDialogOpen, setIsDialogOpen] = useState(false);
Expand All @@ -41,8 +43,9 @@ export const ArchiveButton: VFC<IArchiveButtonProps> = ({
});
}, [JSON.stringify(features), featureIds]);

const onConfirm = async () => {
const onArchive = async () => {
setIsDialogOpen(false);
onConfirm?.();
await refetch();
trackEvent('batch_operations', {
props: {
Expand All @@ -69,7 +72,7 @@ export const ArchiveButton: VFC<IArchiveButtonProps> = ({
projectId={projectId}
featureIds={featureIds}
featuresWithUsage={featuresWithUsage}
onConfirm={onConfirm}
onConfirm={onArchive}
isOpen={isDialogOpen}
onClose={() => setIsDialogOpen(false)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -92,6 +93,7 @@ export const ProjectFeaturesBatchActions: FC<
projectId={projectId}
featureIds={selectedIds}
features={data}
onConfirm={onResetSelection}
/>
<Button
variant="outlined"
Expand Down
8 changes: 4 additions & 4 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3016,10 +3016,10 @@
"@types/history" "^4.7.11"
"@types/react" "*"

"@types/[email protected].14":
version "7.7.14"
resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.7.14.tgz#b880f1ae140ed065bca2e21b3008ca1ebe71595a"
integrity sha512-TYrv7onCiakaG1uAu/UpQ9FojNEt/4/ht87EgJQaEGFoWV606ZLWUZAcUHzMxgc3v1mywP1cDyz3qB4ho3hWOw==
"@types/[email protected].15":
version "7.7.15"
resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.7.15.tgz#e9a093a5f2be4fff5ccb41f1aec9516b520ed9b3"
integrity sha512-tlXKCeq4gk2xT2lB+Hbp/dO5yYZ899HwQOAp/3o3hKw8wp7ngNpdB90BNWE6kWCm5K2KzmEsHnYoJheSS5SVjg==
dependencies:
"@types/react" "*"

Expand Down

0 comments on commit c19bd61

Please sign in to comment.