From 881a4754a02b11761fc146ecae9aa85885418c0d Mon Sep 17 00:00:00 2001 From: Nikola Bjelo Date: Tue, 6 Nov 2018 16:28:05 +0100 Subject: [PATCH] populating selects from graphql queries --- .../Components/Event/Create/Tabs/Technical.js | 91 ++++++++++++++----- client/src/GraphQL/Calls/getOptions.js | 31 +++++++ client/src/GraphQL/Calls/index.js | 2 + 3 files changed, 101 insertions(+), 23 deletions(-) create mode 100644 client/src/GraphQL/Calls/getOptions.js diff --git a/client/src/Components/Event/Create/Tabs/Technical.js b/client/src/Components/Event/Create/Tabs/Technical.js index a463b151d..56bdf46f9 100644 --- a/client/src/Components/Event/Create/Tabs/Technical.js +++ b/client/src/Components/Event/Create/Tabs/Technical.js @@ -1,4 +1,6 @@ import React from 'react'; +import { Query } from 'react-apollo'; + import { Typography, FormControl, @@ -8,10 +10,11 @@ import { FormHelperText, MenuItem, } from '@material-ui/core'; - import { withStyles } from '@material-ui/core/styles'; import styles from '../styles'; +import { getOptionsCalls } from '../../../../GraphQL/Calls/index'; + class Technical extends React.Component { render() { @@ -25,17 +28,38 @@ class Technical extends React.Component { Select the formula - + + {({ loading, error, data }) => { + if (loading) { + return ( + + ); + } + if (error) return `Error! ${error.message}`; + const selects = data.events_Formulas.map((formula, index) => ( + {formula.name} + )); + return ( + + ); + }} + console.log('Comming soon in a modaal')}> To create a new formula, click here @@ -44,17 +68,38 @@ class Technical extends React.Component { Select the Plotter - + + {({ loading, error, data }) => { + if (loading) { + return ( + + ); + } + if (error) return `Error! ${error.message}`; + const selects = data.events_Plotters.map((plotter, index) => ( + {plotter.name} + )); + return ( + + ); + }} + To create a new plotter, click here diff --git a/client/src/GraphQL/Calls/getOptions.js b/client/src/GraphQL/Calls/getOptions.js new file mode 100644 index 000000000..f7bd3edf0 --- /dev/null +++ b/client/src/GraphQL/Calls/getOptions.js @@ -0,0 +1,31 @@ +import gql from 'graphql-tag'; + +const EVENTS_FORMULAS = gql` + query Events_Formulas{ + events_Formulas { + id + ownerId + isTemplate + name + } + } +`; + +const EVENTS_PLOTTERS = gql` + query Events_Plotters{ + events_Plotters { + id + ownerId + isTemplate + name + host + repo + moduleName + } + } +`; + +export default { + EVENTS_PLOTTERS, + EVENTS_FORMULAS, +}; diff --git a/client/src/GraphQL/Calls/index.js b/client/src/GraphQL/Calls/index.js index 334af1c78..b8225b64b 100644 --- a/client/src/GraphQL/Calls/index.js +++ b/client/src/GraphQL/Calls/index.js @@ -1,9 +1,11 @@ import hostedEventsCalls from './hostedEvents'; import listEventsCalls from './listEvents'; import showEventCalls from './showEvent'; +import getOptionsCalls from './getOptions'; export { hostedEventsCalls, listEventsCalls, showEventCalls, + getOptionsCalls, };