@next-libs/cmdb-instances 7.1.14 → 7.1.16

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.
@@ -403,8 +403,50 @@ export function LegacyInstanceList(props) {
403
403
  var [selectedRowKeys, setSelectedRowKeys] = useState((_props$selectedRowKey = props.selectedRowKeys) !== null && _props$selectedRowKey !== void 0 ? _props$selectedRowKey : []);
404
404
  var cache = useRef(new Map());
405
405
  var isFirstRunRef = useRef(true);
406
+
407
+ // istanbul ignore next
408
+ var onSelectionChange = useCallback( /*#__PURE__*/function () {
409
+ var _ref5 = _asyncToGenerator(function* (selected) {
410
+ var _props$onSelectionCha;
411
+ var {
412
+ selectedItems,
413
+ selectedKeys
414
+ } = selected;
415
+ setSelectedRowKeys(selectedKeys);
416
+ if (selectedKeys.length > compact(selectedItems).length) {
417
+ var ids = selectedKeys.filter(id => !cache.current.has(id));
418
+ if (ids.length) {
419
+ var resp;
420
+ var params = {
421
+ fields: ["instanceId"],
422
+ query: {
423
+ instanceId: {
424
+ $in: ids
425
+ }
426
+ },
427
+ page_size: ids.length
428
+ };
429
+ // useAutoDiscoveryProvider=true, 使用useProvider的接口,虽然这里列表用不到选择功能,但还是加上保持统一
430
+ if (props.useAutoDiscoveryProvider) {
431
+ resp = yield listProvider.query([props.objectId, Object.assign(params, props.extraParams)]);
432
+ } else {
433
+ resp = yield InstanceApi_postSearchV3(props.objectId, params);
434
+ }
435
+ resp.list.forEach(i => cache.current.set(i.instanceId, i));
436
+ }
437
+ selectedItems = selectedKeys.map(id => cache.current.get(id));
438
+ }
439
+ (_props$onSelectionCha = props.onSelectionChange) === null || _props$onSelectionCha === void 0 ? void 0 : _props$onSelectionCha.call(props, {
440
+ selectedItems,
441
+ selectedKeys
442
+ });
443
+ });
444
+ return function (_x2) {
445
+ return _ref5.apply(this, arguments);
446
+ };
447
+ }(), []);
406
448
  var getInstanceListData = /*#__PURE__*/function () {
407
- var _ref5 = _asyncToGenerator(function* (sort, asc, page) {
449
+ var _ref6 = _asyncToGenerator(function* (sort, asc, page) {
408
450
  var _modelData$attrList, _modelData$attrList$f2, _modelData$attrList$f3, _props$onSearchExecut;
409
451
  var data = {};
410
452
  var v3Data = {
@@ -505,12 +547,12 @@ export function LegacyInstanceList(props) {
505
547
  // useAutoDiscoveryProvider=true, 使用useProvider的接口
506
548
  return promise ? promise : props.useAutoDiscoveryProvider ? listProvider.query([props.objectId, v3Data]) : InstanceApi_postSearchV3(props.objectId, v3Data);
507
549
  });
508
- return function getInstanceListData(_x2, _x3, _x4) {
509
- return _ref5.apply(this, arguments);
550
+ return function getInstanceListData(_x3, _x4, _x5) {
551
+ return _ref6.apply(this, arguments);
510
552
  };
511
553
  }();
512
554
  var refreshInstanceList = /*#__PURE__*/function () {
513
- var _ref6 = _asyncToGenerator(function* (sort, asc, page) {
555
+ var _ref7 = _asyncToGenerator(function* (sort, asc, page) {
514
556
  setState({
515
557
  loading: true
516
558
  });
@@ -547,8 +589,8 @@ export function LegacyInstanceList(props) {
547
589
  });
548
590
  }
549
591
  });
550
- return function refreshInstanceList(_x5, _x6, _x7) {
551
- return _ref6.apply(this, arguments);
592
+ return function refreshInstanceList(_x6, _x7, _x8) {
593
+ return _ref7.apply(this, arguments);
552
594
  };
553
595
  }();
554
596
  useEffect(() => {
@@ -599,58 +641,62 @@ export function LegacyInstanceList(props) {
599
641
  return;
600
642
  }
601
643
  refreshInstanceList(state.sort, state.asc, 1);
602
- }, [state.q, state.aq, state.instanceSourceQuery, state.pageSize, state.aliveHosts, state.relatedToMe, props.objectId, props.permission, props.defaultQuery]);
644
+ onSelectionChange({
645
+ selectedKeys: [],
646
+ selectedItems: []
647
+ });
648
+ }, [state.q, state.aq, state.instanceSourceQuery, state.aliveHosts, state.relatedToMe, props.objectId, props.permission, props.defaultQuery]);
649
+
650
+ // on pageSize condition change
651
+ useEffect(() => {
652
+ if (isFirstRunRef.current) {
653
+ isFirstRunRef.current = false;
654
+ return;
655
+ }
656
+ var skip = false;
657
+ if (state.page !== 1) {
658
+ var _props$onPaginationCh2;
659
+ setState({
660
+ page: 1
661
+ });
662
+ (_props$onPaginationCh2 = props.onPaginationChange) === null || _props$onPaginationCh2 === void 0 ? void 0 : _props$onPaginationCh2.call(props, {
663
+ page: 1,
664
+ pageSize: state.pageSize
665
+ });
666
+ skip = true;
667
+ }
668
+
669
+ // 当 prop.objectId 改变时先跳过,等 state.fieldIds 更新后再获取数据
670
+ if (props.objectId !== state.objectId) {
671
+ setState({
672
+ objectId: props.objectId
673
+ });
674
+ skip = true;
675
+ }
676
+ if (skip) {
677
+ return;
678
+ }
679
+ refreshInstanceList(state.sort, state.asc, 1);
680
+ }, [state.pageSize]);
681
+
682
+ // on other condition change
683
+ useEffect(() => {
684
+ if (isEmpty(state.fieldIds)) return;
685
+ refreshInstanceList(state.sort, state.asc, state.page);
686
+ }, [state.page]);
603
687
 
604
688
  // on other condition change
605
689
  useEffect(() => {
606
690
  if (isEmpty(state.fieldIds)) return;
607
691
  refreshInstanceList(state.sort, state.asc, state.page);
608
- }, [state.page, state.sort, state.asc, state.fieldIds, state.appSearchInstanceId, state.currentChangeSelect, state.searchByApp, props.dataSource, state.presetConfigsQuery]);
692
+ onSelectionChange({
693
+ selectedKeys: [],
694
+ selectedItems: []
695
+ });
696
+ }, [state.sort, state.asc, state.fieldIds, state.appSearchInstanceId, state.currentChangeSelect, state.searchByApp, props.dataSource, state.presetConfigsQuery]);
609
697
  var onChange = e => {
610
698
  setQ(e.target.value);
611
699
  };
612
-
613
- // istanbul ignore next
614
- var onSelectionChange = useCallback( /*#__PURE__*/function () {
615
- var _ref7 = _asyncToGenerator(function* (selected) {
616
- var _props$onSelectionCha;
617
- var {
618
- selectedItems,
619
- selectedKeys
620
- } = selected;
621
- setSelectedRowKeys(selectedKeys);
622
- if (selectedKeys.length > compact(selectedItems).length) {
623
- var ids = selectedKeys.filter(id => !cache.current.has(id));
624
- if (ids.length) {
625
- var resp;
626
- var params = {
627
- fields: ["instanceId"],
628
- query: {
629
- instanceId: {
630
- $in: ids
631
- }
632
- },
633
- page_size: ids.length
634
- };
635
- // useAutoDiscoveryProvider=true, 使用useProvider的接口,虽然这里列表用不到选择功能,但还是加上保持统一
636
- if (props.useAutoDiscoveryProvider) {
637
- resp = yield listProvider.query([props.objectId, Object.assign(params, props.extraParams)]);
638
- } else {
639
- resp = yield InstanceApi_postSearchV3(props.objectId, params);
640
- }
641
- resp.list.forEach(i => cache.current.set(i.instanceId, i));
642
- }
643
- selectedItems = selectedKeys.map(id => cache.current.get(id));
644
- }
645
- (_props$onSelectionCha = props.onSelectionChange) === null || _props$onSelectionCha === void 0 ? void 0 : _props$onSelectionCha.call(props, {
646
- selectedItems,
647
- selectedKeys
648
- });
649
- });
650
- return function (_x8) {
651
- return _ref7.apply(this, arguments);
652
- };
653
- }(), []);
654
700
  var onSearch = value => {
655
701
  var _props$onSearch;
656
702
  var q = value.trim();
@@ -658,6 +704,10 @@ export function LegacyInstanceList(props) {
658
704
  q
659
705
  });
660
706
  (_props$onSearch = props.onSearch) === null || _props$onSearch === void 0 ? void 0 : _props$onSearch.call(props, q);
707
+ onSelectionChange({
708
+ selectedKeys: [],
709
+ selectedItems: []
710
+ });
661
711
  };
662
712
  var onAdvancedSearch = (queries, queriesToShow, fieldToShow) => {
663
713
  var _props$onAdvancedSear;
@@ -667,6 +717,10 @@ export function LegacyInstanceList(props) {
667
717
  aqToShow: queriesToShow
668
718
  });
669
719
  (_props$onAdvancedSear = props.onAdvancedSearch) === null || _props$onAdvancedSear === void 0 ? void 0 : _props$onAdvancedSear.call(props, queries);
720
+ onSelectionChange({
721
+ selectedKeys: [],
722
+ selectedItems: []
723
+ });
670
724
  };
671
725
  var onSortingChange = useCallback(info => {
672
726
  var _props$onSortingChang;
@@ -691,12 +745,12 @@ export function LegacyInstanceList(props) {
691
745
  (_props$onSortingChang = props.onSortingChange) === null || _props$onSortingChang === void 0 ? void 0 : _props$onSortingChang.call(props, info);
692
746
  }, [state.sort]);
693
747
  var onPaginationChange = useCallback(pagination => {
694
- var _props$onPaginationCh2;
748
+ var _props$onPaginationCh3;
695
749
  setState({
696
750
  page: pagination.page,
697
751
  pageSize: pagination.pageSize
698
752
  });
699
- (_props$onPaginationCh2 = props.onPaginationChange) === null || _props$onPaginationCh2 === void 0 ? void 0 : _props$onPaginationCh2.call(props, pagination);
753
+ (_props$onPaginationCh3 = props.onPaginationChange) === null || _props$onPaginationCh3 === void 0 ? void 0 : _props$onPaginationCh3.call(props, pagination);
700
754
  }, []);
701
755
  var onInstanceSourceChange = useCallback(instanceSourceQuery => {
702
756
  var _props$onInstanceSour;