InterfaceList.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import gql from 'graphql-tag'
  2. import { Query } from 'react-apollo'
  3. import Interface from './Interface'
  4. const INTERFACE_LIST = gql`
  5. query INTERFACE_LIST {
  6. interfaces {
  7. interfaceName
  8. workerScript
  9. ports {
  10. id
  11. device
  12. interfaceName
  13. name
  14. description
  15. }
  16. connections {
  17. id
  18. device
  19. interfaceName
  20. }
  21. options {
  22. name
  23. type
  24. description
  25. values
  26. }
  27. }
  28. }
  29. `
  30. class InterfaceList extends React.Component {
  31. state = {
  32. connectionId: '',
  33. command: '',
  34. result: ''
  35. }
  36. sendCommand = async (event, client) => {
  37. event.preventDefault()
  38. const { data, error } = await client.query({
  39. query: CONNECTION_SEND_QUERY,
  40. variables: this.state
  41. })
  42. console.log(data, error)
  43. const { result } = data
  44. this.setState({ result })
  45. }
  46. changeInput = event => {
  47. this.setState({ [event.target.id]: event.target.value })
  48. }
  49. render() {
  50. return (
  51. <Query query={INTERFACE_LIST}>
  52. {({data}, loading, error) => {
  53. const {interfaces} = data
  54. return (
  55. <div>
  56. <h1>Interface List</h1>
  57. {interfaces.map(iface => <Interface key={iface.interfaceName} data={iface} />)}
  58. </div>
  59. )}}
  60. </Query>
  61. )
  62. }
  63. }
  64. export default InterfaceList
  65. export {INTERFACE_LIST}