Files
klz-cables.com/.pnpm-store/v10/files/cc/52e03f0fff9b0a5fed0adac32211eca49ba696fe911f71da29c2f0e8565bcc351d30e4d3eed6ae0c94b85ff459123ed2236d42445e1ad5dc0e21943c135795
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

78 lines
3.0 KiB
Plaintext

import { fieldShouldBeLocalized } from 'payload/shared';
import toSnakeCase from 'to-snake-case';
import { resolveBlockTableName } from '../../utilities/validateExistingBlockIsIdentical.js';
import { traverseFields } from './traverseFields.js';
export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, numbersToDelete, parentIsLocalized, path, relationships, relationshipsToDelete, selects, texts, textsToDelete, withinArrayOrBlockLocale })=>{
data.forEach((blockRow, i)=>{
if (typeof blockRow.blockType !== 'string') {
return;
}
const matchedBlock = adapter.payload.blocks[blockRow.blockType] ?? (field.blockReferences ?? field.blocks).find((block)=>typeof block !== 'string' && block.slug === blockRow.blockType);
if (!matchedBlock) {
return;
}
const blockType = toSnakeCase(blockRow.blockType);
const newRow = {
arrays: {},
arraysToPush: {},
locales: {},
row: {
_order: i + 1,
_path: `${path}${field.name}`
}
};
if (fieldShouldBeLocalized({
field,
parentIsLocalized
}) && locale) {
newRow.row._locale = locale;
}
if (withinArrayOrBlockLocale) {
newRow.row._locale = withinArrayOrBlockLocale;
}
const blockTableName = resolveBlockTableName(matchedBlock, adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`));
if (!blocks[blockTableName]) {
blocks[blockTableName] = [];
}
const hasUUID = adapter.tables[blockTableName]._uuid;
// If we have declared a _uuid field on arrays,
// that means the ID has to be unique,
// and our ids within arrays are not unique.
// So move the ID to a uuid field for storage
// and allow the database to generate a serial id automatically
if (hasUUID) {
newRow.row._uuid = blockRow.id;
delete blockRow.id;
}
traverseFields({
adapter,
arrays: newRow.arrays,
arraysToPush: newRow.arraysToPush,
baseTableName,
blocks,
blocksToDelete,
columnPrefix: '',
data: blockRow,
fieldPrefix: '',
fields: matchedBlock.flattenedFields,
insideArrayOrBlock: true,
locales: newRow.locales,
numbers,
numbersToDelete,
parentIsLocalized: parentIsLocalized || field.localized,
parentTableName: blockTableName,
path: `${path || ''}${field.name}.${i}.`,
relationships,
relationshipsToAppend: [],
relationshipsToDelete,
row: newRow.row,
selects,
texts,
textsToDelete,
withinArrayOrBlockLocale
});
blocks[blockTableName].push(newRow);
});
};
//# sourceMappingURL=blocks.js.map