-
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
Remove @inject from subject viewers #2719
Conversation
bf7ea84
to
d86303d
Compare
export function SubjectGroupViewerContainer({ | ||
addAnnotation, | ||
annotation, | ||
cellWidth, | ||
cellHeight, | ||
cellStyle, | ||
gridColumns, | ||
gridRows, | ||
gridMaxWidth, | ||
gridMaxHeight, | ||
ImageObject = window.Image, | ||
interactionMode = 'annotate', | ||
isCurrentTaskValidForAnnotation, | ||
loadingState = asyncStates.initialized, | ||
onError = () => true, | ||
onKeyDown = () => true, | ||
onReady = () => true, | ||
setOnPan = () => true, | ||
setOnZoom = () => true, | ||
subject = undefined | ||
}) { |
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 subject group viewer has a lot of props!
9473cc7
to
64079f2
Compare
let nockScope | ||
let wrapper | ||
before(function () { | ||
sinon.stub(console, 'error') | ||
cdmSpy = sinon.spy(BarChartViewerContainer.prototype, 'componentDidMount') | ||
onErrorSpy = sinon.spy() | ||
nockScope = nock('http://localhost:8080') |
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 the project app tests, we mock the Panoptes API with nock. Maybe that would be better for the subject viewer tests too?
let wrapper | ||
|
||
before(function () { | ||
cdmSpy = sinon.spy(BarChartViewerContainer.prototype, 'componentDidMount') | ||
cduSpy = sinon.spy(BarChartViewerContainer.prototype, 'componentDidUpdate') | ||
nockScope = nock('http://localhost:8080') |
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.
Same comment about mocking panoptes-staging.zooniverse.org
or panoptes.zooniverse.org
here.
...lassifier/components/SubjectViewer/components/BarChartViewer/BarChartViewerContainer.spec.js
Outdated
Show resolved
Hide resolved
...lassifier/components/SubjectViewer/components/BarChartViewer/BarChartViewerContainer.spec.js
Outdated
Show resolved
Hide resolved
import { zip } from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React, { Component } from 'react' | ||
import request from 'superagent' |
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.
Goodbye, superagent
!
I was going to ask if we shouldn't also remove this from package.json, then I realised that DataImageViwer(?), SingleTextViewer(?), ScatterPlotViewer, and VariableStarViewer still uses the dependency, dangit. I didn't even realise those first two viewers existed.
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.
SingleTextViewer
inspired me to write this PR, when I saw that it was still using outdated code from when we first started the monorepo.
d58a917
to
6eaa055
Compare
@@ -0,0 +1,17 @@ | |||
# useJSONData | |||
|
|||
A custom hook which loads JSON data for a Panoptes subject. |
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.
[minor] While this is true, the description is missing one important detail: useJSONData
loads JSON data for a Subject, and assumes that Subject that has exactly one JSON(-ish) URL data.
Specifically:
- A text file "technically" counts as a JSON URL (hence, JSON-ish ) for this function, because the Panoptes CLI has (had?) issues differentiating JSON/TXT MIME types.
- If a Subject has multiple JSON(-ish) URLs, only the first is pulled by useJSONData()
This doesn't matter in current (2018 to 2022) LightCurveViewer (or BarChartViewer, I guess) scenarios, since project owners who use these Viewers know the precise Subject format required. However, I can imagine an edge case where useJSONData doesn't work as described, e.g. when we have a Subject that looks like...
subjectWithTextAndJSON.locations = {
'text/plain': 'actual-boring-plain-text.txt',
'application/json': 'json-object-for-data-viewer.json'
}
// In this case, the function attempts to load the plain text as JSON, fails at response.json(), and then skips the actual JSON object file.
I'm marking this as a minor thing right now (⭐ I think editing the README text to include the caveats above should suffice), because if a future theoretical SuperDataViewer needs to use this function to get a Subject with 10 JSON files and a dozen TXT files, we can adjust the code accordingly when it's less theoretical.
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.
Really good point, but I think this can wait until we have real examples of subjects, rather than try to second guess what they might look like now.
Running manual tests now for SubjectGroupViewer and LightCurveViewer, brb |
6d7f5f2
to
93e8697
Compare
Quick ReviewI've encountered a problem with the LightCurveViewer, but I'm not sure what's the cause. I seem to be able to replicate it consistently.
Update: Solved fem-pr2719-20220211-1646-issue-1-v2.mov(EDIT: changed to a cleaner video example.) In the video above, I'm zooming in (on a time span between Day 18 and 19), but when I try to make an annotation, the zoom takes me back to the default zoom (the time span of Day 0 to 30) Testing Setup:
Testing steps:
Notes:
Update: Solved
|
Isn't move mode controlled by a prop? Changing a component prop would certainly trigger a render, although I'm not sure why it would reset zoom. |
@shaunanoordin this code generates a new |
Ah, here we go! I see a potential lead.
I'm checking that !sameSubjcet condition now |
Ha! OK, looks like we've come to the same conclusion 👍 Should be an easy fix, we can just pass in the Subject ID to the LCV and use that to trigger |
@shaunanoordin already done! See the latest commit. |
I see your changes, Jim! 👍 I'll run tests now, brb! |
38d6cf1
to
fc53912
Compare
Quick Review (Update)LightCurveViewer is looking good! 👍
(Cripes, I need to turn those 👆 into actual component tests) |
Quick Review (Update)OK, SubjectGroupViewer (Grid Tool) now! Issue 2: zoom and pan (keyboard only) don't work on the Subject Group Viewer The problem:
Analysis:
Test URL: https://local.zooniverse.org:8080/?env=production&project=zookeeper/galaxy-zoo-weird-and-wonderful&demo=true Tested on/with localhost, macOS, Chrome 98, lib-classifier. I'll do a quick check on the code to see what's up, but I may need to follow up the debug on Monday Additional NotesFull functionality checklist for Subject Group Viewer:
|
Yup, I can see that for
...keep resetting to their default values for some reason. I haven't been able to trace why, unfortunately. This is now a Monday problem! |
I think this is what’s happening: |
Remove `@inject` from `BarChartViewer`, `LightCurveViewer` and `SubjectGroupViewer`. Convert each from a class to a functional component with hooks.
Try to test rendered output, either `onError` or `onReady`.
Move common data fetching code into a custom hook for JSON data subjects.
Pass `subjectID` so that we can test whether the subject has changed.
Use callbacks to update state from previous state.
fae9e2f
to
82a7af5
Compare
@shaunanoordin I've fixed those problems by using callbacks when state is changing continuously. |
Oh, that's new to me! I've never seen Thanks Jim! I'll wrap up testing later tonight |
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
Package: lib-classifier
This PR is primarily a refactor/code cleanup for the following Subject Viewer: BarChartViewer
, LightCurveViewer
, and SubjectGroupViewer
(aka Grid Tool)
- The container components have been rewritten as functional component.
- Notable code changes:
- State-changing hooks that increment existing state values use this format:
setValue(_val => _val + 1)
and not this:setValue(val + 1)
- LightCurveViewer now checks for Subject IDs to determine if it's looking at the same Subject.
- State-changing hooks that increment existing state values use this format:
Code changes look good, and testing for both LightCurveViewer and Grid Tool look great. I can't seem to find a live project that uses BarChartViewer, so I have to rely on Storybook for that.
Testing
Tested on localhost with various projects, with macOS + Chrome.
Testing for LightCurveViewer
- Test URL: https://local.zooniverse.org:8080/?env=production&project=nora-dot-eisner/planet-hunters-tess&demo=true (TESS Planet Hunters)
- ✅ Full functionality checklist noted in a previous comment
Testing for SubjectGroupViewer
- Test URL: https://local.zooniverse.org:8080/?env=production&project=zookeeper/galaxy-zoo-weird-and-wonderful&demo=true (Galaxy Zoo Weird & Wonderful)
- ✅ Full functionality checklist noted in a previous comment
Testing for BarChartViewer
- Tested on Storybook
- ✅ Functionality checklist:
- I'm able view the Subject displayed as a bar chart
- I'm able to hover my mouse across different bars to see their numerical values.
- I'm able to tab-navigate across different bars (and see their numerical values when I have focus)
Status
LGTM 👍
Remove
@inject
fromBarChartViewer
,LightCurveViewer
andSubjectGroupViewer
. Convert each from a class to a functional component with hooks. I've added auseJSONData
hook to load JSON data for BCV and LCV subjects.The enzyme tests were written to test implementation details, like internal class state or lifecycle methods. I've rewritten them to test the rendered subject viewer wrapper, and its props, either
onError
oronReady
.Test projects:
Package:
lib-classifier
Towards #2712.
Review Checklist
General
Components
Apps
yarn panic && yarn bootstrap
ordocker-compose up --build
and app works as expected?Publishing
Post-merging