@gingkoo/pandora-metabase 1.0.156 → 1.0.157-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/lib/cjs/components/dialog/custom-editor/index.js +61 -5
  2. package/lib/cjs/components/dialog/expression/index.js +132 -54
  3. package/lib/cjs/components/dialog/expression/index.less +43 -0
  4. package/lib/cjs/components/dialog/formula/index.js +3 -1
  5. package/lib/cjs/components/dialog/formula/utils.d.ts +1 -0
  6. package/lib/cjs/components/dialog/formula/utils.js +20 -2
  7. package/lib/cjs/components/dialog/formula-list/index.d.ts +2 -0
  8. package/lib/cjs/components/dialog/formula-list/index.js +1119 -151
  9. package/lib/cjs/components/dialog/formula-list/index.less +362 -46
  10. package/lib/cjs/components/dialog/formula-list/utils.d.ts +13 -1
  11. package/lib/cjs/components/dialog/formula-list/utils.js +100 -1
  12. package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +2 -1
  13. package/lib/cjs/components/dialog/select-column-multiple/index.js +4 -2
  14. package/lib/cjs/components/dialog/select-join/index.js +11 -0
  15. package/lib/cjs/components/dialog/select-summarize/index.d.ts +4 -0
  16. package/lib/cjs/components/dialog/select-summarize/index.js +136 -15
  17. package/lib/cjs/components/dialog/select-summarize/index.less +34 -1
  18. package/lib/cjs/components/dialog/select-table/index.d.ts +4 -1
  19. package/lib/cjs/components/dialog/select-table/index.js +51 -7
  20. package/lib/cjs/components/dialog/select-table/index.less +20 -0
  21. package/lib/cjs/components/icons.d.ts +1 -0
  22. package/lib/cjs/components/icons.js +54 -29
  23. package/lib/cjs/components/metabase/index.js +8 -0
  24. package/lib/cjs/components/metabase/index.less +17 -14
  25. package/lib/cjs/components/modules/components/item-name.js +16 -2
  26. package/lib/cjs/components/modules/components/meta-icon.js +6 -4
  27. package/lib/cjs/components/modules/join-data.js +5 -0
  28. package/lib/cjs/components/modules/summarize/group-by.js +12 -1
  29. package/lib/cjs/components/modules/summarize/select-index.js +12 -1
  30. package/lib/cjs/hooks/use-state.js +1 -13
  31. package/lib/cjs/index.d.ts +3 -2
  32. package/lib/cjs/index.js +7 -0
  33. package/lib/cjs/locale/en.js +31 -0
  34. package/lib/cjs/locale/index.js +10 -6
  35. package/lib/cjs/locale/zh.js +31 -0
  36. package/lib/cjs/store/enum.d.ts +2 -1
  37. package/lib/cjs/store/enum.js +1 -0
  38. package/lib/cjs/store/helper.js +25 -2
  39. package/lib/cjs/store/types.d.ts +7 -1
  40. package/lib/cjs/types.d.ts +41 -1
  41. package/lib/cjs/utils/helper.js +20 -0
  42. package/lib/cjs/utils/transformSql.js +59 -2
  43. package/lib/cjs/utils.js +25 -4
  44. package/lib/es/components/dialog/custom-editor/index.js +62 -6
  45. package/lib/es/components/dialog/expression/index.js +133 -55
  46. package/lib/es/components/dialog/expression/index.less +43 -0
  47. package/lib/es/components/dialog/formula/index.js +4 -2
  48. package/lib/es/components/dialog/formula/utils.d.ts +1 -0
  49. package/lib/es/components/dialog/formula/utils.js +18 -1
  50. package/lib/es/components/dialog/formula-list/index.d.ts +2 -0
  51. package/lib/es/components/dialog/formula-list/index.js +1121 -153
  52. package/lib/es/components/dialog/formula-list/index.less +362 -46
  53. package/lib/es/components/dialog/formula-list/utils.d.ts +13 -1
  54. package/lib/es/components/dialog/formula-list/utils.js +99 -0
  55. package/lib/es/components/dialog/select-column-multiple/index.d.ts +2 -1
  56. package/lib/es/components/dialog/select-column-multiple/index.js +4 -2
  57. package/lib/es/components/dialog/select-join/index.js +12 -1
  58. package/lib/es/components/dialog/select-summarize/index.d.ts +4 -0
  59. package/lib/es/components/dialog/select-summarize/index.js +140 -19
  60. package/lib/es/components/dialog/select-summarize/index.less +34 -1
  61. package/lib/es/components/dialog/select-table/index.d.ts +4 -1
  62. package/lib/es/components/dialog/select-table/index.js +51 -7
  63. package/lib/es/components/dialog/select-table/index.less +20 -0
  64. package/lib/es/components/icons.d.ts +1 -0
  65. package/lib/es/components/icons.js +53 -28
  66. package/lib/es/components/metabase/index.js +8 -0
  67. package/lib/es/components/metabase/index.less +17 -14
  68. package/lib/es/components/modules/components/item-name.js +16 -2
  69. package/lib/es/components/modules/components/meta-icon.js +6 -4
  70. package/lib/es/components/modules/join-data.js +6 -1
  71. package/lib/es/components/modules/summarize/group-by.js +12 -1
  72. package/lib/es/components/modules/summarize/select-index.js +12 -1
  73. package/lib/es/hooks/use-state.js +1 -13
  74. package/lib/es/index.d.ts +3 -2
  75. package/lib/es/index.js +3 -1
  76. package/lib/es/locale/en.js +31 -0
  77. package/lib/es/locale/index.js +10 -6
  78. package/lib/es/locale/zh.js +31 -0
  79. package/lib/es/store/enum.d.ts +2 -1
  80. package/lib/es/store/enum.js +1 -0
  81. package/lib/es/store/helper.js +25 -2
  82. package/lib/es/store/types.d.ts +7 -1
  83. package/lib/es/types.d.ts +41 -1
  84. package/lib/es/utils/helper.js +20 -0
  85. package/lib/es/utils/transformSql.js +59 -2
  86. package/lib/es/utils.js +25 -4
  87. package/package.json +1 -1
