@gingkoo/pandora-metabase 1.0.156 → 1.0.157-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 (87) hide show
  1. package/lib/cjs/components/dialog/custom-editor/index.js +61 -5
  2. package/lib/cjs/components/dialog/expression/index.js +132 -54
  3. package/lib/cjs/components/dialog/expression/index.less +43 -0
  4. package/lib/cjs/components/dialog/formula/index.js +3 -1
  5. package/lib/cjs/components/dialog/formula/utils.d.ts +1 -0
  6. package/lib/cjs/components/dialog/formula/utils.js +20 -2
  7. package/lib/cjs/components/dialog/formula-list/index.d.ts +2 -0
  8. package/lib/cjs/components/dialog/formula-list/index.js +1119 -151
  9. package/lib/cjs/components/dialog/formula-list/index.less +362 -46
  10. package/lib/cjs/components/dialog/formula-list/utils.d.ts +13 -1
  11. package/lib/cjs/components/dialog/formula-list/utils.js +100 -1
  12. package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +2 -1
  13. package/lib/cjs/components/dialog/select-column-multiple/index.js +4 -2
  14. package/lib/cjs/components/dialog/select-join/index.js +11 -0
  15. package/lib/cjs/components/dialog/select-summarize/index.d.ts +4 -0
  16. package/lib/cjs/components/dialog/select-summarize/index.js +136 -15
  17. package/lib/cjs/components/dialog/select-summarize/index.less +34 -1
  18. package/lib/cjs/components/dialog/select-table/index.d.ts +4 -1
  19. package/lib/cjs/components/dialog/select-table/index.js +51 -7
  20. package/lib/cjs/components/dialog/select-table/index.less +20 -0
  21. package/lib/cjs/components/icons.d.ts +1 -0
  22. package/lib/cjs/components/icons.js +54 -29
  23. package/lib/cjs/components/metabase/index.js +8 -0
  24. package/lib/cjs/components/metabase/index.less +17 -14
  25. package/lib/cjs/components/modules/components/item-name.js +16 -2
  26. package/lib/cjs/components/modules/components/meta-icon.js +6 -4
  27. package/lib/cjs/components/modules/join-data.js +5 -0
  28. package/lib/cjs/components/modules/summarize/group-by.js +12 -1
  29. package/lib/cjs/components/modules/summarize/select-index.js +12 -1
  30. package/lib/cjs/hooks/use-state.js +1 -13
  31. package/lib/cjs/index.d.ts +3 -2
  32. package/lib/cjs/index.js +7 -0
  33. package/lib/cjs/locale/en.js +31 -0
  34. package/lib/cjs/locale/index.js +10 -6
  35. package/lib/cjs/locale/zh.js +31 -0
  36. package/lib/cjs/store/enum.d.ts +2 -1
  37. package/lib/cjs/store/enum.js +1 -0
  38. package/lib/cjs/store/helper.js +25 -2
  39. package/lib/cjs/store/types.d.ts +7 -1
  40. package/lib/cjs/types.d.ts +41 -1
  41. package/lib/cjs/utils/helper.js +20 -0
  42. package/lib/cjs/utils/transformSql.js +59 -2
  43. package/lib/cjs/utils.js +25 -4
  44. package/lib/es/components/dialog/custom-editor/index.js +62 -6
  45. package/lib/es/components/dialog/expression/index.js +133 -55
  46. package/lib/es/components/dialog/expression/index.less +43 -0
  47. package/lib/es/components/dialog/formula/index.js +4 -2
  48. package/lib/es/components/dialog/formula/utils.d.ts +1 -0
  49. package/lib/es/components/dialog/formula/utils.js +18 -1
  50. package/lib/es/components/dialog/formula-list/index.d.ts +2 -0
  51. package/lib/es/components/dialog/formula-list/index.js +1121 -153
  52. package/lib/es/components/dialog/formula-list/index.less +362 -46
  53. package/lib/es/components/dialog/formula-list/utils.d.ts +13 -1
  54. package/lib/es/components/dialog/formula-list/utils.js +99 -0
  55. package/lib/es/components/dialog/select-column-multiple/index.d.ts +2 -1
  56. package/lib/es/components/dialog/select-column-multiple/index.js +4 -2
  57. package/lib/es/components/dialog/select-join/index.js +12 -1
  58. package/lib/es/components/dialog/select-summarize/index.d.ts +4 -0
  59. package/lib/es/components/dialog/select-summarize/index.js +140 -19
  60. package/lib/es/components/dialog/select-summarize/index.less +34 -1
  61. package/lib/es/components/dialog/select-table/index.d.ts +4 -1
  62. package/lib/es/components/dialog/select-table/index.js +51 -7
  63. package/lib/es/components/dialog/select-table/index.less +20 -0
  64. package/lib/es/components/icons.d.ts +1 -0
  65. package/lib/es/components/icons.js +53 -28
  66. package/lib/es/components/metabase/index.js +8 -0
  67. package/lib/es/components/metabase/index.less +17 -14
  68. package/lib/es/components/modules/components/item-name.js +16 -2
  69. package/lib/es/components/modules/components/meta-icon.js +6 -4
  70. package/lib/es/components/modules/join-data.js +6 -1
  71. package/lib/es/components/modules/summarize/group-by.js +12 -1
  72. package/lib/es/components/modules/summarize/select-index.js +12 -1
  73. package/lib/es/hooks/use-state.js +1 -13
  74. package/lib/es/index.d.ts +3 -2
  75. package/lib/es/index.js +3 -1
  76. package/lib/es/locale/en.js +31 -0
  77. package/lib/es/locale/index.js +10 -6
  78. package/lib/es/locale/zh.js +31 -0
  79. package/lib/es/store/enum.d.ts +2 -1
  80. package/lib/es/store/enum.js +1 -0
  81. package/lib/es/store/helper.js +25 -2
  82. package/lib/es/store/types.d.ts +7 -1
  83. package/lib/es/types.d.ts +41 -1
  84. package/lib/es/utils/helper.js +20 -0
  85. package/lib/es/utils/transformSql.js +59 -2
  86. package/lib/es/utils.js +25 -4
  87. package/package.json +1 -1
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports["default"] = void 0;
9
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
11
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
12
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/extends"));
13
11
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
14
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
13
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
15
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
15
16
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
16
17
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
17
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
18
18
  var _jsxRuntime = require("react/jsx-runtime");
19
19
  var _react = _interopRequireWildcard(require("react"));
20
20
  require("./index.less");
@@ -47,7 +47,758 @@ var _helper = require("../../../store/helper");
47
47
  var _excluded = ["operator", "leftAtoms", "rightAtoms", "atoms"],
48
48
  _excluded2 = ["notExistsToolbar", "toolbar"],
49
49
  _excluded3 = ["subToolbar", "notExistsColumns", "showFields", "isExit", "toolbar"];
