@next-libs/cmdb-instances 6.6.1 → 6.6.5

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,44 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [6.6.5](https://github.com/easyops-cn/next-libs/compare/@next-libs/cmdb-instances@6.6.4...@next-libs/cmdb-instances@6.6.5) (2021-10-13)
7
+
8
+ **Note:** Version bump only for package @next-libs/cmdb-instances
9
+
10
+
11
+
12
+
13
+
14
+ ## [6.6.4](https://github.com/easyops-cn/next-libs/compare/@next-libs/cmdb-instances@6.6.3...@next-libs/cmdb-instances@6.6.4) (2021-10-11)
15
+
16
+ **Note:** Version bump only for package @next-libs/cmdb-instances
17
+
18
+
19
+
20
+
21
+
22
+ ## [6.6.3](https://github.com/easyops-cn/next-libs/compare/@next-libs/cmdb-instances@6.6.2...@next-libs/cmdb-instances@6.6.3) (2021-09-29)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **cmdb-instances:** 实例列表自增id流水号属性排序使用自然排序 ([1eeada1](https://github.com/easyops-cn/next-libs/commit/1eeada18741c0564fb03d84b5622f8b77576ed46))
28
+
29
+
30
+
31
+
32
+
33
+ ## [6.6.2](https://github.com/easyops-cn/next-libs/compare/@next-libs/cmdb-instances@6.6.1...@next-libs/cmdb-instances@6.6.2) (2021-09-27)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * **cmdb-instances:** 修复实例列表高级搜索-关系字段查询回填不正确 ([1fed048](https://github.com/easyops-cn/next-libs/commit/1fed0482fb166e345b6ff5230d3b933dd7cff187))
39
+
40
+
41
+
42
+
43
+
6
44
  ## [6.6.1](https://github.com/easyops-cn/next-libs/compare/@next-libs/cmdb-instances@6.6.0...@next-libs/cmdb-instances@6.6.1) (2021-09-26)
7
45
 
8
46
  **Note:** Version bump only for package @next-libs/cmdb-instances
@@ -101,6 +101,14 @@ function translateConditions(aq, idObjectMap, modelData, t) {
101
101
  relationSideId: relation[`${sides.this}_id`]
102
102
  });
103
103
  });
104
+ relations.push({
105
+ id: `${objectId}.`,
106
+ name: `${relation[`${sides.this}_name`]}`,
107
+ value: {
108
+ type: "str"
109
+ },
110
+ relationSideId: relation[`${sides.this}_id`]
111
+ });
104
112
  });
105
113
  const attrAndRelationList = [...modelData.attrList, ...relations];
106
114
 
@@ -114,7 +122,13 @@ function translateConditions(aq, idObjectMap, modelData, t) {
114
122
 
115
123
  queries.forEach(query => {
116
124
  const key = Object.keys(query)[0];
117
- const attr = attrAndRelationList.find(attr => attr.id === key || attr.relationSideId === key);
125
+ const value = Object.values(query)[0];
126
+ let attr = attrAndRelationList.find(attr => attr.id === key || attr.relationSideId === key);
127
+
128
+ if (Object.keys(value)[0] === _instanceListTable.ElementOperators.Exists && attr.relationSideId) {
129
+ const relationSideId = attr.relationSideId;
130
+ attr = attrAndRelationList.find(attr => attr.id === `${relationSideId}.`) || attr;
131
+ }
118
132
 
119
133
  if (attr) {
120
134
  query = (0, _processors.changeQueryWithCustomRules)(modelData.objectId, attr.id, query);
@@ -130,11 +144,15 @@ function translateConditions(aq, idObjectMap, modelData, t) {
130
144
  condition += `"${info.values.join(" ~ ")}"`;
131
145
  }
132
146
 
133
- conditions.push({
147
+ const curCondition = {
134
148
  attrId: key,
135
149
  condition,
136
150
  valuesStr: info.queryValuesStr
137
- });
151
+ };
152
+
153
+ if (conditions.every(v => !(0, _lodash.isEqual)((0, _lodash.omit)(v, "attrId"), (0, _lodash.omit)(curCondition, "attrId")))) {
154
+ conditions.push(curCondition);
155
+ }
138
156
  }
139
157
  });
140
158
  }
