Files
klz-cables.com/.pnpm-store/v10/files/ca/d306d3a8c86f0d4abb39ca5f03de47c0d15c103f255a0056ce24e95ac27a11b7c96c30651dde74785df8ec6b7ef875cff1ddc52f89be75d9afb65f2cb0c07c
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

45 lines
2.2 KiB
Plaintext

import { getUniqueListBy } from 'payload/shared';
/**
* Get the fields for a row in an iterable field for comparison.
* - Array fields: the fields of the array field, because the fields are the same for each row.
* - Blocks fields: the union of fields from the comparison and version row,
* because the fields from the version and comparison rows may differ.
*/
export function getFieldsForRowComparison({
baseVersionField,
config,
field,
row,
valueFromRow,
valueToRow
}) {
let fields = [];
let versionFields = [];
if (field.type === 'array' && 'fields' in field) {
fields = field.fields;
versionFields = baseVersionField.rows?.length ? baseVersionField.rows[row] : baseVersionField.fields;
} else if (field.type === 'blocks') {
if (valueToRow?.blockType === valueFromRow?.blockType) {
const matchedBlock = config?.blocksMap?.[valueToRow?.blockType] ?? (('blocks' in field || 'blockReferences' in field) && (field.blockReferences ?? field.blocks)?.find(block => typeof block !== 'string' && block.slug === valueToRow?.blockType) || {
fields: []
});
fields = matchedBlock.fields;
versionFields = baseVersionField.rows?.length ? baseVersionField.rows[row] : baseVersionField.fields;
} else {
const matchedVersionBlock = config?.blocksMap?.[valueToRow?.blockType] ?? (('blocks' in field || 'blockReferences' in field) && (field.blockReferences ?? field.blocks)?.find(block => typeof block !== 'string' && block.slug === valueToRow?.blockType) || {
fields: []
});
const matchedComparisonBlock = config?.blocksMap?.[valueFromRow?.blockType] ?? (('blocks' in field || 'blockReferences' in field) && (field.blockReferences ?? field.blocks)?.find(block => typeof block !== 'string' && block.slug === valueFromRow?.blockType) || {
fields: []
});
fields = getUniqueListBy([...matchedVersionBlock.fields, ...matchedComparisonBlock.fields], 'name');
// buildVersionFields already merged the fields of the version and comparison rows together
versionFields = baseVersionField.rows?.length ? baseVersionField.rows[row] : baseVersionField.fields;
}
}
return {
fields,
versionFields
};
}
//# sourceMappingURL=getFieldsForRowComparison.js.map