@gingkoo/pandora-metabase 1.0.104 → 1.0.106

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.
@@ -8,7 +8,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
8
  import './index.less';
9
9
  import React, { useEffect, useMemo, useState } from 'react';
10
10
  import { Repeat, Function } from '@gingkoo/pandora-icons';
11
- import { Button, Tooltip, Input, Select, InputNumber, Dropdown, DatePicker } from '@gingkoo/pandora';
11
+ import { Button, Tooltip, Input, Select, InputNumber, Dropdown } from '@gingkoo/pandora';
12
12
  import cx from 'classnames';
13
13
  import { ChevronODown } from '@gingkoo/pandora-icons';
14
14
  import moment from 'dayjs';
@@ -23,7 +23,7 @@ import { useStore } from '../../../hooks/use-provider';
23
23
  import cloneDeep from 'lodash/cloneDeep';
24
24
  import { getConstantLabel } from '../formula-list/utils';
25
25
  import ItemName from '../../modules/components/item-name';
26
- var RangePicker = DatePicker.RangePicker;
26
+ import { DateFormatPicker, DateRangeFormatPicker } from './date-format-picker';
27
27
  var NUMBER_LIST = ['等于', '不等于', '大于', '小于', '介于之间', '大于或等于', '小于或等于', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
28
28
  var STRING_LIST = ['等于', '不等于', '包含', '不包含', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
29
29
  var DATE_LIST = [
@@ -386,23 +386,21 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
386
386
  });
387
387
  }
