From f3ee4745816b38bba4124f6ab6992ea8e49ae3ea Mon Sep 17 00:00:00 2001 From: Nikola Bjelo Date: Wed, 7 Nov 2018 16:45:33 +0100 Subject: [PATCH] Implementing mutation to create new plotter and formula --- .../Event/Create/Tabs/Technical/NewFormula.js | 80 +++++++++++++ .../Event/Create/Tabs/Technical/NewPlotter.js | 110 ++++++++++++++++++ .../Tabs/{Technical.js => Technical/index.js} | 67 +++++++---- 3 files changed, 235 insertions(+), 22 deletions(-) create mode 100644 client/src/Components/Event/Create/Tabs/Technical/NewFormula.js create mode 100644 client/src/Components/Event/Create/Tabs/Technical/NewPlotter.js rename client/src/Components/Event/Create/Tabs/{Technical.js => Technical/index.js} (64%) diff --git a/client/src/Components/Event/Create/Tabs/Technical/NewFormula.js b/client/src/Components/Event/Create/Tabs/Technical/NewFormula.js new file mode 100644 index 000000000..11ef9356b --- /dev/null +++ b/client/src/Components/Event/Create/Tabs/Technical/NewFormula.js @@ -0,0 +1,80 @@ +import React from 'react'; +import { + Dialog, + DialogTitle, + DialogContent, + DialogContentText, + Button, + TextField, +} from '@material-ui/core'; + +import { Mutation } from 'react-apollo'; +import { getOptionsCalls } from '../../../../../GraphQL/Calls/index'; + +class NewFormula extends React.Component { + constructor() { + super(); + this.state = { name: '' }; + } + + render() { + const { name } = this.state; + return ( + this.props.closeDialogs()} + aria-labelledby='createFormula-dialog-title' + > + + Create a new formula + + + + At least for now, all the formulas are publically available, creating it here will let you select it in the select element. + + + { + const { events_Formulas: formulas } = store.readQuery({ + query: getOptionsCalls.EVENTS_FORMULAS, + }); + store.writeQuery({ + query: getOptionsCalls.EVENTS_FORMULAS, + data: { events_Formulas: formulas.concat([data.events_CreateFormula]) }, + }); + this.props.closeDialogs(); + } + } + > + {createFormula => ( +
+
{ + e.preventDefault(); + createFormula({ + variables: { + formula: { name }, + }, + }); + }} + > + this.setState({ name: e.target.value })} + fullWidth + /> + + +
+ )} +
+ + +
+
+ ); + } +} + +export default NewFormula; diff --git a/client/src/Components/Event/Create/Tabs/Technical/NewPlotter.js b/client/src/Components/Event/Create/Tabs/Technical/NewPlotter.js new file mode 100644 index 000000000..2aeeb50b5 --- /dev/null +++ b/client/src/Components/Event/Create/Tabs/Technical/NewPlotter.js @@ -0,0 +1,110 @@ +import React from 'react'; +import { + Dialog, + DialogTitle, + DialogContent, + DialogContentText, + Button, + TextField, +} from '@material-ui/core'; + +import { Mutation } from 'react-apollo'; +import { getOptionsCalls } from '../../../../../GraphQL/Calls/index'; + +class NewPlotter extends React.Component { + constructor() { + super(); + this.state = { + name: '', + host: '', + repo: '', + moduleName: '', + }; + } + + render() { + const { + name, host, repo, moduleName, + } = this.state; + return ( + this.props.closeDialogs()} + aria-labelledby='createPlotter-dialog-title' + > + + Create a new plotter + + + + At least for now, all the plotters are publically available, creating it here will let you select it in the select element. + + + { + const { events_Plotters: plotters } = store.readQuery({ + query: getOptionsCalls.EVENTS_PLOTTERS, + }); + store.writeQuery({ + query: getOptionsCalls.EVENTS_PLOTTERS, + data: { events_Plotters: plotters.concat([data.events_CreatePlotter]) }, + }); + this.props.closeDialogs(); + } + } + > + {createPlotter => ( +
+
{ + e.preventDefault(); + createPlotter({ + variables: { + plotter: { + name, + host, + repo, + moduleName, + }, + }, + }); + }} + > + this.setState({ name: e.target.value })} + fullWidth + /> + this.setState({ host: e.target.value })} + fullWidth + /> + this.setState({ repo: e.target.value })} + fullWidth + /> + this.setState({ moduleName: e.target.value })} + fullWidth + /> + + +
+ )} +
+ + +
+
+ ); + } +} + +export default NewPlotter; diff --git a/client/src/Components/Event/Create/Tabs/Technical.js b/client/src/Components/Event/Create/Tabs/Technical/index.js similarity index 64% rename from client/src/Components/Event/Create/Tabs/Technical.js rename to client/src/Components/Event/Create/Tabs/Technical/index.js index 29607dd42..438ad27f9 100644 --- a/client/src/Components/Event/Create/Tabs/Technical.js +++ b/client/src/Components/Event/Create/Tabs/Technical/index.js @@ -13,14 +13,29 @@ import { Button, } from '@material-ui/core'; import { withStyles } from '@material-ui/core/styles'; -import styles from '../styles'; +import styles from '../../styles'; -import { getOptionsCalls } from '../../../../GraphQL/Calls/index'; +import { getOptionsCalls } from '../../../../../GraphQL/Calls/index'; +import NewPlotter from './NewPlotter'; +import NewFormula from './NewFormula'; class Technical extends React.Component { + constructor(props) { + super(props); + this.state = { + isNewFormulaOpen: false, + isNewPlotterOpen: false, + }; + } + + closeDialogs = () => { + this.setState({ isNewFormulaOpen: false, isNewPlotterOpen: false }); + } + render() { const { classes, event, edit } = this.props; + const { isNewPlotterOpen, isNewFormulaOpen } = this.state; return ( @@ -50,19 +65,22 @@ class Technical extends React.Component { {formula.name} )); return ( - + + + { isNewFormulaOpen ? this.closeDialogs()} /> : ''} + ); }} - console.log('Comming soon in a modaal')}> + { this.setState({ isNewFormulaOpen: true }); }}> To create a new formula, click here @@ -90,19 +108,24 @@ class Technical extends React.Component { {plotter.name} )); return ( - + + + { isNewPlotterOpen ? this.closeDialogs()} /> : ''} + ); }} - To create a new plotter, click here + { this.setState({ isNewPlotterOpen: true }); }} > + To create a new plotter, click here +