* 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>
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import {
|
|
Column,
|
|
ColumnType,
|
|
MatchColumnsProps,
|
|
} from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
|
import type { Field } from '@/spreadsheet-import/types';
|
|
|
|
import { uniqueEntries } from './uniqueEntries';
|
|
|
|
export const setColumn = <T extends string>(
|
|
oldColumn: Column<T>,
|
|
field?: Field<T>,
|
|
data?: MatchColumnsProps<T>['data'],
|
|
): Column<T> => {
|
|
switch (field?.fieldType.type) {
|
|
case 'select':
|
|
return {
|
|
...oldColumn,
|
|
type: ColumnType.matchedSelect,
|
|
value: field.key,
|
|
matchedOptions: uniqueEntries(data || [], oldColumn.index),
|
|
};
|
|
case 'checkbox':
|
|
return {
|
|
index: oldColumn.index,
|
|
type: ColumnType.matchedCheckbox,
|
|
value: field.key,
|
|
header: oldColumn.header,
|
|
};
|
|
case 'input':
|
|
return {
|
|
index: oldColumn.index,
|
|
type: ColumnType.matched,
|
|
value: field.key,
|
|
header: oldColumn.header,
|
|
};
|
|
default:
|
|
return {
|
|
index: oldColumn.index,
|
|
header: oldColumn.header,
|
|
type: ColumnType.empty,
|
|
};
|
|
}
|
|
};
|