50
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); }
50
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t11 in e) "default" !== _t11 && {}.hasOwnProperty.call(e, _t11) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t11)) && (i.get || i.set) ? o(f, _t11, i) : f[_t11] = e[_t11]); return f; })(e, t); }
51
+ function getScopeKey(item) {
52
+ return item.scopeKey || "".concat(item.datasourceId || '', ":").concat(item.tableId || '', ":").concat(item.tableUuid || '', ":").concat(item.tableName || '', ":").concat(item.tableAlias || '');
53
+ }
54
+ function tableToScopeItem(table) {
55
+ var fixed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
56
+ var tableId = table.id || table.tableId || table.name || table.tableName || '';
57
+ var tableName = table.name || table.tableName || table.table || tableId;
58
+ var datasourceId = table.datasourceId || '';
59
+ var tableAlias = table.alias || table.tableAlias || '';
60
+ var tableUuid = table.tableUuid || '';
61
+ return {
62
+ datasourceId: datasourceId,
63
+ datasourceName: table.datasourceName,
64
+ tableId: tableId,
65
+ tableName: tableName,
66
+ tableNameZh: table.name_zh || table.tableNameZh || tableName,
67
+ tableAlias: tableAlias,
68
+ tableUuid: tableUuid,
69
+ fixed: fixed,
70
+ scopeKey: "".concat(datasourceId, ":").concat(tableId, ":").concat(tableUuid, ":").concat(tableName, ":").concat(tableAlias)
71
+ };
72
+ }
73
+ function scopeItemToTableValue(item) {
74
+ return {
75
+ datasourceId: item.datasourceId,
76
+ datasourceName: item.datasourceName,
77
+ name: item.tableName || '',
78
+ name_zh: item.tableNameZh || '',
79
+ tableUuid: item.tableUuid || '',
80
+ id: item.tableId || '',
81
+ alias: item.tableAlias || ''
82
+ };
83
+ }
84
+ function cleanJsonText() {
85
+ var rawText = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
86
+ return "".concat(rawText || '').trim().replace(/^```(?:json)?/i, '').replace(/```$/i, '').trim();
87
+ }
88
+ function parseFormulaSqlStreamText() {
89
+ var rawText = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
90
+ var parsed = JSON.parse(cleanJsonText(rawText));
91
+ if (!parsed || !Array.isArray(parsed.formulaList)) {
92
+ throw new Error('INVALID_FORMULA_SQL_RESULT');
93
+ }
94
+ return parsed;
95
+ }
96
+ function extractJsonStringValue(rawText, key) {
97
+ var keyPattern = "\"".concat(key, "\"");
98
+ var keyIndex = rawText.indexOf(keyPattern);
99
+ if (keyIndex < 0) return '';
100
+ var colonIndex = rawText.indexOf(':', keyIndex + keyPattern.length);
101
+ if (colonIndex < 0) return '';
102
+ var index = colonIndex + 1;
103
+ while (/\s/.test(rawText[index] || '')) index += 1;
104
+ if (rawText[index] !== '"') return '';
105
+ index += 1;
106
+ var value = '';
107
+ var escaped = false;
108
+ for (; index < rawText.length; index += 1) {
109
+ var char = rawText[index];
110
+ if (escaped) {
111
+ try {
112
+ value += JSON.parse("\"\\".concat(char, "\""));
113
+ } catch (error) {
114
+ value += char;
115
+ }
116
+ escaped = false;
117
+ continue;
118
+ }
119
+ if (char === '\\') {
120
+ escaped = true;
121
+ continue;
122
+ }
123
+ if (char === '"') break;
124
+ value += char;
125
+ }
126
+ return value;
127
+ }
128
+ var SqlImportContent = function SqlImportContent(_ref2) {
129
+ var onSubmit = _ref2.onSubmit,
130
+ onClose = _ref2.onClose,
131
+ streamParser = _ref2.streamParser,
132
+ datasource = _ref2.datasource,
133
+ sourceTable = _ref2.sourceTable,
134
+ tableFlat = _ref2.tableFlat,
135
+ getTables = _ref2.getTables,
136
+ getColumns = _ref2.getColumns,
137
+ defaultAvailableTables = _ref2.defaultAvailableTables,
138
+ openTablePopup = _ref2.openTablePopup,
139
+ closeTablePopup = _ref2.closeTablePopup,
140
+ onPreviewFormula = _ref2.onPreviewFormula;
141
+ var _useState = (0, _react.useState)(''),
142
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
143
+ input = _useState2[0],
144
+ setInput = _useState2[1];
145
+ var _useState3 = (0, _react.useState)(false),
146
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
147
+ loading = _useState4[0],
148
+ setLoading = _useState4[1];
149
+ var _useState5 = (0, _react.useState)([]),
150
+ _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
151
+ messages = _useState6[0],
152
+ setMessages = _useState6[1];
153
+ var _useState7 = (0, _react.useState)([]),
154
+ _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
155
+ tableScope = _useState8[0],
156
+ setTableScope = _useState8[1];
157
+ var _useState9 = (0, _react.useState)(sourceTable || []),
158
+ _useState0 = (0, _slicedToArray2["default"])(_useState9, 2),
159
+ scopeSourceTable = _useState0[0],
160
+ setScopeSourceTable = _useState0[1];
161
+ var _useState1 = (0, _react.useState)(false),
162
+ _useState10 = (0, _slicedToArray2["default"])(_useState1, 2),
163
+ scopeLoading = _useState10[0],
164
+ setScopeLoading = _useState10[1];
165
+ var _useState11 = (0, _react.useState)(false),
166
+ _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
167
+ scopeExpanded = _useState12[0],
168
+ setScopeExpanded = _useState12[1];
169
+ var fixedTableScope = (0, _react.useMemo)(function () {
170
+ return (defaultAvailableTables || []).map(function (table) {
171
+ return tableToScopeItem(table, true);
172
+ });
173
+ }, [defaultAvailableTables]);
174
+ var mergedTableScope = (0, _react.useMemo)(function () {
175
+ var map = new Map();
176
+ fixedTableScope.forEach(function (item) {
177
+ return map.set(getScopeKey(item), item);
178
+ });
179
+ tableScope.forEach(function (item) {
180
+ return map.set(getScopeKey(item), item);
181
+ });
182
+ return Array.from(map.values());
183
+ }, [fixedTableScope, tableScope]);
184
+ var messagesRef = (0, _react.useRef)(null);
185
+ var inputRef = (0, _react.useRef)(null);
186
+ var abortControllerRef = (0, _react.useRef)(null);
187
+ var cancelByUserRef = (0, _react.useRef)(false);
188
+ var tableScopeRef = (0, _react.useRef)([]);
189
+ var focusInput = function focusInput() {
190
+ window.requestAnimationFrame(function () {
191
+ window.setTimeout(function () {
192
+ var _inputNode$resizableT, _inputNode$resizableT2, _inputNode$textarea, _inputNode$textarea$f;
193
+ var inputNode = inputRef.current;
194
+ if (typeof (inputNode === null || inputNode === void 0 ? void 0 : inputNode.focus) === 'function') {
195
+ inputNode.focus();
196
+ return;
197
+ }
198
+ inputNode === null || inputNode === void 0 || (_inputNode$resizableT = inputNode.resizableTextArea) === null || _inputNode$resizableT === void 0 || (_inputNode$resizableT = _inputNode$resizableT.textArea) === null || _inputNode$resizableT === void 0 || (_inputNode$resizableT2 = _inputNode$resizableT.focus) === null || _inputNode$resizableT2 === void 0 || _inputNode$resizableT2.call(_inputNode$resizableT);
199
+ inputNode === null || inputNode === void 0 || (_inputNode$textarea = inputNode.textarea) === null || _inputNode$textarea === void 0 || (_inputNode$textarea$f = _inputNode$textarea.focus) === null || _inputNode$textarea$f === void 0 || _inputNode$textarea$f.call(_inputNode$textarea);
200
+ }, 0);
201
+ });
202
+ };
203
+ (0, _react.useEffect)(function () {
204
+ tableScopeRef.current = mergedTableScope;
205
+ }, [mergedTableScope]);
206
+ (0, _react.useEffect)(function () {
207
+ setScopeSourceTable(sourceTable || []);
208
+ }, [sourceTable]);
209
+ (0, _react.useEffect)(function () {
210
+ requestAnimationFrame(function () {
211
+ if (!messagesRef.current) return;
212
+ messagesRef.current.scrollTop = messagesRef.current.scrollHeight;
213
+ });
214
+ }, [messages]);
215
+ (0, _react.useEffect)(function () {
216
+ focusInput();
217
+ return function () {
218
+ var _abortControllerRef$c;
219
+ (_abortControllerRef$c = abortControllerRef.current) === null || _abortControllerRef$c === void 0 || _abortControllerRef$c.abort();
220
+ };
221
+ }, []);
222
+ var getChatMessages = function getChatMessages() {
223
+ var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : messages;
224
+ return list.filter(function (item) {
225
+ return !item.status;
226
+ }).map(function (item) {
227
+ var _item$parseResult;
228
+ return {
229
+ role: item.role,
230
+ content: [item.content, (_item$parseResult = item.parseResult) !== null && _item$parseResult !== void 0 && (_item$parseResult = _item$parseResult.formulaList) !== null && _item$parseResult !== void 0 && _item$parseResult.length ? "\n\n[\u5DF2\u751F\u6210\u914D\u7F6E]\n".concat(JSON.stringify({
231
+ content: item.parseResult.content,
232
+ name: item.parseResult.name,
233
+ formulaList: item.parseResult.formulaList
234
+ })) : ''].filter(Boolean).join('')
235
+ };
236
+ });
237
+ };
238
+ var addTableScope = function addTableScope(record) {
239
+ var nextItem = tableToScopeItem(record);
240
+ var key = getScopeKey(nextItem);
241
+ setTableScope(function (list) {
242
+ if (fixedTableScope.some(function (item) {
243
+ return getScopeKey(item) === key;
244
+ })) {
245
+ return list;
246
+ }
247
+ if (list.some(function (item) {
248
+ return getScopeKey(item) === key;
249
+ })) {
250
+ return list.filter(function (item) {
251
+ return getScopeKey(item) !== key;
252
+ });
253
+ }
254
+ return [].concat((0, _toConsumableArray2["default"])(list), [nextItem]);
255
+ });
256
+ };
257
+ var removeTableScope = function removeTableScope(target) {
258
+ var key = getScopeKey(target);
259
+ setTableScope(function (list) {
260
+ return list.filter(function (item) {
261
+ return getScopeKey(item) !== key;
262
+ });
263
+ });
264
+ };
265
+ var resolveAvailableTables = function () {
266
+ var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2() {
267
+ var scope, result;
268
+ return _regenerator["default"].wrap(function (_context2) {
269
+ while (1) switch (_context2.prev = _context2.next) {
270
+ case 0:
271
+ scope = tableScopeRef.current;
272
+ if (scope.length) {
273
+ _context2.next = 1;
274
+ break;
275
+ }
276
+ return _context2.abrupt("return", defaultAvailableTables || []);
277
+ case 1:
278
+ _context2.next = 2;
279
+ return Promise.all(scope.map(function () {
280
+ var _ref4 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(item) {
281
+ var _fixedTable$columns;
282
+ var fixedTable, sourceTables, table, columns, _t, _t2;
283
+ return _regenerator["default"].wrap(function (_context) {
284
+ while (1) switch (_context.prev = _context.next) {
285
+ case 0:
286
+ fixedTable = (defaultAvailableTables || []).find(function (table) {
287
+ return getScopeKey(tableToScopeItem(table, true)) === getScopeKey(item);
288
+ });
289
+ if (!(fixedTable !== null && fixedTable !== void 0 && (_fixedTable$columns = fixedTable.columns) !== null && _fixedTable$columns !== void 0 && _fixedTable$columns.length)) {
290
+ _context.next = 1;
291
+ break;
292
+ }
293
+ return _context.abrupt("return", fixedTable);
294
+ case 1:
295
+ _context.next = 2;
296
+ return getTables === null || getTables === void 0 ? void 0 : getTables(item.datasourceId);
297
+ case 2:
298
+ _t = _context.sent;
299
+ if (_t) {
300
+ _context.next = 3;
301
+ break;
302
+ }
303
+ _t = [];
304
+ case 3:
305
+ sourceTables = _t;
306
+ table = sourceTables.find(function (current) {
307
+ return "".concat(current.id || current.tableId || current.name) === "".concat(item.tableId);
308
+ }) || {
309
+ id: item.tableId,
310
+ name: item.tableName || item.tableId,
311
+ name_zh: item.tableNameZh || item.tableName || item.tableId,
312
+ alias: item.tableAlias,
313
+ tableUuid: item.tableUuid,
314
+ datasourceId: item.datasourceId,
315
+ datasourceName: item.datasourceName
316
+ };
317
+ _context.next = 4;
318
+ return getColumns === null || getColumns === void 0 ? void 0 : getColumns(table, item.datasourceId);
319
+ case 4:
320
+ _t2 = _context.sent;
321
+ if (_t2) {
322
+ _context.next = 5;
323
+ break;
324
+ }
325
+ _t2 = [];
326
+ case 5:
327
+ columns = _t2;
328
+ return _context.abrupt("return", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, table), {}, {
329
+ id: table.id || item.tableId,
330
+ name: table.name || item.tableName,
331
+ name_zh: table.name_zh || item.tableNameZh,
332
+ table: table.name || item.tableName,
333
+ tableId: table.id || item.tableId,
334
+ alias: table.alias || item.tableAlias,
335
+ tableUuid: table.tableUuid || item.tableUuid,
336
+ datasourceId: item.datasourceId,
337
+ datasourceName: item.datasourceName,
338
+ columns: Array.isArray(columns) ? columns : []
339
+ }));
340
+ case 6:
341
+ case "end":
342
+ return _context.stop();
343
+ }
344
+ }, _callee);
345
+ }));
346
+ return function (_x) {
347
+ return _ref4.apply(this, arguments);
348
+ };
349
+ }()));
350
+ case 2:
351
+ result = _context2.sent;
352
+ return _context2.abrupt("return", result.filter(function (item) {
353
+ return (item === null || item === void 0 ? void 0 : item.id) || (item === null || item === void 0 ? void 0 : item.name);
354
+ }));
355
+ case 3:
356
+ case "end":
357
+ return _context2.stop();
358
+ }
359
+ }, _callee2);
360
+ }));
361
+ return function resolveAvailableTables() {
362
+ return _ref3.apply(this, arguments);
363
+ };
364
+ }();
365
+ var submit = function () {
366
+ var _ref5 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3() {
367
+ var sql, now, assistantId, userMessage, loadingMessage, nextMessages, rawText, errorContext, result, availableTables, scopedTableScope, controller, _applyResult, aborted, errorMessage, assistantErrorContent, _t3, _t4, _t5;
368
+ return _regenerator["default"].wrap(function (_context3) {
369
+ while (1) switch (_context3.prev = _context3.next) {
370
+ case 0:
371
+ sql = input.trim();
372
+ if (!(!sql || loading)) {
373
+ _context3.next = 1;
374
+ break;
375
+ }
376
+ return _context3.abrupt("return");
377
+ case 1:
378
+ now = Date.now();
379
+ assistantId = "assistant-".concat(now);
380
+ userMessage = {
381
+ id: "user-".concat(now),
382
+ role: 'user',
383
+ content: sql
384
+ };
385
+ loadingMessage = {
386
+ id: assistantId,
387
+ role: 'assistant',
388
+ content: (0, _locale.__)('customColumn.sqlChatThinking'),
389
+ status: 'loading'
390
+ };
391
+ nextMessages = [].concat((0, _toConsumableArray2["default"])(messages), [userMessage]);
392
+ setMessages([].concat((0, _toConsumableArray2["default"])(nextMessages), [loadingMessage]));
393
+ setInput('');
394
+ setLoading(true);
395
+ rawText = '';
396
+ errorContext = '';
397
+ _context3.prev = 2;
398
+ _context3.next = 3;
399
+ return resolveAvailableTables();
400
+ case 3:
401
+ availableTables = _context3.sent;
402
+ scopedTableScope = tableScopeRef.current;
403
+ if (!(typeof streamParser === 'function')) {
404
+ _context3.next = 11;
405
+ break;
406
+ }
407
+ controller = new AbortController();
408
+ abortControllerRef.current = controller;
409
+ cancelByUserRef.current = false;
410
+ _context3.prev = 4;
411
+ _context3.next = 5;
412
+ return streamParser({
413
+ sql: sql,
414
+ messages: getChatMessages(nextMessages),
415
+ availableTables: availableTables,
416
+ tableScope: scopedTableScope
417
+ }, {
418
+ signal: controller.signal,
419
+ onDelta: function onDelta(delta) {
420
+ rawText += delta || '';
421
+ var content = extractJsonStringValue(rawText, 'content') || (0, _locale.__)('customColumn.sqlChatThinking');
422
+ var generatingConfig = /"formulaList"\s*:/.test(rawText);
423
+ setMessages(function (list) {
424
+ return list.map(function (item) {
425
+ return item.id === assistantId ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
426
+ content: generatingConfig && !content ? (0, _locale.__)('customColumn.sqlChatGeneratingConfig') : content,
427
+ status: generatingConfig ? undefined : 'loading',
428
+ generatingConfig: generatingConfig
429
+ }) : item;
430
+ });
431
+ });
432
+ }
433
+ });
434
+ case 5:
435
+ result = _context3.sent;
436
+ _context3.next = 7;
437
+ break;
438
+ case 6:
439
+ _context3.prev = 6;
440
+ _t3 = _context3["catch"](4);
441
+ errorContext = (_t3 === null || _t3 === void 0 ? void 0 : _t3.message) || '';
442
+ throw _t3;
443
+ case 7:
444
+ if (result) {
445
+ _context3.next = 10;
446
+ break;
447
+ }
448
+ _context3.prev = 8;
449
+ result = parseFormulaSqlStreamText(rawText);
450
+ _context3.next = 10;
451
+ break;
452
+ case 9:
453
+ _context3.prev = 9;
454
+ _t4 = _context3["catch"](8);
455
+ errorContext = errorContext || (_t4 === null || _t4 === void 0 ? void 0 : _t4.message) || '';
456
+ throw _t4;
457
+ case 10:
458
+ _context3.next = 13;
459
+ break;
460
+ case 11:
461
+ _context3.next = 12;
462
+ return onSubmit(sql, availableTables, scopedTableScope);
463
+ case 12:
464
+ _applyResult = _context3.sent;
465
+ result = typeof _applyResult === 'function' ? {
466
+ formulaList: [],
467
+ applyAction: _applyResult
468
+ } : undefined;
469
+ case 13:
470
+ setMessages(function (list) {
471
+ return list.map(function (item) {
472
+ var _result;
473
+ return item.id === assistantId ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
474
+ role: 'assistant',
475
+ content: result ? result.content || (0, _locale.__)('customColumn.sqlChatSuccess') : (0, _locale.__)('customColumn.sqlChatSuccessApplied'),
476
+ status: undefined,
477
+ parseResult: result,
478
+ applyAction: (_result = result) === null || _result === void 0 ? void 0 : _result.applyAction,
479
+ generatingConfig: false
480
+ }) : item;
481
+ });
482
+ });
483
+ _context3.next = 15;
484
+ break;
485
+ case 14:
486
+ _context3.prev = 14;
487
+ _t5 = _context3["catch"](2);
488
+ aborted = (_t5 === null || _t5 === void 0 ? void 0 : _t5.name) === 'AbortError';
489
+ errorMessage = aborted && cancelByUserRef.current ? (0, _locale.__)('customColumn.sqlChatCanceled') : (_t5 === null || _t5 === void 0 ? void 0 : _t5.message) || (0, _locale.__)('customColumn.sqlParseFailed');
490
+ assistantErrorContent = [errorMessage, rawText ? "\n\n[AI \u539F\u59CB\u8FD4\u56DE]\n".concat(rawText) : '', errorContext && errorContext !== errorMessage ? "\n\n[\u89E3\u6790\u5931\u8D25\u539F\u56E0]\n".concat(errorContext) : ''].filter(Boolean).join('');
491
+ setMessages(function (list) {
492
+ return list.map(function (item) {
493
+ return item.id === assistantId ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
494
+ role: 'assistant',
495
+ content: assistantErrorContent,
496
+ status: undefined,
497
+ generatingConfig: false
498
+ }) : item;
499
+ });
500
+ });
501
+ case 15:
502
+ _context3.prev = 15;
503
+ abortControllerRef.current = null;
504
+ setLoading(false);
505
+ focusInput();
506
+ return _context3.finish(15);
507
+ case 16:
508
+ case "end":
509
+ return _context3.stop();
510
+ }
511
+ }, _callee3, null, [[2, 14, 15, 16], [4, 6], [8, 9]]);
512
+ }));
513
+ return function submit() {
514
+ return _ref5.apply(this, arguments);
515
+ };
516
+ }();
517
+ var applyResult = function () {
518
+ var _ref6 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4(message) {
519
+ var apply;
520
+ return _regenerator["default"].wrap(function (_context4) {
521
+ while (1) switch (_context4.prev = _context4.next) {
522
+ case 0:
523
+ if (!(!message.parseResult && !message.applyAction)) {
524
+ _context4.next = 1;
525
+ break;
526
+ }
527
+ _pandora.Toast.warning((0, _locale.__)('customColumn.sqlParseInvalid'));
528
+ return _context4.abrupt("return");
529
+ case 1:
530
+ if (!message.applyAction) {
531
+ _context4.next = 2;
532
+ break;
533
+ }
534
+ message.applyAction();
535
+ _context4.next = 4;
536
+ break;
537
+ case 2:
538
+ if (!(message.parseResult && Array.isArray(message.parseResult.formulaList) && message.parseResult.formulaList.length)) {
539
+ _context4.next = 4;
540
+ break;
541
+ }
542
+ _context4.next = 3;
543
+ return onSubmit(message.parseResult);
544
+ case 3:
545
+ apply = _context4.sent;
546
+ if (typeof apply === 'function') {
547
+ apply();
548
+ }
549
+ case 4:
550
+ _context4.next = 5;
551
+ return new Promise(function (resolve) {
552
+ return window.requestAnimationFrame(function () {
553
+ return resolve();
554
+ });
555
+ });
556
+ case 5:
557
+ onClose();
558
+ case 6:
559
+ case "end":
560
+ return _context4.stop();
561
+ }
562
+ }, _callee4);
563
+ }));
564
+ return function applyResult(_x2) {
565
+ return _ref6.apply(this, arguments);
566
+ };
567
+ }();
568
+ var showAddTable = function () {
569
+ var _ref7 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee6(event) {
570
+ var triggerNode, nextSourceTable;
571
+ return _regenerator["default"].wrap(function (_context6) {
572
+ while (1) switch (_context6.prev = _context6.next) {
573
+ case 0:
574
+ if (!scopeLoading) {
575
+ _context6.next = 1;
576
+ break;
577
+ }
578
+ return _context6.abrupt("return");
579
+ case 1:
580
+ triggerNode = event.currentTarget;
581
+ nextSourceTable = scopeSourceTable;
582
+ if (!(!nextSourceTable.length && Array.isArray(datasource) && datasource.length)) {
583
+ _context6.next = 5;
584
+ break;
585
+ }
586
+ setScopeLoading(true);
587
+ _context6.prev = 2;
588
+ _context6.next = 3;
589
+ return Promise.all(datasource.map(function () {
590
+ var _ref8 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5(item) {
591
+ var _t6, _t7, _t8, _t9, _t0;
592
+ return _regenerator["default"].wrap(function (_context5) {
593
+ while (1) switch (_context5.prev = _context5.next) {
594
+ case 0:
595
+ _t6 = _objectSpread2["default"];
596
+ _t7 = (0, _objectSpread2["default"])({}, item);
597
+ _t8 = {};
598
+ _context5.next = 1;
599
+ return getTables === null || getTables === void 0 ? void 0 : getTables(item.datasourceId);
600
+ case 1:
601
+ _t9 = _context5.sent;
602
+ if (_t9) {
603
+ _context5.next = 2;
604
+ break;
605
+ }
606
+ _t9 = [];
607
+ case 2:
608
+ _t0 = _t9.map(function (table) {
609
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, table), {}, {
610
+ datasourceId: item.datasourceId,
611
+ datasourceName: item.datasourceName
612
+ });
613
+ });
614
+ return _context5.abrupt("return", _t6(_t7, _t8, {
615
+ children: _t0
616
+ }));
617
+ case 3:
618
+ case "end":
619
+ return _context5.stop();
620
+ }
621
+ }, _callee5);
622
+ }));
623
+ return function (_x4) {
624
+ return _ref8.apply(this, arguments);
625
+ };
626
+ }()));
627
+ case 3:
628
+ nextSourceTable = _context6.sent;
629
+ setScopeSourceTable(nextSourceTable);
630
+ case 4:
631
+ _context6.prev = 4;
632
+ setScopeLoading(false);
633
+ return _context6.finish(4);
634
+ case 5:
635
+ openTablePopup === null || openTablePopup === void 0 || openTablePopup(triggerNode, (0, _jsxRuntime.jsx)(_dialog.SelectTable, {
636
+ data: datasource || [],
637
+ sourceTable: nextSourceTable || [],
638
+ tableFlat: tableFlat,
639
+ multiple: true,
640
+ lockedValues: fixedTableScope.map(scopeItemToTableValue),
641
+ selectedValues: mergedTableScope.map(scopeItemToTableValue),
642
+ value: {
643
+ datasourceId: '',
644
+ datasourceName: '',
645
+ name: '',
646
+ name_zh: '',
647
+ tableUuid: '',
648
+ id: '',
649
+ alias: ''
650
+ },
651
+ onChange: addTableScope
652
+ }));
653
+ case 6:
654
+ case "end":
655
+ return _context6.stop();
656
+ }
657
+ }, _callee6, null, [[2,, 4, 5]]);
658
+ }));
659
+ return function showAddTable(_x3) {
660
+ return _ref7.apply(this, arguments);
661
+ };
662
+ }();
663
+ return (0, _jsxRuntime.jsxs)("div", {
664
+ className: 'Sqb-FormulaSqlImport',
665
+ children: [(0, _jsxRuntime.jsxs)("div", {
666
+ className: 'Sqb-FormulaSqlImport-header',
667
+ children: [(0, _jsxRuntime.jsx)("div", {
668
+ className: 'Sqb-FormulaSqlImport-title',
669
+ children: (0, _locale.__)('customColumn.sqlChatTitle')
670
+ }), (0, _jsxRuntime.jsx)("div", {
671
+ className: 'Sqb-FormulaSqlImport-desc',
672
+ children: (0, _locale.__)('customColumn.sqlChatDesc')
673
+ })]
674
+ }), (0, _jsxRuntime.jsxs)("div", {
675
+ className: 'Sqb-FormulaSqlImport-scope',
676
+ children: [(0, _jsxRuntime.jsxs)("div", {
677
+ className: 'Sqb-FormulaSqlImport-scopeHeader',
678
+ children: [(0, _jsxRuntime.jsx)("span", {
679
+ children: (0, _locale.__)('customColumn.sqlChatTableScope')
680
+ }), (0, _jsxRuntime.jsx)("button", {
681
+ type: 'button',
682
+ className: 'Sqb-FormulaSqlImport-addTable',
683
+ disabled: scopeLoading,
684
+ onClick: showAddTable,
685
+ children: (0, _jsxRuntime.jsx)(_icons.AddIcon, {
686
+ width: 16,
687
+ height: 16
688
+ })
689
+ })]
690
+ }), (0, _jsxRuntime.jsx)("div", {
691
+ className: (0, _classnames["default"])('Sqb-FormulaSqlImport-scopeSelected', {
692
+ 'Sqb-FormulaSqlImport-scopeSelected--expanded': scopeExpanded
693
+ }),
694
+ children: mergedTableScope.length ? mergedTableScope.map(function (item) {
695
+ return (0, _jsxRuntime.jsxs)("button", {
696
+ type: 'button',
697
+ className: (0, _classnames["default"])('Sqb-FormulaSqlImport-scopeTag', {
698
+ 'Sqb-FormulaSqlImport-scopeTag--fixed': item.fixed
699
+ }),
700
+ onClick: function onClick() {
701
+ if (!item.fixed) removeTableScope(item);
702
+ },
703
+ children: [(0, _jsxRuntime.jsxs)("span", {
704
+ children: [item.datasourceName ? "".concat(item.datasourceName, ".") : '', item.tableNameZh || item.tableName || item.tableId, item.tableAlias ? "(".concat(item.tableAlias, ")") : '']
705
+ }), !item.fixed ? (0, _jsxRuntime.jsx)("span", {
706
+ className: 'Sqb-FormulaSqlImport-scopeTagClose',
707
+ children: "\xD7"
708
+ }) : null]
709
+ }, getScopeKey(item));
710
+ }) : (0, _jsxRuntime.jsx)("span", {
711
+ className: 'Sqb-FormulaSqlImport-scopeHint',
712
+ children: (0, _locale.__)('customColumn.sqlChatScopeFallback')
713
+ })
714
+ }), mergedTableScope.length > 1 ? (0, _jsxRuntime.jsx)(_pandora.Button, {
715
+ type: 'link',
716
+ className: 'Sqb-FormulaSqlImport-scopeToggle',
717
+ title: scopeExpanded ? '收起表范围' : '展开表范围',
718
+ onClick: function onClick() {
719
+ return setScopeExpanded(function (value) {
720
+ return !value;
721
+ });
722
+ },
723
+ children: scopeExpanded ? '收起' : '展开'
724
+ }) : null]
725
+ }), (0, _jsxRuntime.jsx)("div", {
726
+ className: 'Sqb-FormulaSqlImport-messages',
727
+ ref: messagesRef,
728
+ children: messages.length ? messages.map(function (message) {
729
+ var _message$parseResult;
730
+ var isAssistant = message.role === 'assistant';
731
+ return (0, _jsxRuntime.jsxs)("div", {
732
+ className: "Sqb-FormulaSqlImport-message Sqb-FormulaSqlImport-message--".concat(message.role),
733
+ children: [(0, _jsxRuntime.jsx)("div", {
734
+ className: 'Sqb-FormulaSqlImport-avatar',
735
+ children: isAssistant ? 'AI' : (0, _locale.__)('customColumn.sqlChatMe')
736
+ }), (0, _jsxRuntime.jsxs)("div", {
737
+ className: 'Sqb-FormulaSqlImport-bubble',
738
+ children: [(0, _jsxRuntime.jsx)("div", {
739
+ className: 'Sqb-FormulaSqlImport-messageText',
740
+ children: message.status === 'loading' ? (0, _jsxRuntime.jsx)("span", {
741
+ className: 'Sqb-FormulaSqlImport-loading',
742
+ children: message.content
743
+ }) : message.content
744
+ }), message.generatingConfig ? (0, _jsxRuntime.jsx)("div", {
745
+ className: 'Sqb-FormulaSqlImport-status',
746
+ children: (0, _locale.__)('customColumn.sqlChatGeneratingConfig')
747
+ }) : null, message.parseResult || message.applyAction ? (0, _jsxRuntime.jsxs)("div", {
748
+ className: 'Sqb-FormulaSqlImport-proposal',
749
+ children: [(_message$parseResult = message.parseResult) !== null && _message$parseResult !== void 0 && (_message$parseResult = _message$parseResult.formulaList) !== null && _message$parseResult !== void 0 && _message$parseResult.length ? (0, _jsxRuntime.jsx)(_pandora.Button, {
750
+ size: 'small',
751
+ onClick: function onClick() {
752
+ return onPreviewFormula === null || onPreviewFormula === void 0 ? void 0 : onPreviewFormula(message.parseResult);
753
+ },
754
+ children: (0, _locale.__)('customColumn.sqlChatPreview')
755
+ }) : null, (0, _jsxRuntime.jsx)(_pandora.Button, {
756
+ size: 'small',
757
+ primary: true,
758
+ onClick: function onClick() {
759
+ return applyResult(message);
760
+ },
761
+ children: (0, _locale.__)('customColumn.sqlChatApply')
762
+ })]
763
+ }) : null]
764
+ })]
765
+ }, message.id);
766
+ }) : (0, _jsxRuntime.jsx)("div", {
767
+ className: 'Sqb-FormulaSqlImport-empty',
768
+ children: (0, _locale.__)('customColumn.sqlChatEmpty')
769
+ })
770
+ }), (0, _jsxRuntime.jsxs)("div", {
771
+ className: 'Sqb-FormulaSqlImport-composer',
772
+ children: [(0, _jsxRuntime.jsx)(_pandora.Input.TextArea, {
773
+ ref: inputRef,
774
+ rows: 6,
775
+ value: input,
776
+ placeholder: (0, _locale.__)('customColumn.sqlChatPlaceholder'),
777
+ onChange: function onChange(value) {
778
+ setInput(value);
779
+ },
780
+ onKeyDown: function onKeyDown(event) {
781
+ if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing || event.keyCode === 229) {
782
+ return;
783
+ }
784
+ event.preventDefault();
785
+ submit();
786
+ }
787
+ }), (0, _jsxRuntime.jsx)("button", {
788
+ type: 'button',
789
+ className: 'Sqb-FormulaSqlImport-send',
790
+ disabled: loading || !input.trim(),
791
+ "aria-label": (0, _locale.__)('customColumn.sqlChatSend'),
792
+ onClick: submit,
793
+ children: (0, _jsxRuntime.jsx)(_icons.UpArrowIcon, {
794
+ width: 14,
795
+ height: 14
796
+ })
797
+ })]
798
+ })]
799
+ });
800
+ };
801
+ var parentPopupLockCounts = new WeakMap();
51
802
  var CASE_FIXED_OPERATORS = ['case', 'when', 'then', 'else', 'end'];
