Skip to content

Commit d642692

Browse files
authored
Auto Select values (Column with select fields)
Simple solution to select the right value for select and tick the column header if all values matched :)
1 parent f4625df commit d642692

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/steps/MatchColumnsStep/utils/setColumn.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ export const setColumn = <T extends string>(
99
): Column<T> => {
1010
switch (field?.fieldType.type) {
1111
case "select":
12+
const matchedOptions = uniqueEntries(data || [], oldColumn.index)?.map(option => {
13+
const value = options.find(o => o.value == option.value || o.label == option.entry)?.value
14+
return value ? {...option, value} as MatchedOptions<T> : option as MatchedOptions<T>
15+
})
16+
const allMatched = matchedOptions.filter(o => o.value).length == options.length
17+
1218
return {
1319
...oldColumn,
14-
type: ColumnType.matchedSelect,
20+
type: allMatched ? ColumnType.matchedSelectOptions : ColumnType.matchedSelect,
1521
value: field.key,
16-
matchedOptions: uniqueEntries(data || [], oldColumn.index),
22+
matchedOptions
1723
}
1824
case "checkbox":
1925
return { index: oldColumn.index, type: ColumnType.matchedCheckbox, value: field.key, header: oldColumn.header }

0 commit comments

Comments
 (0)