@@ -40,7 +40,10 @@ var BlockTypeEnum = {
40
40
  exists: 'exists',
41
41
  FORMULA: 'FORMULA',
42
42
  collection: 'collection',
43
- andOr: 'andOr'
43
+ andOr: 'andOr',
44
+ caseWhen: 'caseWhen',
45
+ select: 'select',
46
+ subquery: 'subquery'
44
47
  };
45
48
  var SummarizeAlias = 'source';
46
49
  var SQL_GROUP_TYPE = {
@@ -255,6 +258,18 @@ var _handleBaseType2Sql9 = exports.handleBaseType2Sql = function handleBaseType2
255
258
  case '不等于':
256
259
  _right_condition = "!= ".concat(_rightSql);
257
260
  break;
261
+ case '大于':
262
+ _right_condition = "> ".concat(_rightSql);
263
+ break;
264
+ case '小于':
265
+ _right_condition = "< ".concat(_rightSql);
266
+ break;
267
+ case '大于或等于':
268
+ _right_condition = ">= ".concat(_rightSql);
269
+ break;
270
+ case '小于或等于':
271
+ _right_condition = "<= ".concat(_rightSql);
272
+ break;
258
273
  case '包含':
259
274
  _right_condition = "LIKE '%".concat(condition_1, "%'");
260
275
  break;
@@ -441,19 +456,29 @@ var _handleBaseType2Sql9 = exports.handleBaseType2Sql = function handleBaseType2
441
456
  case '等于':
442
457
  _right_condition = "= ".concat(_condition_4);
443
458
  break;
459
+ case '大于':
460
+ _right_condition = "> ".concat(_condition_4);
461
+ break;
462
+ case '小于':
444
463
  case '早于':
445
464
  _right_condition = "< ".concat(_condition_4);
446
465
  break;
466
+ case '大于或等于':
447
467
  case '晚于':
448
468
  _right_condition = ">= ".concat(_condition_4);
449
469
  break;
470
+ case '小于或等于':
471
+ _right_condition = "<= ".concat(_condition_4);
472
+ break;
450
473
  case '介于之间':
451
474
  _right_condition = "(".concat(_left_condition, " >= ").concat(_condition_4, " AND ").concat(_left_condition, " < ").concat(_condition_5, ")");
452
475
  _left_condition = '';
453
476
  break;
477
+ case '为空':
454
478
  case '是空的':
455
479
  _right_condition = "IS NULL";
456
480
  break;
481
+ case '不为空':
457
482
  case '不是空的':
458
483
  _right_condition = "IS NOT NULL";
459
484
  break;
@@ -496,6 +521,38 @@ var _handleBaseType2Sql9 = exports.handleBaseType2Sql = function handleBaseType2
496
521
  sql += " ".concat(collectionSql);
497
522
  constants.push.apply(constants, (0, _toConsumableArray2["default"])(collectionConstants));
498
523
  }