52
803
  var LOGIC_FIXED_OPERATORS = ['(', ')'];
53
804
  var LOGIC_REQUIRED_OPERATORS = ['(', ')'];
@@ -147,11 +898,11 @@ var getTokenStyleByClassName = function getTokenStyleByClassName(className, extr
147
898
  } : {}), extraStyle);
148
899
  };
149
900
  var FormulaList = (0, _react.forwardRef)(function (props, ref) {
150
- var _storage$_metabaseCop;
151
- var _useState = (0, _react.useState)((_storage["default"] === null || _storage["default"] === void 0 || (_storage$_metabaseCop = _storage["default"]._metabaseCopyItems) === null || _storage$_metabaseCop === void 0 ? void 0 : _storage$_metabaseCop.length) || 0),
152
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
153
- checkedItemsCount = _useState2[0],
154
- setCheckedItemsCount = _useState2[1];
901
+ var _storage$_metabaseCop, _store$preProps, _store$preProps2;
902
+ var _useState13 = (0, _react.useState)((_storage["default"] === null || _storage["default"] === void 0 || (_storage$_metabaseCop = _storage["default"]._metabaseCopyItems) === null || _storage$_metabaseCop === void 0 ? void 0 : _storage$_metabaseCop.length) || 0),
903
+ _useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
904
+ checkedItemsCount = _useState14[0],
905
+ setCheckedItemsCount = _useState14[1];
155
906
  (0, _react.useEffect)(function () {
156
907
  var _storage$_metabaseCop3;
157
908
  var handler = function handler() {
@@ -188,7 +939,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
188
939
  enableCopy = _props$enableCopy === void 0 ? true : _props$enableCopy,
189
940
  _props$enableZoom = props.enableZoom,
190
941
  enableZoom = _props$enableZoom === void 0 ? true : _props$enableZoom,
191
- parentPopupChannel = props.parentPopupChannel;
942
+ parentPopupChannel = props.parentPopupChannel,
943
+ onAddSql = props.onAddSql;
192
944
  var parentPopupLockCountRef = (0, _react.useRef)(0);
193
945
  var parentPopupUnlockTimerRef = (0, _react.useRef)(null);
194
946
  var setParentClosable = function setParentClosable(closable) {
@@ -199,6 +951,16 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
199
951
  }
200
952
  store.setClosable(closable);
201
953
  };
954
+ var changeSharedParentLockCount = function changeSharedParentLockCount(delta) {
955
+ if (!parentPopupChannel) return;
956
+ var counts = parentPopupLockCounts.get(store) || {
957
+ primary: 0,
958
+ secondary: 0
959
+ };
960
+ counts[parentPopupChannel] = Math.max(0, counts[parentPopupChannel] + delta);
961
+ parentPopupLockCounts.set(store, counts);
962
+ setParentClosable(counts[parentPopupChannel] === 0);
963
+ };
202
964
  var lockParentPopup = function lockParentPopup() {
203
965
  if (!parentPopupChannel) return;
204
966
  if (parentPopupUnlockTimerRef.current) {
@@ -206,19 +968,16 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
206
968
  parentPopupUnlockTimerRef.current = null;
207
969
  }
208
970
  parentPopupLockCountRef.current += 1;
209
- if (parentPopupLockCountRef.current === 1) {
210
- setParentClosable(false);
211
- }
971
+ changeSharedParentLockCount(1);
212
972
  };
213
973
  var unlockParentPopup = function unlockParentPopup() {
214
974
  var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
215
975
  if (!parentPopupChannel) return;
216
976
  var runUnlock = function runUnlock() {
217
977
  parentPopupUnlockTimerRef.current = null;
218
- parentPopupLockCountRef.current = Math.max(0, parentPopupLockCountRef.current - 1);
219
- if (parentPopupLockCountRef.current === 0) {
220
- setParentClosable(true);
221
- }
978
+ if (parentPopupLockCountRef.current === 0) return;
979
+ parentPopupLockCountRef.current -= 1;
980
+ changeSharedParentLockCount(-1);
222
981
  };
223
982
  if (delay > 0) {
224
983
  if (parentPopupUnlockTimerRef.current) {
@@ -268,8 +1027,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
268
1027
  parentPopupUnlockTimerRef.current = null;
269
1028
  }
270
1029
  if (parentPopupLockCountRef.current > 0) {
1030
+ changeSharedParentLockCount(-parentPopupLockCountRef.current);
271
1031
  parentPopupLockCountRef.current = 0;
272
- setParentClosable(true);
273
1032
  }
274
1033
  };
275
1034
  }, [parentPopupChannel]);
@@ -293,13 +1052,26 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
293
1052
  });
294
1053
  return map;
295
1054
  }, [otherTypes]);
