-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIOR-1038 Some shortcut keys do not work in the "Orders" app (#1424)
* UIOR-1038 fix 'new order' and 'duplicate order' shortcuts * UIOR-1038 fix toggle handling of 'ongoing order information' accordion * UIOR-1038 fix accordion toggle handling in POLineForm * UIOR-1038 async validation of field-arrays always set Promise as error in form and prevents to close accordion * UIOR-1038 update changelog * add unit test for 'new' shortcut
- Loading branch information
1 parent
f395333
commit c17fa49
Showing
11 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ARRAY_ERROR } from 'final-form'; | ||
import { | ||
cloneDeep, | ||
get, | ||
unset, | ||
} from 'lodash'; | ||
|
||
/* | ||
Final form async validation of field array itself return a Promise instead of resolved value | ||
and set it as "FINAL_FORM/array-error". So form always contain this promise in form's | ||
errors object even if there no actual validation error. | ||
Issue: https://github.com/final-form/react-final-form-arrays/issues/176 | ||
*/ | ||
export const omitFieldArraysAsyncErrors = (formErrors, asyncFieldArrays = []) => { | ||
const cloned = cloneDeep(formErrors); | ||
|
||
asyncFieldArrays.forEach((field) => { | ||
const arrayFieldAsyncError = get(formErrors, `${field}[${ARRAY_ERROR}].then`); | ||
|
||
if (arrayFieldAsyncError && !get(formErrors, field, []).filter(Boolean).length) { | ||
unset(cloned, field); | ||
} | ||
}); | ||
|
||
return cloned; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ARRAY_ERROR } from 'final-form'; | ||
|
||
import { omitFieldArraysAsyncErrors } from './omitFieldArraysAsyncErrors'; | ||
|
||
const ASYNC_FIELD_ARRAY = 'fieldArrayWithAsyncValidation'; | ||
|
||
describe('omitFieldArraysAsyncErrors', () => { | ||
it('should omit field-array from form errors if it contains only async error of array itself', () => { | ||
const fieldArrayErrors = []; | ||
|
||
fieldArrayErrors[ARRAY_ERROR] = Promise.resolve(null); | ||
|
||
const formErrors = { | ||
[ASYNC_FIELD_ARRAY]: fieldArrayErrors, | ||
}; | ||
|
||
const errors = omitFieldArraysAsyncErrors(formErrors, [ASYNC_FIELD_ARRAY]); | ||
|
||
expect(errors).toEqual({}); | ||
}); | ||
|
||
it('should keep field-array in form errors object if it contains sync error of array itself', () => { | ||
const fieldArrayErrors = []; | ||
|
||
fieldArrayErrors[ARRAY_ERROR] = 'Invalid array'; | ||
|
||
const formErrors = { | ||
[ASYNC_FIELD_ARRAY]: fieldArrayErrors, | ||
}; | ||
|
||
const errors = omitFieldArraysAsyncErrors(formErrors, [ASYNC_FIELD_ARRAY]); | ||
|
||
expect(ASYNC_FIELD_ARRAY in errors).toBeTruthy(); | ||
}); | ||
|
||
it('should keep field-array in form errors object if it contains its fields\' errors', () => { | ||
const fieldArrayErrors = ['Test field is invalid']; | ||
|
||
fieldArrayErrors[ARRAY_ERROR] = Promise.resolve(null); | ||
|
||
const formErrors = { | ||
[ASYNC_FIELD_ARRAY]: fieldArrayErrors, | ||
}; | ||
|
||
const errors = omitFieldArraysAsyncErrors(formErrors, [ASYNC_FIELD_ARRAY]); | ||
|
||
expect(ASYNC_FIELD_ARRAY in errors).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters