-
Notifications
You must be signed in to change notification settings - Fork 26
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
STCOR-936 - implement App-reordering, user preference management in stripes-core. #1584
base: master
Are you sure you want to change the base?
Conversation
Bigtest Unit Test Results189 tests ±0 184 ✅ ±0 6s ⏱️ ±0s Results for commit 0c6e189. ± Comparison against base commit 2049911. This pull request removes 191 and adds 189 tests. Note that renamed tests count towards both.
This pull request removes 5 skipped tests and adds 5 skipped tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
Jest Unit Test Results 1 files ±0 64 suites +2 1m 34s ⏱️ -2s For more details on these failures, see this check. Results for commit 0c6e189. ± Comparison against base commit 2049911. ♻️ This comment has been updated with latest results. |
src/components/MainNav/MainNav.js
Outdated
this.returnToLogin(); | ||
// this.returnToLogin(); | ||
logout(state.okapi.url, store, queryClient); | ||
} |
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.
In RTR-land where tokens only exist in HTTPOnly cookies, we don't have to worry about this condition because state.okapi.token
will never evaluate to true. IOW, I think the right clean-up here is "remove this entire conditional".
It looks like the bad commit is a9b860dfe591f7e7b236640fc1ceb6d25401b30c
, itself a "clean-up" commit from mega-merge PR #1532. The comment there alludes to fixing up logout, but unfortunately doesn't offer any details about why, specifically, returnToLogin
was removed. If anybody knows this @zburke character we should find him and tell him to write better commit messages.
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.
I've not read every line of this, but it looks good.
}, | ||
{ | ||
"permissionName": "mod-settings.owner.read.stripes-core.prefs.manage", | ||
"displayName": "UI: read the user's own preference for the order of links in the main navigation.", |
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.
Could we say something like "UI: read the user's own preferences, such as the order of links in the main navigation"? We are surely going to want to use this for lots of other things, too, once it's in place.
}, | ||
{ | ||
"permissionName": "mod-settings.owner.write.stripes-core.prefs.manage", | ||
"displayName": "UI: update the user's own preference for the order of links in the main navigation.", |
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.
See previous comment.
@@ -91,7 +91,7 @@ class AppList extends Component { | |||
{ | |||
apps.map(app => { | |||
const isHidden = hiddenItemIds.includes(app.id); | |||
|
|||
// const isHidden = false; |
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.
What's this about?
const id = `clickable-${name}-module`; | ||
|
||
const pathRoot = pathname.split('/')[1]; | ||
const entryRoot = entry.route.split('/')[1]; |
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.
It looks this means each FOLIO UI module has to have a unique top-level path component — e.g. you can't have ui-foobar that uses /foo/bar
and ui-foobaz that uses /foo/baz
. Am I reading that right? If so, is that limitation new, or was it there in the old code?
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.
Good question, @MikeTaylor. It is not a new limitation; old code is identical and hasn't changed in 7+ years. Before that, history is too murky to easily assess, so I don't know if the limitation has always been there but certainly it's been there for a long time.
const { getPreference, setPreference, removePreference } = usePreferences(); | ||
|
||
const { data: userAppList, isLoading, refetch: refetchAppList } = useQuery('UserPrefsAppListing', () => { | ||
return getPreference({ key: APPORDER_PREF_NAME, scope: APPORDER_PREF_SCOPE }); |
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.
Maybe use an expression here rather than a block that does nothing but return the expression?
respJSON = await resp.json(); | ||
if (respJSON.items.length === 1) { | ||
setId(respJSON.items[0].id); | ||
} |
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.
else
... ?
const userId = user.user.id; | ||
|
||
const getPreference = useCallback(async ({ scope, key, callback }) => { | ||
// const res = await localforage.getItem(key, callback); |
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.
What's going on with this commented-out line?
// so we use the `POST` endpoint for saving... 'PUT', and including the id in the path is used for updating | ||
if (!id) { | ||
try { | ||
setId(prefId); |
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.
Would it make more sense to to move this line after the ky.post
, so we only set the ID if the operation was successful?
src/hooks/usePreferences.js
Outdated
try { | ||
return ky.put(`settings/entries/${prefId}`, { json: payload }); | ||
} catch (err) { | ||
console.log(`error updating preference at scope: ${scope}, and key: ${key} for user: ${userId} - ${err.message}`); |
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.
We can move this outside the try
block to avoid duplicating it.
try { | ||
if (id) { | ||
await ky.delete(`settings/entries/${id}`); | ||
setId(null); |
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.
I see we use ky.delete
and then setId
for deletion, as I think we should for creation.
Quality Gate failedFailed conditions |
STCOR-936
This PR Implements 2 things -
mod-settings
.1 is fairly straightforward. A hook -
usePreferences
- that accepts an object of options with the key and scope of a user preference. It will automatically apply the logged in user's id as well as maintain the id of an existing preference in its internal state. As per typical, it try/catches the requests. TODO: Better error handling thanconsole.log
.usePreferences
supplies methodsgetPreference
,setPreference
, anddeletePreference
.getPreference/setPreference
queries the preferences with theuserId
,scope
, andkey
. If the preference is found, it will grab the id and store that in local state to use whensetPreference
is called. If a preference is not found, then theid
remainsnull
and whensetPreference
is called, a new preference is created according tomod-settings
' API.deletePreference
removes the preference and resets the found preference id if there is any.2 involved setting up a context with a Provider -
AppOrderProvider
- that wraps at a high level - outside of the main navigation and around the ui-module container. It access the user preference and provides an ordered list of apps filtered by user permissions (namedapps
). It also provides the persisted preference value - an array containing objects with app information - onlyname
as well as anisNew
field if a platform app does not have a corresponding list order value.The app list -building logic was lifted from
MainNav.js
and<MainNav>
refactored as a functional component, trading out HOC's for hooks. One detail that's subject to further inspection is line 58 where it useslogout
instead of an apparently undefinedreturnToLogin
function.ResizeContainer
andAppListDropdown
were two components that had to be touched as they were forcing alphabetical order of the list - switching fromObject.keys
to using the order of the array of apps/preference.Still Remaining: