Files
klz-cables.com/.pnpm-store/v10/files/a0/1ecf8b87944ca46cc120b3951c7247bde1271c5f5fe67c6d6827ee1181c35d09b6a312fc885706717c4f7f8a75a95a1e351e162b7f02b8e1ee04d4dff293ee
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

67 lines
2.4 KiB
Plaintext

/**
* Get the field by its schema path, e.g. group.title, array.group.title
* If there were any localized on the path, `pathHasLocalized` will be true and `localizedPath` will look like:
* `group.<locale>.title` // group is localized here
*/ export const getFieldByPath = ({ config, fields, includeRelationships = false, localizedPath = '', path })=>{
let currentFields = fields;
let currentField = null;
const segments = path.split('.');
let pathHasLocalized = false;
while(segments.length > 0){
const segment = segments.shift();
localizedPath = `${localizedPath ? `${localizedPath}.` : ''}${segment}`;
const field = currentFields.find((each)=>each.name === segment);
if (!field) {
return null;
}
if (field.localized) {
pathHasLocalized = true;
localizedPath = `${localizedPath}.<locale>`;
}
if ('flattenedFields' in field) {
currentFields = field.flattenedFields;
}
if (config && includeRelationships && (field.type === 'relationship' || field.type === 'upload') && !Array.isArray(field.relationTo)) {
const flattenedFields = config.collections.find((e)=>e.slug === field.relationTo)?.flattenedFields;
if (flattenedFields) {
currentFields = flattenedFields;
}
if (segments.length === 1 && segments[0] === 'id') {
return {
field,
localizedPath,
pathHasLocalized
};
}
}
if ('blocks' in field && segments.length > 0) {
const blockSlug = segments[0];
const block = field.blocks.find((b)=>b.slug === blockSlug);
if (block) {
segments.shift();
localizedPath = `${localizedPath}.${blockSlug}`;
if (segments.length === 0) {
return null;
}
return getFieldByPath({
config,
fields: block.flattenedFields,
includeRelationships,
localizedPath,
path: segments.join('.')
});
}
}
currentField = field;
}
if (!currentField) {
return null;
}
return {
field: currentField,
localizedPath,
pathHasLocalized
};
};
//# sourceMappingURL=getFieldByPath.js.map