@gingkoo/pandora-metabase 1.0.118 → 1.0.119

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 (195) hide show
  1. package/lib/cjs/common/Portal/index.js +0 -2
  2. package/lib/cjs/common/SplitView/index.d.ts +0 -4
  3. package/lib/cjs/common/SplitView/index.js +0 -10
  4. package/lib/cjs/components/dialog/custom-column/config.js +4 -48
  5. package/lib/cjs/components/dialog/custom-column/expression-editor.js +3 -14
  6. package/lib/cjs/components/dialog/custom-column/expressions/suggest.d.ts +2 -34
  7. package/lib/cjs/components/dialog/custom-column/expressions/suggest.js +2 -43
  8. package/lib/cjs/components/dialog/custom-column/expressions/tokenizer.js +8 -65
  9. package/lib/cjs/components/dialog/custom-column/index.js +2 -4
  10. package/lib/cjs/components/dialog/custom-column/tokenized-expression.js +2 -3
  11. package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +1 -1
  12. package/lib/cjs/components/dialog/custom-editor/index.js +2 -7
  13. package/lib/cjs/components/dialog/diff-viewer/index copy.js +1 -16
  14. package/lib/cjs/components/dialog/expression/date-format-picker.js +2 -20
  15. package/lib/cjs/components/dialog/expression/date-format.js +2 -8
  16. package/lib/cjs/components/dialog/expression/index.d.ts +0 -3
  17. package/lib/cjs/components/dialog/expression/index.js +2 -83
  18. package/lib/cjs/components/dialog/formula/index.js +1 -30
  19. package/lib/cjs/components/dialog/formula/utils.js +2 -10
  20. package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.d.ts +19 -0
  21. package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.js +109 -0
  22. package/lib/cjs/components/dialog/formula-list/LogicGroup.d.ts +9 -0
  23. package/lib/cjs/components/dialog/formula-list/LogicGroup.js +43 -0
  24. package/lib/cjs/components/dialog/formula-list/index.d.ts +3 -0
  25. package/lib/cjs/components/dialog/formula-list/index.js +967 -503
  26. package/lib/cjs/components/dialog/formula-list/index.less +724 -0
  27. package/lib/cjs/components/dialog/formula-list/utils.d.ts +0 -7
  28. package/lib/cjs/components/dialog/formula-list/utils.js +117 -113
  29. package/lib/cjs/components/dialog/select-column/index.d.ts +0 -6
  30. package/lib/cjs/components/dialog/select-column/index.js +4 -15
  31. package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +0 -8
  32. package/lib/cjs/components/dialog/select-column-multiple/index.js +6 -45
  33. package/lib/cjs/components/dialog/select-join/index.d.ts +0 -5
  34. package/lib/cjs/components/dialog/select-join/index.js +0 -6
  35. package/lib/cjs/components/dialog/select-join-column/index.d.ts +0 -8
  36. package/lib/cjs/components/dialog/select-join-column/index.js +7 -21
  37. package/lib/cjs/components/dialog/select-join-column-multiple/index.d.ts +0 -8
  38. package/lib/cjs/components/dialog/select-join-column-multiple/index.js +5 -35
  39. package/lib/cjs/components/dialog/select-permission-table/index.d.ts +0 -5
  40. package/lib/cjs/components/dialog/select-permission-table/index.js +0 -6
  41. package/lib/cjs/components/dialog/select-summarize/index.d.ts +3 -3
  42. package/lib/cjs/components/dialog/select-summarize/index.js +105 -18
  43. package/lib/cjs/components/dialog/select-summarize/index.less +23 -0
  44. package/lib/cjs/components/dialog/select-table/index.d.ts +0 -6
  45. package/lib/cjs/components/dialog/select-table/index.js +1 -9
  46. package/lib/cjs/components/metabase/index.js +72 -86
  47. package/lib/cjs/components/metabase/index.less +7 -7
  48. package/lib/cjs/components/modules/components/Wrapper.js +1 -1
  49. package/lib/cjs/components/modules/components/header.js +2 -2
  50. package/lib/cjs/components/modules/components/meta-icon.d.ts +0 -3
  51. package/lib/cjs/components/modules/components/meta-icon.js +2 -47
  52. package/lib/cjs/components/modules/custom-column.js +3 -29
  53. package/lib/cjs/components/modules/enum/filter-enum.js +9 -88
  54. package/lib/cjs/components/modules/filter.js +2 -20
  55. package/lib/cjs/components/modules/index.d.ts +4 -2
  56. package/lib/cjs/components/modules/index.js +24 -1
  57. package/lib/cjs/components/modules/join-data.js +13 -291
  58. package/lib/cjs/components/modules/row-limit.js +0 -1
  59. package/lib/cjs/components/modules/sort.js +1 -61
  60. package/lib/cjs/components/modules/summarize/group-by.d.ts +0 -5
  61. package/lib/cjs/components/modules/summarize/group-by.js +231 -76
  62. package/lib/cjs/components/modules/summarize/select-index.js +96 -46
  63. package/lib/cjs/components/modules/table-data.js +11 -64
  64. package/lib/cjs/components/popup.js +26 -32
  65. package/lib/cjs/hooks/patch.d.ts +1 -0
  66. package/lib/cjs/hooks/patch.js +104 -6
  67. package/lib/cjs/hooks/patch2.js +3 -165
  68. package/lib/cjs/hooks/use-provider.js +0 -3
  69. package/lib/cjs/hooks/use-state.js +55 -135
  70. package/lib/cjs/index.js +0 -15
  71. package/lib/cjs/locale/en.js +5 -0
  72. package/lib/cjs/locale/index.js +1 -4
  73. package/lib/cjs/locale/zh.js +5 -0
  74. package/lib/cjs/sql-formula.js +0 -1
  75. package/lib/cjs/store/enum.d.ts +6 -6
  76. package/lib/cjs/store/enum.js +0 -13
  77. package/lib/cjs/store/helper.d.ts +2 -1
  78. package/lib/cjs/store/helper.js +15 -225
  79. package/lib/cjs/store/types.d.ts +45 -67
  80. package/lib/cjs/store/types.js +3 -49
  81. package/lib/cjs/types.d.ts +1 -0
  82. package/lib/cjs/utils/cookies.js +0 -3
  83. package/lib/cjs/utils/event.js +1 -1
  84. package/lib/cjs/utils/helper-dom.d.ts +1 -0
  85. package/lib/cjs/utils/helper-dom.js +17 -10
  86. package/lib/cjs/utils/helper.js +1 -24
  87. package/lib/cjs/utils/keydown.js +4 -7
  88. package/lib/cjs/utils/platform.d.ts +0 -9
  89. package/lib/cjs/utils/platform.js +0 -10
  90. package/lib/cjs/utils/selection.js +0 -6
  91. package/lib/cjs/utils/storage.d.ts +0 -9
  92. package/lib/cjs/utils/storage.js +1 -11
  93. package/lib/cjs/utils/transformSql.d.ts +5 -0
  94. package/lib/cjs/utils/transformSql.js +42 -113
  95. package/lib/cjs/utils.d.ts +1 -6
  96. package/lib/cjs/utils.js +115 -255
  97. package/lib/es/common/Portal/index.js +0 -2
  98. package/lib/es/common/SplitView/index.d.ts +0 -4
  99. package/lib/es/common/SplitView/index.js +0 -10
  100. package/lib/es/components/dialog/custom-column/config.js +4 -48
  101. package/lib/es/components/dialog/custom-column/expression-editor.js +3 -14
  102. package/lib/es/components/dialog/custom-column/expressions/suggest.d.ts +2 -34
  103. package/lib/es/components/dialog/custom-column/expressions/suggest.js +2 -43
  104. package/lib/es/components/dialog/custom-column/expressions/tokenizer.js +8 -65
  105. package/lib/es/components/dialog/custom-column/index.js +2 -4
  106. package/lib/es/components/dialog/custom-column/tokenized-expression.js +1 -3
  107. package/lib/es/components/dialog/custom-column/tokenizedI-input.js +1 -1
  108. package/lib/es/components/dialog/custom-editor/index.js +1 -7
  109. package/lib/es/components/dialog/diff-viewer/index copy.js +1 -15
  110. package/lib/es/components/dialog/expression/date-format-picker.js +2 -20
  111. package/lib/es/components/dialog/expression/date-format.js +2 -8
  112. package/lib/es/components/dialog/expression/index.d.ts +0 -3
  113. package/lib/es/components/dialog/expression/index.js +2 -82
  114. package/lib/es/components/dialog/formula/index.js +0 -30
  115. package/lib/es/components/dialog/formula/utils.js +2 -10
  116. package/lib/es/components/dialog/formula-list/CaseWhenGroup.d.ts +19 -0
  117. package/lib/es/components/dialog/formula-list/CaseWhenGroup.js +102 -0
  118. package/lib/es/components/dialog/formula-list/LogicGroup.d.ts +9 -0
  119. package/lib/es/components/dialog/formula-list/LogicGroup.js +36 -0
  120. package/lib/es/components/dialog/formula-list/index.d.ts +3 -0
  121. package/lib/es/components/dialog/formula-list/index.js +966 -503
  122. package/lib/es/components/dialog/formula-list/index.less +724 -0
  123. package/lib/es/components/dialog/formula-list/utils.d.ts +0 -7
  124. package/lib/es/components/dialog/formula-list/utils.js +117 -113
  125. package/lib/es/components/dialog/index.js +3 -3
  126. package/lib/es/components/dialog/select-column/index.d.ts +0 -6
  127. package/lib/es/components/dialog/select-column/index.js +4 -14
  128. package/lib/es/components/dialog/select-column-multiple/index.d.ts +0 -8
  129. package/lib/es/components/dialog/select-column-multiple/index.js +7 -47
  130. package/lib/es/components/dialog/select-join/index.d.ts +0 -5
  131. package/lib/es/components/dialog/select-join/index.js +0 -5
  132. package/lib/es/components/dialog/select-join-column/index.d.ts +0 -8
  133. package/lib/es/components/dialog/select-join-column/index.js +7 -20
  134. package/lib/es/components/dialog/select-join-column-multiple/index.d.ts +0 -8
  135. package/lib/es/components/dialog/select-join-column-multiple/index.js +5 -34
  136. package/lib/es/components/dialog/select-permission-table/index.d.ts +0 -5
  137. package/lib/es/components/dialog/select-permission-table/index.js +0 -5
  138. package/lib/es/components/dialog/select-summarize/index.d.ts +3 -3
  139. package/lib/es/components/dialog/select-summarize/index.js +106 -18
  140. package/lib/es/components/dialog/select-summarize/index.less +23 -0
  141. package/lib/es/components/dialog/select-table/index.d.ts +0 -6
  142. package/lib/es/components/dialog/select-table/index.js +1 -8
  143. package/lib/es/components/metabase/index.js +72 -87
  144. package/lib/es/components/metabase/index.less +7 -7
  145. package/lib/es/components/modules/components/Wrapper.js +1 -1
  146. package/lib/es/components/modules/components/header.js +2 -2
  147. package/lib/es/components/modules/components/meta-icon.d.ts +0 -3
  148. package/lib/es/components/modules/components/meta-icon.js +2 -46
  149. package/lib/es/components/modules/custom-column.js +3 -29
  150. package/lib/es/components/modules/enum/filter-enum.js +9 -88
  151. package/lib/es/components/modules/filter.js +2 -19
  152. package/lib/es/components/modules/index.d.ts +4 -2
  153. package/lib/es/components/modules/index.js +24 -1
  154. package/lib/es/components/modules/join-data.js +13 -291
  155. package/lib/es/components/modules/row-limit.js +0 -1
  156. package/lib/es/components/modules/sort.js +1 -61
  157. package/lib/es/components/modules/summarize/group-by.d.ts +0 -5
  158. package/lib/es/components/modules/summarize/group-by.js +233 -78
  159. package/lib/es/components/modules/summarize/select-index.js +96 -46
  160. package/lib/es/components/modules/table-data.js +11 -64
  161. package/lib/es/components/popup.js +27 -33
  162. package/lib/es/hooks/patch.d.ts +1 -0
  163. package/lib/es/hooks/patch.js +103 -5
  164. package/lib/es/hooks/patch2.js +2 -164
  165. package/lib/es/hooks/use-provider.js +0 -3
  166. package/lib/es/hooks/use-state.js +55 -135
  167. package/lib/es/index.js +0 -14
  168. package/lib/es/locale/en.js +5 -0
  169. package/lib/es/locale/index.js +1 -4
  170. package/lib/es/locale/zh.js +5 -0
  171. package/lib/es/sql-formula.js +0 -1
  172. package/lib/es/store/enum.d.ts +6 -6
  173. package/lib/es/store/enum.js +0 -13
  174. package/lib/es/store/helper.d.ts +2 -1
  175. package/lib/es/store/helper.js +13 -224
  176. package/lib/es/store/types.d.ts +45 -67
  177. package/lib/es/store/types.js +3 -49
  178. package/lib/es/types.d.ts +1 -0
  179. package/lib/es/types.js +1 -18
  180. package/lib/es/utils/cookies.js +0 -3
  181. package/lib/es/utils/event.js +1 -1
  182. package/lib/es/utils/helper-dom.d.ts +1 -0
  183. package/lib/es/utils/helper-dom.js +16 -9
  184. package/lib/es/utils/helper.js +1 -24
  185. package/lib/es/utils/keydown.js +4 -7
  186. package/lib/es/utils/platform.d.ts +0 -9
  187. package/lib/es/utils/platform.js +0 -10
  188. package/lib/es/utils/selection.js +0 -6
  189. package/lib/es/utils/storage.d.ts +0 -9
  190. package/lib/es/utils/storage.js +1 -10
  191. package/lib/es/utils/transformSql.d.ts +5 -0
  192. package/lib/es/utils/transformSql.js +42 -112
  193. package/lib/es/utils.d.ts +1 -6
  194. package/lib/es/utils.js +116 -255
  195. package/package.json +1 -1
