Refactor spreadsheet import (#11250)

Mostly renaming objects to avoid conflicts (it was painful because names
were too generic so you could cmd+replace easily)

Also refactoring `useBuildAvailableFieldsForImport`
This commit is contained in:
Félix Malfait
2025-03-28 07:56:51 +01:00
committed by GitHub
parent 9af2628264
commit e9e33c4d29
84 changed files with 960 additions and 916 deletions

View File

@ -1,30 +1,34 @@
import {
ColumnType,
MatchedOptions,
MatchedSelectColumn,
MatchedSelectOptionsColumn,
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
SpreadsheetMatchedSelectColumn,
SpreadsheetMatchedSelectOptionsColumn,
} from '@/spreadsheet-import/types/SpreadsheetColumn';
import { SpreadsheetColumnType } from '@/spreadsheet-import/types/SpreadsheetColumnType';
import { SpreadsheetMatchedOptions } from '@/spreadsheet-import/types/SpreadsheetMatchedOptions';
export const setSubColumn = <T>(
oldColumn: MatchedSelectColumn<T> | MatchedSelectOptionsColumn<T>,
oldColumn:
| SpreadsheetMatchedSelectColumn<T>
| SpreadsheetMatchedSelectOptionsColumn<T>,
entry: string,
value: string,
): MatchedSelectColumn<T> | MatchedSelectOptionsColumn<T> => {
):
| SpreadsheetMatchedSelectColumn<T>
| SpreadsheetMatchedSelectOptionsColumn<T> => {
const options = oldColumn.matchedOptions.map((option) =>
option.entry === entry ? { ...option, value } : option,
);
const allMathced = options.every(({ value }) => !!value);
if (allMathced) {
const allMatched = options.every(({ value }) => !!value);
if (allMatched) {
return {
...oldColumn,
matchedOptions: options as MatchedOptions<T>[],
type: ColumnType.matchedSelectOptions,
matchedOptions: options as SpreadsheetMatchedOptions<T>[],
type: SpreadsheetColumnType.matchedSelectOptions,
};
} else {
return {
...oldColumn,
matchedOptions: options as MatchedOptions<T>[],
type: ColumnType.matchedSelect,
matchedOptions: options as SpreadsheetMatchedOptions<T>[],
type: SpreadsheetColumnType.matchedSelect,
};
}
};