@riil-frontend/component-topology 8.0.8 → 8.0.10

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.
@@ -0,0 +1,78 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { queryCisByIds } from "../../services";
4
+ /**
5
+ * Ci缓存
6
+ */
7
+
8
+ var CiCache = /*#__PURE__*/function () {
9
+ function CiCache() {
10
+ this.ciMap = {};
11
+ }
12
+
13
+ var _proto = CiCache.prototype;
14
+
15
+ /**
16
+ *
17
+ * @param ids {string[]}
18
+ * @returns {Promise<Object>}
19
+ */
20
+ _proto.load =
21
+ /*#__PURE__*/
22
+ function () {
23
+ var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(ids) {
24
+ var _this = this;
25
+
26
+ var unloadCiIds, cis, map;
27
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
28
+ while (1) {
29
+ switch (_context.prev = _context.next) {
30
+ case 0:
31
+ unloadCiIds = ids.filter(function (id) {
32
+ return !_this.ciMap[id];
33
+ });
34
+
35
+ if (!unloadCiIds.length) {
36
+ _context.next = 6;
37
+ break;
38
+ }
39
+
40
+ _context.next = 4;
41
+ return queryCisByIds(unloadCiIds);
42
+
43
+ case 4:
44
+ cis = _context.sent;
45
+ cis.forEach(function (ci) {
46
+ _this.ciMap[ci.id] = ci;
47
+ });
48
+
49
+ case 6:
50
+ map = {};
51
+ ids.forEach(function (id) {
52
+ map[id] = _this.ciMap[id];
53
+ });
54
+ return _context.abrupt("return", this.ciMap);
55
+
56
+ case 9:
57
+ case "end":
58
+ return _context.stop();
59
+ }
60
+ }
61
+ }, _callee, this);
62
+ }));
63
+
64
+ function load(_x) {
65
+ return _load.apply(this, arguments);
66
+ }
67
+
68
+ return load;
69
+ }();
70
+
71
+ _proto.getCi = function getCi(id) {
72
+ return this.ciMap[id];
73
+ };
74
+
75
+ return CiCache;
76
+ }();
77
+
78
+ export default new CiCache();
@@ -6,7 +6,8 @@ import _ from 'lodash';
6
6
  import { queryCisByIds, queryModelAsset } from "../../services"; // 查询所有连线
7
7
 
8
8
  import { getEdges } from "../../../utils/htElementUtils";
9
- import CiTypeCache from "../cache/CiTypeCache"; // const interfaceTypeMap = {
9
+ import CiTypeCache from "../cache/CiTypeCache";
10
+ import CiCache from "../cache/CiCache"; // const interfaceTypeMap = {
10
11
  // "network.interface": {
11
12
  // displayName: "网络接口",
12
13
  // },
