Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined>('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<string | undefined>('Default title');
setTitle('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ export const CustomizePanelEditor = ({
const dateFormat = useMemo(() => core.uiSettings.get<string>(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);

Expand Down