nodes.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. const {
  49. topologiesLoaded, nodesLoaded, topologies, currentTopology, isGraphViewMode,
  50. isTableViewMode, isResourceViewMode
  51. } = this.props;
  52. // TODO: Rename view mode components.
  53. return (
  54. <div className="nodes-wrapper">
  55. <DelayedShow delay={TOPOLOGY_LOADER_DELAY} show={!topologiesLoaded || !nodesLoaded}>
  56. <Loading itemType="topologies" show={!topologiesLoaded} />
  57. <Loading
  58. itemType={getNodeType(currentTopology, topologies)}
  59. show={topologiesLoaded && !nodesLoaded} />
  60. </DelayedShow>
  61. {topologiesLoaded && nodesLoaded && this.renderConditionalEmptyTopologyError()}
  62. {isGraphViewMode && <NodesChart />}
  63. {isTableViewMode && <NodesGrid />}
  64. {isResourceViewMode && <NodesResources />}
  65. </div>
  66. );
  67. }
  68. }
  69. function mapStateToProps(state) {
  70. return {
  71. currentTopology: state.get('currentTopology'),
  72. isGraphViewMode: isGraphViewModeSelector(state),
  73. isResourceViewMode: isResourceViewModeSelector(state),
  74. isTableViewMode: isTableViewModeSelector(state),
  75. nodesDisplayEmpty: isNodesDisplayEmpty(state),
  76. nodesLoaded: nodesLoadedSelector(state),
  77. topologies: state.get('topologies'),
  78. topologiesLoaded: state.get('topologiesLoaded'),
  79. topologyNodeCountZero: isTopologyNodeCountZero(state),
  80. };
  81. }
  82. export default connect(mapStateToProps)(Nodes);