nodes.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import NodesChart from '../charts/nodes-chart';
  4. import NodesGrid from '../charts/nodes-grid';
  5. import NodesResources from './nodes-resources';
  6. import NodesError from '../charts/nodes-error';
  7. import DelayedShow from '../utils/delayed-show';
  8. import { Loading, getNodeType } from './loading';
  9. import {
  10. isTopologyNodeCountZero,
  11. isNodesDisplayEmpty,
  12. } from '../utils/topology-utils';
  13. import { nodesLoadedSelector } from '../selectors/node-filters';
  14. import {
  15. isGraphViewModeSelector,
  16. isTableViewModeSelector,
  17. isResourceViewModeSelector,
  18. } from '../selectors/topology';
  19. import { TOPOLOGY_LOADER_DELAY } from '../constants/timer';
  20. // TODO: The information that we already have available on the frontend should enable
  21. // us to determine which of these cases exactly is preventing us from seeing the nodes.
  22. const NODES_STATS_COUNT_ZERO_CAUSES = [
  23. 'We haven\'t received any reports from probes recently. Are the probes properly connected?',
  24. 'Containers view only: you\'re not running Docker, or you don\'t have any containers',
  25. ];
  26. const NODES_NOT_DISPLAYED_CAUSES = [
  27. 'There are nodes, but they\'ve been filtered out by pinned searches in the top-left corner.',
  28. 'There are nodes, but they\'re currently hidden. Check the view options in the bottom-left if they allow for showing hidden nodes.',
  29. 'There are no nodes for this particular moment in time. Use the time travel feature at the bottom-right corner to explore different times.',
  30. ];
  31. const renderCauses = causes => (
  32. <ul>{causes.map(cause => <li key={cause}>{cause}</li>)}</ul>
  33. );
  34. class Nodes extends React.Component {
  35. renderConditionalEmptyTopologyError() {
  36. const { topologyNodeCountZero, nodesDisplayEmpty } = this.props;
  37. return (
  38. <NodesError faIconClass="far fa-circle" hidden={!nodesDisplayEmpty}>
  39. {/* <div className="heading">Nothing to show. This can have any of these reasons:</div> */}
  40. <div style={{textAlign:'center',width:'100%',marginTop:'16px'}}>未发现服务节点</div>
  41. {/* {topologyNodeCountZero
  42. ? renderCauses(NODES_STATS_COUNT_ZERO_CAUSES)
  43. : renderCauses(NODES_NOT_DISPLAYED_CAUSES)} */}
  44. </NodesError>
  45. );
  46. }
  47. render() {
  48. console.log('000000','scripts/components/nodes.js')
  49. const {
  50. topologiesLoaded, nodesLoaded, topologies, currentTopology, isGraphViewMode,
  51. isTableViewMode, isResourceViewMode
  52. } = this.props;
  53. // TODO: Rename view mode components.
  54. return (
  55. <div className="nodes-wrapper">
  56. <DelayedShow delay={TOPOLOGY_LOADER_DELAY} show={!topologiesLoaded || !nodesLoaded}>
  57. <Loading itemType="topologies" show={!topologiesLoaded} />
  58. <Loading
  59. itemType={getNodeType(currentTopology, topologies)}
  60. show={topologiesLoaded && !nodesLoaded} />
  61. </DelayedShow>
  62. {topologiesLoaded && nodesLoaded && this.renderConditionalEmptyTopologyError()}
  63. {isGraphViewMode && <NodesChart />}
  64. {isTableViewMode && <NodesGrid />}
  65. {isResourceViewMode && <NodesResources />}
  66. </div>
  67. );
  68. }
  69. }
  70. function mapStateToProps(state) {
  71. return {
  72. currentTopology: state.get('currentTopology'),
  73. isGraphViewMode: isGraphViewModeSelector(state),
  74. isResourceViewMode: isResourceViewModeSelector(state),
  75. isTableViewMode: isTableViewModeSelector(state),
  76. nodesDisplayEmpty: isNodesDisplayEmpty(state),
  77. nodesLoaded: nodesLoadedSelector(state),
  78. topologies: state.get('topologies'),
  79. topologiesLoaded: state.get('topologiesLoaded'),
  80. topologyNodeCountZero: isTopologyNodeCountZero(state),
  81. };
  82. }
  83. export default connect(mapStateToProps)(Nodes);