@gingkoo/pandora-metabase 1.0.157-alpha.7 → 1.0.157-alpha.8

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 (29) hide show
  1. package/lib/cjs/components/dialog/custom-editor/index.js +4 -3
  2. package/lib/cjs/components/dialog/formula-list/index.d.ts +2 -1
  3. package/lib/cjs/components/dialog/formula-list/index.js +984 -212
  4. package/lib/cjs/components/dialog/formula-list/index.less +322 -58
  5. package/lib/cjs/components/dialog/select-table/index.d.ts +4 -1
  6. package/lib/cjs/components/dialog/select-table/index.js +51 -7
  7. package/lib/cjs/components/dialog/select-table/index.less +20 -0
  8. package/lib/cjs/components/metabase/index.less +12 -14
  9. package/lib/cjs/components/modules/components/meta-icon.js +6 -4
  10. package/lib/cjs/index.d.ts +2 -2
  11. package/lib/cjs/locale/en.js +24 -0
  12. package/lib/cjs/locale/index.js +10 -6
  13. package/lib/cjs/locale/zh.js +24 -0
  14. package/lib/cjs/types.d.ts +31 -0
  15. package/lib/es/components/dialog/custom-editor/index.js +4 -3
  16. package/lib/es/components/dialog/formula-list/index.d.ts +2 -1
  17. package/lib/es/components/dialog/formula-list/index.js +986 -214
  18. package/lib/es/components/dialog/formula-list/index.less +322 -58
  19. package/lib/es/components/dialog/select-table/index.d.ts +4 -1
  20. package/lib/es/components/dialog/select-table/index.js +51 -7
  21. package/lib/es/components/dialog/select-table/index.less +20 -0
  22. package/lib/es/components/metabase/index.less +12 -14
  23. package/lib/es/components/modules/components/meta-icon.js +6 -4
  24. package/lib/es/index.d.ts +2 -2
  25. package/lib/es/locale/en.js +24 -0
  26. package/lib/es/locale/index.js +10 -6
  27. package/lib/es/locale/zh.js +24 -0
  28. package/lib/es/types.d.ts +31 -0
  29. package/package.json +1 -1
@@ -11,9 +11,9 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/exten
11
11
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
12
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
13
13
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
15
14
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
16
15
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
16
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
17
17
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
18
18
  var _jsxRuntime = require("react/jsx-runtime");
19
19
  var _react = _interopRequireWildcard(require("react"));
