@gingkoo/pandora-metabase 1.0.158-alpha.10 → 1.0.158-alpha.11
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/formula/index.js +51 -10
- package/lib/cjs/components/dialog/formula/index.less +7 -0
- package/lib/cjs/components/dialog/formula-list/index.d.ts +1 -0
- package/lib/cjs/components/dialog/formula-list/index.js +84 -107
- package/lib/cjs/components/dialog/formula-list/utils.d.ts +2 -1
- package/lib/cjs/components/dialog/formula-list/utils.js +228 -51
- package/lib/cjs/components/metabase/index.js +68 -58
- package/lib/cjs/components/metabase/index.less +7 -0
- package/lib/cjs/components/modules/components/header.d.ts +2 -1
- package/lib/cjs/components/modules/components/header.js +6 -2
- package/lib/cjs/components/modules/join-data.js +7 -1
- package/lib/cjs/components/sql-syntax-confirm.d.ts +14 -0
- package/lib/cjs/components/sql-syntax-confirm.js +98 -0
- package/lib/cjs/hooks/use-state.js +33 -27
- package/lib/cjs/index.d.ts +4 -2
- package/lib/cjs/index.js +11 -1
- package/lib/cjs/locale/en.js +19 -0
- package/lib/cjs/locale/zh.js +19 -0
- package/lib/cjs/types.d.ts +6 -0
- package/lib/cjs/utils/transformSql.d.ts +40 -1
- package/lib/cjs/utils/transformSql.js +677 -3
- package/lib/cjs/utils.d.ts +1 -1
- package/lib/cjs/utils.js +3 -1
- package/lib/es/components/dialog/formula/index.js +52 -11
- package/lib/es/components/dialog/formula/index.less +7 -0
- package/lib/es/components/dialog/formula-list/index.d.ts +1 -0
- package/lib/es/components/dialog/formula-list/index.js +84 -107
- package/lib/es/components/dialog/formula-list/utils.d.ts +2 -1
- package/lib/es/components/dialog/formula-list/utils.js +228 -51
- package/lib/es/components/metabase/index.js +68 -58
- package/lib/es/components/metabase/index.less +7 -0
- package/lib/es/components/modules/components/header.d.ts +2 -1
- package/lib/es/components/modules/components/header.js +6 -2
- package/lib/es/components/modules/join-data.js +7 -1
- package/lib/es/components/sql-syntax-confirm.d.ts +14 -0
- package/lib/es/components/sql-syntax-confirm.js +92 -0
- package/lib/es/hooks/use-state.js +33 -27
- package/lib/es/index.d.ts +4 -2
- package/lib/es/index.js +6 -2
- package/lib/es/locale/en.js +19 -0
- package/lib/es/locale/zh.js +19 -0
- package/lib/es/types.d.ts +6 -0
- package/lib/es/utils/transformSql.d.ts +40 -1
- package/lib/es/utils/transformSql.js +676 -2
- package/lib/es/utils.d.ts +1 -1
- package/lib/es/utils.js +3 -1
- package/package.json +1 -1
|
@@ -34,7 +34,7 @@ var VisualBox = _styledComponents["default"].div.attrs({
|
|
|
34
34
|
className: 'visual-box scroller'
|
|
35
35
|
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])([""])));
|
|
36
36
|
var CaseEditor = _react["default"].forwardRef(function (props, ref) {
|
|
37
|
-
var
|
|
37
|
+
var _fun$args;
|
|
38
38
|
var store = (0, _useProvider.useStore)();
|
|
39
39
|
var value = props.value,
|
|
40
40
|
data = props.data,
|
|
@@ -54,18 +54,36 @@ var CaseEditor = _react["default"].forwardRef(function (props, ref) {
|
|
|
54
54
|
var formulaList = (0, _react.useMemo)(function () {
|
|
55
55
|
return (0, _utils2.getObjTem)(store.formulaTemplates);
|
|
56
56
|
}, [store.formulaTemplates]);
|
|
57
|
+
var _useState3 = (0, _react.useState)(''),
|
|
58
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
59
|
+
formulaSearch = _useState4[0],
|
|
60
|
+
setFormulaSearch = _useState4[1];
|
|
61
|
+
var filteredFormulaTemplates = (0, _react.useMemo)(function () {
|
|
62
|
+
var keyword = formulaSearch.trim().toLocaleLowerCase();
|
|
63
|
+
var templates = store.formulaTemplates || [];
|
|
64
|
+
if (!keyword) return templates;
|
|
65
|
+
return templates.map(function (template) {
|
|
66
|
+
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, template), {}, {
|
|
67
|
+
children: (template.children || []).filter(function (option) {
|
|
68
|
+
return "".concat(option.name || '', " ").concat(option.id || '').toLocaleLowerCase().includes(keyword);
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
}).filter(function (template) {
|
|
72
|
+
return template.children.length > 0;
|
|
73
|
+
});
|
|
74
|
+
}, [formulaSearch, store.formulaTemplates]);
|
|
57
75
|
var currentFormulaKey = fun.id || fun.name;
|
|
58
76
|
var currentFormulaTemplate = (0, _react.useMemo)(function () {
|
|
59
77
|
return formulaList[currentFormulaKey];
|
|
60
78
|
}, [formulaList, currentFormulaKey]);
|
|
61
79
|
var effectiveArity = (currentFormulaTemplate === null || currentFormulaTemplate === void 0 ? void 0 : currentFormulaTemplate.arity) || fun.arity;
|
|
62
|
-
var
|
|
80
|
+
var _useState5 = (0, _react.useState)({
|
|
63
81
|
canAdd: true,
|
|
64
82
|
canDel: true
|
|
65
83
|
}),
|
|
66
|
-
|
|
67
|
-
formulaOpr =
|
|
68
|
-
setFormulaOpr =
|
|
84
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
85
|
+
formulaOpr = _useState6[0],
|
|
86
|
+
setFormulaOpr = _useState6[1];
|
|
69
87
|
(0, _react.useEffect)(function () {
|
|
70
88
|
setFormulaOpr((0, _utils2.getParamActions)(fun.args, effectiveArity));
|
|
71
89
|
}, [fun.args, effectiveArity]);
|
|
@@ -86,10 +104,10 @@ var CaseEditor = _react["default"].forwardRef(function (props, ref) {
|
|
|
86
104
|
}, [currentFormulaKey, currentFormulaTemplate, effectiveArity]);
|
|
87
105
|
var _ref = (0, _react.useRef)(null);
|
|
88
106
|
var formulaRightClickValueId = (0, _rightClickValue.useRightClickValue)(fun);
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
rightClickMenuState =
|
|
92
|
-
setRightClickMenuState =
|
|
107
|
+
var _useState7 = (0, _react.useState)(null),
|
|
108
|
+
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
|
109
|
+
rightClickMenuState = _useState8[0],
|
|
110
|
+
setRightClickMenuState = _useState8[1];
|
|
93
111
|
var usable = (0, _react.useMemo)(function () {
|
|
94
112
|
return fun.name && (0, _utils.isOk)(fun.args, true);
|
|
95
113
|
}, [fun]);
|
|
@@ -171,6 +189,26 @@ var CaseEditor = _react["default"].forwardRef(function (props, ref) {
|
|
|
171
189
|
zIndex: (0, _helperDom.getTopLayerZIndex)() + 1
|
|
172
190
|
}
|
|
173
191
|
},
|
|
192
|
+
dropdownRender: function dropdownRender(menu) {
|
|
193
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
194
|
+
className: 'Sqb-FormulaSelect-dropdown',
|
|
195
|
+
children: [(0, _jsxRuntime.jsx)(_pandora.Input, {
|
|
196
|
+
autoFocus: true,
|
|
197
|
+
style: {
|
|
198
|
+
width: '100%',
|
|
199
|
+
marginBottom: 6
|
|
200
|
+
},
|
|
201
|
+
value: formulaSearch,
|
|
202
|
+
placeholder: (0, _locale.__)('data.search'),
|
|
203
|
+
onChange: function onChange(searchValue) {
|
|
204
|
+
return setFormulaSearch(searchValue || '');
|
|
205
|
+
},
|
|
206
|
+
onClick: function onClick(event) {
|
|
207
|
+
return event.stopPropagation();
|
|
208
|
+
}
|
|
209
|
+
}), menu]
|
|
210
|
+
});
|
|
211
|
+
},
|
|
174
212
|
value: fun.id || fun.name,
|
|
175
213
|
triggerElement: function triggerElement(value) {
|
|
176
214
|
return (0, _jsxRuntime.jsx)("div", {
|
|
@@ -185,7 +223,10 @@ var CaseEditor = _react["default"].forwardRef(function (props, ref) {
|
|
|
185
223
|
if (readonly) return;
|
|
186
224
|
handleFunName(val);
|
|
187
225
|
},
|
|
188
|
-
|
|
226
|
+
onVisibleChange: function onVisibleChange(visible) {
|
|
227
|
+
if (!visible) setFormulaSearch('');
|
|
228
|
+
},
|
|
229
|
+
children: filteredFormulaTemplates.map(function (options, index) {
|
|
189
230
|
return (0, _jsxRuntime.jsx)(_pandora.Select.OptGroup, {
|
|
190
231
|
label: options.name,
|
|
191
232
|
children: Array.from(options.children || []).map(function (option, ind) {
|
|
@@ -18,6 +18,7 @@ interface PropsType {
|
|
|
18
18
|
enableCopy?: boolean;
|
|
19
19
|
enableZoom?: boolean;
|
|
20
20
|
parentPopupChannel?: 'primary' | 'secondary';
|
|
21
|
+
pairBrackets?: boolean;
|
|
21
22
|
onAddSql?: (sql: string, availableTables?: any[], tableScope?: FormulaSqlTableScopeItem[]) => Promise<void | (() => void)> | void | (() => void);
|
|
22
23
|
}
|
|
23
24
|
declare const FormulaList: React.ForwardRefExoticComponent<PropsType & React.RefAttributes<unknown>>;
|
|
@@ -874,6 +874,12 @@ var createUnknownAtom = function createUnknownAtom() {
|
|
|
874
874
|
type: _types.AtomsTypeEnum.UNKNOWN
|
|
875
875
|
};
|
|
876
876
|
};
|
|
877
|
+
var createCaseWhenBranch = function createCaseWhenBranch() {
|
|
878
|
+
return {
|
|
879
|
+
whenAtoms: [createUnknownAtom()],
|
|
880
|
+
thenAtoms: [createUnknownAtom()]
|
|
881
|
+
};
|
|
882
|
+
};
|
|
877
883
|
var getTokenStyleByClassName = function getTokenStyleByClassName(className, extraStyle) {
|
|
878
884
|
var names = " ".concat(className || '', " ");
|
|
879
885
|
var color = TOKEN_PALETTE.blue;
|
|
@@ -898,7 +904,7 @@ var getTokenStyleByClassName = function getTokenStyleByClassName(className, extr
|
|
|
898
904
|
} : {}), extraStyle);
|
|
899
905
|
};
|
|
900
906
|
var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
901
|
-
var _storage$_metabaseCop, _store$preProps, _store$preProps2;
|
|
907
|
+
var _storage$_metabaseCop, _ref9, _store$preProps, _store$preProps2;
|
|
902
908
|
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
909
|
_useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
|
|
904
910
|
checkedItemsCount = _useState14[0],
|
|
@@ -940,7 +946,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
940
946
|
_props$enableZoom = props.enableZoom,
|
|
941
947
|
enableZoom = _props$enableZoom === void 0 ? true : _props$enableZoom,
|
|
942
948
|
parentPopupChannel = props.parentPopupChannel,
|
|
949
|
+
pairBracketsProp = props.pairBrackets,
|
|
943
950
|
onAddSql = props.onAddSql;
|
|
951
|
+
var pairBrackets = (_ref9 = pairBracketsProp !== null && pairBracketsProp !== void 0 ? pairBracketsProp : store.pairBrackets) !== null && _ref9 !== void 0 ? _ref9 : false;
|
|
944
952
|
var parentPopupLockCountRef = (0, _react.useRef)(0);
|
|
945
953
|
var parentPopupUnlockTimerRef = (0, _react.useRef)(null);
|
|
946
954
|
var setParentClosable = function setParentClosable(closable) {
|
|
@@ -1076,10 +1084,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1076
1084
|
var hasFormulaDiffAction = Boolean(store.showFormulaDiff && store.hasFormulaDiffCode);
|
|
1077
1085
|
var operatorList = (0, _react.useMemo)(function () {
|
|
1078
1086
|
if (store.operatorList.length > 0) {
|
|
1079
|
-
return (0, _utils3.normalizeOperatorList)(store.operatorList);
|
|
1087
|
+
return (0, _utils3.normalizeOperatorList)(store.operatorList, pairBrackets);
|
|
1080
1088
|
}
|
|
1081
|
-
return (0, _utils3.normalizeOperatorList)(_utils3.operatorList);
|
|
1082
|
-
}, [store.operatorList]);
|
|
1089
|
+
return (0, _utils3.normalizeOperatorList)(_utils3.operatorList, pairBrackets);
|
|
1090
|
+
}, [store.operatorList, pairBrackets]);
|
|
1083
1091
|
var _useState15 = (0, _react.useState)(false),
|
|
1084
1092
|
_useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
|
|
1085
1093
|
sqlLoading = _useState16[0],
|
|
@@ -1110,12 +1118,12 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1110
1118
|
function getSelectDisplayText(item) {
|
|
1111
1119
|
var displayField = item.displayField || 'value';
|
|
1112
1120
|
var getOptionText = function getOptionText(value) {
|
|
1113
|
-
var
|
|
1121
|
+
var _ref0, _option$displayField;
|
|
1114
1122
|
var option = (item.options || []).find(function (currentOption) {
|
|
1115
1123
|
return currentOption.value === value;
|
|
1116
1124
|
});
|
|
1117
1125
|
if (!option) return value || '';
|
|
1118
|
-
return String((
|
|
1126
|
+
return String((_ref0 = (_option$displayField = option[displayField]) !== null && _option$displayField !== void 0 ? _option$displayField : option.value) !== null && _ref0 !== void 0 ? _ref0 : '');
|
|
1119
1127
|
};
|
|
1120
1128
|
if (Array.isArray(item.val)) {
|
|
1121
1129
|
return item.val.map(function (currentValue) {
|
|
@@ -1236,7 +1244,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1236
1244
|
var nextItem = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
|
|
1237
1245
|
caseAtoms: [],
|
|
1238
1246
|
whenClauses: [],
|
|
1239
|
-
elseAtoms:
|
|
1247
|
+
elseAtoms: item.elseAtoms
|
|
1240
1248
|
});
|
|
1241
1249
|
visited.set(item, nextItem);
|
|
1242
1250
|
nextItem.caseAtoms = (item.caseAtoms || []).map(function (currentItem) {
|
|
@@ -1297,13 +1305,13 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1297
1305
|
setCaseList(nextList);
|
|
1298
1306
|
};
|
|
1299
1307
|
var getFormulaSqlText = function getFormulaSqlText(result) {
|
|
1300
|
-
var
|
|
1308
|
+
var _ref1, _result$sql;
|
|
1301
1309
|
if (typeof result === 'string') return result;
|
|
1302
1310
|
if (!result) return '';
|
|
1303
|
-
return String((
|
|
1311
|
+
return String((_ref1 = (_result$sql = result.sql) !== null && _result$sql !== void 0 ? _result$sql : result.code) !== null && _ref1 !== void 0 ? _ref1 : '');
|
|
1304
1312
|
};
|
|
1305
1313
|
var getFormulaDiffData = function getFormulaDiffData(result) {
|
|
1306
|
-
var _result$oldCode,
|
|
1314
|
+
var _result$oldCode, _ref10, _result$newCode;
|
|
1307
1315
|
if (typeof result === 'string') {
|
|
1308
1316
|
return {
|
|
1309
1317
|
oldCode: '',
|
|
@@ -1318,7 +1326,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1318
1326
|
}
|
|
1319
1327
|
return {
|
|
1320
1328
|
oldCode: String((_result$oldCode = result.oldCode) !== null && _result$oldCode !== void 0 ? _result$oldCode : ''),
|
|
1321
|
-
newCode: String((
|
|
1329
|
+
newCode: String((_ref10 = (_result$newCode = result.newCode) !== null && _result$newCode !== void 0 ? _result$newCode : result.code) !== null && _ref10 !== void 0 ? _ref10 : '')
|
|
1322
1330
|
};
|
|
1323
1331
|
};
|
|
1324
1332
|
var normalizeFormulaValueForOutput = function normalizeFormulaValueForOutput() {
|
|
@@ -1340,7 +1348,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1340
1348
|
var parseFormulaSql = (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.parseFormulaSql;
|
|
1341
1349
|
var parseFormulaSqlStream = (_store$preProps2 = store.preProps) === null || _store$preProps2 === void 0 ? void 0 : _store$preProps2.parseFormulaSqlStream;
|
|
1342
1350
|
var resolvedAddSql = onAddSql || typeof parseFormulaSql === 'function' || typeof parseFormulaSqlStream === 'function' ? (function () {
|
|
1343
|
-
var
|
|
1351
|
+
var _ref11 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee7(sqlOrResult, availableTables, tableScope) {
|
|
1344
1352
|
var result;
|
|
1345
1353
|
return _regenerator["default"].wrap(function (_context7) {
|
|
1346
1354
|
while (1) switch (_context7.prev = _context7.next) {
|
|
@@ -1396,11 +1404,11 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1396
1404
|
}, _callee7);
|
|
1397
1405
|
}));
|
|
1398
1406
|
return function (_x5, _x6, _x7) {
|
|
1399
|
-
return
|
|
1407
|
+
return _ref11.apply(this, arguments);
|
|
1400
1408
|
};
|
|
1401
1409
|
}()) : undefined;
|
|
1402
1410
|
var showFormulaSql = function () {
|
|
1403
|
-
var
|
|
1411
|
+
var _ref12 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee8() {
|
|
1404
1412
|
var result, sql, _t1;
|
|
1405
1413
|
return _regenerator["default"].wrap(function (_context8) {
|
|
1406
1414
|
while (1) switch (_context8.prev = _context8.next) {
|
|
@@ -1461,7 +1469,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1461
1469
|
}, _callee8, null, [[2, 5, 6, 7]]);
|
|
1462
1470
|
}));
|
|
1463
1471
|
return function showFormulaSql() {
|
|
1464
|
-
return
|
|
1472
|
+
return _ref12.apply(this, arguments);
|
|
1465
1473
|
};
|
|
1466
1474
|
}();
|
|
1467
1475
|
var previewFormulaConfig = function previewFormulaConfig(result) {
|
|
@@ -1548,11 +1556,11 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1548
1556
|
});
|
|
1549
1557
|
},
|
|
1550
1558
|
defaultAvailableTables: data,
|
|
1551
|
-
streamParser: typeof parseFormulaSqlStream === 'function' ? function (
|
|
1552
|
-
var sql =
|
|
1553
|
-
messages =
|
|
1554
|
-
availableTables =
|
|
1555
|
-
tableScope =
|
|
1559
|
+
streamParser: typeof parseFormulaSqlStream === 'function' ? function (_ref13, handlers) {
|
|
1560
|
+
var sql = _ref13.sql,
|
|
1561
|
+
messages = _ref13.messages,
|
|
1562
|
+
availableTables = _ref13.availableTables,
|
|
1563
|
+
tableScope = _ref13.tableScope;
|
|
1556
1564
|
return parseFormulaSqlStream({
|
|
1557
1565
|
sql: sql,
|
|
1558
1566
|
messages: messages,
|
|
@@ -1572,7 +1580,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1572
1580
|
});
|
|
1573
1581
|
};
|
|
1574
1582
|
var showFormulaDiff = function () {
|
|
1575
|
-
var
|
|
1583
|
+
var _ref14 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee9() {
|
|
1576
1584
|
var result, _getFormulaDiffData, oldCode, newCode, _t10;
|
|
1577
1585
|
return _regenerator["default"].wrap(function (_context9) {
|
|
1578
1586
|
while (1) switch (_context9.prev = _context9.next) {
|
|
@@ -1626,7 +1634,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1626
1634
|
}, _callee9, null, [[2, 5, 6, 7]]);
|
|
1627
1635
|
}));
|
|
1628
1636
|
return function showFormulaDiff() {
|
|
1629
|
-
return
|
|
1637
|
+
return _ref14.apply(this, arguments);
|
|
1630
1638
|
};
|
|
1631
1639
|
}();
|
|
1632
1640
|
var renderTokenContent = function renderTokenContent(children) {
|
|
@@ -1704,16 +1712,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1704
1712
|
onAddAfter: function onAddAfter(event) {
|
|
1705
1713
|
event.stopPropagation();
|
|
1706
1714
|
var nextWhenClauses = (draftValue.whenClauses || []).slice();
|
|
1707
|
-
nextWhenClauses.splice(branchIndex + 1, 0,
|
|
1708
|
-
whenAtoms: [{
|
|
1709
|
-
val: '',
|
|
1710
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1711
|
-
}],
|
|
1712
|
-
thenAtoms: [{
|
|
1713
|
-
val: '',
|
|
1714
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1715
|
-
}]
|
|
1716
|
-
});
|
|
1715
|
+
nextWhenClauses.splice(branchIndex + 1, 0, createCaseWhenBranch());
|
|
1717
1716
|
updateDraftValue((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, draftValue), {}, {
|
|
1718
1717
|
whenClauses: nextWhenClauses
|
|
1719
1718
|
}));
|
|
@@ -1738,29 +1737,18 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1738
1737
|
onAddBranch: function onAddBranch(event) {
|
|
1739
1738
|
event.stopPropagation();
|
|
1740
1739
|
updateDraftValue((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, draftValue), {}, {
|
|
1741
|
-
whenClauses: [].concat((0, _toConsumableArray2["default"])(draftValue.whenClauses || []), [
|
|
1742
|
-
whenAtoms: [{
|
|
1743
|
-
val: '',
|
|
1744
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1745
|
-
}],
|
|
1746
|
-
thenAtoms: [{
|
|
1747
|
-
val: '',
|
|
1748
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1749
|
-
}]
|
|
1750
|
-
}])
|
|
1740
|
+
whenClauses: [].concat((0, _toConsumableArray2["default"])(draftValue.whenClauses || []), [createCaseWhenBranch()])
|
|
1751
1741
|
}));
|
|
1752
1742
|
},
|
|
1753
1743
|
onAddElse: function onAddElse(event) {
|
|
1754
1744
|
event.stopPropagation();
|
|
1755
1745
|
updateDraftValue((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, draftValue), {}, {
|
|
1756
|
-
elseAtoms: [
|
|
1757
|
-
val: '',
|
|
1758
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1759
|
-
}]
|
|
1746
|
+
elseAtoms: [createUnknownAtom()]
|
|
1760
1747
|
}));
|
|
1761
1748
|
},
|
|
1762
1749
|
onRemoveElse: function onRemoveElse(event) {
|
|
1763
1750
|
event.stopPropagation();
|
|
1751
|
+
if (draftValue.elseAtoms == null) return;
|
|
1764
1752
|
updateDraftValue((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, draftValue), {}, {
|
|
1765
1753
|
elseAtoms: undefined
|
|
1766
1754
|
}));
|
|
@@ -1949,16 +1937,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1949
1937
|
onAddAfter: function onAddAfter(e) {
|
|
1950
1938
|
e.stopPropagation();
|
|
1951
1939
|
var nextWhenClauses = whenClauses.slice();
|
|
1952
|
-
nextWhenClauses.splice(branchIndex + 1, 0,
|
|
1953
|
-
whenAtoms: [{
|
|
1954
|
-
val: '',
|
|
1955
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1956
|
-
}],
|
|
1957
|
-
thenAtoms: [{
|
|
1958
|
-
val: '',
|
|
1959
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1960
|
-
}]
|
|
1961
|
-
});
|
|
1940
|
+
nextWhenClauses.splice(branchIndex + 1, 0, createCaseWhenBranch());
|
|
1962
1941
|
updateAtomAt(index, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
|
|
1963
1942
|
whenClauses: nextWhenClauses
|
|
1964
1943
|
}));
|
|
@@ -1983,29 +1962,18 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
1983
1962
|
onAddBranch: function onAddBranch(e) {
|
|
1984
1963
|
e.stopPropagation();
|
|
1985
1964
|
updateAtomAt(index, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
|
|
1986
|
-
whenClauses: [].concat((0, _toConsumableArray2["default"])(whenClauses), [
|
|
1987
|
-
whenAtoms: [{
|
|
1988
|
-
val: '',
|
|
1989
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1990
|
-
}],
|
|
1991
|
-
thenAtoms: [{
|
|
1992
|
-
val: '',
|
|
1993
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
1994
|
-
}]
|
|
1995
|
-
}])
|
|
1965
|
+
whenClauses: [].concat((0, _toConsumableArray2["default"])(whenClauses), [createCaseWhenBranch()])
|
|
1996
1966
|
}));
|
|
1997
1967
|
},
|
|
1998
1968
|
onAddElse: function onAddElse(e) {
|
|
1999
1969
|
e.stopPropagation();
|
|
2000
1970
|
updateAtomAt(index, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
|
|
2001
|
-
elseAtoms: [
|
|
2002
|
-
val: '',
|
|
2003
|
-
type: _types.AtomsTypeEnum.UNKNOWN
|
|
2004
|
-
}]
|
|
1971
|
+
elseAtoms: [createUnknownAtom()]
|
|
2005
1972
|
}));
|
|
2006
1973
|
},
|
|
2007
1974
|
onRemoveElse: function onRemoveElse(e) {
|
|
2008
1975
|
e.stopPropagation();
|
|
1976
|
+
if (value.elseAtoms == null) return;
|
|
2009
1977
|
updateAtomAt(index, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
|
|
2010
1978
|
elseAtoms: undefined
|
|
2011
1979
|
}));
|
|
@@ -2399,7 +2367,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2399
2367
|
var oldType = (currentItem === null || currentItem === void 0 ? void 0 : currentItem.type) || '';
|
|
2400
2368
|
var isOperatorItem = oldType === _types.AtomsTypeEnum.OPERATOR;
|
|
2401
2369
|
var otherTypeConfig = otherTypeMap.get(String(oldType));
|
|
2402
|
-
if (oldType === _types.AtomsTypeEnum.OPERATOR && (oldVal === '(' || oldVal === ')')) {
|
|
2370
|
+
if (pairBrackets && oldType === _types.AtomsTypeEnum.OPERATOR && (oldVal === '(' || oldVal === ')')) {
|
|
2403
2371
|
if (val === '()') return;
|
|
2404
2372
|
var matchingIndex = getMatchingParenthesisIndex(_caseList, i);
|
|
2405
2373
|
if (matchingIndex >= 0) {
|
|
@@ -2411,7 +2379,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2411
2379
|
setCaseList(_caseList);
|
|
2412
2380
|
return;
|
|
2413
2381
|
}
|
|
2414
|
-
if (oldType === _types.AtomsTypeEnum.OPERATOR && val === '()') {
|
|
2382
|
+
if (pairBrackets && oldType === _types.AtomsTypeEnum.OPERATOR && val === '()') {
|
|
2415
2383
|
_caseList.splice(i, 1, {
|
|
2416
2384
|
type: _types.AtomsTypeEnum.OPERATOR,
|
|
2417
2385
|
val: '('
|
|
@@ -2477,6 +2445,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2477
2445
|
}
|
|
2478
2446
|
function getDeletionIndexSet(list, indices) {
|
|
2479
2447
|
var indexSet = new Set(indices);
|
|
2448
|
+
if (!pairBrackets) return indexSet;
|
|
2480
2449
|
indices.forEach(function (index) {
|
|
2481
2450
|
var matchingIndex = getMatchingParenthesisIndex(list, index);
|
|
2482
2451
|
if (matchingIndex >= 0) indexSet.add(matchingIndex);
|
|
@@ -2638,29 +2607,40 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2638
2607
|
var _caseList = caseList.slice() || [];
|
|
2639
2608
|
var _ind = index;
|
|
2640
2609
|
var otherTypeConfig = otherTypeMap.get(String(type));
|
|
2641
|
-
var isParentheses = type === '()';
|
|
2642
|
-
var
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
}
|
|
2610
|
+
var isParentheses = pairBrackets && type === '()';
|
|
2611
|
+
var isSingleParenthesis = !pairBrackets && (type === '(' || type === ')');
|
|
2612
|
+
var temItems;
|
|
2613
|
+
if (isParentheses) {
|
|
2614
|
+
temItems = [{
|
|
2615
|
+
type: _types.AtomsTypeEnum.OPERATOR,
|
|
2616
|
+
val: '('
|
|
2617
|
+
}, {
|
|
2618
|
+
type: _types.AtomsTypeEnum.OPERATOR,
|
|
2619
|
+
val: ')'
|
|
2620
|
+
}];
|
|
2621
|
+
} else if (isSingleParenthesis) {
|
|
2622
|
+
temItems = [{
|
|
2623
|
+
type: _types.AtomsTypeEnum.OPERATOR,
|
|
2624
|
+
val: type
|
|
2625
|
+
}];
|
|
2626
|
+
} else {
|
|
2627
|
+
temItems = [otherTypeConfig ? {
|
|
2628
|
+
id: '',
|
|
2629
|
+
val: '',
|
|
2630
|
+
type: type
|
|
2631
|
+
} : (0, _utils3.getTemplateItem)(type)];
|
|
2632
|
+
}
|
|
2653
2633
|
if (position === 'add') {
|
|
2654
|
-
_caseList.push.apply(_caseList, temItems);
|
|
2634
|
+
_caseList.push.apply(_caseList, (0, _toConsumableArray2["default"])(temItems));
|
|
2655
2635
|
_ind = _caseList.length - 1;
|
|
2656
2636
|
} else if (position === 'before') {
|
|
2657
|
-
_caseList.splice.apply(_caseList, [index, 0].concat(temItems));
|
|
2637
|
+
_caseList.splice.apply(_caseList, [index, 0].concat((0, _toConsumableArray2["default"])(temItems)));
|
|
2658
2638
|
_ind = index;
|
|
2659
2639
|
} else if (position === 'after') {
|
|
2660
|
-
_caseList.splice.apply(_caseList, [index + 1, 0].concat(temItems));
|
|
2640
|
+
_caseList.splice.apply(_caseList, [index + 1, 0].concat((0, _toConsumableArray2["default"])(temItems)));
|
|
2661
2641
|
_ind = index + 1;
|
|
2662
2642
|
} else {
|
|
2663
|
-
_caseList.splice.apply(_caseList, [index, 1].concat(temItems));
|
|
2643
|
+
_caseList.splice.apply(_caseList, [index, 1].concat((0, _toConsumableArray2["default"])(temItems)));
|
|
2664
2644
|
_ind = index;
|
|
2665
2645
|
}
|
|
2666
2646
|
setCaseList(_caseList);
|
|
@@ -2738,6 +2718,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2738
2718
|
snapshotMode: snapshotMode,
|
|
2739
2719
|
notExistsColumns: exitData,
|
|
2740
2720
|
isExit: true,
|
|
2721
|
+
sqlValidationQueryKind: 'exists',
|
|
2741
2722
|
toolbar: _toolbar,
|
|
2742
2723
|
btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
|
|
2743
2724
|
value: (0, _cloneDeep["default"])(_value),
|
|
@@ -2747,13 +2728,14 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2747
2728
|
return;
|
|
2748
2729
|
}
|
|
2749
2730
|
try {
|
|
2731
|
+
var _store$preProps4;
|
|
2750
2732
|
if ((0, _isEqual["default"])(newList, oldList)) {
|
|
2751
2733
|
o.close();
|
|
2752
2734
|
return;
|
|
2753
2735
|
}
|
|
2754
2736
|
var expression = {
|
|
2755
2737
|
notExists: (0, _cloneDeep["default"])(newList),
|
|
2756
|
-
quotes: (0, _utils2.buildSqlQuery)(newList, caseList[i].type),
|
|
2738
|
+
quotes: (0, _utils2.buildSqlQuery)(newList, caseList[i].type, (_store$preProps4 = store.preProps) === null || _store$preProps4 === void 0 ? void 0 : _store$preProps4.sqlDialect),
|
|
2757
2739
|
type: caseList[i].type
|
|
2758
2740
|
};
|
|
2759
2741
|
caseList[i] = expression;
|
|
@@ -2770,13 +2752,13 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2770
2752
|
};
|
|
2771
2753
|
var showSubQuery = function showSubQuery(i) {
|
|
2772
2754
|
var _caseList$i3, _caseList$i4;
|
|
2773
|
-
var _store$
|
|
2774
|
-
subToolbar = _store$
|
|
2775
|
-
notExistsColumns = _store$
|
|
2776
|
-
showFields = _store$
|
|
2777
|
-
isExit = _store$
|
|
2778
|
-
toolbar = _store$
|
|
2779
|
-
other = (0, _objectWithoutProperties2["default"])(_store$
|
|
2755
|
+
var _store$preProps5 = store.preProps,
|
|
2756
|
+
subToolbar = _store$preProps5.subToolbar,
|
|
2757
|
+
notExistsColumns = _store$preProps5.notExistsColumns,
|
|
2758
|
+
showFields = _store$preProps5.showFields,
|
|
2759
|
+
isExit = _store$preProps5.isExit,
|
|
2760
|
+
toolbar = _store$preProps5.toolbar,
|
|
2761
|
+
other = (0, _objectWithoutProperties2["default"])(_store$preProps5, _excluded3);
|
|
2780
2762
|
var _value = ((_caseList$i3 = caseList[i]) === null || _caseList$i3 === void 0 ? void 0 : _caseList$i3.subQuery) || [];
|
|
2781
2763
|
var oldList = (0, _cloneDeep["default"])(((_caseList$i4 = caseList[i]) === null || _caseList$i4 === void 0 ? void 0 : _caseList$i4.subQuery) || []);
|
|
2782
2764
|
var childModalZIndex = (0, _helperDom.getTopLayerZIndex)() + 1;
|
|
@@ -2792,6 +2774,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2792
2774
|
snapshotMode: snapshotMode,
|
|
2793
2775
|
isExit: true,
|
|
2794
2776
|
isSubquery: true,
|
|
2777
|
+
sqlValidationQueryKind: 'query',
|
|
2795
2778
|
notExistsColumns: exitData,
|
|
2796
2779
|
fieldEnableAlias: false,
|
|
2797
2780
|
toolbar: _toolbar,
|
|
@@ -2803,13 +2786,14 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2803
2786
|
return;
|
|
2804
2787
|
}
|
|
2805
2788
|
try {
|
|
2789
|
+
var _store$preProps6;
|
|
2806
2790
|
if ((0, _isEqual["default"])(newList, oldList)) {
|
|
2807
2791
|
o.close();
|
|
2808
2792
|
return;
|
|
2809
2793
|
}
|
|
2810
2794
|
var expression = {
|
|
2811
2795
|
subQuery: (0, _cloneDeep["default"])(newList),
|
|
2812
|
-
quotes: (0, _utils2.buildSqlQuery)(newList, caseList[i].type),
|
|
2796
|
+
quotes: (0, _utils2.buildSqlQuery)(newList, caseList[i].type, (_store$preProps6 = store.preProps) === null || _store$preProps6 === void 0 ? void 0 : _store$preProps6.sqlDialect),
|
|
2813
2797
|
type: caseList[i].type
|
|
2814
2798
|
};
|
|
2815
2799
|
caseList[i] = expression;
|
|
@@ -2865,15 +2849,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
2865
2849
|
},
|
|
2866
2850
|
ref: _ref,
|
|
2867
2851
|
onOk: function onOk(data) {
|
|
2868
|
-
var _ref$current;
|
|
2869
|
-
var errorElements = ((_ref$current = _ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelectorAll('.isSqlError')) || [];
|
|
2870
|
-
if (errorElements.length) {
|
|
2871
|
-
_pandora.Modal.error({
|
|
2872
|
-
title: (0, _locale.__)('metabase.prompt'),
|
|
2873
|
-
content: (0, _locale.__)('metabase.validationFormula')
|
|
2874
|
-
});
|
|
2875
|
-
return;
|
|
2876
|
-
}
|
|
2877
2852
|
var _caseList = caseList.slice();
|
|
2878
2853
|
_caseList[i] = data;
|
|
2879
2854
|
setCaseList(_caseList);
|
|
@@ -3402,7 +3377,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
|
|
|
3402
3377
|
children: (0, _jsxRuntime.jsxs)(_pandora.Space, {
|
|
3403
3378
|
direction: 'vertical',
|
|
3404
3379
|
size: 'middle',
|
|
3405
|
-
className: 'preview-container',
|
|
3380
|
+
className: (0, _classnames["default"])('preview-container', {
|
|
3381
|
+
isSqlError: errorInfo.isError
|
|
3382
|
+
}),
|
|
3406
3383
|
children: [(0, _jsxRuntime.jsxs)("div", {
|
|
3407
3384
|
className: 'Sqb-FormulaPreviewHeader',
|
|
3408
3385
|
children: [(0, _jsxRuntime.jsx)("p", {
|
|
@@ -12,7 +12,7 @@ export declare const normalizeExpressionAtom: (expression: AtomsExpression, tabl
|
|
|
12
12
|
export declare const normalizeExpressionAtoms: (atoms?: AtomsItem[], tables?: ExpressionTable[], filterCustomType?: boolean) => AtomsItem[];
|
|
13
13
|
export declare const insertTemplateAt: (oldType: string, type: string, list: any[], index: number) => any[];
|
|
14
14
|
export declare const operatorList: string[];
|
|
15
|
-
export declare const normalizeOperatorList: (operators?: string[]) => string[];
|
|
15
|
+
export declare const normalizeOperatorList: (operators?: string[], pairBrackets?: boolean) => string[];
|
|
16
16
|
export declare const customTypes: ({
|
|
17
17
|
value: AtomsTypeEnum;
|
|
18
18
|
label: any;
|
|
@@ -27,6 +27,7 @@ export declare const isOk: (rhsVal: AtomsItem[], allowEmptyInputString?: boolean
|
|
|
27
27
|
export declare function validateExpressionIntegrity(list: AtomsItem[]): {
|
|
28
28
|
isError: boolean;
|
|
29
29
|
error?: string;
|
|
30
|
+
code?: 'parentheses' | 'case' | 'window' | 'duplicate-logical-operator' | 'and-or';
|
|
30
31
|
isBracket?: boolean;
|
|
31
32
|
isCase?: boolean;
|
|
32
33
|
isOver?: boolean;
|