CSV importing and exporting fixes (#8824)
Fixes issue https://github.com/twentyhq/twenty/issues/5793 (and duplicate https://github.com/twentyhq/twenty/issues/8822) - Fix importing multi-select and array fields. - Fix exporting and importing RAW_JSON fields. --------- Co-authored-by: ad-elias <elias@autodiligence.com>
This commit is contained in:
@ -8,6 +8,8 @@ import {
|
||||
ImportedStructuredRow,
|
||||
} from '@/spreadsheet-import/types';
|
||||
|
||||
import { isDefined } from '@ui/utilities/isDefined';
|
||||
import { z } from 'zod';
|
||||
import { normalizeCheckboxValue } from './normalizeCheckboxValue';
|
||||
|
||||
export const normalizeTableData = <T extends string>(
|
||||
@ -54,10 +56,45 @@ export const normalizeTableData = <T extends string>(
|
||||
}
|
||||
case ColumnType.matchedSelect:
|
||||
case ColumnType.matchedSelectOptions: {
|
||||
const matchedOption = column.matchedOptions.find(
|
||||
({ entry }) => entry === curr,
|
||||
);
|
||||
acc[column.value] = matchedOption?.value || undefined;
|
||||
const field = fields.find((field) => field.key === column.value);
|
||||
|
||||
if (!field) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
if (field.fieldType.type === 'multiSelect' && isDefined(curr)) {
|
||||
const currentOptionsSchema = z.preprocess(
|
||||
(value) => JSON.parse(z.string().parse(value)),
|
||||
z.array(z.unknown()),
|
||||
);
|
||||
|
||||
const rawCurrentOptions = currentOptionsSchema.safeParse(curr).data;
|
||||
|
||||
const matchedOptionValues = [
|
||||
...new Set(
|
||||
rawCurrentOptions
|
||||
?.map(
|
||||
(option) =>
|
||||
column.matchedOptions.find(
|
||||
(matchedOption) => matchedOption.entry === option,
|
||||
)?.value,
|
||||
)
|
||||
.filter(isDefined),
|
||||
),
|
||||
];
|
||||
|
||||
const fieldValue =
|
||||
matchedOptionValues && matchedOptionValues.length > 0
|
||||
? JSON.stringify(matchedOptionValues)
|
||||
: undefined;
|
||||
|
||||
acc[column.value] = fieldValue;
|
||||
} else {
|
||||
const matchedOption = column.matchedOptions.find(
|
||||
({ entry }) => entry === curr,
|
||||
);
|
||||
acc[column.value] = matchedOption?.value || undefined;
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
case ColumnType.empty:
|
||||
|
||||
Reference in New Issue
Block a user