@@ -47,112 +47,753 @@ 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 _t4 in e) "default" !== _t4 && {}.hasOwnProperty.call(e, _t4) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t4)) && (i.get || i.set) ? o(f, _t4, i) : f[_t4] = e[_t4]); 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
+ }
51
128
  var SqlImportContent = function SqlImportContent(_ref2) {
52
129
  var onSubmit = _ref2.onSubmit,
53
130
  onClose = _ref2.onClose,
54
- matchBrackets = _ref2.matchBrackets;
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;
55
141
  var _useState = (0, _react.useState)(''),
56
142
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
57
- sql = _useState2[0],
58
- setSql = _useState2[1];
143
+ input = _useState2[0],
144
+ setInput = _useState2[1];
59
145
  var _useState3 = (0, _react.useState)(false),
60
146
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
61
147
  loading = _useState4[0],
62
148
  setLoading = _useState4[1];
63
- var editorRef = (0, _react.useRef)(null);
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]);
64
215
  (0, _react.useEffect)(function () {
65
- var timer = window.setTimeout(function () {
66
- var _editor$getCodeMirror, _codeMirror$focus;
67
- var editor = editorRef.current;
68
- var codeMirror = (editor === null || editor === void 0 ? void 0 : editor.editor) || (editor === null || editor === void 0 || (_editor$getCodeMirror = editor.getCodeMirror) === null || _editor$getCodeMirror === void 0 ? void 0 : _editor$getCodeMirror.call(editor)) || editor;
69
- codeMirror === null || codeMirror === void 0 || (_codeMirror$focus = codeMirror.focus) === null || _codeMirror$focus === void 0 || _codeMirror$focus.call(codeMirror);
70
- }, 0);
216
+ focusInput();
71
217
  return function () {
72
- return window.clearTimeout(timer);
218
+ var _abortControllerRef$c;
219
+ (_abortControllerRef$c = abortControllerRef.current) === null || _abortControllerRef$c === void 0 || _abortControllerRef$c.abort();
73
220
  };
74
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
+ }();
75
365
  var submit = function () {
76
- var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
77
- var applyResult, _t;
78
- return _regenerator["default"].wrap(function (_context) {
79
- while (1) switch (_context.prev = _context.next) {
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) {
80
370
  case 0:
81
- if (!(!sql.trim() || loading)) {
82
- _context.next = 1;
371
+ sql = input.trim();
372
+ if (!(!sql || loading)) {
373
+ _context3.next = 1;
83
374
  break;
84
375
  }
85
- return _context.abrupt("return");
376
+ return _context3.abrupt("return");
86
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('');
87
394
  setLoading(true);
88
- _context.prev = 2;
89
- _context.next = 3;
90
- return onSubmit(sql.trim());
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);
91
544
  case 3:
92
- applyResult = _context.sent;
93
- if (typeof applyResult === 'function') {
94
- applyResult();
545
+ apply = _context4.sent;
546
+ if (typeof apply === 'function') {
547
+ apply();
95
548
  }
96
- _context.next = 4;
549
+ case 4:
550
+ _context4.next = 5;
97
551
  return new Promise(function (resolve) {
98
552
  return window.requestAnimationFrame(function () {
99
553
  return resolve();
100
554
  });
101
555
  });
102
- case 4:
556
+ case 5:
103
557
  onClose();
104
- _context.next = 6;
105
- break;
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);
106
634
  case 5:
107
- _context.prev = 5;
108
- _t = _context["catch"](2);
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
+ }));
109
653
  case 6:
110
- _context.prev = 6;
111
- setLoading(false);
112
- return _context.finish(6);
113
- case 7:
114
654
  case "end":
115
- return _context.stop();
655
+ return _context6.stop();
116
656
  }
117
- }, _callee, null, [[2, 5, 6, 7]]);
657
+ }, _callee6, null, [[2,, 4, 5]]);
118
658
  }));
119
- return function submit() {
120
- return _ref3.apply(this, arguments);
659
+ return function showAddTable(_x3) {
660
+ return _ref7.apply(this, arguments);
121
661
  };
122
662
  }();
123
663
  return (0, _jsxRuntime.jsxs)("div", {
124
664
  className: 'Sqb-FormulaSqlImport',
125
- children: [(0, _jsxRuntime.jsx)("div", {
126
- className: 'Sqb-FormulaSqlImport-editor',
127
- children: (0, _jsxRuntime.jsx)(_pandora.Editor, {
128
- ref: editorRef,
129
- showFull: false,
130
- className: 'Sqb-FormulaSqlPreviewEditor',
131
- language: 'sql',
132
- height: '100%',
133
- fullscreen: true,
134
- showLanguage: false,
135
- matchBrackets: matchBrackets,
136
- lineWrapping: true,
137
- lineNumbers: true,
138
- value: sql,
139
- readOnly: loading,
140
- onChange: function onChange(value) {
141
- if (loading) return;
142
- setSql(value);
143
- }
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')
144
769
  })
145
770
  }), (0, _jsxRuntime.jsxs)("div", {
146
- className: 'Sqb-FormulaSqlImport-actions',
147
- children: [(0, _jsxRuntime.jsx)(_pandora.Button, {
148
- onClick: onClose,
149
- children: (0, _locale.__)('customColumn.cancel')
150
- }), (0, _jsxRuntime.jsx)(_pandora.Button, {
151
- primary: true,
152
- loading: loading,
153
- disabled: !sql.trim() || loading,
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'),
154
792
  onClick: submit,
155
- children: (0, _locale.__)('customColumn.parseSql')
793
+ children: (0, _jsxRuntime.jsx)(_icons.UpArrowIcon, {
794
+ width: 14,
795
+ height: 14
796
+ })
156
797
  })]
157
798
  })]
158
799
  });
@@ -257,11 +898,11 @@ var getTokenStyleByClassName = function getTokenStyleByClassName(className, extr
257
898
  } : {}), extraStyle);
