123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import gql from 'graphql-tag'
- import { Query, Mutation } from 'react-apollo'
- import InstrumentSubsystem from './InstrumentSubsystem'
- const CREATE_INSTRUMENT = gql`
- mutation CREATE_INSTRUMENT($name: String!, $description: String!, $interfaces: [String]!) {
- createInstrument(name: $name, description: $description, interfaces: $interfaces) {
- id
- }
- }
- `
- class Instrument extends React.Component {
- state = {
- id: this.props.instrument ? this.props.instrument.id : null,
- name: '',
- description: '',
- documents: [],
- interfaces: [],
- subsystems: []
- }
- toState = event => {
- this.setState({ [event.target.name]: event.target.value })
- }
- addComment = event => {
- event.preventDefault()
- const newState = { ...this.state }
- newState.changes.push(this.state.change)
- newState.change = ''
- this.setState(newState)
- }
- render() {
- return (
- <Mutation mutation={CREATE_PROJECT_VERSION} variables={this.state}>
- {(createProjectVersion, { data, error, loading }) => (
- <form onSubmit={async event => {
- event.preventDefault()
- const { data } = await createProjectVersion()
- this.state.id = data.createProjectVersion.id
- }}>
- {!this.props.title && <h1>Project Version</h1>}
- <fieldset id='project-generic'>
- <label htmlFor='name'>Project name</label>
- <input type='text' name='name' id='name' placeholder='Project version name' value={this.state.name} onChange={this.toState} />
- <label htmlFor='description'>Date</label>
- <input type='text' name='description' id='description' placeholder='Project description' value={this.state.description} onChange={this.toState} />
- {this.props.project || (
- <Query query={QUERY_PROJECTS}>
- {({ data, error, loading }) => {
- if (loading) return <p>Loading projects...</p>
- if (error) return <p>Error: {error.message}</p>
- if (!data || !data.projects.length) return <p>No projects found.</p>
- if (!this.state.project) this.setState({ project: data.projects[0].id })
- return (
- <label htmlFor="version">
- <select name="version" id="version">onChange={this.toState}>
- {data.projects.map(project =>
- <option key={project.id} value={project.id}>{project.name}</option>)
- }
- </select>
- </label>
- )
- }}
- </Query>
- )}
- </fieldset>
- <button type='submit'>Save</button>
- </form>
- )}
- </Mutation>
- )
- }
- }
- export default Instrument
|