From e091a83703d8d1a170c150d0b716646aea7ef33f Mon Sep 17 00:00:00 2001 From: Mikko Korhonen Date: Thu, 18 Sep 2025 15:37:53 +0300 Subject: [PATCH] feat(home): improve widget editing state management Signed-off-by: Mikko Korhonen --- .changeset/easy-maps-appear.md | 5 + plugins/home/report-alpha.api.md | 1 + .../CustomHomepage/CustomHomepageButtons.tsx | 5 + .../CustomHomepageGrid.test.tsx | 169 ++++++++++++++++++ .../CustomHomepage/CustomHomepageGrid.tsx | 34 +++- plugins/home/src/translation.ts | 1 + 6 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 .changeset/easy-maps-appear.md create mode 100644 plugins/home/src/components/CustomHomepage/CustomHomepageGrid.test.tsx diff --git a/.changeset/easy-maps-appear.md b/.changeset/easy-maps-appear.md new file mode 100644 index 0000000000..67c97c20f6 --- /dev/null +++ b/.changeset/easy-maps-appear.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-home': minor +--- + +Widget configurations are now only saved to storage when the Save button is explicitly clicked. Added a Cancel button that allows users to discard unsaved changes and revert to the last saved state. diff --git a/plugins/home/report-alpha.api.md b/plugins/home/report-alpha.api.md index 58ceef751d..6344805372 100644 --- a/plugins/home/report-alpha.api.md +++ b/plugins/home/report-alpha.api.md @@ -107,6 +107,7 @@ export const homeTranslationRef: TranslationRef< { readonly 'starredEntities.noStarredEntitiesMessage': 'Click the star beside an entity name to add it to this list!'; readonly 'addWidgetDialog.title': 'Add new widget to dashboard'; + readonly 'customHomepageButtons.cancel': 'Cancel'; readonly 'customHomepageButtons.clearAll': 'Clear all'; readonly 'customHomepageButtons.edit': 'Edit'; readonly 'customHomepageButtons.restoreDefaults': 'Restore defaults'; diff --git a/plugins/home/src/components/CustomHomepage/CustomHomepageButtons.tsx b/plugins/home/src/components/CustomHomepage/CustomHomepageButtons.tsx index 0496e923de..b7e397c995 100644 --- a/plugins/home/src/components/CustomHomepage/CustomHomepageButtons.tsx +++ b/plugins/home/src/components/CustomHomepage/CustomHomepageButtons.tsx @@ -45,6 +45,7 @@ interface CustomHomepageButtonsProps { changeEditMode: (mode: boolean) => void; defaultConfigAvailable: boolean; restoreDefault: () => void; + cancel: () => void; } export const CustomHomepageButtons = (props: CustomHomepageButtonsProps) => { const { @@ -55,6 +56,7 @@ export const CustomHomepageButtons = (props: CustomHomepageButtonsProps) => { changeEditMode, defaultConfigAvailable, restoreDefault, + cancel, } = props; const styles = useStyles(); const { t } = useTranslationRef(homeTranslationRef); @@ -73,6 +75,9 @@ export const CustomHomepageButtons = (props: CustomHomepageButtonsProps) => { ) : ( <> + {defaultConfigAvailable && (