refactor(content-management): remove duplicated bootstrap serialization

StaticPagesEditorComponent.persist() hand-rolled the same title/html/route
mapping already implemented in ContentPageService.toBootstrapRecord(), with
subtly different behavior (always wrote empty-string html entries per locale
instead of omitting them, no title fallback). Added ContentManagementFacade.serializePages()
as a thin passthrough and switched the component to use the single canonical
implementation.
This commit is contained in:
sdarbinyan
2026-07-15 03:51:24 +04:00
parent bc03cc3d27
commit 608e1cc02b
2 changed files with 6 additions and 23 deletions

View File

@@ -82,29 +82,7 @@ export class StaticPagesEditorComponent {
private persist(pages: ContentPage[]): void { private persist(pages: ContentPage[]): void {
this.projectEditor.updateBootstrap(current => ({ this.projectEditor.updateBootstrap(current => ({
...current, ...current,
staticPages: pages.reduce<Record<string, any>>((acc, page) => { staticPages: this.contentFacade.serializePages(pages)
const record = {
id: page.id,
slug: page.slug,
title: Object.fromEntries(Object.entries(page.translations).map(([locale, translation]) => [locale, translation.title || page.title]).filter(([, value]) => !!value)),
html: Object.fromEntries(Object.entries(page.translations).map(([locale, translation]) => [locale, translation.html || ''])),
showInFooter: page.showInFooter,
showInHeader: page.showInHeader,
showInSitemap: page.showInSitemap,
icon: page.icon,
order: page.order,
visibility: page.visibility,
requiresAuthentication: page.requiresAuthentication,
footerGroup: page.footerGroup,
translations: page.translations,
seo: page.seo,
visible: true,
route: `/${page.slug}`,
content: Object.fromEntries(Object.entries(page.translations).map(([locale, translation]) => [locale, translation.html || ''])),
};
acc[page.id] = record;
return acc;
}, {})
})); }));
} }
} }

View File

@@ -1,6 +1,7 @@
import { Injectable, computed, inject } from '@angular/core'; import { Injectable, computed, inject } from '@angular/core';
import { BootstrapConfig } from '../../../shared/models/config'; import { BootstrapConfig } from '../../../shared/models/config';
import { ContentPageService } from '../services/content-page.service'; import { ContentPageService } from '../services/content-page.service';
import { ContentPage } from '../models/content-page.model';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class ContentManagementFacade { export class ContentManagementFacade {
@@ -21,4 +22,8 @@ export class ContentManagementFacade {
toBootstrapRecord(bootstrap: BootstrapConfig | null) { toBootstrapRecord(bootstrap: BootstrapConfig | null) {
return bootstrap ? this.service.toBootstrapRecord(this.pages(bootstrap)) : {}; return bootstrap ? this.service.toBootstrapRecord(this.pages(bootstrap)) : {};
} }
serializePages(pages: ContentPage[]) {
return this.service.toBootstrapRecord(pages);
}
} }