@@ -341,7 +359,7 @@ function InstanceList(props) {
341
359
  const isFirstRunRef = (0, _react.useRef)(true);
342
360
 
343
361
  const getInstanceListData = async (sort, asc, page) => {
344
- var _props$onSearchExecut;
362
+ var _modelData$attrList, _modelData$attrList$f2, _modelData$attrList$f3, _props$onSearchExecut;
345
363
 
346
364
  const data = {};
347
365
  const v3Data = {
@@ -355,14 +373,16 @@ function InstanceList(props) {
355
373
  let query = {};
356
374
  v3Data.page = data.page = page;
357
375
  v3Data["page_size"] = data["page_size"] = state.pageSize;
376
+ const sortType = modelData === null || modelData === void 0 ? void 0 : (_modelData$attrList = modelData.attrList) === null || _modelData$attrList === void 0 ? void 0 : (_modelData$attrList$f2 = _modelData$attrList.find(attr => attr.id === sort)) === null || _modelData$attrList$f2 === void 0 ? void 0 : (_modelData$attrList$f3 = _modelData$attrList$f2.value) === null || _modelData$attrList$f3 === void 0 ? void 0 : _modelData$attrList$f3.default_type;
377
+ const order = ["series-number", "auto-increment-id"].includes(sortType) ? asc ? 2 : -2 : asc ? 1 : -1;
358
378
 
359
379
  if (sort) {
360
380
  data.sort = {
361
- [sort]: asc ? 1 : -1
381
+ [sort]: order
362
382
  };
363
383
  v3Data.sort = [{
364
384
  key: sort,
365
- order: asc ? 1 : -1
385
+ order
366
386
  }];
367
387
  }
368
388
 
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.convertValue = convertValue;
9
9
  exports.getFieldConditionsAndValues = getFieldConditionsAndValues;
10
- exports.AdvancedSearch = exports.AdvancedSearchForm = exports.ConditionType = exports.LogicalOperators = void 0;
10
+ exports.AdvancedSearch = exports.AdvancedSearchForm = exports.ConditionType = exports.LogicalOperators = exports.ElementOperators = void 0;
11
11
 
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
13
 
@@ -50,11 +50,12 @@ var ComparisonOperators;
50
50
  ComparisonOperators["NotIn"] = "$nin";
51
51
  })(ComparisonOperators || (ComparisonOperators = {}));
52
52
 
53
- var ElementOperators;
53
+ let ElementOperators;
54
+ exports.ElementOperators = ElementOperators;
54
55
 
55
56
  (function (ElementOperators) {
56
57
  ElementOperators["Exists"] = "$exists";
57
- })(ElementOperators || (ElementOperators = {}));
58
+ })(ElementOperators || (exports.ElementOperators = ElementOperators = {}));
58
59
 
59
60
  let LogicalOperators;
60
61
  exports.LogicalOperators = LogicalOperators;