524
+ if (type === BlockTypeEnum.select) {
525
+ var values = (Array.isArray(item.val) ? item.val : [item.val]).filter(function (value) {
526
+ return value !== null && value !== undefined && value !== '';
527
+ }).map(function (value) {
528
+ return String(value);
529
+ });
530
+ var selectSql = values.join(', ');
531
+ sql += selectSql ? " ".concat(selectSql) : '';
532
+ sql_items.push.apply(sql_items, (0, _toConsumableArray2["default"])(values));
533
+ }
534
+ if (type === BlockTypeEnum.subquery) {
535
+ if (Array.isArray(item.subQuery) && item.subQuery.length) {
536
+ sql += " (".concat(handleSqlUnion(item.subQuery, db).sql, ")");
537
+ }
538
+ }
539
+ if (type === BlockTypeEnum.caseWhen) {
540
+ var caseSqlResult = _handleBaseType2Sql9(item.caseAtoms || [], db);
541
+ constants.push.apply(constants, (0, _toConsumableArray2["default"])(caseSqlResult.constants));
542
+ var whenSql = (item.whenClauses || []).map(function (clause) {
543
+ var whenResult = _handleBaseType2Sql9(clause.whenAtoms || [], db);
544
+ var thenResult = _handleBaseType2Sql9(clause.thenAtoms || [], db);
545
+ constants.push.apply(constants, (0, _toConsumableArray2["default"])(whenResult.constants).concat((0, _toConsumableArray2["default"])(thenResult.constants)));
546
+ var whenCondition = whenResult.sql.trim();
547
+ var thenValue = thenResult.sql.trim();
548
+ return whenCondition && thenValue ? "WHEN ".concat(whenCondition, " THEN ").concat(thenValue) : '';
549
+ }).filter(Boolean).join(' ');
550
+ var elseResult = _handleBaseType2Sql9(item.elseAtoms || [], db);
551
+ constants.push.apply(constants, (0, _toConsumableArray2["default"])(elseResult.constants));
552
+ var caseExpression = caseSqlResult.sql.trim();
553
+ var elseSql = elseResult.sql.trim();
554
+ sql += " CASE".concat(caseExpression ? " ".concat(caseExpression) : '').concat(whenSql ? " ".concat(whenSql) : '').concat(elseSql ? " ELSE ".concat(elseSql) : '', " END");
555
+ }
499
556
  if (type === BlockTypeEnum.andOr) {
500
557
  var itemsSql = normalizeAndOrItems(item).map(function (logicItem, index) {
501
558
  var _handleBaseType2Sql8 = _handleBaseType2Sql9(logicItem.atoms || [], db),
@@ -755,7 +812,7 @@ var handleSqlUnion = function handleSqlUnion(metas) {
755
812
  unionMetas.forEach(function (it) {
756
813
  if (Array.isArray(it.subquery) && it.subquery.length) {
757
814
  var u_data = handleSqlStruct(it.subquery, db);
758
- var _sqlStruct2text2 = _sqlStruct2text3(u_data, 0, db),
815
+ var _sqlStruct2text2 = _sqlStruct2text3(u_data, 0, db, noFields),
759
816
  u_sqltext = _sqlStruct2text2.sql,
760
817
  u_fields = _sqlStruct2text2.fields;
761
818
  union_fields.push(u_fields);
package/lib/cjs/utils.js CHANGED
@@ -951,10 +951,10 @@ var buildExpressionQuotes = function buildExpressionQuotes(item) {
951
951
  if (condition === '在') {
952
952
  return normalizeAtomQuotes("".concat(lhsText, " ").concat(_locale.isEn ? 'is' : '是', " ").concat(firstVal));
953
953
  }
954
- if (condition === '是空的') {
954
+ if (condition === '为空' || condition === '是空的') {
955
955
  return normalizeAtomQuotes("".concat(lhsText, " ").concat(_locale.isEn ? 'is empty' : '为空'));
956
956
  }
957
- if (condition === '不是空的') {
957
+ if (condition === '不为空' || condition === '不是空的') {
958
958
  return normalizeAtomQuotes("".concat(lhsText, " ").concat(_locale.isEn ? 'not empty' : '不为空'));
959
959
  }
960
960
  if (condition === '当前') {
@@ -1244,15 +1244,27 @@ var changeTableAlias = exports.changeTableAlias = function changeTableAlias(list
1244
1244
  }
1245
1245
  if (v.type === _enum.TypeEnum.summarize) {
1246
1246
  v.group.map(function (group) {
1247
+ var _group$orderBy;
1247
1248
  var groupAtoms = group.atoms;
1249
+ var shouldRefreshSql = false;
1248
1250
  if (groupAtoms && groupAtoms.length > 0) {
1249
1251
  group.atoms = _changeAlias(groupAtoms, {
1250
1252
  uuid: tableUuid,
1251
1253
  alias: alias
1252
1254
  }, AliasType.table);
1253
- group.sql = (0, _helper.summarizeToSql)(v.group, group).sql;
1255
+ shouldRefreshSql = true;
1254
1256
  } else if (group.tableUuid === tableUuid) {
1255
1257
  group.alias = alias;
1258
+ shouldRefreshSql = true;
1259
+ }
1260
+ if ((_group$orderBy = group.orderBy) !== null && _group$orderBy !== void 0 && _group$orderBy.length) {
1261
+ group.orderBy = _changeAlias(group.orderBy, {
1262
+ uuid: tableUuid,
1263
+ alias: alias
1264
+ }, AliasType.table);
1265
+ shouldRefreshSql = true;
1266
+ }
1267
+ if (shouldRefreshSql) {
1256
1268
  group.sql = (0, _helper.summarizeToSql)(v.group, group).sql;
1257
1269
  }
1258
1270
  });
@@ -1330,12 +1342,21 @@ var changeFieldAlias = exports.changeFieldAlias = function changeFieldAlias(list
1330
1342
  if (v.type === _enum.TypeEnum.rowLimit) {}
1331
1343
  if (v.type === _enum.TypeEnum.summarize) {
1332
1344
  v.group.map(function (group) {
1345
+ var _group$orderBy2;
1333
1346
  var groupAtoms = group.atoms;
1347
+ var shouldRefreshSql = false;
1334
1348
  if (groupAtoms && groupAtoms.length > 0) {
1335
1349
  group.atoms = _changeAlias(groupAtoms, aliasTarget, AliasType.field);
1336
- group.sql = (0, _helper.summarizeToSql)(v.group, group).sql;
1350
+ shouldRefreshSql = true;
1337
1351
  } else if (isAliasTargetSummarizeRecord(group, aliasTarget)) {
1338
1352
  group.fieldAlias = alias;
1353
+ shouldRefreshSql = true;
1354
+ }
1355
+ if ((_group$orderBy2 = group.orderBy) !== null && _group$orderBy2 !== void 0 && _group$orderBy2.length) {
1356
+ group.orderBy = _changeAlias(group.orderBy, aliasTarget, AliasType.field);
1357
+ shouldRefreshSql = true;
1358
+ }
1359
+ if (shouldRefreshSql) {
1339
1360
  group.sql = (0, _helper.summarizeToSql)(v.group, group).sql;
1340
1361
  }
1341
1362
  });
@@ -1,13 +1,15 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
1
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
4
  import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
4
5
  var _templateObject;
6
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
7
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
8
  import { useState, useMemo, useRef } from 'react';
7
9
  import cx from 'classnames';
8
10
  import './index.less';
9
11
  import FormulaList from '../formula-list';
10
- import { isOk } from '../formula-list/utils';
12
+ import { isOk, normalizeExpressionAtoms } from '../formula-list/utils';
11
13
  import { __ } from '../../../locale';
12
14
  import Styled from 'styled-components';
13
15
  import { FormulaTypeEnum } from '../../../store/types';
@@ -18,7 +20,7 @@ var VisualBox = Styled.div.attrs({
18
20
  className: 'visual-box'
19
21
  })(_templateObject || (_templateObject = _taggedTemplateLiteral([""])));
20
22
  var CaseEditor = function CaseEditor(props) {
21
- var _store$preProps;
23
+ var _store$preProps, _store$preProps2;
22
24
  var value = props.value,
23
25
  data = props.data,
24
26
  exitData = props.exitData,
@@ -27,7 +29,9 @@ var CaseEditor = function CaseEditor(props) {
27
29
  _props$readonly = props.readonly,
28
30
  readonly = _props$readonly === void 0 ? false : _props$readonly;
29
31
  var store = useStore();
30
- var _useState = useState(value.formulaList || []),
32
+ var _useState = useState(function () {
33
+ return normalizeExpressionAtoms(value.formulaList || [], data);
34
+ }),
31
35
  _useState2 = _slicedToArray(_useState, 2),
32
36
  caseList = _useState2[0],
33
37
  setCaseList = _useState2[1];
@@ -50,9 +54,60 @@ var CaseEditor = function CaseEditor(props) {
50
54
  }
51
55
  typeof onOk === 'function' && (onOk === null || onOk === void 0 ? void 0 : onOk(_objectSpread(_objectSpread({}, value), {}, {
52
56
  name: name,
53
- formulaList: caseList
57
+ formulaList: normalizeExpressionAtoms(caseList, data)
54
58
  })));
55
59
  };
60
+ var parseFormulaSql = (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.parseFormulaSql;
61
+ var handleParseSql = function () {
62
+ var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(sql, availableTables, tableScope) {
63
+ var normalizedSql, result, _t;
64
+ return _regeneratorRuntime.wrap(function (_context) {
65
+ while (1) switch (_context.prev = _context.next) {
66
+ case 0:
67
+ normalizedSql = sql.trim();
68
+ if (!(!normalizedSql || typeof parseFormulaSql !== 'function')) {
69
+ _context.next = 1;
70
+ break;
71
+ }
72
+ return _context.abrupt("return");
73
+ case 1:
74
+ _context.prev = 1;
75
+ _context.next = 2;
76
+ return parseFormulaSql({
77
+ sql: normalizedSql,
78
+ availableTables: availableTables !== null && availableTables !== void 0 && availableTables.length ? availableTables : data,
79
+ tableScope: tableScope
80
+ });
81
+ case 2:
82
+ result = _context.sent;
83
+ if (!(!result || !Array.isArray(result.formulaList))) {
84
+ _context.next = 3;
85
+ break;
86
+ }
87
+ Toast.warning(__('customColumn.sqlParseInvalid'));
88
+ throw new Error('INVALID_CUSTOM_COLUMN_SQL_RESULT');
89
+ case 3:
90
+ return _context.abrupt("return", function () {
91
+ setName(result.name || name);
92
+ setCaseList(normalizeExpressionAtoms(result.formulaList, data));
93
+ });
94
+ case 4:
95
+ _context.prev = 4;
96
+ _t = _context["catch"](1);
97
+ if ((_t === null || _t === void 0 ? void 0 : _t.message) !== 'INVALID_CUSTOM_COLUMN_SQL_RESULT') {
98
+ Toast.warning(__('customColumn.sqlParseFailed'));
99
+ }
100
+ throw _t;
101
+ case 5:
102
+ case "end":
103
+ return _context.stop();
104
+ }
105
+ }, _callee, null, [[1, 4]]);
106
+ }));
107
+ return function handleParseSql(_x, _x2, _x3) {
108
+ return _ref.apply(this, arguments);
109
+ };
110
+ }();
56
111
  return _jsxs("div", {
57
112
  className: 'custom-box',
58
113
  ref: ref,
@@ -84,7 +139,7 @@ var CaseEditor = function CaseEditor(props) {
84
139
  })]
85
140
  }), _jsx(FormulaList, {
86
141
  isCustom: true,
87
- otherTypes: (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.otherTypes,
142
+ otherTypes: (_store$preProps2 = store.preProps) === null || _store$preProps2 === void 0 ? void 0 : _store$preProps2.otherTypes,
88
143
  value: caseList,
89
144
  data: data,
90
145
  exitData: exitData,
@@ -93,7 +148,8 @@ var CaseEditor = function CaseEditor(props) {
93
148
  if (readonly) return;
94
149
  setCaseList(nextList);
95
150
  },
96
- _type: FormulaTypeEnum.CUSTOM
151
+ _type: FormulaTypeEnum.CUSTOM,
152
+ onAddSql: !readonly && typeof parseFormulaSql === 'function' ? handleParseSql : undefined
97
153
  })]
98
154
  })
99
155
  })