Files
klz-cables.com/.pnpm-store/v10/files/1b/02d4bbccd7d8d551144c9628b22b195e0e2b8d8b8994ad34c66a571624d8325597cccd3d89ac57b8aaecdbbbe9f432649896be27b6082012cb466edc5a621c
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

100 lines
3.0 KiB
Plaintext

export function reduceFormStateByPath({
formState,
path,
rowIndex
}) {
const filteredState = {};
const prefix = typeof rowIndex !== 'number' ? path : `${path}.${rowIndex}`;
for (const key in formState) {
if (!key.startsWith(prefix)) {
continue;
}
const {
customComponents: _,
validate: __,
...field
} = formState[key];
if (Array.isArray(field.rows)) {
field.rows = field.rows.map(row => {
if (!row || typeof row !== 'object') {
return row;
}
const {
customComponents: _,
...serializableRow
} = row;
return serializableRow;
});
}
filteredState[key] = field;
}
return filteredState;
}
export function mergeFormStateFromClipboard({
dataFromClipboard: clipboardData,
formState,
path,
rowIndex
}) {
const {
type: typeFromClipboard,
data: dataFromClipboard,
path: pathFromClipboard,
rowIndex: rowIndexFromClipboard
} = clipboardData;
const copyFromField = typeof rowIndexFromClipboard !== 'number';
const pasteIntoField = typeof rowIndex !== 'number';
const fromRowToField = !copyFromField && pasteIntoField;
const isArray = typeFromClipboard === 'array';
let pathToReplace;
if (copyFromField && pasteIntoField) {
pathToReplace = pathFromClipboard;
} else if (copyFromField) {
pathToReplace = `${pathFromClipboard}.${rowIndex}`;
} else {
pathToReplace = `${pathFromClipboard}.${rowIndexFromClipboard}`;
}
let targetSegment;
if (!pasteIntoField) {
targetSegment = `${path}.${rowIndex}`;
} else if (fromRowToField) {
targetSegment = `${path}.0`;
} else {
targetSegment = path;
}
if (fromRowToField) {
const lastRenderedPath = `${path}.0`;
const rowIDFromClipboard = dataFromClipboard[`${pathToReplace}.id`].value;
const hasRows = formState[path].rows?.length;
formState[path].rows = [{
...(hasRows && isArray ? formState[path].rows[0] : {}),
id: rowIDFromClipboard,
isLoading: false,
lastRenderedPath
}];
formState[path].value = 1;
formState[path].initialValue = 1;
formState[path].disableFormData = true;
for (const fieldPath in formState) {
if (fieldPath !== path && !fieldPath.startsWith(lastRenderedPath) && fieldPath.startsWith(path)) {
delete formState[fieldPath];
}
}
}
for (const clipboardPath in dataFromClipboard) {
// Pasting a row id, skip overwriting
if (!pasteIntoField && clipboardPath.endsWith('.id') || !clipboardPath.startsWith(pathToReplace)) {
continue;
}
const newPath = clipboardPath.replace(pathToReplace, targetSegment);
const customComponents = isArray ? formState[newPath]?.customComponents : undefined;
const validate = isArray ? formState[newPath]?.validate : undefined;
formState[newPath] = {
customComponents,
validate,
...dataFromClipboard[clipboardPath]
};
}
return formState;
}
//# sourceMappingURL=mergeFormStateFromClipboard.js.map