feat: wip import csv [part 1] (#1033)
* feat: wip import csv * feat: start implementing twenty UI * feat: new radio button component * feat: use new radio button component and fix scroll issue * fix: max height modal * feat: wip try to customize react-data-grid to match design * feat: wip match columns * feat: wip match column selection * feat: match column * feat: clean heading component & try to fix scroll in last step * feat: validation step * fix: small cleaning and remove unused component * feat: clean folder architecture * feat: remove translations * feat: remove chackra theme * feat: remove unused libraries * feat: use option button to open spreadsheet & fix stories * Fix lint and fix imports --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,67 @@
|
||||
import {
|
||||
Columns,
|
||||
ColumnType,
|
||||
} from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
||||
import type { Data, Fields, RawData } from '@/spreadsheet-import/types';
|
||||
|
||||
import { normalizeCheckboxValue } from './normalizeCheckboxValue';
|
||||
|
||||
export const normalizeTableData = <T extends string>(
|
||||
columns: Columns<T>,
|
||||
data: RawData[],
|
||||
fields: Fields<T>,
|
||||
) =>
|
||||
data.map((row) =>
|
||||
columns.reduce((acc, column, index) => {
|
||||
const curr = row[index];
|
||||
switch (column.type) {
|
||||
case ColumnType.matchedCheckbox: {
|
||||
const field = fields.find((field) => field.key === column.value);
|
||||
|
||||
if (!field) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
if (
|
||||
'booleanMatches' in field.fieldType &&
|
||||
Object.keys(field.fieldType).length
|
||||
) {
|
||||
const booleanMatchKey = Object.keys(
|
||||
field.fieldType.booleanMatches || [],
|
||||
).find((key) => key.toLowerCase() === curr?.toLowerCase());
|
||||
|
||||
if (!booleanMatchKey) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
const booleanMatch =
|
||||
field.fieldType.booleanMatches?.[booleanMatchKey];
|
||||
acc[column.value] = booleanMatchKey
|
||||
? booleanMatch
|
||||
: normalizeCheckboxValue(curr);
|
||||
} else {
|
||||
acc[column.value] = normalizeCheckboxValue(curr);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
case ColumnType.matched: {
|
||||
acc[column.value] = curr === '' ? undefined : curr;
|
||||
return acc;
|
||||
}
|
||||
case ColumnType.matchedSelect:
|
||||
case ColumnType.matchedSelectOptions: {
|
||||
const matchedOption = column.matchedOptions.find(
|
||||
({ entry }) => entry === curr,
|
||||
);
|
||||
acc[column.value] = matchedOption?.value || undefined;
|
||||
return acc;
|
||||
}
|
||||
case ColumnType.empty:
|
||||
case ColumnType.ignored: {
|
||||
return acc;
|
||||
}
|
||||
default:
|
||||
return acc;
|
||||
}
|
||||
}, {} as Data<T>),
|
||||
);
|
||||
Reference in New Issue
Block a user