@@ -1,7 +1,8 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
6
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
7
  var _excluded = ["notExistsToolbar", "toolbar"],
7
8
  _excluded2 = ["subToolbar", "notExistsColumns", "showFields", "isExit", "toolbar"];
@@ -11,7 +12,6 @@ import React, { useEffect, useState, useMemo, useRef, forwardRef } from 'react';
11
12
  import './index.less';
12
13
  import { FieldString, FieldNumber, FfPlus } from '@gingkoo/pandora-icons';
13
14
  import cx from 'classnames';
14
- // import './index.less';
15
15
  import Metabase from '../../../index';
16
16
  import { __ } from '../../../locale';
17
17
  import isEqual from 'lodash/isEqual';
@@ -31,22 +31,25 @@ import { useStore, Provider } from '../../../hooks/use-provider';
31
31
  import ItemName from '../../modules/components/item-name';
32
32
  import DiffViewer from '../diff-viewer';
33
33
  import storage from '../../../utils/storage';
34
+ import { getTopLayerZIndex } from '../../../utils/helper-dom';
35
+ import CaseWhenGroup from './CaseWhenGroup';
36
+ import LogicGroup from './LogicGroup';
37
+ var CASE_FIXED_OPERATORS = ['case', 'when', 'then', 'else', 'end'];
38
+ var LOGIC_FIXED_OPERATORS = ['(', ')'];
39
+ var LOGIC_REQUIRED_OPERATORS = ['(', ')'];
34
40
  var FormulaList = forwardRef(function (props, ref) {
35
- var _storage$_metabaseCop, _caseList2;
36
- // 响应 storage._metabaseCopyItems 变化,保证粘贴按钮能实时显示
41
+ var _storage$_metabaseCop;
37
42
  var _useState = useState((storage === null || storage === void 0 || (_storage$_metabaseCop = storage._metabaseCopyItems) === null || _storage$_metabaseCop === void 0 ? void 0 : _storage$_metabaseCop.length) || 0),
38
43
  _useState2 = _slicedToArray(_useState, 2),
39
44
  checkedItemsCount = _useState2[0],
40
45
  setCheckedItemsCount = _useState2[1];
41
46
  useEffect(function () {
42
47
  var _storage$_metabaseCop3;
43
- // 监听 _metabaseCopyItems 变化(自定义事件)
44
48
  var handler = function handler() {
45
49
  var _storage$_metabaseCop2;
46
50
  setCheckedItemsCount((storage === null || storage === void 0 || (_storage$_metabaseCop2 = storage._metabaseCopyItems) === null || _storage$_metabaseCop2 === void 0 ? void 0 : _storage$_metabaseCop2.length) || 0);
47
51
  };
48
52
  window.addEventListener('sqb-checked-items-changed', handler);
49
- // 初始化
50
53
  setCheckedItemsCount((storage === null || storage === void 0 || (_storage$_metabaseCop3 = storage._metabaseCopyItems) === null || _storage$_metabaseCop3 === void 0 ? void 0 : _storage$_metabaseCop3.length) || 0);
51
54
  return function () {
52
55
  window.removeEventListener('sqb-checked-items-changed', handler);
@@ -68,7 +71,96 @@ var FormulaList = forwardRef(function (props, ref) {
68
71
  showPreview = _props$showPreview === void 0 ? true : _props$showPreview,
69
72
  check = props.check,
70
73
  _props$_type = props._type,
71
- _type = _props$_type === void 0 ? 'filter' : _props$_type;
74
+ _type = _props$_type === void 0 ? 'filter' : _props$_type,
75
+ _props$embedded = props.embedded,
76
+ embedded = _props$embedded === void 0 ? false : _props$embedded,
77
+ _props$enableCopy = props.enableCopy,
78
+ enableCopy = _props$enableCopy === void 0 ? true : _props$enableCopy,
79
+ parentPopupChannel = props.parentPopupChannel;
80
+ var parentPopupLockCountRef = useRef(0);
81
+ var parentPopupUnlockTimerRef = useRef(null);
82
+ var setParentClosable = function setParentClosable(closable) {
83
+ if (!parentPopupChannel) return;
84
+ if (parentPopupChannel === 'secondary') {
85
+ store.setClosable2(closable);
86
+ return;
87
+ }
88
+ store.setClosable(closable);
89
+ };
90
+ var lockParentPopup = function lockParentPopup() {
91
+ if (!parentPopupChannel) return;
92
+ if (parentPopupUnlockTimerRef.current) {
93
+ window.clearTimeout(parentPopupUnlockTimerRef.current);
94
+ parentPopupUnlockTimerRef.current = null;
95
+ }
96
+ parentPopupLockCountRef.current += 1;
97
+ if (parentPopupLockCountRef.current === 1) {
98
+ setParentClosable(false);
99
+ }
100
+ };
101
+ var unlockParentPopup = function unlockParentPopup() {
102
+ var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
103
+ if (!parentPopupChannel) return;
104
+ var runUnlock = function runUnlock() {
105
+ parentPopupUnlockTimerRef.current = null;
106
+ parentPopupLockCountRef.current = Math.max(0, parentPopupLockCountRef.current - 1);
107
+ if (parentPopupLockCountRef.current === 0) {
108
+ setParentClosable(true);
109
+ }
110
+ };
111
+ if (delay > 0) {
112
+ if (parentPopupUnlockTimerRef.current) {
113
+ window.clearTimeout(parentPopupUnlockTimerRef.current);
114
+ }
115
+ parentPopupUnlockTimerRef.current = window.setTimeout(runUnlock, delay);
116
+ return;
117
+ }
118
+ runUnlock();
119
+ };
120
+ var openChildModal = function openChildModal(options) {
121
+ var _options$zIndex, _modalInstance;
122
+ var lockDelay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 120;
123
+ if (parentPopupChannel) {
124
+ lockParentPopup();
125
+ }
126
+ var modalZIndex = (_options$zIndex = options.zIndex) !== null && _options$zIndex !== void 0 ? _options$zIndex : getTopLayerZIndex() + 1;
127
+ var closed = false;
128
+ var modalInstance;
129
+ var releaseParentPopup = function releaseParentPopup() {
130
+ if (!parentPopupChannel || closed) return;
131
+ closed = true;
132
+ unlockParentPopup(lockDelay);
133
+ };
134
+ modalInstance = Modal2.openModal(_objectSpread(_objectSpread({
135
+ zIndex: modalZIndex
136
+ }, options), {}, {
137
+ onClose: function onClose() {
138
+ var _options$onClose;
139
+ releaseParentPopup();
140
+ (_options$onClose = options.onClose) === null || _options$onClose === void 0 || _options$onClose.call(options);
141
+ }
142
+ }));
143
+ var originalClose = (_modalInstance = modalInstance) === null || _modalInstance === void 0 || (_modalInstance = _modalInstance.close) === null || _modalInstance === void 0 ? void 0 : _modalInstance.bind(modalInstance);
144
+ if (originalClose) {
145
+ modalInstance.close = function () {
146
+ releaseParentPopup();
147
+ return originalClose.apply(void 0, arguments);
148
+ };
149
+ }
150
+ return modalInstance;
151
+ };
152
+ useEffect(function () {
153
+ return function () {
154
+ if (parentPopupUnlockTimerRef.current) {
155
+ window.clearTimeout(parentPopupUnlockTimerRef.current);
156
+ parentPopupUnlockTimerRef.current = null;
157
+ }
158
+ if (parentPopupLockCountRef.current > 0) {
159
+ parentPopupLockCountRef.current = 0;
160
+ setParentClosable(true);
161
+ }
162
+ };
163
+ }, [parentPopupChannel]);
72
164
  var mergedTypes = useMemo(function () {
73
165
  var map = new Map();
74
166
  [].concat(_toConsumableArray(_customTypes), _toConsumableArray(otherTypes)).forEach(function (item) {
@@ -90,14 +182,12 @@ var FormulaList = forwardRef(function (props, ref) {
90
182
  return map;
91
183
  }, [otherTypes]);
92
184
  var caseList = value || [];
93
- // const [caseList, setCaseListState] = useState<AtomsItem[]>(cloneDeep(value));
94
185
  var caseListRef = useRef(caseList);
95
186
  var operatorList = useMemo(function () {
96
187
  if (store.operatorList.length > 0) {
97
188
  return store.operatorList;
98
- } else {
99
- return __operatorList;
100
189
  }
190
+ return __operatorList;
101
191
  }, [store.operatorList]);
102
192
  var _useState3 = useState(''),
103
193
  _useState4 = _slicedToArray(_useState3, 2),
@@ -108,6 +198,9 @@ var FormulaList = forwardRef(function (props, ref) {
108
198
  previewMode = _useState6[0],
109
199
  setPreviewMode = _useState6[1];
110
200
  var _useState7 = useState(function () {
201
+ if (!enableCopy) {
202
+ return false;
203
+ }
111
204
  if (store.copyType.includes(FormulaTypeEnum.ALL)) {
112
205
  return true;
113
206
  }
@@ -116,33 +209,221 @@ var FormulaList = forwardRef(function (props, ref) {
116
209
  _useState8 = _slicedToArray(_useState7, 2),
117
210
  isCopy = _useState8[0],
118
211
  setIsCopy = _useState8[1];
119
- // const [formulaList, setFunctionList] = useState<{ [params: string]: FormulaTemplatesItem }>(
120
- // );
121
212
  var formulaList = useMemo(function () {
122
213
  return getObjTem(store.formulaTemplates);
123
214
  }, [store.formulaTemplates]);
124
- useEffect(function () {
125
- setOldCode(getPreviewStr(caseList));
126
- }, []);
127
215
  var _useState9 = useState(''),
128
216
  _useState0 = _slicedToArray(_useState9, 2),
129
217
  filterVal = _useState0[0],
130
218
  setFilterVal = _useState0[1];
131
219
  var setCaseList = function setCaseList(data) {
132
- var quotes = data.map(function (v, i) {
133
- if (v !== null && v !== void 0 && v.quotes) {
134
- return v === null || v === void 0 ? void 0 : v.quotes;
135
- } else if (v !== null && v !== void 0 && v.fieldName) {
136
- return v === null || v === void 0 ? void 0 : v.fieldName;
137
- } else {
138
- return v.val;
139
- }
220
+ var quotes = data.map(function (v) {
221
+ if (v !== null && v !== void 0 && v.quotes) return v.quotes;
222
+ if (v !== null && v !== void 0 && v.fieldName) return v.fieldName;
223
+ return v === null || v === void 0 ? void 0 : v.val;
140
224
  }).join(' ');
141
- // setCaseListState(data);
142
225
  caseList = data;
143
226
  caseListRef.current = data;
144
227
  onChange === null || onChange === void 0 || onChange(data, quotes);
145
228
  };
229
+ var updateAtomAt = function updateAtomAt(index, nextItem) {
230
+ var nextList = caseList.slice();
231
+ nextList[index] = nextItem;
232
+ setCaseList(nextList);
233
+ };
234
+ function getItemDisplayText(v) {
235
+ if (!v) return '';
236
+ if (v.quotes) return v.quotes;
237
+ if (v.fieldName) return v.fieldName;
238
+ if (v.type === AtomsTypeEnum.FORMULA) {
239
+ return v.name ? getQuotes(v, v.args, formulaList) : '';
240
+ }
241
+ if (v.type === AtomsTypeEnum.CASE_WHEN) {
242
+ var caseValueText = (v.caseValue || []).map(function (item) {
243
+ return getItemDisplayText(item);
244
+ }).join(' ');
245
+ var branchText = (v.branches || []).map(function (branch) {
246
+ var whenText = (branch.when || []).map(function (item) {
247
+ return getItemDisplayText(item);
248
+ }).join(' ');
249
+ var thenText = (branch.then || []).map(function (item) {
250
+ return getItemDisplayText(item);
251
+ }).join(' ');
252
+ return "when ".concat(whenText, " then ").concat(thenText).trim();
253
+ }).join(' ');
254
+ var elseText = (v.elseValue || []).length ? " else ".concat((v.elseValue || []).map(function (item) {
255
+ return getItemDisplayText(item);
256
+ }).join(' ')) : '';
257
+ return "case ".concat(caseValueText, " ").concat(branchText).concat(elseText, " end").replace(/\s+/g, ' ').trim();
258
+ }
259
+ if (v.type === AtomsTypeEnum.AND_OR) {
260
+ var listText = (v.list || []).map(function (item) {
261
+ return getItemDisplayText(item);
262
+ }).join(' ');
263
+ return "".concat(v.operator || 'and', " ( ").concat(listText, " )").replace(/\s+/g, ' ').trim();
264
+ }
265
+ if (Array.isArray(v.val)) {
266
+ return v.val.join(', ');
267
+ }
268
+ return v.val || '';
269
+ }
270
+ var getPreviewStr = function getPreviewStr() {
271
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
272
+ return data.map(function (v) {
273
+ if (v.type === AtomsTypeEnum.OPERATOR && (v.val === 'and' || v.val === 'or')) {
274
+ return "\r".concat(v.val, "\r");
275
+ }
276
+ if (v.type === AtomsTypeEnum.OPERATOR && (v.val === '(' || v.val === ')')) {
277
+ return "".concat(v.val);
278
+ }
279
+ return getItemDisplayText(v);
280
+ }).join(' ');
281
+ };
282
+ useEffect(function () {
283
+ setOldCode(getPreviewStr(caseList));
284
+ }, []);
285
+ var renderTokenContent = function renderTokenContent(children) {
286
+ return _jsx("span", {
287
+ className: 'Sqb-TokenContent',
288
+ children: children
289
+ });
290
+ };
291
+ var renderNestedFormulaList = function renderNestedFormulaList(list, onNestedChange) {
292
+ return _jsx("div", {
293
+ className: 'Sqb-NestedFormulaList',
294
+ children: _jsx(FormulaList, {
295
+ ref: ref,
296
+ embedded: true,
297
+ value: list,
298
+ data: data,
299
+ exitData: exitData,
300
+ onChange: function onChange(atoms) {
301
+ return onNestedChange(atoms);
302
+ },
303
+ customTypes: _customTypes,
304
+ otherTypes: otherTypes,
305
+ isCustom: isCustom,
306
+ showPreview: false,
307
+ check: check,
308
+ _type: _type,
309
+ parentPopupChannel: parentPopupChannel
310
+ })
311
+ });
312
+ };
313
+ var renderCaseWhenEditor = function renderCaseWhenEditor(value, index) {
314
+ return _jsx(CaseWhenGroup, {
315
+ caseValueContent: renderNestedFormulaList(value.caseValue || [], function (nextList) {
316
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
317
+ caseValue: nextList
318
+ }));
319
+ }),
320
+ branches: (value.branches || []).map(function (branch, branchIndex) {
321
+ return {
322
+ key: "case-".concat(index, "-branch-").concat(branchIndex),
323
+ whenContent: renderNestedFormulaList(branch.when || [], function (nextList) {
324
+ var nextBranches = (value.branches || []).slice();
325
+ nextBranches[branchIndex] = _objectSpread(_objectSpread({}, branch), {}, {
326
+ when: nextList
327
+ });
328
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
329
+ branches: nextBranches
330
+ }));
331
+ }),
332
+ thenContent: renderNestedFormulaList(branch.then || [], function (nextList) {
333
+ var nextBranches = (value.branches || []).slice();
334
+ nextBranches[branchIndex] = _objectSpread(_objectSpread({}, branch), {}, {
335
+ then: nextList
336
+ });
337
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
338
+ branches: nextBranches
339
+ }));
340
+ }),
341
+ onAddAfter: function onAddAfter(e) {
342
+ e.stopPropagation();
343
+ var nextBranches = (value.branches || []).slice();
344
+ nextBranches.splice(branchIndex + 1, 0, {
345
+ when: [{
346
+ val: '',
347
+ type: AtomsTypeEnum.UNKNOWN
348
+ }],
349
+ then: [{
350
+ val: '',
351
+ type: AtomsTypeEnum.UNKNOWN
352
+ }]
353
+ });
354
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
355
+ branches: nextBranches
356
+ }));
357
+ },
358
+ onDelete: function onDelete(e) {
359
+ e.stopPropagation();
360
+ var nextBranches = (value.branches || []).filter(function (_, currentIndex) {
361
+ return currentIndex !== branchIndex;
362
+ });
363
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
364
+ branches: nextBranches
365
+ }));
366
+ }
367
+ };
368
+ }),
369
+ elseContent: value.elseValue ? renderNestedFormulaList(value.elseValue || [], function (nextList) {
370
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
371
+ elseValue: nextList
372
+ }));
373
+ }) : undefined,
374
+ onAddBranch: function onAddBranch(e) {
375
+ e.stopPropagation();
376
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
377
+ branches: [].concat(_toConsumableArray(value.branches || []), [{
378
+ when: [{
379
+ val: '',
380
+ type: AtomsTypeEnum.UNKNOWN
381
+ }],
382
+ then: [{
383
+ val: '',
384
+ type: AtomsTypeEnum.UNKNOWN
385
+ }]
386
+ }])
387
+ }));
388
+ },
389
+ onAddElse: function onAddElse(e) {
390
+ e.stopPropagation();
391
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
392
+ elseValue: [{
393
+ val: '',
394
+ type: AtomsTypeEnum.UNKNOWN
395
+ }]
396
+ }));
397
+ },
398
+ onRemoveElse: function onRemoveElse(e) {
399
+ e.stopPropagation();
400
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
401
+ elseValue: undefined
402
+ }));
403
+ },
404
+ onDeleteCase: function onDeleteCase(e) {
405
+ return handleDel(e, index);
406
+ }
407
+ });
408
+ };
409
+ var renderAndOrEditor = function renderAndOrEditor(value, index) {
410
+ return _jsx(LogicGroup, {
411
+ operator: value.operator || 'and',
412
+ onToggleOperator: function onToggleOperator() {
413
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
414
+ operator: value.operator === 'or' ? 'and' : 'or'
415
+ }));
416
+ },
417
+ content: renderNestedFormulaList(value.list || [], function (nextList) {
418
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
419
+ list: nextList
420
+ }));
421
+ }),
422
+ onDelete: function onDelete(e) {
423
+ return handleDel(e, index);
424
+ }
425
+ });
426
+ };
146
427
  var _useState1 = useState(-1),
