@riil-frontend/component-topology 12.0.0-dev.9 → 12.1.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/build/1.js +1 -1
  2. package/build/index.css +1 -1
  3. package/build/index.js +14 -14
  4. package/es/components/TemplateButton/index.module.scss +1 -1
  5. package/es/core/components/AlarmListPanel/components/AlarmListItem.js +58 -3
  6. package/es/core/components/TopoView/topoView.js +5 -1
  7. package/es/core/editor/components/Toolbar/widgets/EdgeColorButton/EdgeColorButton.js +5 -12
  8. package/es/core/editor/components/Toolbar/widgets/EdgeTypeButton/EdgeType.js +27 -10
  9. package/es/core/editor/components/Toolbar/widgets/EdgeTypeButton/EdgeType.module.scss +21 -1
  10. package/es/core/editor/components/Toolbar/widgets/EdgeTypeButton/LineType.js +9 -0
  11. package/es/core/editor/components/Toolbar/widgets/EdgeTypeButton/index.js +2 -2
  12. package/es/core/editor/components/Toolbar/widgets/Layout/index.js +16 -2
  13. package/es/core/editor/hooks/useKeyboardShortcut.js +3 -1
  14. package/es/core/editor/utils/copyElementUtil.js +12 -0
  15. package/es/core/editor/utils/edgeTypeStyleUtil.js +8 -30
  16. package/es/core/hooks/useAlarm.js +131 -81
  17. package/es/core/hooks/useCmpLinkAlarm.js +153 -0
  18. package/es/core/hooks/useEventData.js +1 -2
  19. package/es/core/hooks/useGraphAlarmDisplay.js +91 -56
  20. package/es/core/hooks/useResourceConfig.js +1 -3
  21. package/es/core/hooks/useTopoEdit.js +31 -43
  22. package/es/core/models/Alarm.js +69 -142
  23. package/es/core/models/AttributeMetricDisplay.js +9 -3
  24. package/es/core/models/TopoApp.js +1 -1
  25. package/es/core/models/cache/CiCache.d.ts +1 -1
  26. package/es/core/models/cache/CiCache.js +3 -3
  27. package/es/core/models/topoData.js +0 -1
  28. package/es/core/models/utils/linkUtils.js +20 -13
  29. package/es/core/services/topo/basic.js +2 -2
  30. package/es/core/store/models/topoConfig.js +7 -10
  31. package/es/core/store/models/topoMod.js +81 -134
  32. package/es/core/utils/edgeUtil.js +8 -0
  33. package/es/core/utils/metricUtil.js +8 -4
  34. package/es/core/utils/showGraphManageStatusUtil.js +3 -2
  35. package/es/core/viewer/components/plugins/ResourceDetail/components/ResourceOverview/components/LinkTopo/LinkTopoCard.js +2 -2
  36. package/es/core/viewer/components/plugins/ViewerPlugin.js +3 -1
  37. package/es/core/viewer/components/titlebar/widgets/AlarmButton.js +1 -5
  38. package/es/networkTopo/components/TopoView.js +6 -11
  39. package/es/networkTopo/hooks/useEdgeExpand.js +2 -3
  40. package/es/networkTopo/services/topo/basic.js +3 -3
  41. package/es/networkTopo/store/topoCenter.js +260 -223
  42. package/es/style.js +1 -1
  43. package/es/utils/ResourceConfigUtil.js +3 -36
  44. package/es/utils/ciRefAttributeTranslateUtil.d.ts +9 -2
  45. package/es/utils/ciRefAttributeTranslateUtil.js +8 -9
  46. package/es/utils/topoData.js +1 -1
  47. package/lib/components/TemplateButton/index.module.scss +1 -1
  48. package/lib/core/components/AlarmListPanel/components/AlarmListItem.js +60 -3
  49. package/lib/core/components/TopoView/topoView.js +5 -1
  50. package/lib/core/editor/components/Toolbar/widgets/EdgeColorButton/EdgeColorButton.js +6 -12
  51. package/lib/core/editor/components/Toolbar/widgets/EdgeTypeButton/EdgeType.js +27 -9
  52. package/lib/core/editor/components/Toolbar/widgets/EdgeTypeButton/EdgeType.module.scss +21 -1
  53. package/lib/core/editor/components/Toolbar/widgets/EdgeTypeButton/LineType.js +8 -0
  54. package/lib/core/editor/components/Toolbar/widgets/EdgeTypeButton/index.js +1 -1
  55. package/lib/core/editor/components/Toolbar/widgets/Layout/index.js +16 -2
  56. package/lib/core/editor/hooks/useKeyboardShortcut.js +2 -0
  57. package/lib/core/editor/utils/copyElementUtil.js +15 -0
  58. package/lib/core/editor/utils/edgeTypeStyleUtil.js +8 -31
  59. package/lib/core/hooks/useAlarm.js +130 -79
  60. package/lib/core/hooks/useCmpLinkAlarm.js +166 -0
  61. package/lib/core/hooks/useEventData.js +1 -2
  62. package/lib/core/hooks/useGraphAlarmDisplay.js +91 -55
  63. package/lib/core/hooks/useResourceConfig.js +1 -3
  64. package/lib/core/hooks/useTopoEdit.js +30 -42
  65. package/lib/core/models/Alarm.js +69 -144
  66. package/lib/core/models/AttributeMetricDisplay.js +10 -2
  67. package/lib/core/models/TopoApp.js +1 -1
  68. package/lib/core/models/cache/CiCache.d.ts +1 -1
  69. package/lib/core/models/cache/CiCache.js +3 -3
  70. package/lib/core/models/topoData.js +0 -1
  71. package/lib/core/models/utils/linkUtils.js +21 -13
  72. package/lib/core/services/topo/basic.js +2 -2
  73. package/lib/core/store/models/topoConfig.js +7 -10
  74. package/lib/core/store/models/topoMod.js +81 -134
  75. package/lib/core/utils/edgeUtil.js +10 -0
  76. package/lib/core/utils/metricUtil.js +8 -4
  77. package/lib/core/utils/showGraphManageStatusUtil.js +3 -2
  78. package/lib/core/viewer/components/plugins/ResourceDetail/components/ResourceOverview/components/LinkTopo/LinkTopoCard.js +2 -2
  79. package/lib/core/viewer/components/plugins/ViewerPlugin.js +3 -1
  80. package/lib/core/viewer/components/titlebar/widgets/AlarmButton.js +1 -5
  81. package/lib/networkTopo/components/TopoView.js +5 -14
  82. package/lib/networkTopo/hooks/useEdgeExpand.js +2 -3
  83. package/lib/networkTopo/services/topo/basic.js +3 -3
  84. package/lib/networkTopo/store/topoCenter.js +262 -225
  85. package/lib/style.js +1 -1
  86. package/lib/utils/ResourceConfigUtil.js +3 -38
  87. package/lib/utils/ciRefAttributeTranslateUtil.d.ts +9 -2
  88. package/lib/utils/ciRefAttributeTranslateUtil.js +8 -9
  89. package/lib/utils/topoData.js +1 -1
  90. package/package.json +2 -2
