fix(project-editor): preserve multilingual nav labels on edit

updateLabel() previously overwrote NavigationItemConfig.label with a bare
string via updateNavLink, destroying every other locale's translation
whenever a localized label object was edited. Add a facade method
updateNavLinkLabel() that inspects the existing label shape: plain
strings are replaced as before, but localized objects only have the
current default locale's key overwritten, leaving other locales intact.
This commit is contained in:
sdarbinyan
2026-07-13 15:57:39 +04:00
parent a8b2b4bf0b
commit 68442919d3
2 changed files with 33 additions and 1 deletions

View File

@@ -179,6 +179,38 @@ export class ProjectEditorFacade {
}); });
} }
/**
* Updates a nav item's label without destroying other locales' translations.
* If the item's current label is a plain string (or unset), it's replaced outright.
* If it's already a NavigationLocalizedText object, only the current default
* locale's key is overwritten; every other locale key is preserved untouched.
*/
updateNavLinkLabel(target: 'header' | 'footer', id: string, value: string): void {
this.updateBootstrap(current => {
const list = current.navigation[target];
if (!this.isFlatNavList(list)) {
return current;
}
const defaultLocale = current.localization.defaultLocale ?? 'en';
return {
...current,
navigation: {
...current.navigation,
[target]: (list as NavigationItemConfig[]).map(item => {
if (item.id !== id) {
return item;
}
const currentLabel = item.label;
const nextLabel = currentLabel && typeof currentLabel === 'object'
? { ...currentLabel, [defaultLocale]: value }
: value;
return { ...item, label: nextLabel };
}),
},
};
});
}
reorderNavLink(target: 'header' | 'footer', id: string, direction: -1 | 1): void { reorderNavLink(target: 'header' | 'footer', id: string, direction: -1 | 1): void {
this.updateBootstrap(current => { this.updateBootstrap(current => {
const list = current.navigation[target]; const list = current.navigation[target];

View File

@@ -46,7 +46,7 @@ export class ProjectEditorNavigationSectionComponent {
} }
updateLabel(target: 'header' | 'footer', id: string, value: string): void { updateLabel(target: 'header' | 'footer', id: string, value: string): void {
this.facade.updateNavLink(target, id, { label: value }); this.facade.updateNavLinkLabel(target, id, value);
} }
updateRoute(target: 'header' | 'footer', id: string, value: string): void { updateRoute(target: 'header' | 'footer', id: string, value: string): void {