-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
002de34
Extract ProjectContents from editor
eatyourgreens f17ca33
Link up workflow contents
eatyourgreens 365665d
Add actions for generic Panoptes resources
eatyourgreens ed87a3e
Remove workflows from project list
eatyourgreens 4b15a09
Add a rough project dashboard
eatyourgreens 7b57687
Load workflows with the project
eatyourgreens dfb081d
Add tutorials as generic resources.
eatyourgreens 2303339
Add an action to create new translations
eatyourgreens d04baab
Set appropriate defaults for workflows and tutorials
eatyourgreens 7ef41fb
Fix some linter warnings
eatyourgreens 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import fixIt from 'react-fix-it'; | ||
import { Link } from 'react-router'; | ||
import ProjectContentsContainer from '../containers/ProjectContentsContainer'; | ||
import ProjectContents from './ProjectContents'; | ||
|
||
const propTypes = { | ||
project: PropTypes.object.isRequired, | ||
tutorials: PropTypes.array.isRequired, | ||
workflows: PropTypes.array.isRequired, | ||
}; | ||
|
||
function ProjectDashboard(props) { | ||
const { project } = props; | ||
return ( | ||
<div> | ||
<ProjectContentsContainer {...props}> | ||
<ProjectContents /> | ||
</ProjectContentsContainer> | ||
<h3>Workflows</h3> | ||
<ul> | ||
{props.workflows.map((workflow) => { | ||
return ( | ||
<li key={workflow.id}> | ||
<Link to={`/project/${project.id}/workflows/${workflow.id}`}>{workflow.display_name}</Link> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
<h3>Tutorials</h3> | ||
<ul> | ||
{props.tutorials.map((tutorial) => { | ||
return ( | ||
<li key={tutorial.id}> | ||
<Link to={`/project/${project.id}/tutorials/${tutorial.id}`}>{tutorial.id}: {tutorial.display_name}</Link> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
|
||
ProjectDashboard.propTypes = propTypes; | ||
|
||
ProjectDashboard.defaultProps = { | ||
project: { | ||
tutorials: [], | ||
workflows: [] | ||
} | ||
}; | ||
|
||
export default fixIt(ProjectDashboard); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import fixIt, { options } from 'react-fix-it'; | ||
import Tutorial from './Tutorial'; | ||
import WorkflowContents from './WorkflowContents'; | ||
|
||
const resources = { | ||
tutorials: Tutorial, | ||
workflows: WorkflowContents | ||
}; | ||
|
||
const propTypes = { | ||
contents: PropTypes.object.isRequired, | ||
params: PropTypes.shape({ | ||
resource_type: PropTypes.string | ||
}) | ||
}; | ||
|
||
options.log = (test) => { | ||
console.warn(test); | ||
}; | ||
|
||
function Resource(props) { | ||
const { contents } = props; | ||
const ResourceViewer = resources[props.params.resource_type]; | ||
return (<ResourceViewer contents={contents} />); | ||
} | ||
|
||
Resource.propTypes = propTypes; | ||
export default fixIt(Resource); |
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,29 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import fixIt, { options } from 'react-fix-it'; | ||
|
||
const propTypes = { | ||
contents: PropTypes.object.isRequired, | ||
}; | ||
|
||
options.log = (test) => { | ||
console.warn(test); | ||
}; | ||
|
||
function Tutorial(props) { | ||
const { contents } = props; | ||
const tutorial = contents.original.length ? contents.original[0] : { steps: [] }; | ||
const steps = []; | ||
tutorial.steps && tutorial.steps.map((step, key) => { | ||
steps.push(<p key={key}><b>{key}</b> {step.content}</p>); | ||
}); | ||
return ( | ||
<div> | ||
<h2>Tutorial</h2> | ||
{steps} | ||
</div> | ||
); | ||
} | ||
|
||
Tutorial.propTypes = propTypes; | ||
export default fixIt(Tutorial); |
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,33 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import fixIt, { options } from 'react-fix-it'; | ||
|
||
const propTypes = { | ||
contents: PropTypes.object.isRequired, | ||
}; | ||
|
||
options.log = (test) => { | ||
console.warn(test); | ||
}; | ||
|
||
class WorkflowContents extends Component { | ||
|
||
render() { | ||
const { contents } = this.props; | ||
const workflow_contents = contents.original.length ? contents.original[0] : {strings: []}; | ||
console.log(workflow_contents) | ||
const strings = []; | ||
for (const key in workflow_contents.strings) { | ||
strings.push(<p key={key}><b>{key}</b> {workflow_contents.strings[key]}</p>); | ||
} | ||
return ( | ||
<div> | ||
<h2>Workflow Contents</h2> | ||
{strings} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
WorkflowContents.propTypes = propTypes; | ||
export default fixIt(WorkflowContents); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import * as projectActions from '../ducks/project'; | ||
|
||
const propTypes = { | ||
actions: PropTypes.object.isRequired, | ||
children: PropTypes.node, | ||
project: PropTypes.shape({ | ||
data: PropTypes.object, | ||
tutorials: PropTypes.array, | ||
workflows: PropTypes.array | ||
}), | ||
params: PropTypes.shape({ | ||
project_id: PropTypes.string | ||
}) | ||
}; | ||
|
||
class ProjectDashboardContainer extends Component { | ||
|
||
componentDidMount() { | ||
const { actions } = this.props; | ||
actions.fetchProject(this.props.params.project_id); | ||
} | ||
|
||
render() { | ||
const project = this.props.project.data; | ||
const { workflows, tutorials } = this.props.project; | ||
return ( | ||
<div> | ||
<h2>Project Dashboard</h2> | ||
{React.cloneElement(this.props.children, { project, workflows, tutorials })} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
project: state.project | ||
}); | ||
const mapDispatchToProps = (dispatch) => ({ | ||
actions: bindActionCreators(projectActions, dispatch), | ||
}); | ||
|
||
ProjectDashboardContainer.propTypes = propTypes; | ||
ProjectDashboardContainer.defaultProps = { | ||
children: null, | ||
project: { | ||
data: null, | ||
tutorials: [], | ||
workflows: [] | ||
} | ||
}; | ||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
)(ProjectDashboardContainer); |
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,102 @@ | ||
import apiClient from 'panoptes-client/lib/api-client'; | ||
|
||
// Action Types | ||
export const FETCH_PROJECT = 'FETCH_PROJECT'; | ||
export const FETCH_PROJECT_SUCCESS = 'FETCH_PROJECT_SUCCESS'; | ||
export const FETCH_PROJECT_ERROR = 'FETCH_PROJECT_ERROR'; | ||
export const FETCH_WORKFLOWS = 'FETCH_WORKFLOWS'; | ||
export const FETCH_WORKFLOWS_SUCCESS = 'FETCH_WORKFLOWS_SUCCESS'; | ||
export const FETCH_WORKFLOWS_ERROR = 'FETCH_WORKFLOWS_ERROR'; | ||
export const FETCH_TUTORIALS = 'FETCH_TUTORIALS'; | ||
export const FETCH_TUTORIALS_SUCCESS = 'FETCH_TUTORIALS_SUCCESS'; | ||
export const FETCH_TUTORIALS_ERROR = 'FETCH_TUTORIALS_ERROR'; | ||
|
||
// Reducer | ||
const initialState = { | ||
data: {}, | ||
tutorials: [], | ||
workflows: [], | ||
error: false, | ||
loading: false, | ||
}; | ||
|
||
const projectReducer = (state = initialState, action) => { | ||
switch (action.type) { | ||
case FETCH_PROJECT: | ||
return Object.assign({}, initialState, { loading: true }); | ||
case FETCH_PROJECT_SUCCESS: | ||
return Object.assign({}, state, { data: action.payload, loading: false }); | ||
case FETCH_PROJECT_ERROR: | ||
return Object.assign({}, state, { error: action.payload, loading: false }); | ||
case FETCH_WORKFLOWS: | ||
return Object.assign({}, state, { loading: true }); | ||
case FETCH_WORKFLOWS_SUCCESS: | ||
return Object.assign({}, state, { workflows: action.payload, loading: false }); | ||
case FETCH_TUTORIALS: | ||
return Object.assign({}, state, { loading: true }); | ||
case FETCH_TUTORIALS_SUCCESS: | ||
return Object.assign({}, state, { tutorials: action.payload, loading: false }); | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
// Action Creators | ||
const fetchProject = (id) => { | ||
return (dispatch) => { | ||
dispatch({ | ||
type: FETCH_PROJECT, | ||
}); | ||
const query = { | ||
id, | ||
current_user_roles: ['owner', 'translator'], | ||
include: ['workflows'] | ||
}; | ||
apiClient.type('projects').get(query) | ||
.then(([project]) => { | ||
dispatch(fetchWorkflows(project)); | ||
dispatch(fetchTutorials(project)); | ||
dispatch({ | ||
type: FETCH_PROJECT_SUCCESS, | ||
payload: project, | ||
}); | ||
}); | ||
}; | ||
}; | ||
|
||
function fetchWorkflows(project) { | ||
return (dispatch) => { | ||
dispatch({ | ||
type: FETCH_WORKFLOWS, | ||
}); | ||
apiClient.type('workflows').get(project.links.workflows) | ||
.then((workflows) => { | ||
dispatch({ | ||
type: FETCH_WORKFLOWS_SUCCESS, | ||
payload: workflows, | ||
}); | ||
}); | ||
}; | ||
} | ||
|
||
function fetchTutorials(project) { | ||
return (dispatch) => { | ||
dispatch({ | ||
type: FETCH_TUTORIALS, | ||
}); | ||
apiClient.type('tutorials').get({ project_id: project.id }) | ||
.then((tutorials) => { | ||
dispatch({ | ||
type: FETCH_TUTORIALS_SUCCESS, | ||
payload: tutorials, | ||
}); | ||
}); | ||
}; | ||
} | ||
|
||
// Exports | ||
export default projectReducer; | ||
|
||
export { | ||
fetchProject | ||
}; |
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
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.
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.