@@ -33,10 +34,10 @@ export function isCrucialLink(link) {
33
34
  export function isExitLink(link) {
34
35
  return (link === null || link === void 0 ? void 0 : link.attributes) && !(link !== null && link !== void 0 && link.attributes['destination_id']);
35
36
  }
36
- export function mergeLinksData(links, linkCis, nodes, interfaceCis, interfaceDoc) {
37
+ export function mergeLinksData(links, linkCis, nodes, interfaceCiMap, interfaceDoc) {
37
38
  var linkCiMap = keyBy(links, 'id');
38
39
  return links.map(function (link) {
39
- var _interfaceCis$find, _interfaceCis$find2;
40
+ var _interfaceCiMap$attri, _interfaceCiMap$attri2;
40
41
 
41
42
  var linkCi = linkCiMap[link.id];
42
43
 
@@ -63,14 +64,10 @@ export function mergeLinksData(links, linkCis, nodes, interfaceCis, interfaceDoc
63
64
  destination_type_object: interfaceDoc[attributes.destination_type],
64
65
  // 源/目的接口
65
66
  source_id_object: {
66
- displayName: (_interfaceCis$find = interfaceCis.find(function (node) {
67
- return node.id === attributes.source_id;
68
- })) === null || _interfaceCis$find === void 0 ? void 0 : _interfaceCis$find.attributes['display_name']
67
+ displayName: (_interfaceCiMap$attri = interfaceCiMap[attributes.source_id]) === null || _interfaceCiMap$attri === void 0 ? void 0 : _interfaceCiMap$attri.attributes['display_name']
69
68
  },
70
69
  destination_id_object: {
71
- displayName: (_interfaceCis$find2 = interfaceCis.find(function (node) {
72
- return node.id === attributes.destination_id;
73
- })) === null || _interfaceCis$find2 === void 0 ? void 0 : _interfaceCis$find2.attributes['display_name']
70
+ displayName: (_interfaceCiMap$attri2 = interfaceCiMap[attributes.destination_id]) === null || _interfaceCiMap$attri2 === void 0 ? void 0 : _interfaceCiMap$attri2.attributes['display_name']
74
71
  }
75
72
  })
76
73
  });
@@ -82,7 +79,7 @@ export function getLinksDetail(_x, _x2) {
82
79
 
83
80
  function _getLinksDetail() {
84
81
  _getLinksDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(links, nodes) {
85
- var linkCis, interfaceIds, interfaceTypes, interfaceCis, interfaceDoc;
82
+ var linkCis, interfaceIds, interfaceTypes, interfaceCiMap, interfaceDoc;
86
83
  return _regeneratorRuntime.wrap(function _callee$(_context) {
87
84
  while (1) {
88
85
  switch (_context.prev = _context.next) {
@@ -112,16 +109,16 @@ function _getLinksDetail() {
112
109
  return item !== 'ip';
113
110
  });
114
111
  _context.next = 7;
115
- return queryCisByIds(interfaceIds);
112
+ return CiCache.load(interfaceIds);
116
113
 
117
114
  case 7:
118
- interfaceCis = _context.sent;
115
+ interfaceCiMap = _context.sent;
119
116
  _context.next = 10;
120
117
  return CiTypeCache.getCiTypeMap(interfaceTypes);
121
118
 
122
119
  case 10:
123
120
  interfaceDoc = _context.sent;
124
- return _context.abrupt("return", mergeLinksData(links, linkCis, nodes, interfaceCis, interfaceDoc));
121
+ return _context.abrupt("return", mergeLinksData(links, linkCis, nodes, interfaceCiMap, interfaceDoc));
125
122
 
126
123
  case 12:
127
124
  case "end":
@@ -6,6 +6,10 @@ import rlog from '@riil-frontend/component-topology-utils/es/rlog';
6
6
  export default function (engine) {
7
7
  return {
8
8
  state: {
9
+ /**
10
+ * 格式:{id1: {attributes: {}}}
11
+ */
12
+ ciMap: {},
9
13
  // 指标默认设置
10
14
  resAndMetrics: {},
11
15
  metricDoc: {},
package/es/style.js CHANGED
@@ -3,10 +3,10 @@ import '@alifd/next/es/box/style';
3
3
  import '@alifd/next/es/message/style';
4
4
  import '@riil-frontend/component-topology-utils/es/style';
5
5
  import '@riil-frontend/component-riil-event-emitter/es/style';
6
+ import '@riil-frontend/utils/es/style';
6
7
  import '@alifd/next/es/drawer/style';
7
8
  import '@alifd/next/es/menu-button/style';
8
9
  import '@alifd/next/es/search/style';
9
- import '@riil-frontend/utils/es/style';
10
10
  import '@alifd/next/es/tab/style';
11
11
  import '@alifd/next/es/table/style';
12
12
  import '@riil-frontend/component-table-layout/es/style';
@@ -37,7 +37,7 @@ var LINE_TYPE_OPTIONS = [{
37
37
  label: '双折线',
38
38
  icon: 'topo_linear_icon_bilinear'
39
39
  }, {
40
- value: 'flex',
40
+ value: 'doublearc',
41
41
  label: '双弧线',
42
42
  icon: 'topo_linear_icon_arcline'
43
43
  }];
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports["default"] = useCiAttributeChange;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-utils/es/rlog"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _CiCache = _interopRequireDefault(require("../models/cache/CiCache"));
15
+
16
+ var _useTopoEventListener = _interopRequireDefault(require("./useTopoEventListener"));
17
+
18
+ function mergeData(cis, ciChangeData) {
19
+ if (!cis.find(function (item) {
20
+ return item.id === ciChangeData.id;
21
+ })) {
22
+ return cis;
23
+ }
24
+
25
+ return cis.map(function (ci) {
26
+ if (ci.id === ciChangeData.id) {
27
+ return (0, _extends2["default"])({}, ci, {
28
+ attributes: (0, _extends2["default"])({}, ci.attributes, ciChangeData.attributes)
29
+ });
30
+ }
31
+
32
+ return ci;
33
+ });
34
+ }
35
+ /**
36
+ * 监听ci属性变更
37
+ *
38
+ * @param {*} props
39
+ */
40
+
41
+
42
+ function useCiAttributeChange(props) {
43
+ var topo = props.topo;
44
+ (0, _useTopoEventListener["default"])({
45
+ type: 'attribute',
46
+ onMessage: function onMessage(ciChangeData) {
47
+ // 更新拓扑数据
48
+ var topoData = topo.store.getModelState('topoMod').data;
49
+
50
+ if (topoData) {
51
+ var newData = (0, _extends2["default"])({}, topoData, {
52
+ nodes: mergeData(topoData.nodes, ciChangeData),
53
+ links: mergeData(topoData.links, ciChangeData),
54
+ linkGroups: mergeData(topoData.linkGroups, ciChangeData)
55
+ });
56
+ var topoDispatchers = topo.store.getModelDispatchers('topoMod');
57
+ topoDispatchers.update({
58
+ data: newData
59
+ });
60
+ } // 更新缓存
61
+
62
+
63
+ var ci = _CiCache["default"].getCi(ciChangeData.id);
64
+
65
+ if (ci) {
66
+ ci.attributes = (0, _extends2["default"])({}, ci.attributes, ciChangeData.attributes);
67
+ }
68
+ }
69
+ });
70
+ }
@@ -7,10 +7,10 @@ exports["default"] = void 0;
7
7
 
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
 
10
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
-
12
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
11
 
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
14
  var _react = require("react");
15
15
 
16
16
  var _ahooks = require("ahooks");
@@ -19,6 +19,14 @@ var _lodash = _interopRequireDefault(require("lodash"));
19
19
 
20
20
  var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-utils/es/rlog"));
21
21
 
22
+ var _topo = _interopRequireDefault(require("@riil-frontend/component-topology-common/es/services/topo"));
23
+
24
+ var _componentRiilEventEmitter = require("@riil-frontend/component-riil-event-emitter");
25
+
26
+ var _DictCache = _interopRequireDefault(require("../models/cache/DictCache"));
27
+
28
+ var _useCiAttributeChange = _interopRequireDefault(require("./useCiAttributeChange"));
29
+
22
30
  /**
23
31
  * 轮询获取指标hooks
24
32
  * @param {*} props
@@ -26,12 +34,156 @@ var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-ut
26
34
  var usePolling = function usePolling(props) {
27
35
  var topo = props.topo;
28
36
  var store = topo.store;
37
+ (0, _useCiAttributeChange["default"])({
38
+ topo: topo
39
+ });
29
40
  var bizState = store.useModelState('topoBizMod');
30
41
  var resAndMetrics = bizState.resAndMetrics,
31
42
  pollingSwitch = bizState.pollingSwitch;
32
43
  var displayConfig = topo.store.useModelState('displayConfig');
33
44
  var resourceOverviewState = topo.store.useModelState('topoBaseInfoOverview');
34
- var resIdsList = resAndMetrics === null || resAndMetrics === void 0 ? void 0 : resAndMetrics.resIdsList; // 轮询hooks
45
+ var resIdsList = resAndMetrics === null || resAndMetrics === void 0 ? void 0 : resAndMetrics.resIdsList;
46
+ /**
47
+ * 查询拓扑图资源的属性指标
48
+ *
49
+ * @returns {array}
50
+ */
51
+
52
+ function fetchData() {
53
+ return _fetchData.apply(this, arguments);
54
+ }
55
+ /**
56
+ *
57
+ * @returns {{id, attributes: object[], metrics: object[]}[]} 属性和指标
58
+ */
59
+
60
+
61
+ function _fetchData() {
62
+ _fetchData = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
63
+ var _topo$store$getModelS, resIdsList, nodeIdsList, codes, param, _yield$Promise$all, ciMetricResult, transformLinkData;
64
+
65
+ return _regenerator["default"].wrap(function _callee$(_context) {
66
+ while (1) {
67
+ switch (_context.prev = _context.next) {
68
+ case 0:
69
+ transformLinkData = function _transformLinkData(data) {
70
+ var _topo$dataModel$getDa = topo.dataModel.getData(),
71
+ links = _topo$dataModel$getDa.links,
72
+ linkGroups = _topo$dataModel$getDa.linkGroups;
73
+
74
+ var link = [].concat(links, linkGroups).find(function (item) {
75
+ return item.id === data.id;
76
+ });
77
+
78
+ if (!link) {
79
+ return data;
80
+ }
81
+
82
+ return (0, _extends2["default"])({}, data, {
83
+ attributeMap: link.attributes || {}
84
+ });
85
+ };
86
+
87
+ _topo$store$getModelS = topo.store.getModelState('topoBizMod').resAndMetrics, resIdsList = _topo$store$getModelS.resIdsList, nodeIdsList = _topo$store$getModelS.nodeIdsList; // rlog.debug('根据ci的id获取属性的值-getCiArrByIds', resIdsList, metrics);
88
+ // 无资源,不查询
89
+
90
+ if (resIdsList.length) {
91
+ _context.next = 4;
92
+ break;
93
+ }
94
+
95
+ return _context.abrupt("return", []);
96
+
97
+ case 4:
98
+ // 需要查询的指标列表
99
+ codes = topo.attributeMetricDisplay.getResourceMetricCodes();
100
+ param = {
101
+ ciId: nodeIdsList,
102
+ codes: codes,
103
+ // 过滤掉不需要查询的
104
+ relationId: topo.attributeMetricDisplay.getEdges().map(function (edge) {
105
+ return {
106
+ ciId: edge.id,
107
+ operation: edge.operation
108
+ };
109
+ })
110
+ };
111
+ _context.t0 = Promise;
112
+ _context.t1 = // 查询指标值
113
+ _topo["default"].ciInfo.batchQueryCiInfo(param);
114
+ _context.next = 10;
115
+ return _DictCache["default"].init();
116
+
117
+ case 10:
118
+ _context.t2 = _context.sent;
119
+ _context.t3 = [_context.t1, _context.t2];
120
+ _context.next = 14;
121
+ return _context.t0.all.call(_context.t0, _context.t3);
122
+
123
+ case 14:
124
+ _yield$Promise$all = _context.sent;
125
+ ciMetricResult = _yield$Promise$all[0];
126
+ return _context.abrupt("return", ciMetricResult.map(function (data) {
127
+ var ci = topo.dataModel.getDataById(data.id);
128
+ var resultData = (0, _extends2["default"])({}, data, ci, {
129
+ attributeMap: (0, _extends2["default"])({}, (ci === null || ci === void 0 ? void 0 : ci.attributes) || {})
130
+ });
131
+ resultData = transformLinkData(resultData); // 特殊处理:ipv6 从ipv6_address_list取第一个
132
+
133
+ // 特殊处理:ipv6 从ipv6_address_list取第一个
134
+ if (resultData.attributeMap.ipv6_address_list && !resultData.attributeMap.ipv6_address) {
135
+ resultData.attributeMap.ipv6_address = (resultData.attributeMap.ipv6_address_list || '').split(',')[0];
136
+ }
137
+
138
+ return resultData;
139
+ }));
140
+
141
+ case 17:
142
+ case "end":
143
+ return _context.stop();
144
+ }
145
+ }
146
+ }, _callee);
147
+ }));
148
+ return _fetchData.apply(this, arguments);
149
+ }
150
+
151
+ function refresh() {
152
+ return _refresh.apply(this, arguments);
153
+ } // 轮询hooks
154
+
155
+
156
+ function _refresh() {
157
+ _refresh = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
158
+ var data;
159
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
160
+ while (1) {
161
+ switch (_context2.prev = _context2.next) {
162
+ case 0:
163
+ if (!(!pollingSwitch || !(resAndMetrics !== null && resAndMetrics !== void 0 && resAndMetrics.resIdsList.length))) {
164
+ _context2.next = 2;
165
+ break;
166
+ }
167
+
168
+ return _context2.abrupt("return");
169
+
170
+ case 2:
171
+ _context2.next = 4;
172
+ return fetchData();
173
+
174
+ case 4:
175
+ data = _context2.sent;
176
+ return _context2.abrupt("return", data);
177
+
178
+ case 6:
179
+ case "end":
180
+ return _context2.stop();
181
+ }
182
+ }
183
+ }, _callee2);
184
+ }));
185
+ return _refresh.apply(this, arguments);
186
+ }
35
187
 
36
188
  var _useRequest = (0, _ahooks.useRequest)(refresh, {
37
189
  pollingInterval: 60 * 1000,
@@ -42,30 +194,13 @@ var usePolling = function usePolling(props) {
42
194
  if (result) {
43
195
  var dd = _lodash["default"].cloneDeep(result);
44
196
 
45
- topo.attributeMetricDisplay.loadAttributeAndMetric(dd);
197
+ topo.attributeMetricDisplay.loadData(dd);
46
198
  }
47
199
  }
48
200
  }),
49
201
  loading = _useRequest.loading,
50
202
  startPoll = _useRequest.run,
51
- stopPoll = _useRequest.cancel;
52
-
53
- function convertData(data) {
54
- return data.map(function (item) {
55
- return (0, _extends2["default"])({}, item, {
56
- attributes: convertAttrMap(item.attributes),
57
- metrics: convertAttrMap(item.metrics)
58
- });
59
- });
60
- }
61
-
62
- function convertAttrMap(attrs) {
63
- var map = {};
64
- attrs.forEach(function (attr) {
65
- map[attr.code] = attr.value;
66
- });
67
- return map;
68
- } // 需要刷新数据的场景:显示模式、资源变化、配置变化、开关开启、概览
203
+ stopPoll = _useRequest.cancel; // 需要刷新数据的场景:显示模式、资源变化、配置变化、开关开启、概览
69
204
 
70
205
 
71
206
  (0, _react.useEffect)(function () {
@@ -87,46 +222,16 @@ var usePolling = function usePolling(props) {
87
222
  stopPoll();
88
223
  }
89
224
  };
90
- }, [pollingSwitch, resIdsList, displayConfig, resourceOverviewState.id, resourceOverviewState.metricCodes]);
91
- /**
92
- *
93
- * @returns {{id, attributes: object[], metrics: object[]}[]} 属性和指标
94
- */
95
-
96
- function refresh() {
97
- return _refresh.apply(this, arguments);
98
- }
99
-
100
- function _refresh() {
101
- _refresh = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
102
- return _regenerator["default"].wrap(function _callee$(_context) {
103
- while (1) {
104
- switch (_context.prev = _context.next) {
105
- case 0:
106
- if (!(!pollingSwitch || !(resAndMetrics !== null && resAndMetrics !== void 0 && resAndMetrics.resIdsList.length))) {
107
- _context.next = 2;
108
- break;
109
- }
110
-
111
- return _context.abrupt("return");
112
-
113
- case 2:
114
- _context.next = 4;
115
- return topo.attributeMetricDisplay.fetchData();
116
-
117
- case 4:
118
- return _context.abrupt("return", _context.sent);
119
-
120
- case 5:
121
- case "end":
122
- return _context.stop();
123
- }
124
- }
125
- }, _callee);
126
- }));
127
- return _refresh.apply(this, arguments);
128
- }
225
+ }, [pollingSwitch, resIdsList, displayConfig, resourceOverviewState.id, resourceOverviewState.metricCodes]); // 属性变更监听更新
129
226
 
227
+ (0, _componentRiilEventEmitter.useCbbEventListener)('topo', {
228
+ name: 'topo',
229
+ onMessage: function onMessage(message) {
230
+ if (message.type === 'attribute') {
231
+ var data = message.data;
232
+ }
233
+ }
234
+ });
130
235
  return {
131
236
  startPoll: startPoll,
132
237
  stopPoll: stopPoll