388
388
  if (type === SQL_GROUP_TYPE.DATE) {
389
- return _jsx("div", {
390
- children: _jsx(RangePicker, {
391
- showTime: {
392
- format: 'HH:mm'
393
- },
394
- format: 'YYYY-MM-DD HH:mm',
395
- className: 'w_300',
396
- // @ts-ignore
397
- value: firstVal ? [moment(firstVal !== null && firstVal !== void 0 ? firstVal : undefined), moment(secondVal !== null && secondVal !== void 0 ? secondVal : undefined)] : [],
398
- onChange: function onChange(val) {
399
- // @ts-ignore
400
- val && setRhsVal([{
389
+ var _rhsVal$, _rhsVal$2;
390
+ var dateVal = ((_rhsVal$ = rhsVal[0]) === null || _rhsVal$ === void 0 ? void 0 : _rhsVal$.type) === AtomsTypeEnum.INPUT_STRING_LIST ? rhsVal[0].val : undefined;
391
+ var dateFormat = ((_rhsVal$2 = rhsVal[0]) === null || _rhsVal$2 === void 0 ? void 0 : _rhsVal$2.type) === AtomsTypeEnum.INPUT_STRING_LIST ? rhsVal[0].format : undefined;
392
+ return _jsx(DateRangeFormatPicker, {
393
+ value: dateVal,
394
+ format: dateFormat,
395
+ onChange: function onChange(val, format) {
396
+ if (val) {
397
+ setRhsVal([{
401
398
  type: AtomsTypeEnum.INPUT_STRING_LIST,
402
- val: [moment(val[0]).format('YYYY-MM-DD HH:mm'), moment(val[1]).format('YYYY-MM-DD HH:mm')]
399
+ val: val,
400
+ format: format
403
401
  }]);
404
402
  }
405
- })
403
+ }
406
404
  });
407
405
  }
408
406
  } else if (conditionText === '当前') {
@@ -487,58 +485,50 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
487
485
  })]
488
486
  });
489
487
  } else if (~['早于', '晚于', '在'].indexOf(conditionText)) {
490
- return _jsx("div", {
491
- children: _jsx(DatePicker, {
492
- showTime: {
493
- format: 'HH:mm'
494
- },
495
- format: 'YYYY-MM-DD HH:mm',
496
- className: 'w_300',
497
- value: firstVal ? moment(firstVal) : '',
498
- onChange: function onChange(val) {
499
- if (val) {
500
- setRhsVal([{
501
- type: AtomsTypeEnum.INPUT_STRING,
502
- val: moment(val).format('YYYY-MM-DD HH:mm')
503
- }
504
- // {
505
- // type: AtomsTypeEnum.INPUT_STRING,
506
- // val: moment(val).format('YYYY-MM-DD HH:mm'),
507
- // },
508
- ]);
509
- } else {
510
- setRhsVal([{
511
- val: '',
512
- type: AtomsTypeEnum.INPUT_STRING
513
- }]);
514
- // setVal([]);
515
- }
488
+ var _rhsVal$3, _rhsVal$4;
489
+ var _dateVal = ((_rhsVal$3 = rhsVal[0]) === null || _rhsVal$3 === void 0 ? void 0 : _rhsVal$3.type) === AtomsTypeEnum.INPUT_STRING ? rhsVal[0].val : undefined;
490
+ var _dateFormat = ((_rhsVal$4 = rhsVal[0]) === null || _rhsVal$4 === void 0 ? void 0 : _rhsVal$4.type) === AtomsTypeEnum.INPUT_STRING ? rhsVal[0].format : undefined;
491
+ return _jsx(DateFormatPicker, {
492
+ value: _dateVal,
493
+ format: _dateFormat,
494
+ onChange: function onChange(val, format) {
495
+ if (val) {
496
+ setRhsVal([{
497
+ type: AtomsTypeEnum.INPUT_STRING,
498
+ val: val,
499
+ format: format
500
+ }]);
501
+ } else {
502
+ setRhsVal([{
503
+ val: '',
504
+ type: AtomsTypeEnum.INPUT_STRING,
505
+ format: format
506
+ }]);
516
507
  }
517
- })
508
+ }
518
509
  });
519
510
  } else if (~['等于'].indexOf(conditionText) && type === SQL_GROUP_TYPE.DATE) {
520
- return _jsx("div", {
521
- children: _jsx(DatePicker, {
522
- showTime: {
523
- format: 'HH:mm'
524
- },
525
- format: 'YYYY-MM-DD HH:mm',
526
- className: 'w_300',
527
- value: firstVal ? moment(firstVal) : '',
528
- onChange: function onChange(val) {
529
- if (val) {
530
- setRhsVal([{
531
- type: AtomsTypeEnum.INPUT_STRING,
532
- val: moment(val).format('YYYY-MM-DD HH:mm')
533
- }]);
534
- } else {
535
- setRhsVal([{
536
- val: '',
537
- type: AtomsTypeEnum.INPUT_STRING
538
- }]);
539
- }
511
+ var _rhsVal$5, _rhsVal$6;
512
+ var _dateVal2 = ((_rhsVal$5 = rhsVal[0]) === null || _rhsVal$5 === void 0 ? void 0 : _rhsVal$5.type) === AtomsTypeEnum.INPUT_STRING ? rhsVal[0].val : undefined;
513
+ var _dateFormat2 = ((_rhsVal$6 = rhsVal[0]) === null || _rhsVal$6 === void 0 ? void 0 : _rhsVal$6.type) === AtomsTypeEnum.INPUT_STRING ? rhsVal[0].format : undefined;
514
+ return _jsx(DateFormatPicker, {
515
+ value: _dateVal2,
516
+ format: _dateFormat2,
517
+ onChange: function onChange(val, format) {
518
+ if (val) {
519
+ setRhsVal([{
520
+ type: AtomsTypeEnum.INPUT_STRING,
521
+ val: val,
522
+ format: format
523
+ }]);
524
+ } else {
525
+ setRhsVal([{
526
+ val: '',
527
+ type: AtomsTypeEnum.INPUT_STRING,
528
+ format: format
529
+ }]);
540
530
  }
541
- })
531
+ }
542
532
  });
543
533
  } else if (~['In', 'Not In'].indexOf(conditionText)) {
544
534
  var options = firstVal ? firstVal.split(',') : [];
@@ -921,7 +911,8 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
921
911
  } else if (~['介于之间'].indexOf(_condition)) {
922
912
  setRhsVal([{
923
913
  val: ['', ''],
924
- type: AtomsTypeEnum.INPUT_STRING_LIST
914
+ type: AtomsTypeEnum.INPUT_STRING_LIST,
915
+ format: 'YYYY-MM-DD HH:mm'
925
916
  }]);
926
917
  } else if (~['当前'].indexOf(_condition)) {
927
918
  setRhsVal([{
@@ -931,7 +922,8 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
931
922
  } else if (~['早于', '晚于', '在'].indexOf(_condition)) {
932
923
  setRhsVal([{
933
924
  val: moment().format('YYYY-MM-DD HH:mm'),
934
- type: AtomsTypeEnum.INPUT_STRING
925
+ type: AtomsTypeEnum.INPUT_STRING,
926
+ format: 'YYYY-MM-DD HH:mm'
935
927
  }]);
936
928
  } else {
937
929
  setRhsVal([{
@@ -5,7 +5,7 @@ import React, { useEffect } from 'react';
5
5
  import cx from 'classnames';
6
6
  import { __ } from '../../../locale';
7
7
  import { TypeEnum } from '../../../store/enum';
8
- import { Tooltip, Button } from '@gingkoo/pandora';
8
+ import { Tooltip, Button, Toast } from '@gingkoo/pandora';
9
9
  import { FfPlus } from '@gingkoo/pandora-icons';
10
10
  import storage from '../../../utils/storage';
11
11
  import { getHelper, isCanPaste } from '../../../utils';
@@ -345,11 +345,16 @@ var NextDom = function NextDom(props) {
345
345
  var handlePaste = function handlePaste() {
346
346
  var _store$metaList3;
347
347
  var index = (_store$metaList3 = store.metaList) === null || _store$metaList3 === void 0 || (_store$metaList3 = _store$metaList3[groupIndex]) === null || _store$metaList3 === void 0 || (_store$metaList3 = _store$metaList3.list) === null || _store$metaList3 === void 0 ? void 0 : _store$metaList3.indexOf(meta);
348
- store.addMeta('', index + 1, groupIndex, store.metabaseCopyModule);
349
- // 粘贴后重置
350
- store.setMetabaseCopyModule([]);
351
- store.setIsMetabaseCopy(false);
352
- storage._metabaseCopyModule = [];
348
+ var success = store.addMeta('', index + 1, groupIndex, store.metabaseCopyModule, function (conflictingAlias) {
349
+ // 冲突提示
350
+ Toast.warning("".concat(conflictingAlias, " \u7684 table1 \u4E0E\u7C98\u8D34\u4F4D\u7F6E\u76F8\u90BB\u9879\u51B2\u7A81\uFF0C\u8BF7\u8C03\u6574\u540E\u518D\u7C98\u8D34"));
351
+ });
352
+ // 仅在成功时重置
353
+ if (success) {
354
+ store.setMetabaseCopyModule([]);
355
+ store.setIsMetabaseCopy(false);
356
+ storage._metabaseCopyModule = [];
357
+ }
353
358
  };
354
359
  return _jsxs(_Fragment, {
355
360
  children: [store.metabaseCopyModule && store.metabaseCopyModule.length > 0 && isShowAdd && _jsx(Tooltip, {
@@ -1,3 +1,4 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
@@ -6,7 +7,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
7
  var _excluded = ["alias", "datasourceName", "datasourceId", "column"];
7
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
9
  import { useEffect, useState, useRef, useMemo } from 'react';
9
- import { uuidv4 } from '../utils/helper';
10
+ import { uuidv4, getAlias } from '../utils/helper';
10
11
  import { TypeEnum, JoinEnum, UnionEnum } from '../store/enum';
11
12
  import { splitByUnion } from '../utils';
12
13
  import storage from '../utils/storage';
@@ -186,14 +187,18 @@ var useStore = function useStore() {
186
187
  _useState66 = _slicedToArray(_useState65, 2),
187
188
  isMetabaseCopy = _useState66[0],
188
189
  setIsMetabaseCopy = _useState66[1]; // 是否开启勾选组复制
189
- var _useState67 = useState([]),
190
+ var _useState67 = useState(false),
190
191
  _useState68 = _slicedToArray(_useState67, 2),
191
- existsError = _useState68[0],
192
- setExistsError = _useState68[1]; // exists 的错误字段
193
- var _useState69 = useState(storage._metabaseCopyModule || []),
192
+ joinAliasConflictCheck = _useState68[0],
193
+ setJoinAliasConflictCheck = _useState68[1]; // 是否开启关联别名冲突检测
194
+ var _useState69 = useState([]),
194
195
  _useState70 = _slicedToArray(_useState69, 2),
195
- metabaseCopyModule = _useState70[0],
196
- setMetabaseCopyModule = _useState70[1]; // 复制的内容
196
+ existsError = _useState70[0],
197
+ setExistsError = _useState70[1]; // exists 的错误字段
198
+ var _useState71 = useState(storage._metabaseCopyModule || []),
199
+ _useState72 = _slicedToArray(_useState71, 2),
200
+ metabaseCopyModule = _useState72[0],
201
+ setMetabaseCopyModule = _useState72[1]; // 复制的内容
197
202
  var setFormulaTemplates = function setFormulaTemplates(data) {
198
203
  var newData = data === null || data === void 0 ? void 0 : data.map(function (v) {
199
204
  var children = v.children.map(function (vv) {
@@ -605,10 +610,102 @@ var useStore = function useStore() {
605
610
  _setMeta(defaultMeta);
606
611
  }
607
612
  };
608
- var getNewMeta = function getNewMeta(_type, index, groupIndex, obj) {
613
+ // 重新生成 UUID 的辅助函数
614
+ // 只修改 table2 中的 alias、tableUuid,expressions 中相等的 tableUuid 和 tableAlias 同步修改
615
+ var _regenerateUuid = function regenerateUuid(obj) {
616
+ var uuidMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
617
+ var aliasMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
618
+ var tableAliasMap = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
619
+ var existingAliases = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
620
+ var originalTable2Uuid = arguments.length > 5 ? arguments[5] : undefined;
621
+ var
622
+ // 原始 table2 的 tableUuid,用于同步 expressions
623
+ newTable2Uuid = arguments.length > 6 ? arguments[6] : undefined;
624
+ var
625
+ // 新的 table2 的 tableUuid
626
+ originalTable2Alias = arguments.length > 7 ? arguments[7] : undefined;
627
+ if (!obj) return obj;
628
+ if (Array.isArray(obj)) {
629
+ return obj.map(function (item) {
630
+ return _regenerateUuid(item, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
631
+ });
632
+ }
633
+ if (_typeof(obj) === 'object') {
634
+ var newObj = _objectSpread({}, obj);
635
+ // 处理 joinData 类型:只修改 table2 的 alias 和 tableUuid
636
+ if (newObj.type === 'joinData') {
637
+ if (newObj.table2) {
638
+ var table2 = _objectSpread({}, newObj.table2);
639
+ var originalAlias = table2.alias;
640
+ // 修改 table2.alias
641
+ if (table2.alias) {
642
+ if (!aliasMap[table2.alias]) {
643
+ table2.alias = getAlias(table2.alias, [], [], [].concat(_toConsumableArray(Object.values(aliasMap)), _toConsumableArray(existingAliases)));
644
+ aliasMap[originalAlias] = table2.alias; // 用原始 alias 作为 key
645
+ } else {
646
+ table2.alias = aliasMap[table2.alias];
647
+ }
648
+ }
649
+ // 修改 table2.tableUuid
650
+ if (table2.tableUuid && !uuidMap[table2.tableUuid]) {
651
+ var originalUuid = table2.tableUuid;
652
+ var newUuid = uuidv4('table');
653
+ uuidMap[originalUuid] = newUuid;
654
+ table2.tableUuid = newUuid;
655
+ // 记录原始和新 tableUuid,用于 expressions 同步
656
+ originalTable2Uuid = originalUuid;
657
+ newTable2Uuid = newUuid;
658
+ } else if (uuidMap[table2.tableUuid]) {
659
+ table2.tableUuid = uuidMap[table2.tableUuid];
660
+ newTable2Uuid = table2.tableUuid;
661
+ }
662
+ // 记录原始 alias,用于 expressions 同步 tableAlias
663
+ if (originalAlias) {
664
+ originalTable2Alias = originalAlias;
665
+ }
666
+ newObj.table2 = table2;
667
+ }
668
+ }
669
+ // 处理 expressions 中 tableUuid 相等的情况
670
+ if (originalTable2Uuid && newTable2Uuid && newObj.tableUuid === originalTable2Uuid) {
671
+ newObj.tableUuid = newTable2Uuid;
672
+ // 如果 originalTable2Alias 存在,tableAlias 要跟修改后的 table2.alias 保持一致
673
+ if (originalTable2Alias && aliasMap[originalTable2Alias]) {
674
+ newObj.tableAlias = aliasMap[originalTable2Alias];
675
+ }
676
+ }
677
+ // 递归处理嵌套对象
678
+ if (newObj.filter) newObj.filter = _regenerateUuid(newObj.filter, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
679
+ if (newObj.lhs) newObj.lhs = _regenerateUuid(newObj.lhs, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
680
+ if (newObj.rhs) newObj.rhs = _regenerateUuid(newObj.rhs, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
681
+ if (newObj.expressions) newObj.expressions = _regenerateUuid(newObj.expressions, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
682
+ if (newObj.customColumn) newObj.customColumn = _regenerateUuid(newObj.customColumn, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
683
+ if (newObj.group) newObj.group = _regenerateUuid(newObj.group, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
684
+ if (newObj.by) newObj.by = _regenerateUuid(newObj.by, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
685
+ if (newObj.columns) newObj.columns = _regenerateUuid(newObj.columns, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
686
+ if (newObj.subquery) newObj.subquery = _regenerateUuid(newObj.subquery, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
687
+ if (newObj.list) newObj.list = _regenerateUuid(newObj.list, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
688
+ if (newObj.table) newObj.table = _regenerateUuid(newObj.table, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
689
+ if (newObj.args) newObj.args = _regenerateUuid(newObj.args, uuidMap, aliasMap, tableAliasMap, existingAliases, originalTable2Uuid, newTable2Uuid, originalTable2Alias);
690
+ return newObj;
691
+ }
692
+ return obj;
693
+ };
694
+ var getNewMeta = function getNewMeta(_type, index, groupIndex, obj, uuidMap, aliasMap, tableAliasMap, existingAliases) {
609
695
  var type = _type || obj.type;
610
696
  var item = false;
611
697
  var newMeta = metaList[groupIndex].list.slice();
698
+ // 如果没有传入 existingAliases,从 metaList 中提取
699
+ if (!existingAliases && newMeta) {
700
+ existingAliases = newMeta === null || newMeta === void 0 ? void 0 : newMeta.map(function (v) {
701
+ var _v$table3, _v$table4;
702
+ if (v.type === TypeEnum.data) return (_v$table3 = v.table) === null || _v$table3 === void 0 ? void 0 : _v$table3.alias;
703
+ if (v.type === TypeEnum.joinData) return (_v$table4 = v.table2) === null || _v$table4 === void 0 ? void 0 : _v$table4.alias;
704
+ return undefined;
705
+ }).filter(function (alias) {
706
+ return Boolean(alias);
707
+ });
708
+ }
612
709
  var mainTable = newMeta[0];
613
710
  metaKey += 1;
614
711
  if (type === TypeEnum.joinData) {
@@ -718,28 +815,105 @@ var useStore = function useStore() {
718
815
  return false;
719
816
  }
720
817
  if (obj) {
721
- item = _objectSpread(_objectSpread({}, obj), {}, {
722
- metaKey: metaKey
723
- });
818
+ // 只对 joinData 类型调用 regenerateUuid
819
+ if (obj.type === TypeEnum.joinData) {
820
+ item = _objectSpread(_objectSpread({}, _regenerateUuid(obj, uuidMap || {}, aliasMap || {}, tableAliasMap || {}, existingAliases || [])), {}, {
821
+ metaKey: metaKey
822
+ });
823
+ } else {
824
+ item = _objectSpread(_objectSpread({}, obj), {}, {
825
+ metaKey: metaKey
826
+ });
827
+ }
724
828
  }
725
829
  return item;
726
830
  };
727
- var addMeta = function addMeta(type, index, groupIndex, obj) {
831
+ // 检查粘贴位置上下级的 table1 是否与被粘贴项的 table1 有相同的 alias
832
+ var checkTable1Conflict = function checkTable1Conflict(objList, index, groupIndex) {
833
+ var _metaList$groupIndex, _objList$;
834
+ if (!objList || objList.length === 0) return {
835
+ hasConflict: false
836
+ };
837
+ var groupList = ((_metaList$groupIndex = metaList[groupIndex]) === null || _metaList$groupIndex === void 0 ? void 0 : _metaList$groupIndex.list) || [];
838
+ // 获取被粘贴项的 table1 alias
839
+ var pastedTable1Alias = (_objList$ = objList[0]) === null || _objList$ === void 0 || (_objList$ = _objList$.table1) === null || _objList$ === void 0 ? void 0 : _objList$.alias;
840
+ if (!pastedTable1Alias) return {
841
+ hasConflict: false
842
+ };
843
+ // 检查上下级的 table1 和 table2 alias
844
+ var checkItem = function checkItem(item) {
845
+ if (!item) return undefined;
846
+ if (item.type === TypeEnum.joinData) {
847
+ var _item$table, _item$table2;
848
+ if (((_item$table = item.table1) === null || _item$table === void 0 ? void 0 : _item$table.alias) === pastedTable1Alias) return item.table1.alias;
849
+ if (((_item$table2 = item.table2) === null || _item$table2 === void 0 ? void 0 : _item$table2.alias) === pastedTable1Alias) return item.table2.alias;
850
+ }
851
+ if (item.type === TypeEnum.data) {
852
+ var _item$table3;
853
+ if (((_item$table3 = item.table) === null || _item$table3 === void 0 ? void 0 : _item$table3.alias) === pastedTable1Alias) return item.table.alias;
854
+ }
855
+ return undefined;
856
+ };
857
+ // 检查上邻(index - 1 位置)
858
+ var prevItem = groupList[index - 1];
859
+ var prevConflict = checkItem(prevItem);
860
+ if (prevConflict) {
861
+ return {
862
+ hasConflict: true,
863
+ conflictingAlias: pastedTable1Alias
864
+ };
865
+ }
866
+ // 检查下邻(index 位置,即被插入位置的原元素)
867
+ var nextItem = groupList[index];
868
+ var nextConflict = checkItem(nextItem);
869
+ if (nextConflict) {
870
+ return {
871
+ hasConflict: true,
872
+ conflictingAlias: pastedTable1Alias
873
+ };
874
+ }
875
+ return {
876
+ hasConflict: false
877
+ };
878
+ };
879
+ var addMeta = function addMeta(type, index, groupIndex, obj, onConflict) {
880
+ // 检查 table1 冲突(仅在启用配置时检测)
881
+ if (joinAliasConflictCheck && obj && obj.length > 0) {
882
+ var conflict = checkTable1Conflict(obj, index, groupIndex);
883
+ if (conflict.hasConflict && conflict.conflictingAlias && onConflict) {
884
+ onConflict(conflict.conflictingAlias);
885
+ return false;
886
+ }
887
+ }
728
888
  var newMeta = metaList[groupIndex].list.slice();
729
889
  var items = [];
890
+ // 创建共享的映射对象,确保循环调用时保持一致
891
+ var sharedUuidMap = {};
892
+ var sharedAliasMap = {};
893
+ var sharedTableAliasMap = {};
894
+ // 提取当前组中已存在的 alias
895
+ var existingAliases = newMeta === null || newMeta === void 0 ? void 0 : newMeta.map(function (v) {
896
+ var _v$table5, _v$table6;
897
+ if (v.type === TypeEnum.data) return (_v$table5 = v.table) === null || _v$table5 === void 0 ? void 0 : _v$table5.alias;
898
+ if (v.type === TypeEnum.joinData) return (_v$table6 = v.table2) === null || _v$table6 === void 0 ? void 0 : _v$table6.alias;
899
+ return undefined;
900
+ }).filter(function (alias) {
901
+ return Boolean(alias);
902
+ });
730
903
  if (obj) {
731
904
  items = obj.map(function (v) {
732
- return getNewMeta(type, index, groupIndex, v);
905
+ return getNewMeta(type, index, groupIndex, v, sharedUuidMap, sharedAliasMap, sharedTableAliasMap, existingAliases);
733
906
  });
734
907
  } else {
735
- items = [getNewMeta(type, index, groupIndex, obj)];
908
+ items = [getNewMeta(type, index, groupIndex, obj, sharedUuidMap, sharedAliasMap, sharedTableAliasMap, existingAliases)];
736
909
  }
737
910
  if (items[0] === false) {
738
- return;
911
+ return false;
739
912
  }
740
913
  // @ts-ignore
741
914
  newMeta.splice.apply(newMeta, [index, 0].concat(_toConsumableArray(items)));
742
915
  setMeta(newMeta, groupIndex);
916
+ return true;
743
917
  };
744
918
  var delMeta = function delMeta(meta, groupIndex) {
745
919
  if (meta.type === 'group') {
@@ -908,7 +1082,9 @@ var useStore = function useStore() {
908
1082
  operatorList: operatorList,
909
1083
  setOperatorList: setOperatorList,
910
1084
  setExistsErrorFn: setExistsErrorFn,
911
- existsError: existsError
1085
+ existsError: existsError,
1086
+ joinAliasConflictCheck: joinAliasConflictCheck,
1087
+ setJoinAliasConflictCheck: setJoinAliasConflictCheck
912
1088
  };
913
1089
  };
914
1090
  export default useStore;
package/lib/es/index.js CHANGED
@@ -71,6 +71,8 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
71
71
  moduleDiff = _props$moduleDiff === void 0 ? false : _props$moduleDiff,
72
72
  _props$moduleCopy = props.moduleCopy,
73
73
  moduleCopy = _props$moduleCopy === void 0 ? false : _props$moduleCopy,
74
+ _props$joinAliasConfl = props.joinAliasConflictCheck,
75
+ joinAliasConflictCheck = _props$joinAliasConfl === void 0 ? false : _props$joinAliasConfl,
74
76
  _props$operatorList = props.operatorList,
75
77
  operatorList = _props$operatorList === void 0 ? EMPTY_ARRAY : _props$operatorList;
76
78
  var store = useData();
@@ -115,8 +117,9 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
115
117
  store.setModuleDiff(moduleDiff);
116
118
  store.setIsSubquery(isSubquery);
117
119
  store.setModuleCopy(moduleCopy);
120
+ store.setJoinAliasConflictCheck(joinAliasConflictCheck);
118
121
  store.setOperatorList(operatorList || []);
119
- }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit, tableEnableAlias, fieldEnableAlias, groupByEnableAlias, isSelectFields, tableFlat, copyType, metabaseCopy, moduleDiff, isSubquery, moduleCopy, operatorList]);
122
+ }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit, tableEnableAlias, fieldEnableAlias, groupByEnableAlias, isSelectFields, tableFlat, copyType, metabaseCopy, moduleDiff, isSubquery, moduleCopy, joinAliasConflictCheck, operatorList]);
120
123
  React.useImperativeHandle(ref, function () {
121
124
  return {
122
125
  // setDatasource: (list) => {
@@ -107,10 +107,12 @@ export interface AtomsField {
107
107
  export interface AtomsInputString {
108
108
  val: string;
109
109
  type: AtomsTypeEnum.INPUT_STRING;
110
+ format?: string;
110
111
  }
111
112
  export interface AtomsInputStringList {
112
113
  val: string[];
113
114
  type: AtomsTypeEnum.INPUT_STRING_LIST;
115
+ format?: string;
114
116
  }
115
117
  export interface AtomsInputNumberList {
116
118
  val: number[];
package/lib/es/types.d.ts CHANGED
@@ -52,6 +52,7 @@ export interface MetabaseProps {
52
52
  metabaseCopy?: boolean;
53
53
  moduleDiff?: boolean;
54
54
  moduleCopy?: boolean;
55
+ joinAliasConflictCheck?: boolean;
55
56
  getModuleDiffCode?: (obj: {
56
57
  oldCode: MetaListType;
57
58
  newCode: MetaListType;
@@ -16,5 +16,5 @@ export declare const replaceTpl: (inputString: string, values: {
16
16
  [key: string]: any;
17
17
  }) => string;
18
18
  export declare const uuidv4: (prefix?: string) => string;
19
- export declare const getAlias: (name: string | undefined, list: MetaListType[], columns?: any[]) => string;
19
+ export declare const getAlias: (name?: string, list?: MetaListType[], columns?: any[], extraAliases?: string[]) => string;
20
20
  export declare const mergeNameAlias: (name: string, alias: string, isEnable: boolean) => string;
@@ -133,15 +133,32 @@ export var uuidv4 = function uuidv4() {
133
133
  };
134
134
  export var getAlias = function getAlias() {
135
135
  var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
136
- var list = arguments.length > 1 ? arguments[1] : undefined;
136
+ var list = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
137
137
  var columns = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
138
+ var extraAliases = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
138
139
  // 提取所有有效的 alias
139
- if (!list || list.length < 1) return name;
140
- // const baseOld = oldName?.split('_')[0] ?? '';
141
- // const baseNew = name?.split('_')[0] ?? '';
142
- // if (oldName && baseOld === baseNew) {
143
- // return oldName;
144
- // }
140
+ if (!list || list.length < 1) {
141
+ // 如果没有 list,只有 extraAliases,需要检查 extraAliases 中是否有冲突
142
+ if (extraAliases.length === 0) return name;
143
+ var _regex = new RegExp("^".concat(name, "_(\\d+)$"));
144
+ var _indexes = extraAliases.map(function (alias) {
145
+ var match = alias.match(_regex);
146
+ return match ? parseInt(match[1], 10) : 0;
147
+ }).filter(function (num) {
148
+ return num > 0;
149
+ });
150
+ var _hasPureName = extraAliases.includes(name);
151
+ if (_hasPureName) {
152
+ _indexes.push(1);
153
+ }
154
+ if (_indexes.length === 0) {
155
+ return name;
156
+ }
157
+ var _uniqueIndexes = _toConsumableArray(new Set(_indexes)).sort(function (a, b) {
158
+ return a - b;
159
+ });
160
+ return "".concat(name, "_").concat(Math.max.apply(Math, _toConsumableArray(_uniqueIndexes)) + 1);
161
+ }
145
162
  var aliass = list === null || list === void 0 ? void 0 : list.map(function (v) {
146
163
  if (v.type === TypeEnum.data) {
147
164
  var _v$table;
@@ -154,7 +171,7 @@ export var getAlias = function getAlias() {
154
171
  return undefined;
155
172
  }).concat(columns.map(function (v) {
156
173
  return v.alias;
157
- })).filter(function (alias) {
174
+ })).concat(extraAliases).filter(function (alias) {
158
175
  return Boolean(alias);
159
176
  });
160
177
  // 收集所有 name_x 中的数字
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.104",
3
+ "version": "1.0.106",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",