Skip to content

Commit 12c2c65

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 b4ea748 commit 12c2c65

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
@@ -470,6 +470,25 @@ describe('The node collector reducer', () => {
470470
);
471471
});
472472

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

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
290290
collector.error = 'Value argument must be a string';
291291
return;
292292
}
293+
collector.error = null;
293294
collector.input.value = action.payload.value;
294295
return;
295296
}
@@ -299,6 +300,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
299300
collector.error = 'MultiValueCollector does not accept an object';
300301
return;
301302
}
303+
collector.error = null;
302304
if (Array.isArray(action.payload.value)) {
303305
collector.input.value = [...action.payload.value];
304306
} else {
@@ -319,6 +321,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
319321
collector.error = 'No option found matching value to update';
320322
return;
321323
}
324+
collector.error = null;
322325
collector.input.value = {
323326
type: option.type,
324327
id: option.value,
@@ -339,6 +342,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
339342
collector.error = 'No option found matching value to update';
340343
return;
341344
}
345+
collector.error = null;
342346
collector.input.value = option.type;
343347
return;
344348
}
@@ -356,6 +360,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
356360
collector.error = 'Value argument must contain a phoneNumber and countryCode property';
357361
return;
358362
}
363+
collector.error = null;
359364
collector.input.value = action.payload.value;
360365
return;
361366
}
@@ -378,6 +383,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
378383
'Value argument must contain a phoneNumber, countryCode, and extension property';
379384
return;
380385
}
386+
collector.error = null;
381387
collector.input.value = action.payload.value;
382388
return;
383389
}
@@ -395,6 +401,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
395401
collector.error = 'Value argument must contain an attestationValue property';
396402
return;
397403
}
404+
collector.error = null;
398405
collector.input.value = action.payload.value;
399406
return;
400407
}
@@ -412,6 +419,7 @@ export const nodeCollectorReducer = createReducer(initialCollectorValues, (build
412419
collector.error = 'Value argument must contain an assertionValue property';
413420
return;
414421
}
422+
collector.error = null;
415423
collector.input.value = action.payload.value;
416424
return;
417425
}

0 commit comments

Comments
 (0)