From bd4b98279fdd7d7dc7632c2013157371d9d99f05 Mon Sep 17 00:00:00 2001 From: Ola Pawlus Date: Wed, 25 Jun 2025 11:24:52 +0200 Subject: [PATCH 1/2] [Embeddable Rebuild] Fix panel title sync with saved object when using defaultTitle --- .../customize_panel_action/customize_panel_editor.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.tsx b/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.tsx index 122fd05e5309c..4d8f41c60d472 100644 --- a/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.tsx +++ b/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.tsx @@ -99,7 +99,13 @@ export const CustomizePanelEditor = ({ const dateFormat = useMemo(() => core.uiSettings.get(UI_SETTINGS.DATE_FORMAT), []); const save = () => { - if (panelTitle !== api.title$?.value) api.setTitle?.(panelTitle); + // If the panel title matches the default title, we set api.title to undefined to indicate there's no custom title. + // This ensures the panel stays in sync with the centrally saved object's title and reflects any updates to its title. + if (panelTitle === api?.defaultTitle$?.value) { + api.setTitle?.(undefined); + } else if (panelTitle !== api.title$?.value) { + api.setTitle?.(panelTitle); + } if (hideTitle !== api.hideTitle$?.value) api.setHideTitle?.(hideTitle); if (panelDescription !== api.description$?.value) api.setDescription?.(panelDescription); From 76b8a3474f842bf979f5a0ab7eedd20fe96db5b2 Mon Sep 17 00:00:00 2001 From: Ola Pawlus Date: Thu, 26 Jun 2025 12:47:45 +0200 Subject: [PATCH 2/2] adding test case for panel title on apply matching default title --- .../customize_panel_editor.test.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.test.tsx b/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.test.tsx index 91be0c249be51..21633f28e8217 100644 --- a/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.test.tsx +++ b/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.test.tsx @@ -89,6 +89,17 @@ describe('customize panel editor', () => { expect(titleInput).toHaveValue('Default title'); }); + // Even if the input value matches defaultTitle on apply, we expect setTitle(undefined) to be called, meaning the title is treated as "not customized". + it('should not set panel custom title if it matches default title on apply', async () => { + api.defaultTitle$ = new BehaviorSubject('Default title'); + renderPanelEditor(); + const titleInput = screen.getByTestId('customEmbeddablePanelTitleInput'); + expect(titleInput).toHaveValue('Default title'); + await userEvent.click(screen.getByTestId('saveCustomizePanelButton')); + expect(setTitle).toHaveBeenCalledWith(undefined); + expect(api.title$?.getValue()).toBeUndefined(); + }); + it('should use title even when empty string', () => { api.defaultTitle$ = new BehaviorSubject('Default title'); setTitle('');