258
899
  };
259
900
  var FormulaList = (0, _react.forwardRef)(function (props, ref) {
260
- var _storage$_metabaseCop, _store$preProps;
261
- var _useState5 = (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),
262
- _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
263
- checkedItemsCount = _useState6[0],
264
- setCheckedItemsCount = _useState6[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];
265
906
  (0, _react.useEffect)(function () {
266
907
  var _storage$_metabaseCop3;
267
908
  var handler = function handler() {
@@ -439,15 +1080,15 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
439
1080
  }
440
1081
  return _utils3.operatorList;
441
1082
  }, [store.operatorList]);
442
- var _useState7 = (0, _react.useState)(false),
443
- _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
444
- sqlLoading = _useState8[0],
445
- setSqlLoading = _useState8[1];
446
- var _useState9 = (0, _react.useState)(false),
447
- _useState0 = (0, _slicedToArray2["default"])(_useState9, 2),
448
- diffLoading = _useState0[0],
449
- setDiffLoading = _useState0[1];
450
- var _useState1 = (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 () {
451
1092
  if (!enableCopy) {
452
1093
  return false;
453
1094
  }
@@ -456,25 +1097,25 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
456
1097
  }
457
1098
  return store.copyType.includes(_type);
458
1099
  }),
459
- _useState10 = (0, _slicedToArray2["default"])(_useState1, 2),
460
- isCopy = _useState10[0],
461
- setIsCopy = _useState10[1];
1100
+ _useState20 = (0, _slicedToArray2["default"])(_useState19, 2),
1101
+ isCopy = _useState20[0],
1102
+ setIsCopy = _useState20[1];
462
1103
  var formulaList = (0, _react.useMemo)(function () {
463
1104
  return (0, _utils.getObjTem)(store.formulaTemplates);
464
1105
  }, [store.formulaTemplates]);
465
- var _useState11 = (0, _react.useState)(''),
466
- _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
467
- filterVal = _useState12[0],
468
- setFilterVal = _useState12[1];
1106
+ var _useState21 = (0, _react.useState)(''),
1107
+ _useState22 = (0, _slicedToArray2["default"])(_useState21, 2),
1108
+ filterVal = _useState22[0],
1109
+ setFilterVal = _useState22[1];
469
1110
  function getSelectDisplayText(item) {
470
1111
  var displayField = item.displayField || 'value';
471
1112
  var getOptionText = function getOptionText(value) {
472
- var _ref4, _option$displayField;
1113
+ var _ref9, _option$displayField;
473
1114
  var option = (item.options || []).find(function (currentOption) {
474
1115
  return currentOption.value === value;
475
1116
  });
476
1117
  if (!option) return value || '';
477
- return String((_ref4 = (_option$displayField = option[displayField]) !== null && _option$displayField !== void 0 ? _option$displayField : option.value) !== null && _ref4 !== void 0 ? _ref4 : '');
1118
+ return String((_ref9 = (_option$displayField = option[displayField]) !== null && _option$displayField !== void 0 ? _option$displayField : option.value) !== null && _ref9 !== void 0 ? _ref9 : '');
478
1119
  };
479
1120
  if (Array.isArray(item.val)) {
480
1121
  return item.val.map(function (currentValue) {
@@ -656,13 +1297,13 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
656
1297
  setCaseList(nextList);
657
1298
  };
658
1299
  var getFormulaSqlText = function getFormulaSqlText(result) {
659
- var _ref5, _result$sql;
1300
+ var _ref0, _result$sql;
660
1301
  if (typeof result === 'string') return result;
661
1302
  if (!result) return '';
662
- return String((_ref5 = (_result$sql = result.sql) !== null && _result$sql !== void 0 ? _result$sql : result.code) !== null && _ref5 !== void 0 ? _ref5 : '');
1303
+ return String((_ref0 = (_result$sql = result.sql) !== null && _result$sql !== void 0 ? _result$sql : result.code) !== null && _ref0 !== void 0 ? _ref0 : '');
663
1304
  };
664
1305
  var getFormulaDiffData = function getFormulaDiffData(result) {
665
- var _result$oldCode, _ref6, _result$newCode;
1306
+ var _result$oldCode, _ref1, _result$newCode;
666
1307
  if (typeof result === 'string') {
667
1308
  return {
668
1309
  oldCode: '',
@@ -677,7 +1318,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
677
1318
  }
678
1319
  return {
679
1320
  oldCode: String((_result$oldCode = result.oldCode) !== null && _result$oldCode !== void 0 ? _result$oldCode : ''),
680
- newCode: String((_ref6 = (_result$newCode = result.newCode) !== null && _result$newCode !== void 0 ? _result$newCode : result.code) !== null && _ref6 !== void 0 ? _ref6 : '')
1321
+ newCode: String((_ref1 = (_result$newCode = result.newCode) !== null && _result$newCode !== void 0 ? _result$newCode : result.code) !== null && _ref1 !== void 0 ? _ref1 : '')
681
1322
  };
682
1323
  };
683
1324
  var normalizeFormulaValueForOutput = function normalizeFormulaValueForOutput() {
@@ -692,65 +1333,97 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
692
1333
  var getInitialFormulaValue = function getInitialFormulaValue() {
693
1334
  return (0, _cloneDeep["default"])(normalizeFormulaValueForOutput(initialValueRef.current || []));
694
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
+ };
695
1340
  var parseFormulaSql = (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.parseFormulaSql;
696
- var resolvedAddSql = onAddSql || (typeof parseFormulaSql === 'function' ? (function () {
697
- var _ref7 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(sql) {
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) {
698
1344
  var result;
699
- return _regenerator["default"].wrap(function (_context2) {
700
- while (1) switch (_context2.prev = _context2.next) {
1345
+ return _regenerator["default"].wrap(function (_context7) {
1346
+ while (1) switch (_context7.prev = _context7.next) {
701
1347
  case 0:
702
- _context2.next = 1;
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;
703
1359
  return parseFormulaSql({
704
- sql: sql,
705
- availableTables: data
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
706
1368
  });
707
- case 1:
708
- result = _context2.sent;
1369
+ case 2:
1370
+ result = _context7.sent;
709
1371
  if (!(!result || !Array.isArray(result.formulaList))) {
710
- _context2.next = 2;
1372
+ _context7.next = 3;
711
1373
  break;
712
1374
  }
713
1375
  _pandora.Toast.warning((0, _locale.__)('customColumn.sqlParseInvalid'));
714
1376
  throw new Error('INVALID_FORMULA_SQL_RESULT');
715
- case 2:
716
- return _context2.abrupt("return", function () {
1377
+ case 3:
1378
+ return _context7.abrupt("return", function () {
717
1379
  return setCaseList(result.formulaList);
718
1380
  });
719
- case 3:
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:
720
1393
  case "end":
721
- return _context2.stop();
1394
+ return _context7.stop();
722
1395
  }
723
- }, _callee2);
1396
+ }, _callee7);
724
1397
  }));
725
- return function (_x) {
726
- return _ref7.apply(this, arguments);
1398
+ return function (_x5, _x6, _x7) {
1399
+ return _ref10.apply(this, arguments);
727
1400
  };
728
- }()) : undefined);
1401
+ }()) : undefined;
729
1402
  var showFormulaSql = function () {
730
- var _ref8 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3() {
731
- var result, sql, _t2;
732
- return _regenerator["default"].wrap(function (_context3) {
733
- while (1) switch (_context3.prev = _context3.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) {
734
1407
  case 0:
735
1408
  if (!(!hasFormulaSqlAction || sqlLoading)) {
736
- _context3.next = 1;
1409
+ _context8.next = 1;
737
1410
  break;
738
1411
  }
739
- return _context3.abrupt("return");
1412
+ return _context8.abrupt("return");
740
1413
  case 1:
741
1414
  setSqlLoading(true);
742
- _context3.prev = 2;
743
- _context3.next = 3;
1415
+ _context8.prev = 2;
1416
+ _context8.next = 3;
744
1417
  return store.getFormulaSqlCode(getCurrentFormulaValue());
745
1418
  case 3:
746
- result = _context3.sent;
1419
+ result = _context8.sent;
747
1420
  sql = getFormulaSqlText(result);
748
1421
  if (sql) {
749
- _context3.next = 4;
1422
+ _context8.next = 4;
750
1423
  break;
751
1424
  }
752
1425
  _pandora.Toast.warning('暂无可展示的SQL');
753
- return _context3.abrupt("return");
1426
+ return _context8.abrupt("return");
754
1427
  case 4:
755
1428
  openChildModal({
756
1429
  title: '查看SQL',
@@ -771,28 +1444,69 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
771
1444
  }),
772
1445
  onClose: function onClose() {}
773
1446
  });
774
- _context3.next = 6;
1447
+ _context8.next = 6;
775
1448
  break;
776
1449
  case 5:
777
- _context3.prev = 5;
778
- _t2 = _context3["catch"](2);
1450
+ _context8.prev = 5;
1451
+ _t1 = _context8["catch"](2);
779
1452
  _pandora.Toast.error('获取SQL失败');
780
1453
  case 6:
781
- _context3.prev = 6;
1454
+ _context8.prev = 6;
782
1455
  setSqlLoading(false);
783
- return _context3.finish(6);
1456
+ return _context8.finish(6);
784
1457
  case 7:
785
1458
  case "end":
786
- return _context3.stop();
1459
+ return _context8.stop();
787
1460
  }
788
- }, _callee3, null, [[2, 5, 6, 7]]);
1461
+ }, _callee8, null, [[2, 5, 6, 7]]);
789
1462
  }));
790
1463
  return function showFormulaSql() {
791
- return _ref8.apply(this, arguments);
1464
+ return _ref11.apply(this, arguments);
792
1465
  };
793
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
+ };
794
1500
  var showAddSql = function showAddSql() {
1501
+ var _store$sourceTable;
1502
+ if (!resolvedAddSql) {
1503
+ _pandora.Toast.warning((0, _locale.__)('customColumn.sqlChatMissingParser'));
1504
+ return;
1505
+ }
795
1506
  closePopup();
1507
+ if (!((_store$sourceTable = store.sourceTable) !== null && _store$sourceTable !== void 0 && _store$sourceTable.length)) {
1508
+ store.getSourceTable(store.sourceList || []);
1509
+ }
796
1510
  var modalInstance;
797
1511
  modalInstance = openChildModal({
798
1512
  title: (0, _locale.__)('customColumn.addSql'),
@@ -804,7 +1518,53 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
804
1518
  var _modalInstance2;
805
1519
  return (_modalInstance2 = modalInstance) === null || _modalInstance2 === void 0 ? void 0 : _modalInstance2.close();
806
1520
  },
807
- matchBrackets: store.matchBrackets
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
808
1568
  }),
809
1569
  modalWidth: 900,
810
1570
  modalHeight: 600,
@@ -812,33 +1572,33 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
812
1572
  });
