Skip to content

Commit f898981

Browse files
committed
fix(dashboard): offer Exit edit mode when there is nothing to discard
Follow-up to #40832, which disabled the Discard button when a dashboard edit session has no unsaved changes. That fixed the misleading label but left the toolbar with no way back to view mode on a pristine session (Save and Discard both disabled, and the actions menu has no exit item). Keep the button always enabled instead, labeled Discard when there are unsaved changes and Exit edit mode when there are none. The handler is unchanged in both cases: it drops the ?edit param and returns to view mode. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 751f5eb commit f898981

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎superset-frontend/src/dashboard/components/Header/Header.test.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,15 @@ test('should disable both buttons when no actions available', () => {
522522
expect(onRedo).not.toHaveBeenCalled();
523523
});
524524

525-
test('should render the "Discard" button as disabled', () => {
525+
test('should render an enabled "Exit edit mode" button when there are no unsaved changes', () => {
526526
setup(editableState);
527-
expect(screen.getByRole('button', { name: /discard/i })).toBeDisabled();
527+
expect(screen.getByRole('button', { name: /exit edit mode/i })).toBeEnabled();
528+
expect(
529+
screen.queryByRole('button', { name: /discard/i }),
530+
).not.toBeInTheDocument();
528531
});
529532

530-
test('should enable the "Discard" button when there are unsaved changes', () => {
533+
test('should render an enabled "Discard" button when there are unsaved changes', () => {
531534
const unsavedState = {
532535
...editableState,
533536
dashboardState: {
@@ -537,6 +540,9 @@ test('should enable the "Discard" button when there are unsaved changes', () =>
537540
};
538541
setup(unsavedState);
539542
expect(screen.getByRole('button', { name: /discard/i })).toBeEnabled();
543+
expect(
544+
screen.queryByRole('button', { name: /exit edit mode/i }),
545+
).not.toBeInTheDocument();
540546
});
541547

542548
test('should render the "Save" button as disabled', () => {

‎superset-frontend/src/dashboard/components/Header/index.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,14 @@ const Header = (): JSX.Element => {
722722
<Button
723723
css={discardBtnStyle}
724724
buttonSize="small"
725-
disabled={!hasUnsavedChanges}
726725
onClick={discardChanges}
727726
buttonStyle="secondary"
728727
data-test="discard-changes-button"
729-
aria-label={t('Discard')}
728+
aria-label={
729+
hasUnsavedChanges ? t('Discard') : t('Exit edit mode')
730+
}
730731
>
731-
{t('Discard')}
732+
{hasUnsavedChanges ? t('Discard') : t('Exit edit mode')}
732733
</Button>
733734
<Button
734735
css={saveBtnStyle}

0 commit comments

Comments
 (0)