From 66039c144d9fa1c06460411dbf29da47703ee9cc Mon Sep 17 00:00:00 2001 From: Jamie Howard <48524071+jhoward1994@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:36:25 +0100 Subject: [PATCH] (content-manager): ask for confirmation of d&p tab change (#19912) * feat(content-manager): ask for confirmation of d&p tab change when form is modified * fix(admin): controlled tabs * chore(admin): types * chore: update design-system to 1.17.0 --- package.json | 2 +- .../core/admin/admin/src/components/Form.tsx | 40 ++++- packages/core/admin/package.json | 2 +- .../admin/src/pages/EditView/EditViewPage.tsx | 19 +-- packages/core/content-manager/package.json | 2 +- packages/core/content-releases/package.json | 2 +- .../core/content-type-builder/package.json | 2 +- packages/core/email/package.json | 2 +- packages/core/review-workflows/package.json | 2 +- packages/core/upload/package.json | 2 +- packages/plugins/cloud/package.json | 2 +- packages/plugins/color-picker/package.json | 2 +- packages/plugins/documentation/package.json | 2 +- packages/plugins/graphql/package.json | 2 +- packages/plugins/i18n/package.json | 2 +- packages/plugins/sentry/package.json | 2 +- .../plugins/users-permissions/package.json | 2 +- yarn.lock | 147 +++++++++++++----- 18 files changed, 158 insertions(+), 78 deletions(-) diff --git a/package.json b/package.json index ca9ba63fd6..151efbae67 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "watch": "nx run-many --target=watch --nx-ignore-cycles" }, "resolutions": { - "@strapi/design-system": "1.17.0-typescript.0", + "@strapi/design-system": "1.18.0-typescript.0", "@types/koa": "2.13.4" }, "devDependencies": { diff --git a/packages/core/admin/admin/src/components/Form.tsx b/packages/core/admin/admin/src/components/Form.tsx index a4532d6473..cacf8cfbcc 100644 --- a/packages/core/admin/admin/src/components/Form.tsx +++ b/packages/core/admin/admin/src/components/Form.tsx @@ -687,20 +687,38 @@ const isErrorMessageDescriptor = (object?: string | object): object is Translati ); }; +/** + * Props for the Blocker component. + * @param onProceed Function to be called when the user confirms the action that triggered the blocker. + * @param onCancel Function to be called when the user cancels the action that triggered the blocker. + */ +interface BlockerProps { + onProceed?: () => void; + onCancel?: () => void; +} /* ------------------------------------------------------------------------------------------------- * Blocker * -----------------------------------------------------------------------------------------------*/ -const Blocker = () => { +const Blocker = ({ onProceed = () => {}, onCancel = () => {} }: BlockerProps) => { const { formatMessage } = useIntl(); const modified = useForm('Blocker', (state) => state.modified); const isSubmitting = useForm('Blocker', (state) => state.isSubmitting); - const blocker = useBlocker( - ({ currentLocation, nextLocation }) => - !isSubmitting && modified && currentLocation.pathname !== nextLocation.pathname - ); + const blocker = useBlocker(({ currentLocation, nextLocation }) => { + return ( + !isSubmitting && + modified && + (currentLocation.pathname !== nextLocation.pathname || + currentLocation.search !== nextLocation.search) + ); + }); if (blocker.state === 'blocked') { + const handleCancel = () => { + onCancel(); + blocker.reset(); + }; + return ( { id: 'app.components.ConfirmDialog.title', defaultMessage: 'Confirmation', })} - onClose={() => blocker.reset()} + onClose={handleCancel} > @@ -723,7 +741,7 @@ const Blocker = () => { blocker.reset()} variant="tertiary"> + } endAction={ -