147
428
  _useState10 = _slicedToArray(_useState1, 2),
148
429
  ind = _useState10[0],
@@ -160,51 +441,194 @@ var FormulaList = forwardRef(function (props, ref) {
160
441
  isCheck = _useState14[0],
161
442
  setIsCheck = _useState14[1];
162
443
  var myInstanceIdRef = useRef(Math.random().toString(36).slice(2));
163
- var _useState15 = useState(!!window.__sqb_selection_active__),
444
+ var _useState15 = useState(null),
164
445
  _useState16 = _slicedToArray(_useState15, 2),
165
- globalSelectionActive = _useState16[0],
166
- setGlobalSelectionActive = _useState16[1];
167
- var _useState17 = useState(window.__sqb_selection_owner__ || null),
446
+ hoveredCaseGroupKey = _useState16[0],
447
+ setHoveredCaseGroupKey = _useState16[1];
448
+ var _useState17 = useState(!!window.__sqb_selection_active__),
168
449
  _useState18 = _slicedToArray(_useState17, 2),
169
- globalSelectionOwner = _useState18[0],
170
- setGlobalSelectionOwner = _useState18[1];
171
- var _useState19 = useState([]),
450
+ globalSelectionActive = _useState18[0],
451
+ setGlobalSelectionActive = _useState18[1];
452
+ var _useState19 = useState(window.__sqb_selection_owner__ || null),
172
453
  _useState20 = _slicedToArray(_useState19, 2),
173
- selectedIndices = _useState20[0],
174
- setSelectedIndices = _useState20[1];
175
- var _useState21 = useState(null),
454
+ globalSelectionOwner = _useState20[0],
455
+ setGlobalSelectionOwner = _useState20[1];
456
+ var _useState21 = useState([]),
176
457
  _useState22 = _slicedToArray(_useState21, 2),
177
- hoveredCopyIndex = _useState22[0],
178
- setHoveredCopyIndex = _useState22[1];
179
- useEffect(function () {
180
- var _errorInfo = validateExpressionIntegrity(caseList);
181
- setErrorInfo(_errorInfo);
458
+ selectedIndices = _useState22[0],
459
+ setSelectedIndices = _useState22[1];
460
+ var _useState23 = useState(null),
461
+ _useState24 = _slicedToArray(_useState23, 2),
462
+ hoveredCopyIndex = _useState24[0],
463
+ setHoveredCopyIndex = _useState24[1];
464
+ var getCaseGroupEnd = function getCaseGroupEnd(list, startIndex) {
465
+ var depth = 0;
466
+ for (var index = startIndex; index < list.length; index++) {
467
+ var item = list[index];
468
+ if (item.type !== AtomsTypeEnum.OPERATOR) continue;
469
+ if (item.val === 'case') depth += 1;
470
+ if (item.val === 'end') {
471
+ depth -= 1;
472
+ if (depth === 0) {
473
+ return index;
474
+ }
475
+ }
476
+ }
477
+ return startIndex;
478
+ };
479
+ var getLogicGroupIndices = function getLogicGroupIndices(list, startIndex) {
480
+ var _list, _list2;
481
+ var prevItem = list[startIndex - 1];
482
+ var currentItem = list[startIndex];
483
+ if (!currentItem) return [];
484
+ if (currentItem.type === AtomsTypeEnum.OPERATOR && ['and', 'or'].includes(currentItem.val) && ((_list = list[startIndex + 1]) === null || _list === void 0 ? void 0 : _list.type) === AtomsTypeEnum.OPERATOR && ((_list2 = list[startIndex + 1]) === null || _list2 === void 0 ? void 0 : _list2.val) === '(') {
485
+ var depth = 0;
486
+ var _indices = [];
487
+ for (var index = startIndex; index < list.length; index++) {
488
+ var item = list[index];
489
+ _indices.push(index);
490
+ if ((item === null || item === void 0 ? void 0 : item.type) !== AtomsTypeEnum.OPERATOR) continue;
491
+ if (item.val === '(') depth += 1;
492
+ if (item.val === ')') {
493
+ depth -= 1;
494
+ if (depth === 0) {
495
+ return _indices;
496
+ }
497
+ }
498
+ }
499
+ return _indices;
500
+ }
501
+ if (currentItem.type === AtomsTypeEnum.OPERATOR) return [];
502
+ if ((prevItem === null || prevItem === void 0 ? void 0 : prevItem.type) === AtomsTypeEnum.OPERATOR && ['and', 'or'].includes((prevItem === null || prevItem === void 0 ? void 0 : prevItem.val) || '')) {
503
+ return [];
504
+ }
505
+ var indices = [startIndex];
506
+ var cursor = startIndex;
507
+ while (cursor + 2 < list.length) {
508
+ var operatorItem = list[cursor + 1];
509
+ var nextItem = list[cursor + 2];
510
+ if ((operatorItem === null || operatorItem === void 0 ? void 0 : operatorItem.type) !== AtomsTypeEnum.OPERATOR || !['and', 'or'].includes((operatorItem === null || operatorItem === void 0 ? void 0 : operatorItem.val) || '') || !nextItem || nextItem.type === AtomsTypeEnum.OPERATOR) {
511
+ break;
512
+ }
513
+ indices.push(cursor + 1, cursor + 2);
514
+ cursor += 2;
515
+ }
516
+ return indices.length >= 3 ? indices : [];
517
+ };
518
+ var renderGroups = useMemo(function () {
519
+ var groups = [];
520
+ var index = 0;
521
+ while (index < caseList.length) {
522
+ var item = caseList[index];
523
+ if ((item === null || item === void 0 ? void 0 : item.type) === AtomsTypeEnum.OPERATOR && (item === null || item === void 0 ? void 0 : item.val) === 'case') {
524
+ var endIndex = getCaseGroupEnd(caseList, index);
525
+ groups.push({
526
+ type: 'caseWhen',
527
+ indices: Array.from({
528
+ length: endIndex - index + 1
529
+ }, function (_, offset) {
530
+ return index + offset;
531
+ })
532
+ });
533
+ index = endIndex + 1;
534
+ continue;
535
+ }
536
+ var logicIndices = getLogicGroupIndices(caseList, index);
537
+ if (logicIndices.length > 0) {
538
+ groups.push({
539
+ type: 'logic',
540
+ indices: logicIndices
541
+ });
542
+ index = logicIndices[logicIndices.length - 1] + 1;
543
+ continue;
544
+ }
545
+ groups.push({
546
+ type: 'single',
547
+ indices: [index]
548
+ });
549
+ index += 1;
550
+ }
551
+ return groups;
182
552
  }, [caseList]);
183
- // 获取预览字符串
184
- var getPreviewStr = function getPreviewStr() {
185
- var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
186
- return data.map(function (v, i) {
187
- if (v !== null && v !== void 0 && v.quotes) {
188
- return v === null || v === void 0 ? void 0 : v.quotes;
189
- } else if (v !== null && v !== void 0 && v.fieldName) {
190
- return v === null || v === void 0 ? void 0 : v.fieldName;
191
- } else {
192
- if (v.type === AtomsTypeEnum.OPERATOR && (v.val === 'and' || v.val === 'or')) {
193
- return "\r".concat(v.val, "\r");
553
+ var getCaseGroupRows = function getCaseGroupRows(indices) {
554
+ var rows = [];
555
+ var currentRow = [];
556
+ var depth = 0;
557
+ indices.forEach(function (itemIndex) {
558
+ var item = caseList[itemIndex];
559
+ if ((item === null || item === void 0 ? void 0 : item.type) === AtomsTypeEnum.OPERATOR) {
560
+ if (item.val === 'case') {
561
+ if (depth === 0) {
562
+ if (currentRow.length > 0) rows.push(currentRow);
563
+ currentRow = [itemIndex];
564
+ depth = 1;
565
+ return;
566
+ }
567
+ depth += 1;
194
568
  }
195
- if (v.type === AtomsTypeEnum.OPERATOR && (v.val === '(' || v.val === ')')) {
196
- return "".concat(v.val);
569
+ if (depth === 1 && (item.val === 'when' || item.val === 'else')) {
570
+ if (currentRow.length > 0) rows.push(currentRow);
571
+ currentRow = [itemIndex];
572
+ return;
573
+ }
574
+ if (item.val === 'end') {
575
+ depth -= 1;
576
+ if (depth === 0) {
577
+ if (currentRow.length > 0) rows.push(currentRow);
578
+ rows.push([itemIndex]);
579
+ currentRow = [];
580
+ return;
581
+ }
197
582
  }
198
- return v.val;
199
583
  }
200
- }).join(' ');
584
+ currentRow.push(itemIndex);
585
+ });
586
+ if (currentRow.length > 0) {
587
+ rows.push(currentRow);
588
+ }
589
+ return rows;
201
590
  };
591
+ var isFixedCaseOperator = function isFixedCaseOperator(item) {
592
+ return item.type === AtomsTypeEnum.OPERATOR && CASE_FIXED_OPERATORS.includes(item.val || '');
593
+ };
594
+ var isFixedLogicOperator = function isFixedLogicOperator(item) {
595
+ return item.type === AtomsTypeEnum.OPERATOR && LOGIC_FIXED_OPERATORS.includes(item.val || '');
596
+ };
597
+ var isRequiredLogicOperator = function isRequiredLogicOperator(item) {
598
+ return item.type === AtomsTypeEnum.OPERATOR && LOGIC_REQUIRED_OPERATORS.includes(item.val || '');
599
+ };
600
+ var canDeleteItem = function canDeleteItem(item, groupType) {
601
+ if (groupType === 'logic') {
602
+ return !isRequiredLogicOperator(item);
603
+ }
604
+ return !isFixedCaseOperator(item);
605
+ };
606
+ var canShowInsertArrows = function canShowInsertArrows(item, groupType) {
607
+ if (groupType === 'caseWhen') {
608
+ return !isFixedCaseOperator(item);
609
+ }
610
+ if (groupType === 'logic') {
611
+ return !isRequiredLogicOperator(item);
612
+ }
613
+ return !(item.type === AtomsTypeEnum.OPERATOR && ['case', 'end'].includes(item.val));
614
+ };
615
+ useEffect(function () {
616
+ var _errorInfo = validateExpressionIntegrity(caseList);
617
+ setErrorInfo(_errorInfo);
618
+ }, [caseList]);
202
619
  function closePopup() {
203
620
  store.setPopup({
204
621
  visible: false
205
622
  });
206
623
  }
207
- // 连接符
624
+ var getSelectTriggerProps = function getSelectTriggerProps() {
625
+ return {
626
+ clickToClose: true,
627
+ style: {
628
+ zIndex: getTopLayerZIndex() + 1
629
+ }
630
+ };
631
+ };
208
632
  var selectOperator = function selectOperator(props) {
209
633
  var triggerElement = props.triggerElement,
210
634
  ind = props.ind,
@@ -220,9 +644,7 @@ var FormulaList = forwardRef(function (props, ref) {
220
644
  },
221
645
  showSearch: true,
222
646
  trigger: trigger,
223
- triggerProps: {
224
- clickToClose: true
225
- },
647
+ triggerProps: getSelectTriggerProps(),
226
648
  virtualListProps: {
227
649
  threshold: null
228
650
  },
@@ -239,6 +661,9 @@ var FormulaList = forwardRef(function (props, ref) {
239
661
  onVisibleChange: function onVisibleChange(visible) {
240
662
  if (visible) {
241
663
  setFilterVal('');
664
+ lockParentPopup();
665
+ } else {
666
+ unlockParentPopup(300);
242
667
  }
243
668
  },
244
669
  value: '',
@@ -252,7 +677,6 @@ var FormulaList = forwardRef(function (props, ref) {
252
677
  },
253
678
  value: filterVal,
254
679
  placeholder: __('SqlQueryBuilder.pleaseEnter'),
255
- // size='large'
256
680
  onChange: function onChange(val) {
257
681
  setFilterVal(val);
258
682
  }
@@ -270,7 +694,6 @@ var FormulaList = forwardRef(function (props, ref) {
270
694
  })]
271
695
  });
272
696
  };
273
- // 字段
274
697
  function handleField(e, i, val) {
275
698
  store.setPopup({
276
699
  visible: true,
@@ -281,7 +704,7 @@ var FormulaList = forwardRef(function (props, ref) {
281
704
  multiple: false,
282
705
  value: [val],
283
706
  theme: ColumnsPopupThemeEnum.skyBlue,
284
- onSelect: function onSelect(fields, quotes) {
707
+ onSelect: function onSelect(fields) {
285
708
  var _caseList = caseList.slice();
286
709
  _caseList[i] = fields[0];
287
710
  setCaseList(_caseList);
@@ -290,7 +713,6 @@ var FormulaList = forwardRef(function (props, ref) {
290
713
  })
291
714
  });
292
715
  }
293
- // 常量
294
716
  var handleConstant = function handleConstant(val, i) {
295
717
  var _caseList = caseList.slice();
296
718
  var currentItem = _caseList[i];
@@ -310,7 +732,6 @@ var FormulaList = forwardRef(function (props, ref) {
310
732
  _caseList = insertTemplateAt(oldVal, val, _caseList, i);
311
733
  setCaseList(_caseList);
312
734
  };
313
- // 表达式
314
735
  function handleExpression(e, i, val) {
315
736
  store.setPopup({
316
737
  visible: true,
@@ -331,7 +752,6 @@ var FormulaList = forwardRef(function (props, ref) {
331
752
  })
332
753
  });
333
754
  }
334
- // 删除
335
755
  function handleDel(e, index) {
336
756
  e.stopPropagation();
337
757
  var _caseList = caseList.slice();
@@ -339,13 +759,21 @@ var FormulaList = forwardRef(function (props, ref) {
339
759
  setCaseList(_caseList);
340
760
  closePopup();
341
761
  }
342
- // 重置粘贴状态
762
+ function handleDelItems(e, indices) {
763
+ e.stopPropagation();
764
+ if (!indices.length) return;
765
+ var indexSet = new Set(indices);
766
+ var _caseList = caseList.filter(function (_, itemIndex) {
767
+ return !indexSet.has(itemIndex);
768
+ });
769
+ setCaseList(_caseList);
770
+ closePopup();
771
+ }
343
772
  function initPaste() {
344
773
  var isDispatch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
345
774
  setSelectedIndices([]);
346
775
  setLocalItem([]);
347
776
  setIsCheck(false);
348
- //有些事不需要通知别的过滤器重置勾选状态
349
777
  if (isDispatch) {
350
778
  window.dispatchEvent(new CustomEvent('sqb-check-active', {
351
779
  detail: {
@@ -354,11 +782,9 @@ var FormulaList = forwardRef(function (props, ref) {
354
782
  }));
355
783
  }
356
784
  }
357
- // 粘贴到末尾并清除勾选
358
785
  function handlePaste() {
359
786
  var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
360
787
  var _caseList = caseList.slice();
361
- // determine items to paste (selected items have priority)
362
788
  var itemsToPaste = storage._metabaseCopyItems || [];
363
789
  itemsToPaste = changeCopyField(itemsToPaste, data);
364
790
  if (itemsToPaste.length) {
@@ -371,13 +797,10 @@ var FormulaList = forwardRef(function (props, ref) {
371
797
  }
372
798
  initPaste();
373
799
  }
374
- // 将值存在 localStorage
375
800
  function setLocalItem(next) {
376
801
  var _caseList = caseList.slice();
377
- // determine items to paste (selected items have priority)
378
802
  var itemsToPaste = [];
379
803
  if (next.length > 0) {
380
- // paste all selected items
381
804
  itemsToPaste = next.map(function (i) {
382
805
  return _caseList[i] ? cloneDeep(_caseList[i]) : null;
383
806
  }).filter(Boolean);
@@ -399,11 +822,33 @@ var FormulaList = forwardRef(function (props, ref) {
399
822
  });
400
823
  setSelectedIndices(next);
401
824
  setLocalItem(next);
402
- // const active = next.length > 0;
403
825
  }
826
+ function toggleSelectGroup(indices, checked) {
827
+ var next = selectedIndices.slice();
828
+ if (checked) {
829
+ indices.forEach(function (index) {
830
+ if (!next.includes(index)) next.push(index);
831
+ });
832
+ } else {
833
+ var indexSet = new Set(indices);
834
+ next = next.filter(function (index) {
835
+ return !indexSet.has(index);
836
+ });
837
+ }
838
+ next = next.sort(function (a, b) {
839
+ return a - b;
840
+ });
841
+ setSelectedIndices(next);
842
+ setLocalItem(next);
843
+ }
844
+ var isGroupSelected = function isGroupSelected(indices) {
845
+ return indices.length > 0 && indices.every(function (index) {
846
+ return selectedIndices.includes(index);
847
+ });
848
+ };
404
849
  var copyAll = function copyAll() {
405
850
  _setIsCheck(true);
406
- var allIndices = caseList.map(function (v, i) {
851
+ var allIndices = caseList.map(function (_, i) {
407
852
  return i;
408
853
  });
409
854
  setSelectedIndices(allIndices);
@@ -412,11 +857,9 @@ var FormulaList = forwardRef(function (props, ref) {
412
857
  var delSelect = function delSelect() {
413
858
  Modal.confirm({
414
859
  title: __('metabase.prompt'),
415
- // 提示
416
860
  content: __('customColumn.confirmDelete'),
417
- // 确认删除吗
418
861
  onOk: function () {
419
- var _onOk = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
862
+ var _onOk = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
420
863
  var selectedIndexSet, _caseList;
421
864
  return _regeneratorRuntime.wrap(function (_context) {
422
865
  while (1) switch (_context.prev = _context.next) {
@@ -441,7 +884,6 @@ var FormulaList = forwardRef(function (props, ref) {
441
884
  onCancel: function onCancel() {}
442
885
  });
443
886
  };
444
- // 开启关闭勾选,清除别的过滤器勾选
445
887
  var _setIsCheck = function _setIsCheck(val) {
446
888
  initPaste();
447
889
  setIsCheck(val);
@@ -459,7 +901,6 @@ var FormulaList = forwardRef(function (props, ref) {
459
901
  window.removeEventListener('sqb-check-active', onCheckActive);
460
902
  };
461
903
  }, []);
462
- // 添加
463
904
  var addOperator = function addOperator(type, index, position) {
464
905
  var _caseList = caseList.slice() || [];
465
906
  var _ind = index;
@@ -479,14 +920,59 @@ var FormulaList = forwardRef(function (props, ref) {
479
920
  _caseList.splice(index + 1, 0, temItem);
480
921
  _ind = index + 1;
481
922
  } else {
482
- //替换
483
923
  _caseList.splice(index, 1, temItem);
484
924
  _ind = index;
485
925
  }
486
926
  setCaseList(_caseList);
487
927
  return _ind < 0 ? 0 : _ind;
488
928
  };
489
- // NotExists 窗口
929
+ var getItemNameProps = function getItemNameProps(v) {
930
+ if (v.type === AtomsTypeEnum.NOT_EXISTS || v.type === AtomsTypeEnum.EXISTS) {
931
+ return {
932
+ isError: isExistsError(v.notExists, store.existsError)
933
+ };
934
+ }
935
+ if (v.type === AtomsTypeEnum.SUB_QUERY) {
936
+ return {
937
+ isError: isExistsError(v.subQuery, store.existsError)
938
+ };
939
+ }
940
+ if (v.type === AtomsTypeEnum.FIELD) {
941
+ return {
942
+ isError: isError(v, data)
943
+ };
944
+ }
945
+ if (v.type === AtomsTypeEnum.CONSTANT) {
946
+ return {
947
+ isError: !!(v.id || v.val) && !getConstantLabel(store.constantList, v.id || v.val),
948
+ message: '常量丢失'
949
+ };
950
+ }
951
+ if (otherTypeMap.has(String(v.type))) {
952
+ var currentOtherType = otherTypeMap.get(String(v.type));
953
+ var listSource = (currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.list) || [];
954
+ return {
955
+ isError: !!(v.id || v.val) && !getConstantLabel(listSource, v.id || v.val),
956
+ message: "".concat(currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.label, "\u4E22\u5931")
957
+ };
958
+ }
959
+ if (v.type === AtomsTypeEnum.EXPRESSION) {
960
+ return {
961
+ isError: isError(v, data)
962
+ };
963
+ }
964
+ if (v.type === AtomsTypeEnum.FORMULA) {
965
+ var formulaMissing = formulaIsError(v, formulaList);
966
+ return {
967
+ isError: isError(v, data) || formulaMissing,
968
+ message: formulaMissing ? '公式丢失' : ''
969
+ };
970
+ }
971
+ return {
972
+ isError: false,
973
+ message: ''
974
+ };
975
+ };
490
976
  var showNotExists = function showNotExists(i) {
491
977
  var _caseList$i, _caseList$i2;
492
978
  var _store$preProps = store.preProps,
@@ -495,23 +981,22 @@ var FormulaList = forwardRef(function (props, ref) {
495
981
  other = _objectWithoutProperties(_store$preProps, _excluded);
496
982
  var _value = ((_caseList$i = caseList[i]) === null || _caseList$i === void 0 ? void 0 : _caseList$i.notExists) || [];
497
983
  var oldList = cloneDeep(((_caseList$i2 = caseList[i]) === null || _caseList$i2 === void 0 ? void 0 : _caseList$i2.notExists) || []);
984
+ var childModalZIndex = getTopLayerZIndex() + 1;
498
985
  var _toolbar = notExistsToolbar || toolbar;
499
- // _toolbar = _toolbar.filter((v: string) => v !== 'group'); // 子查询不需要分组
500
- var o = Modal2.openModal({
986
+ var o = openChildModal({
987
+ zIndex: childModalZIndex,
501
988
  title: caseList[i].type,
502
- transparentMask: true,
989
+ transparentMask: false,
503
990
  content: _jsx(_Fragment, {
504
991
  children: _jsx(Metabase, _objectSpread(_objectSpread({}, other), {}, {
992
+ popupZIndex: childModalZIndex + 1,
505
993
  notExistsColumns: exitData,
506
- // showFields={false}
507
994
  isExit: true,
508
- // showSubquery={subShowSubquery}
509
995
  toolbar: _toolbar,
510
996
  btnText: __('SqlQueryBuilder.confirm'),
511
997
  value: cloneDeep(_value),
512
998
  onOk: function onOk(newList) {
513
999
  try {
514
- // 子查询未改变不做操作
515
1000
  if (isEqual(newList, oldList)) {
516
1001
  o.close();
517
1002
  return;
@@ -525,18 +1010,14 @@ var FormulaList = forwardRef(function (props, ref) {
525
1010
  onChange === null || onChange === void 0 || onChange(caseList, '');
526
1011
  setCaseList(_toConsumableArray(caseList));
527
1012
  o.close();
528
- } catch (e) {
529
- console.warn(e);
530
- } finally {
1013
+ } catch (e) {} finally {
531
1014
  o.close();
532
1015
  }
533
1016
  }
534
1017
  }))
535
- }),
536
- onClose: function onClose() {}
1018
+ })
537
1019
  });
538
1020
  };
539
- // 子查询 窗口
540
1021
  var showSubQuery = function showSubQuery(i) {
541
1022
  var _caseList$i3, _caseList$i4;
542
1023
  var _store$preProps2 = store.preProps,
@@ -548,12 +1029,15 @@ var FormulaList = forwardRef(function (props, ref) {
548
1029
  other = _objectWithoutProperties(_store$preProps2, _excluded2);
549
1030
  var _value = ((_caseList$i3 = caseList[i]) === null || _caseList$i3 === void 0 ? void 0 : _caseList$i3.subQuery) || [];
550
1031
  var oldList = cloneDeep(((_caseList$i4 = caseList[i]) === null || _caseList$i4 === void 0 ? void 0 : _caseList$i4.subQuery) || []);
1032
+ var childModalZIndex = getTopLayerZIndex() + 1;
551
1033
  var _toolbar = subToolbar || toolbar;
552
- var o = Modal2.openModal({
1034
+ var o = openChildModal({
1035
+ zIndex: childModalZIndex,
553
1036
  title: __('SqlQueryBuilder.subquery'),
554
- transparentMask: true,
1037
+ transparentMask: false,
555
1038
  content: _jsx(_Fragment, {
556
1039
  children: _jsx(Metabase, _objectSpread(_objectSpread({}, other), {}, {
1040
+ popupZIndex: childModalZIndex + 1,
557
1041
  isExit: true,
558
1042
  isSubquery: true,
559
1043
  notExistsColumns: exitData,
@@ -563,7 +1047,6 @@ var FormulaList = forwardRef(function (props, ref) {
563
1047
  value: cloneDeep(_value),
564
1048
  onOk: function onOk(newList) {
565
1049
  try {
566
- // 子查询未改变不做操作
567
1050
  if (isEqual(newList, oldList)) {
568
1051
  o.close();
569
1052
  return;
@@ -577,15 +1060,12 @@ var FormulaList = forwardRef(function (props, ref) {
577
1060
  onChange === null || onChange === void 0 || onChange(caseList, '');
578
1061
  setCaseList(_toConsumableArray(caseList));
579
1062
  o.close();
580
- } catch (e) {
581
- console.warn(e);
582
- } finally {
1063
+ } catch (e) {} finally {
583
1064
  o.close();
584
1065
  }
585
1066
  }
586
1067
  }))
587
- }),
588
- onClose: function onClose() {}
1068
+ })
589
1069
  });
590
1070
  };
591
1071
  function selectConstant(e) {
@@ -610,7 +1090,6 @@ var FormulaList = forwardRef(function (props, ref) {
610
1090
  })
611
1091
  });
612
1092
  }
613
- // 函数弹窗
614
1093
  var showFunction = function showFunction(e, i) {
615
1094
  var _value = caseList[i];
616
1095
  var o = Modal2.openModal({
@@ -647,317 +1126,275 @@ var FormulaList = forwardRef(function (props, ref) {
647
1126
  onClose: function onClose() {}
648
1127
  });
649
1128
  };
650
- // 分段
651
- var itemDom = function itemDom(v, index) {
1129
+ var itemDom = function itemDom(v, index, groupType) {
652
1130
  var type = v.type;
653
1131
  if (v.type === AtomsTypeEnum.NOT_EXISTS || v.type === AtomsTypeEnum.EXISTS) {
654
- return _jsx(ItemName, {
655
- isError: isExistsError(v.notExists, store.existsError),
656
- children: _jsxs("div", {
657
- className: "Sqb-TableName purple-name",
658
- onClick: function onClick(e) {
659
- return showNotExists(index);
660
- },
661
- children: [v.type, " ( * )", _jsx("span", {
662
- className: 'item-del',
663
- style: {
664
- fontSize: 0
665
- },
666
- onClick: function onClick(e) {
667
- return handleDel(e, index);
668
- },
669
- children: _jsx(CloseIcon, {})
670
- })]
671
- }, index)
672
- }, index);
673
- } else if (v.type === AtomsTypeEnum.SUB_QUERY) {
674
- return _jsx(ItemName, {
675
- isError: isExistsError(v.subQuery, store.existsError),
676
- children: _jsxs("div", {
677
- className: "Sqb-TableName purple-name",
678
- onClick: function onClick(e) {
679
- return showSubQuery(index);
680
- },
681
- children: [v.label || __('SqlQueryBuilder.subquery'), _jsx("span", {
682
- className: 'item-del',
683
- style: {
684
- fontSize: 0
685
- },
686
- onClick: function onClick(e) {
687
- return handleDel(e, index);
688
- },
689
- children: _jsx(CloseIcon, {})
690
- })]
691
- }, index)
692
- }, index);
693
- } else if (type === AtomsTypeEnum.FIELD) {
694
- // 字段
695
- return _jsx(ItemName, {
696
- isError: isError(v, data),
697
- children: _jsxs("div", {
698
- className: cx("Sqb-TableName ", {
699
- notSelected: !(v !== null && v !== void 0 && v.fieldName)
1132
+ return {
1133
+ className: 'purple-name',
1134
+ onClick: function onClick() {
1135
+ return showNotExists(index);
1136
+ },
1137
+ node: _jsxs(_Fragment, {
1138
+ children: [v.type, " ( * )", renderDeleteIcon(v, index, groupType)]
1139
+ })
1140
+ };
1141
+ }
1142
+ if (v.type === AtomsTypeEnum.SUB_QUERY) {
1143
+ return {
1144
+ className: 'purple-name',
1145
+ onClick: function onClick() {
1146
+ return showSubQuery(index);
1147
+ },
1148
+ node: _jsxs(_Fragment, {
1149
+ children: [v.label || __('SqlQueryBuilder.subquery'), renderDeleteIcon(v, index, groupType)]
1150
+ })
1151
+ };
1152
+ }
1153
+ if (type === AtomsTypeEnum.FIELD) {
1154
+ return {
1155
+ className: cx({
1156
+ notSelected: !(v !== null && v !== void 0 && v.fieldName)
1157
+ }),
1158
+ onClick: function onClick(e) {
1159
+ return handleField(e, index, v);
1160
+ },
1161
+ node: _jsxs(_Fragment, {
1162
+ children: [!(v !== null && v !== void 0 && v.fieldName) && __('customColumn.selectField'), v.fieldName, renderDeleteIcon(v, index, groupType)]
1163
+ })
1164
+ };
1165
+ }
1166
+ if (type === AtomsTypeEnum.INPUT_STRING) {
1167
+ return {
1168
+ className: 'notSelected',
1169
+ node: _jsxs(_Fragment, {
1170
+ children: [_jsx(FieldString, {}), _jsx(Input, {
1171
+ className: ':sqb-Custom-input',
1172
+ value: v.val,
1173
+ placeholder: __('SqlQueryBuilder.pleaseEnter'),
1174
+ size: 'large',
1175
+ onChange: function onChange(val) {
1176
+ handleConstant(val, index);
1177
+ }
1178
+ }), renderDeleteIcon(v, index, groupType)]
1179
+ })
1180
+ };
1181
+ }
1182
+ if (type === AtomsTypeEnum.INPUT_NUMBER) {
1183
+ return {
1184
+ className: 'notSelected',
1185
+ node: _jsxs(_Fragment, {
1186
+ children: [_jsx(FieldNumber, {}), _jsx(InputNumber, {
1187
+ className: ':sqb-Custom-input',
1188
+ value: v.val,
1189
+ placeholder: __('SqlQueryBuilder.pleaseEnter'),
1190
+ size: 'large',
1191
+ onChange: function onChange(val) {
1192
+ handleConstant(val, index);
1193
+ }
1194
+ }), renderDeleteIcon(v, index, groupType)]
1195
+ })
1196
+ };
1197
+ }
1198
+ if (type === AtomsTypeEnum.OPERATOR) {
1199
+ if (isFixedCaseOperator(v)) {
1200
+ return {
1201
+ raw: true,
1202
+ node: _jsx("span", {
1203
+ className: 'Sqb-CaseKeyword',
1204
+ children: v.val
1205
+ })
1206
+ };
1207
+ }
1208
+ if (groupType === 'logic' && isFixedLogicOperator(v)) {
1209
+ return {
1210
+ raw: true,
1211
+ node: _jsx("span", {
1212
+ className: 'Sqb-CaseKeyword',
1213
+ children: v.val
1214
+ })
1215
+ };
1216
+ }
1217
+ if (groupType === 'logic' && ['and', 'or'].includes(v.val)) {
1218
+ var nextLogicOperator = v.val === 'and' ? 'or' : 'and';
1219
+ return {
1220
+ className: cx({
1221
+ 'logic-operator': true,
1222
+ 'logic-and': v.val === 'and',
1223
+ 'logic-or': v.val === 'or'
700
1224
  }),
701
- onClick: function onClick(e) {
702
- return handleField(e, index, v);
1225
+ onClick: function onClick() {
1226
+ handleConstant(nextLogicOperator, index);
703
1227
  },
704
- children: [!(v !== null && v !== void 0 && v.fieldName) && __('customColumn.selectField'), v.fieldName, _jsx("span", {
705
- className: 'item-del',
706
- style: {
707
- fontSize: 0
708
- },
709
- onClick: function onClick(e) {
710
- return handleDel(e, index);
711
- },
712
- children: _jsx(CloseIcon, {})
713
- })]
714
- })
715
- }, index);
716
- } else if (type === AtomsTypeEnum.INPUT_STRING) {
717
- // 输入框
718
- return _jsxs("div", {
719
- className: cx("Sqb-TableName notSelected "),
720
- children: [_jsx(FieldString, {}), _jsx(Input, {
721
- className: ':Sqb-Custom-input',
1228
+ node: renderTokenContent(v.val)
1229
+ };
1230
+ }
1231
+ return {
1232
+ className: cx('operator-trigger', {
1233
+ notSelected: !v.val,
1234
+ 'flow-operator': ['case', 'when', 'then', 'else', 'end'].includes(v.val),
1235
+ 'logic-operator': ['and', 'or'].includes(v.val),
1236
+ 'logic-and': v.val === 'and',
1237
+ 'logic-or': v.val === 'or'
1238
+ }),
1239
+ node: _jsx(Select, {
1240
+ triggerProps: getSelectTriggerProps(),
722
1241
  value: v.val,
723
- placeholder: __('SqlQueryBuilder.pleaseEnter'),
724
- size: 'large',
725
- onChange: function onChange(val) {
726
- handleConstant(val, index);
727
- }
728
- }), _jsx("span", {
729
- className: 'item-del',
730
- style: {
731
- fontSize: 0
732
- },
733
- onClick: function onClick(e) {
734
- return handleDel(e, index);
1242
+ triggerElement: function triggerElement() {
1243
+ return renderTokenContent(_jsxs(_Fragment, {
1244
+ children: [!v.val && __('customColumn.selectOperator'), v.val, renderDeleteIcon(v, index)]
1245
+ }));
735
1246
  },
736
- children: _jsx(CloseIcon, {})
737
- })]
738
- });
739
- } else if (type === AtomsTypeEnum.INPUT_NUMBER) {
740
- // 输入框
741
- return _jsxs("div", {
742
- className: cx("Sqb-TableName notSelected "),
743
- children: [_jsx(FieldNumber, {}), _jsx(InputNumber, {
744
- className: ':sqb-Custom-input',
745
- value: v.val,
746
- placeholder: __('SqlQueryBuilder.pleaseEnter'),
747
- size: 'large',
748
1247
  onChange: function onChange(val) {
749
1248
  handleConstant(val, index);
750
- }
751
- }), _jsx("span", {
752
- className: 'item-del',
753
- style: {
754
- fontSize: 0
755
1249
  },
756
- onClick: function onClick(e) {
757
- return handleDel(e, index);
758
- },
759
- children: _jsx(CloseIcon, {})
760
- })]
761
- });
762
- } else if (type === AtomsTypeEnum.OPERATOR) {
763
- //连接符
764
- return _jsx(Select, {
765
- triggerProps: {
766
- clickToClose: true
767
- },
768
- value: v.val,
769
- triggerElement: function triggerElement(value) {
770
- return _jsxs("div", {
771
- className: cx("Sqb-TableName Sqb-TableName-OPERATOR", {
772
- notSelected: !v.val
773
- }),
774
- children: [!v.val && __('customColumn.selectOperator'), v.val, _jsx("span", {
775
- className: 'item-del',
776
- style: {
777
- fontSize: 0
778
- },
779
- onClick: function onClick(e) {
780
- return handleDel(e, index);
781
- },
782
- children: _jsx(CloseIcon, {})
783
- })]
784
- });
785
- },
786
- onChange: function onChange(val) {
787
- handleConstant(val, index);
788
- },
789
- children: operatorList.map(function (option, index) {
790
- return _jsx(Select.Option, {
791
- value: option,
792
- children: option
793
- }, index + '' + ind);
1250
+ children: operatorList.map(function (option, optionIndex) {
1251
+ return _jsx(Select.Option, {
1252
+ value: option,
1253
+ children: option
1254
+ }, optionIndex + '' + ind);
1255
+ })
794
1256
  })
795
- });
796
- } else if (type === AtomsTypeEnum.CONSTANT) {
797
- //常量
798
- return _jsx(ItemName, {
799
- isError: !!(v.id || v.val) && !getConstantLabel(store.constantList, v.id || v.val),
800
- message: "\u5E38\u91CF\u4E22\u5931",
801
- children: _jsxs("div", {
802
- className: cx("Sqb-TableName", {
803
- notSelected: !v.val
804
- }),
805
- "v-index": index,
806
- "v-val": v.id || v.val,
807
- onClick: selectConstant,
808
- children: [getConstantLabel(store.constantList, v.id || v.val, v.val) || __('SqlQueryBuilder.pickConstant'), _jsx("span", {
809
- className: 'item-del',
810
- style: {
811
- fontSize: 0
812
- },
813
- onClick: function onClick(e) {
814
- return handleDel(e, index);
815
- },
816
- children: _jsx(CloseIcon, {})
817
- })]
1257
+ };
1258
+ }
1259
+ if (type === AtomsTypeEnum.CONSTANT) {
1260
+ return {
1261
+ className: cx({
1262
+ notSelected: !v.val
1263
+ }),
1264
+ attrs: {
1265
+ 'v-index': index,
1266
+ 'v-val': v.id || v.val
1267
+ },
1268
+ onClick: selectConstant,
1269
+ node: _jsxs(_Fragment, {
1270
+ children: [getConstantLabel(store.constantList, v.id || v.val, v.val) || __('SqlQueryBuilder.pickConstant'), renderDeleteIcon(v, index, groupType)]
818
1271
  })
819
- }, index);
820
- } else if (otherTypeMap.has(String(type))) {
821
- // 业务自定义常量类型(otherTypes)
1272
+ };
1273
+ }
1274
+ if (otherTypeMap.has(String(type))) {
822
1275
  var currentOtherType = otherTypeMap.get(String(type));
823
1276
  var listSource = (currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.list) || [];
824
- return _jsx(ItemName, {
825
- isError: !!(v.id || v.val) && !getConstantLabel(listSource, v.id || v.val),
826
- message: "".concat(currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.label, "\u4E22\u5931"),
827
- children: _jsxs("div", {
828
- className: cx("Sqb-TableName", {
829
- notSelected: !v.val
830
- }),
831
- "v-index": index,
832
- "v-val": v.id || v.val,
833
- "v-type": type,
834
- onClick: selectConstant,
835
- children: [getConstantLabel(listSource, v.id || v.val, v.val) || "\u8BF7\u9009\u62E9".concat(currentOtherType.label), _jsx("span", {
836
- className: 'item-del',
837
- style: {
838
- fontSize: 0
839
- },
840
- onClick: function onClick(e) {
841
- return handleDel(e, index);
842
- },
843
- children: _jsx(CloseIcon, {})
844
- })]
1277
+ return {
1278
+ className: cx({
1279
+ notSelected: !v.val
1280
+ }),
1281
+ attrs: {
1282
+ 'v-index': index,
1283
+ 'v-val': v.id || v.val,
1284
+ 'v-type': type
1285
+ },
1286
+ onClick: selectConstant,
1287
+ node: _jsxs(_Fragment, {
1288
+ children: [getConstantLabel(listSource, v.id || v.val, v.val) || "\u8BF7\u9009\u62E9".concat(currentOtherType.label), renderDeleteIcon(v, index, groupType)]
845
1289
  })
846
- }, index);
847
- } else if (type === AtomsTypeEnum.EXPRESSION) {
1290
+ };
1291
+ }
1292
+ if (type === AtomsTypeEnum.EXPRESSION) {
848
1293
  if (~['早于', '晚于', '在'].indexOf(v.condition) && v.rhs.length > 1) {
849
- var _caseList$index$quote;
850
- var _caseList = caseList.slice();
851
- _caseList[index].rhs = [_caseList[index].rhs[0]];
852
- _caseList[index].quotes = (_caseList$index$quote = _caseList[index].quotes.split(' || ')) === null || _caseList$index$quote === void 0 ? void 0 : _caseList$index$quote[0];
853
- setCaseList(_caseList);
1294
+ var _nextList$index$quote;
1295
+ var nextList = caseList.slice();
1296
+ nextList[index].rhs = [nextList[index].rhs[0]];
1297
+ nextList[index].quotes = (_nextList$index$quote = nextList[index].quotes.split(' || ')) === null || _nextList$index$quote === void 0 ? void 0 : _nextList$index$quote[0];
1298
+ setCaseList(nextList);
854
1299
  }
855
- // 表达式
856
- return _jsx(ItemName, {
857
- isError: isError(v, data),
858
- children: _jsxs("div", {
859
- className: cx("Sqb-TableName purple-name", {
860
- notSelected: !v.quotes
861
- }),
862
- onClick: function onClick(e) {
863
- return handleExpression(e, index, v);
864
- },
865
- children: [v.quotes ? v.quotes : __('customColumn.selectExpression'), _jsx("span", {
866
- className: 'item-del',
867
- style: {
868
- fontSize: 0
869
- },
870
- onClick: function onClick(e) {
871
- return handleDel(e, index);
872
- },
873
- children: _jsx(CloseIcon, {})
874
- })]
1300
+ return {
1301
+ className: cx('purple-name', {
1302
+ notSelected: !v.quotes
1303
+ }),
1304
+ onClick: function onClick(e) {
1305
+ return handleExpression(e, index, v);
1306
+ },
1307
+ node: _jsxs(_Fragment, {
1308
+ children: [v.quotes ? v.quotes : __('customColumn.selectExpression'), renderDeleteIcon(v, index, groupType)]
875
1309
  })
876
- }, index);
877
- } else if (type === AtomsTypeEnum.FORMULA) {
878
- // 公式
879
- return _jsx(ItemName, {
880
- isError: isError(v, data) || formulaIsError(v, formulaList),
881
- message: formulaIsError(v, formulaList) ? '公式丢失' : '',
882
- children: _jsxs("div", {
883
- className: cx("Sqb-TableName gray-name"),
884
- onClick: function onClick(e) {
885
- return showFunction(e, index);
1310
+ };
1311
+ }
1312
+ if (type === AtomsTypeEnum.CASE_WHEN) {
1313
+ return {
1314
+ raw: true,
1315
+ node: renderCaseWhenEditor(v, index)
1316
+ };
1317
+ }
1318
+ if (type === AtomsTypeEnum.AND_OR) {
1319
+ return {
1320
+ raw: true,
1321
+ node: renderAndOrEditor(v, index)
1322
+ };
1323
+ }
1324
+ if (type === AtomsTypeEnum.FORMULA) {
1325
+ return {
1326
+ className: 'gray-name',
1327
+ onClick: function onClick(e) {
1328
+ return showFunction(e, index);
1329
+ },
1330
+ node: _jsxs(_Fragment, {
1331
+ children: [v.name ? getQuotes(v, v.args, formulaList) : __('customColumn.selectFormula'), renderDeleteIcon(v, index, groupType)]
1332
+ })
1333
+ };
1334
+ }
1335
+ if (type === AtomsTypeEnum.SELECT) {
1336
+ return {
1337
+ className: cx('operator-trigger', {
1338
+ notSelected: !v.val,
1339
+ 'flow-operator': v.val === 'caseWhen',
1340
+ 'logic-operator': v.val === 'andOr'
1341
+ }),
1342
+ node: _jsx(Select, {
1343
+ triggerProps: getSelectTriggerProps(),
1344
+ multiple: v.multiple,
1345
+ value: v.val,
1346
+ triggerElement: function triggerElement() {
1347
+ return renderTokenContent(_jsxs(_Fragment, {
1348
+ children: [!v.val && __('customColumn.selectOperator'), v.val, !v.fixed && renderDeleteIcon(v, index, groupType)]
1349
+ }));
886
1350
  },
887
- children: [v.name ? getQuotes(v, v.args, formulaList) : __('customColumn.selectFormula'), _jsx("span", {
888
- className: 'item-del',
889
- style: {
890
- fontSize: 0
891
- },
892
- onClick: function onClick(e) {
893
- return handleDel(e, index);
894
- },
895
- children: _jsx(CloseIcon, {})
896
- })]
1351
+ onChange: function onChange(val) {
1352
+ handleConstant(val, index);
1353
+ },
1354
+ children: v.options.map(function (option, optionIndex) {
1355
+ return _jsx(Select.Option, {
1356
+ value: option.value,
1357
+ children: option.label
1358
+ }, optionIndex + '' + ind);
1359
+ })
897
1360
  })
898
- }, index);
899
- } else if (type === AtomsTypeEnum.SELECT) {
900
- // 选择框
901
- return _jsx(Select, {
902
- triggerProps: {
903
- clickToClose: true
904
- },
905
- multiple: v.multiple,
906
- value: v.val,
907
- triggerElement: function triggerElement(value) {
908
- return _jsxs("div", {
909
- className: cx("Sqb-TableName Sqb-TableName-OPERATOR", {
910
- notSelected: !v.val
911
- }),
912
- children: [!v.val && __('customColumn.selectOperator'), v.val, !v.fixed && _jsx("span", {
913
- className: 'item-del',
914
- style: {
915
- fontSize: 0
916
- },
917
- onClick: function onClick(e) {
918
- return handleDel(e, index);
919
- },
920
- children: _jsx(CloseIcon, {})
921
- })]
922
- });
923
- },
924
- onChange: function onChange(val) {
925
- handleConstant(val, index);
1361
+ };
1362
+ }
1363
+ if (groupType === 'logic') {
1364
+ return {
1365
+ className: cx('gray-name', 'notSelected'),
1366
+ style: {
1367
+ minWidth: 44,
1368
+ justifyContent: 'center'
926
1369
  },
927
- children: v.options.map(function (option, index) {
928
- return _jsx(Select.Option, {
929
- value: option.value,
930
- children: option.label
931
- }, index + '' + ind);
1370
+ node: selectOperator({
1371
+ triggerElement: function triggerElement() {
1372
+ return renderTokenContent(_jsx(AddIcon, {}));
1373
+ },
1374
+ ind: index,
1375
+ position: ''
932
1376
  })
933
- });
934
- } else {
935
- return selectOperator({
1377
+ };
1378
+ }
1379
+ return {
1380
+ className: cx({
1381
+ notSelected: true
1382
+ }),
1383
+ node: selectOperator({
936
1384
  triggerElement: function triggerElement() {
937
- return _jsxs("div", {
938
- className: cx("Sqb-TableName ", {
939
- notSelected: true
940
- }),
941
- children: [__('customColumn.selectCustomInput'), _jsx("span", {
942
- className: 'item-del',
943
- style: {
944
- fontSize: 0
945
- },
946
- onClick: function onClick(e) {
947
- return handleDel(e, index);
948
- },
949
- children: _jsx(CloseIcon, {})
950
- })]
951
- });
1385
+ return renderTokenContent(_jsxs(_Fragment, {
1386
+ children: [__('customColumn.selectCustomInput'), renderDeleteIcon(v, index, groupType)]
1387
+ }));
952
1388
  },
953
1389
  ind: index,
954
1390
  position: ''
955
- });
956
- }
1391
+ })
1392
+ };
957
1393
  };
958
1394
  var copyDom = function copyDom() {
959
1395
  var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
960
1396
  var positioned = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1397
+ if (embedded) return null;
961
1398
  if (!isCopy || selectedIndices.length === 0 && checkedItemsCount === 0) return null;
962
1399
  return _jsx("div", {
963
1400
  className: cx('Sqb-Filter-item-copy', {
@@ -985,10 +1422,147 @@ var FormulaList = forwardRef(function (props, ref) {
985
1422
  })
986
1423
  });
987
1424
  };
1425
+ var renderItemShell = function renderItemShell(v, i, groupType, extraClassName) {
1426
+ var showCheckbox = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1427
+ var itemContent = itemDom(v, i, groupType);
1428
+ var isCompositeAtom = v.type === AtomsTypeEnum.CASE_WHEN || v.type === AtomsTypeEnum.AND_OR;
1429
+ var isPassiveCaseKeyword = groupType === 'caseWhen' && isFixedCaseOperator(v) || groupType === 'logic' && isFixedLogicOperator(v);
1430
+ return _jsx(React.Fragment, {
1431
+ children: _jsxs("div", {
1432
+ className: cx('Sqb-Filter-item', _defineProperty({
1433
+ hover: ind === i && hoveredCopyIndex !== i,
1434
+ 'item-fixed': v.fixed || false,
1435
+ 'item-selected': isCheck,
1436
+ 'item-composite': isCompositeAtom,
1437
+ 'group-child': groupType !== 'single',
1438
+ 'group-flow-child': groupType === 'caseWhen',
1439
+ 'group-logic-child': groupType === 'logic'
1440
+ }, extraClassName || '', !!extraClassName)),
1441
+ onMouseEnter: function onMouseEnter(e) {
1442
+ if (isCheck || isPassiveCaseKeyword) return;
1443
+ setInd(i);
1444
+ },
1445
+ onMouseLeave: function onMouseLeave() {
1446
+ if (isCheck || isPassiveCaseKeyword) return;
1447
+ setInd(-1);
1448
+ },
1449
+ children: [copyDom(i), canShowInsertArrows(v, groupType) && selectOperator({
1450
+ triggerElement: function triggerElement() {
1451
+ return _jsx("div", {
1452
+ className: 'left-arrow',
1453
+ "v-index": i,
1454
+ "v-type": 'before',
1455
+ onClick: function onClick() {
1456
+ if (!selectedIndices.length) addOperator(AtomsTypeEnum.UNKNOWN, i, 'before');
1457
+ },
1458
+ children: _jsx("img", {
1459
+ src: arrow
1460
+ })
1461
+ });
1462
+ },
1463
+ ind: i,
1464
+ position: 'before',
1465
+ trigger: 'hover'
1466
+ }), !embedded && showCheckbox && v.type !== AtomsTypeEnum.UNKNOWN && _jsx(Checkbox, {
1467
+ className: 'item-check',
1468
+ checked: selectedIndices.includes(i),
1469
+ disabled: globalSelectionActive && globalSelectionOwner !== myInstanceIdRef.current,
1470
+ onChange: function onChange(e) {
1471
+ var _e$target$checked, _e$target;
1472
+ return toggleSelect(i, (_e$target$checked = e === null || e === void 0 || (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.checked) !== null && _e$target$checked !== void 0 ? _e$target$checked : !selectedIndices.includes(i));
1473
+ }
1474
+ }), _jsx("div", {
1475
+ style: {
1476
+ pointerEvents: isCheck || store.isMetabaseCopy ? 'none' : 'auto'
1477
+ },
1478
+ className: cx({
1479
+ openCheck: isCheck
1480
+ }),
1481
+ children: _jsx(ItemName, _objectSpread(_objectSpread({}, getItemNameProps(v)), {}, {
1482
+ children: itemContent.raw ? itemContent.node : _jsx("div", _objectSpread(_objectSpread({
1483
+ className: cx('Sqb-TableName', itemContent.className),
1484
+ onClick: itemContent.onClick,
1485
+ style: itemContent.style
1486
+ }, itemContent.attrs || {}), {}, {
1487
+ children: itemContent.node
1488
+ }))
1489
+ }))
1490
+ }), canShowInsertArrows(v, groupType) && selectOperator({
1491
+ triggerElement: function triggerElement(value) {
1492
+ return _jsx("div", {
1493
+ className: 'right-arrow',
1494
+ "v-index": i,
1495
+ "v-type": 'after',
1496
+ onClick: function onClick() {
1497
+ addOperator(AtomsTypeEnum.UNKNOWN, i, 'after');
1498
+ },
1499
+ children: _jsx("img", {
1500
+ src: arrow
1501
+ })
1502
+ });
1503
+ },
1504
+ ind: i,
1505
+ position: 'after',
1506
+ trigger: 'hover'
1507
+ })]
1508
+ })
1509
+ }, i);
1510
+ };
1511
+ var renderCaseSection = function renderCaseSection(itemIndices, groupType, sectionClassName) {
1512
+ return itemIndices.map(function (itemIndex) {
1513
+ return renderItemShell(caseList[itemIndex], itemIndex, groupType, "case-row-item ".concat(sectionClassName), false);
1514
+ });
1515
+ };
1516
+ var renderDeleteIcon = function renderDeleteIcon(item, index, groupType) {
1517
+ if (!canDeleteItem(item, groupType)) return null;
1518
+ return _jsx("span", {
1519
+ className: 'item-del',
1520
+ style: {
1521
+ fontSize: 0
1522
+ },
1523
+ onClick: function onClick(e) {
1524
+ return handleDel(e, index);
1525
+ },
1526
+ children: _jsx(CloseIcon, {})
1527
+ });
1528
+ };
1529
+ var renderCaseRecoverButton = function renderCaseRecoverButton(onClick, className, label) {
1530
+ return _jsxs("button", {
1531
+ type: 'button',
1532
+ className: cx('Sqb-CaseRecover', className),
1533
+ onClick: onClick,
1534
+ children: [_jsx(FfPlus, {}), _jsx("span", {
1535
+ children: label
1536
+ })]
1537
+ });
1538
+ };
1539
+ var renderGroupInsertArrow = function renderGroupInsertArrow(index, position) {
1540
+ return selectOperator({
1541
+ triggerElement: function triggerElement() {
1542
+ return _jsx("div", {
1543
+ className: position === 'before' ? 'left-arrow' : 'right-arrow',
1544
+ "v-index": index,
1545
+ "v-type": position,
1546
+ onClick: function onClick() {
1547
+ if (position === 'before' && selectedIndices.length) return;
1548
+ addOperator(AtomsTypeEnum.UNKNOWN, index, position);
1549
+ },
1550
+ children: _jsx("img", {
1551
+ src: arrow
1552
+ })
1553
+ });
1554
+ },
1555
+ ind: index,
1556
+ position: position,
1557
+ trigger: 'hover'
1558
+ });
1559
+ };
988
1560
  return _jsx(_Fragment, {
989
1561
  children: _jsxs("div", {
990
- className: "Sqb-NotebookCell",
991
- children: [isCopy && caseList.length > 0 && _jsxs(Space, {
1562
+ className: cx('Sqb-NotebookCell', {
1563
+ 'Sqb-NotebookCell--embedded': embedded
1564
+ }),
1565
+ children: [!embedded && isCopy && caseList.length > 0 && _jsxs(Space, {
992
1566
  size: 'small',
993
1567
  direction: 'vertical',
994
1568
  className: cx('item-isCheck', {
@@ -1027,75 +1601,8 @@ var FormulaList = forwardRef(function (props, ref) {
1027
1601
  },
1028
1602
  children: "\u6E05\u9664\u590D\u5236"
1029
1603
  })]
1030
- }), (_caseList2 = caseList) === null || _caseList2 === void 0 ? void 0 : _caseList2.map(function (v, i) {
1031
- return _jsx(React.Fragment, {
1032
- children: _jsxs("div", {
1033
- className: cx('Sqb-Filter-item', {
1034
- hover: ind === i && hoveredCopyIndex !== i,
1035
- 'item-fixed': v.fixed || false,
1036
- 'item-selected': isCheck
1037
- }),
1038
- onMouseEnter: function onMouseEnter(e) {
1039
- if (isCheck) return;
1040
- setInd(i);
1041
- },
1042
- onMouseLeave: function onMouseLeave() {
1043
- if (isCheck) return;
1044
- setInd(-1);
1045
- },
1046
- children: [copyDom(i), selectOperator({
1047
- triggerElement: function triggerElement() {
1048
- return _jsx("div", {
1049
- className: 'left-arrow',
1050
- "v-index": i,
1051
- "v-type": 'before',
1052
- onClick: function onClick() {
1053
- if (!selectedIndices.length) addOperator(AtomsTypeEnum.UNKNOWN, i, 'before');
1054
- },
1055
- children: _jsx("img", {
1056
- src: arrow
1057
- })
1058
- });
1059
- },
1060
- ind: i,
1061
- position: 'before',
1062
- trigger: 'hover'
1063
- }), v.type !== AtomsTypeEnum.UNKNOWN && _jsx(Checkbox, {
1064
- className: 'item-check',
1065
- checked: selectedIndices.includes(i),
1066
- disabled: globalSelectionActive && globalSelectionOwner !== myInstanceIdRef.current,
1067
- onChange: function onChange(e) {
1068
- var _e$target$checked, _e$target;
1069
- return toggleSelect(i, (_e$target$checked = e === null || e === void 0 || (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.checked) !== null && _e$target$checked !== void 0 ? _e$target$checked : !selectedIndices.includes(i));
1070
- }
1071
- }), _jsx("div", {
1072
- style: {
1073
- pointerEvents: isCheck || store.isMetabaseCopy ? 'none' : 'auto'
1074
- },
1075
- className: cx('Sqb-Filter-item-content', {
1076
- openCheck: isCheck
1077
- }),
1078
- children: itemDom(v, i)
1079
- }), selectOperator({
1080
- triggerElement: function triggerElement(value) {
1081
- return _jsx("div", {
1082
- className: 'right-arrow',
1083
- "v-index": i,
1084
- "v-type": 'after',
1085
- onClick: function onClick() {
1086
- addOperator(AtomsTypeEnum.UNKNOWN, i, 'after');
1087
- },
1088
- children: _jsx("img", {
1089
- src: arrow
1090
- })
1091
- });
1092
- },
1093
- ind: i,
1094
- position: 'after',
1095
- trigger: 'hover'
1096
- })]
1097
- }, i)
1098
- }, i);
1604
+ }), caseList.map(function (item, itemIndex) {
1605
+ return renderItemShell(item, itemIndex, 'single');
1099
1606
  }), Array.from(caseList).length < 1 && selectOperator({
1100
1607
  triggerElement: function triggerElement() {
1101
1608
  return _jsx("div", {
@@ -1106,7 +1613,7 @@ var FormulaList = forwardRef(function (props, ref) {
1106
1613
  ind: -1,
1107
1614
  position: 'add',
1108
1615
  trigger: 'click'
1109
- }), copyDom(-1, false), showPreview && _jsx("div", {
1616
+ }), !embedded && copyDom(-1, false), !embedded && showPreview && _jsx("div", {
1110
1617
  className: cx("mb-2 font-bold uppercase tracking-wider preview-box"),
1111
1618
  style: {
1112
1619
  fontSize: 12,
@@ -1149,54 +1656,10 @@ var FormulaList = forwardRef(function (props, ref) {
1149
1656
  isSqlError: errorInfo.isError
1150
1657
  }),
1151
1658
  children: caseList.map(function (v, i) {
1152
- if (v !== null && v !== void 0 && v.quotes) {
1153
- return _jsx("span", {
1154
- className: 'mr-1',
1155
- children: v === null || v === void 0 ? void 0 : v.quotes
1156
- }, i);
1157
- } else if (v !== null && v !== void 0 && v.fieldName) {
1158
- return _jsx("span", {
1159
- className: 'mr-1',
1160
- children: v === null || v === void 0 ? void 0 : v.fieldName
1161
- }, i);
1162
- } else {
1163
- if (v.type === AtomsTypeEnum.OPERATOR && (v.val === 'and' || v.val === 'or')) {
1164
- return _jsxs("span", {
1165
- className: 'mr-1',
1166
- children: [_jsx("br", {}), v.val, _jsx("br", {})]
1167
- }, i);
1168
- }
1169
- if (v.type === AtomsTypeEnum.OPERATOR) {
1170
- if (v.val === '(' || v.val === ')') {
1171
- return _jsx("span", {
1172
- className: cx('mr-1', {
1173
- error: errorInfo.isBracket
1174
- }),
1175
- children: v.val
1176
- }, i);
1177
- }
1178
- if (v.val === 'case' || v.val === 'end' || v.val === 'when' || v.val === 'then') {
1179
- return _jsx("span", {
1180
- className: cx('mr-1', {
1181
- error: errorInfo.isCase
1182
- }),
1183
- children: v.val
1184
- }, i);
1185
- }
1186
- if (v.val === 'over') {
1187
- return _jsx("span", {
1188
- className: cx('mr-1', {
1189
- error: errorInfo.isOver
1190
- }),
1191
- children: v.val
1192
- }, i);
1193
- }
1194
- }
1195
- return _jsx("span", {
1196
- className: 'mr-1',
1197
- children: v.val
1198
- }, i);
1199
- }
1659
+ return _jsx("span", {
1660
+ className: 'mr-1',
1661
+ children: getItemDisplayText(v)
1662
+ }, i);
1200
1663
  })
1201
1664
  }), _jsx("div", {
1202
1665
  className: 'errorMsg mt-2',