InstrumentSubsystem.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import gql from 'graphql-tag'
  2. import { Query, Mutation } from 'react-apollo'
  3. import Gallery from './Gallery'
  4. import InstrumentCommand from './InstrumentCommand'
  5. import InstrumentParameter from './InstrumentParameter'
  6. const CREATE_INSTRUMENT_SUBSYSTEM = gql`
  7. mutation CREATE_INSTRUMENT_SUBSYSTEM($name: String!, $description: String!) {
  8. createInstrumentSubsystem(name: $name, description: $description) {
  9. id
  10. }
  11. }
  12. `
  13. const UPDATE_INSTRUMENT_SUBSYSTEM = gql`
  14. mutation UPDATE_INSTRUMENT_SUBSYSTEM($name: String, $description: String, $commands: [ID]) {
  15. updateInstrumentSubsystem(name: $name, description:$description, commands: $commands) {
  16. id
  17. }
  18. }
  19. `
  20. const InstrumentSubsystemFields = {
  21. id: null,
  22. name: '',
  23. description: '',
  24. commands: [],
  25. parameters: [],
  26. subsystems: []
  27. }
  28. const InstrumentSubsystemFormFields = props => {
  29. const { state, onChange } = props
  30. return (
  31. <fieldset>
  32. <label htmlFor='name'>Name</label>
  33. <input type='text' name='name' id='name' placeholder='Name' value={state.name} onChange={onChange} />
  34. <label htmlFor='description'>Name</label>
  35. <textarea name='description' id='description' placeholder='Description' value={state.description} onChange={onChange} />
  36. </fieldset>
  37. )
  38. }
  39. const InstrumentSubsystem = props => {
  40. const { subsystem } = props
  41. return subsystem ? (
  42. <div>
  43. <h1>{subsystem.name}</h1>
  44. <p>{subsystem.description}</p>
  45. <Gallery title='Commands' items={subsystem.commands.map(command =>
  46. <InstrumentCommand command={command} />)} />
  47. <Gallery title='Parameters' items={subsystem.parameters.map(parameter =>
  48. <InstrumentParameter parameter={parameter} />)} />
  49. <Gallery title='Subsystems' items={subsystem.subsystems.map(childSubsystem =>
  50. <InstrumentSubsystem subsystem={childSubsystem} />)} />
  51. </div>
  52. ) : (
  53. <p>No data found.</p>
  54. )
  55. }
  56. export default InstrumentSubsystem
  57. export { InstrumentSubsystemFields, InstrumentSubsystemFormFields }
  58. export { CREATE_INSTRUMENT_SUBSYSTEM }