Skip to content

Commit e8a66c7

Browse files
committed
fix(davinci-client): clear stale collector error on successful value update
Stale validation errors persisted in state after a user corrected their input — a subsequent valid dispatch left the previous error message visible. Mirror the pattern already used in pollCollectorValues by resetting collector.error to null on every successful value-assignment path in updateCollectorValues.
1 parent e49dc30 commit e8a66c7

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

packages/davinci-client/src/lib/node.reducer.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,25 @@ describe('The node collector reducer', () => {
473473
);
474474
});
475475

476+
it('should clear error on collector when a valid value is provided after an error', () => {
477+
const state: TextCollector[] = [
478+
{
479+
category: 'SingleValueCollector',
480+
error: 'Value argument must be a string',
481+
type: 'TextCollector',
482+
id: 'username-0',
483+
name: 'username',
484+
input: { key: 'username', value: '', type: 'TEXT' },
485+
output: { key: 'username', label: 'Username', type: 'TEXT', value: '' },
486+
},
487+
];
488+
const action = { type: 'node/update', payload: { id: 'username-0', value: 'validString' } };
489+
const result = nodeCollectorReducer(state, action);
490+
const collector = result.find((c) => c.id === 'username-0') as TextCollector | undefined;
491+
expect(collector?.error).toBeNull();
492+
expect(collector?.input.value).toBe('validString');
493+
});
494+
476495
it('should set error on SingleValueCollector when value is not a string', () => {
477496
const state: TextCollector[] = [
478497
{

packages/davinci-client/src/lib/node.reducer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
248248
collector.error = 'Value argument must be a string';
249249
return;
250250
}
251+
collector.error = null;
251252
collector.input.value = action.payload.value;
252253
return;
253254
}
@@ -257,6 +258,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
257258
collector.error = 'MultiValueCollector does not accept an object';
258259
return;
259260
}
261+
collector.error = null;
260262
if (Array.isArray(action.payload.value)) {
261263
collector.input.value = [...action.payload.value];
262264
} else {
@@ -277,6 +279,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
277279
collector.error = 'No option found matching value to update';
278280
return;
279281
}
282+
collector.error = null;
280283
collector.input.value = {
281284
type: option.type,
282285
id: option.value,
@@ -297,6 +300,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
297300
collector.error = 'No option found matching value to update';
298301
return;
299302
}
303+
collector.error = null;
300304
collector.input.value = option.type;
301305
return;
302306
}
@@ -314,6 +318,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
314318
collector.error = 'Value argument must contain a phoneNumber and countryCode property';
315319
return;
316320
}
321+
collector.error = null;
317322
collector.input.value = action.payload.value;
318323
return;
319324
}
@@ -336,6 +341,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
336341
'Value argument must contain a phoneNumber, countryCode, and extension property';
337342
return;
338343
}
344+
collector.error = null;
339345
collector.input.value = action.payload.value;
340346
return;
341347
}
@@ -353,6 +359,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
353359
collector.error = 'Value argument must contain an attestationValue property';
354360
return;
355361
}
362+
collector.error = null;
356363
collector.input.value = action.payload.value;
357364
return;
358365
}
@@ -370,6 +377,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
370377
collector.error = 'Value argument must contain an assertionValue property';
371378
return;
372379
}
380+
collector.error = null;
373381
collector.input.value = action.payload.value;
374382
return;
375383
}

0 commit comments

Comments
 (0)