-
Notifications
You must be signed in to change notification settings - Fork 6
Team Results page now gets settings from query parameters #2276
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
Merged
mvolkmann
merged 15 commits into
develop
from
feature-2265-team-directory-query-parameters
Apr 29, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
dd21de9
Team Results page now gets settings from query parameters
mvolkmann 3389007
cleanup for 2265
mvolkmann 4a6b6dd
View Feedback page now gets settings from query parameters
mvolkmann 11d7d29
added query parmeter support in ViewFeedbackPage with new approach
mvolkmann 6fd5d5a
more use of queryParameterSetup
mvolkmann 34b887e
improved query-parameters.js
mvolkmann 8f4c718
more use of queryParameterSetup
mvolkmann 558473f
more use of queryParameterSetup
mvolkmann b35933f
more use of queryParameterSetup
mvolkmann e4f6416
improved query-parameters.js
mvolkmann 78a24a1
renamed queryParameterSetup to useQueryParameters
mvolkmann a4848d6
query-parameters cleanup
mvolkmann e14885c
fixed query-parameters.js to retain other query parameters
mvolkmann d1c30a2
fixed a failing test
mvolkmann fda4639
better test fix
mvolkmann 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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { useEffect } from 'react'; | ||
|
|
||
| /** | ||
| * @typedef {object} QPBoolean | ||
| * @property {string} name | ||
| * @property {boolean} default | ||
| * @property {boolean} value | ||
| * @property {(boolean) => void} setter - takes query parameter value and updates state | ||
| * @property {[(any) => string]} toQP - takes state value and returns query parameter value | ||
| */ | ||
|
|
||
| /** | ||
| * @typedef {object} QPString | ||
| * @property {string} name | ||
| * @property {string} default | ||
| * @property {string} value | ||
| * @property {(string) => void} setter - takes query parameter value and updates state | ||
| * @property {[(any) => string]} toQP - takes state value and returns query parameter value | ||
| */ | ||
|
|
||
| /** | ||
| * @param {(QPBoolean | QPString)[]} qps - query parameters | ||
| */ | ||
| export const useQueryParameters = qps => { | ||
| useEffect(() => { | ||
| const url = new URL(location.href); | ||
| const params = url.searchParams; | ||
| for (const qp of qps) { | ||
| let v = params.get(qp.name); | ||
| if (typeof qp.default === 'boolean') { | ||
| qp.setter(v ? v === 'true' : qp.default); | ||
| } else { | ||
| if (v && Array.isArray(qp.default)) v = v.split(','); | ||
| qp.setter(v || qp.default); | ||
| } | ||
| } | ||
| }, []); | ||
|
|
||
| const dependencies = qps.map(qp => qp.value); | ||
|
|
||
| useEffect(() => { | ||
| const url = new URL(location.href); | ||
| let newUrl = url.origin + url.pathname; | ||
| const params = {}; | ||
|
|
||
| // Add query parameters listed in qps that do not have their default value. | ||
| for (const qp of qps) { | ||
| let { toQP, value } = qp; | ||
| if (toQP) value = toQP(value); | ||
| if (value && !compare(value, qp.default)) params[qp.name] = value; | ||
| } | ||
|
|
||
| // Add query parameters that are not listed in qps. | ||
S78901 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (const [k, v] of url.searchParams) { | ||
| if (!qps.some(qp => qp.name === k)) params[k] = v; | ||
| } | ||
|
|
||
| if (Object.keys(params).length) { | ||
| newUrl += '?' + new URLSearchParams(params).toString(); | ||
| } | ||
| history.replaceState(params, '', newUrl); | ||
| }, dependencies); | ||
| }; | ||
|
|
||
| const compare = (a, b) => stringValue(a) === stringValue(b); | ||
| const stringValue = v => (Array.isArray(v) ? v.sort().join(',') : v); | ||
Oops, something went wrong.
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.
This state is tracked in
TeamResultsnow.