Skip to content

Commit 4e1a12d

Browse files
committed
Match select values by field option value or label
1 parent d6fa618 commit 4e1a12d

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/steps/MatchColumnsStep/tests/MatchColumnsStep.test.tsx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,20 @@ describe("Match Columns automatic matching", () => {
187187
const OPTION_RESULT_TWO = "Dane"
188188
const OPTION_RESULT_TWO_VALUE = "2"
189189
const OPTION_RESULT_THREE = "Kane"
190-
const OPTION_RESULT_THREE_VALUE = "3"
191190
const data = [
191+
// match by option label
192192
[OPTION_RESULT_ONE, "123", "[email protected]"],
193-
[OPTION_RESULT_TWO, "333", "[email protected]"],
193+
// match by option value
194+
[OPTION_RESULT_TWO_VALUE, "333", "[email protected]"],
195+
// do not match
194196
[OPTION_RESULT_THREE, "534", "[email protected]"],
195197
]
196198
const options = [
197199
{ label: OPTION_RESULT_ONE, value: OPTION_RESULT_ONE_VALUE },
198200
{ label: OPTION_RESULT_TWO, value: OPTION_RESULT_TWO_VALUE },
199-
{ label: OPTION_RESULT_THREE, value: OPTION_RESULT_THREE_VALUE },
200201
]
201202
// finds only names with automatic matching
202-
const result = [
203-
{ name: OPTION_RESULT_ONE_VALUE },
204-
{ name: OPTION_RESULT_TWO_VALUE },
205-
{ name: OPTION_RESULT_THREE_VALUE },
206-
]
203+
const result = [{ name: OPTION_RESULT_ONE_VALUE }, { name: OPTION_RESULT_TWO_VALUE }, { name: undefined }]
207204

208205
const alternativeFields = [
209206
{
@@ -230,7 +227,7 @@ describe("Match Columns automatic matching", () => {
230227
</Providers>,
231228
)
232229

233-
expect(screen.getByText(/0 Unmatched/)).toBeInTheDocument()
230+
expect(screen.getByText(/1 Unmatched/)).toBeInTheDocument()
234231

235232
const nextButton = screen.getByRole("button", {
236233
name: "Next",
@@ -251,16 +248,17 @@ describe("Match Columns automatic matching", () => {
251248
const OPTION_RESULT_TWO = "Dane"
252249
const OPTION_RESULT_TWO_VALUE = "2"
253250
const OPTION_RESULT_THREE = "Kane"
254-
const OPTION_RESULT_THREE_VALUE = "3"
255251
const data = [
252+
// match by option label
256253
[OPTION_RESULT_ONE, "123", "[email protected]"],
257-
[OPTION_RESULT_TWO, "333", "[email protected]"],
254+
// match by option value
255+
[OPTION_RESULT_TWO_VALUE, "333", "[email protected]"],
256+
// do not match
258257
[OPTION_RESULT_THREE, "534", "[email protected]"],
259258
]
260259
const options = [
261260
{ label: OPTION_RESULT_ONE, value: OPTION_RESULT_ONE_VALUE },
262261
{ label: OPTION_RESULT_TWO, value: OPTION_RESULT_TWO_VALUE },
263-
{ label: OPTION_RESULT_THREE, value: OPTION_RESULT_THREE_VALUE },
264262
]
265263
const result = [{ name: undefined }, { name: undefined }, { name: undefined }]
266264

@@ -310,23 +308,20 @@ describe("Match Columns automatic matching", () => {
310308
const OPTION_RESULT_TWO = "Dane"
311309
const OPTION_RESULT_TWO_VALUE = "2"
312310
const OPTION_RESULT_THREE = "Kane"
313-
const OPTION_RESULT_THREE_VALUE = "3"
314311
const data = [
312+
// match by option label
315313
[OPTION_RESULT_ONE, "123", "[email protected]"],
316-
[OPTION_RESULT_TWO, "333", "[email protected]"],
314+
// match by option value
315+
[OPTION_RESULT_TWO_VALUE, "333", "[email protected]"],
316+
// do not match
317317
[OPTION_RESULT_THREE, "534", "[email protected]"],
318318
]
319319
const options = [
320320
{ label: OPTION_RESULT_ONE, value: OPTION_RESULT_ONE_VALUE },
321321
{ label: OPTION_RESULT_TWO, value: OPTION_RESULT_TWO_VALUE },
322-
{ label: OPTION_RESULT_THREE, value: OPTION_RESULT_THREE_VALUE },
323322
]
324323
// finds only names with automatic matching
325-
const result = [
326-
{ name: OPTION_RESULT_ONE_VALUE },
327-
{ name: OPTION_RESULT_TWO_VALUE },
328-
{ name: OPTION_RESULT_THREE_VALUE },
329-
]
324+
const result = [{ name: OPTION_RESULT_ONE_VALUE }, { name: OPTION_RESULT_TWO_VALUE }, { name: undefined }]
330325

331326
const alternativeFields = [
332327
{
@@ -357,7 +352,7 @@ describe("Match Columns automatic matching", () => {
357352
container: document.getElementById(SELECT_DROPDOWN_ID)!,
358353
})
359354

360-
expect(screen.getByText(/0 Unmatched/)).toBeInTheDocument()
355+
expect(screen.getByText(/1 Unmatched/)).toBeInTheDocument()
361356

362357
const nextButton = screen.getByRole("button", {
363358
name: "Next",

src/steps/MatchColumnsStep/utils/setColumn.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export const setColumn = <T extends string>(
1414
const uniqueData = uniqueEntries(data || [], oldColumn.index) as MatchedOptions<T>[]
1515
const matchedOptions = autoMapSelectValues
1616
? uniqueData.map((option) => {
17-
const value = options.find((o) => o.value == option.value || o.label == option.entry)?.value
17+
const value = options.find(
18+
(fieldOption) => fieldOption.value === option.entry || fieldOption.label === option.entry,
19+
)?.value
1820
return value ? ({ ...option, value } as MatchedOptions<T>) : (option as MatchedOptions<T>)
1921
})
2022
: uniqueData

0 commit comments

Comments
 (0)