-
Notifications
You must be signed in to change notification settings - Fork 0
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
Generalise the contents editor #5
Conversation
db9cc26
to
a3d9ed7
Compare
src/ducks/contents.js
Outdated
@@ -26,13 +26,16 @@ const projectContentsReducer = (state = initialState, action) => { | |||
}; | |||
|
|||
// Action Creators | |||
const fetchProjectContents = (project_id) => { | |||
const fetchProjectContents = (id, type) => { | |||
type = type ? type.split('/')[0] : 'project'; | |||
return (dispatch) => { | |||
dispatch({ | |||
type: FETCH_PROJECT_CONTENTS, |
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.
Action types should also be generalised.
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 point.
I was thinking that this should be a generic loader for any of the resources listed in #6, so that new resource types can be added without having to write a lot of new code.
Maybe we should define a TranslationResource
component (I'm not sure about the name), which is a generic adapter for specific translations, something like the PFE file viewer.
src/ducks/projects.js
Outdated
@@ -32,7 +32,8 @@ const fetchProjects = () => { | |||
type: FETCH_PROJECTS, | |||
}); | |||
const query = { | |||
current_user_roles: ['owner', 'translator'] | |||
current_user_roles: ['owner', 'translator'], | |||
include: ['workflows'] |
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 query fetches all projects, so including all workflows is probably a bad idea.
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.
Can we filter workflows? I can't think of a way involving not fetching all projects.
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'm thinking just don't include them here. They aren't needed until you select a project to work on.
Projects like NfN and Wildcam Gorongosa, with large numbers of workflows, would still be a problem.
children: PropTypes.node, | ||
contents: PropTypes.object, | ||
params: PropTypes.shape({ | ||
project_id: PropTypes.string |
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.
Missing resource_id: PropTypes.string
src/ducks/resource.js
Outdated
title: contents.title, | ||
description: contents.description, | ||
introduction: contents.introduction, | ||
language: 'nz', |
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's fine for testing, but this will have to be a parameter, rather than hardcoded.
26eabbe
to
cc3440f
Compare
src/ducks/resource.js
Outdated
const key = `${type}_id`; | ||
const query = {}; | ||
query[key] = id; | ||
apiClient.type(`${type}_contents`).get(query) |
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.
type
here only works for workflows and projects. Tutorials and field guides will have a different rule for determining resource type.
}; | ||
|
||
// Action Creators | ||
const fetchResource = (id, type) => { |
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 function should also take language as a parameter.
src/ducks/resource.js
Outdated
type: FETCH_RESOURCE, | ||
}); | ||
const key = `${type}_id`; | ||
const query = {}; |
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.
query
should specify the resource language, I think.
b49dfdd
to
f294e03
Compare
Tests failing because yarn won't install. I'm not sure why Travis is installing yarn. |
It'll try to install yarn if there's a yarn.lock file in the root of the repository. Why yarn fails to install on travis, I'm not sure yet since we were running into that with the lab app. I'm thinking of scrapping yarn for npm 5. |
808c8da
to
1733091
Compare
return actions.fetchProjectContents(this.props.params.project_id); | ||
const type = this.props.params.resource_type; | ||
const id = type ? this.props.params.resource_id : this.props.params.project_id; | ||
return actions.fetchResource(id, type); |
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.
Why are we returning a value from componentDidMount
?
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.
Sorry, just some cruft. However, I have experienced problems in triggering actions when return
weren't used...
src/ducks/resource.js
Outdated
description: contents.description, | ||
introduction: contents.introduction, | ||
language: 'nz', | ||
'links.project': contents.links.project, |
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 will need generalising too. Resources aren't necessarily linked to the project eg. Tutorials and WorkflowContents are linked to workflows.
1733091
to
9a56746
Compare
Adds workflow contents, by ID. Lists all workflow strings.
Generalise resource loading and display. Add a bit of a hack to handle ProjectContents and WorkflowContents.
f15422f
to
2303339
Compare
src/components/ProjectDashboard.jsx
Outdated
</ProjectContentsContainer> | ||
<h3>Workflows</h3> | ||
<ul> | ||
{project.workflows.map((workflow) => { |
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 throws if workflows
is undefined
.
src/components/ProjectDashboard.jsx
Outdated
</ul> | ||
<h3>Tutorials</h3> | ||
<ul> | ||
{project.tutorials.map((tutorial) => { |
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 throws if tutorials
is 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.
Should be fixed now.
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.
👍
Default workflows and tutorials to empty arrays. Store them in project state, not the project resource.
}; | ||
apiClient.type('projects').get(query) | ||
.then(([project]) => { | ||
dispatch(fetchWorkflows(project)); |
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 think dispatching multiple actions within a dispatch call isn't recommended. That might lead to unnecessary calls to store.dispatch. There are ways for batching actions I'm reading up about.
In general I think having actions dispatched from components improves understanding of what is going on, instead of having to follow all the nested calls inside the action creators.
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.
Actually, we're using a middleware, whose point is to accommodate dispatching actions with actions. Only the readability concern remains, but no biggie.
case FETCH_RESOURCE: | ||
return Object.assign({}, initialState, { loading: true }); | ||
case FETCH_RESOURCE_SUCCESS: | ||
return Object.assign({}, state, { original: action.payload, loading: 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 is original
supposed to store? Given the name, I was expecting to see in here only the original in english and any available translation under translation
. However I see allI the clones with different language
flags I created in some early tests. I'm a bit confused.
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.
Yeah, my aim is to eventually store the original here, maybe split the translations out into their own array.
At the moment, the API query will bring back everything. We can either update the query so that it only fetches the original resource, or split the response into the original + translations.
translation
, by the way, is the translation that you're currently working on, so a single resource.
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 makes sense. Cheers
Add type validation for URL params. Don't return a value from ComponentDidMount.
c68203c
to
7ef41fb
Compare
No description provided.