813
1573
  };
814
1574
  var showFormulaDiff = function () {
815
- var _ref9 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4() {
816
- var result, _getFormulaDiffData, oldCode, newCode, _t3;
817
- return _regenerator["default"].wrap(function (_context4) {
818
- while (1) switch (_context4.prev = _context4.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) {
819
1579
  case 0:
820
1580
  if (!(!hasFormulaDiffAction || diffLoading)) {
821
- _context4.next = 1;
1581
+ _context9.next = 1;
822
1582
  break;
823
1583
  }
824
- return _context4.abrupt("return");
1584
+ return _context9.abrupt("return");
825
1585
  case 1:
826
1586
  setDiffLoading(true);
827
- _context4.prev = 2;
828
- _context4.next = 3;
1587
+ _context9.prev = 2;
1588
+ _context9.next = 3;
829
1589
  return store.getFormulaDiffCode({
830
1590
  oldCode: getInitialFormulaValue(),
831
1591
  newCode: getCurrentFormulaValue()
832
1592
  });
833
1593
  case 3:
834
- result = _context4.sent;
1594
+ result = _context9.sent;
835
1595
  _getFormulaDiffData = getFormulaDiffData(result), oldCode = _getFormulaDiffData.oldCode, newCode = _getFormulaDiffData.newCode;
836
1596
  if (!(!oldCode && !newCode)) {
837
- _context4.next = 4;
1597
+ _context9.next = 4;
838
1598
  break;
839
1599
  }
840
1600
  _pandora.Toast.warning('暂无可展示的对比结果');
841
- return _context4.abrupt("return");
1601
+ return _context9.abrupt("return");
842
1602
  case 4:
843
1603
  openChildModal({
844
1604
  title: '对比结果',
@@ -849,24 +1609,24 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
849
1609
  }),
850
1610
  onClose: function onClose() {}
851
1611
  });
852
- _context4.next = 6;
1612
+ _context9.next = 6;
853
1613
  break;
854
1614
  case 5:
855
- _context4.prev = 5;
856
- _t3 = _context4["catch"](2);
1615
+ _context9.prev = 5;
1616
+ _t10 = _context9["catch"](2);
857
1617
  _pandora.Toast.error('获取对比结果失败');
858
1618
  case 6:
859
- _context4.prev = 6;
1619
+ _context9.prev = 6;
860
1620
  setDiffLoading(false);
861
- return _context4.finish(6);
1621
+ return _context9.finish(6);
862
1622
  case 7:
863
1623
  case "end":
864
- return _context4.stop();
1624
+ return _context9.stop();
865
1625
  }
866
- }, _callee4, null, [[2, 5, 6, 7]]);
1626
+ }, _callee9, null, [[2, 5, 6, 7]]);
867
1627
  }));
