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:
@@ -82,29 +82,7 @@ export class StaticPagesEditorComponent {
|
||||
private persist(pages: ContentPage[]): void {
|
||||
this.projectEditor.updateBootstrap(current => ({
|
||||
...current,
|
||||
staticPages: pages.reduce<Record<string, any>>((acc, page) => {
|
||||
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;
|
||||
}, {})
|
||||
staticPages: this.contentFacade.serializePages(pages)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable, computed, inject } from '@angular/core';
|
||||
import { BootstrapConfig } from '../../../shared/models/config';
|
||||
import { ContentPageService } from '../services/content-page.service';
|
||||
import { ContentPage } from '../models/content-page.model';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ContentManagementFacade {
|
||||
@@ -21,4 +22,8 @@ export class ContentManagementFacade {
|
||||
toBootstrapRecord(bootstrap: BootstrapConfig | null) {
|
||||
return bootstrap ? this.service.toBootstrapRecord(this.pages(bootstrap)) : {};
|
||||
}
|
||||
|
||||
serializePages(pages: ContentPage[]) {
|
||||
return this.service.toBootstrapRecord(pages);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user