-
Notifications
You must be signed in to change notification settings - Fork 29
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: Move MetaTools into same grid area as subject viewer #4021
Merged
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3fba336
move resize observer from flipbook controls to DefaultLayout
goplayoutside3 6c9ebb6
add SubjectViewerFactory and update DefaultLayout specs
goplayoutside3 8b2cc1f
Merge branch 'master' into viewer-grid-resize-observer
goplayoutside3 2e87741
Merge branch 'master' into viewer-grid-resize-observer
goplayoutside3 5f52654
refactor MetaTools into functional component
goplayoutside3 c8fcf26
Merge branch 'viewer-grid-resize-observer'
goplayoutside3 e372f92
put MetaTools in same grid area as SubjectViewer
goplayoutside3 bd47256
add stories for MetaTools container
goplayoutside3 b45fb2f
refactpr Metadata to a functional component
goplayoutside3 b8f4974
refactor Metadata's component's unit tests
goplayoutside3 c5bee72
remove +tab+ formatter
goplayoutside3 0c9fdc6
remove PR #4005
goplayoutside3 16130da
Merge branch 'master'
goplayoutside3 1b77ed7
add observer to MetaTools
goplayoutside3 38ed474
update MetadataButton spec
goplayoutside3 52b4794
remove story's border
goplayoutside3 71f450d
Merge branch 'master'
goplayoutside3 22274cd
clean up
goplayoutside3 5cb7796
Merge branch 'master' into metatools-refactor
goplayoutside3 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 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 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
1 change: 0 additions & 1 deletion
1
packages/lib-classifier/src/components/Classifier/components/MetaTools/MetaTools.spec.js
This file contains 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
77 changes: 77 additions & 0 deletions
77
packages/lib-classifier/src/components/Classifier/components/MetaTools/MetaTools.stories.js
This file contains 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,77 @@ | ||
import zooTheme from '@zooniverse/grommet-theme' | ||
import { Box, Grommet } from 'grommet' | ||
import { Provider } from 'mobx-react' | ||
import { | ||
DrawingTaskFactory, | ||
SubjectFactory, | ||
UPPFactory, | ||
WorkflowFactory | ||
} from '@test/factories' | ||
import mockStore from '@test/mockStore' | ||
|
||
import MetaTools from './MetaTools' | ||
|
||
export default { | ||
title: 'Meta Tools / MetaToolsContainer', | ||
component: MetaTools, | ||
args: { | ||
dark: false | ||
} | ||
} | ||
|
||
const background = { | ||
dark: 'dark-1', | ||
light: 'light-1' | ||
} | ||
|
||
const mockSubject = SubjectFactory.build({ | ||
locations: [ | ||
{ | ||
'image/jpeg': | ||
'https://panoptes-uploads.zooniverse.org/subject_location/1e54b552-4608-4701-9db9-b8342b81278a.jpeg' | ||
} | ||
], | ||
metadata: { | ||
time: 'Morning', | ||
location: 'United States' | ||
} | ||
}) | ||
|
||
const mockWorkflow = WorkflowFactory.build({ | ||
tasks: { | ||
T0: DrawingTaskFactory.build() | ||
} | ||
}) | ||
|
||
const upp = UPPFactory.build() | ||
|
||
const store = mockStore({ | ||
subject: mockSubject, | ||
workflow: mockWorkflow | ||
}) | ||
|
||
store.userProjectPreferences.setUPP(upp) | ||
|
||
export const Default = ({ dark }) => { | ||
const themeMode = dark ? 'dark' : 'light' | ||
return ( | ||
<Grommet background={background} theme={zooTheme} themeMode={themeMode}> | ||
<Provider classifierStore={store}> | ||
<MetaTools /> | ||
</Provider> | ||
</Grommet> | ||
) | ||
} | ||
|
||
export const SmallSubjectViewer = ({ dark }) => { | ||
const themeMode = dark ? 'dark' : 'light' | ||
return ( | ||
<Grommet background={background} theme={zooTheme} themeMode={themeMode}> | ||
<Provider classifierStore={store}> | ||
<Box width='300px' style={{ border: 'solid 1px red' }}> | ||
mcbouslog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<MetaTools /> | ||
</Box> | ||
</Provider> | ||
</Grommet> | ||
) | ||
} |
This file contains 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
53 changes: 21 additions & 32 deletions
53
...classifier/src/components/Classifier/components/MetaTools/components/Metadata/Metadata.js
This file contains 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,45 +1,34 @@ | ||
import { Component } from 'react'; | ||
import { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import MetadataButton from './components/MetadataButton' | ||
import { MetadataModal } from './components/MetadataModal' | ||
|
||
export default class Metadata extends Component { | ||
constructor () { | ||
super() | ||
const Metadata = ({ | ||
isThereMetadata = false, | ||
metadata = {} | ||
}) => { | ||
const [showMetadataModal, setShowMetadataModal] = useState(false) | ||
|
||
this.state = { | ||
showMetadataModal: false | ||
} | ||
|
||
this.toggleMetadataModal = this.toggleMetadataModal.bind(this) | ||
} | ||
|
||
toggleMetadataModal () { | ||
this.setState((prevState) => { return { showMetadataModal: !prevState.showMetadataModal } }) | ||
const toggleMetadataModal = () => { | ||
setShowMetadataModal(!showMetadataModal) | ||
} | ||
|
||
render () { | ||
const { isThereMetadata, metadata } = this.props | ||
return ( | ||
<> | ||
<MetadataButton disabled={!isThereMetadata} onClick={this.toggleMetadataModal} /> | ||
{isThereMetadata && | ||
<MetadataModal | ||
active={this.state.showMetadataModal} | ||
closeFn={this.toggleMetadataModal} | ||
metadata={metadata} | ||
/>} | ||
</> | ||
) | ||
} | ||
} | ||
|
||
Metadata.defaultProps = { | ||
isThereMetadata: false, | ||
metadata: {} | ||
return ( | ||
<> | ||
<MetadataButton disabled={!isThereMetadata} onClick={toggleMetadataModal} /> | ||
{isThereMetadata && | ||
<MetadataModal | ||
active={showMetadataModal} | ||
closeFn={toggleMetadataModal} | ||
metadata={metadata} | ||
/>} | ||
</> | ||
) | ||
} | ||
|
||
Metadata.propTypes = { | ||
isThereMetadata: PropTypes.bool, | ||
metadata: PropTypes.object | ||
} | ||
|
||
export default Metadata |
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.
When I run locally, signed in, and load https://local.zooniverse.org:3000/projects/brooke/i-fancy-cats/classify/workflow/693 or https://local.zooniverse.org:3000/projects/pmlogan/poets-and-lovers/classify/workflow/21362/subject-set/104809?env=production the Metadata, FavouritesButton, and CollectionsButton are unexpectedly disabled. Console logging the subject from MetaTools returns
null
and the component doesn't appear to rerender once the subject (and related isThereMetadata) is defined.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.
Oh I think the mobx observer should wrap the MetaTools export.
export default withResponsiveContext(observer(MetaTools))
with related mobx observer import.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.
You're right! I think adding
observer
restored some of the expected functionality, but I also noticed that you can visit i-fancy-cats on frontend.preview, sign-in to enable FavouritesButton and CollectionsButton, but then upon sign-out theupp
from the store still contains user data, and the buttons are all still enabled. I think this is a bug of the UserProjectPreferences store so I'll do a quick search for an already existing Github Issue or open a new one.