Skip to content

Commit 8eacb23

Browse files
authored
Merge pull request #149 from Yo1L/patch-2
Auto Select values (Column with select fields)
2 parents a192098 + 07c1558 commit 8eacb23

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/steps/MatchColumnsStep/utils/setColumn.ts

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

0 commit comments

Comments
 (0)