296
- var normalizedValue = (0, _react.useMemo)(function () {
297
- return (0, _utils2.normalizeAndOrStructure)(value || []).map(_utils2.syncAtomQuotes);
1055
+ var normalizedStructureValue = (0, _react.useMemo)(function () {
1056
+ return (0, _utils2.normalizeAndOrStructure)(value || []);
298
1057
  }, [value]);
1058
+ var normalizedExpressionValue = (0, _react.useMemo)(function () {
1059
+ return (0, _utils3.normalizeExpressionAtoms)(normalizedStructureValue, data);
1060
+ }, [normalizedStructureValue, data]);
1061
+ var normalizedValue = (0, _react.useMemo)(function () {
1062
+ return normalizedExpressionValue.map(_utils2.syncAtomQuotes);
1063
+ }, [normalizedExpressionValue]);
299
1064
  var caseList = normalizedValue;
300
1065
  var initialValueRef = (0, _react.useRef)((0, _cloneDeep["default"])(caseList));
301
1066
  var caseListRef = (0, _react.useRef)(caseList);
302
1067
  caseListRef.current = caseList;
1068
+ (0, _react.useEffect)(function () {
1069
+ if ((0, _isEqual["default"])(normalizedExpressionValue, normalizedStructureValue)) return;
1070
+ var quotes = normalizedValue.map(function (item) {
1071
+ return (0, _utils2.getAtomDisplayText)(item);
1072
+ }).join(' ');
1073
+ onChange === null || onChange === void 0 || onChange(normalizedValue, quotes);
1074
+ }, [normalizedExpressionValue, normalizedStructureValue, normalizedValue, onChange]);
303
1075
  var hasFormulaSqlAction = Boolean(store.showFormulaSql && store.hasFormulaSqlCode);
304
1076
  var hasFormulaDiffAction = Boolean(store.showFormulaDiff && store.hasFormulaDiffCode);
305
1077
  var operatorList = (0, _react.useMemo)(function () {
@@ -308,15 +1080,15 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
308
1080
  }
309
1081
  return _utils3.operatorList;
310
1082
  }, [store.operatorList]);
311
- var _useState3 = (0, _react.useState)(false),
312
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
313
- sqlLoading = _useState4[0],
314
- setSqlLoading = _useState4[1];
315
- var _useState5 = (0, _react.useState)(false),
316
- _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
317
- diffLoading = _useState6[0],
318
- setDiffLoading = _useState6[1];
319
- var _useState7 = (0, _react.useState)(function () {
1083
+ var _useState15 = (0, _react.useState)(false),
1084
+ _useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
1085
+ sqlLoading = _useState16[0],
1086
+ setSqlLoading = _useState16[1];
1087
+ var _useState17 = (0, _react.useState)(false),
1088
+ _useState18 = (0, _slicedToArray2["default"])(_useState17, 2),
1089
+ diffLoading = _useState18[0],
1090
+ setDiffLoading = _useState18[1];
1091
+ var _useState19 = (0, _react.useState)(function () {
320
1092
  if (!enableCopy) {
321
1093
  return false;
322
1094
  }
@@ -325,25 +1097,25 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
325
1097
  }
326
1098
  return store.copyType.includes(_type);
327
1099
  }),
328
- _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
329
- isCopy = _useState8[0],
330
- setIsCopy = _useState8[1];
1100
+ _useState20 = (0, _slicedToArray2["default"])(_useState19, 2),
1101
+ isCopy = _useState20[0],
1102
+ setIsCopy = _useState20[1];
331
1103
  var formulaList = (0, _react.useMemo)(function () {
332
1104
  return (0, _utils.getObjTem)(store.formulaTemplates);
333
1105
  }, [store.formulaTemplates]);
334
- var _useState9 = (0, _react.useState)(''),
335
- _useState0 = (0, _slicedToArray2["default"])(_useState9, 2),
336
- filterVal = _useState0[0],
337
- setFilterVal = _useState0[1];
1106
+ var _useState21 = (0, _react.useState)(''),
1107
+ _useState22 = (0, _slicedToArray2["default"])(_useState21, 2),
1108
+ filterVal = _useState22[0],
1109
+ setFilterVal = _useState22[1];
338
1110
  function getSelectDisplayText(item) {
339
1111
  var displayField = item.displayField || 'value';
340
1112
  var getOptionText = function getOptionText(value) {
341
- var _ref2, _option$displayField;
1113
+ var _ref9, _option$displayField;
342
1114
  var option = (item.options || []).find(function (currentOption) {
343
1115
  return currentOption.value === value;
344
1116
  });
345
1117
  if (!option) return value || '';
346
- return String((_ref2 = (_option$displayField = option[displayField]) !== null && _option$displayField !== void 0 ? _option$displayField : option.value) !== null && _ref2 !== void 0 ? _ref2 : '');
1118
+ return String((_ref9 = (_option$displayField = option[displayField]) !== null && _option$displayField !== void 0 ? _option$displayField : option.value) !== null && _ref9 !== void 0 ? _ref9 : '');
347
1119
  };
348
1120
  if (Array.isArray(item.val)) {
349
1121
  return item.val.map(function (currentValue) {
@@ -508,8 +1280,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
508
1280
  var withSyncedQuotes = function withSyncedQuotes(item) {
509
1281
  return _withSyncedQuotesInner(item, new WeakMap());
510
1282
  };
511
- var setCaseList = function setCaseList(data) {
512
- var nextData = data.map(function (item) {
1283
+ var setCaseList = function setCaseList(atoms) {
1284
+ var nextData = (0, _utils3.normalizeExpressionAtoms)(atoms, data).map(function (item) {
513
1285
  return withSyncedQuotes(item);
514
1286
  });
515
1287
  var quotes = nextData.map(function (item) {
@@ -525,13 +1297,13 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
525
1297
  setCaseList(nextList);
526
1298
  };
527
1299
  var getFormulaSqlText = function getFormulaSqlText(result) {
528
- var _ref3, _result$sql;
1300
+ var _ref0, _result$sql;
529
1301
  if (typeof result === 'string') return result;
530
1302
  if (!result) return '';
531
- return String((_ref3 = (_result$sql = result.sql) !== null && _result$sql !== void 0 ? _result$sql : result.code) !== null && _ref3 !== void 0 ? _ref3 : '');
1303
+ return String((_ref0 = (_result$sql = result.sql) !== null && _result$sql !== void 0 ? _result$sql : result.code) !== null && _ref0 !== void 0 ? _ref0 : '');
532
1304
  };
533
1305
  var getFormulaDiffData = function getFormulaDiffData(result) {
534
- var _result$oldCode, _ref4, _result$newCode;
1306
+ var _result$oldCode, _ref1, _result$newCode;
535
1307
  if (typeof result === 'string') {
536
1308
  return {
537
1309
  oldCode: '',
@@ -546,7 +1318,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
546
1318
  }
547
1319
  return {
548
1320
  oldCode: String((_result$oldCode = result.oldCode) !== null && _result$oldCode !== void 0 ? _result$oldCode : ''),
549
- newCode: String((_ref4 = (_result$newCode = result.newCode) !== null && _result$newCode !== void 0 ? _result$newCode : result.code) !== null && _ref4 !== void 0 ? _ref4 : '')
1321
+ newCode: String((_ref1 = (_result$newCode = result.newCode) !== null && _result$newCode !== void 0 ? _result$newCode : result.code) !== null && _ref1 !== void 0 ? _ref1 : '')
550
1322
  };
551
1323
  };
552
1324
  var normalizeFormulaValueForOutput = function normalizeFormulaValueForOutput() {
@@ -561,31 +1333,97 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
561
1333
  var getInitialFormulaValue = function getInitialFormulaValue() {
562
1334
  return (0, _cloneDeep["default"])(normalizeFormulaValueForOutput(initialValueRef.current || []));
563
1335
  };
1336
+ var getMetasContext = function getMetasContext() {
1337
+ var _store$getCurrentMeta;
1338
+ return (0, _utils2.normalizeLegacySummarizeForSave)((0, _utils2.splitByUnion)(((_store$getCurrentMeta = store.getCurrentMetaList) === null || _store$getCurrentMeta === void 0 ? void 0 : _store$getCurrentMeta.call(store)) || []));
1339
+ };
1340
+ var parseFormulaSql = (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.parseFormulaSql;
1341
+ var parseFormulaSqlStream = (_store$preProps2 = store.preProps) === null || _store$preProps2 === void 0 ? void 0 : _store$preProps2.parseFormulaSqlStream;
1342
+ var resolvedAddSql = onAddSql || typeof parseFormulaSql === 'function' || typeof parseFormulaSqlStream === 'function' ? (function () {
1343
+ var _ref10 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee7(sqlOrResult, availableTables, tableScope) {
1344
+ var result;
1345
+ return _regenerator["default"].wrap(function (_context7) {
1346
+ while (1) switch (_context7.prev = _context7.next) {
1347
+ case 0:
1348
+ if (!(typeof sqlOrResult === 'string')) {
1349
+ _context7.next = 4;
1350
+ break;
1351
+ }
1352
+ if (!onAddSql) {
1353
+ _context7.next = 1;
1354
+ break;
1355
+ }
1356
+ return _context7.abrupt("return", onAddSql(sqlOrResult, availableTables, tableScope));
1357
+ case 1:
1358
+ _context7.next = 2;
1359
+ return parseFormulaSql({
1360
+ sql: sqlOrResult,
1361
+ availableTables: availableTables !== null && availableTables !== void 0 && availableTables.length ? availableTables : data,
1362
+ tableScope: tableScope,
1363
+ metasContext: getMetasContext(),
1364
+ constantList: store.constantList || [],
1365
+ formulaTemplates: store.formulaTemplates || [],
1366
+ operatorList: store.operatorList || [],
1367
+ otherTypes: otherTypes
1368
+ });
1369
+ case 2:
1370
+ result = _context7.sent;
1371
+ if (!(!result || !Array.isArray(result.formulaList))) {
1372
+ _context7.next = 3;
1373
+ break;
1374
+ }
1375
+ _pandora.Toast.warning((0, _locale.__)('customColumn.sqlParseInvalid'));
1376
+ throw new Error('INVALID_FORMULA_SQL_RESULT');
1377
+ case 3:
1378
+ return _context7.abrupt("return", function () {
1379
+ return setCaseList(result.formulaList);
1380
+ });
1381
+ case 4:
1382
+ if (!(!sqlOrResult || !Array.isArray(sqlOrResult.formulaList))) {
1383
+ _context7.next = 5;
1384
+ break;
1385
+ }
1386
+ _pandora.Toast.warning((0, _locale.__)('customColumn.sqlParseInvalid'));
1387
+ throw new Error('INVALID_FORMULA_SQL_RESULT');
1388
+ case 5:
1389
+ return _context7.abrupt("return", function () {
1390
+ return setCaseList(sqlOrResult.formulaList);
1391
+ });
1392
+ case 6:
1393
+ case "end":
1394
+ return _context7.stop();
1395
+ }
1396
+ }, _callee7);
1397
+ }));
1398
+ return function (_x5, _x6, _x7) {
1399
+ return _ref10.apply(this, arguments);
1400
+ };
1401
+ }()) : undefined;
564
1402
  var showFormulaSql = function () {
565
- var _ref5 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
566
- var result, sql, _t;
567
- return _regenerator["default"].wrap(function (_context) {
568
- while (1) switch (_context.prev = _context.next) {
1403
+ var _ref11 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee8() {
1404
+ var result, sql, _t1;
1405
+ return _regenerator["default"].wrap(function (_context8) {
1406
+ while (1) switch (_context8.prev = _context8.next) {
569
1407
  case 0:
570
1408
  if (!(!hasFormulaSqlAction || sqlLoading)) {
571
- _context.next = 1;
1409
+ _context8.next = 1;
572
1410
  break;
573
1411
  }
574
- return _context.abrupt("return");
1412
+ return _context8.abrupt("return");
575
1413
  case 1:
576
1414
  setSqlLoading(true);
577
- _context.prev = 2;
578
- _context.next = 3;
1415
+ _context8.prev = 2;
1416
+ _context8.next = 3;
579
1417
  return store.getFormulaSqlCode(getCurrentFormulaValue());
580
1418
  case 3:
581
- result = _context.sent;
1419
+ result = _context8.sent;
582
1420
  sql = getFormulaSqlText(result);
583
1421
  if (sql) {
584
- _context.next = 4;
1422
+ _context8.next = 4;
585
1423
  break;
586
1424
  }
587
1425
  _pandora.Toast.warning('暂无可展示的SQL');
588
- return _context.abrupt("return");
1426
+ return _context8.abrupt("return");
589
1427
  case 4:
590
1428
  openChildModal({
591
1429
  title: '查看SQL',
@@ -606,54 +1444,161 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
606
1444
  }),
607
1445
  onClose: function onClose() {}
608
1446
  });
609
- _context.next = 6;
1447
+ _context8.next = 6;
610
1448
  break;
611
1449
  case 5:
612
- _context.prev = 5;
613
- _t = _context["catch"](2);
1450
+ _context8.prev = 5;
1451
+ _t1 = _context8["catch"](2);
614
1452
  _pandora.Toast.error('获取SQL失败');
615
1453
  case 6:
616
- _context.prev = 6;
1454
+ _context8.prev = 6;
617
1455
  setSqlLoading(false);
618
- return _context.finish(6);
1456
+ return _context8.finish(6);
619
1457
  case 7:
620
1458
  case "end":
621
- return _context.stop();
1459
+ return _context8.stop();
622
1460
  }
623
- }, _callee, null, [[2, 5, 6, 7]]);
1461
+ }, _callee8, null, [[2, 5, 6, 7]]);
624
1462
  }));
625
1463
  return function showFormulaSql() {
626
- return _ref5.apply(this, arguments);
1464
+ return _ref11.apply(this, arguments);
627
1465
  };
628
1466
  }();
1467
+ var previewFormulaConfig = function previewFormulaConfig(result) {
1468
+ var _result$formulaList;
1469
+ if (!(result !== null && result !== void 0 && (_result$formulaList = result.formulaList) !== null && _result$formulaList !== void 0 && _result$formulaList.length)) return;
1470
+ openChildModal({
1471
+ title: (0, _locale.__)('customColumn.sqlChatPreview'),
1472
+ transparentMask: true,
1473
+ className: 'Sqb-FormulaSqlConfigPreviewModal',
1474
+ content: (0, _jsxRuntime.jsx)(_useProvider.Provider, {
1475
+ value: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, store), {}, {
1476
+ snapshotMode: true
1477
+ }),
1478
+ children: (0, _jsxRuntime.jsx)("div", {
1479
+ className: 'Sqb-FormulaSqlConfigPreview',
1480
+ children: (0, _jsxRuntime.jsx)(FormulaList, {
1481
+ value: (0, _cloneDeep["default"])(result.formulaList),
1482
+ data: data,
1483
+ exitData: exitData,
1484
+ customTypes: _customTypes,
1485
+ otherTypes: otherTypes,
1486
+ check: check,
1487
+ _type: _type,
1488
+ showPreview: false,
1489
+ enableCopy: false,
1490
+ enableZoom: false,
1491
+ onChange: function onChange() {}
1492
+ })
1493
+ })
1494
+ }),
1495
+ modalWidth: 760,
1496
+ modalHeight: 420,
1497
+ onClose: function onClose() {}
1498
+ });
1499
+ };
1500
+ var showAddSql = function showAddSql() {
1501
+ var _store$sourceTable;
1502
+ if (!resolvedAddSql) {
1503
+ _pandora.Toast.warning((0, _locale.__)('customColumn.sqlChatMissingParser'));
1504
+ return;
1505
+ }
1506
+ closePopup();
1507
+ if (!((_store$sourceTable = store.sourceTable) !== null && _store$sourceTable !== void 0 && _store$sourceTable.length)) {
1508
+ store.getSourceTable(store.sourceList || []);
1509
+ }
1510
+ var modalInstance;
1511
+ modalInstance = openChildModal({
1512
+ title: (0, _locale.__)('customColumn.addSql'),
1513
+ transparentMask: true,
1514
+ className: 'Sqb-FormulaSqlImportModal',
1515
+ content: (0, _jsxRuntime.jsx)(SqlImportContent, {
1516
+ onSubmit: resolvedAddSql,
1517
+ onClose: function onClose() {
1518
+ var _modalInstance2;
1519
+ return (_modalInstance2 = modalInstance) === null || _modalInstance2 === void 0 ? void 0 : _modalInstance2.close();
1520
+ },
1521
+ datasource: store.sourceList,
1522
+ sourceTable: store.sourceTable,
1523
+ tableFlat: store.tableFlat,
1524
+ openTablePopup: function openTablePopup(node, content) {
1525
+ store.setPopup2({
1526
+ visible: true,
1527
+ node: node,
1528
+ content: content
1529
+ });
1530
+ },
1531
+ closeTablePopup: function closeTablePopup() {
1532
+ return store.setPopup2({
1533
+ visible: false
1534
+ });
1535
+ },
1536
+ onPreviewFormula: previewFormulaConfig,
1537
+ getTables: function getTables(datasourceId) {
1538
+ return store.fetchDataset(datasourceId);
1539
+ },
1540
+ getColumns: function getColumns(table, datasourceId) {
1541
+ return new Promise(function (resolve) {
1542
+ var nextTable = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, table), {}, {
1543
+ name: table.name || table.tableName || table.id || table.tableId
1544
+ });
1545
+ store.fetchColumns(nextTable, datasourceId, [], function (columns) {
1546
+ return resolve(columns || []);
1547
+ }, false);
1548
+ });
1549
+ },
1550
+ defaultAvailableTables: data,
1551
+ streamParser: typeof parseFormulaSqlStream === 'function' ? function (_ref12, handlers) {
1552
+ var sql = _ref12.sql,
1553
+ messages = _ref12.messages,
1554
+ availableTables = _ref12.availableTables,
1555
+ tableScope = _ref12.tableScope;
1556
+ return parseFormulaSqlStream({
1557
+ sql: sql,
1558
+ messages: messages,
1559
+ availableTables: availableTables || data,
1560
+ tableScope: tableScope || [],
1561
+ metasContext: getMetasContext(),
1562
+ constantList: store.constantList || [],
1563
+ formulaTemplates: store.formulaTemplates || [],
1564
+ operatorList: store.operatorList || [],
1565
+ otherTypes: otherTypes
1566
+ }, handlers);
1567
+ } : undefined
1568
+ }),
1569
+ modalWidth: 900,
1570
+ modalHeight: 600,
1571
+ onClose: function onClose() {}
1572
+ });
1573
+ };
629
1574
  var showFormulaDiff = function () {
630
- var _ref6 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2() {
631
- var result, _getFormulaDiffData, oldCode, newCode, _t2;
632
- return _regenerator["default"].wrap(function (_context2) {
633
- while (1) switch (_context2.prev = _context2.next) {
1575
+ var _ref13 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee9() {
1576
+ var result, _getFormulaDiffData, oldCode, newCode, _t10;
1577
+ return _regenerator["default"].wrap(function (_context9) {
1578
+ while (1) switch (_context9.prev = _context9.next) {
634
1579
  case 0:
635
1580
  if (!(!hasFormulaDiffAction || diffLoading)) {
636
- _context2.next = 1;
1581
+ _context9.next = 1;
637
1582
  break;
638
1583
  }
639
- return _context2.abrupt("return");
1584
+ return _context9.abrupt("return");
640
1585
  case 1:
641
1586
  setDiffLoading(true);
642
- _context2.prev = 2;
643
- _context2.next = 3;
1587
+ _context9.prev = 2;
1588
+ _context9.next = 3;
644
1589
  return store.getFormulaDiffCode({
645
1590
  oldCode: getInitialFormulaValue(),
646
1591
  newCode: getCurrentFormulaValue()
647
1592
  });
648
1593
  case 3:
649
- result = _context2.sent;
1594
+ result = _context9.sent;
650
1595
  _getFormulaDiffData = getFormulaDiffData(result), oldCode = _getFormulaDiffData.oldCode, newCode = _getFormulaDiffData.newCode;
651
1596
  if (!(!oldCode && !newCode)) {
652
- _context2.next = 4;
1597
+ _context9.next = 4;
653
1598
  break;
654
1599
  }
655
1600
  _pandora.Toast.warning('暂无可展示的对比结果');
656
- return _context2.abrupt("return");
1601
+ return _context9.abrupt("return");
657
1602
  case 4:
658
1603
  openChildModal({
659
1604
  title: '对比结果',
@@ -664,24 +1609,24 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
664
1609
  }),
665
1610
  onClose: function onClose() {}
666
1611
  });
667
- _context2.next = 6;
1612
+ _context9.next = 6;
668
1613
  break;
669
1614
  case 5:
670
- _context2.prev = 5;
671
- _t2 = _context2["catch"](2);
1615
+ _context9.prev = 5;
1616
+ _t10 = _context9["catch"](2);
672
1617
  _pandora.Toast.error('获取对比结果失败');
673
1618
  case 6:
674
- _context2.prev = 6;
1619
+ _context9.prev = 6;
675
1620
  setDiffLoading(false);
676
- return _context2.finish(6);
1621
+ return _context9.finish(6);
677
1622
  case 7:
678
1623
  case "end":
679
- return _context2.stop();
1624
+ return _context9.stop();
680
1625
  }
681
- }, _callee2, null, [[2, 5, 6, 7]]);
1626
+ }, _callee9, null, [[2, 5, 6, 7]]);
682
1627
  }));
683
1628
  return function showFormulaDiff() {
684
- return _ref6.apply(this, arguments);
1629
+ return _ref13.apply(this, arguments);
685
1630
  };
686
1631
  }();
687
1632
  var renderTokenContent = function renderTokenContent(children) {
@@ -696,23 +1641,23 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
696
1641
  var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
697
1642
  var modalInstance;
698
1643
  var CaseWhenZoomEditor = function CaseWhenZoomEditor() {
699
- var _useState1 = (0, _react.useState)(function () {
1644
+ var _useState23 = (0, _react.useState)(function () {
700
1645
  return (0, _cloneDeep["default"])(value);
701
1646
  }),
702
- _useState10 = (0, _slicedToArray2["default"])(_useState1, 2),
703
- draftValue = _useState10[0],
704
- setDraftValue = _useState10[1];
705
- var _useState11 = (0, _react.useState)(null),
706
- _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
707
- activeZoomRegionKey = _useState12[0],
708
- setActiveZoomRegionKey = _useState12[1];
1647
+ _useState24 = (0, _slicedToArray2["default"])(_useState23, 2),
1648
+ draftValue = _useState24[0],
1649
+ setDraftValue = _useState24[1];
1650
+ var _useState25 = (0, _react.useState)(null),
1651
+ _useState26 = (0, _slicedToArray2["default"])(_useState25, 2),
1652
+ activeZoomRegionKey = _useState26[0],
1653
+ setActiveZoomRegionKey = _useState26[1];
709
1654
  var updateDraftValue = function updateDraftValue(nextValue) {
710
1655
  setDraftValue(withSyncedQuotes(nextValue));
711
1656
  };
712
1657
  var handleOk = function handleOk() {
713
- var _modalInstance2, _modalInstance2$close;
1658
+ var _modalInstance3, _modalInstance3$close;
714
1659
  updateAtomAt(index, (0, _cloneDeep["default"])(draftValue));
715
- (_modalInstance2 = modalInstance) === null || _modalInstance2 === void 0 || (_modalInstance2$close = _modalInstance2.close) === null || _modalInstance2$close === void 0 || _modalInstance2$close.call(_modalInstance2);
1660
+ (_modalInstance3 = modalInstance) === null || _modalInstance3 === void 0 || (_modalInstance3$close = _modalInstance3.close) === null || _modalInstance3$close === void 0 || _modalInstance3$close.call(_modalInstance3);
716
1661
  };
717
1662
  return (0, _jsxRuntime.jsx)(_useProvider.Provider, {
718
1663
  value: store,
@@ -828,8 +1773,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
828
1773
  className: 'sqb-formula-list-zoom-editor-cancel',
829
1774
  style: ZOOM_FOOTER_CANCEL_STYLE,
830
1775
  onClick: function onClick() {
831
- var _modalInstance3, _modalInstance3$close;
832
- return (_modalInstance3 = modalInstance) === null || _modalInstance3 === void 0 || (_modalInstance3$close = _modalInstance3.close) === null || _modalInstance3$close === void 0 ? void 0 : _modalInstance3$close.call(_modalInstance3);
1776
+ var _modalInstance4, _modalInstance4$close;
1777
+ return (_modalInstance4 = modalInstance) === null || _modalInstance4 === void 0 || (_modalInstance4$close = _modalInstance4.close) === null || _modalInstance4$close === void 0 ? void 0 : _modalInstance4$close.call(_modalInstance4);
833
1778
  },
834
1779
  children: "\u53D6\u6D88"
835
1780
  }), (0, _jsxRuntime.jsx)(_pandora.Button, {
@@ -860,21 +1805,21 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
860
1805
  var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
861
1806
  var modalInstance;
862
1807
  var FormulaListZoomEditor = function FormulaListZoomEditor() {
863
- var _useState13 = (0, _react.useState)(function () {
1808
+ var _useState27 = (0, _react.useState)(function () {
864
1809
  return (0, _cloneDeep["default"])(caseList || []);
865
1810
  }),
866
- _useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
867
- draftList = _useState14[0],
868
- setDraftList = _useState14[1];
1811
+ _useState28 = (0, _slicedToArray2["default"])(_useState27, 2),
1812
+ draftList = _useState28[0],
1813
+ setDraftList = _useState28[1];
869
1814
  var updateDraftList = function updateDraftList(nextList) {
870
1815
  setDraftList(nextList.map(function (item) {
871
1816
  return withSyncedQuotes(item);
872
1817
  }));
873
1818
  };
874
1819
  var handleOk = function handleOk() {
875
- var _modalInstance4, _modalInstance4$close;
1820
+ var _modalInstance5, _modalInstance5$close;
876
1821
  setCaseList((0, _cloneDeep["default"])(draftList));
877
- (_modalInstance4 = modalInstance) === null || _modalInstance4 === void 0 || (_modalInstance4$close = _modalInstance4.close) === null || _modalInstance4$close === void 0 || _modalInstance4$close.call(_modalInstance4);
1822
+ (_modalInstance5 = modalInstance) === null || _modalInstance5 === void 0 || (_modalInstance5$close = _modalInstance5.close) === null || _modalInstance5$close === void 0 || _modalInstance5$close.call(_modalInstance5);
878
1823
  };
879
1824
  return (0, _jsxRuntime.jsx)(_useProvider.Provider, {
880
1825
  value: store,
@@ -906,8 +1851,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
906
1851
  className: 'sqb-formula-list-zoom-editor-cancel',
907
1852
  style: ZOOM_FOOTER_CANCEL_STYLE,
908
1853
  onClick: function onClick() {
909
- var _modalInstance5, _modalInstance5$close;
910
- return (_modalInstance5 = modalInstance) === null || _modalInstance5 === void 0 || (_modalInstance5$close = _modalInstance5.close) === null || _modalInstance5$close === void 0 ? void 0 : _modalInstance5$close.call(_modalInstance5);
1854
+ var _modalInstance6, _modalInstance6$close;
1855
+ return (_modalInstance6 = modalInstance) === null || _modalInstance6 === void 0 || (_modalInstance6$close = _modalInstance6.close) === null || _modalInstance6$close === void 0 ? void 0 : _modalInstance6$close.call(_modalInstance6);
911
1856
  },
912
1857
  children: "\u53D6\u6D88"
913
1858
  }), (0, _jsxRuntime.jsx)(_pandora.Button, {
@@ -1140,43 +2085,43 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1140
2085
  }
1141
2086
  });
1142
2087
  };
1143
- var _useState15 = (0, _react.useState)(-1),
1144
- _useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
1145
- ind = _useState16[0],
1146
- setInd = _useState16[1];
2088
+ var _useState29 = (0, _react.useState)(-1),
2089
+ _useState30 = (0, _slicedToArray2["default"])(_useState29, 2),
2090
+ ind = _useState30[0],
2091
+ setInd = _useState30[1];
1147
2092
  var filterCustomType = store.filterCustomType;
1148
2093
  var _ref = (0, _react.useRef)(null);
1149
- var _useState17 = (0, _react.useState)({
2094
+ var _useState31 = (0, _react.useState)({
1150
2095
  isError: false
1151
2096
  }),
1152
- _useState18 = (0, _slicedToArray2["default"])(_useState17, 2),
1153
- errorInfo = _useState18[0],
1154
- setErrorInfo = _useState18[1];
1155
- var _useState19 = (0, _react.useState)(false),
1156
- _useState20 = (0, _slicedToArray2["default"])(_useState19, 2),
1157
- isCheck = _useState20[0],
1158
- setIsCheck = _useState20[1];
2097
+ _useState32 = (0, _slicedToArray2["default"])(_useState31, 2),
2098
+ errorInfo = _useState32[0],
2099
+ setErrorInfo = _useState32[1];
2100
+ var _useState33 = (0, _react.useState)(false),
2101
+ _useState34 = (0, _slicedToArray2["default"])(_useState33, 2),
2102
+ isCheck = _useState34[0],
2103
+ setIsCheck = _useState34[1];
1159
2104
  var myInstanceIdRef = (0, _react.useRef)(Math.random().toString(36).slice(2));
1160
- var _useState21 = (0, _react.useState)(null),
1161
- _useState22 = (0, _slicedToArray2["default"])(_useState21, 2),
1162
- hoveredCaseGroupKey = _useState22[0],
1163
- setHoveredCaseGroupKey = _useState22[1];
1164
- var _useState23 = (0, _react.useState)(!!window.__sqb_selection_active__),
1165
- _useState24 = (0, _slicedToArray2["default"])(_useState23, 2),
1166
- globalSelectionActive = _useState24[0],
1167
- setGlobalSelectionActive = _useState24[1];
1168
- var _useState25 = (0, _react.useState)(window.__sqb_selection_owner__ || null),
1169
- _useState26 = (0, _slicedToArray2["default"])(_useState25, 2),
1170
- globalSelectionOwner = _useState26[0],
1171
- setGlobalSelectionOwner = _useState26[1];
1172
- var _useState27 = (0, _react.useState)([]),
1173
- _useState28 = (0, _slicedToArray2["default"])(_useState27, 2),
1174
- selectedIndices = _useState28[0],
1175
- setSelectedIndices = _useState28[1];
1176
- var _useState29 = (0, _react.useState)(null),
1177
- _useState30 = (0, _slicedToArray2["default"])(_useState29, 2),
1178
- hoveredCopyIndex = _useState30[0],
1179
- setHoveredCopyIndex = _useState30[1];
2105
+ var _useState35 = (0, _react.useState)(null),
2106
+ _useState36 = (0, _slicedToArray2["default"])(_useState35, 2),
2107
+ hoveredCaseGroupKey = _useState36[0],
2108
+ setHoveredCaseGroupKey = _useState36[1];
2109
+ var _useState37 = (0, _react.useState)(!!window.__sqb_selection_active__),
2110
+ _useState38 = (0, _slicedToArray2["default"])(_useState37, 2),
2111
+ globalSelectionActive = _useState38[0],
2112
+ setGlobalSelectionActive = _useState38[1];
2113
+ var _useState39 = (0, _react.useState)(window.__sqb_selection_owner__ || null),
2114
+ _useState40 = (0, _slicedToArray2["default"])(_useState39, 2),
2115
+ globalSelectionOwner = _useState40[0],
2116
+ setGlobalSelectionOwner = _useState40[1];
2117
+ var _useState41 = (0, _react.useState)([]),
2118
+ _useState42 = (0, _slicedToArray2["default"])(_useState41, 2),
2119
+ selectedIndices = _useState42[0],
2120
+ setSelectedIndices = _useState42[1];
2121
+ var _useState43 = (0, _react.useState)(null),
2122
+ _useState44 = (0, _slicedToArray2["default"])(_useState43, 2),
2123
+ hoveredCopyIndex = _useState44[0],
2124
+ setHoveredCopyIndex = _useState44[1];
1180
2125
  var getCaseGroupEnd = function getCaseGroupEnd(list, startIndex) {
1181
2126
  var depth = 0;
1182
2127
  for (var index = startIndex; index < list.length; index++) {
@@ -1433,6 +2378,11 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1433
2378
  value: [val],
1434
2379
  theme: _enum.ColumnsPopupThemeEnum.skyBlue,
1435
2380
  readonly: snapshotMode,
2381
+ onValueSync: function onValueSync(fields) {
2382
+ var _caseList = caseList.slice();
2383
+ _caseList[i] = fields[0];
2384
+ setCaseList(_caseList);
2385
+ },
1436
2386
  onSelect: function onSelect(fields) {
1437
2387
  var _caseList = caseList.slice();
1438
2388
  _caseList[i] = fields[0];
@@ -1589,10 +2539,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1589
2539
  title: (0, _locale.__)('metabase.prompt'),
1590
2540
  content: (0, _locale.__)('customColumn.confirmDelete'),
1591
2541
  onOk: function () {
1592
- var _onOk = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3() {
2542
+ var _onOk = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee0() {
1593
2543
  var selectedIndexSet, _caseList;
1594
- return _regenerator["default"].wrap(function (_context3) {
1595
- while (1) switch (_context3.prev = _context3.next) {
2544
+ return _regenerator["default"].wrap(function (_context0) {
2545
+ while (1) switch (_context0.prev = _context0.next) {
1596
2546
  case 0:
1597
2547
  selectedIndexSet = new Set(selectedIndices);
1598
2548
  _caseList = caseList.filter(function (_, index) {
@@ -1602,9 +2552,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1602
2552
  initPaste();
1603
2553
  case 1:
1604
2554
  case "end":
1605
- return _context3.stop();
2555
+ return _context0.stop();
1606
2556
  }
1607
- }, _callee3);
2557
+ }, _callee0);
1608
2558
  }));
1609
2559
  function onOk() {
1610
2560
  return _onOk.apply(this, arguments);
@@ -1705,10 +2655,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1705
2655
  };
1706
2656
  var showNotExists = function showNotExists(i) {
1707
2657
  var _caseList$i, _caseList$i2;
1708
- var _store$preProps = store.preProps,
1709
- notExistsToolbar = _store$preProps.notExistsToolbar,
1710
- toolbar = _store$preProps.toolbar,
1711
- other = (0, _objectWithoutProperties2["default"])(_store$preProps, _excluded2);
2658
+ var _store$preProps3 = store.preProps,
2659
+ notExistsToolbar = _store$preProps3.notExistsToolbar,
2660
+ toolbar = _store$preProps3.toolbar,
2661
+ other = (0, _objectWithoutProperties2["default"])(_store$preProps3, _excluded2);
1712
2662
  var _value = ((_caseList$i = caseList[i]) === null || _caseList$i === void 0 ? void 0 : _caseList$i.notExists) || [];
1713
2663
  var oldList = (0, _cloneDeep["default"])(((_caseList$i2 = caseList[i]) === null || _caseList$i2 === void 0 ? void 0 : _caseList$i2.notExists) || []);
1714
2664
  var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
@@ -1720,12 +2670,18 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1720
2670
  content: (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
1721
2671
  children: (0, _jsxRuntime.jsx)(_index2["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other), {}, {
1722
2672
  popupZIndex: childModalZIndex + 1,
2673
+ readonly: snapshotMode,
2674
+ snapshotMode: snapshotMode,
1723
2675
  notExistsColumns: exitData,
1724
2676
  isExit: true,
1725
2677
  toolbar: _toolbar,
1726
2678
  btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
1727
2679
  value: (0, _cloneDeep["default"])(_value),
1728
2680
  onOk: function onOk(newList) {
2681
+ if (snapshotMode) {
2682
+ o.close();
2683
+ return;
2684
+ }
1729
2685
  try {
1730
2686
  if ((0, _isEqual["default"])(newList, oldList)) {
1731
2687
  o.close();
@@ -1750,13 +2706,13 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1750
2706
  };
1751
2707
  var showSubQuery = function showSubQuery(i) {
1752
2708
  var _caseList$i3, _caseList$i4;
1753
- var _store$preProps2 = store.preProps,
1754
- subToolbar = _store$preProps2.subToolbar,
1755
- notExistsColumns = _store$preProps2.notExistsColumns,
1756
- showFields = _store$preProps2.showFields,
1757
- isExit = _store$preProps2.isExit,
1758
- toolbar = _store$preProps2.toolbar,
1759
- other = (0, _objectWithoutProperties2["default"])(_store$preProps2, _excluded3);
2709
+ var _store$preProps4 = store.preProps,
2710
+ subToolbar = _store$preProps4.subToolbar,
2711
+ notExistsColumns = _store$preProps4.notExistsColumns,
2712
+ showFields = _store$preProps4.showFields,
2713
+ isExit = _store$preProps4.isExit,
2714
+ toolbar = _store$preProps4.toolbar,
2715
+ other = (0, _objectWithoutProperties2["default"])(_store$preProps4, _excluded3);
1760
2716
  var _value = ((_caseList$i3 = caseList[i]) === null || _caseList$i3 === void 0 ? void 0 : _caseList$i3.subQuery) || [];
1761
2717
  var oldList = (0, _cloneDeep["default"])(((_caseList$i4 = caseList[i]) === null || _caseList$i4 === void 0 ? void 0 : _caseList$i4.subQuery) || []);
1762
2718
  var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
@@ -1768,6 +2724,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1768
2724
  content: (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
1769
2725
  children: (0, _jsxRuntime.jsx)(_index2["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other), {}, {
1770
2726
  popupZIndex: childModalZIndex + 1,
2727
+ readonly: snapshotMode,
2728
+ snapshotMode: snapshotMode,
1771
2729
  isExit: true,
1772
2730
  isSubquery: true,
1773
2731
  notExistsColumns: exitData,
@@ -1776,6 +2734,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1776
2734
  btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
1777
2735
  value: (0, _cloneDeep["default"])(_value),
1778
2736
  onOk: function onOk(newList) {
2737
+ if (snapshotMode) {
2738
+ o.close();
2739
+ return;
2740
+ }
1779
2741
  try {
1780
2742
  if ((0, _isEqual["default"])(newList, oldList)) {
1781
2743
  o.close();
@@ -1990,7 +2952,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1990
2952
  }
1991
2953
  if (type === _types.AtomsTypeEnum.EXPRESSION) {
1992
2954
  var quotes = (0, _utils2.getAtomDisplayText)(v);
1993
- if (~['早于', '晚于', '在'].indexOf(v.condition) && v.rhs.length > 1) {
2955
+ if (~['大于', '小于', '大于或等于', '小于或等于', '早于', '晚于', '在'].indexOf(v.condition) && v.rhs.length > 1) {
1994
2956
  var _getAtomDisplayText$s;
1995
2957
  var nextList = caseList.slice();
1996
2958
  nextList[index].rhs = [nextList[index].rhs[0]];
@@ -2395,6 +3357,12 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
2395
3357
  disabled: diffLoading,
2396
3358
  onClick: showFormulaDiff,
2397
3359
  children: "\u5BF9\u6BD4\u7ED3\u679C"
3360
+ }), (hasFormulaSqlAction || hasFormulaDiffAction || resolvedAddSql) && (0, _jsxRuntime.jsx)(_pandora.Button, {
3361
+ className: 'Sqb-FormulaAddSqlAction',
3362
+ size: 'small',
3363
+ type: 'link',
3364
+ onClick: showAddSql,
3365
+ children: (0, _locale.__)('customColumn.addSql')
2398
3366
  })]
2399
3367
  }), !snapshotMode && (0, _jsxRuntime.jsx)("div", {
2400
3368
  className: 'errorMsg mt-2',