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:
@@ -0,0 +1,35 @@
|
||||
function slugifyContentId(value, fallback = "item") {
|
||||
const normalized = String(value || "")
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
|
||||
return normalized || fallback;
|
||||
}
|
||||
|
||||
function ensureUniqueIds(items, getExistingId, getSourceValue, fallbackPrefix) {
|
||||
const usedIds = new Set();
|
||||
|
||||
return (Array.isArray(items) ? items : []).map((item, index) => {
|
||||
const existingId = String(getExistingId(item, index) || "").trim();
|
||||
let nextId = existingId || slugifyContentId(getSourceValue(item, index), `${fallbackPrefix}-${index + 1}`);
|
||||
let suffix = 2;
|
||||
|
||||
while (usedIds.has(nextId)) {
|
||||
nextId = `${existingId || slugifyContentId(getSourceValue(item, index), fallbackPrefix)}-${suffix}`;
|
||||
suffix += 1;
|
||||
}
|
||||
|
||||
usedIds.add(nextId);
|
||||
return {
|
||||
...item,
|
||||
id: nextId,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
slugifyContentId,
|
||||
ensureUniqueIds,
|
||||
};
|
||||
Reference in New Issue
Block a user