@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.
- package/lib/cjs/components/dialog/custom-editor/index.js +61 -5
- package/lib/cjs/components/dialog/expression/index.js +132 -54
- package/lib/cjs/components/dialog/expression/index.less +43 -0
- package/lib/cjs/components/dialog/formula/index.js +3 -1
- package/lib/cjs/components/dialog/formula/utils.d.ts +1 -0
- package/lib/cjs/components/dialog/formula/utils.js +20 -2
- package/lib/cjs/components/dialog/formula-list/index.d.ts +2 -0
- package/lib/cjs/components/dialog/formula-list/index.js +1119 -151
- package/lib/cjs/components/dialog/formula-list/index.less +362 -46
- package/lib/cjs/components/dialog/formula-list/utils.d.ts +13 -1
- package/lib/cjs/components/dialog/formula-list/utils.js +100 -1
- package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +2 -1
- package/lib/cjs/components/dialog/select-column-multiple/index.js +4 -2
- package/lib/cjs/components/dialog/select-join/index.js +11 -0
- package/lib/cjs/components/dialog/select-summarize/index.d.ts +4 -0
- package/lib/cjs/components/dialog/select-summarize/index.js +136 -15
- package/lib/cjs/components/dialog/select-summarize/index.less +34 -1
- package/lib/cjs/components/dialog/select-table/index.d.ts +4 -1
- package/lib/cjs/components/dialog/select-table/index.js +51 -7
- package/lib/cjs/components/dialog/select-table/index.less +20 -0
- package/lib/cjs/components/icons.d.ts +1 -0
- package/lib/cjs/components/icons.js +54 -29
- package/lib/cjs/components/metabase/index.js +8 -0
- package/lib/cjs/components/metabase/index.less +17 -14
- package/lib/cjs/components/modules/components/item-name.js +16 -2
- package/lib/cjs/components/modules/components/meta-icon.js +6 -4
- package/lib/cjs/components/modules/join-data.js +5 -0
- package/lib/cjs/components/modules/summarize/group-by.js +12 -1
- package/lib/cjs/components/modules/summarize/select-index.js +12 -1
- package/lib/cjs/hooks/use-state.js +1 -13
- package/lib/cjs/index.d.ts +3 -2
- package/lib/cjs/index.js +7 -0
- package/lib/cjs/locale/en.js +31 -0
- package/lib/cjs/locale/index.js +10 -6
- package/lib/cjs/locale/zh.js +31 -0
- package/lib/cjs/store/enum.d.ts +2 -1
- package/lib/cjs/store/enum.js +1 -0
- package/lib/cjs/store/helper.js +25 -2
- package/lib/cjs/store/types.d.ts +7 -1
- package/lib/cjs/types.d.ts +41 -1
- package/lib/cjs/utils/helper.js +20 -0
- package/lib/cjs/utils/transformSql.js +59 -2
- package/lib/cjs/utils.js +25 -4
- package/lib/es/components/dialog/custom-editor/index.js +62 -6
- package/lib/es/components/dialog/expression/index.js +133 -55
- package/lib/es/components/dialog/expression/index.less +43 -0
- package/lib/es/components/dialog/formula/index.js +4 -2
- package/lib/es/components/dialog/formula/utils.d.ts +1 -0
- package/lib/es/components/dialog/formula/utils.js +18 -1
- package/lib/es/components/dialog/formula-list/index.d.ts +2 -0
- package/lib/es/components/dialog/formula-list/index.js +1121 -153
- package/lib/es/components/dialog/formula-list/index.less +362 -46
- package/lib/es/components/dialog/formula-list/utils.d.ts +13 -1
- package/lib/es/components/dialog/formula-list/utils.js +99 -0
- package/lib/es/components/dialog/select-column-multiple/index.d.ts +2 -1
- package/lib/es/components/dialog/select-column-multiple/index.js +4 -2
- package/lib/es/components/dialog/select-join/index.js +12 -1
- package/lib/es/components/dialog/select-summarize/index.d.ts +4 -0
- package/lib/es/components/dialog/select-summarize/index.js +140 -19
- package/lib/es/components/dialog/select-summarize/index.less +34 -1
- package/lib/es/components/dialog/select-table/index.d.ts +4 -1
- package/lib/es/components/dialog/select-table/index.js +51 -7
- package/lib/es/components/dialog/select-table/index.less +20 -0
- package/lib/es/components/icons.d.ts +1 -0
- package/lib/es/components/icons.js +53 -28
- package/lib/es/components/metabase/index.js +8 -0
- package/lib/es/components/metabase/index.less +17 -14
- package/lib/es/components/modules/components/item-name.js +16 -2
- package/lib/es/components/modules/components/meta-icon.js +6 -4
- package/lib/es/components/modules/join-data.js +6 -1
- package/lib/es/components/modules/summarize/group-by.js +12 -1
- package/lib/es/components/modules/summarize/select-index.js +12 -1
- package/lib/es/hooks/use-state.js +1 -13
- package/lib/es/index.d.ts +3 -2
- package/lib/es/index.js +3 -1
- package/lib/es/locale/en.js +31 -0
- package/lib/es/locale/index.js +10 -6
- package/lib/es/locale/zh.js +31 -0
- package/lib/es/store/enum.d.ts +2 -1
- package/lib/es/store/enum.js +1 -0
- package/lib/es/store/helper.js +25 -2
- package/lib/es/store/types.d.ts +7 -1
- package/lib/es/types.d.ts +41 -1
- package/lib/es/utils/helper.js +20 -0
- package/lib/es/utils/transformSql.js +59 -2
- package/lib/es/utils.js +25 -4
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
3
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
5
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
6
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
6
7
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
7
8
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
8
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
9
9
|
var _excluded = ["operator", "leftAtoms", "rightAtoms", "atoms"],
|
|
10
10
|
_excluded2 = ["notExistsToolbar", "toolbar"],
|
|
11
11
|
_excluded3 = ["subToolbar", "notExistsColumns", "showFields", "isExit", "toolbar"];
|
|
@@ -23,11 +23,11 @@ import { AtomsTypeEnum, FormulaTypeEnum } from '../../../store/types';
|
|
|
23
23
|
import { ColumnsPopupThemeEnum } from '../../../store/enum';
|
|
24
24
|
import { Select, Input, Modal2, Modal, InputNumber, Space, Button, Checkbox, Tooltip, Toast, Editor } from '@gingkoo/pandora';
|
|
25
25
|
import cloneDeep from 'lodash/cloneDeep';
|
|
26
|
-
import { buildSqlQuery, getAtomDisplayText, isError, changeCopyField, isExistsError, normalizeAndOrStructure, syncAtomQuotes } from '../../../utils';
|
|
26
|
+
import { buildSqlQuery, getAtomDisplayText, isError, changeCopyField, isExistsError, normalizeAndOrStructure, normalizeLegacySummarizeForSave, splitByUnion, syncAtomQuotes } from '../../../utils';
|
|
27
27
|
import Formula from '../formula';
|
|
28
|
-
import { AddIcon, CloseIcon } from '../../icons';
|
|
29
|
-
import { Expression, SelectColumnMultiple } from '../../dialog';
|
|
30
|
-
import { customTypes, operatorList as __operatorList, insertTemplateAt, getTemplateItem, validateExpressionIntegrity, getConstantLabel } from './utils';
|
|
28
|
+
import { AddIcon, CloseIcon, UpArrowIcon } from '../../icons';
|
|
29
|
+
import { Expression, SelectColumnMultiple, SelectTable } from '../../dialog';
|
|
30
|
+
import { customTypes, operatorList as __operatorList, insertTemplateAt, getTemplateItem, validateExpressionIntegrity, getConstantLabel, normalizeExpressionAtoms } from './utils';
|
|
31
31
|
import SelectList from '../../dialog/select-list';
|
|
32
32
|
import arrow from './arrow.svg';
|
|
33
33
|
import { useStore, Provider } from '../../../hooks/use-provider';
|
|
@@ -39,6 +39,757 @@ import { getTopLayerZIndex } from '../../../utils/helper-dom';
|
|
|
39
39
|
import CaseWhenGroup from './CaseWhenGroup';
|
|
40
40
|
import LogicGroup from './LogicGroup';
|
|
41
41
|
import { SummarizeAlias } from '../../../store/helper';
|
|
42
|
+
function getScopeKey(item) {
|
|
43
|
+
return item.scopeKey || "".concat(item.datasourceId || '', ":").concat(item.tableId || '', ":").concat(item.tableUuid || '', ":").concat(item.tableName || '', ":").concat(item.tableAlias || '');
|
|
44
|
+
}
|
|
45
|
+
function tableToScopeItem(table) {
|
|
46
|
+
var fixed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
47
|
+
var tableId = table.id || table.tableId || table.name || table.tableName || '';
|
|
48
|
+
var tableName = table.name || table.tableName || table.table || tableId;
|
|
49
|
+
var datasourceId = table.datasourceId || '';
|
|
50
|
+
var tableAlias = table.alias || table.tableAlias || '';
|
|
51
|
+
var tableUuid = table.tableUuid || '';
|
|
52
|
+
return {
|
|
53
|
+
datasourceId: datasourceId,
|
|
54
|
+
datasourceName: table.datasourceName,
|
|
55
|
+
tableId: tableId,
|
|
56
|
+
tableName: tableName,
|
|
57
|
+
tableNameZh: table.name_zh || table.tableNameZh || tableName,
|
|
58
|
+
tableAlias: tableAlias,
|
|
59
|
+
tableUuid: tableUuid,
|
|
60
|
+
fixed: fixed,
|
|
61
|
+
scopeKey: "".concat(datasourceId, ":").concat(tableId, ":").concat(tableUuid, ":").concat(tableName, ":").concat(tableAlias)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function scopeItemToTableValue(item) {
|
|
65
|
+
return {
|
|
66
|
+
datasourceId: item.datasourceId,
|
|
67
|
+
datasourceName: item.datasourceName,
|
|
68
|
+
name: item.tableName || '',
|
|
69
|
+
name_zh: item.tableNameZh || '',
|
|
70
|
+
tableUuid: item.tableUuid || '',
|
|
71
|
+
id: item.tableId || '',
|
|
72
|
+
alias: item.tableAlias || ''
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function cleanJsonText() {
|
|
76
|
+
var rawText = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
77
|
+
return "".concat(rawText || '').trim().replace(/^```(?:json)?/i, '').replace(/```$/i, '').trim();
|
|
78
|
+
}
|
|
79
|
+
function parseFormulaSqlStreamText() {
|
|
80
|
+
var rawText = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
81
|
+
var parsed = JSON.parse(cleanJsonText(rawText));
|
|
82
|
+
if (!parsed || !Array.isArray(parsed.formulaList)) {
|
|
83
|
+
throw new Error('INVALID_FORMULA_SQL_RESULT');
|
|
84
|
+
}
|
|
85
|
+
return parsed;
|
|
86
|
+
}
|
|
87
|
+
function extractJsonStringValue(rawText, key) {
|
|
88
|
+
var keyPattern = "\"".concat(key, "\"");
|
|
89
|
+
var keyIndex = rawText.indexOf(keyPattern);
|
|
90
|
+
if (keyIndex < 0) return '';
|
|
91
|
+
var colonIndex = rawText.indexOf(':', keyIndex + keyPattern.length);
|
|
92
|
+
if (colonIndex < 0) return '';
|
|
93
|
+
var index = colonIndex + 1;
|
|
94
|
+
while (/\s/.test(rawText[index] || '')) index += 1;
|
|
95
|
+
if (rawText[index] !== '"') return '';
|
|
96
|
+
index += 1;
|
|
97
|
+
var value = '';
|
|
98
|
+
var escaped = false;
|
|
99
|
+
for (; index < rawText.length; index += 1) {
|
|
100
|
+
var char = rawText[index];
|
|
101
|
+
if (escaped) {
|
|
102
|
+
try {
|
|
103
|
+
value += JSON.parse("\"\\".concat(char, "\""));
|
|
104
|
+
} catch (error) {
|
|
105
|
+
value += char;
|
|
106
|
+
}
|
|
107
|
+
escaped = false;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (char === '\\') {
|
|
111
|
+
escaped = true;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (char === '"') break;
|
|
115
|
+
value += char;
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
var SqlImportContent = function SqlImportContent(_ref2) {
|
|
120
|
+
var onSubmit = _ref2.onSubmit,
|
|
121
|
+
onClose = _ref2.onClose,
|
|
122
|
+
streamParser = _ref2.streamParser,
|
|
123
|
+
datasource = _ref2.datasource,
|
|
124
|
+
sourceTable = _ref2.sourceTable,
|
|
125
|
+
tableFlat = _ref2.tableFlat,
|
|
126
|
+
getTables = _ref2.getTables,
|
|
127
|
+
getColumns = _ref2.getColumns,
|
|
128
|
+
defaultAvailableTables = _ref2.defaultAvailableTables,
|
|
129
|
+
openTablePopup = _ref2.openTablePopup,
|
|
130
|
+
closeTablePopup = _ref2.closeTablePopup,
|
|
131
|
+
onPreviewFormula = _ref2.onPreviewFormula;
|
|
132
|
+
var _useState = useState(''),
|
|
133
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
134
|
+
input = _useState2[0],
|
|
135
|
+
setInput = _useState2[1];
|
|
136
|
+
var _useState3 = useState(false),
|
|
137
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
138
|
+
loading = _useState4[0],
|
|
139
|
+
setLoading = _useState4[1];
|
|
140
|
+
var _useState5 = useState([]),
|
|
141
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
142
|
+
messages = _useState6[0],
|
|
143
|
+
setMessages = _useState6[1];
|
|
144
|
+
var _useState7 = useState([]),
|
|
145
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
146
|
+
tableScope = _useState8[0],
|
|
147
|
+
setTableScope = _useState8[1];
|
|
148
|
+
var _useState9 = useState(sourceTable || []),
|
|
149
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
150
|
+
scopeSourceTable = _useState0[0],
|
|
151
|
+
setScopeSourceTable = _useState0[1];
|
|
152
|
+
var _useState1 = useState(false),
|
|
153
|
+
_useState10 = _slicedToArray(_useState1, 2),
|
|
154
|
+
scopeLoading = _useState10[0],
|
|
155
|
+
setScopeLoading = _useState10[1];
|
|
156
|
+
var _useState11 = useState(false),
|
|
157
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
158
|
+
scopeExpanded = _useState12[0],
|
|
159
|
+
setScopeExpanded = _useState12[1];
|
|
160
|
+
var fixedTableScope = useMemo(function () {
|
|
161
|
+
return (defaultAvailableTables || []).map(function (table) {
|
|
162
|
+
return tableToScopeItem(table, true);
|
|
163
|
+
});
|
|
164
|
+
}, [defaultAvailableTables]);
|
|
165
|
+
var mergedTableScope = useMemo(function () {
|
|
166
|
+
var map = new Map();
|
|
167
|
+
fixedTableScope.forEach(function (item) {
|
|
168
|
+
return map.set(getScopeKey(item), item);
|
|
169
|
+
});
|
|
170
|
+
tableScope.forEach(function (item) {
|
|
171
|
+
return map.set(getScopeKey(item), item);
|
|
172
|
+
});
|
|
173
|
+
return Array.from(map.values());
|
|
174
|
+
}, [fixedTableScope, tableScope]);
|
|
175
|
+
var messagesRef = useRef(null);
|
|
176
|
+
var inputRef = useRef(null);
|
|
177
|
+
var abortControllerRef = useRef(null);
|
|
178
|
+
var cancelByUserRef = useRef(false);
|
|
179
|
+
var tableScopeRef = useRef([]);
|
|
180
|
+
var focusInput = function focusInput() {
|
|
181
|
+
window.requestAnimationFrame(function () {
|
|
182
|
+
window.setTimeout(function () {
|
|
183
|
+
var _inputNode$resizableT, _inputNode$resizableT2, _inputNode$textarea, _inputNode$textarea$f;
|
|
184
|
+
var inputNode = inputRef.current;
|
|
185
|
+
if (typeof (inputNode === null || inputNode === void 0 ? void 0 : inputNode.focus) === 'function') {
|
|
186
|
+
inputNode.focus();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
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);
|
|
190
|
+
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);
|
|
191
|
+
}, 0);
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
useEffect(function () {
|
|
195
|
+
tableScopeRef.current = mergedTableScope;
|
|
196
|
+
}, [mergedTableScope]);
|
|
197
|
+
useEffect(function () {
|
|
198
|
+
setScopeSourceTable(sourceTable || []);
|
|
199
|
+
}, [sourceTable]);
|
|
200
|
+
useEffect(function () {
|
|
201
|
+
requestAnimationFrame(function () {
|
|
202
|
+
if (!messagesRef.current) return;
|
|
203
|
+
messagesRef.current.scrollTop = messagesRef.current.scrollHeight;
|
|
204
|
+
});
|
|
205
|
+
}, [messages]);
|
|
206
|
+
useEffect(function () {
|
|
207
|
+
focusInput();
|
|
208
|
+
return function () {
|
|
209
|
+
var _abortControllerRef$c;
|
|
210
|
+
(_abortControllerRef$c = abortControllerRef.current) === null || _abortControllerRef$c === void 0 || _abortControllerRef$c.abort();
|
|
211
|
+
};
|
|
212
|
+
}, []);
|
|
213
|
+
var getChatMessages = function getChatMessages() {
|
|
214
|
+
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : messages;
|
|
215
|
+
return list.filter(function (item) {
|
|
216
|
+
return !item.status;
|
|
217
|
+
}).map(function (item) {
|
|
218
|
+
var _item$parseResult;
|
|
219
|
+
return {
|
|
220
|
+
role: item.role,
|
|
221
|
+
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({
|
|
222
|
+
content: item.parseResult.content,
|
|
223
|
+
name: item.parseResult.name,
|
|
224
|
+
formulaList: item.parseResult.formulaList
|
|
225
|
+
})) : ''].filter(Boolean).join('')
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
var addTableScope = function addTableScope(record) {
|
|
230
|
+
var nextItem = tableToScopeItem(record);
|
|
231
|
+
var key = getScopeKey(nextItem);
|
|
232
|
+
setTableScope(function (list) {
|
|
233
|
+
if (fixedTableScope.some(function (item) {
|
|
234
|
+
return getScopeKey(item) === key;
|
|
235
|
+
})) {
|
|
236
|
+
return list;
|
|
237
|
+
}
|
|
238
|
+
if (list.some(function (item) {
|
|
239
|
+
return getScopeKey(item) === key;
|
|
240
|
+
})) {
|
|
241
|
+
return list.filter(function (item) {
|
|
242
|
+
return getScopeKey(item) !== key;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return [].concat(_toConsumableArray(list), [nextItem]);
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
var removeTableScope = function removeTableScope(target) {
|
|
249
|
+
var key = getScopeKey(target);
|
|
250
|
+
setTableScope(function (list) {
|
|
251
|
+
return list.filter(function (item) {
|
|
252
|
+
return getScopeKey(item) !== key;
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
var resolveAvailableTables = function () {
|
|
257
|
+
var _ref3 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2() {
|
|
258
|
+
var scope, result;
|
|
259
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
260
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
261
|
+
case 0:
|
|
262
|
+
scope = tableScopeRef.current;
|
|
263
|
+
if (scope.length) {
|
|
264
|
+
_context2.next = 1;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
return _context2.abrupt("return", defaultAvailableTables || []);
|
|
268
|
+
case 1:
|
|
269
|
+
_context2.next = 2;
|
|
270
|
+
return Promise.all(scope.map(function () {
|
|
271
|
+
var _ref4 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(item) {
|
|
272
|
+
var _fixedTable$columns;
|
|
273
|
+
var fixedTable, sourceTables, table, columns, _t, _t2;
|
|
274
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
275
|
+
while (1) switch (_context.prev = _context.next) {
|
|
276
|
+
case 0:
|
|
277
|
+
fixedTable = (defaultAvailableTables || []).find(function (table) {
|
|
278
|
+
return getScopeKey(tableToScopeItem(table, true)) === getScopeKey(item);
|
|
279
|
+
});
|
|
280
|
+
if (!(fixedTable !== null && fixedTable !== void 0 && (_fixedTable$columns = fixedTable.columns) !== null && _fixedTable$columns !== void 0 && _fixedTable$columns.length)) {
|
|
281
|
+
_context.next = 1;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
return _context.abrupt("return", fixedTable);
|
|
285
|
+
case 1:
|
|
286
|
+
_context.next = 2;
|
|
287
|
+
return getTables === null || getTables === void 0 ? void 0 : getTables(item.datasourceId);
|
|
288
|
+
case 2:
|
|
289
|
+
_t = _context.sent;
|
|
290
|
+
if (_t) {
|
|
291
|
+
_context.next = 3;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
_t = [];
|
|
295
|
+
case 3:
|
|
296
|
+
sourceTables = _t;
|
|
297
|
+
table = sourceTables.find(function (current) {
|
|
298
|
+
return "".concat(current.id || current.tableId || current.name) === "".concat(item.tableId);
|
|
299
|
+
}) || {
|
|
300
|
+
id: item.tableId,
|
|
301
|
+
name: item.tableName || item.tableId,
|
|
302
|
+
name_zh: item.tableNameZh || item.tableName || item.tableId,
|
|
303
|
+
alias: item.tableAlias,
|
|
304
|
+
tableUuid: item.tableUuid,
|
|
305
|
+
datasourceId: item.datasourceId,
|
|
306
|
+
datasourceName: item.datasourceName
|
|
307
|
+
};
|
|
308
|
+
_context.next = 4;
|
|
309
|
+
return getColumns === null || getColumns === void 0 ? void 0 : getColumns(table, item.datasourceId);
|
|
310
|
+
case 4:
|
|
311
|
+
_t2 = _context.sent;
|
|
312
|
+
if (_t2) {
|
|
313
|
+
_context.next = 5;
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
_t2 = [];
|
|
317
|
+
case 5:
|
|
318
|
+
columns = _t2;
|
|
319
|
+
return _context.abrupt("return", _objectSpread(_objectSpread({}, table), {}, {
|
|
320
|
+
id: table.id || item.tableId,
|
|
321
|
+
name: table.name || item.tableName,
|
|
322
|
+
name_zh: table.name_zh || item.tableNameZh,
|
|
323
|
+
table: table.name || item.tableName,
|
|
324
|
+
tableId: table.id || item.tableId,
|
|
325
|
+
alias: table.alias || item.tableAlias,
|
|
326
|
+
tableUuid: table.tableUuid || item.tableUuid,
|
|
327
|
+
datasourceId: item.datasourceId,
|
|
328
|
+
datasourceName: item.datasourceName,
|
|
329
|
+
columns: Array.isArray(columns) ? columns : []
|
|
330
|
+
}));
|
|
331
|
+
case 6:
|
|
332
|
+
case "end":
|
|
333
|
+
return _context.stop();
|
|
334
|
+
}
|
|
335
|
+
}, _callee);
|
|
336
|
+
}));
|
|
337
|
+
return function (_x) {
|
|
338
|
+
return _ref4.apply(this, arguments);
|
|
339
|
+
};
|
|
340
|
+
}()));
|
|
341
|
+
case 2:
|
|
342
|
+
result = _context2.sent;
|
|
343
|
+
return _context2.abrupt("return", result.filter(function (item) {
|
|
344
|
+
return (item === null || item === void 0 ? void 0 : item.id) || (item === null || item === void 0 ? void 0 : item.name);
|
|
345
|
+
}));
|
|
346
|
+
case 3:
|
|
347
|
+
case "end":
|
|
348
|
+
return _context2.stop();
|
|
349
|
+
}
|
|
350
|
+
}, _callee2);
|
|
351
|
+
}));
|
|
352
|
+
return function resolveAvailableTables() {
|
|
353
|
+
return _ref3.apply(this, arguments);
|
|
354
|
+
};
|
|
355
|
+
}();
|
|
356
|
+
var submit = function () {
|
|
357
|
+
var _ref5 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3() {
|
|
358
|
+
var sql, now, assistantId, userMessage, loadingMessage, nextMessages, rawText, errorContext, result, availableTables, scopedTableScope, controller, _applyResult, aborted, errorMessage, assistantErrorContent, _t3, _t4, _t5;
|
|
359
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
360
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
361
|
+
case 0:
|
|
362
|
+
sql = input.trim();
|
|
363
|
+
if (!(!sql || loading)) {
|
|
364
|
+
_context3.next = 1;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
return _context3.abrupt("return");
|
|
368
|
+
case 1:
|
|
369
|
+
now = Date.now();
|
|
370
|
+
assistantId = "assistant-".concat(now);
|
|
371
|
+
userMessage = {
|
|
372
|
+
id: "user-".concat(now),
|
|
373
|
+
role: 'user',
|
|
374
|
+
content: sql
|
|
375
|
+
};
|
|
376
|
+
loadingMessage = {
|
|
377
|
+
id: assistantId,
|
|
378
|
+
role: 'assistant',
|
|
379
|
+
content: __('customColumn.sqlChatThinking'),
|
|
380
|
+
status: 'loading'
|
|
381
|
+
};
|
|
382
|
+
nextMessages = [].concat(_toConsumableArray(messages), [userMessage]);
|
|
383
|
+
setMessages([].concat(_toConsumableArray(nextMessages), [loadingMessage]));
|
|
384
|
+
setInput('');
|
|
385
|
+
setLoading(true);
|
|
386
|
+
rawText = '';
|
|
387
|
+
errorContext = '';
|
|
388
|
+
_context3.prev = 2;
|
|
389
|
+
_context3.next = 3;
|
|
390
|
+
return resolveAvailableTables();
|
|
391
|
+
case 3:
|
|
392
|
+
availableTables = _context3.sent;
|
|
393
|
+
scopedTableScope = tableScopeRef.current;
|
|
394
|
+
if (!(typeof streamParser === 'function')) {
|
|
395
|
+
_context3.next = 11;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
controller = new AbortController();
|
|
399
|
+
abortControllerRef.current = controller;
|
|
400
|
+
cancelByUserRef.current = false;
|
|
401
|
+
_context3.prev = 4;
|
|
402
|
+
_context3.next = 5;
|
|
403
|
+
return streamParser({
|
|
404
|
+
sql: sql,
|
|
405
|
+
messages: getChatMessages(nextMessages),
|
|
406
|
+
availableTables: availableTables,
|
|
407
|
+
tableScope: scopedTableScope
|
|
408
|
+
}, {
|
|
409
|
+
signal: controller.signal,
|
|
410
|
+
onDelta: function onDelta(delta) {
|
|
411
|
+
rawText += delta || '';
|
|
412
|
+
var content = extractJsonStringValue(rawText, 'content') || __('customColumn.sqlChatThinking');
|
|
413
|
+
var generatingConfig = /"formulaList"\s*:/.test(rawText);
|
|
414
|
+
setMessages(function (list) {
|
|
415
|
+
return list.map(function (item) {
|
|
416
|
+
return item.id === assistantId ? _objectSpread(_objectSpread({}, item), {}, {
|
|
417
|
+
content: generatingConfig && !content ? __('customColumn.sqlChatGeneratingConfig') : content,
|
|
418
|
+
status: generatingConfig ? undefined : 'loading',
|
|
419
|
+
generatingConfig: generatingConfig
|
|
420
|
+
}) : item;
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
case 5:
|
|
426
|
+
result = _context3.sent;
|
|
427
|
+
_context3.next = 7;
|
|
428
|
+
break;
|
|
429
|
+
case 6:
|
|
430
|
+
_context3.prev = 6;
|
|
431
|
+
_t3 = _context3["catch"](4);
|
|
432
|
+
errorContext = (_t3 === null || _t3 === void 0 ? void 0 : _t3.message) || '';
|
|
433
|
+
throw _t3;
|
|
434
|
+
case 7:
|
|
435
|
+
if (result) {
|
|
436
|
+
_context3.next = 10;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
_context3.prev = 8;
|
|
440
|
+
result = parseFormulaSqlStreamText(rawText);
|
|
441
|
+
_context3.next = 10;
|
|
442
|
+
break;
|
|
443
|
+
case 9:
|
|
444
|
+
_context3.prev = 9;
|
|
445
|
+
_t4 = _context3["catch"](8);
|
|
446
|
+
errorContext = errorContext || (_t4 === null || _t4 === void 0 ? void 0 : _t4.message) || '';
|
|
447
|
+
throw _t4;
|
|
448
|
+
case 10:
|
|
449
|
+
_context3.next = 13;
|
|
450
|
+
break;
|
|
451
|
+
case 11:
|
|
452
|
+
_context3.next = 12;
|
|
453
|
+
return onSubmit(sql, availableTables, scopedTableScope);
|
|
454
|
+
case 12:
|
|
455
|
+
_applyResult = _context3.sent;
|
|
456
|
+
result = typeof _applyResult === 'function' ? {
|
|
457
|
+
formulaList: [],
|
|
458
|
+
applyAction: _applyResult
|
|
459
|
+
} : undefined;
|
|
460
|
+
case 13:
|
|
461
|
+
setMessages(function (list) {
|
|
462
|
+
return list.map(function (item) {
|
|
463
|
+
var _result;
|
|
464
|
+
return item.id === assistantId ? _objectSpread(_objectSpread({}, item), {}, {
|
|
465
|
+
role: 'assistant',
|
|
466
|
+
content: result ? result.content || __('customColumn.sqlChatSuccess') : __('customColumn.sqlChatSuccessApplied'),
|
|
467
|
+
status: undefined,
|
|
468
|
+
parseResult: result,
|
|
469
|
+
applyAction: (_result = result) === null || _result === void 0 ? void 0 : _result.applyAction,
|
|
470
|
+
generatingConfig: false
|
|
471
|
+
}) : item;
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
_context3.next = 15;
|
|
475
|
+
break;
|
|
476
|
+
case 14:
|
|
477
|
+
_context3.prev = 14;
|
|
478
|
+
_t5 = _context3["catch"](2);
|
|
479
|
+
aborted = (_t5 === null || _t5 === void 0 ? void 0 : _t5.name) === 'AbortError';
|
|
480
|
+
errorMessage = aborted && cancelByUserRef.current ? __('customColumn.sqlChatCanceled') : (_t5 === null || _t5 === void 0 ? void 0 : _t5.message) || __('customColumn.sqlParseFailed');
|
|
481
|
+
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('');
|
|
482
|
+
setMessages(function (list) {
|
|
483
|
+
return list.map(function (item) {
|
|
484
|
+
return item.id === assistantId ? _objectSpread(_objectSpread({}, item), {}, {
|
|
485
|
+
role: 'assistant',
|
|
486
|
+
content: assistantErrorContent,
|
|
487
|
+
status: undefined,
|
|
488
|
+
generatingConfig: false
|
|
489
|
+
}) : item;
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
case 15:
|
|
493
|
+
_context3.prev = 15;
|
|
494
|
+
abortControllerRef.current = null;
|
|
495
|
+
setLoading(false);
|
|
496
|
+
focusInput();
|
|
497
|
+
return _context3.finish(15);
|
|
498
|
+
case 16:
|
|
499
|
+
case "end":
|
|
500
|
+
return _context3.stop();
|
|
501
|
+
}
|
|
502
|
+
}, _callee3, null, [[2, 14, 15, 16], [4, 6], [8, 9]]);
|
|
503
|
+
}));
|
|
504
|
+
return function submit() {
|
|
505
|
+
return _ref5.apply(this, arguments);
|
|
506
|
+
};
|
|
507
|
+
}();
|
|
508
|
+
var applyResult = function () {
|
|
509
|
+
var _ref6 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(message) {
|
|
510
|
+
var apply;
|
|
511
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
512
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
513
|
+
case 0:
|
|
514
|
+
if (!(!message.parseResult && !message.applyAction)) {
|
|
515
|
+
_context4.next = 1;
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
Toast.warning(__('customColumn.sqlParseInvalid'));
|
|
519
|
+
return _context4.abrupt("return");
|
|
520
|
+
case 1:
|
|
521
|
+
if (!message.applyAction) {
|
|
522
|
+
_context4.next = 2;
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
message.applyAction();
|
|
526
|
+
_context4.next = 4;
|
|
527
|
+
break;
|
|
528
|
+
case 2:
|
|
529
|
+
if (!(message.parseResult && Array.isArray(message.parseResult.formulaList) && message.parseResult.formulaList.length)) {
|
|
530
|
+
_context4.next = 4;
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
_context4.next = 3;
|
|
534
|
+
return onSubmit(message.parseResult);
|
|
535
|
+
case 3:
|
|
536
|
+
apply = _context4.sent;
|
|
537
|
+
if (typeof apply === 'function') {
|
|
538
|
+
apply();
|
|
539
|
+
}
|
|
540
|
+
case 4:
|
|
541
|
+
_context4.next = 5;
|
|
542
|
+
return new Promise(function (resolve) {
|
|
543
|
+
return window.requestAnimationFrame(function () {
|
|
544
|
+
return resolve();
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
case 5:
|
|
548
|
+
onClose();
|
|
549
|
+
case 6:
|
|
550
|
+
case "end":
|
|
551
|
+
return _context4.stop();
|
|
552
|
+
}
|
|
553
|
+
}, _callee4);
|
|
554
|
+
}));
|
|
555
|
+
return function applyResult(_x2) {
|
|
556
|
+
return _ref6.apply(this, arguments);
|
|
557
|
+
};
|
|
558
|
+
}();
|
|
559
|
+
var showAddTable = function () {
|
|
560
|
+
var _ref7 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee6(event) {
|
|
561
|
+
var triggerNode, nextSourceTable;
|
|
562
|
+
return _regeneratorRuntime.wrap(function (_context6) {
|
|
563
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
564
|
+
case 0:
|
|
565
|
+
if (!scopeLoading) {
|
|
566
|
+
_context6.next = 1;
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
return _context6.abrupt("return");
|
|
570
|
+
case 1:
|
|
571
|
+
triggerNode = event.currentTarget;
|
|
572
|
+
nextSourceTable = scopeSourceTable;
|
|
573
|
+
if (!(!nextSourceTable.length && Array.isArray(datasource) && datasource.length)) {
|
|
574
|
+
_context6.next = 5;
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
setScopeLoading(true);
|
|
578
|
+
_context6.prev = 2;
|
|
579
|
+
_context6.next = 3;
|
|
580
|
+
return Promise.all(datasource.map(function () {
|
|
581
|
+
var _ref8 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(item) {
|
|
582
|
+
var _t6, _t7, _t8, _t9, _t0;
|
|
583
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
584
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
585
|
+
case 0:
|
|
586
|
+
_t6 = _objectSpread;
|
|
587
|
+
_t7 = _objectSpread({}, item);
|
|
588
|
+
_t8 = {};
|
|
589
|
+
_context5.next = 1;
|
|
590
|
+
return getTables === null || getTables === void 0 ? void 0 : getTables(item.datasourceId);
|
|
591
|
+
case 1:
|
|
592
|
+
_t9 = _context5.sent;
|
|
593
|
+
if (_t9) {
|
|
594
|
+
_context5.next = 2;
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
_t9 = [];
|
|
598
|
+
case 2:
|
|
599
|
+
_t0 = _t9.map(function (table) {
|
|
600
|
+
return _objectSpread(_objectSpread({}, table), {}, {
|
|
601
|
+
datasourceId: item.datasourceId,
|
|
602
|
+
datasourceName: item.datasourceName
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
return _context5.abrupt("return", _t6(_t7, _t8, {
|
|
606
|
+
children: _t0
|
|
607
|
+
}));
|
|
608
|
+
case 3:
|
|
609
|
+
case "end":
|
|
610
|
+
return _context5.stop();
|
|
611
|
+
}
|
|
612
|
+
}, _callee5);
|
|
613
|
+
}));
|
|
614
|
+
return function (_x4) {
|
|
615
|
+
return _ref8.apply(this, arguments);
|
|
616
|
+
};
|
|
617
|
+
}()));
|
|
618
|
+
case 3:
|
|
619
|
+
nextSourceTable = _context6.sent;
|
|
620
|
+
setScopeSourceTable(nextSourceTable);
|
|
621
|
+
case 4:
|
|
622
|
+
_context6.prev = 4;
|
|
623
|
+
setScopeLoading(false);
|
|
624
|
+
return _context6.finish(4);
|
|
625
|
+
case 5:
|
|
626
|
+
openTablePopup === null || openTablePopup === void 0 || openTablePopup(triggerNode, _jsx(SelectTable, {
|
|
627
|
+
data: datasource || [],
|
|
628
|
+
sourceTable: nextSourceTable || [],
|
|
629
|
+
tableFlat: tableFlat,
|
|
630
|
+
multiple: true,
|
|
631
|
+
lockedValues: fixedTableScope.map(scopeItemToTableValue),
|
|
632
|
+
selectedValues: mergedTableScope.map(scopeItemToTableValue),
|
|
633
|
+
value: {
|
|
634
|
+
datasourceId: '',
|
|
635
|
+
datasourceName: '',
|
|
636
|
+
name: '',
|
|
637
|
+
name_zh: '',
|
|
638
|
+
tableUuid: '',
|
|
639
|
+
id: '',
|
|
640
|
+
alias: ''
|
|
641
|
+
},
|
|
642
|
+
onChange: addTableScope
|
|
643
|
+
}));
|
|
644
|
+
case 6:
|
|
645
|
+
case "end":
|
|
646
|
+
return _context6.stop();
|
|
647
|
+
}
|
|
648
|
+
}, _callee6, null, [[2,, 4, 5]]);
|
|
649
|
+
}));
|
|
650
|
+
return function showAddTable(_x3) {
|
|
651
|
+
return _ref7.apply(this, arguments);
|
|
652
|
+
};
|
|
653
|
+
}();
|
|
654
|
+
return _jsxs("div", {
|
|
655
|
+
className: 'Sqb-FormulaSqlImport',
|
|
656
|
+
children: [_jsxs("div", {
|
|
657
|
+
className: 'Sqb-FormulaSqlImport-header',
|
|
658
|
+
children: [_jsx("div", {
|
|
659
|
+
className: 'Sqb-FormulaSqlImport-title',
|
|
660
|
+
children: __('customColumn.sqlChatTitle')
|
|
661
|
+
}), _jsx("div", {
|
|
662
|
+
className: 'Sqb-FormulaSqlImport-desc',
|
|
663
|
+
children: __('customColumn.sqlChatDesc')
|
|
664
|
+
})]
|
|
665
|
+
}), _jsxs("div", {
|
|
666
|
+
className: 'Sqb-FormulaSqlImport-scope',
|
|
667
|
+
children: [_jsxs("div", {
|
|
668
|
+
className: 'Sqb-FormulaSqlImport-scopeHeader',
|
|
669
|
+
children: [_jsx("span", {
|
|
670
|
+
children: __('customColumn.sqlChatTableScope')
|
|
671
|
+
}), _jsx("button", {
|
|
672
|
+
type: 'button',
|
|
673
|
+
className: 'Sqb-FormulaSqlImport-addTable',
|
|
674
|
+
disabled: scopeLoading,
|
|
675
|
+
onClick: showAddTable,
|
|
676
|
+
children: _jsx(AddIcon, {
|
|
677
|
+
width: 16,
|
|
678
|
+
height: 16
|
|
679
|
+
})
|
|
680
|
+
})]
|
|
681
|
+
}), _jsx("div", {
|
|
682
|
+
className: cx('Sqb-FormulaSqlImport-scopeSelected', {
|
|
683
|
+
'Sqb-FormulaSqlImport-scopeSelected--expanded': scopeExpanded
|
|
684
|
+
}),
|
|
685
|
+
children: mergedTableScope.length ? mergedTableScope.map(function (item) {
|
|
686
|
+
return _jsxs("button", {
|
|
687
|
+
type: 'button',
|
|
688
|
+
className: cx('Sqb-FormulaSqlImport-scopeTag', {
|
|
689
|
+
'Sqb-FormulaSqlImport-scopeTag--fixed': item.fixed
|
|
690
|
+
}),
|
|
691
|
+
onClick: function onClick() {
|
|
692
|
+
if (!item.fixed) removeTableScope(item);
|
|
693
|
+
},
|
|
694
|
+
children: [_jsxs("span", {
|
|
695
|
+
children: [item.datasourceName ? "".concat(item.datasourceName, ".") : '', item.tableNameZh || item.tableName || item.tableId, item.tableAlias ? "(".concat(item.tableAlias, ")") : '']
|
|
696
|
+
}), !item.fixed ? _jsx("span", {
|
|
697
|
+
className: 'Sqb-FormulaSqlImport-scopeTagClose',
|
|
698
|
+
children: "\xD7"
|
|
699
|
+
}) : null]
|
|
700
|
+
}, getScopeKey(item));
|
|
701
|
+
}) : _jsx("span", {
|
|
702
|
+
className: 'Sqb-FormulaSqlImport-scopeHint',
|
|
703
|
+
children: __('customColumn.sqlChatScopeFallback')
|
|
704
|
+
})
|
|
705
|
+
}), mergedTableScope.length > 1 ? _jsx(Button, {
|
|
706
|
+
type: 'link',
|
|
707
|
+
className: 'Sqb-FormulaSqlImport-scopeToggle',
|
|
708
|
+
title: scopeExpanded ? '收起表范围' : '展开表范围',
|
|
709
|
+
onClick: function onClick() {
|
|
710
|
+
return setScopeExpanded(function (value) {
|
|
711
|
+
return !value;
|
|
712
|
+
});
|
|
713
|
+
},
|
|
714
|
+
children: scopeExpanded ? '收起' : '展开'
|
|
715
|
+
}) : null]
|
|
716
|
+
}), _jsx("div", {
|
|
717
|
+
className: 'Sqb-FormulaSqlImport-messages',
|
|
718
|
+
ref: messagesRef,
|
|
719
|
+
children: messages.length ? messages.map(function (message) {
|
|
720
|
+
var _message$parseResult;
|
|
721
|
+
var isAssistant = message.role === 'assistant';
|
|
722
|
+
return _jsxs("div", {
|
|
723
|
+
className: "Sqb-FormulaSqlImport-message Sqb-FormulaSqlImport-message--".concat(message.role),
|
|
724
|
+
children: [_jsx("div", {
|
|
725
|
+
className: 'Sqb-FormulaSqlImport-avatar',
|
|
726
|
+
children: isAssistant ? 'AI' : __('customColumn.sqlChatMe')
|
|
727
|
+
}), _jsxs("div", {
|
|
728
|
+
className: 'Sqb-FormulaSqlImport-bubble',
|
|
729
|
+
children: [_jsx("div", {
|
|
730
|
+
className: 'Sqb-FormulaSqlImport-messageText',
|
|
731
|
+
children: message.status === 'loading' ? _jsx("span", {
|
|
732
|
+
className: 'Sqb-FormulaSqlImport-loading',
|
|
733
|
+
children: message.content
|
|
734
|
+
}) : message.content
|
|
735
|
+
}), message.generatingConfig ? _jsx("div", {
|
|
736
|
+
className: 'Sqb-FormulaSqlImport-status',
|
|
737
|
+
children: __('customColumn.sqlChatGeneratingConfig')
|
|
738
|
+
}) : null, message.parseResult || message.applyAction ? _jsxs("div", {
|
|
739
|
+
className: 'Sqb-FormulaSqlImport-proposal',
|
|
740
|
+
children: [(_message$parseResult = message.parseResult) !== null && _message$parseResult !== void 0 && (_message$parseResult = _message$parseResult.formulaList) !== null && _message$parseResult !== void 0 && _message$parseResult.length ? _jsx(Button, {
|
|
741
|
+
size: 'small',
|
|
742
|
+
onClick: function onClick() {
|
|
743
|
+
return onPreviewFormula === null || onPreviewFormula === void 0 ? void 0 : onPreviewFormula(message.parseResult);
|
|
744
|
+
},
|
|
745
|
+
children: __('customColumn.sqlChatPreview')
|
|
746
|
+
}) : null, _jsx(Button, {
|
|
747
|
+
size: 'small',
|
|
748
|
+
primary: true,
|
|
749
|
+
onClick: function onClick() {
|
|
750
|
+
return applyResult(message);
|
|
751
|
+
},
|
|
752
|
+
children: __('customColumn.sqlChatApply')
|
|
753
|
+
})]
|
|
754
|
+
}) : null]
|
|
755
|
+
})]
|
|
756
|
+
}, message.id);
|
|
757
|
+
}) : _jsx("div", {
|
|
758
|
+
className: 'Sqb-FormulaSqlImport-empty',
|
|
759
|
+
children: __('customColumn.sqlChatEmpty')
|
|
760
|
+
})
|
|
761
|
+
}), _jsxs("div", {
|
|
762
|
+
className: 'Sqb-FormulaSqlImport-composer',
|
|
763
|
+
children: [_jsx(Input.TextArea, {
|
|
764
|
+
ref: inputRef,
|
|
765
|
+
rows: 6,
|
|
766
|
+
value: input,
|
|
767
|
+
placeholder: __('customColumn.sqlChatPlaceholder'),
|
|
768
|
+
onChange: function onChange(value) {
|
|
769
|
+
setInput(value);
|
|
770
|
+
},
|
|
771
|
+
onKeyDown: function onKeyDown(event) {
|
|
772
|
+
if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing || event.keyCode === 229) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
event.preventDefault();
|
|
776
|
+
submit();
|
|
777
|
+
}
|
|
778
|
+
}), _jsx("button", {
|
|
779
|
+
type: 'button',
|
|
780
|
+
className: 'Sqb-FormulaSqlImport-send',
|
|
781
|
+
disabled: loading || !input.trim(),
|
|
782
|
+
"aria-label": __('customColumn.sqlChatSend'),
|
|
783
|
+
onClick: submit,
|
|
784
|
+
children: _jsx(UpArrowIcon, {
|
|
785
|
+
width: 14,
|
|
786
|
+
height: 14
|
|
787
|
+
})
|
|
788
|
+
})]
|
|
789
|
+
})]
|
|
790
|
+
});
|
|
791
|
+
};
|
|
792
|
+
var parentPopupLockCounts = new WeakMap();
|
|
42
793
|
var CASE_FIXED_OPERATORS = ['case', 'when', 'then', 'else', 'end'];
|
|
43
794
|
var LOGIC_FIXED_OPERATORS = ['(', ')'];
|
|
44
795
|
var LOGIC_REQUIRED_OPERATORS = ['(', ')'];
|
|
@@ -138,11 +889,11 @@ var getTokenStyleByClassName = function getTokenStyleByClassName(className, extr
|
|
|
138
889
|
} : {}), extraStyle);
|
|
139
890
|
};
|
|
140
891
|
var FormulaList = forwardRef(function (props, ref) {
|
|
141
|
-
var _storage$_metabaseCop;
|
|
142
|
-
var
|
|
143
|
-
|
|
144
|
-
checkedItemsCount =
|
|
145
|
-
setCheckedItemsCount =
|
|
892
|
+
var _storage$_metabaseCop, _store$preProps, _store$preProps2;
|
|
893
|
+
var _useState13 = useState((storage === null || storage === void 0 || (_storage$_metabaseCop = storage._metabaseCopyItems) === null || _storage$_metabaseCop === void 0 ? void 0 : _storage$_metabaseCop.length) || 0),
|
|
894
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
895
|
+
checkedItemsCount = _useState14[0],
|
|
896
|
+
setCheckedItemsCount = _useState14[1];
|
|
146
897
|
useEffect(function () {
|
|
147
898
|
var _storage$_metabaseCop3;
|
|
148
899
|
var handler = function handler() {
|
|
@@ -179,7 +930,8 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
179
930
|
enableCopy = _props$enableCopy === void 0 ? true : _props$enableCopy,
|
|
180
931
|
_props$enableZoom = props.enableZoom,
|
|
181
932
|
enableZoom = _props$enableZoom === void 0 ? true : _props$enableZoom,
|
|
182
|
-
parentPopupChannel = props.parentPopupChannel
|
|
933
|
+
parentPopupChannel = props.parentPopupChannel,
|
|
934
|
+
onAddSql = props.onAddSql;
|
|
183
935
|
var parentPopupLockCountRef = useRef(0);
|
|
184
936
|
var parentPopupUnlockTimerRef = useRef(null);
|
|
185
937
|
var setParentClosable = function setParentClosable(closable) {
|
|
@@ -190,6 +942,16 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
190
942
|
}
|
|
191
943
|
store.setClosable(closable);
|
|
192
944
|
};
|
|
945
|
+
var changeSharedParentLockCount = function changeSharedParentLockCount(delta) {
|
|
946
|
+
if (!parentPopupChannel) return;
|
|
947
|
+
var counts = parentPopupLockCounts.get(store) || {
|
|
948
|
+
primary: 0,
|
|
949
|
+
secondary: 0
|
|
950
|
+
};
|
|
951
|
+
counts[parentPopupChannel] = Math.max(0, counts[parentPopupChannel] + delta);
|
|
952
|
+
parentPopupLockCounts.set(store, counts);
|
|
953
|
+
setParentClosable(counts[parentPopupChannel] === 0);
|
|
954
|
+
};
|
|
193
955
|
var lockParentPopup = function lockParentPopup() {
|
|
194
956
|
if (!parentPopupChannel) return;
|
|
195
957
|
if (parentPopupUnlockTimerRef.current) {
|
|
@@ -197,19 +959,16 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
197
959
|
parentPopupUnlockTimerRef.current = null;
|
|
198
960
|
}
|
|
199
961
|
parentPopupLockCountRef.current += 1;
|
|
200
|
-
|
|
201
|
-
setParentClosable(false);
|
|
202
|
-
}
|
|
962
|
+
changeSharedParentLockCount(1);
|
|
203
963
|
};
|
|
204
964
|
var unlockParentPopup = function unlockParentPopup() {
|
|
205
965
|
var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
206
966
|
if (!parentPopupChannel) return;
|
|
207
967
|
var runUnlock = function runUnlock() {
|
|
208
968
|
parentPopupUnlockTimerRef.current = null;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
969
|
+
if (parentPopupLockCountRef.current === 0) return;
|
|
970
|
+
parentPopupLockCountRef.current -= 1;
|
|
971
|
+
changeSharedParentLockCount(-1);
|
|
213
972
|
};
|
|
214
973
|
if (delay > 0) {
|
|
215
974
|
if (parentPopupUnlockTimerRef.current) {
|
|
@@ -259,8 +1018,8 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
259
1018
|
parentPopupUnlockTimerRef.current = null;
|
|
260
1019
|
}
|
|
261
1020
|
if (parentPopupLockCountRef.current > 0) {
|
|
1021
|
+
changeSharedParentLockCount(-parentPopupLockCountRef.current);
|
|
262
1022
|
parentPopupLockCountRef.current = 0;
|
|
263
|
-
setParentClosable(true);
|
|
264
1023
|
}
|
|
265
1024
|
};
|
|
266
1025
|
}, [parentPopupChannel]);
|
|
@@ -284,13 +1043,26 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
284
1043
|
});
|
|
285
1044
|
return map;
|
|
286
1045
|
}, [otherTypes]);
|
|
287
|
-
var
|
|
288
|
-
return normalizeAndOrStructure(value || [])
|
|
1046
|
+
var normalizedStructureValue = useMemo(function () {
|
|
1047
|
+
return normalizeAndOrStructure(value || []);
|
|
289
1048
|
}, [value]);
|
|
1049
|
+
var normalizedExpressionValue = useMemo(function () {
|
|
1050
|
+
return normalizeExpressionAtoms(normalizedStructureValue, data);
|
|
1051
|
+
}, [normalizedStructureValue, data]);
|
|
1052
|
+
var normalizedValue = useMemo(function () {
|
|
1053
|
+
return normalizedExpressionValue.map(syncAtomQuotes);
|
|
1054
|
+
}, [normalizedExpressionValue]);
|
|
290
1055
|
var caseList = normalizedValue;
|
|
291
1056
|
var initialValueRef = useRef(cloneDeep(caseList));
|
|
292
1057
|
var caseListRef = useRef(caseList);
|
|
293
1058
|
caseListRef.current = caseList;
|
|
1059
|
+
useEffect(function () {
|
|
1060
|
+
if (isEqual(normalizedExpressionValue, normalizedStructureValue)) return;
|
|
1061
|
+
var quotes = normalizedValue.map(function (item) {
|
|
1062
|
+
return getAtomDisplayText(item);
|
|
1063
|
+
}).join(' ');
|
|
1064
|
+
onChange === null || onChange === void 0 || onChange(normalizedValue, quotes);
|
|
1065
|
+
}, [normalizedExpressionValue, normalizedStructureValue, normalizedValue, onChange]);
|
|
294
1066
|
var hasFormulaSqlAction = Boolean(store.showFormulaSql && store.hasFormulaSqlCode);
|
|
295
1067
|
var hasFormulaDiffAction = Boolean(store.showFormulaDiff && store.hasFormulaDiffCode);
|
|
296
1068
|
var operatorList = useMemo(function () {
|
|
@@ -299,15 +1071,15 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
299
1071
|
}
|
|
300
1072
|
return __operatorList;
|
|
301
1073
|
}, [store.operatorList]);
|
|
302
|
-
var
|
|
303
|
-
|
|
304
|
-
sqlLoading =
|
|
305
|
-
setSqlLoading =
|
|
306
|
-
var
|
|
307
|
-
|
|
308
|
-
diffLoading =
|
|
309
|
-
setDiffLoading =
|
|
310
|
-
var
|
|
1074
|
+
var _useState15 = useState(false),
|
|
1075
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
1076
|
+
sqlLoading = _useState16[0],
|
|
1077
|
+
setSqlLoading = _useState16[1];
|
|
1078
|
+
var _useState17 = useState(false),
|
|
1079
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
1080
|
+
diffLoading = _useState18[0],
|
|
1081
|
+
setDiffLoading = _useState18[1];
|
|
1082
|
+
var _useState19 = useState(function () {
|
|
311
1083
|
if (!enableCopy) {
|
|
312
1084
|
return false;
|
|
313
1085
|
}
|
|
@@ -316,25 +1088,25 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
316
1088
|
}
|
|
317
1089
|
return store.copyType.includes(_type);
|
|
318
1090
|
}),
|
|
319
|
-
|
|
320
|
-
isCopy =
|
|
321
|
-
setIsCopy =
|
|
1091
|
+
_useState20 = _slicedToArray(_useState19, 2),
|
|
1092
|
+
isCopy = _useState20[0],
|
|
1093
|
+
setIsCopy = _useState20[1];
|
|
322
1094
|
var formulaList = useMemo(function () {
|
|
323
1095
|
return getObjTem(store.formulaTemplates);
|
|
324
1096
|
}, [store.formulaTemplates]);
|
|
325
|
-
var
|
|
326
|
-
|
|
327
|
-
filterVal =
|
|
328
|
-
setFilterVal =
|
|
1097
|
+
var _useState21 = useState(''),
|
|
1098
|
+
_useState22 = _slicedToArray(_useState21, 2),
|
|
1099
|
+
filterVal = _useState22[0],
|
|
1100
|
+
setFilterVal = _useState22[1];
|
|
329
1101
|
function getSelectDisplayText(item) {
|
|
330
1102
|
var displayField = item.displayField || 'value';
|
|
331
1103
|
var getOptionText = function getOptionText(value) {
|
|
332
|
-
var
|
|
1104
|
+
var _ref9, _option$displayField;
|
|
333
1105
|
var option = (item.options || []).find(function (currentOption) {
|
|
334
1106
|
return currentOption.value === value;
|
|
335
1107
|
});
|
|
336
1108
|
if (!option) return value || '';
|
|
337
|
-
return String((
|
|
1109
|
+
return String((_ref9 = (_option$displayField = option[displayField]) !== null && _option$displayField !== void 0 ? _option$displayField : option.value) !== null && _ref9 !== void 0 ? _ref9 : '');
|
|
338
1110
|
};
|
|
339
1111
|
if (Array.isArray(item.val)) {
|
|
340
1112
|
return item.val.map(function (currentValue) {
|
|
@@ -499,8 +1271,8 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
499
1271
|
var withSyncedQuotes = function withSyncedQuotes(item) {
|
|
500
1272
|
return _withSyncedQuotesInner(item, new WeakMap());
|
|
501
1273
|
};
|
|
502
|
-
var setCaseList = function setCaseList(
|
|
503
|
-
var nextData = data.map(function (item) {
|
|
1274
|
+
var setCaseList = function setCaseList(atoms) {
|
|
1275
|
+
var nextData = normalizeExpressionAtoms(atoms, data).map(function (item) {
|
|
504
1276
|
return withSyncedQuotes(item);
|
|
505
1277
|
});
|
|
506
1278
|
var quotes = nextData.map(function (item) {
|
|
@@ -516,13 +1288,13 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
516
1288
|
setCaseList(nextList);
|
|
517
1289
|
};
|
|
518
1290
|
var getFormulaSqlText = function getFormulaSqlText(result) {
|
|
519
|
-
var
|
|
1291
|
+
var _ref0, _result$sql;
|
|
520
1292
|
if (typeof result === 'string') return result;
|
|
521
1293
|
if (!result) return '';
|
|
522
|
-
return String((
|
|
1294
|
+
return String((_ref0 = (_result$sql = result.sql) !== null && _result$sql !== void 0 ? _result$sql : result.code) !== null && _ref0 !== void 0 ? _ref0 : '');
|
|
523
1295
|
};
|
|
524
1296
|
var getFormulaDiffData = function getFormulaDiffData(result) {
|
|
525
|
-
var _result$oldCode,
|
|
1297
|
+
var _result$oldCode, _ref1, _result$newCode;
|
|
526
1298
|
if (typeof result === 'string') {
|
|
527
1299
|
return {
|
|
528
1300
|
oldCode: '',
|
|
@@ -537,7 +1309,7 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
537
1309
|
}
|
|
538
1310
|
return {
|
|
539
1311
|
oldCode: String((_result$oldCode = result.oldCode) !== null && _result$oldCode !== void 0 ? _result$oldCode : ''),
|
|
540
|
-
newCode: String((
|
|
1312
|
+
newCode: String((_ref1 = (_result$newCode = result.newCode) !== null && _result$newCode !== void 0 ? _result$newCode : result.code) !== null && _ref1 !== void 0 ? _ref1 : '')
|
|
541
1313
|
};
|
|
542
1314
|
};
|
|
543
1315
|
var normalizeFormulaValueForOutput = function normalizeFormulaValueForOutput() {
|
|
@@ -552,31 +1324,97 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
552
1324
|
var getInitialFormulaValue = function getInitialFormulaValue() {
|
|
553
1325
|
return cloneDeep(normalizeFormulaValueForOutput(initialValueRef.current || []));
|
|
554
1326
|
};
|
|
1327
|
+
var getMetasContext = function getMetasContext() {
|
|
1328
|
+
var _store$getCurrentMeta;
|
|
1329
|
+
return normalizeLegacySummarizeForSave(splitByUnion(((_store$getCurrentMeta = store.getCurrentMetaList) === null || _store$getCurrentMeta === void 0 ? void 0 : _store$getCurrentMeta.call(store)) || []));
|
|
1330
|
+
};
|
|
1331
|
+
var parseFormulaSql = (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.parseFormulaSql;
|
|
1332
|
+
var parseFormulaSqlStream = (_store$preProps2 = store.preProps) === null || _store$preProps2 === void 0 ? void 0 : _store$preProps2.parseFormulaSqlStream;
|
|
1333
|
+
var resolvedAddSql = onAddSql || typeof parseFormulaSql === 'function' || typeof parseFormulaSqlStream === 'function' ? (function () {
|
|
1334
|
+
var _ref10 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee7(sqlOrResult, availableTables, tableScope) {
|
|
1335
|
+
var result;
|
|
1336
|
+
return _regeneratorRuntime.wrap(function (_context7) {
|
|
1337
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
1338
|
+
case 0:
|
|
1339
|
+
if (!(typeof sqlOrResult === 'string')) {
|
|
1340
|
+
_context7.next = 4;
|
|
1341
|
+
break;
|
|
1342
|
+
}
|
|
1343
|
+
if (!onAddSql) {
|
|
1344
|
+
_context7.next = 1;
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
return _context7.abrupt("return", onAddSql(sqlOrResult, availableTables, tableScope));
|
|
1348
|
+
case 1:
|
|
1349
|
+
_context7.next = 2;
|
|
1350
|
+
return parseFormulaSql({
|
|
1351
|
+
sql: sqlOrResult,
|
|
1352
|
+
availableTables: availableTables !== null && availableTables !== void 0 && availableTables.length ? availableTables : data,
|
|
1353
|
+
tableScope: tableScope,
|
|
1354
|
+
metasContext: getMetasContext(),
|
|
1355
|
+
constantList: store.constantList || [],
|
|
1356
|
+
formulaTemplates: store.formulaTemplates || [],
|
|
1357
|
+
operatorList: store.operatorList || [],
|
|
1358
|
+
otherTypes: otherTypes
|
|
1359
|
+
});
|
|
1360
|
+
case 2:
|
|
1361
|
+
result = _context7.sent;
|
|
1362
|
+
if (!(!result || !Array.isArray(result.formulaList))) {
|
|
1363
|
+
_context7.next = 3;
|
|
1364
|
+
break;
|
|
1365
|
+
}
|
|
1366
|
+
Toast.warning(__('customColumn.sqlParseInvalid'));
|
|
1367
|
+
throw new Error('INVALID_FORMULA_SQL_RESULT');
|
|
1368
|
+
case 3:
|
|
1369
|
+
return _context7.abrupt("return", function () {
|
|
1370
|
+
return setCaseList(result.formulaList);
|
|
1371
|
+
});
|
|
1372
|
+
case 4:
|
|
1373
|
+
if (!(!sqlOrResult || !Array.isArray(sqlOrResult.formulaList))) {
|
|
1374
|
+
_context7.next = 5;
|
|
1375
|
+
break;
|
|
1376
|
+
}
|
|
1377
|
+
Toast.warning(__('customColumn.sqlParseInvalid'));
|
|
1378
|
+
throw new Error('INVALID_FORMULA_SQL_RESULT');
|
|
1379
|
+
case 5:
|
|
1380
|
+
return _context7.abrupt("return", function () {
|
|
1381
|
+
return setCaseList(sqlOrResult.formulaList);
|
|
1382
|
+
});
|
|
1383
|
+
case 6:
|
|
1384
|
+
case "end":
|
|
1385
|
+
return _context7.stop();
|
|
1386
|
+
}
|
|
1387
|
+
}, _callee7);
|
|
1388
|
+
}));
|
|
1389
|
+
return function (_x5, _x6, _x7) {
|
|
1390
|
+
return _ref10.apply(this, arguments);
|
|
1391
|
+
};
|
|
1392
|
+
}()) : undefined;
|
|
555
1393
|
var showFormulaSql = function () {
|
|
556
|
-
var
|
|
557
|
-
var result, sql,
|
|
558
|
-
return _regeneratorRuntime.wrap(function (
|
|
559
|
-
while (1) switch (
|
|
1394
|
+
var _ref11 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee8() {
|
|
1395
|
+
var result, sql, _t1;
|
|
1396
|
+
return _regeneratorRuntime.wrap(function (_context8) {
|
|
1397
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
560
1398
|
case 0:
|
|
561
1399
|
if (!(!hasFormulaSqlAction || sqlLoading)) {
|
|
562
|
-
|
|
1400
|
+
_context8.next = 1;
|
|
563
1401
|
break;
|
|
564
1402
|
}
|
|
565
|
-
return
|
|
1403
|
+
return _context8.abrupt("return");
|
|
566
1404
|
case 1:
|
|
567
1405
|
setSqlLoading(true);
|
|
568
|
-
|
|
569
|
-
|
|
1406
|
+
_context8.prev = 2;
|
|
1407
|
+
_context8.next = 3;
|
|
570
1408
|
return store.getFormulaSqlCode(getCurrentFormulaValue());
|
|
571
1409
|
case 3:
|
|
572
|
-
result =
|
|
1410
|
+
result = _context8.sent;
|
|
573
1411
|
sql = getFormulaSqlText(result);
|
|
574
1412
|
if (sql) {
|
|
575
|
-
|
|
1413
|
+
_context8.next = 4;
|
|
576
1414
|
break;
|
|
577
1415
|
}
|
|
578
1416
|
Toast.warning('暂无可展示的SQL');
|
|
579
|
-
return
|
|
1417
|
+
return _context8.abrupt("return");
|
|
580
1418
|
case 4:
|
|
581
1419
|
openChildModal({
|
|
582
1420
|
title: '查看SQL',
|
|
@@ -597,54 +1435,161 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
597
1435
|
}),
|
|
598
1436
|
onClose: function onClose() {}
|
|
599
1437
|
});
|
|
600
|
-
|
|
1438
|
+
_context8.next = 6;
|
|
601
1439
|
break;
|
|
602
1440
|
case 5:
|
|
603
|
-
|
|
604
|
-
|
|
1441
|
+
_context8.prev = 5;
|
|
1442
|
+
_t1 = _context8["catch"](2);
|
|
605
1443
|
Toast.error('获取SQL失败');
|
|
606
1444
|
case 6:
|
|
607
|
-
|
|
1445
|
+
_context8.prev = 6;
|
|
608
1446
|
setSqlLoading(false);
|
|
609
|
-
return
|
|
1447
|
+
return _context8.finish(6);
|
|
610
1448
|
case 7:
|
|
611
1449
|
case "end":
|
|
612
|
-
return
|
|
1450
|
+
return _context8.stop();
|
|
613
1451
|
}
|
|
614
|
-
},
|
|
1452
|
+
}, _callee8, null, [[2, 5, 6, 7]]);
|
|
615
1453
|
}));
|
|
616
1454
|
return function showFormulaSql() {
|
|
617
|
-
return
|
|
1455
|
+
return _ref11.apply(this, arguments);
|
|
618
1456
|
};
|
|
619
1457
|
}();
|
|
1458
|
+
var previewFormulaConfig = function previewFormulaConfig(result) {
|
|
1459
|
+
var _result$formulaList;
|
|
1460
|
+
if (!(result !== null && result !== void 0 && (_result$formulaList = result.formulaList) !== null && _result$formulaList !== void 0 && _result$formulaList.length)) return;
|
|
1461
|
+
openChildModal({
|
|
1462
|
+
title: __('customColumn.sqlChatPreview'),
|
|
1463
|
+
transparentMask: true,
|
|
1464
|
+
className: 'Sqb-FormulaSqlConfigPreviewModal',
|
|
1465
|
+
content: _jsx(Provider, {
|
|
1466
|
+
value: _objectSpread(_objectSpread({}, store), {}, {
|
|
1467
|
+
snapshotMode: true
|
|
1468
|
+
}),
|
|
1469
|
+
children: _jsx("div", {
|
|
1470
|
+
className: 'Sqb-FormulaSqlConfigPreview',
|
|
1471
|
+
children: _jsx(FormulaList, {
|
|
1472
|
+
value: cloneDeep(result.formulaList),
|
|
1473
|
+
data: data,
|
|
1474
|
+
exitData: exitData,
|
|
1475
|
+
customTypes: _customTypes,
|
|
1476
|
+
otherTypes: otherTypes,
|
|
1477
|
+
check: check,
|
|
1478
|
+
_type: _type,
|
|
1479
|
+
showPreview: false,
|
|
1480
|
+
enableCopy: false,
|
|
1481
|
+
enableZoom: false,
|
|
1482
|
+
onChange: function onChange() {}
|
|
1483
|
+
})
|
|
1484
|
+
})
|
|
1485
|
+
}),
|
|
1486
|
+
modalWidth: 760,
|
|
1487
|
+
modalHeight: 420,
|
|
1488
|
+
onClose: function onClose() {}
|
|
1489
|
+
});
|
|
1490
|
+
};
|
|
1491
|
+
var showAddSql = function showAddSql() {
|
|
1492
|
+
var _store$sourceTable;
|
|
1493
|
+
if (!resolvedAddSql) {
|
|
1494
|
+
Toast.warning(__('customColumn.sqlChatMissingParser'));
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
closePopup();
|
|
1498
|
+
if (!((_store$sourceTable = store.sourceTable) !== null && _store$sourceTable !== void 0 && _store$sourceTable.length)) {
|
|
1499
|
+
store.getSourceTable(store.sourceList || []);
|
|
1500
|
+
}
|
|
1501
|
+
var modalInstance;
|
|
1502
|
+
modalInstance = openChildModal({
|
|
1503
|
+
title: __('customColumn.addSql'),
|
|
1504
|
+
transparentMask: true,
|
|
1505
|
+
className: 'Sqb-FormulaSqlImportModal',
|
|
1506
|
+
content: _jsx(SqlImportContent, {
|
|
1507
|
+
onSubmit: resolvedAddSql,
|
|
1508
|
+
onClose: function onClose() {
|
|
1509
|
+
var _modalInstance2;
|
|
1510
|
+
return (_modalInstance2 = modalInstance) === null || _modalInstance2 === void 0 ? void 0 : _modalInstance2.close();
|
|
1511
|
+
},
|
|
1512
|
+
datasource: store.sourceList,
|
|
1513
|
+
sourceTable: store.sourceTable,
|
|
1514
|
+
tableFlat: store.tableFlat,
|
|
1515
|
+
openTablePopup: function openTablePopup(node, content) {
|
|
1516
|
+
store.setPopup2({
|
|
1517
|
+
visible: true,
|
|
1518
|
+
node: node,
|
|
1519
|
+
content: content
|
|
1520
|
+
});
|
|
1521
|
+
},
|
|
1522
|
+
closeTablePopup: function closeTablePopup() {
|
|
1523
|
+
return store.setPopup2({
|
|
1524
|
+
visible: false
|
|
1525
|
+
});
|
|
1526
|
+
},
|
|
1527
|
+
onPreviewFormula: previewFormulaConfig,
|
|
1528
|
+
getTables: function getTables(datasourceId) {
|
|
1529
|
+
return store.fetchDataset(datasourceId);
|
|
1530
|
+
},
|
|
1531
|
+
getColumns: function getColumns(table, datasourceId) {
|
|
1532
|
+
return new Promise(function (resolve) {
|
|
1533
|
+
var nextTable = _objectSpread(_objectSpread({}, table), {}, {
|
|
1534
|
+
name: table.name || table.tableName || table.id || table.tableId
|
|
1535
|
+
});
|
|
1536
|
+
store.fetchColumns(nextTable, datasourceId, [], function (columns) {
|
|
1537
|
+
return resolve(columns || []);
|
|
1538
|
+
}, false);
|
|
1539
|
+
});
|
|
1540
|
+
},
|
|
1541
|
+
defaultAvailableTables: data,
|
|
1542
|
+
streamParser: typeof parseFormulaSqlStream === 'function' ? function (_ref12, handlers) {
|
|
1543
|
+
var sql = _ref12.sql,
|
|
1544
|
+
messages = _ref12.messages,
|
|
1545
|
+
availableTables = _ref12.availableTables,
|
|
1546
|
+
tableScope = _ref12.tableScope;
|
|
1547
|
+
return parseFormulaSqlStream({
|
|
1548
|
+
sql: sql,
|
|
1549
|
+
messages: messages,
|
|
1550
|
+
availableTables: availableTables || data,
|
|
1551
|
+
tableScope: tableScope || [],
|
|
1552
|
+
metasContext: getMetasContext(),
|
|
1553
|
+
constantList: store.constantList || [],
|
|
1554
|
+
formulaTemplates: store.formulaTemplates || [],
|
|
1555
|
+
operatorList: store.operatorList || [],
|
|
1556
|
+
otherTypes: otherTypes
|
|
1557
|
+
}, handlers);
|
|
1558
|
+
} : undefined
|
|
1559
|
+
}),
|
|
1560
|
+
modalWidth: 900,
|
|
1561
|
+
modalHeight: 600,
|
|
1562
|
+
onClose: function onClose() {}
|
|
1563
|
+
});
|
|
1564
|
+
};
|
|
620
1565
|
var showFormulaDiff = function () {
|
|
621
|
-
var
|
|
622
|
-
var result, _getFormulaDiffData, oldCode, newCode,
|
|
623
|
-
return _regeneratorRuntime.wrap(function (
|
|
624
|
-
while (1) switch (
|
|
1566
|
+
var _ref13 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee9() {
|
|
1567
|
+
var result, _getFormulaDiffData, oldCode, newCode, _t10;
|
|
1568
|
+
return _regeneratorRuntime.wrap(function (_context9) {
|
|
1569
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
625
1570
|
case 0:
|
|
626
1571
|
if (!(!hasFormulaDiffAction || diffLoading)) {
|
|
627
|
-
|
|
1572
|
+
_context9.next = 1;
|
|
628
1573
|
break;
|
|
629
1574
|
}
|
|
630
|
-
return
|
|
1575
|
+
return _context9.abrupt("return");
|
|
631
1576
|
case 1:
|
|
632
1577
|
setDiffLoading(true);
|
|
633
|
-
|
|
634
|
-
|
|
1578
|
+
_context9.prev = 2;
|
|
1579
|
+
_context9.next = 3;
|
|
635
1580
|
return store.getFormulaDiffCode({
|
|
636
1581
|
oldCode: getInitialFormulaValue(),
|
|
637
1582
|
newCode: getCurrentFormulaValue()
|
|
638
1583
|
});
|
|
639
1584
|
case 3:
|
|
640
|
-
result =
|
|
1585
|
+
result = _context9.sent;
|
|
641
1586
|
_getFormulaDiffData = getFormulaDiffData(result), oldCode = _getFormulaDiffData.oldCode, newCode = _getFormulaDiffData.newCode;
|
|
642
1587
|
if (!(!oldCode && !newCode)) {
|
|
643
|
-
|
|
1588
|
+
_context9.next = 4;
|
|
644
1589
|
break;
|
|
645
1590
|
}
|
|
646
1591
|
Toast.warning('暂无可展示的对比结果');
|
|
647
|
-
return
|
|
1592
|
+
return _context9.abrupt("return");
|
|
648
1593
|
case 4:
|
|
649
1594
|
openChildModal({
|
|
650
1595
|
title: '对比结果',
|
|
@@ -655,24 +1600,24 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
655
1600
|
}),
|
|
656
1601
|
onClose: function onClose() {}
|
|
657
1602
|
});
|
|
658
|
-
|
|
1603
|
+
_context9.next = 6;
|
|
659
1604
|
break;
|
|
660
1605
|
case 5:
|
|
661
|
-
|
|
662
|
-
|
|
1606
|
+
_context9.prev = 5;
|
|
1607
|
+
_t10 = _context9["catch"](2);
|
|
663
1608
|
Toast.error('获取对比结果失败');
|
|
664
1609
|
case 6:
|
|
665
|
-
|
|
1610
|
+
_context9.prev = 6;
|
|
666
1611
|
setDiffLoading(false);
|
|
667
|
-
return
|
|
1612
|
+
return _context9.finish(6);
|
|
668
1613
|
case 7:
|
|
669
1614
|
case "end":
|
|
670
|
-
return
|
|
1615
|
+
return _context9.stop();
|
|
671
1616
|
}
|
|
672
|
-
},
|
|
1617
|
+
}, _callee9, null, [[2, 5, 6, 7]]);
|
|
673
1618
|
}));
|
|
674
1619
|
return function showFormulaDiff() {
|
|
675
|
-
return
|
|
1620
|
+
return _ref13.apply(this, arguments);
|
|
676
1621
|
};
|
|
677
1622
|
}();
|
|
678
1623
|
var renderTokenContent = function renderTokenContent(children) {
|
|
@@ -687,23 +1632,23 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
687
1632
|
var childModalZIndex = getTopLayerZIndex() + 1;
|
|
688
1633
|
var modalInstance;
|
|
689
1634
|
var CaseWhenZoomEditor = function CaseWhenZoomEditor() {
|
|
690
|
-
var
|
|
1635
|
+
var _useState23 = useState(function () {
|
|
691
1636
|
return cloneDeep(value);
|
|
692
1637
|
}),
|
|
693
|
-
|
|
694
|
-
draftValue =
|
|
695
|
-
setDraftValue =
|
|
696
|
-
var
|
|
697
|
-
|
|
698
|
-
activeZoomRegionKey =
|
|
699
|
-
setActiveZoomRegionKey =
|
|
1638
|
+
_useState24 = _slicedToArray(_useState23, 2),
|
|
1639
|
+
draftValue = _useState24[0],
|
|
1640
|
+
setDraftValue = _useState24[1];
|
|
1641
|
+
var _useState25 = useState(null),
|
|
1642
|
+
_useState26 = _slicedToArray(_useState25, 2),
|
|
1643
|
+
activeZoomRegionKey = _useState26[0],
|
|
1644
|
+
setActiveZoomRegionKey = _useState26[1];
|
|
700
1645
|
var updateDraftValue = function updateDraftValue(nextValue) {
|
|
701
1646
|
setDraftValue(withSyncedQuotes(nextValue));
|
|
702
1647
|
};
|
|
703
1648
|
var handleOk = function handleOk() {
|
|
704
|
-
var
|
|
1649
|
+
var _modalInstance3, _modalInstance3$close;
|
|
705
1650
|
updateAtomAt(index, cloneDeep(draftValue));
|
|
706
|
-
(
|
|
1651
|
+
(_modalInstance3 = modalInstance) === null || _modalInstance3 === void 0 || (_modalInstance3$close = _modalInstance3.close) === null || _modalInstance3$close === void 0 || _modalInstance3$close.call(_modalInstance3);
|
|
707
1652
|
};
|
|
708
1653
|
return _jsx(Provider, {
|
|
709
1654
|
value: store,
|
|
@@ -819,8 +1764,8 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
819
1764
|
className: 'sqb-formula-list-zoom-editor-cancel',
|
|
820
1765
|
style: ZOOM_FOOTER_CANCEL_STYLE,
|
|
821
1766
|
onClick: function onClick() {
|
|
822
|
-
var
|
|
823
|
-
return (
|
|
1767
|
+
var _modalInstance4, _modalInstance4$close;
|
|
1768
|
+
return (_modalInstance4 = modalInstance) === null || _modalInstance4 === void 0 || (_modalInstance4$close = _modalInstance4.close) === null || _modalInstance4$close === void 0 ? void 0 : _modalInstance4$close.call(_modalInstance4);
|
|
824
1769
|
},
|
|
825
1770
|
children: "\u53D6\u6D88"
|
|
826
1771
|
}), _jsx(Button, {
|
|
@@ -851,21 +1796,21 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
851
1796
|
var childModalZIndex = getTopLayerZIndex() + 1;
|
|
852
1797
|
var modalInstance;
|
|
853
1798
|
var FormulaListZoomEditor = function FormulaListZoomEditor() {
|
|
854
|
-
var
|
|
1799
|
+
var _useState27 = useState(function () {
|
|
855
1800
|
return cloneDeep(caseList || []);
|
|
856
1801
|
}),
|
|
857
|
-
|
|
858
|
-
draftList =
|
|
859
|
-
setDraftList =
|
|
1802
|
+
_useState28 = _slicedToArray(_useState27, 2),
|
|
1803
|
+
draftList = _useState28[0],
|
|
1804
|
+
setDraftList = _useState28[1];
|
|
860
1805
|
var updateDraftList = function updateDraftList(nextList) {
|
|
861
1806
|
setDraftList(nextList.map(function (item) {
|
|
862
1807
|
return withSyncedQuotes(item);
|
|
863
1808
|
}));
|
|
864
1809
|
};
|
|
865
1810
|
var handleOk = function handleOk() {
|
|
866
|
-
var
|
|
1811
|
+
var _modalInstance5, _modalInstance5$close;
|
|
867
1812
|
setCaseList(cloneDeep(draftList));
|
|
868
|
-
(
|
|
1813
|
+
(_modalInstance5 = modalInstance) === null || _modalInstance5 === void 0 || (_modalInstance5$close = _modalInstance5.close) === null || _modalInstance5$close === void 0 || _modalInstance5$close.call(_modalInstance5);
|
|
869
1814
|
};
|
|
870
1815
|
return _jsx(Provider, {
|
|
871
1816
|
value: store,
|
|
@@ -897,8 +1842,8 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
897
1842
|
className: 'sqb-formula-list-zoom-editor-cancel',
|
|
898
1843
|
style: ZOOM_FOOTER_CANCEL_STYLE,
|
|
899
1844
|
onClick: function onClick() {
|
|
900
|
-
var
|
|
901
|
-
return (
|
|
1845
|
+
var _modalInstance6, _modalInstance6$close;
|
|
1846
|
+
return (_modalInstance6 = modalInstance) === null || _modalInstance6 === void 0 || (_modalInstance6$close = _modalInstance6.close) === null || _modalInstance6$close === void 0 ? void 0 : _modalInstance6$close.call(_modalInstance6);
|
|
902
1847
|
},
|
|
903
1848
|
children: "\u53D6\u6D88"
|
|
904
1849
|
}), _jsx(Button, {
|
|
@@ -1131,43 +2076,43 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1131
2076
|
}
|
|
1132
2077
|
});
|
|
1133
2078
|
};
|
|
1134
|
-
var
|
|
1135
|
-
|
|
1136
|
-
ind =
|
|
1137
|
-
setInd =
|
|
2079
|
+
var _useState29 = useState(-1),
|
|
2080
|
+
_useState30 = _slicedToArray(_useState29, 2),
|
|
2081
|
+
ind = _useState30[0],
|
|
2082
|
+
setInd = _useState30[1];
|
|
1138
2083
|
var filterCustomType = store.filterCustomType;
|
|
1139
2084
|
var _ref = useRef(null);
|
|
1140
|
-
var
|
|
2085
|
+
var _useState31 = useState({
|
|
1141
2086
|
isError: false
|
|
1142
2087
|
}),
|
|
1143
|
-
|
|
1144
|
-
errorInfo =
|
|
1145
|
-
setErrorInfo =
|
|
1146
|
-
var
|
|
1147
|
-
|
|
1148
|
-
isCheck =
|
|
1149
|
-
setIsCheck =
|
|
2088
|
+
_useState32 = _slicedToArray(_useState31, 2),
|
|
2089
|
+
errorInfo = _useState32[0],
|
|
2090
|
+
setErrorInfo = _useState32[1];
|
|
2091
|
+
var _useState33 = useState(false),
|
|
2092
|
+
_useState34 = _slicedToArray(_useState33, 2),
|
|
2093
|
+
isCheck = _useState34[0],
|
|
2094
|
+
setIsCheck = _useState34[1];
|
|
1150
2095
|
var myInstanceIdRef = useRef(Math.random().toString(36).slice(2));
|
|
1151
|
-
var
|
|
1152
|
-
|
|
1153
|
-
hoveredCaseGroupKey =
|
|
1154
|
-
setHoveredCaseGroupKey =
|
|
1155
|
-
var
|
|
1156
|
-
|
|
1157
|
-
globalSelectionActive =
|
|
1158
|
-
setGlobalSelectionActive =
|
|
1159
|
-
var
|
|
1160
|
-
|
|
1161
|
-
globalSelectionOwner =
|
|
1162
|
-
setGlobalSelectionOwner =
|
|
1163
|
-
var
|
|
1164
|
-
|
|
1165
|
-
selectedIndices =
|
|
1166
|
-
setSelectedIndices =
|
|
1167
|
-
var
|
|
1168
|
-
|
|
1169
|
-
hoveredCopyIndex =
|
|
1170
|
-
setHoveredCopyIndex =
|
|
2096
|
+
var _useState35 = useState(null),
|
|
2097
|
+
_useState36 = _slicedToArray(_useState35, 2),
|
|
2098
|
+
hoveredCaseGroupKey = _useState36[0],
|
|
2099
|
+
setHoveredCaseGroupKey = _useState36[1];
|
|
2100
|
+
var _useState37 = useState(!!window.__sqb_selection_active__),
|
|
2101
|
+
_useState38 = _slicedToArray(_useState37, 2),
|
|
2102
|
+
globalSelectionActive = _useState38[0],
|
|
2103
|
+
setGlobalSelectionActive = _useState38[1];
|
|
2104
|
+
var _useState39 = useState(window.__sqb_selection_owner__ || null),
|
|
2105
|
+
_useState40 = _slicedToArray(_useState39, 2),
|
|
2106
|
+
globalSelectionOwner = _useState40[0],
|
|
2107
|
+
setGlobalSelectionOwner = _useState40[1];
|
|
2108
|
+
var _useState41 = useState([]),
|
|
2109
|
+
_useState42 = _slicedToArray(_useState41, 2),
|
|
2110
|
+
selectedIndices = _useState42[0],
|
|
2111
|
+
setSelectedIndices = _useState42[1];
|
|
2112
|
+
var _useState43 = useState(null),
|
|
2113
|
+
_useState44 = _slicedToArray(_useState43, 2),
|
|
2114
|
+
hoveredCopyIndex = _useState44[0],
|
|
2115
|
+
setHoveredCopyIndex = _useState44[1];
|
|
1171
2116
|
var getCaseGroupEnd = function getCaseGroupEnd(list, startIndex) {
|
|
1172
2117
|
var depth = 0;
|
|
1173
2118
|
for (var index = startIndex; index < list.length; index++) {
|
|
@@ -1424,6 +2369,11 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1424
2369
|
value: [val],
|
|
1425
2370
|
theme: ColumnsPopupThemeEnum.skyBlue,
|
|
1426
2371
|
readonly: snapshotMode,
|
|
2372
|
+
onValueSync: function onValueSync(fields) {
|
|
2373
|
+
var _caseList = caseList.slice();
|
|
2374
|
+
_caseList[i] = fields[0];
|
|
2375
|
+
setCaseList(_caseList);
|
|
2376
|
+
},
|
|
1427
2377
|
onSelect: function onSelect(fields) {
|
|
1428
2378
|
var _caseList = caseList.slice();
|
|
1429
2379
|
_caseList[i] = fields[0];
|
|
@@ -1580,10 +2530,10 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1580
2530
|
title: __('metabase.prompt'),
|
|
1581
2531
|
content: __('customColumn.confirmDelete'),
|
|
1582
2532
|
onOk: function () {
|
|
1583
|
-
var _onOk = _asyncToGenerator(_regeneratorRuntime.mark(function
|
|
2533
|
+
var _onOk = _asyncToGenerator(_regeneratorRuntime.mark(function _callee0() {
|
|
1584
2534
|
var selectedIndexSet, _caseList;
|
|
1585
|
-
return _regeneratorRuntime.wrap(function (
|
|
1586
|
-
while (1) switch (
|
|
2535
|
+
return _regeneratorRuntime.wrap(function (_context0) {
|
|
2536
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
1587
2537
|
case 0:
|
|
1588
2538
|
selectedIndexSet = new Set(selectedIndices);
|
|
1589
2539
|
_caseList = caseList.filter(function (_, index) {
|
|
@@ -1593,9 +2543,9 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1593
2543
|
initPaste();
|
|
1594
2544
|
case 1:
|
|
1595
2545
|
case "end":
|
|
1596
|
-
return
|
|
2546
|
+
return _context0.stop();
|
|
1597
2547
|
}
|
|
1598
|
-
},
|
|
2548
|
+
}, _callee0);
|
|
1599
2549
|
}));
|
|
1600
2550
|
function onOk() {
|
|
1601
2551
|
return _onOk.apply(this, arguments);
|
|
@@ -1696,10 +2646,10 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1696
2646
|
};
|
|
1697
2647
|
var showNotExists = function showNotExists(i) {
|
|
1698
2648
|
var _caseList$i, _caseList$i2;
|
|
1699
|
-
var _store$
|
|
1700
|
-
notExistsToolbar = _store$
|
|
1701
|
-
toolbar = _store$
|
|
1702
|
-
other = _objectWithoutProperties(_store$
|
|
2649
|
+
var _store$preProps3 = store.preProps,
|
|
2650
|
+
notExistsToolbar = _store$preProps3.notExistsToolbar,
|
|
2651
|
+
toolbar = _store$preProps3.toolbar,
|
|
2652
|
+
other = _objectWithoutProperties(_store$preProps3, _excluded2);
|
|
1703
2653
|
var _value = ((_caseList$i = caseList[i]) === null || _caseList$i === void 0 ? void 0 : _caseList$i.notExists) || [];
|
|
1704
2654
|
var oldList = cloneDeep(((_caseList$i2 = caseList[i]) === null || _caseList$i2 === void 0 ? void 0 : _caseList$i2.notExists) || []);
|
|
1705
2655
|
var childModalZIndex = getTopLayerZIndex() + 1;
|
|
@@ -1711,12 +2661,18 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1711
2661
|
content: _jsx(_Fragment, {
|
|
1712
2662
|
children: _jsx(Metabase, _objectSpread(_objectSpread({}, other), {}, {
|
|
1713
2663
|
popupZIndex: childModalZIndex + 1,
|
|
2664
|
+
readonly: snapshotMode,
|
|
2665
|
+
snapshotMode: snapshotMode,
|
|
1714
2666
|
notExistsColumns: exitData,
|
|
1715
2667
|
isExit: true,
|
|
1716
2668
|
toolbar: _toolbar,
|
|
1717
2669
|
btnText: __('SqlQueryBuilder.confirm'),
|
|
1718
2670
|
value: cloneDeep(_value),
|
|
1719
2671
|
onOk: function onOk(newList) {
|
|
2672
|
+
if (snapshotMode) {
|
|
2673
|
+
o.close();
|
|
2674
|
+
return;
|
|
2675
|
+
}
|
|
1720
2676
|
try {
|
|
1721
2677
|
if (isEqual(newList, oldList)) {
|
|
1722
2678
|
o.close();
|
|
@@ -1741,13 +2697,13 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1741
2697
|
};
|
|
1742
2698
|
var showSubQuery = function showSubQuery(i) {
|
|
1743
2699
|
var _caseList$i3, _caseList$i4;
|
|
1744
|
-
var _store$
|
|
1745
|
-
subToolbar = _store$
|
|
1746
|
-
notExistsColumns = _store$
|
|
1747
|
-
showFields = _store$
|
|
1748
|
-
isExit = _store$
|
|
1749
|
-
toolbar = _store$
|
|
1750
|
-
other = _objectWithoutProperties(_store$
|
|
2700
|
+
var _store$preProps4 = store.preProps,
|
|
2701
|
+
subToolbar = _store$preProps4.subToolbar,
|
|
2702
|
+
notExistsColumns = _store$preProps4.notExistsColumns,
|
|
2703
|
+
showFields = _store$preProps4.showFields,
|
|
2704
|
+
isExit = _store$preProps4.isExit,
|
|
2705
|
+
toolbar = _store$preProps4.toolbar,
|
|
2706
|
+
other = _objectWithoutProperties(_store$preProps4, _excluded3);
|
|
1751
2707
|
var _value = ((_caseList$i3 = caseList[i]) === null || _caseList$i3 === void 0 ? void 0 : _caseList$i3.subQuery) || [];
|
|
1752
2708
|
var oldList = cloneDeep(((_caseList$i4 = caseList[i]) === null || _caseList$i4 === void 0 ? void 0 : _caseList$i4.subQuery) || []);
|
|
1753
2709
|
var childModalZIndex = getTopLayerZIndex() + 1;
|
|
@@ -1759,6 +2715,8 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1759
2715
|
content: _jsx(_Fragment, {
|
|
1760
2716
|
children: _jsx(Metabase, _objectSpread(_objectSpread({}, other), {}, {
|
|
1761
2717
|
popupZIndex: childModalZIndex + 1,
|
|
2718
|
+
readonly: snapshotMode,
|
|
2719
|
+
snapshotMode: snapshotMode,
|
|
1762
2720
|
isExit: true,
|
|
1763
2721
|
isSubquery: true,
|
|
1764
2722
|
notExistsColumns: exitData,
|
|
@@ -1767,6 +2725,10 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1767
2725
|
btnText: __('SqlQueryBuilder.confirm'),
|
|
1768
2726
|
value: cloneDeep(_value),
|
|
1769
2727
|
onOk: function onOk(newList) {
|
|
2728
|
+
if (snapshotMode) {
|
|
2729
|
+
o.close();
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
1770
2732
|
try {
|
|
1771
2733
|
if (isEqual(newList, oldList)) {
|
|
1772
2734
|
o.close();
|
|
@@ -1981,7 +2943,7 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
1981
2943
|
}
|
|
1982
2944
|
if (type === AtomsTypeEnum.EXPRESSION) {
|
|
1983
2945
|
var quotes = getAtomDisplayText(v);
|
|
1984
|
-
if (~['早于', '晚于', '在'].indexOf(v.condition) && v.rhs.length > 1) {
|
|
2946
|
+
if (~['大于', '小于', '大于或等于', '小于或等于', '早于', '晚于', '在'].indexOf(v.condition) && v.rhs.length > 1) {
|
|
1985
2947
|
var _getAtomDisplayText$s;
|
|
1986
2948
|
var nextList = caseList.slice();
|
|
1987
2949
|
nextList[index].rhs = [nextList[index].rhs[0]];
|
|
@@ -2386,6 +3348,12 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
2386
3348
|
disabled: diffLoading,
|
|
2387
3349
|
onClick: showFormulaDiff,
|
|
2388
3350
|
children: "\u5BF9\u6BD4\u7ED3\u679C"
|
|
3351
|
+
}), (hasFormulaSqlAction || hasFormulaDiffAction || resolvedAddSql) && _jsx(Button, {
|
|
3352
|
+
className: 'Sqb-FormulaAddSqlAction',
|
|
3353
|
+
size: 'small',
|
|
3354
|
+
type: 'link',
|
|
3355
|
+
onClick: showAddSql,
|
|
3356
|
+
children: __('customColumn.addSql')
|
|
2389
3357
|
})]
|
|
2390
3358
|
}), !snapshotMode && _jsx("div", {
|
|
2391
3359
|
className: 'errorMsg mt-2',
|