868
1628
  return function showFormulaDiff() {
869
- return _ref9.apply(this, arguments);
1629
+ return _ref13.apply(this, arguments);
870
1630
  };
871
1631
  }();
872
1632
  var renderTokenContent = function renderTokenContent(children) {
@@ -881,16 +1641,16 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
881
1641
  var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
882
1642
  var modalInstance;
883
1643
  var CaseWhenZoomEditor = function CaseWhenZoomEditor() {
884
- var _useState13 = (0, _react.useState)(function () {
1644
+ var _useState23 = (0, _react.useState)(function () {
885
1645
  return (0, _cloneDeep["default"])(value);
886
1646
  }),
887
- _useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
888
- draftValue = _useState14[0],
889
- setDraftValue = _useState14[1];
890
- var _useState15 = (0, _react.useState)(null),
891
- _useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
892
- activeZoomRegionKey = _useState16[0],
893
- setActiveZoomRegionKey = _useState16[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];
894
1654
  var updateDraftValue = function updateDraftValue(nextValue) {
895
1655
  setDraftValue(withSyncedQuotes(nextValue));
896
1656
  };
@@ -1045,12 +1805,12 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1045
1805
  var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
1046
1806
  var modalInstance;
1047
1807
  var FormulaListZoomEditor = function FormulaListZoomEditor() {
1048
- var _useState17 = (0, _react.useState)(function () {
1808
+ var _useState27 = (0, _react.useState)(function () {
1049
1809
  return (0, _cloneDeep["default"])(caseList || []);
1050
1810
  }),
1051
- _useState18 = (0, _slicedToArray2["default"])(_useState17, 2),
1052
- draftList = _useState18[0],
1053
- setDraftList = _useState18[1];
1811
+ _useState28 = (0, _slicedToArray2["default"])(_useState27, 2),
1812
+ draftList = _useState28[0],
1813
+ setDraftList = _useState28[1];
1054
1814
  var updateDraftList = function updateDraftList(nextList) {
1055
1815
  setDraftList(nextList.map(function (item) {
1056
1816
  return withSyncedQuotes(item);
@@ -1325,43 +2085,43 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1325
2085
  }
1326
2086
  });
1327
2087
  };
1328
- var _useState19 = (0, _react.useState)(-1),
1329
- _useState20 = (0, _slicedToArray2["default"])(_useState19, 2),
1330
- ind = _useState20[0],
1331
- setInd = _useState20[1];
2088
+ var _useState29 = (0, _react.useState)(-1),
2089
+ _useState30 = (0, _slicedToArray2["default"])(_useState29, 2),
2090
+ ind = _useState30[0],
2091
+ setInd = _useState30[1];
1332
2092
  var filterCustomType = store.filterCustomType;
1333
2093
  var _ref = (0, _react.useRef)(null);
1334
- var _useState21 = (0, _react.useState)({
2094
+ var _useState31 = (0, _react.useState)({
1335
2095
  isError: false
1336
2096
  }),
1337
- _useState22 = (0, _slicedToArray2["default"])(_useState21, 2),
1338
- errorInfo = _useState22[0],
1339
- setErrorInfo = _useState22[1];
1340
- var _useState23 = (0, _react.useState)(false),
1341
- _useState24 = (0, _slicedToArray2["default"])(_useState23, 2),
1342
- isCheck = _useState24[0],
1343
- setIsCheck = _useState24[1];
1344
- var myInstanceIdRef = (0, _react.useRef)(Math.random().toString(36).slice(2));
1345
- var _useState25 = (0, _react.useState)(null),
1346
- _useState26 = (0, _slicedToArray2["default"])(_useState25, 2),
1347
- hoveredCaseGroupKey = _useState26[0],
1348
- setHoveredCaseGroupKey = _useState26[1];
1349
- var _useState27 = (0, _react.useState)(!!window.__sqb_selection_active__),
1350
- _useState28 = (0, _slicedToArray2["default"])(_useState27, 2),
1351
- globalSelectionActive = _useState28[0],
1352
- setGlobalSelectionActive = _useState28[1];
1353
- var _useState29 = (0, _react.useState)(window.__sqb_selection_owner__ || null),
1354
- _useState30 = (0, _slicedToArray2["default"])(_useState29, 2),
1355
- globalSelectionOwner = _useState30[0],
1356
- setGlobalSelectionOwner = _useState30[1];
1357
- var _useState31 = (0, _react.useState)([]),
1358
2097
  _useState32 = (0, _slicedToArray2["default"])(_useState31, 2),
1359
- selectedIndices = _useState32[0],
1360
- setSelectedIndices = _useState32[1];
1361
- var _useState33 = (0, _react.useState)(null),
2098
+ errorInfo = _useState32[0],
2099
+ setErrorInfo = _useState32[1];
2100
+ var _useState33 = (0, _react.useState)(false),
1362
2101
  _useState34 = (0, _slicedToArray2["default"])(_useState33, 2),
1363
- hoveredCopyIndex = _useState34[0],
1364
- setHoveredCopyIndex = _useState34[1];
2102
+ isCheck = _useState34[0],
2103
+ setIsCheck = _useState34[1];
2104
+ var myInstanceIdRef = (0, _react.useRef)(Math.random().toString(36).slice(2));
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];
1365
2125
  var getCaseGroupEnd = function getCaseGroupEnd(list, startIndex) {
1366
2126
  var depth = 0;
1367
2127
  for (var index = startIndex; index < list.length; index++) {
@@ -1779,10 +2539,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1779
2539
  title: (0, _locale.__)('metabase.prompt'),
1780
2540
  content: (0, _locale.__)('customColumn.confirmDelete'),
1781
2541
  onOk: function () {
1782
- var _onOk = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5() {
2542
+ var _onOk = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee0() {
1783
2543
  var selectedIndexSet, _caseList;
1784
- return _regenerator["default"].wrap(function (_context5) {
1785
- while (1) switch (_context5.prev = _context5.next) {
2544
+ return _regenerator["default"].wrap(function (_context0) {
2545
+ while (1) switch (_context0.prev = _context0.next) {
1786
2546
  case 0:
1787
2547
  selectedIndexSet = new Set(selectedIndices);
1788
2548
  _caseList = caseList.filter(function (_, index) {
@@ -1792,9 +2552,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1792
2552
  initPaste();
1793
2553
  case 1:
1794
2554
  case "end":
1795
- return _context5.stop();
2555
+ return _context0.stop();
1796
2556
  }
1797
- }, _callee5);
2557
+ }, _callee0);
1798
2558
  }));
1799
2559
  function onOk() {
1800
2560
  return _onOk.apply(this, arguments);
@@ -1895,10 +2655,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1895
2655
  };
1896
2656
  var showNotExists = function showNotExists(i) {
1897
2657
  var _caseList$i, _caseList$i2;
1898
- var _store$preProps2 = store.preProps,
1899
- notExistsToolbar = _store$preProps2.notExistsToolbar,
1900
- toolbar = _store$preProps2.toolbar,
1901
- other = (0, _objectWithoutProperties2["default"])(_store$preProps2, _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);
1902
2662
  var _value = ((_caseList$i = caseList[i]) === null || _caseList$i === void 0 ? void 0 : _caseList$i.notExists) || [];
1903
2663
  var oldList = (0, _cloneDeep["default"])(((_caseList$i2 = caseList[i]) === null || _caseList$i2 === void 0 ? void 0 : _caseList$i2.notExists) || []);
1904
2664
  var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
@@ -1910,12 +2670,18 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1910
2670
  content: (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
1911
2671
  children: (0, _jsxRuntime.jsx)(_index2["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other), {}, {
1912
2672
  popupZIndex: childModalZIndex + 1,
2673
+ readonly: snapshotMode,
2674
+ snapshotMode: snapshotMode,
1913
2675
  notExistsColumns: exitData,
1914
2676
  isExit: true,
1915
2677
  toolbar: _toolbar,
1916
2678
  btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
1917
2679
  value: (0, _cloneDeep["default"])(_value),
1918
2680
  onOk: function onOk(newList) {
2681
+ if (snapshotMode) {
2682
+ o.close();
2683
+ return;
2684
+ }
1919
2685
  try {
1920
2686
  if ((0, _isEqual["default"])(newList, oldList)) {
1921
2687
  o.close();
@@ -1940,13 +2706,13 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1940
2706
  };
1941
2707
  var showSubQuery = function showSubQuery(i) {
1942
2708
  var _caseList$i3, _caseList$i4;
1943
- var _store$preProps3 = store.preProps,
1944
- subToolbar = _store$preProps3.subToolbar,
1945
- notExistsColumns = _store$preProps3.notExistsColumns,
1946
- showFields = _store$preProps3.showFields,
1947
- isExit = _store$preProps3.isExit,
1948
- toolbar = _store$preProps3.toolbar,
1949
- other = (0, _objectWithoutProperties2["default"])(_store$preProps3, _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);
1950
2716
  var _value = ((_caseList$i3 = caseList[i]) === null || _caseList$i3 === void 0 ? void 0 : _caseList$i3.subQuery) || [];
1951
2717
  var oldList = (0, _cloneDeep["default"])(((_caseList$i4 = caseList[i]) === null || _caseList$i4 === void 0 ? void 0 : _caseList$i4.subQuery) || []);
1952
2718
  var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
@@ -1958,6 +2724,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1958
2724
  content: (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
1959
2725
  children: (0, _jsxRuntime.jsx)(_index2["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other), {}, {
1960
2726
  popupZIndex: childModalZIndex + 1,
2727
+ readonly: snapshotMode,
2728
+ snapshotMode: snapshotMode,
1961
2729
  isExit: true,
1962
2730
  isSubquery: true,
1963
2731
  notExistsColumns: exitData,
@@ -1966,6 +2734,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1966
2734
  btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
1967
2735
  value: (0, _cloneDeep["default"])(_value),
1968
2736
  onOk: function onOk(newList) {
2737
+ if (snapshotMode) {
2738
+ o.close();
2739
+ return;
2740
+ }
1969
2741
  try {
1970
2742
  if ((0, _isEqual["default"])(newList, oldList)) {
1971
2743
  o.close();
@@ -2585,7 +3357,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
2585
3357
  disabled: diffLoading,
2586
3358
  onClick: showFormulaDiff,
2587
3359
  children: "\u5BF9\u6BD4\u7ED3\u679C"
2588
- }), (hasFormulaSqlAction || hasFormulaDiffAction) && resolvedAddSql && (0, _jsxRuntime.jsx)(_pandora.Button, {
3360
+ }), (hasFormulaSqlAction || hasFormulaDiffAction || resolvedAddSql) && (0, _jsxRuntime.jsx)(_pandora.Button, {
2589
3361
  className: 'Sqb-FormulaAddSqlAction',
2590
3362
  size: 'small',
2591
3363
  type: 'link',