-
Notifications
You must be signed in to change notification settings - Fork 79
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
Allow the Editor to fetch file details if the parent doesn't pass… #1225
Allow the Editor to fetch file details if the parent doesn't pass… #1225
Conversation
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 use some initial feedback before I get too far down this rabbit hole.
This thing mostly works, but needs a bit of cleaning
client/src/boot/registerQueries.js
Outdated
@@ -11,6 +12,7 @@ const registerQueries = () => { | |||
Injector.query.registerFragment('FileInterfaceFields', fileInterface); | |||
Injector.query.registerFragment('FileFields', file); | |||
Injector.query.register('ReadFilesQuery', isLegacy ? readFilesQueryLegacy : readFilesQuery); | |||
Injector.query.register('ReadOneFileQuery', isLegacy ? readFilesQueryLegacy : readOneFileQuery); |
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.
Just have the GraphQL 4 version working for now ... need to do the GraphQL v3 equivalent as well.
if (props.file) { | ||
return <Component {...props} />; | ||
} else { | ||
const newProps = {...props, fileId: props.targetId}; |
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 file is NOT provided by the parent, we need to fire a GraphQL request to retrieve a single file as defined by props.targetId
.
function magic(Component) { | ||
return (props) => { | ||
if (props.file) { | ||
return <Component {...props} />; |
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 file
is provided by the parent, we do nothing.
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.
There's a scenario where AssetAdmin is not done loading the first page of file results, so it can't pass the file
to the Editor.
When it's done, it provides the file
, which causes the Editor to reload. I'm thinking either:
- AssetAdmin communicates us its loading state and we just wait until it's done fetching its initial list before we start loading the editor or,
- We bail on having AssetAdmin passing us the file info and always rely on our own GraphQL request all the time.
I'm leaning towards the second options. That would increase our number of request slightly, but it reduces the complexity of the component and the tie-in with AssetAdmin.
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.
Had a chat with @emteknetnz. We decided to break the link between AssetAdmin and Editor and always fire a GraphQL request to check if targetID is a folder or a file.
import { hasFilters } from 'components/Search/Search'; | ||
import { graphqlTemplates } from 'lib/Injector'; | ||
|
||
const apolloConfig = { |
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 file mostly copies readFilesQuery
, but removes all the fluff.
We're still using the same graphQL endpoint to retrieve our single file. Maybe we should create an actual readOneFile query server side. Not sure if that's advisable.
…tor works even when viewing a file not on the current page
79e211a
to
b7061ce
Compare
@@ -323,12 +324,11 @@ class Editor extends Component { | |||
Editor.propTypes = { | |||
file: fileShape, | |||
className: PropTypes.string, | |||
targetId: PropTypes.number.isRequired, | |||
fileId: PropTypes.number.isRequired, |
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 renamed this to fileId
. This avoids us having to do gymnastic to change the prop from targetId
to fileID
when we pass it to the graphQL query and it just makes more sense since the target will always be a file ID any way.
}; | ||
}, | ||
props({ data: { error, readFiles, loading } }) { | ||
const file = (readFiles && readFiles.nodes[0]) ? readFiles.nodes[0] : 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.
That's the only difference between v3.5 and 4. In 4, results are on the top level of readFiles
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
Ready for review.
A couple edge cases to consider:
Parent issue