-
Notifications
You must be signed in to change notification settings - Fork 30
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
Classifier: Refactor ClassifierContainer hooks #2793
Conversation
3df2d43
to
65121a0
Compare
3998f30
to
877bb0a
Compare
18a958c
to
852f74f
Compare
c954986
to
b51ab8c
Compare
b51ab8c
to
ecf8fe6
Compare
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.
PR Review
I tested this refactor PR by making real classifications to the i-fancy-cats staging project, and I made demo classifications to the live FEM project Corresponding with Quakers. Functionality is unchanging 👍
Classifier and ClassifierContainer do not have any test files, which is on our radar as a team, so in an effort to add better tests and documentation to lib-classifier (like your question in #2809), can a spec file be added for each custom hook in this PR? I’m thinking a unit test similar to useStores, or if mocking workflows and stores is overkill, then a README for each custom hook will be super helpful going forward.
packages/lib-classifier/src/components/Classifier/ClassifierContainer.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/components/Classifier/ClassifierContainer.js
Outdated
Show resolved
Hide resolved
@@ -37,6 +37,7 @@ export default function Classifier({ | |||
useEffect(function onURLChange() { | |||
const { workflows } = classifierStore | |||
if (workflowID) { | |||
console.log('starting new subject queue', { workflowID, subjectSetID, subjectID }) |
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.
console.log('starting new subject queue', { workflowID, subjectSetID, subjectID }) | |
// console.log('starting new subject queue', { workflowID, subjectSetID, subjectID }) |
Console logs in this PR are helpful for classifier debugging, but the ones that log data will be noisy if these are committed to master. I'm suggesting commenting them out until they're specifically used for debugging locally.
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.
Console logs are also recorded in Sentry. I've added these so that we can better use Sentry to debug problems on Davy Notebooks and HMS NHS.
I'd prefer to leave them in until we're sure that those projects are working properly.
@@ -51,9 +52,10 @@ export default function Classifier({ | |||
if (workflowSnapshot) { | |||
// pass the subjectSetID prop into the store as part of the new workflow data | |||
workflowSnapshot.subjectSet = subjectSetID | |||
console.log('Refreshing workflow snapshot', workflowSnapshot.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.
console.log('Refreshing workflow snapshot', workflowSnapshot.id) | |
// console.log('Refreshing workflow snapshot', workflowSnapshot.id) |
Testing hooks in isolation isn't recommended. Better to test them in the component that uses them. https://react-hooks-testing-library.com/ Here, that would involve mounting and rendering the classifier, maybe with mocked local storage. |
Makes sense, and in that case can a README be added to the No rush! This is a refactor PR. |
d245960
to
db28fa5
Compare
I've added a short Readme for the hooks. They're mostly wrappers for external libraries, so I've included links to those libraries too. |
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 added a short Readme for the hooks. They're mostly wrappers for external libraries, so I've included links to those libraries too.
Looks good thanks!
- Add a `hooks` directory to the `Classifier` component. Import the `useStore` and `useWorkflowSnapshot` hooks from that directory. - Explicitly declare `SWR` options in the the `useWorkflowSnapshot` hook.
Move the store hydration and initialisation code into a `useHydratedStore` hook.
Move store clean-up into `ClassifierContainer`. `useHydratedStore` hydrates the store but doesn't try to alter it after loading it.
`store.startClassification` allows us to start a new classification automatically, when the subject queue advances, or manually, after loading a workflow from Panoptes.
Co-authored-by: Delilah C. <23665803+goplayoutside3@users.noreply.github.com>
Co-authored-by: Delilah C. <23665803+goplayoutside3@users.noreply.github.com>
9e3235c
to
34d56b5
Compare
hooks
directory to theClassifier
component. Import theuseStore
anduseWorkflowSnapshot
hooks from that directory.SWR
options in theuseWorkflowSnapshot
hook.useHydratedStore
hook, which hydrates the store from session storage whencachePanoptesData
is set. Otherwise, it just returnstrue
.useEffect
hook to clean up the store and set up volatile callbacks for the parent page after hydration has finished.store.startClassification()
action, to replace thesubjects.setActiveSubject(subjects.active?.id)
hack.This PR includes #2792. It shouldn't change anything, just refactor the hooks to make the classifier component easier to read and debug.
Package:
lib-classifier
Review Checklist
General
Components
Apps
yarn panic && yarn bootstrap
ordocker-compose up --build
and app works as expected?Publishing
Post-merging