forked from UKSOURCE/cms.lams
feat(cms): enhance content editors and implement automatic ID generation
Improve the CMS administration interface across multiple pages (Accreditation, Admissions, History, Partnerships, and Policies) with a focus on usability and data integrity. Key changes include: - Implement `ensureUniqueIds` utility to automatically generate and maintain unique slugs for content items, removing the need for manual ID entry in the UI. - Refactor the Admissions calculator to support detailed per-option editing via a new dedicated view and routes. - Replace basic datalists with a custom, searchable icon combobox component for better visual selection. - Update `_renderSingletonPageView` to handle active tab persistence via query parameters. - Streamline editor configurations by removing redundant fields and improving help text. - Enhance the Admissions "Key Dates" editor with a dynamic table interface for managing columns and rows. - Normalize data payloads in controllers to ensure consistent API responses and internal linking.
This commit is contained in:
@@ -9,6 +9,7 @@ const createRenderSingletonPageView = require("./_renderSingletonPageView");
|
||||
const writeAuditLog = require("../audit/writeAuditLog");
|
||||
const diffObject = require("../audit/diffObject");
|
||||
const jsonHelper = require("../utils/jsonHelper");
|
||||
const { ensureUniqueIds } = require("../utils/contentEditorIds");
|
||||
|
||||
function formatLastUpdated(date = new Date()) {
|
||||
return `Last updated: ${new Intl.DateTimeFormat("en-US", {
|
||||
@@ -18,9 +19,26 @@ function formatLastUpdated(date = new Date()) {
|
||||
}).format(date)}`;
|
||||
}
|
||||
|
||||
function withLastUpdated(payload) {
|
||||
function withLastUpdated(payload, { beforeData } = {}) {
|
||||
const existingPolicies = Array.isArray(beforeData?.policies) ? beforeData.policies : [];
|
||||
|
||||
const policies = ensureUniqueIds(
|
||||
Array.isArray(payload.policies) ? payload.policies : [],
|
||||
(policy) => policy.id,
|
||||
(policy, index) => policy.navLabel || policy.title || `policy-${index + 1}`,
|
||||
"policy",
|
||||
).map((policy) => {
|
||||
const existingPolicy = existingPolicies.find((item) => item.id === policy.id);
|
||||
|
||||
return {
|
||||
...policy,
|
||||
sections: Array.isArray(existingPolicy?.sections) ? existingPolicy.sections : [],
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
...payload,
|
||||
policies,
|
||||
hero: {
|
||||
...(payload.hero || {}),
|
||||
lastUpdated: formatLastUpdated(),
|
||||
|
||||
Reference in New Issue
Block a user