JengaExtra.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React from 'react'
  2. import newEventStores from 'stores/newEvent'
  3. import {
  4. nodeIsDyTransaction,
  5. nodeIsFunctionGroup,
  6. nodeIsIotMessage,
  7. nodeIsNormalService,
  8. nodeIsTimerService,
  9. nodeIsTransaction
  10. } from 'stores/funcs/nodeType'
  11. import { getEventNodeById } from 'stores/funcs/newEvent'
  12. import NodeParams from './NodeParams'
  13. import NodeServiceParams from './NodeServiceParams'
  14. import TimerServiceParams from './TimerServiceParams'
  15. import NodePublicService from './NodePublicService'
  16. import NodeFuncGroup from './NodeFuncGroup'
  17. import IotMessageConfig from './IotMessageConfig'
  18. export default class JengaExtra extends React.Component {
  19. constructor(props) {
  20. super(props)
  21. this.state = {
  22. curEventNodeId: newEventStores.curEventNodeId,
  23. type: this.getType(newEventStores.curEventNodeId)
  24. }
  25. this.onEventChange = this.onEventChange.bind(this)
  26. this.getType = this.getType.bind(this)
  27. }
  28. componentDidMount() {
  29. this.unsubscribe = newEventStores.listen(this.onEventChange)
  30. }
  31. componentWillUnmount() {
  32. this.unsubscribe()
  33. }
  34. onEventChange(status) {
  35. let obj = {}
  36. if (status && status.types) {
  37. if (status.types.includes('curEventNodeId')) {
  38. if (this.state.curEventNodeId !== status.data.curEventNodeId) {
  39. obj.curEventNodeId = status.data.curEventNodeId
  40. obj.type = this.getType(obj.curEventNodeId)
  41. }
  42. }
  43. }
  44. if (Object.keys(obj).length > 0) {
  45. this.setState(obj)
  46. }
  47. }
  48. getType(nodeId) {
  49. let type = null
  50. let node = getEventNodeById(nodeId)
  51. if (node) {
  52. if (nodeIsTimerService(node.type)) {
  53. type = 'timer'
  54. } else if (nodeIsTransaction(node.type)) {
  55. type = 'transaction'
  56. } else if (nodeIsDyTransaction(node.type)) {
  57. type = 'dyTransaction'
  58. } else if (nodeIsIotMessage(node.type)) {
  59. type = 'iotMessage'
  60. } else if (nodeIsNormalService(node.type)) {
  61. type = 'service'
  62. } else if (nodeIsFunctionGroup(node.type)) {
  63. type = 'funcGroup'
  64. }
  65. }
  66. return type
  67. }
  68. render() {
  69. return (
  70. <React.Fragment>
  71. {this.state.type === 'service' ? (
  72. <NodePublicService nodeId={this.state.curEventNodeId} />
  73. ) : this.state.type === 'funcGroup' ? (
  74. <NodeFuncGroup nodeId={this.state.curEventNodeId} />
  75. ) : null}
  76. {['funcGroup', 'transaction', 'dyTransaction'].indexOf(
  77. this.state.type
  78. ) >= 0 ? (
  79. <NodeParams nodeId={this.state.curEventNodeId} />
  80. ) : this.state.type === 'service' ? (
  81. <NodeServiceParams nodeId={this.state.curEventNodeId} />
  82. ) : this.state.type === 'timer' ? (
  83. <TimerServiceParams nodeId={this.state.curEventNodeId} />
  84. ) : this.state.type === 'iotMessage' ? (
  85. <IotMessageConfig nodeId={this.state.curEventNodeId} />
  86. ) : null}
  87. </React.Fragment>
  88. )
  89. }
  90. }