JengaNavInfo.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import React from 'react'
  2. import cls from 'classnames'
  3. import i18n from 'i18next'
  4. import newEventStores from 'stores/newEvent'
  5. import treeStores from 'stores/tree'
  6. import {
  7. nodeIsDyTransaction,
  8. nodeIsFunctionGroup,
  9. nodeIsIotMessage,
  10. nodeIsNormalService,
  11. nodeIsTimerService,
  12. nodeIsTransaction
  13. } from 'stores/funcs/nodeType'
  14. import { getEventNodeById } from 'stores/funcs/newEvent'
  15. import JengaDebugBtn from './debug/JengaDebugBtn'
  16. import LogBtn from 'src/components/common/serviceLogView/LogBtn'
  17. import JengaNavNavigateNodes from './JengaNavNavigateNodes'
  18. export default class JengaNavInfo extends React.Component {
  19. constructor(props) {
  20. super(props)
  21. this.state = {
  22. curEventNodeId: newEventStores.curEventNodeId,
  23. type: this.getType(newEventStores.curEventNodeId),
  24. curClassId: treeStores.curClassId
  25. }
  26. this.onEventChange = this.onEventChange.bind(this)
  27. this.onTreeChange = this.onTreeChange.bind(this)
  28. this.getType = this.getType.bind(this)
  29. this.getInfo = this.getInfo.bind(this)
  30. }
  31. componentDidMount() {
  32. this.unsubscribe = newEventStores.listen(this.onEventChange)
  33. this.unsubscribeTree = treeStores.listen(this.onTreeChange)
  34. }
  35. componentWillUnmount() {
  36. this.unsubscribe()
  37. this.unsubscribeTree()
  38. }
  39. onEventChange(status) {
  40. let obj = {}
  41. if (status && status.types) {
  42. if (status.types.includes('curEventNodeId')) {
  43. if (this.state.curEventNodeId !== status.data.curEventNodeId) {
  44. obj.curEventNodeId = status.data.curEventNodeId
  45. obj.type = this.getType(obj.curEventNodeId)
  46. }
  47. }
  48. }
  49. if (Object.keys(obj).length > 0) {
  50. this.setState(obj)
  51. }
  52. }
  53. onTreeChange(status) {
  54. let obj = {}
  55. if (status && status.types) {
  56. if (status.types.includes('curClassId')) {
  57. if (this.state.curClassId !== status.data.curClassId) {
  58. obj.curClassId = status.data.curClassId
  59. }
  60. }
  61. }
  62. if (Object.keys(obj).length > 0) {
  63. this.setState(obj)
  64. }
  65. }
  66. getType(nodeId) {
  67. let type = null
  68. let node = getEventNodeById(nodeId)
  69. if (node) {
  70. if (nodeIsTimerService(node.type)) {
  71. type = 'timer'
  72. } else if (nodeIsTransaction(node.type)) {
  73. type = 'transaction'
  74. } else if (nodeIsDyTransaction(node.type)) {
  75. type = 'dyTransaction'
  76. } else if (nodeIsIotMessage(node.type)) {
  77. type = 'iotMessage'
  78. } else if (nodeIsNormalService(node.type)) {
  79. type = 'service'
  80. } else if (nodeIsFunctionGroup(node.type)) {
  81. type = 'funcGroup'
  82. }
  83. }
  84. return type
  85. }
  86. getInfo() {
  87. let { curClassId } = this.state
  88. if (this.props.curEventNodeList) {
  89. return null
  90. }
  91. switch (this.state.type) {
  92. case 'service':
  93. case 'timer':
  94. case 'transaction':
  95. case 'dyTransaction':
  96. return (
  97. <div
  98. className={cls('title', {
  99. 'f--hlc': ['service', 'timer'].indexOf(this.state.type) >= 0
  100. })}
  101. >
  102. {i18n.t('EventView.jenga_nav.' + this.state.type + 'Id')}
  103. <span>{this.state.curEventNodeId}</span>
  104. {['service', 'timer'].indexOf(this.state.type) >= 0 ? (
  105. <>
  106. {!curClassId && (
  107. <>
  108. <JengaDebugBtn nodeId={this.state.curEventNodeId} />
  109. <LogBtn />
  110. </>
  111. )}
  112. </>
  113. ) : null}
  114. </div>
  115. )
  116. case 'iotMessage':
  117. return (
  118. <div className={cls('title f--hlc')}>
  119. {<LogBtn className={'btn-iot-log'} />}
  120. </div>
  121. )
  122. default:
  123. return null
  124. }
  125. }
  126. render() {
  127. return (
  128. <div className="jenga-nav-info f--hlc flex-1">
  129. {this.getInfo()}
  130. <JengaNavNavigateNodes />
  131. </div>
  132. )
  133. }
  134. }