Skip to content
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

Merged
merged 10 commits into from
Jun 22, 2017
Merged

Generalise the contents editor #5

merged 10 commits into from
Jun 22, 2017

Conversation

eatyourgreens
Copy link
Contributor

No description provided.

@eatyourgreens eatyourgreens force-pushed the general-editor branch 2 times, most recently from db9cc26 to a3d9ed7 Compare May 31, 2017 15:18
@@ -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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -32,7 +32,8 @@ const fetchProjects = () => {
type: FETCH_PROJECTS,
});
const query = {
current_user_roles: ['owner', 'translator']
current_user_roles: ['owner', 'translator'],
include: ['workflows']
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

title: contents.title,
description: contents.description,
introduction: contents.introduction,
language: 'nz',
Copy link
Contributor

@simoneduca simoneduca Jun 6, 2017

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.

const key = `${type}_id`;
const query = {};
query[key] = id;
apiClient.type(`${type}_contents`).get(query)
Copy link
Contributor Author

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) => {
Copy link
Contributor Author

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.

type: FETCH_RESOURCE,
});
const key = `${type}_id`;
const query = {};
Copy link
Contributor Author

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.

@eatyourgreens eatyourgreens force-pushed the general-editor branch 2 times, most recently from b49dfdd to f294e03 Compare June 13, 2017 14:50
@eatyourgreens
Copy link
Contributor Author

Tests failing because yarn won't install. I'm not sure why Travis is installing yarn.

@eatyourgreens eatyourgreens changed the title [WIP] Generalise the contents editor Generalise the contents editor Jun 13, 2017
@srallen
Copy link
Contributor

srallen commented Jun 13, 2017

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.

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);
Copy link
Contributor Author

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?

Copy link
Contributor

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...

@eatyourgreens eatyourgreens mentioned this pull request Jun 15, 2017
18 tasks
description: contents.description,
introduction: contents.introduction,
language: 'nz',
'links.project': contents.links.project,
Copy link
Contributor Author

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.

</ProjectContentsContainer>
<h3>Workflows</h3>
<ul>
{project.workflows.map((workflow) => {
Copy link
Contributor

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.

</ul>
<h3>Tutorials</h3>
<ul>
{project.tutorials.map((tutorial) => {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now.

Copy link
Contributor

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));
Copy link
Contributor

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.

Copy link
Contributor

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 });
Copy link
Contributor

@simoneduca simoneduca Jun 21, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.
@eatyourgreens eatyourgreens merged commit c160b51 into master Jun 22, 2017
@eatyourgreens eatyourgreens deleted the general-editor branch June 22, 2017 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants