@gingkoo/pandora-metabase 1.0.157 → 1.0.158-alpha.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.
Files changed (65) hide show
  1. package/lib/cjs/components/dialog/column-type-label/index.d.ts +8 -0
  2. package/lib/cjs/components/dialog/column-type-label/index.js +22 -0
  3. package/lib/cjs/components/dialog/column-type-label/index.less +17 -0
  4. package/lib/cjs/components/dialog/expression/index.js +7 -6
  5. package/lib/cjs/components/dialog/formula/index.js +1 -1
  6. package/lib/cjs/components/dialog/formula/utils.js +2 -0
  7. package/lib/cjs/components/dialog/formula-list/index.js +87 -23
  8. package/lib/cjs/components/dialog/formula-list/index.less +16 -0
  9. package/lib/cjs/components/dialog/formula-list/utils.d.ts +5 -4
  10. package/lib/cjs/components/dialog/formula-list/utils.js +61 -13
  11. package/lib/cjs/components/dialog/select-column/index.js +7 -1
  12. package/lib/cjs/components/dialog/select-column/index.less +6 -1
  13. package/lib/cjs/components/dialog/select-column-multiple/index.js +9 -6
  14. package/lib/cjs/components/dialog/select-column-multiple/index.less +10 -0
  15. package/lib/cjs/components/dialog/select-join-column/index.js +7 -3
  16. package/lib/cjs/components/dialog/select-join-column/index.less +10 -0
  17. package/lib/cjs/components/dialog/select-join-column-multiple/index.js +7 -3
  18. package/lib/cjs/components/dialog/select-join-column-multiple/index.less +10 -0
  19. package/lib/cjs/components/metabase/index.js +51 -0
  20. package/lib/cjs/components/metabase/index.less +0 -19
  21. package/lib/cjs/components/modules/components/meta-icon.js +1 -3
  22. package/lib/cjs/components/modules/join-data.js +81 -13
  23. package/lib/cjs/components/modules/summarize/group-by.js +10 -6
  24. package/lib/cjs/components/modules/table-data.js +25 -7
  25. package/lib/cjs/hooks/use-state.js +31 -63
  26. package/lib/cjs/index.js +1 -1
  27. package/lib/cjs/locale/en.js +2 -0
  28. package/lib/cjs/locale/zh.js +2 -0
  29. package/lib/cjs/store/types.d.ts +2 -0
  30. package/lib/cjs/utils/transformSql.js +4 -0
  31. package/lib/cjs/utils.d.ts +2 -0
  32. package/lib/cjs/utils.js +74 -36
  33. package/lib/es/components/dialog/column-type-label/index.d.ts +8 -0
  34. package/lib/es/components/dialog/column-type-label/index.js +16 -0
  35. package/lib/es/components/dialog/column-type-label/index.less +17 -0
  36. package/lib/es/components/dialog/expression/index.js +7 -6
  37. package/lib/es/components/dialog/formula/index.js +1 -1
  38. package/lib/es/components/dialog/formula/utils.js +2 -0
  39. package/lib/es/components/dialog/formula-list/index.js +89 -25
  40. package/lib/es/components/dialog/formula-list/index.less +16 -0
  41. package/lib/es/components/dialog/formula-list/utils.d.ts +5 -4
  42. package/lib/es/components/dialog/formula-list/utils.js +60 -12
  43. package/lib/es/components/dialog/select-column/index.js +7 -1
  44. package/lib/es/components/dialog/select-column/index.less +6 -1
  45. package/lib/es/components/dialog/select-column-multiple/index.js +9 -6
  46. package/lib/es/components/dialog/select-column-multiple/index.less +10 -0
  47. package/lib/es/components/dialog/select-join-column/index.js +7 -3
  48. package/lib/es/components/dialog/select-join-column/index.less +10 -0
  49. package/lib/es/components/dialog/select-join-column-multiple/index.js +7 -3
  50. package/lib/es/components/dialog/select-join-column-multiple/index.less +10 -0
  51. package/lib/es/components/metabase/index.js +51 -0
  52. package/lib/es/components/metabase/index.less +0 -19
  53. package/lib/es/components/modules/components/meta-icon.js +2 -4
  54. package/lib/es/components/modules/join-data.js +83 -15
  55. package/lib/es/components/modules/summarize/group-by.js +10 -6
  56. package/lib/es/components/modules/table-data.js +27 -9
  57. package/lib/es/hooks/use-state.js +31 -63
  58. package/lib/es/index.js +1 -1
  59. package/lib/es/locale/en.js +2 -0
  60. package/lib/es/locale/zh.js +2 -0
  61. package/lib/es/store/types.d.ts +2 -0
  62. package/lib/es/utils/transformSql.js +4 -0
  63. package/lib/es/utils.d.ts +2 -0
  64. package/lib/es/utils.js +74 -36
  65. package/package.json +1 -1
@@ -23,11 +23,11 @@ import { AtomsTypeEnum, FormulaTypeEnum } from '../../../store/types';
23
23
  import { ColumnsPopupThemeEnum } from '../../../store/enum';
24
24
  import { Select, Input, Modal2, Modal, InputNumber, Space, Button, Checkbox, Tooltip, Toast, Editor } from '@gingkoo/pandora';
25
25
  import cloneDeep from 'lodash/cloneDeep';
26
- import { buildSqlQuery, getAtomDisplayText, isError, changeCopyField, isExistsError, normalizeAndOrStructure, normalizeLegacySummarizeForSave, splitByUnion, syncAtomQuotes } from '../../../utils';
26
+ import { buildSqlQuery, getAtomDisplayText, getFieldReferenceError, changeCopyField, isExistsError, normalizeAndOrStructure, normalizeLegacySummarizeForSave, splitByUnion, syncAtomQuotes } from '../../../utils';
27
27
  import Formula from '../formula';
28
28
  import { AddIcon, CloseIcon, UpArrowIcon } from '../../icons';
29
29
  import { Expression, SelectColumnMultiple, SelectTable } from '../../dialog';
30
- import { customTypes, operatorList as __operatorList, insertTemplateAt, getTemplateItem, validateExpressionIntegrity, getConstantLabel, normalizeExpressionAtoms } from './utils';
30
+ import { customTypes, operatorList as __operatorList, insertTemplateAt, getTemplateItem, validateExpressionIntegrity, getConstantLabel, normalizeExpressionAtoms, normalizeOperatorList } from './utils';
31
31
  import SelectList from '../../dialog/select-list';
32
32
  import arrow from './arrow.svg';
33
33
  import { useStore, Provider } from '../../../hooks/use-provider';
@@ -1047,8 +1047,8 @@ var FormulaList = forwardRef(function (props, ref) {
1047
1047
  return normalizeAndOrStructure(value || []);
1048
1048
  }, [value]);
1049
1049
  var normalizedExpressionValue = useMemo(function () {
1050
- return normalizeExpressionAtoms(normalizedStructureValue, data);
1051
- }, [normalizedStructureValue, data]);
1050
+ return normalizeExpressionAtoms(normalizedStructureValue, data, store.filterCustomType);
1051
+ }, [normalizedStructureValue, data, store.filterCustomType]);
1052
1052
  var normalizedValue = useMemo(function () {
1053
1053
  return normalizedExpressionValue.map(syncAtomQuotes);
1054
1054
  }, [normalizedExpressionValue]);
@@ -1067,9 +1067,9 @@ var FormulaList = forwardRef(function (props, ref) {
1067
1067
  var hasFormulaDiffAction = Boolean(store.showFormulaDiff && store.hasFormulaDiffCode);
1068
1068
  var operatorList = useMemo(function () {
1069
1069
  if (store.operatorList.length > 0) {
1070
- return store.operatorList;
1070
+ return normalizeOperatorList(store.operatorList);
1071
1071
  }
1072
- return __operatorList;
1072
+ return normalizeOperatorList(__operatorList);
1073
1073
  }, [store.operatorList]);
1074
1074
  var _useState15 = useState(false),
1075
1075
  _useState16 = _slicedToArray(_useState15, 2),
@@ -1272,7 +1272,7 @@ var FormulaList = forwardRef(function (props, ref) {
1272
1272
  return _withSyncedQuotesInner(item, new WeakMap());
1273
1273
  };
1274
1274
  var setCaseList = function setCaseList(atoms) {
1275
- var nextData = normalizeExpressionAtoms(atoms, data).map(function (item) {
1275
+ var nextData = normalizeExpressionAtoms(atoms, data, store.filterCustomType).map(function (item) {
1276
1276
  return withSyncedQuotes(item);
1277
1277
  });
1278
1278
  var quotes = nextData.map(function (item) {
@@ -2387,8 +2387,32 @@ var FormulaList = forwardRef(function (props, ref) {
2387
2387
  var _caseList = caseList.slice();
2388
2388
  var currentItem = _caseList[i];
2389
2389
  var oldVal = _caseList[i].val;
2390
- var oldType = _caseList[i].type;
2390
+ var oldType = (currentItem === null || currentItem === void 0 ? void 0 : currentItem.type) || '';
2391
+ var isOperatorItem = oldType === AtomsTypeEnum.OPERATOR;
2391
2392
  var otherTypeConfig = otherTypeMap.get(String(oldType));
2393
+ if (oldType === AtomsTypeEnum.OPERATOR && (oldVal === '(' || oldVal === ')')) {
2394
+ if (val === '()') return;
2395
+ var matchingIndex = getMatchingParenthesisIndex(_caseList, i);
2396
+ if (matchingIndex >= 0) {
2397
+ _caseList.splice(matchingIndex, 1);
2398
+ }
2399
+ var currentIndex = matchingIndex >= 0 && matchingIndex < i ? i - 1 : i;
2400
+ _caseList[currentIndex].val = val;
2401
+ _caseList = insertTemplateAt(oldVal, val, _caseList, currentIndex);
2402
+ setCaseList(_caseList);
2403
+ return;
2404
+ }
2405
+ if (oldType === AtomsTypeEnum.OPERATOR && val === '()') {
2406
+ _caseList.splice(i, 1, {
2407
+ type: AtomsTypeEnum.OPERATOR,
2408
+ val: '('
2409
+ }, {
2410
+ type: AtomsTypeEnum.OPERATOR,
2411
+ val: ')'
2412
+ });
2413
+ setCaseList(_caseList);
2414
+ return;
2415
+ }
2392
2416
  if (oldType === AtomsTypeEnum.CONSTANT) {
2393
2417
  _caseList[i].id = val;
2394
2418
  _caseList[i].val = getConstantLabel(store.constantList, val);
@@ -2399,7 +2423,9 @@ var FormulaList = forwardRef(function (props, ref) {
2399
2423
  } else {
2400
2424
  _caseList[i].val = val;
2401
2425
  }
2402
- _caseList = insertTemplateAt(oldVal, val, _caseList, i);
2426
+ if (isOperatorItem) {
2427
+ _caseList = insertTemplateAt(oldVal, val, _caseList, i);
2428
+ }
2403
2429
  setCaseList(_caseList);
2404
2430
  };
2405
2431
  function handleExpression(e, i, val) {
@@ -2423,17 +2449,44 @@ var FormulaList = forwardRef(function (props, ref) {
2423
2449
  })
2424
2450
  });
2425
2451
  }
2452
+ function getMatchingParenthesisIndex(list, index) {
2453
+ var item = list[index];
2454
+ if ((item === null || item === void 0 ? void 0 : item.type) !== AtomsTypeEnum.OPERATOR) return -1;
2455
+ var isOpening = item.val === '(';
2456
+ var isClosing = item.val === ')';
2457
+ if (!isOpening && !isClosing) return -1;
2458
+ var depth = 0;
2459
+ var step = isOpening ? 1 : -1;
2460
+ for (var currentIndex = index; currentIndex >= 0 && currentIndex < list.length; currentIndex += step) {
2461
+ var currentItem = list[currentIndex];
2462
+ if ((currentItem === null || currentItem === void 0 ? void 0 : currentItem.type) !== AtomsTypeEnum.OPERATOR) continue;
2463
+ if (currentItem.val === '(') depth += isOpening ? 1 : -1;
2464
+ if (currentItem.val === ')') depth += isOpening ? -1 : 1;
2465
+ if (depth === 0) return currentIndex;
2466
+ }
2467
+ return -1;
2468
+ }
2469
+ function getDeletionIndexSet(list, indices) {
2470
+ var indexSet = new Set(indices);
2471
+ indices.forEach(function (index) {
2472
+ var matchingIndex = getMatchingParenthesisIndex(list, index);
2473
+ if (matchingIndex >= 0) indexSet.add(matchingIndex);
2474
+ });
2475
+ return indexSet;
2476
+ }
2426
2477
  function handleDel(e, index) {
2427
2478
  e.stopPropagation();
2428
2479
  var _caseList = caseList.slice();
2429
- _caseList.splice(index, 1);
2430
- setCaseList(_caseList);
2480
+ var indexSet = getDeletionIndexSet(_caseList, [index]);
2481
+ setCaseList(_caseList.filter(function (_, itemIndex) {
2482
+ return !indexSet.has(itemIndex);
2483
+ }));
2431
2484
  closePopup();
2432
2485
  }
2433
2486
  function handleDelItems(e, indices) {
2434
2487
  e.stopPropagation();
2435
2488
  if (!indices.length) return;
2436
- var indexSet = new Set(indices);
2489
+ var indexSet = getDeletionIndexSet(caseList, indices);
2437
2490
  var _caseList = caseList.filter(function (_, itemIndex) {
2438
2491
  return !indexSet.has(itemIndex);
2439
2492
  });
@@ -2535,7 +2588,7 @@ var FormulaList = forwardRef(function (props, ref) {
2535
2588
  return _regeneratorRuntime.wrap(function (_context0) {
2536
2589
  while (1) switch (_context0.prev = _context0.next) {
2537
2590
  case 0:
2538
- selectedIndexSet = new Set(selectedIndices);
2591
+ selectedIndexSet = getDeletionIndexSet(caseList, selectedIndices);
2539
2592
  _caseList = caseList.filter(function (_, index) {
2540
2593
  return !selectedIndexSet.has(index);
2541
2594
  });
@@ -2576,28 +2629,37 @@ var FormulaList = forwardRef(function (props, ref) {
2576
2629
  var _caseList = caseList.slice() || [];
2577
2630
  var _ind = index;
2578
2631
  var otherTypeConfig = otherTypeMap.get(String(type));
2579
- var temItem = otherTypeConfig ? {
2632
+ var isParentheses = type === '()';
2633
+ var temItems = isParentheses ? [{
2634
+ type: AtomsTypeEnum.OPERATOR,
2635
+ val: '('
2636
+ }, {
2637
+ type: AtomsTypeEnum.OPERATOR,
2638
+ val: ')'
2639
+ }] : [otherTypeConfig ? {
2580
2640
  id: '',
2581
2641
  val: '',
2582
2642
  type: type
2583
- } : getTemplateItem(type);
2643
+ } : getTemplateItem(type)];
2584
2644
  if (position === 'add') {
2585
- _caseList.push(temItem);
2645
+ _caseList.push.apply(_caseList, temItems);
2586
2646
  _ind = _caseList.length - 1;
2587
2647
  } else if (position === 'before') {
2588
- _caseList.splice(index, 0, temItem);
2648
+ _caseList.splice.apply(_caseList, [index, 0].concat(temItems));
2589
2649
  _ind = index;
2590
2650
  } else if (position === 'after') {
2591
- _caseList.splice(index + 1, 0, temItem);
2651
+ _caseList.splice.apply(_caseList, [index + 1, 0].concat(temItems));
2592
2652
  _ind = index + 1;
2593
2653
  } else {
2594
- _caseList.splice(index, 1, temItem);
2654
+ _caseList.splice.apply(_caseList, [index, 1].concat(temItems));
2595
2655
  _ind = index;
2596
2656
  }
2597
2657
  setCaseList(_caseList);
2598
2658
  return _ind < 0 ? 0 : _ind;
2599
2659
  };
2600
2660
  var getItemNameProps = function getItemNameProps(v) {
2661
+ var referenceError = getFieldReferenceError(v, data);
2662
+ var referenceErrorMessage = referenceError ? __("metabase.".concat(referenceError, "NotExists")) : '';
2601
2663
  if (v.type === AtomsTypeEnum.NOT_EXISTS || v.type === AtomsTypeEnum.EXISTS) {
2602
2664
  return {
2603
2665
  isError: isExistsError(v.notExists, store.existsError)
@@ -2610,7 +2672,8 @@ var FormulaList = forwardRef(function (props, ref) {
2610
2672
  }
2611
2673
  if (v.type === AtomsTypeEnum.FIELD) {
2612
2674
  return {
2613
- isError: isError(v, data)
2675
+ isError: Boolean(referenceError),
2676
+ message: referenceErrorMessage
2614
2677
  };
2615
2678
  }
2616
2679
  if (v.type === AtomsTypeEnum.CONSTANT) {
@@ -2629,14 +2692,15 @@ var FormulaList = forwardRef(function (props, ref) {
2629
2692
  }
2630
2693
  if (v.type === AtomsTypeEnum.EXPRESSION) {
2631
2694
  return {
2632
- isError: isError(v, data)
2695
+ isError: Boolean(referenceError),
2696
+ message: referenceErrorMessage
2633
2697
  };
2634
2698
  }
2635
2699
  if (v.type === AtomsTypeEnum.FORMULA) {
2636
2700
  var formulaMissing = formulaIsError(v, formulaList);
2637
2701
  return {
2638
- isError: isError(v, data) || formulaMissing,
2639
- message: formulaMissing ? '公式丢失' : ''
2702
+ isError: Boolean(referenceError) || formulaMissing,
2703
+ message: formulaMissing ? '公式丢失' : referenceErrorMessage
2640
2704
  };
2641
2705
  }
2642
2706
  return {
@@ -2855,7 +2919,7 @@ var FormulaList = forwardRef(function (props, ref) {
2855
2919
  className: 'notSelected',
2856
2920
  node: _jsxs(_Fragment, {
2857
2921
  children: [_jsx(FieldString, {}), _jsx(Input, {
2858
- className: ':sqb-Custom-input',
2922
+ className: 'sqb-Custom-input',
2859
2923
  value: v.val,
2860
2924
  placeholder: __('SqlQueryBuilder.pleaseEnter'),
2861
2925
  size: 'large',
@@ -2871,7 +2935,7 @@ var FormulaList = forwardRef(function (props, ref) {
2871
2935
  className: 'notSelected',
2872
2936
  node: _jsxs(_Fragment, {
2873
2937
  children: [_jsx(FieldNumber, {}), _jsx(InputNumber, {
2874
- className: ':sqb-Custom-input',
2938
+ className: 'sqb-Custom-input',
2875
2939
  value: v.val,
2876
2940
  placeholder: __('SqlQueryBuilder.pleaseEnter'),
2877
2941
  size: 'large',
@@ -407,6 +407,22 @@
407
407
  position: relative;
408
408
  // margin: 0 var(--sqb-item-shell-margin-x);
409
409
 
410
+ // Keep value inputs consistent in both the inline editor and its modal.
411
+ .sqb-Custom-input {
412
+ border: 0;
413
+ border-radius: 0;
414
+ padding: 0;
415
+ background: none !important;
416
+
417
+ .pd-Input,
418
+ .pd-Input-inner-wrapper {
419
+ border: 0;
420
+ border-radius: 0;
421
+ padding: 0;
422
+ background: none !important;
423
+ }
424
+ }
425
+
410
426
  &.hover,
411
427
  &:hover {
412
428
  z-index: 5;
@@ -7,11 +7,12 @@ type ExpressionTable = {
7
7
  columns?: any[];
8
8
  };
9
9
  export declare const EMPTY_RHS_CONDITIONS: Set<string>;
10
- export declare const getExpressionDatabaseType: (expression: AtomsExpression, tables?: ExpressionTable[]) => string;
11
- export declare const normalizeExpressionAtom: (expression: AtomsExpression, tables?: ExpressionTable[]) => AtomsExpression;
12
- export declare const normalizeExpressionAtoms: (atoms?: AtomsItem[], tables?: ExpressionTable[]) => AtomsItem[];
10
+ export declare const getExpressionDatabaseType: (expression: AtomsExpression, tables?: ExpressionTable[], filterCustomType?: boolean) => string;
11
+ export declare const normalizeExpressionAtom: (expression: AtomsExpression, tables?: ExpressionTable[], filterCustomType?: boolean) => AtomsExpression;
12
+ export declare const normalizeExpressionAtoms: (atoms?: AtomsItem[], tables?: ExpressionTable[], filterCustomType?: boolean) => AtomsItem[];
13
13
  export declare const insertTemplateAt: (oldType: string, type: string, list: any[], index: number) => any[];
14
14
  export declare const operatorList: string[];
15
+ export declare const normalizeOperatorList: (operators?: string[]) => string[];
15
16
  export declare const customTypes: ({
16
17
  value: AtomsTypeEnum;
17
18
  label: any;
@@ -22,7 +23,7 @@ export declare const customTypes: ({
22
23
  children: string[];
23
24
  })[];
24
25
  export declare const getTemplateItem: (type: AtomsTypeEnum, item?: any) => AtomsItem;
25
- export declare const isOk: (rhsVal: AtomsItem[]) => boolean;
26
+ export declare const isOk: (rhsVal: AtomsItem[], allowEmptyInputString?: boolean) => boolean;
26
27
  export declare function validateExpressionIntegrity(list: AtomsItem[]): {
27
28
  isError: boolean;
28
29
  error?: string;
@@ -28,6 +28,10 @@ var findExpressionColumn = function findExpressionColumn(expression) {
28
28
  };
29
29
  export var getExpressionDatabaseType = function getExpressionDatabaseType(expression) {
30
30
  var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
31
+ var filterCustomType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
32
+ if (filterCustomType) {
33
+ return String(expression.database_type || '').toUpperCase();
34
+ }
31
35
  var column = findExpressionColumn(expression, tables);
32
36
  return String((column === null || column === void 0 ? void 0 : column.database_type) || expression.database_type || '').toUpperCase();
33
37
  };
@@ -37,7 +41,8 @@ var normalizeExpressionRhs = function normalizeExpressionRhs(expression) {
37
41
  };
38
42
  export var normalizeExpressionAtom = function normalizeExpressionAtom(expression) {
39
43
  var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
40
- var databaseType = getExpressionDatabaseType(expression, tables);
44
+ var filterCustomType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
45
+ var databaseType = getExpressionDatabaseType(expression, tables, filterCustomType);
41
46
  return _objectSpread(_objectSpread({}, expression), {}, {
42
47
  lhs: expression.lhs || [],
43
48
  rhs: normalizeExpressionRhs(expression),
@@ -47,6 +52,7 @@ export var normalizeExpressionAtom = function normalizeExpressionAtom(expression
47
52
  export var normalizeExpressionAtoms = function normalizeExpressionAtoms() {
48
53
  var atoms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
49
54
  var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
55
+ var filterCustomType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
50
56
  var normalizeList = function normalizeList() {
51
57
  var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
52
58
  return items.map(normalizeItem);
@@ -54,7 +60,7 @@ export var normalizeExpressionAtoms = function normalizeExpressionAtoms() {
54
60
  var normalizeItem = function normalizeItem(item) {
55
61
  if (!item || _typeof(item) !== 'object') return item;
56
62
  if (item.type === AtomsTypeEnum.EXPRESSION) {
57
- var nextExpression = normalizeExpressionAtom(item, tables);
63
+ var nextExpression = normalizeExpressionAtom(item, tables, filterCustomType);
58
64
  return _objectSpread(_objectSpread({}, nextExpression), {}, {
59
65
  lhs: normalizeList(nextExpression.lhs),
60
66
  rhs: normalizeList(nextExpression.rhs)
@@ -103,6 +109,9 @@ export var normalizeExpressionAtoms = function normalizeExpressionAtoms() {
103
109
  };
104
110
  export var insertTemplateAt = function insertTemplateAt(oldType, type, list, index) {
105
111
  var temList = [];
112
+ var isInOperator = function isInOperator(operator) {
113
+ return ['in', 'not in'].includes(String(operator || '').toLowerCase());
114
+ };
106
115
  var needChange = ['RANK()', 'DENSE_RANK()', 'ROW_NUMBER()', 'when', 'case', 'then'].includes(oldType);
107
116
  if (needChange) {
108
117
  return list;
@@ -189,10 +198,46 @@ export var insertTemplateAt = function insertTemplateAt(oldType, type, list, ind
189
198
  type: AtomsTypeEnum.OPERATOR
190
199
  }];
191
200
  }
201
+ if (isInOperator(type) && !isInOperator(oldType)) {
202
+ temList = [{
203
+ type: AtomsTypeEnum.OPERATOR,
204
+ val: '('
205
+ }, {
206
+ type: AtomsTypeEnum.INPUT_STRING,
207
+ val: ''
208
+ }, {
209
+ type: AtomsTypeEnum.OPERATOR,
210
+ val: ','
211
+ }, {
212
+ type: AtomsTypeEnum.INPUT_STRING,
213
+ val: ''
214
+ }, {
215
+ type: AtomsTypeEnum.OPERATOR,
216
+ val: ')'
217
+ }];
218
+ }
192
219
  list.splice.apply(list, [index + 1, 0].concat(_toConsumableArray(temList)));
193
220
  return list;
194
221
  };
195
- export var operatorList = ['and', 'or', '(', ')', ',', '+', '-', '*', '/', '!', '!=', '<=', '>=', '<', '>', '=', 'case', 'when', 'then', 'else', 'end', 'NULL', 'DESC', 'ASC', 'OVER', 'PARTITION BY', 'ORDER BY', 'RANK()', 'DENSE_RANK()', 'ROW_NUMBER()'];
222
+ export var operatorList = ['and', 'or', '()', ',', '+', '-', '*', '/', '!', '!=', '<=', '>=', '<', '>', '=', 'case', 'when', 'then', 'else', 'end', 'NULL', 'DESC', 'ASC', 'OVER', 'PARTITION BY', 'ORDER BY', 'RANK()', 'DENSE_RANK()', 'ROW_NUMBER()'];
223
+ export var normalizeOperatorList = function normalizeOperatorList() {
224
+ var operators = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : operatorList;
225
+ var normalized = [];
226
+ var hasParentheses = false;
227
+ operators.forEach(function (operator) {
228
+ if (operator === '(' || operator === ')' || operator === '()') {
229
+ if (!hasParentheses) {
230
+ normalized.push('()');
231
+ hasParentheses = true;
232
+ }
233
+ return;
234
+ }
235
+ if (!normalized.includes(operator)) {
236
+ normalized.push(operator);
237
+ }
238
+ });
239
+ return normalized;
240
+ };
196
241
  export var customTypes = [{
197
242
  value: AtomsTypeEnum.FIELD,
198
243
  label: __('customColumn.field')
@@ -217,11 +262,11 @@ export var customTypes = [{
217
262
  }, {
218
263
  value: AtomsTypeEnum.OPERATOR,
219
264
  label: __('customColumn.operator'),
220
- children: operatorList
265
+ children: normalizeOperatorList(operatorList)
221
266
  }, {
222
267
  value: AtomsTypeEnum.FORMULA,
223
268
  label: __('customColumn.formula'),
224
- children: operatorList
269
+ children: normalizeOperatorList(operatorList)
225
270
  }, {
226
271
  value: AtomsTypeEnum.NOT_EXISTS,
227
272
  label: 'NOT_EXISTS'
@@ -352,6 +397,7 @@ export var getTemplateItem = function getTemplateItem(type, item) {
352
397
  return temItem;
353
398
  };
354
399
  var _isOk = function isOk(rhsVal) {
400
+ var allowEmptyInputString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
355
401
  return rhsVal.every(function (v) {
356
402
  if (v.type === AtomsTypeEnum.UNKNOWN) {
357
403
  return false;
@@ -361,36 +407,38 @@ var _isOk = function isOk(rhsVal) {
361
407
  return Boolean(v.fieldName);
362
408
  } else if (v.type === AtomsTypeEnum.EXPRESSION || v.type === AtomsTypeEnum.EXISTS || v.type === AtomsTypeEnum.NOT_EXISTS || v.type === AtomsTypeEnum.SUB_QUERY) {
363
409
  return Boolean(v.quotes);
410
+ } else if (v.type === AtomsTypeEnum.INPUT_STRING) {
411
+ return allowEmptyInputString ? typeof v.val === 'string' : Boolean(v.val);
364
412
  } else if (v.type === AtomsTypeEnum.INPUT_STRING_LIST) {
365
413
  return Array.isArray(v.val) && v.val.every(function (vv) {
366
414
  return Boolean(vv);
367
415
  });
368
416
  } else if (v.type === AtomsTypeEnum.COLLECTION) {
369
- return _isOk(v.list || []);
417
+ return _isOk(v.list || [], allowEmptyInputString);
370
418
  } else if (v.type === AtomsTypeEnum.CASE_WHEN) {
371
419
  return (v.whenClauses || []).length > 0 && (v.whenClauses || []).every(function (clause) {
372
- return _isOk(clause.whenAtoms || []) && _isOk(clause.thenAtoms || []);
373
- }) && _isOk(v.caseAtoms || []) && _isOk(v.elseAtoms || []);
420
+ return _isOk(clause.whenAtoms || [], allowEmptyInputString) && _isOk(clause.thenAtoms || [], allowEmptyInputString);
421
+ }) && _isOk(v.caseAtoms || [], allowEmptyInputString) && _isOk(v.elseAtoms || [], allowEmptyInputString);
374
422
  } else if (v.type === AtomsTypeEnum.AND_OR) {
375
423
  if (Array.isArray(v.items) && v.items.length > 0) {
376
424
  return v.items.every(function (item, index) {
377
425
  var _item$atoms;
378
426
  if (index > 0 && !item.operator) return false;
379
- return Boolean((_item$atoms = item.atoms) === null || _item$atoms === void 0 ? void 0 : _item$atoms.length) && _isOk(item.atoms || []);
427
+ return Boolean((_item$atoms = item.atoms) === null || _item$atoms === void 0 ? void 0 : _item$atoms.length) && _isOk(item.atoms || [], allowEmptyInputString);
380
428
  });
381
429
  }
382
430
  var legacyItem = v;
383
431
  var hasBinarySides = Array.isArray(legacyItem.leftAtoms) || Array.isArray(legacyItem.rightAtoms);
384
432
  if (hasBinarySides) {
385
433
  var _legacyItem$leftAtoms, _legacyItem$rightAtom;
386
- return Boolean(legacyItem.operator) && Boolean((_legacyItem$leftAtoms = legacyItem.leftAtoms) === null || _legacyItem$leftAtoms === void 0 ? void 0 : _legacyItem$leftAtoms.length) && Boolean((_legacyItem$rightAtom = legacyItem.rightAtoms) === null || _legacyItem$rightAtom === void 0 ? void 0 : _legacyItem$rightAtom.length) && _isOk(legacyItem.leftAtoms || []) && _isOk(legacyItem.rightAtoms || []);
434
+ return Boolean(legacyItem.operator) && Boolean((_legacyItem$leftAtoms = legacyItem.leftAtoms) === null || _legacyItem$leftAtoms === void 0 ? void 0 : _legacyItem$leftAtoms.length) && Boolean((_legacyItem$rightAtom = legacyItem.rightAtoms) === null || _legacyItem$rightAtom === void 0 ? void 0 : _legacyItem$rightAtom.length) && _isOk(legacyItem.leftAtoms || [], allowEmptyInputString) && _isOk(legacyItem.rightAtoms || [], allowEmptyInputString);
387
435
  }
388
- return Boolean(legacyItem.operator) && _isOk(legacyItem.atoms || []);
436
+ return Boolean(legacyItem.operator) && _isOk(legacyItem.atoms || [], allowEmptyInputString);
389
437
  } else if (v.type === AtomsTypeEnum.FORMULA) {
390
438
  if (!v.quotes) {
391
439
  return false;
392
440
  }
393
- return _isOk(v.args || []);
441
+ return _isOk(v.args || [], true);
394
442
  } else if (v.type === AtomsTypeEnum.SELECT) {
395
443
  return Array.isArray(v.val) ? v.val.length > 0 : Boolean(v.val);
396
444
  } else {
@@ -16,6 +16,7 @@ import { useStore } from '../../../hooks/use-provider';
16
16
  import { getColumnIdFirstKey, isSameColumnByIdFirst, uuidv4 } from '../../../utils/helper';
17
17
  import { changeFieldAlias, isValidSQLAlias } from '../../../utils';
18
18
  import { SearchIcon } from '../../icons';
19
+ import ColumnTypeLabel from '../column-type-label';
19
20
  var SelectColumn = function SelectColumn(_ref) {
20
21
  var _ref$data = _ref.data,
21
22
  data = _ref$data === void 0 ? [] : _ref$data,
@@ -227,7 +228,12 @@ var SelectColumn = function SelectColumn(_ref) {
227
228
  children: _jsx(SelectIcon, {})
228
229
  }) : _jsx("div", {
229
230
  className: 'no-select mr-2'
230
- }), v.name, v.name_zh ? " \uFF08".concat(v.name_zh, "\uFF09") : '', v.fieldAlias ? " as ".concat(v.fieldAlias) : '', store.fieldEnableAlias && !readonly && _jsx(Tooltip, {
231
+ }), _jsxs("span", {
232
+ className: 'Sqb-SelectColumn-name',
233
+ children: [v.name, v.name_zh ? " \uFF08".concat(v.name_zh, "\uFF09") : '', v.fieldAlias ? " as ".concat(v.fieldAlias) : '']
234
+ }), _jsx(ColumnTypeLabel, {
235
+ column: v
236
+ }), store.fieldEnableAlias && !readonly && _jsx(Tooltip, {
231
237
  title: __('SqlQueryBuilder.alias'),
232
238
  children: _jsx(Button, {
233
239
  className: ':Sqb-TableName-as',
@@ -37,9 +37,14 @@
37
37
  }
38
38
  .Sqb-TableName-as {
39
39
  // font-size: 16px;
40
- margin-left: auto;
40
+ margin-left: 8px;
41
41
  }
42
42
  }
43
+ .Sqb-SelectColumn-name {
44
+ flex: 1 1 auto;
45
+ min-width: 0;
46
+ overflow-wrap: anywhere;
47
+ }
43
48
  .Sqb-SelectColumn--header {
44
49
  position: sticky;
45
50
  top: 0;
@@ -14,6 +14,7 @@ import { SummarizeAlias } from '../../../store/helper';
14
14
  import { AtomsTypeEnum } from '../../../store/types';
15
15
  import { __ } from '../../../locale';
16
16
  import { NUMBER_GROUP, DATE_GROUP } from '../const';
17
+ import ColumnTypeLabel from '../column-type-label';
17
18
  import { useStore } from '../../../hooks/use-provider';
18
19
  import { replaceTpl, mergeNameAlias, uuidv4 } from '../../../utils/helper';
19
20
  import { SearchIcon, TableIcon, CircleIcon, LetterAaIcon, CalendarIcon, WellIcon, ForeignKeyIcon, UpArrowIcon2, DownArrowIcon2 } from '../../icons';
@@ -265,9 +266,8 @@ var SelectJoinColumn = function SelectJoinColumn(_ref) {
265
266
  return matchedColumn ? syncSelectedFieldByColumn(field, matchedColumn, tableItem) : field;
266
267
  });
267
268
  setValue(syncedValue);
268
- if (!readonly && !isEqual(syncedValue, _value || [])) {
269
- var _ref2;
270
- (_ref2 = onValueSync || onSelect) === null || _ref2 === void 0 || _ref2(syncedValue, getQuotes(syncedValue));
269
+ if (!readonly && onValueSync && !isEqual(syncedValue, _value || [])) {
270
+ onValueSync(syncedValue, getQuotes(syncedValue));
271
271
  }
272
272
  }, [data, _value, onValueSync]);
273
273
  var changeValue = function changeValue(tableUuid, val) {
@@ -503,11 +503,14 @@ var SelectJoinColumn = function SelectJoinColumn(_ref) {
503
503
  children: [_jsx("span", {
504
504
  className: 'List-item-icon',
505
505
  children: IconMap[special_type || database_type] || _jsx(LetterAaIcon, {})
506
- }), _jsx("div", {
507
- children: _jsxs("h4", {
506
+ }), _jsxs("div", {
507
+ className: 'List-item-content',
508
+ children: [_jsxs("h4", {
508
509
  className: 'List-item-title ml-2',
509
510
  children: [replaceTpl(store.fieldNameTpl, v), v.fieldAlias ? " as ".concat(v.fieldAlias) : '']
510
- })
511
+ }), _jsx(ColumnTypeLabel, {
512
+ column: v
513
+ })]
511
514
  })]
512
515
  })
513
516
  })
@@ -23,6 +23,16 @@
23
23
  align-items: center;
24
24
  color: #b8bbc3;
25
25
  }
26
+ .List-item-content {
27
+ display: flex;
28
+ align-items: center;
29
+ min-width: 0;
30
+ width: 100%;
31
+ .List-item-title {
32
+ flex: 1 1 auto;
33
+ min-width: 0;
34
+ }
35
+ }
26
36
  .List-item-title {
27
37
  word-break: break-word;
28
38
  word-wrap: anywhere;
@@ -10,6 +10,7 @@ import { ColumnsPopupThemeEnum, SQL_GROUP_TYPE } from '../../../store/enum';
10
10
  import { SummarizeAlias } from '../../../store/helper';
11
11
  import { __ } from '../../../locale';
12
12
  import { NUMBER_GROUP, DATE_GROUP } from '../const';
13
+ import ColumnTypeLabel from '../column-type-label';
13
14
  import { useStore } from '../../../hooks/use-provider';
14
15
  import { getColumnIdFirstKey, isSameColumnByIdName, replaceTpl, mergeNameAlias } from '../../../utils/helper';
15
16
  import { SearchIcon, TableIcon, CircleIcon, LetterAaIcon, CalendarIcon, WellIcon, ForeignKeyIcon, UpArrowIcon2, DownArrowIcon2, RightArrowIcon } from '../../icons';
@@ -308,11 +309,14 @@ var SelectJoinColumn = function SelectJoinColumn(_ref) {
308
309
  children: [_jsx("span", {
309
310
  className: 'List-item-icon',
310
311
  children: IconMap[special_type || database_type] || _jsx(LetterAaIcon, {})
311
- }), _jsx("div", {
312
- children: _jsx("h4", {
312
+ }), _jsxs("div", {
313
+ className: 'List-item-content',
314
+ children: [_jsx("h4", {
313
315
  className: 'List-item-title ml-2',
314
316
  children: replaceTpl(store.fieldNameTpl, v)
315
- })
317
+ }), _jsx(ColumnTypeLabel, {
318
+ column: v
319
+ })]
316
320
  })]
317
321
  }), OPEN_GROUP && isGroup && groupe !== SQL_GROUP_TYPE.STRING && _jsx(Popover, {
318
322
  placement: 'rt',
@@ -23,6 +23,16 @@
23
23
  align-items: center;
24
24
  color: #b8bbc3;
25
25
  }
26
+ .List-item-content {
27
+ display: flex;
28
+ align-items: center;
29
+ min-width: 0;
30
+ width: 100%;
31
+ .List-item-title {
32
+ flex: 1 1 auto;
33
+ min-width: 0;
34
+ }
35
+ }
26
36
  .List-item-title {
27
37
  word-break: break-word;
28
38
  word-wrap: anywhere;
@@ -10,6 +10,7 @@ import { ColumnsPopupThemeEnum, SQL_GROUP_TYPE } from '../../../store/enum';
10
10
  import { SummarizeAlias } from '../../../store/helper';
11
11
  import { __ } from '../../../locale';
12
12
  import { NUMBER_GROUP, DATE_GROUP } from '../const';
13
+ import ColumnTypeLabel from '../column-type-label';
13
14
  import { useStore } from '../../../hooks/use-provider';
14
15
  import { getColumnIdFirstKey, isSameColumnByIdName, replaceTpl, mergeNameAlias } from '../../../utils/helper';
15
16
  import { SearchIcon, TableIcon, CircleIcon, LetterAaIcon, CalendarIcon, WellIcon, ForeignKeyIcon, UpArrowIcon2, DownArrowIcon2 } from '../../icons';
@@ -244,11 +245,14 @@ var SelectJoinColumn = function SelectJoinColumn(_ref) {
244
245
  children: [_jsx("span", {
245
246
  className: 'List-item-icon',
246
247
  children: IconMap[special_type || database_type] || _jsx(LetterAaIcon, {})
247
- }), _jsx("div", {
248
- children: _jsx("h4", {
248
+ }), _jsxs("div", {
249
+ className: 'List-item-content',
250
+ children: [_jsx("h4", {
249
251
  className: 'List-item-title ml-2',
250
252
  children: replaceTpl(store.fieldNameTpl, v)
251
- })
253
+ }), _jsx(ColumnTypeLabel, {
254
+ column: v
255
+ })]
252
256
  })]
253
257
  })
254
258
  })
@@ -23,6 +23,16 @@
23
23
  align-items: center;
24
24
  color: #b8bbc3;
25
25
  }
26
+ .List-item-content {
27
+ display: flex;
28
+ align-items: center;
29
+ min-width: 0;
30
+ width: 100%;
31
+ .List-item-title {
32
+ flex: 1 1 auto;
33
+ min-width: 0;
34
+ }
35
+ }
26
36
  .List-item-title {
27
37
  word-break: break-word;
28
38
  word-wrap: anywhere;