Skip to content

Commit e00a4c4

Browse files
authored
refactor: Build new action buttons for cancel confirmation modal (#1732)
Build new action buttons for cancel confirmation modal in basic block and advanced block editors.
1 parent 341a03c commit e00a4c4

File tree

9 files changed

+46
-18
lines changed

9 files changed

+46
-18
lines changed

src/editors/AdvancedEditor.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe('AdvancedEditor', () => {
3838

3939
// Expect open cancel confimation modal
4040
expect(await screen.findByText(/Are you sure you want to exit the editor/)).toBeInTheDocument();
41-
// Click on "OK"
42-
const confirmButton = await screen.findByRole('button', { name: 'OK' });
41+
// Click on "Discard button"
42+
const confirmButton = await screen.findByRole('button', { name: 'Discard Changes and Exit' });
4343
fireEvent.click(confirmButton);
4444
// Should call `onClose`
4545
expect(onCloseMock).toHaveBeenCalled();

src/editors/containers/EditorContainer/components/CancelConfirmModal.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@ const CancelConfirmModal = ({
1717
const intl = useIntl();
1818
return (
1919
<BaseModal
20-
size="md"
20+
size="lg"
21+
footerAction={(
22+
<Button
23+
variant="outline-brand"
24+
onClick={() => onCloseEditor?.()}
25+
>
26+
<FormattedMessage {...messages.discardChangesButtonlabel} />
27+
</Button>
28+
)}
2129
confirmAction={(
2230
<Button
2331
variant="primary"
24-
onClick={() => onCloseEditor?.()}
32+
onClick={closeCancelConfirmModal}
2533
>
26-
<FormattedMessage {...messages.okButtonLabel} />
34+
<FormattedMessage {...messages.keepEditingButtonLabel} />
2735
</Button>
2836
)}
2937
isOpen={isOpen}
3038
close={closeCancelConfirmModal}
3139
title={intl.formatMessage(messages.cancelConfirmTitle)}
40+
hideCancelButton
3241
>
3342
<FormattedMessage {...messages.cancelConfirmDescription} />
3443
</BaseModal>

src/editors/containers/EditorContainer/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ describe('EditorContainer', () => {
9090
expect(defaultPropsHtml.onClose).not.toHaveBeenCalled();
9191

9292
// Should close modal if cancelled
93-
const cancelBtn = await screen.findByRole('button', { name: 'Cancel' });
93+
const cancelBtn = await screen.findByRole('button', { name: 'Keep Editing' });
9494
fireEvent.click(cancelBtn);
9595
expect(defaultPropsHtml.onClose).not.toHaveBeenCalled();
9696

9797
// open modal again
9898
fireEvent.click(closeButton);
9999
// And can confirm the cancelation:
100-
const confirmButton = await screen.findByRole('button', { name: 'OK' });
100+
const confirmButton = await screen.findByRole('button', { name: 'Discard Changes and Exit' });
101101
fireEvent.click(confirmButton);
102102
expect(defaultPropsHtml.onClose).toHaveBeenCalled();
103103
window.dispatchEvent(mockEvent);

src/editors/containers/EditorContainer/messages.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ const messages = defineMessages({
1717
defaultMessage: 'Exit the editor',
1818
description: 'Alt text for the Exit button',
1919
},
20-
okButtonLabel: {
21-
id: 'authoring.editorContainer.okButton.label',
22-
defaultMessage: 'OK',
23-
description: 'Label for OK button',
20+
keepEditingButtonLabel: {
21+
id: 'authoring.editorContainer.keepEditing.label',
22+
defaultMessage: 'Keep Editing',
23+
description: 'Label for keep editing button on the editor cancel confirmation',
24+
},
25+
discardChangesButtonlabel: {
26+
id: 'authoring.editorContainer.discardChanges.label',
27+
defaultMessage: 'Discard Changes and Exit',
28+
description: 'Label for discard changes button on the editor cancel confirmation',
2429
},
2530
modalTitle: {
2631
id: 'authoring.editorContainer.accessibleTitle',

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/SwitchToAdvancedEditorCard.test.jsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ exports[`SwitchToAdvancedEditorCard snapshot snapshot: SwitchToAdvancedEditorCar
2323
}
2424
footerAction={null}
2525
headerComponent={null}
26+
hideCancelButton={false}
2627
isFullscreenScroll={true}
2728
isOpen={false}
2829
size="md"

src/editors/sharedComponents/BaseModal/__snapshots__/index.test.jsx.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ exports[`BaseModal ImageUploadModal template component snapshot 1`] = `
3232
</Scrollable>
3333
<ModalDialog.Footer>
3434
<ActionRow>
35-
props.footerAction node
36-
<ActionRow.Spacer />
35+
<Fragment>
36+
props.footerAction node
37+
<ActionRow.Spacer />
38+
</Fragment>
3739
<ModalDialog.CloseButton
3840
onClick={[MockFunction props.close]}
3941
variant="tertiary"

src/editors/sharedComponents/BaseModal/index.jsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const BaseModal = ({
2222
isFullscreenScroll,
2323
bodyStyle,
2424
className,
25+
hideCancelButton,
2526
}) => (
2627
<ModalDialog
2728
isOpen={isOpen}
@@ -47,11 +48,17 @@ const BaseModal = ({
4748
</Scrollable>
4849
<ModalDialog.Footer>
4950
<ActionRow>
50-
{footerAction}
51-
<ActionRow.Spacer />
52-
<ModalDialog.CloseButton variant="tertiary" onClick={close}>
53-
<FormattedMessage {...messages.cancelButtonLabel} />
54-
</ModalDialog.CloseButton>
51+
{footerAction && (
52+
<>
53+
{footerAction}
54+
<ActionRow.Spacer />
55+
</>
56+
)}
57+
{!hideCancelButton && (
58+
<ModalDialog.CloseButton variant="tertiary" onClick={close}>
59+
<FormattedMessage {...messages.cancelButtonLabel} />
60+
</ModalDialog.CloseButton>
61+
)}
5562
{confirmAction}
5663
</ActionRow>
5764
</ModalDialog.Footer>
@@ -65,6 +72,7 @@ BaseModal.defaultProps = {
6572
isFullscreenScroll: true,
6673
bodyStyle: null,
6774
className: undefined,
75+
hideCancelButton: false,
6876
};
6977

7078
BaseModal.propTypes = {
@@ -79,6 +87,7 @@ BaseModal.propTypes = {
7987
isFullscreenScroll: PropTypes.bool,
8088
bodyStyle: PropTypes.shape({}),
8189
className: PropTypes.string,
90+
hideCancelButton: PropTypes.bool,
8291
};
8392

8493
export default BaseModal;

src/editors/sharedComponents/ImageUploadModal/ImageSettingsModal/__snapshots__/index.test.jsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ exports[`ImageSettingsModal render snapshot 1`] = `
3737
}
3838
footerAction={null}
3939
headerComponent={null}
40+
hideCancelButton={false}
4041
isFullscreenScroll={true}
4142
isOpen={false}
4243
size="lg"

src/editors/sharedComponents/SourceCodeModal/__snapshots__/index.test.jsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ exports[`SourceCodeModal renders as expected with default behavior 1`] = `
3030
}
3131
footerAction={null}
3232
headerComponent={null}
33+
hideCancelButton={false}
3334
isFullscreenScroll={true}
3435
isOpen={false}
3536
size="xl"

0 commit comments

Comments
 (0)