@@ -2,128 +2,178 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import { useEffect } from "react";
3
3
  import rlog from "@riil-frontend/component-topology-utils/es/rlog";
4
4
  import useGraphAlarmDisplay from "./useGraphAlarmDisplay";
5
- import useTopoEventListener from "./useTopoEventListener";
5
+ import useTopoEventListener from "./useTopoEventListener"; // 告警在活状态
6
+
7
+ var showAlarmStatus = ["toDeal", "dealing", "change", "woDealing"];
6
8
  /**
7
- *
8
- *
9
- * @param {*} options
9
+ * 告警是否在活
10
+ * @param {*} alarm
11
+ * @returns
10
12
  */
11
13
 
12
- export default function useAlarm(options) {
13
- var topo = options.topo;
14
- var store = topo.store;
14
+ var isAlarmAlive = function isAlarmAlive(alarm) {
15
+ return showAlarmStatus.indexOf(alarm.status) >= 0;
16
+ };
15
17
 
16
- var _topo$store$useModelS = topo.store.useModelState('displayConfig'),
17
- alarmSwitch = _topo$store$useModelS.alarmSwitch,
18
- alarmListDefaultOpen = _topo$store$useModelS.alarmListDefaultOpen;
18
+ var handleRiskData = function handleRiskData(topo, receivedData) {
19
+ var _risks, _topo$viewProps, _topo$viewProps2;
19
20
 
20
- useGraphAlarmDisplay({
21
- topo: topo,
22
- alarmSwitch: alarmSwitch
23
- });
21
+ // 非在活状态:
22
+ // 已修复 recovered
23
+ // 已关闭 closed
24
+ var prevRisks = topo.store.getModelState('topoAlarm').risks;
25
+
26
+ var isLiveRisk = function isLiveRisk(data) {
27
+ return ['recovered', 'closed'].indexOf(data.status) === -1;
28
+ };
29
+
30
+ var hasCiPermission = function hasCiPermission(data) {
31
+ var _data$resourceId;
24
32
 
25
- var handleRiskData = function handleRiskData(receivedData) {
26
- var _risks, _topo$viewProps, _topo$viewProps2;
33
+ var ciId = (_data$resourceId = data.resourceId) !== null && _data$resourceId !== void 0 ? _data$resourceId : data.ciId;
34
+ var ci = topo.dataModel.getDataById(ciId);
35
+ return !!(ci !== null && ci !== void 0 && ci.operation);
36
+ }; // 合并
27
37
 
28
- // 非在活状态:
29
- // 已修复 recovered
30
- // 已关闭 closed
31
- var prevRisks = topo.store.getModelState('topoAlarm').risks;
32
38
 
33
- var isLiveRisk = function isLiveRisk(data) {
34
- return ['recovered', 'closed'].indexOf(data.status) === -1;
35
- };
39
+ var risks = prevRisks.map(function (risk) {
40
+ var newRisk = receivedData.find(function (item) {
41
+ return item.id === risk.id;
42
+ });
43
+ return newRisk || risk;
44
+ }); // 新的
36
45
 
37
- var hasCiPermission = function hasCiPermission(data) {
38
- var _data$resourceId;
46
+ var addRisks = receivedData.filter(function (risk) {
47
+ return !prevRisks.find(function (item) {
48
+ return item.id === risk.id;
49
+ });
50
+ }).filter(hasCiPermission);
39
51
 
40
- var ciId = (_data$resourceId = data.resourceId) !== null && _data$resourceId !== void 0 ? _data$resourceId : data.ciId;
41
- var ci = topo.dataModel.getDataById(ciId);
42
- return ci && ci.operation;
43
- }; // 合并
52
+ (_risks = risks).push.apply(_risks, addRisks); // 过滤掉无权限、非在活的
44
53
 
45
54
 
46
- var risks = prevRisks.map(function (risk) {
47
- var newRisk = receivedData.find(function (item) {
48
- return item.id === risk.id;
49
- });
50
- return newRisk || risk;
51
- }); // 新的
55
+ risks = risks.filter(isLiveRisk).filter(hasCiPermission).sort(function (a, b) {
56
+ return a.executeTime - b.executeTime;
57
+ });
58
+ rlog.debug('更新风险', {
59
+ prevRisks: prevRisks,
60
+ receivedData: receivedData,
61
+ risks: risks
62
+ });
63
+ topo.store.getModelDispatchers('topoAlarm').update({
64
+ risks: risks
65
+ }); // 获取配置
52
66
 
53
- var addRisks = receivedData.filter(function (risk) {
54
- return !prevRisks.find(function (item) {
55
- return item.id === risk.id;
56
- });
57
- }).filter(hasCiPermission);
67
+ var _topo$store$getModelS = topo.store.getModelState('displayConfig'),
68
+ alarmSwitch = _topo$store$getModelS.alarmSwitch,
69
+ alarmListDefaultOpen = _topo$store$getModelS.alarmListDefaultOpen; // 告警静默
58
70
 
59
- (_risks = risks).push.apply(_risks, addRisks); // 过滤掉无权限、非在活的
60
71
 
72
+ if (alarmSwitch === false) {
73
+ return;
74
+ } // 告警列表
61
75
 
62
- risks = risks.filter(isLiveRisk).filter(hasCiPermission).sort(function (a, b) {
63
- return a.executeTime - b.executeTime;
64
- });
65
- rlog.debug('更新风险', {
66
- prevRisks: prevRisks,
67
- receivedData: receivedData,
68
- risks: risks
69
- });
70
- topo.store.getModelDispatchers('topoAlarm').update({
71
- risks: risks
76
+
77
+ if (addRisks.length && alarmListDefaultOpen) {
78
+ topo.alarm.updateState({
79
+ alarmPanelIsOpen: true
72
80
  });
81
+ }
73
82
 
74
- if (alarmSwitch === false) {
75
- // 告警静默
76
- return;
77
- }
83
+ if ((_topo$viewProps = topo.viewProps) !== null && _topo$viewProps !== void 0 && _topo$viewProps.onRisk) {
84
+ topo.viewProps.onRisk(risks);
85
+ }
78
86
 
79
- if (addRisks.length && alarmListDefaultOpen) {
80
- topo.alarm.updateState({
81
- alarmPanelIsOpen: true
82
- });
83
- }
87
+ if ((_topo$viewProps2 = topo.viewProps) !== null && _topo$viewProps2 !== void 0 && _topo$viewProps2.onResourceEvent) {
88
+ topo.viewProps.onResourceEvent(topo.alarm.getEvents());
89
+ }
90
+ };
91
+ /**
92
+ * 关联拓扑告警级别消息处理
93
+ * @param {*} topo
94
+ * @param {*} data
95
+ */
84
96
 
85
- if ((_topo$viewProps = topo.viewProps) !== null && _topo$viewProps !== void 0 && _topo$viewProps.onRisk) {
86
- topo.viewProps.onRisk(risks);
87
- }
88
97
 
89
- if ((_topo$viewProps2 = topo.viewProps) !== null && _topo$viewProps2 !== void 0 && _topo$viewProps2.onResourceEvent) {
90
- topo.viewProps.onResourceEvent(topo.alarm.getEvents());
91
- }
92
- };
98
+ var handleRelateTopoAlarm = function handleRelateTopoAlarm(topo, data) {
99
+ var relateTopoAlarm = _extends({}, topo.store.getModelState('topoAlarm').relateTopoAlarm);
93
100
 
94
- var handleRelateTopoAlarm = function handleRelateTopoAlarm(data) {
95
- var relateTopoAlarm = _extends({}, topo.store.getModelState('topoAlarm').relateTopoAlarm);
101
+ data.forEach(function (item) {
102
+ var alertLevel = item.alertLevel;
96
103
 
97
- data.forEach(function (item) {
104
+ if (alertLevel === -1) {
105
+ // -1表示删除
106
+ delete relateTopoAlarm[item.topoId];
107
+ } else {
98
108
  relateTopoAlarm[item.topoId] = item.alertLevel;
109
+ }
110
+ });
111
+ topo.store.getModelDispatchers('topoAlarm').update({
112
+ relateTopoAlarm: relateTopoAlarm
113
+ });
114
+ rlog.debug("\u5173\u8054\u62D3\u6251\u544A\u8B66\uFF1A\u6536\u5230 " + data.length, {
115
+ received: data,
116
+ all: relateTopoAlarm
117
+ });
118
+ };
119
+ /**
120
+ * 处理分级告警
121
+ * @param {*} alarms
122
+ * @returns
123
+ */
124
+
125
+
126
+ function convertAlarmData(alarms) {
127
+ return alarms.map(function (alarm) {
128
+ var resourceId = alarm.resourceId; // 分级资源id转换
129
+
130
+ if (alarm.cmpAlertId) {
131
+ resourceId = "sub:" + alarm.mainCiId;
132
+ }
133
+
134
+ return _extends({}, alarm, {
135
+ // 数据id
136
+ resourceId: resourceId,
137
+ // 是否在活
138
+ alive: isAlarmAlive(alarm)
99
139
  });
100
- topo.store.getModelDispatchers('topoAlarm').update({
101
- relateTopoAlarm: relateTopoAlarm
102
- });
103
- rlog.debug("\u5173\u8054\u62D3\u6251\u544A\u8B66\uFF1A\u6536\u5230 " + data.length, {
104
- received: data,
105
- all: relateTopoAlarm
106
- });
107
- }; // 订阅消息
140
+ });
141
+ }
142
+ /**
143
+ *
144
+ *
145
+ * @param {*} options
146
+ */
147
+
148
+
149
+ export default function useAlarm(options) {
150
+ var topo = options.topo;
151
+
152
+ var _topo$store$useModelS = topo.store.useModelState('displayConfig'),
153
+ alarmSwitch = _topo$store$useModelS.alarmSwitch;
108
154
 
155
+ useGraphAlarmDisplay({
156
+ topo: topo,
157
+ alarmSwitch: alarmSwitch
158
+ }); // 订阅消息
109
159
 
110
160
  useTopoEventListener({
111
161
  type: 'alarm',
112
162
  onMessage: function onMessage(data) {
113
163
  rlog.debug("Topoget--AlertMesage------------", topo, data);
114
- topo.alarm.handleAlarmEvent(data);
164
+ topo.alarm.handleAlarmEvent(convertAlarmData(data));
115
165
  }
116
166
  });
117
167
  useTopoEventListener({
118
168
  type: 'risk',
119
169
  onMessage: function onMessage(data) {
120
- handleRiskData(data);
170
+ handleRiskData(topo, data);
121
171
  }
122
172
  });
123
173
  useTopoEventListener({
124
174
  type: 'relateTopoAlarm',
125
175
  onMessage: function onMessage(data) {
126
- handleRelateTopoAlarm(data);
176
+ handleRelateTopoAlarm(topo, data);
127
177
  }
128
178
  });
129
179
  }
@@ -0,0 +1,153 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _extends from "@babel/runtime/helpers/extends";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import { useEffect, useState, useMemo } from "react";
5
+ import { useRequest } from 'ahooks';
6
+ import DictCache from "../models/cache/DictCache";
7
+
8
+ function addCmpLinkOfflineStatusForDisplayLineColor(cis, cmpLinkRunStatusList) {
9
+ return cis.map(function (ci) {
10
+ var cmpLinkRunStatusData = cmpLinkRunStatusList.find(function (item) {
11
+ return item.id === ci.id;
12
+ });
13
+
14
+ if (cmpLinkRunStatusData) {
15
+ return _extends({}, ci, {
16
+ manageStatus: cmpLinkRunStatusData.runStatus === '2' ? 0 : 3
17
+ });
18
+ }
19
+
20
+ return ci;
21
+ });
22
+ }
23
+
24
+ function getCmpLinIds(datas) {
25
+ var linkIds = datas.filter(function (item) {
26
+ return item.isSubResource && item.typeCode === 'network_link';
27
+ }).map(function (item) {
28
+ return item.ciId;
29
+ });
30
+ return linkIds;
31
+ }
32
+ /**
33
+ * 分级链路下級鏈路
34
+ * @param {*} props
35
+ * @returns
36
+ */
37
+
38
+
39
+ export default function useCmpLinkAlarm(props) {
40
+ var topo = props.topo,
41
+ resources = props.resources,
42
+ graphLoaded = props.graphLoaded;
43
+
44
+ var _useState = useState(getCmpLinIds(resources)),
45
+ cmpLinkIds = _useState[0],
46
+ setCmpLinkIds = _useState[1];
47
+
48
+ var _useState2 = useState([]),
49
+ cmpLinkRunStatus = _useState2[0],
50
+ setCmpLinkRunStatus = _useState2[1];
51
+
52
+ var cmpLinkAlarmLevels = useMemo(function () {
53
+ return cmpLinkRunStatus // 3:fault:重要故障; 4:urgently:紧急故障 』为红色
54
+ .filter(function (item) {
55
+ return ['3', '4'].includes(item.runStatus);
56
+ }).map(function (item) {
57
+ return {
58
+ id: item.id,
59
+ level: 1
60
+ };
61
+ });
62
+ }, [cmpLinkRunStatus]);
63
+ useEffect(function () {
64
+ var ids = getCmpLinIds(resources);
65
+
66
+ if (cmpLinkIds.join(',') !== ids.join(',')) {
67
+ setCmpLinkIds(ids);
68
+ }
69
+ }, [resources]);
70
+
71
+ function getCmpLinkRunStatus(_x) {
72
+ return _getCmpLinkRunStatus.apply(this, arguments);
73
+ } // 轮询hooks
74
+
75
+
76
+ function _getCmpLinkRunStatus() {
77
+ _getCmpLinkRunStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(ids) {
78
+ var _yield$Promise$all, ciMetricsResult;
79
+
80
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
81
+ while (1) switch (_context.prev = _context.next) {
82
+ case 0:
83
+ if (ids.length) {
84
+ _context.next = 2;
85
+ break;
86
+ }
87
+
88
+ return _context.abrupt("return", []);
89
+
90
+ case 2:
91
+ _context.t0 = Promise;
92
+ _context.t1 = // 查询指标值
93
+ topo.serverApi.ciInfo.batchQueryCiInfo({
94
+ ciId: [],
95
+ codes: ['run_status'],
96
+ relationId: ids.map(function (id) {
97
+ return {
98
+ ciId: id,
99
+ operation: "delete"
100
+ };
101
+ })
102
+ });
103
+ _context.next = 6;
104
+ return DictCache.init();
105
+
106
+ case 6:
107
+ _context.t2 = _context.sent;
108
+ _context.t3 = [_context.t1, _context.t2];
109
+ _context.next = 10;
110
+ return _context.t0.all.call(_context.t0, _context.t3);
111
+
112
+ case 10:
113
+ _yield$Promise$all = _context.sent;
114
+ ciMetricsResult = _yield$Promise$all[0];
115
+ return _context.abrupt("return", ciMetricsResult);
116
+
117
+ case 13:
118
+ case "end":
119
+ return _context.stop();
120
+ }
121
+ }, _callee);
122
+ }));
123
+ return _getCmpLinkRunStatus.apply(this, arguments);
124
+ }
125
+
126
+ var _useRequest = useRequest(getCmpLinkRunStatus, {
127
+ pollingInterval: 60 * 1000,
128
+ pollingWhenHidden: false,
129
+ // debounceInterval: 200,
130
+ manual: true,
131
+ onSuccess: function onSuccess(result) {
132
+ setCmpLinkRunStatus(result.map(function (item) {
133
+ return {
134
+ id: "sub:" + item.id,
135
+ runStatus: item.metrics.run_status
136
+ };
137
+ }));
138
+ }
139
+ }),
140
+ run = _useRequest.run;
141
+
142
+ useEffect(function () {
143
+ if (graphLoaded) {
144
+ run(cmpLinkIds);
145
+ }
146
+ }, [graphLoaded, cmpLinkIds]);
147
+ return {
148
+ cmpLinkRunStatus: cmpLinkRunStatus,
149
+ cmpLinkAlarmLevels: cmpLinkAlarmLevels,
150
+ addCmpLinkOfflineStatusForDisplayLineColor: addCmpLinkOfflineStatusForDisplayLineColor
151
+ };
152
+ }
153
+ ;
@@ -1,7 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  export default function useEventData(props) {
3
- var topo = props.topo;
4
- var topoDatas = topo.dataModel.useDatas();
3
+ var topo = props.topo; // const topoDatas = topo.dataModel.useDatas()
5
4
 
6
5
  var _topo$store$useModelS = topo.store.useModelState('topoAlarm'),
7
6
  risks = _topo$store$useModelS.risks,
@@ -1,18 +1,18 @@
1
- import { useEffect } from "react";
1
+ import { useEffect, useMemo } from "react";
2
2
  import rlog from "@riil-frontend/component-topology-utils/es/rlog";
3
3
  import { getElements } from "../../utils/htElementUtils";
4
4
  import { removeManageStatus, showManageStatus } from "../utils/showGraphManageStatusUtil";
5
+ import useCmpLinkAlarm from "./useCmpLinkAlarm";
6
+ /**
7
+ * 获取ci的最高告警级别
8
+ * @param {Array} alarmList
9
+ * @param {*} risks
10
+ * @returns
11
+ */
5
12
 
6
- function getCiAlarmLevels(alarmList, risks) {
13
+ function getCiAlarmLevelMap(alarmList) {
7
14
  var ciIdLevelMap = {};
8
- [].concat(alarmList, risks.map(function (item) {
9
- var _item$resourceId;
10
-
11
- return {
12
- id: (_item$resourceId = item.resourceId) !== null && _item$resourceId !== void 0 ? _item$resourceId : item.ciId,
13
- level: 5
14
- };
15
- })).forEach(function (item) {
15
+ alarmList.forEach(function (item) {
16
16
  var level = ciIdLevelMap[item.id]; // 优先显示高等级告警。值小的等级高
17
17
 
18
18
  if (!level || item.level < level) {
@@ -21,13 +21,53 @@ function getCiAlarmLevels(alarmList, risks) {
21
21
 
22
22
  ciIdLevelMap[item.id] = level;
23
23
  });
24
+ return ciIdLevelMap;
25
+ }
26
+
27
+ function getGraphCiElementAlarmLevels(resources, alarmList) {
28
+ var ciIdLevelMap = getCiAlarmLevelMap(alarmList);
24
29
  return Object.keys(ciIdLevelMap).map(function (id) {
25
30
  return {
26
31
  id: id,
27
32
  level: ciIdLevelMap[id]
28
33
  };
34
+ }).filter(function (alarm) {
35
+ var resource = resources.find(function (item) {
36
+ return item.id === alarm.id;
37
+ });
38
+ return !!resource;
29
39
  });
30
40
  }
41
+ /**
42
+ * 获得关联拓扑节点告警级别
43
+ * @param {*} topo
44
+ * @param {*} relateTopoAlarm
45
+ * @returns
46
+ */
47
+
48
+
49
+ function getRelateTopoNodeAlarmLevels(topo, relateTopoAlarm) {
50
+ return Object.keys(relateTopoAlarm).map(function (topoId) {
51
+ var level = relateTopoAlarm[topoId];
52
+ var relateTopoNode = topo.getDataModel().getDatas().toArray().find(function (node) {
53
+ return "" + node.a('bindTopo') === "" + topoId;
54
+ });
55
+
56
+ if (!level || !relateTopoNode) {
57
+ return null;
58
+ }
59
+
60
+ return {
61
+ elementId: relateTopoNode.getId(),
62
+ level: level
63
+ };
64
+ }).filter(function (item) {
65
+ return !!item;
66
+ });
67
+ } // 获取拓扑图元素最高告警级别。包含资源、链路、关联拓扑节点
68
+
69
+
70
+ function getGraphElementAlarmLevels(resources) {}
31
71
  /**
32
72
  * 告警显示到ht拓扑
33
73
  *
@@ -38,7 +78,6 @@ function getCiAlarmLevels(alarmList, risks) {
38
78
  export default function useGraphAlarmDisplay(options) {
39
79
  var topo = options.topo,
40
80
  alarmSwitch = options.alarmSwitch;
41
- var store = topo.store;
42
81
  var topoState = topo.store.useModelState('topoMod');
43
82
  var graphLoaded = topoState.graphLoaded,
44
83
  viewState = topoState.viewState;
@@ -49,22 +88,32 @@ export default function useGraphAlarmDisplay(options) {
49
88
  risks = _topo$alarm$useState.risks,
50
89
  relateTopoAlarm = _topo$alarm$useState.relateTopoAlarm;
51
90
 
52
- var resources = topo.dataModel.useCis();
53
-
54
- function getCisEventLevel() {
55
- return getCiAlarmLevels(alarmList || [], risks).filter(function (alarm) {
56
- var resource = resources.find(function (item) {
57
- return item.id === alarm.id;
58
- });
59
-
60
- if (!resource) {
61
- return false;
62
- }
63
-
64
- return true;
65
- });
66
- }
67
-
91
+ var oldResources = topo.dataModel.useCis(); // 分级拓扑下级链路特殊处理
92
+
93
+ var _useCmpLinkAlarm = useCmpLinkAlarm({
94
+ topo: topo,
95
+ resources: oldResources,
96
+ graphLoaded: graphLoaded
97
+ }),
98
+ cmpLinkAlarmLevels = _useCmpLinkAlarm.cmpLinkAlarmLevels,
99
+ cmpLinkRunStatus = _useCmpLinkAlarm.cmpLinkRunStatus,
100
+ addCmpLinkOfflineStatusForDisplayLineColor = _useCmpLinkAlarm.addCmpLinkOfflineStatusForDisplayLineColor;
101
+
102
+ var resources = useMemo(function () {
103
+ return addCmpLinkOfflineStatusForDisplayLineColor(oldResources, cmpLinkRunStatus);
104
+ }, [oldResources, cmpLinkRunStatus]); // ci告警级别
105
+
106
+ var cisEventLevel = useMemo(function () {
107
+ var levels = [].concat(alarmList || [], cmpLinkAlarmLevels, risks.map(function (item) {
108
+ var _item$resourceId;
109
+
110
+ return {
111
+ id: (_item$resourceId = item.resourceId) !== null && _item$resourceId !== void 0 ? _item$resourceId : item.ciId,
112
+ level: 5
113
+ };
114
+ }));
115
+ return getGraphCiElementAlarmLevels(resources, levels);
116
+ }, [resources, alarmList, cmpLinkAlarmLevels, risks]);
68
117
  useEffect(function () {
69
118
  showAlarm();
70
119
  showManageStatus({
@@ -72,8 +121,8 @@ export default function useGraphAlarmDisplay(options) {
72
121
  resources: resources,
73
122
  isEditMode: isEditMode,
74
123
  graphLoaded: graphLoaded,
75
- // 有告警且未监控时,此时开启告警静默,应当显示未监控图标
76
- cisEventLevel: alarmSwitch === false ? [] : getCisEventLevel()
124
+ alarmSwitch: alarmSwitch,
125
+ cisEventLevel: cisEventLevel
77
126
  });
78
127
 
79
128
  function showAlarm() {
@@ -85,43 +134,29 @@ export default function useGraphAlarmDisplay(options) {
85
134
  // 告警静默
86
135
  topo.view.loadAlarm([]);
87
136
  return;
88
- }
137
+ } // 关联拓扑告警
138
+
89
139
 
90
- var finalAlarms = getCisEventLevel(); // 将告警级别放入ht元素,便于测试
140
+ var relateTopoAlarms = getRelateTopoNodeAlarmLevels(topo, relateTopoAlarm);
141
+ var elementsAlarmLevels = [].concat(cisEventLevel, relateTopoAlarms); // 将告警级别放入ht元素,便于测试
91
142
 
92
143
  getElements(topo.getDataModel()).filter(function (item) {
93
144
  return !!item.getTag();
94
145
  }).forEach(function (element) {
95
- var _finalAlarms$find;
146
+ var _elementsAlarmLevels$;
96
147
 
97
- var alarmLevel = (_finalAlarms$find = finalAlarms.find(function (item) {
98
- return item.id === element.getTag();
99
- })) === null || _finalAlarms$find === void 0 ? void 0 : _finalAlarms$find.level;
148
+ var alarmLevel = (_elementsAlarmLevels$ = elementsAlarmLevels.find(function (item) {
149
+ return item.id === element.getTag() || item.elementId === element.getId();
150
+ })) === null || _elementsAlarmLevels$ === void 0 ? void 0 : _elementsAlarmLevels$.level;
100
151
  element.a('alarmLevel', alarmLevel);
101
152
  });
102
- var relateTopoAlarms = Object.keys(relateTopoAlarm).map(function (topoId) {
103
- var level = relateTopoAlarm[topoId];
104
- var relateTopoNode = topo.getDataModel().getDatas().toArray().find(function (node) {
105
- return "" + node.a('bindTopo') === "" + topoId;
106
- });
107
-
108
- if (!level || !relateTopoNode) {
109
- return null;
110
- }
111
-
112
- return {
113
- elementId: relateTopoNode.getId(),
114
- level: level
115
- };
116
- }).filter(function (item) {
117
- return !!item;
118
- });
119
- rlog.debug('关联拓扑告警:推送ht', {
120
- all: relateTopoAlarm,
153
+ rlog.debug('推送告警 => ht', {
154
+ alarms: elementsAlarmLevels,
155
+ relateTopoAlarmMap: relateTopoAlarm,
121
156
  relateTopoAlarms: relateTopoAlarms
122
157
  }); // 更新到ht拓扑
123
158
 
124
- topo.view.loadAlarm([].concat(finalAlarms, relateTopoAlarms));
159
+ topo.view.loadAlarm(elementsAlarmLevels);
125
160
  }
126
161
 
127
162
  return function () {
@@ -130,5 +165,5 @@ export default function useGraphAlarmDisplay(options) {
130
165
  resources: resources
131
166
  });
132
167
  };
133
- }, [graphLoaded, resources, alarmSwitch, alarmList, risks, relateTopoAlarm]);
168
+ }, [graphLoaded, resources, alarmSwitch, cisEventLevel, relateTopoAlarm]);
134
169
  }
@@ -42,9 +42,7 @@ export default function (props) {
42
42
  return {
43
43
  resources: config.resources,
44
44
  groups: config.groups,
45
- exportLinkIdList: config.exportLinkIdList,
46
- relateTopoIdList: config.relateTopoIdList //linkIps: config.linkIps,
47
-
45
+ relateTopoIdList: config.relateTopoIdList
48
46
  };
49
47
  };
50
48