@@ -262,7 +263,7 @@ function getFieldConditionsAndValues(fieldQueryOperatorExpressionsMap, id, value
262
263
 
263
264
  if (!expressions && isRelation) {
264
265
  isRelationWithNoExpression = true;
265
- const relatedKey = (0, _lodash.findKey)(fieldQueryOperatorExpressionsMap, (v, k) => (0, _lodash.startsWith)(k, `${relationSideId}.`));
266
+ const relatedKey = (0, _lodash.findKey)(fieldQueryOperatorExpressionsMap, (v, k) => (0, _lodash.startsWith)(k, `${relationSideId}.`) || k === relationSideId);
266
267
  const relatedExpressions = fieldQueryOperatorExpressionsMap[relatedKey];
267
268
 
268
269
  if (relatedExpressions && !(0, _lodash.isNil)(relatedExpressions[ElementOperators.Exists])) {
@@ -303,7 +304,7 @@ function getFieldConditionsAndValues(fieldQueryOperatorExpressionsMap, id, value
303
304
  }
304
305
 
305
306
  let queryValuesStr = "";
306
- let values = currentCondition.operations.map(operation => {
307
+ const values = currentCondition.operations.map(operation => {
307
308
  var _expressions;
308
309
 
309
310
  let value; // istanbul ignore else
@@ -344,14 +345,17 @@ function getFieldConditionsAndValues(fieldQueryOperatorExpressionsMap, id, value
344
345
 
345
346
  return value;
346
347
  });
347
- let disabled = false;
348
-
349
- if (isRelation && expressions && currentCondition.operations[0].operator === ElementOperators.Exists && isRelationWithNoExpression) {
350
- disabled = true;
351
- currentCondition = availableConditions[0];
352
- values = [null];
353
- queryValuesStr = "";
354
- }
348
+ const disabled = false; // if (
349
+ // isRelation &&
350
+ // expressions &&
351
+ // currentCondition.operations[0].operator === ElementOperators.Exists &&
352
+ // isRelationWithNoExpression
353
+ // ) {
354
+ // disabled = true;
355
+ // currentCondition = availableConditions[0];
356
+ // values = [null];
357
+ // queryValuesStr = "";
358
+ // }
355
359
 
356
360
  return {
357
361
  availableConditions,
@@ -401,26 +405,27 @@ class AdvancedSearchForm extends _react.default.Component {
401
405
 
402
406
  if (relatedFieldIndex !== -1) {
403
407
  const relatedField = newFields[relatedFieldIndex];
408
+ const relatedCondition = relatedField.availableConditions.find(condition => condition.type === value);
404
409
 
405
410
  if (condition.operations[0].operator === ElementOperators.Exists) {
406
411
  newFields = (0, _immutabilityHelper.default)(newFields, {
407
412
  [relatedFieldIndex]: {
408
413
  currentCondition: {
409
- $set: relatedField.availableConditions[0]
414
+ $set: relatedCondition
410
415
  },
411
416
  values: {
412
417
  $set: [null]
413
- },
414
- disabled: {
415
- $set: true
416
418
  }
417
419
  }
418
420
  });
419
- } else {
421
+ } else if (relatedField.currentCondition.operations[0].operator === ElementOperators.Exists) {
420
422
  newFields = (0, _immutabilityHelper.default)(newFields, {
421
423
  [relatedFieldIndex]: {
422
- disabled: {
423
- $set: false
424
+ currentCondition: {
425
+ $set: relatedField.availableConditions[0]
426
+ },
427
+ values: {
428
+ $set: [null]
424
429
  }
425
430
  }
426
431
  });
@@ -1,7 +1,7 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
3
3
  import React, { useEffect, useReducer, useState, useRef, useMemo } from "react";
4
- import { difference, isEmpty, isEqual, isString, map, uniq, union, filter, reject, sortBy, uniqueId, findIndex, find, startsWith, compact } from "lodash";
4
+ import { difference, isEmpty, isEqual, isString, map, uniq, union, filter, reject, sortBy, uniqueId, findIndex, find, startsWith, compact, omit } from "lodash";
5
5
  import { BrickAsComponent, handleHttpError } from "@next-core/brick-kit";
6
6
  import i18n from "i18next";
7
7
  import { K, NS_LIBS_CMDB_INSTANCES } from "../i18n/constants";
@@ -9,7 +9,7 @@ import { InstanceApi_postSearchV3 } from "@next-sdk/cmdb-sdk";
9
9
  import { Icon as LegacyIcon } from "@ant-design/compatible";
10
10
  import { Button, Spin, Input, Tag, Select } from "antd";
11
11
  import { getRelationObjectSides, forEachAvailableFields, getInstanceNameKeys } from "@next-libs/cmdb-utils";
12
- import { ConditionType, LogicalOperators, AdvancedSearch, getFieldConditionsAndValues, MoreButtonsContainer, InstanceListTable } from "../instance-list-table";
12
+ import { ConditionType, LogicalOperators, AdvancedSearch, getFieldConditionsAndValues, MoreButtonsContainer, InstanceListTable, ElementOperators } from "../instance-list-table";
13
13
  import styles from "./InstanceList.module.css";
14
14
  import { extraFieldAttrs, CMDB_MODAL_FIELDS_SETTINGS, CMDB_RESOURCE_FIELDS_SETTINGS, MAX_DEFAULT_FIELDS_COUNT, MAX_DEFAULT_MODAL_FIELDS_COUNT } from "./constants";
15
15
  import { JsonStorage } from "@next-libs/storage";
@@ -75,6 +75,14 @@ function translateConditions(aq, idObjectMap, modelData, t) {
75
75
  relationSideId: relation["".concat(sides.this, "_id")]
76
76
  });
77
77
  });
78
+ relations.push({
79
+ id: "".concat(objectId, "."),
80
+ name: "".concat(relation["".concat(sides.this, "_name")]),
81
+ value: {
82
+ type: "str"
83
+ },
84
+ relationSideId: relation["".concat(sides.this, "_id")]
85
+ });
78
86
  });
79
87
  var attrAndRelationList = [...modelData.attrList, ...relations];
80
88
 
@@ -88,8 +96,14 @@ function translateConditions(aq, idObjectMap, modelData, t) {
88
96
 
89
97
  _queries.forEach(query => {
90
98
  var key = Object.keys(query)[0];
99
+ var value = Object.values(query)[0];
91
100
  var attr = attrAndRelationList.find(attr => attr.id === key || attr.relationSideId === key);
92
101
 
102
+ if (Object.keys(value)[0] === ElementOperators.Exists && attr.relationSideId) {
103
+ var relationSideId = attr.relationSideId;
104
+ attr = attrAndRelationList.find(attr => attr.id === "".concat(relationSideId, ".")) || attr;
105
+ }
106
+
93
107
  if (attr) {
94
108
  query = changeQueryWithCustomRules(modelData.objectId, attr.id, query);
95
109
  var info = getFieldConditionsAndValues(query, key, attr.value.type, undefined, undefined, modelData.objectId, attr.id);
@@ -104,11 +118,15 @@ function translateConditions(aq, idObjectMap, modelData, t) {
104
118
  condition += "\"".concat(info.values.join(" ~ "), "\"");
105
119
  }
106
120
 
107
- conditions.push({
121
+ var curCondition = {
108
122
  attrId: key,
109
123
  condition,
110
124
  valuesStr: info.queryValuesStr
111
- });
125
+ };
126
+
127
+ if (conditions.every(v => !isEqual(omit(v, "attrId"), omit(curCondition, "attrId")))) {
128
+ conditions.push(curCondition);
129
+ }
112
130
  }
113
131
  });
114
132
  }
@@ -311,7 +329,7 @@ export function InstanceList(props) {
311
329
 
312
330
  var getInstanceListData = /*#__PURE__*/function () {
313
331
  var _ref3 = _asyncToGenerator(function* (sort, asc, page) {
314
- var _props$onSearchExecut;
332
+ var _modelData$attrList, _modelData$attrList$f2, _modelData$attrList$f3, _props$onSearchExecut;
315
333
 
316
334
  var data = {};
317
335
  var v3Data = {
@@ -325,14 +343,16 @@ export function InstanceList(props) {
325
343
  var query = {};
326
344
  v3Data.page = data.page = page;
327
345
  v3Data["page_size"] = data["page_size"] = state.pageSize;
346
+ var sortType = modelData === null || modelData === void 0 ? void 0 : (_modelData$attrList = modelData.attrList) === null || _modelData$attrList === void 0 ? void 0 : (_modelData$attrList$f2 = _modelData$attrList.find(attr => attr.id === sort)) === null || _modelData$attrList$f2 === void 0 ? void 0 : (_modelData$attrList$f3 = _modelData$attrList$f2.value) === null || _modelData$attrList$f3 === void 0 ? void 0 : _modelData$attrList$f3.default_type;
347
+ var order = ["series-number", "auto-increment-id"].includes(sortType) ? asc ? 2 : -2 : asc ? 1 : -1;
328
348
 
329
349
  if (sort) {
330
350
  data.sort = {
331
- [sort]: asc ? 1 : -1
351
+ [sort]: order
332
352
  };
333
353
  v3Data.sort = [{
334
354
  key: sort,
335
- order: asc ? 1 : -1
355
+ order
336
356
  }];
337
357
  }
338
358
 
@@ -27,7 +27,7 @@ var ComparisonOperators;
27
27
  ComparisonOperators["NotIn"] = "$nin";
28
28
  })(ComparisonOperators || (ComparisonOperators = {}));
29
29
 
30
- var ElementOperators;
30
+ export var ElementOperators;
31
31
 
32
32
  (function (ElementOperators) {
33
33
  ElementOperators["Exists"] = "$exists";
@@ -236,7 +236,7 @@ export function getFieldConditionsAndValues(fieldQueryOperatorExpressionsMap, id
236
236
 
237
237
  if (!expressions && isRelation) {
238
238
  isRelationWithNoExpression = true;
239
- var relatedKey = findKey(fieldQueryOperatorExpressionsMap, (v, k) => startsWith(k, "".concat(relationSideId, ".")));
239
+ var relatedKey = findKey(fieldQueryOperatorExpressionsMap, (v, k) => startsWith(k, "".concat(relationSideId, ".")) || k === relationSideId);
240
240
  var relatedExpressions = fieldQueryOperatorExpressionsMap[relatedKey];
241
241
 
242
242
  if (relatedExpressions && !isNil(relatedExpressions[ElementOperators.Exists])) {
@@ -318,14 +318,17 @@ export function getFieldConditionsAndValues(fieldQueryOperatorExpressionsMap, id
318
318
 
319
319
  return value;
320
320
  });
321
- var disabled = false;
322
-
323
- if (isRelation && expressions && currentCondition.operations[0].operator === ElementOperators.Exists && isRelationWithNoExpression) {
324
- disabled = true;
325
- currentCondition = availableConditions[0];
326
- values = [null];
327
- queryValuesStr = "";
328
- }
321
+ var disabled = false; // if (
322
+ // isRelation &&
323
+ // expressions &&
324
+ // currentCondition.operations[0].operator === ElementOperators.Exists &&
325
+ // isRelationWithNoExpression
326
+ // ) {
327
+ // disabled = true;
328
+ // currentCondition = availableConditions[0];
329
+ // values = [null];
330
+ // queryValuesStr = "";
331
+ // }
329
332
 
330
333
  return {
331
334
  availableConditions,
@@ -376,26 +379,27 @@ export class AdvancedSearchForm extends React.Component {
376
379
 
377
380
  if (relatedFieldIndex !== -1) {
378
381
  var relatedField = newFields[relatedFieldIndex];
382
+ var relatedCondition = relatedField.availableConditions.find(condition => condition.type === value);
379
383
 
380
384
  if (condition.operations[0].operator === ElementOperators.Exists) {
381
385
  newFields = update(newFields, {
382
386
  [relatedFieldIndex]: {
383
387
  currentCondition: {
384
- $set: relatedField.availableConditions[0]
388
+ $set: relatedCondition
385
389
  },
386
390
  values: {
387
391
  $set: [null]
388
- },
389
- disabled: {
390
- $set: true
391
392
  }
392
393
  }
393
394
  });
394
- } else {
395
+ } else if (relatedField.currentCondition.operations[0].operator === ElementOperators.Exists) {
395
396
  newFields = update(newFields, {
396
397
  [relatedFieldIndex]: {
397
- disabled: {
398
- $set: false
398
+ currentCondition: {
399
+ $set: relatedField.availableConditions[0]
400
+ },
401
+ values: {
402
+ $set: [null]
399
403
  }
400
404
  }
401
405
  });
@@ -14,7 +14,7 @@ declare enum ComparisonOperators {
14
14
  In = "$in",
15
15
  NotIn = "$nin"
16
16
  }
17
- declare enum ElementOperators {
17
+ export declare enum ElementOperators {
18
18
  Exists = "$exists"
19
19
  }
20
20
  export declare enum LogicalOperators {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-libs/cmdb-instances",
3
- "version": "6.6.1",
3
+ "version": "6.6.5",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "https://github.com/easyops-cn/next-libs/tree/master/libs/cmdb-instances",
6
6
  "license": "GPL-3.0",
@@ -36,12 +36,12 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@next-core/brick-types": "^2.16.0",
39
- "@next-libs/basic-components": "^3.2.3",
39
+ "@next-libs/basic-components": "^3.2.4",
40
40
  "@next-libs/cmdb-utils": "^3.0.2",
41
- "@next-libs/code-editor-components": "^4.0.7",
42
- "@next-libs/forms": "^3.2.5",
41
+ "@next-libs/code-editor-components": "^4.0.9",
42
+ "@next-libs/forms": "^3.2.6",
43
43
  "@next-libs/storage": "^2.0.2",
44
- "@next-sdk/cmdb-sdk": "^2.1.1",
44
+ "@next-sdk/cmdb-sdk": "^2.1.13",
45
45
  "@next-sdk/permission-sdk": "^2.1.1",
46
46
  "@types/file-saver": "^2.0.3",
47
47
  "classnames": "^2.3.1",
@@ -50,5 +50,5 @@
50
50
  "immutability-helper": "^3.1.1",
51
51
  "marked": "^2.1.3"
52
52
  },
53
- "gitHead": "3b343ce2f9cab18091539c81f62517b792621f6e"
53
+ "gitHead": "69b77c3b8d38591913d4b92b755f44ceb908a761"
54
54
  }