import gql from 'graphql-tag' import { Query, Mutation } from 'react-apollo' import { adopt } from 'react-adopt' import InstrumentSubsystem, { InstrumentSubsystemFormFields, InstrumentSubsystemFields } from './InstrumentSubsystem' import File, { FileFormFields } from './File' import Gallery from './Gallery' import { INTERFACES_FULL } from './InterfaceList' const CREATE_INSTRUMENT = gql` mutation CREATE_INSTRUMENT($name: String!, $description: String!, $interfaces: [String]!) { createInstrument(name: $name, description: $description, interfaces: $interfaces) { id } } ` const InstrumentFields = { id: null, name: '', description: '', documents: [], interfaces: [], commands: [], parameters: [], subsystems: [] } const MockInterfaces = { interfaces: [{ name: 'serial' }, { name: 'usbtmc' }] } class InstrumentForm extends React.Component { state = { ...InstrumentFields, ...this.props.instrument } toState = event => { this.setState({ [event.target.name]: event.target.value }) } handleInterface = event => { let interfaces = this.state.interfaces const ifaceSelected = event.target.checked const index = this.state.interfaces.findIndex(iface => iface === event.target.value) if (ifaceSelected && index < 0) interfaces = [ ...this.state.interfaces, event.target.value ] if (!ifaceSelected && index >= 0) interfaces = [ ...this.state.interfaces.slice(0, index), ...this.state.interfaces.slice(index + 1) ] this.setState({ interfaces }) } render() { return (

Create new instrument.