Files
klz-cables.com/.pnpm-store/v10/files/ae/5d3b4864b6ea307a5c8d8048b4e0404898e92f5db50d1538eabade3be5e4b3357c03d4797d2b5cafd9edaee1f1c96113c996415857387ee8912c55e8d78d1a
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

73 lines
2.1 KiB
Plaintext

'use client';
import { getTranslation } from '@payloadcms/translations';
const reduceToIDs = options => options.reduce((ids, option) => {
if (option.options) {
return [...ids, ...reduceToIDs(option.options)];
}
return [...ids, option.id];
}, []);
const optionsReducer = (state, action) => {
switch (action.type) {
case 'ADD':
{
const {
collection,
data,
hasMultipleRelations,
i18n,
relation
} = action;
const labelKey = collection.admin.useAsTitle || 'id';
const loadedIDs = reduceToIDs(state);
if (!hasMultipleRelations) {
return [...state, ...data.docs.reduce((docs, doc) => {
if (loadedIDs.indexOf(doc.id) === -1) {
loadedIDs.push(doc.id);
return [...docs, {
label: doc[labelKey],
value: doc.id
}];
}
return docs;
}, [])];
}
const newOptions = [...state];
const optionsToAddTo = newOptions.find(optionGroup => optionGroup.label === getTranslation(collection.labels.plural, i18n));
const newSubOptions = data.docs.reduce((docs, doc) => {
if (loadedIDs.indexOf(doc.id) === -1) {
loadedIDs.push(doc.id);
return [...docs, {
label: doc[labelKey],
relationTo: relation,
value: doc.id
}];
}
return docs;
}, []);
if (optionsToAddTo) {
optionsToAddTo.options = [...optionsToAddTo.options, ...newSubOptions];
} else {
newOptions.push({
label: getTranslation(collection.labels.plural, i18n),
options: newSubOptions,
value: undefined
});
}
return newOptions;
}
case 'CLEAR':
{
return action.required ? [] : [{
label: action.i18n.t('general:none'),
value: 'null'
}];
}
default:
{
return state;
}
}
};
export default optionsReducer;
//# sourceMappingURL=optionsReducer.js.map