-
Notifications
You must be signed in to change notification settings - Fork 2
fix: sort credential fields by display_order before rendering #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
emmettownsend
wants to merge
3
commits into
mxenabled:master
from
inrupt:fix/sort-credentials-by-display-order
+76
−6
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
1adbc27
fix: sort credential fields by display_order before rendering
emmettownsend 63bc8da
fix: default missing display_order to Infinity and improve test asser…
emmettownsend 14be0a0
refactor: memoize sorted credentials and improve test coverage
emmettownsend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import React, { | ||
| Fragment, | ||
| useMemo, | ||
| useRef, | ||
| useState, | ||
| useEffect, | ||
|
|
@@ -112,9 +113,13 @@ export const Credentials = React.forwardRef( | |
| const tokens = useTokens() | ||
| const styles = getStyles(tokens, isSmall) | ||
| const getNextDelay = getDelay(0, 100) | ||
| const initialValues = buildInitialValues(credentials) | ||
| const formSchema = buildFormSchema(credentials) | ||
| const loginFieldCount = credentials.length | ||
| const sortedCredentials = useMemo( | ||
| () => [...credentials].sort((a, b) => (a.display_order ?? Infinity) - (b.display_order ?? Infinity)), | ||
| [credentials], | ||
| ) | ||
| const initialValues = buildInitialValues(sortedCredentials) | ||
| const formSchema = buildFormSchema(sortedCredentials) | ||
| const loginFieldCount = sortedCredentials.length | ||
| const showDisconnectOption = | ||
| currentMember && | ||
| currentMember.is_managed_by_user && | ||
|
|
@@ -249,7 +254,7 @@ export const Credentials = React.forwardRef( | |
| const inputRefs = useRef({}) | ||
|
|
||
| useEffect(() => { | ||
| for (const field of credentials) { | ||
| for (const field of sortedCredentials) { | ||
| if (errors[field.field_name]) { | ||
| inputRefs.current[field.field_name]?.focus() | ||
| break | ||
|
|
@@ -258,7 +263,7 @@ export const Credentials = React.forwardRef( | |
| }, [errors]) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above — pre-existing dependency array pattern, not introduced by this change. |
||
|
|
||
| function attemptConnect() { | ||
| const credentialsPayload = credentials.map((credential) => { | ||
| const credentialsPayload = sortedCredentials.map((credential) => { | ||
| return { | ||
| guid: credential.guid, | ||
| value: values[credential.field_name], | ||
|
|
@@ -443,7 +448,7 @@ export const Credentials = React.forwardRef( | |
| onSubmit={(e) => e.preventDefault()} | ||
| style={styles.form} | ||
| > | ||
| {credentials.map((field) => ( | ||
| {sortedCredentials.map((field) => ( | ||
| <SlideDown delay={getNextDelay()} key={field.guid}> | ||
| {field.field_type === CREDENTIAL_FIELD_TYPES.PASSWORD ? ( | ||
| <div style={errors[field.field_name] ? styles.passwordInputError : {}}> | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code had the same pattern —
credentialswas used in this effect without being in the dependency array. This change only swapped the variable name; the dependency array behaviour is pre-existing.