@next-libs/cmdb-instances 7.1.15 → 7.1.17

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.
@@ -414,6 +414,43 @@ function LegacyInstanceList(props) {
414
414
  const [selectedRowKeys, setSelectedRowKeys] = (0, _react.useState)((_props$selectedRowKey = props.selectedRowKeys) !== null && _props$selectedRowKey !== void 0 ? _props$selectedRowKey : []);
415
415
  const cache = (0, _react.useRef)(new Map());
416
416
  const isFirstRunRef = (0, _react.useRef)(true);
417
+
418
+ // istanbul ignore next
419
+ const onSelectionChange = (0, _react.useCallback)(async selected => {
420
+ var _props$onSelectionCha;
421
+ let {
422
+ selectedItems,
423
+ selectedKeys
424
+ } = selected;
425
+ setSelectedRowKeys(selectedKeys);
426
+ if (selectedKeys.length > (0, _lodash.compact)(selectedItems).length) {
427
+ const ids = selectedKeys.filter(id => !cache.current.has(id));
428
+ if (ids.length) {
429
+ let resp;
430
+ const params = {
431
+ fields: ["instanceId"],
432
+ query: {
433
+ instanceId: {
434
+ $in: ids
435
+ }
436
+ },
437
+ page_size: ids.length
438
+ };
439
+ // useAutoDiscoveryProvider=true, 使用useProvider的接口,虽然这里列表用不到选择功能,但还是加上保持统一
440
+ if (props.useAutoDiscoveryProvider) {
441
+ resp = await listProvider.query([props.objectId, Object.assign(params, props.extraParams)]);
442
+ } else {
443
+ resp = await (0, _cmdbSdk.InstanceApi_postSearchV3)(props.objectId, params);
444
+ }
445
+ resp.list.forEach(i => cache.current.set(i.instanceId, i));
446
+ }
447
+ selectedItems = selectedKeys.map(id => cache.current.get(id));
448
+ }
449
+ (_props$onSelectionCha = props.onSelectionChange) === null || _props$onSelectionCha === void 0 ? void 0 : _props$onSelectionCha.call(props, {
450
+ selectedItems,
451
+ selectedKeys
452
+ });
453
+ }, []);
417
454
  const getInstanceListData = async (sort, asc, page) => {
418
455
  var _modelData$attrList, _modelData$attrList$f2, _modelData$attrList$f3, _props$onSearchExecut;
419
456
  const data = {};
@@ -604,53 +641,62 @@ function LegacyInstanceList(props) {
604
641
  return;
605
642
  }
606
643
  refreshInstanceList(state.sort, state.asc, 1);
607
- }, [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
+ (0, _react.useEffect)(() => {
652
+ if (isFirstRunRef.current) {
653
+ isFirstRunRef.current = false;
654
+ return;
655
+ }
656
+ let 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]);
608
681
 
609
682
  // on other condition change
610
683
  (0, _react.useEffect)(() => {
611
684
  if ((0, _lodash.isEmpty)(state.fieldIds)) return;
612
685
  refreshInstanceList(state.sort, state.asc, state.page);
613
- }, [state.page, state.sort, state.asc, state.fieldIds, state.appSearchInstanceId, state.currentChangeSelect, state.searchByApp, props.dataSource, state.presetConfigsQuery]);
686
+ }, [state.page]);
687
+
688
+ // on other condition change
689
+ (0, _react.useEffect)(() => {
690
+ if ((0, _lodash.isEmpty)(state.fieldIds)) return;
691
+ refreshInstanceList(state.sort, state.asc, state.page);
692
+ onSelectionChange({
693
+ selectedKeys: [],
694
+ selectedItems: []
695
+ });
696
+ }, [state.sort, state.asc, state.fieldIds, state.appSearchInstanceId, state.currentChangeSelect, state.searchByApp, props.dataSource, state.presetConfigsQuery]);
614
697
  const onChange = e => {
615
698
  setQ(e.target.value);
616
699
  };
617
-
618
- // istanbul ignore next
619
- const onSelectionChange = (0, _react.useCallback)(async selected => {
620
- var _props$onSelectionCha;
621
- let {
622
- selectedItems,
623
- selectedKeys
624
- } = selected;
625
- setSelectedRowKeys(selectedKeys);
626
- if (selectedKeys.length > (0, _lodash.compact)(selectedItems).length) {
627
- const ids = selectedKeys.filter(id => !cache.current.has(id));
628
- if (ids.length) {
629
- let resp;
630
- const params = {
631
- fields: ["instanceId"],
632
- query: {
633
- instanceId: {
634
- $in: ids
635
- }
636
- },
637
- page_size: ids.length
638
- };
639
- // useAutoDiscoveryProvider=true, 使用useProvider的接口,虽然这里列表用不到选择功能,但还是加上保持统一
640
- if (props.useAutoDiscoveryProvider) {
641
- resp = await listProvider.query([props.objectId, Object.assign(params, props.extraParams)]);
642
- } else {
643
- resp = await (0, _cmdbSdk.InstanceApi_postSearchV3)(props.objectId, params);
644
- }
645
- resp.list.forEach(i => cache.current.set(i.instanceId, i));
646
- }
647
- selectedItems = selectedKeys.map(id => cache.current.get(id));
648
- }
649
- (_props$onSelectionCha = props.onSelectionChange) === null || _props$onSelectionCha === void 0 ? void 0 : _props$onSelectionCha.call(props, {
650
- selectedItems,
651
- selectedKeys
652
- });
653
- }, []);
654
700
  const onSearch = value => {
655
701
  var _props$onSearch;
656
702
  const q = value.trim();
@@ -658,6 +704,10 @@ 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
  const onAdvancedSearch = (queries, queriesToShow, fieldToShow) => {
663
713
  var _props$onAdvancedSear;
@@ -667,6 +717,10 @@ 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
  const onSortingChange = (0, _react.useCallback)(info => {
672
726
  var _props$onSortingChang;
@@ -691,12 +745,12 @@ 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
  const onPaginationChange = (0, _react.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
  const onInstanceSourceChange = (0, _react.useCallback)(instanceSourceQuery => {
702
756
  var _props$onInstanceSour;