Files
klz-cables.com/.pnpm-store/v10/files/aa/64a08de2e95fdb7f90a14f86995e7ce62d13422f682eb57af39d1d4ccecd3b6e50656ea39b20955a910b2862cf012f7520aded3c02cb5fdd104d1ac4248af9
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

166 lines
4.8 KiB
Plaintext

import { createClientFields } from 'payload';
import { fieldAffectsData, getFieldPaths, tabHasName } from 'payload/shared';
export const traverseFields = ({
clientSchemaMap,
config,
fields,
i18n,
parentIndexPath,
parentSchemaPath,
payload,
schemaMap
}) => {
for (const [index, field] of fields.entries()) {
const {
indexPath,
schemaPath
} = getFieldPaths({
field,
index,
parentIndexPath,
parentSchemaPath
});
clientSchemaMap.set(schemaPath, field);
switch (field.type) {
case 'array':
{
traverseFields({
clientSchemaMap,
config,
fields: field.fields,
i18n,
parentIndexPath: '',
parentSchemaPath: schemaPath,
payload,
schemaMap
});
break;
}
case 'blocks':
;
(field.blockReferences ?? field.blocks).map(_block => {
const block = typeof _block === 'string' ? config.blocksMap ? config.blocksMap[_block] : config.blocks.find(block => typeof block !== 'string' && block.slug === _block) : _block;
const blockSchemaPath = `${schemaPath}.${block.slug}`;
clientSchemaMap.set(blockSchemaPath, block);
traverseFields({
clientSchemaMap,
config,
fields: block.fields,
i18n,
parentIndexPath: '',
parentSchemaPath: schemaPath + '.' + block.slug,
payload,
schemaMap
});
});
break;
case 'collapsible':
case 'row':
{
traverseFields({
clientSchemaMap,
config,
fields: field.fields,
i18n,
parentIndexPath: indexPath,
parentSchemaPath: schemaPath,
payload,
schemaMap
});
break;
}
case 'group':
{
if (fieldAffectsData(field)) {
traverseFields({
clientSchemaMap,
config,
fields: field.fields,
i18n,
parentIndexPath: '',
parentSchemaPath: schemaPath,
payload,
schemaMap
});
} else {
traverseFields({
clientSchemaMap,
config,
fields: field.fields,
i18n,
parentIndexPath: indexPath,
parentSchemaPath: schemaPath,
payload,
schemaMap
});
}
break;
}
case 'richText':
{
// richText sub-fields are not part of the ClientConfig or the Config.
// They only exist in the field schema map.
// Thus, we need to
// 1. get them from the field schema map
// 2. convert them to client fields
// 3. add them to the client schema map
// So these would basically be all fields that are not part of the client config already
const richTextFieldSchemaMap = new Map();
for (const [path, subField] of schemaMap.entries()) {
if (path.startsWith(`${schemaPath}.`)) {
richTextFieldSchemaMap.set(path, subField);
}
}
// Now loop through them, convert each entry to a client field and add it to the client schema map
for (const [path, subField] of richTextFieldSchemaMap.entries()) {
// check if fields is the only key in the subField object
const isFieldsOnly = Object.keys(subField).length === 1 && 'fields' in subField;
const clientFields = createClientFields({
defaultIDType: payload.config.db.defaultIDType,
disableAddingID: true,
fields: isFieldsOnly ? subField.fields : [subField],
i18n,
importMap: payload.importMap
});
clientSchemaMap.set(path, isFieldsOnly ? {
fields: clientFields
} : clientFields[0]);
}
break;
}
case 'tab':
{
const isNamedTab = tabHasName(field);
traverseFields({
clientSchemaMap,
config,
fields: field.fields,
i18n,
parentIndexPath: isNamedTab ? '' : indexPath,
parentSchemaPath: schemaPath,
payload,
schemaMap
});
break;
}
case 'tabs':
{
traverseFields({
clientSchemaMap,
config,
fields: field.tabs.map(tab => ({
...tab,
type: 'tab'
})),
i18n,
parentIndexPath: indexPath,
parentSchemaPath: schemaPath,
payload,
schemaMap
});
break;
}
}
}
};
//# sourceMappingURL=traverseFields.js.map