Skip to content

Commit 376486f

Browse files
committed
Refactor Projects.jsx into presentational and container components in separate directories
1 parent c55e297 commit 376486f

File tree

18 files changed

+301
-240
lines changed

18 files changed

+301
-240
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import Expand from '../Expand';
5+
import NewProjectForm from '../../containers/NewProjectForm';
6+
7+
8+
const AddProject = (props) => {
9+
const expandBoxStyle = {
10+
zIndex: 1000,
11+
position: 'relative',
12+
width: 500,
13+
WebkitBoxShadow: '0 0 5px black',
14+
MozBoxShadow: '0 0 5px black',
15+
boxShadow: '0 0 5px black',
16+
color: 'black'
17+
};
18+
return (
19+
<Expand
20+
id={props.id}
21+
label={props.label || "Add Project"}
22+
expandBoxStyle={expandBoxStyle} style={props.style}
23+
>
24+
<NewProjectForm label="Create Project" onSubmit={props.addProject} />
25+
</Expand>
26+
);
27+
};
28+
29+
AddProject.propTypes = {
30+
id: PropTypes.string.isRequired,
31+
label: PropTypes.string,
32+
addProject: PropTypes.func.isRequired,
33+
style: PropTypes.object
34+
};
35+
36+
37+
export default AddProject;

static/js/components/Datasets.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { connect } from "react-redux";
33
import { reduxForm } from 'redux-form';
44

5-
import { FormComponent, Form, TextInput, FileInput, SubmitButton } from './Form';
5+
import { FormComponent, Form, TextInput, FileInput, SubmitButton } from './Form/index';
66
import * as Validate from '../validate';
77
import Expand from './Expand';
88
import Delete from './Delete';

static/js/components/Delete.jsx renamed to static/js/components/Delete/index.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23

34
const Delete = (props) => {
45
const style = {
@@ -19,11 +20,11 @@ const Delete = (props) => {
1920
);
2021
};
2122
Delete.propTypes = {
22-
ID: React.PropTypes.oneOfType([
23-
React.PropTypes.number,
24-
React.PropTypes.string]).isRequired,
25-
delete: React.PropTypes.func.isRequired,
26-
typeName: React.PropTypes.string
23+
ID: PropTypes.oneOfType([
24+
PropTypes.number,
25+
PropTypes.string]).isRequired,
26+
delete: PropTypes.func.isRequired,
27+
typeName: PropTypes.string
2728
};
2829

2930
export default Delete;

static/js/components/Features.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { reduxForm } from 'redux-form';
44
import ReactTabs from 'react-tabs';
55

66
import { FormComponent, Form, TextInput, TextareaInput, SubmitButton,
7-
CheckBoxInput, SelectInput } from './Form';
7+
CheckBoxInput, SelectInput } from './Form/index';
88
import * as Validate from '../validate';
99
import Expand from './Expand';
1010
import * as Action from '../actions';

static/js/components/Form.jsx renamed to static/js/components/Form/index.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React, { PropTypes } from 'react';
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
24

35
export const FormComponent = (props) => {
46
};

static/js/components/Main.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { connect, Provider } from 'react-redux';
33
import ReactDOM from 'react-dom';
44
import ReactTabs from 'react-tabs';
5+
import PropTypes from 'prop-types';
56

67
import 'bootstrap-css';
78
import 'bootstrap';
@@ -10,7 +11,9 @@ import configureStore from '../configureStore';
1011
import * as Action from '../actions';
1112
import WebSocket from 'baselayer/components/WebSocket';
1213
import CesiumMessageHandler from '../CesiumMessageHandler';
13-
import { ProjectSelector, AddProject, ProjectTab } from './Projects';
14+
import AddProject from '../containers/AddProject';
15+
import ProjectSelector from '../containers/ProjectSelector';
16+
import ProjectTab from '../containers/ProjectTab';
1417
import DatasetsTab from './Datasets';
1518
import FeaturesTab from './Features';
1619
import ModelsTab from './Models';
@@ -372,10 +375,10 @@ class MainContent extends React.Component {
372375
}
373376
}
374377
MainContent.propTypes = {
375-
selectedProject: React.PropTypes.object.isRequired,
376-
root: React.PropTypes.string.isRequired,
377-
logoSpinAngle: React.PropTypes.number.isRequired,
378-
spinLogo: React.PropTypes.func
378+
selectedProject: PropTypes.object.isRequired,
379+
root: PropTypes.string.isRequired,
380+
logoSpinAngle: PropTypes.number.isRequired,
381+
spinLogo: PropTypes.func
379382
};
380383

381384
const mapStateToProps = function (state) {

static/js/components/Models.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { PropTypes } from 'react';
22
import { connect } from 'react-redux';
33
import { reduxForm } from 'redux-form';
44

5-
import { FormComponent, TextInput, CheckBoxInput, SelectInput, SubmitButton, Form } from './Form';
5+
import { FormComponent, TextInput, CheckBoxInput, SelectInput, SubmitButton, Form } from './Form/index';
66

77
import * as Validate from '../validate';
88

static/js/components/Predictions.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { connect } from 'react-redux';
33
import { reduxForm } from 'redux-form';
44

55
import { FormComponent, SelectInput, SubmitButton,
6-
Form } from './Form';
6+
Form } from './Form/index';
77

88
import * as Validate from '../validate';
99

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { FormComponent, Form, SelectInput, TextInput, SubmitButton } from '../Form/index';
5+
6+
7+
const ProjectForm = (props) => {
8+
const { fields: { projectName, projectDescription },
9+
error, resetForm, submitting, handleSubmit } = props;
10+
11+
return (
12+
<Form onSubmit={handleSubmit} error={error}>
13+
<TextInput label="Project Name" {...projectName} />
14+
<TextInput label="Project Description (optional)" {...projectDescription} />
15+
<SubmitButton
16+
label={props.label}
17+
submitting={submitting} resetForm={resetForm}
18+
/>
19+
</Form>
20+
);
21+
};
22+
ProjectForm.propTypes = {
23+
fields: PropTypes.object.isRequired,
24+
label: PropTypes.string.isRequired,
25+
error: PropTypes.string,
26+
handleSubmit: PropTypes.func.isRequired,
27+
submitting: PropTypes.bool.isRequired,
28+
resetForm: PropTypes.func.isRequired
29+
};
30+
31+
export default ProjectForm;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import {SelectInput, Form} from '../Form/index';
5+
6+
7+
let ProjectSelector = (props) => {
8+
const { fields: { project } } = props;
9+
10+
const projects = props.projects.map(proj => (
11+
{
12+
id: proj.id,
13+
label: proj.name
14+
}
15+
));
16+
17+
return (
18+
<div style={props.style}>
19+
<Form onSubmit={form => null}>
20+
<SelectInput
21+
label={props.label}
22+
options={projects}
23+
{...project}
24+
/>
25+
</Form>
26+
</div>
27+
);
28+
};
29+
ProjectSelector.propTypes = {
30+
fields: PropTypes.object,
31+
projects: PropTypes.arrayOf(PropTypes.object).isRequired,
32+
style: PropTypes.object,
33+
label: PropTypes.string
34+
};
35+
36+
37+
export default ProjectSelector;

0 commit comments

Comments
 (0)