@gingkoo/pandora-metabase 1.0.141 → 1.0.142

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 (31) hide show
  1. package/lib/cjs/components/dialog/formula-list/LogicGroup.d.ts +8 -5
  2. package/lib/cjs/components/dialog/formula-list/LogicGroup.js +64 -18
  3. package/lib/cjs/components/dialog/formula-list/index.js +374 -153
  4. package/lib/cjs/components/dialog/formula-list/index.less +18 -5
  5. package/lib/cjs/components/dialog/formula-list/utils.js +45 -17
  6. package/lib/cjs/components/dialog/select-summarize/index.js +7 -0
  7. package/lib/cjs/components/modules/summarize/group-by.js +10 -1
  8. package/lib/cjs/components/modules/summarize/select-index.js +3 -1
  9. package/lib/cjs/hooks/use-state.js +165 -75
  10. package/lib/cjs/index.js +17 -3
  11. package/lib/cjs/store/types.d.ts +4 -4
  12. package/lib/cjs/types.d.ts +20 -1
  13. package/lib/cjs/utils/transformSql.js +51 -38
  14. package/lib/cjs/utils.d.ts +1 -0
  15. package/lib/cjs/utils.js +291 -56
  16. package/lib/es/components/dialog/formula-list/LogicGroup.d.ts +8 -5
  17. package/lib/es/components/dialog/formula-list/LogicGroup.js +65 -19
  18. package/lib/es/components/dialog/formula-list/index.js +373 -152
  19. package/lib/es/components/dialog/formula-list/index.less +18 -5
  20. package/lib/es/components/dialog/formula-list/utils.js +45 -17
  21. package/lib/es/components/dialog/select-summarize/index.js +7 -0
  22. package/lib/es/components/modules/summarize/group-by.js +10 -1
  23. package/lib/es/components/modules/summarize/select-index.js +3 -1
  24. package/lib/es/hooks/use-state.js +165 -75
  25. package/lib/es/index.js +18 -4
  26. package/lib/es/store/types.d.ts +4 -4
  27. package/lib/es/types.d.ts +20 -1
  28. package/lib/es/utils/transformSql.js +52 -39
  29. package/lib/es/utils.d.ts +1 -0
  30. package/lib/es/utils.js +290 -55
  31. package/package.json +1 -1
@@ -1,12 +1,19 @@
1
1
  .preview-box {
2
- .pd-Radio-button-solid .pd-Radio-button.pd-Radio-checked {
3
- background-color: #509ee3;
4
- border-color: #509ee3;
5
- }
6
2
  .preview-container {
7
3
  width: 100%;
8
4
  }
9
5
 
6
+ .Sqb-FormulaPreviewHeader {
7
+ display: flex;
8
+ align-items: center;
9
+ gap: 8px;
10
+ flex-wrap: wrap;
11
+
12
+ p {
13
+ margin: 0;
14
+ }
15
+ }
16
+
10
17
  .isSqlError {
11
18
  background-color: rgba(255, 0, 0, 0.1) !important;
12
19
  padding: 5px;
@@ -20,6 +27,12 @@
20
27
  // font-size: 10px;
21
28
  }
22
29
  }
30
+
31
+ .Sqb-FormulaSqlPreview {
32
+ max-height: 100%;
33
+ overflow: auto;
34
+ }
35
+
23
36
  .Sqb-Filter-item {
24
37
  --sqb-item-shell-margin-x: 14px;
25
38
  --sqb-item-gap-x: 8px;
@@ -1441,7 +1454,7 @@
1441
1454
  vertical-align: middle;
1442
1455
  }
1443
1456
 
1444
- .Sqb-FormulaGroup.logic-group > .Sqb-TableName.logic-operator {
1457
+ .Sqb-FormulaGroup.logic-group .Sqb-TableName.logic-operator {
1445
1458
  justify-content: center;
1446
1459
  flex: 0 0 32px;
1447
1460
  width: 32px;
@@ -220,14 +220,17 @@ var getTemplateItem = exports.getTemplateItem = function getTemplateItem(type, i
220
220
  };
221
221
  } else if (type === _types.AtomsTypeEnum.AND_OR) {
222
222
  return {
223
- operator: 'and',
224
- leftAtoms: [{
225
- val: '',
226
- type: _types.AtomsTypeEnum.UNKNOWN
227
- }],
228
- rightAtoms: [{
229
- val: '',
230
- type: _types.AtomsTypeEnum.UNKNOWN
223
+ items: [{
224
+ atoms: [{
225
+ val: '',
226
+ type: _types.AtomsTypeEnum.UNKNOWN
227
+ }]
228
+ }, {
229
+ operator: 'and',
230
+ atoms: [{
231
+ val: '',
232
+ type: _types.AtomsTypeEnum.UNKNOWN
233
+ }]
231
234
  }],
232
235
  quotes: '',
233
236
  type: type
@@ -278,12 +281,20 @@ var _isOk = exports.isOk = function isOk(rhsVal) {
278
281
  return _isOk(clause.whenAtoms || []) && _isOk(clause.thenAtoms || []);
279
282
  }) && _isOk(v.caseAtoms || []) && _isOk(v.elseAtoms || []);
280
283
  } else if (v.type === _types.AtomsTypeEnum.AND_OR) {
281
- var hasBinarySides = Array.isArray(v.leftAtoms) || Array.isArray(v.rightAtoms);
284
+ if (Array.isArray(v.items) && v.items.length > 0) {
285
+ return v.items.every(function (item, index) {
286
+ var _item$atoms;
287
+ if (index > 0 && !item.operator) return false;
288
+ return Boolean((_item$atoms = item.atoms) === null || _item$atoms === void 0 ? void 0 : _item$atoms.length) && _isOk(item.atoms || []);
289
+ });
290
+ }
291
+ var legacyItem = v;
292
+ var hasBinarySides = Array.isArray(legacyItem.leftAtoms) || Array.isArray(legacyItem.rightAtoms);
282
293
  if (hasBinarySides) {
283
- var _v$leftAtoms, _v$rightAtoms;
284
- return Boolean(v.operator) && Boolean((_v$leftAtoms = v.leftAtoms) === null || _v$leftAtoms === void 0 ? void 0 : _v$leftAtoms.length) && Boolean((_v$rightAtoms = v.rightAtoms) === null || _v$rightAtoms === void 0 ? void 0 : _v$rightAtoms.length) && _isOk(v.leftAtoms || []) && _isOk(v.rightAtoms || []);
294
+ var _legacyItem$leftAtoms, _legacyItem$rightAtom;
295
+ return Boolean(legacyItem.operator) && Boolean((_legacyItem$leftAtoms = legacyItem.leftAtoms) === null || _legacyItem$leftAtoms === void 0 ? void 0 : _legacyItem$leftAtoms.length) && Boolean((_legacyItem$rightAtom = legacyItem.rightAtoms) === null || _legacyItem$rightAtom === void 0 ? void 0 : _legacyItem$rightAtom.length) && _isOk(legacyItem.leftAtoms || []) && _isOk(legacyItem.rightAtoms || []);
285
296
  }
286
- return Boolean(v.operator) && _isOk(v.atoms || []);
297
+ return Boolean(legacyItem.operator) && _isOk(legacyItem.atoms || []);
287
298
  } else if (v.type === _types.AtomsTypeEnum.FORMULA) {
288
299
  if (!v.quotes) {
289
300
  return false;
@@ -408,25 +419,42 @@ function validateExpressionIntegrity(list) {
408
419
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
409
420
  var item = _step2.value;
410
421
  if (item.type === _types.AtomsTypeEnum.AND_OR) {
411
- if (!item.operator) {
422
+ if (Array.isArray(item.items) && item.items.length > 0) {
423
+ for (var index = 0; index < item.items.length; index++) {
424
+ var logicItem = item.items[index];
425
+ if (index > 0 && !logicItem.operator) {
426
+ return {
427
+ isError: true,
428
+ error: 'AND / OR 结构缺少操作符'
429
+ };
430
+ }
431
+ var _nestedError = validateExpressionIntegrity(logicItem.atoms || []);
432
+ if (_nestedError.isError) {
433
+ return _nestedError;
434
+ }
435
+ }
436
+ continue;
437
+ }
438
+ var legacyItem = item;
439
+ if (!legacyItem.operator) {
412
440
  return {
413
441
  isError: true,
414
442
  error: 'AND / OR 结构缺少操作符'
415
443
  };
416
444
  }
417
- var hasBinarySides = Array.isArray(item.leftAtoms) || Array.isArray(item.rightAtoms);
445
+ var hasBinarySides = Array.isArray(legacyItem.leftAtoms) || Array.isArray(legacyItem.rightAtoms);
418
446
  if (hasBinarySides) {
419
- var leftError = validateExpressionIntegrity(item.leftAtoms || []);
447
+ var leftError = validateExpressionIntegrity(legacyItem.leftAtoms || []);
420
448
  if (leftError.isError) {
421
449
  return leftError;
422
450
  }
423
- var rightError = validateExpressionIntegrity(item.rightAtoms || []);
451
+ var rightError = validateExpressionIntegrity(legacyItem.rightAtoms || []);
424
452
  if (rightError.isError) {
425
453
  return rightError;
426
454
  }
427
455
  continue;
428
456
  }
429
- var nestedError = validateExpressionIntegrity(item.atoms || []);
457
+ var nestedError = validateExpressionIntegrity(legacyItem.atoms || []);
430
458
  if (nestedError.isError) {
431
459
  return nestedError;
432
460
  }
@@ -140,6 +140,13 @@ var SelectSummarize = function SelectSummarize(_ref) {
140
140
  return [lhs, item.condition, rhs].filter(Boolean).join(' ').trim();
141
141
  }
142
142
  if (item.type === _types.AtomsTypeEnum.AND_OR) {
143
+ if (Array.isArray(item.items) && item.items.length > 0) {
144
+ var itemsText = item.items.map(function (logicItem, index) {
145
+ var atomsText = getFormulaSummary(logicItem.atoms || []);
146
+ return index === 0 ? atomsText : "".concat(logicItem.operator || 'and', " ").concat(atomsText);
147
+ }).join(' ');
148
+ return "( ".concat(itemsText, " )").replace(/\s+/g, ' ').trim();
149
+ }
143
150
  var hasBinarySides = Array.isArray(item.leftAtoms) || Array.isArray(item.rightAtoms);
144
151
  if (hasBinarySides) {
145
152
  var leftText = getFormulaSummary(item.leftAtoms || []);
@@ -45,6 +45,13 @@ var _getSummaryText = function getSummaryText() {
45
45
  return [lhs, item.condition, rhs].filter(Boolean).join(' ').trim();
46
46
  }
47
47
  if (item.type === _types.AtomsTypeEnum.AND_OR) {
48
+ if (Array.isArray(item.items) && item.items.length > 0) {
49
+ var itemsText = item.items.map(function (logicItem, index) {
50
+ var atomsText = _getSummaryText(logicItem.atoms || []);
51
+ return index === 0 ? atomsText : "".concat(logicItem.operator || 'and', " ").concat(atomsText);
52
+ }).join(' ');
53
+ return "( ".concat(itemsText, " )").replace(/\s+/g, ' ').trim();
54
+ }
48
55
  var hasBinarySides = Array.isArray(item.leftAtoms) || Array.isArray(item.rightAtoms);
49
56
  if (hasBinarySides) {
50
57
  var leftText = _getSummaryText(item.leftAtoms || []);
@@ -439,7 +446,9 @@ var GroupBy = function GroupBy(props) {
439
446
  if (_found) return _found;
440
447
  }
441
448
  if (item.type === _types.AtomsTypeEnum.AND_OR) {
442
- var _found2 = _getFirstField([].concat((0, _toConsumableArray2["default"])(item.leftAtoms || []), (0, _toConsumableArray2["default"])(item.rightAtoms || []), (0, _toConsumableArray2["default"])(item.atoms || [])));
449
+ var _found2 = _getFirstField([].concat((0, _toConsumableArray2["default"])((item.items || []).flatMap(function (logicItem) {
450
+ return logicItem.atoms || [];
451
+ })), (0, _toConsumableArray2["default"])(item.leftAtoms || []), (0, _toConsumableArray2["default"])(item.rightAtoms || []), (0, _toConsumableArray2["default"])(item.atoms || [])));
443
452
  if (_found2) return _found2;
444
453
  }
445
454
  if (item.type === _types.AtomsTypeEnum.CASE_WHEN) {
@@ -352,7 +352,9 @@ var SelectIndex = function SelectIndex(props) {
352
352
  if (_found) return _found;
353
353
  }
354
354
  if (item.type === _types.AtomsTypeEnum.AND_OR) {
355
- var _found2 = _getFirstField([].concat((0, _toConsumableArray2["default"])(item.leftAtoms || []), (0, _toConsumableArray2["default"])(item.rightAtoms || []), (0, _toConsumableArray2["default"])(item.atoms || [])));
355
+ var _found2 = _getFirstField([].concat((0, _toConsumableArray2["default"])((item.items || []).flatMap(function (logicItem) {
356
+ return logicItem.atoms || [];
357
+ })), (0, _toConsumableArray2["default"])(item.leftAtoms || []), (0, _toConsumableArray2["default"])(item.rightAtoms || []), (0, _toConsumableArray2["default"])(item.atoms || [])));
356
358
  if (_found2) return _found2;
357
359
  }
358
360
  if (item.type === _types.AtomsTypeEnum.CASE_WHEN) {
@@ -186,30 +186,46 @@ var useStore = function useStore() {
186
186
  _useState60 = (0, _slicedToArray2["default"])(_useState59, 2),
187
187
  moduleDiff = _useState60[0],
188
188
  setModuleDiff = _useState60[1];
189
- var _useState61 = (0, _react.useState)([]),
189
+ var _useState61 = (0, _react.useState)(false),
190
190
  _useState62 = (0, _slicedToArray2["default"])(_useState61, 2),
191
- sourceData = _useState62[0],
192
- setSourceData = _useState62[1];
191
+ showFormulaSql = _useState62[0],
192
+ setShowFormulaSql = _useState62[1];
193
193
  var _useState63 = (0, _react.useState)(false),
194
194
  _useState64 = (0, _slicedToArray2["default"])(_useState63, 2),
195
- moduleCopy = _useState64[0],
196
- setModuleCopy = _useState64[1];
195
+ showFormulaDiff = _useState64[0],
196
+ setShowFormulaDiff = _useState64[1];
197
197
  var _useState65 = (0, _react.useState)(false),
198
198
  _useState66 = (0, _slicedToArray2["default"])(_useState65, 2),
199
- isMetabaseCopy = _useState66[0],
200
- setIsMetabaseCopy = _useState66[1];
199
+ hasFormulaSqlCode = _useState66[0],
200
+ setHasFormulaSqlCode = _useState66[1];
201
201
  var _useState67 = (0, _react.useState)(false),
202
202
  _useState68 = (0, _slicedToArray2["default"])(_useState67, 2),
203
- joinAliasConflictCheck = _useState68[0],
204
- setJoinAliasConflictCheck = _useState68[1];
203
+ hasFormulaDiffCode = _useState68[0],
204
+ setHasFormulaDiffCode = _useState68[1];
205
205
  var _useState69 = (0, _react.useState)([]),
206
206
  _useState70 = (0, _slicedToArray2["default"])(_useState69, 2),
207
- existsError = _useState70[0],
208
- setExistsError = _useState70[1];
209
- var _useState71 = (0, _react.useState)(_storage["default"]._metabaseCopyModule || []),
207
+ sourceData = _useState70[0],
208
+ setSourceData = _useState70[1];
209
+ var _useState71 = (0, _react.useState)(false),
210
210
  _useState72 = (0, _slicedToArray2["default"])(_useState71, 2),
211
- metabaseCopyModule = _useState72[0],
212
- setMetabaseCopyModule = _useState72[1];
211
+ moduleCopy = _useState72[0],
212
+ setModuleCopy = _useState72[1];
213
+ var _useState73 = (0, _react.useState)(false),
214
+ _useState74 = (0, _slicedToArray2["default"])(_useState73, 2),
215
+ isMetabaseCopy = _useState74[0],
216
+ setIsMetabaseCopy = _useState74[1];
217
+ var _useState75 = (0, _react.useState)(false),
218
+ _useState76 = (0, _slicedToArray2["default"])(_useState75, 2),
219
+ joinAliasConflictCheck = _useState76[0],
220
+ setJoinAliasConflictCheck = _useState76[1];
221
+ var _useState77 = (0, _react.useState)([]),
222
+ _useState78 = (0, _slicedToArray2["default"])(_useState77, 2),
223
+ existsError = _useState78[0],
224
+ setExistsError = _useState78[1];
225
+ var _useState79 = (0, _react.useState)(_storage["default"]._metabaseCopyModule || []),
226
+ _useState80 = (0, _slicedToArray2["default"])(_useState79, 2),
227
+ metabaseCopyModule = _useState80[0],
228
+ setMetabaseCopyModule = _useState80[1];
213
229
  var setFormulaTemplates = function setFormulaTemplates(data) {
214
230
  var newData = data === null || data === void 0 ? void 0 : data.map(function (v) {
215
231
  var children = v.children.map(function (vv) {
@@ -231,6 +247,8 @@ var useStore = function useStore() {
231
247
  var fetchColumnsFn = (0, _react.useRef)();
232
248
  var fetchChangeFn = (0, _react.useRef)();
233
249
  var fetchDiffFn = (0, _react.useRef)();
250
+ var fetchFormulaSqlFn = (0, _react.useRef)();
251
+ var fetchFormulaDiffFn = (0, _react.useRef)();
234
252
  var fetchExistsError = (0, _react.useRef)();
235
253
  var setFetchChangeFn = function setFetchChangeFn(fn) {
236
254
  fetchChangeFn.current = fn;
@@ -238,6 +256,14 @@ var useStore = function useStore() {
238
256
  var setFetchDiffFn = function setFetchDiffFn(fn) {
239
257
  fetchDiffFn.current = fn;
240
258
  };
259
+ var setFetchFormulaSqlFn = function setFetchFormulaSqlFn(fn) {
260
+ fetchFormulaSqlFn.current = fn;
261
+ setHasFormulaSqlCode(Boolean(fn));
262
+ };
263
+ var setFetchFormulaDiffFn = function setFetchFormulaDiffFn(fn) {
264
+ fetchFormulaDiffFn.current = fn;
265
+ setHasFormulaDiffCode(Boolean(fn));
266
+ };
241
267
  var setExistsErrorFn = function () {
242
268
  var _ref = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(fn, value) {
243
269
  var data;
@@ -295,6 +321,60 @@ var useStore = function useStore() {
295
321
  return _ref2.apply(this, arguments);
296
322
  };
297
323
  }();
324
+ var getFormulaSqlCode = function () {
325
+ var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3(value) {
326
+ var data;
327
+ return _regenerator["default"].wrap(function (_context3) {
328
+ while (1) switch (_context3.prev = _context3.next) {
329
+ case 0:
330
+ if (fetchFormulaSqlFn.current) {
331
+ _context3.next = 1;
332
+ break;
333
+ }
334
+ return _context3.abrupt("return", '');
335
+ case 1:
336
+ _context3.next = 2;
337
+ return fetchFormulaSqlFn.current(value);
338
+ case 2:
339
+ data = _context3.sent;
340
+ return _context3.abrupt("return", data);
341
+ case 3:
342
+ case "end":
343
+ return _context3.stop();
344
+ }
345
+ }, _callee3);
346
+ }));
347
+ return function getFormulaSqlCode(_x3) {
348
+ return _ref3.apply(this, arguments);
349
+ };
350
+ }();
351
+ var getFormulaDiffCode = function () {
352
+ var _ref4 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4(params) {
353
+ var data;
354
+ return _regenerator["default"].wrap(function (_context4) {
355
+ while (1) switch (_context4.prev = _context4.next) {
356
+ case 0:
357
+ if (fetchFormulaDiffFn.current) {
358
+ _context4.next = 1;
359
+ break;
360
+ }
361
+ return _context4.abrupt("return", undefined);
362
+ case 1:
363
+ _context4.next = 2;
364
+ return fetchFormulaDiffFn.current(params);
365
+ case 2:
366
+ data = _context4.sent;
367
+ return _context4.abrupt("return", data);
368
+ case 3:
369
+ case "end":
370
+ return _context4.stop();
371
+ }
372
+ }, _callee4);
373
+ }));
374
+ return function getFormulaDiffCode(_x4) {
375
+ return _ref4.apply(this, arguments);
376
+ };
377
+ }();
298
378
  var setFetchColumnsFn = function setFetchColumnsFn(fn) {
299
379
  fetchColumnsFn.current = fn;
300
380
  };
@@ -328,84 +408,84 @@ var useStore = function useStore() {
328
408
  }
329
409
  }, [sourceList, isExit, tableFlat]);
330
410
  var getSourceTable = function () {
331
- var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4(source) {
411
+ var _ref5 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee6(source) {
332
412
  var results;
333
- return _regenerator["default"].wrap(function (_context4) {
334
- while (1) switch (_context4.prev = _context4.next) {
413
+ return _regenerator["default"].wrap(function (_context6) {
414
+ while (1) switch (_context6.prev = _context6.next) {
335
415
  case 0:
336
- _context4.next = 1;
416
+ _context6.next = 1;
337
417
  return Promise.all(source.map(function () {
338
- var _ref4 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3(v) {
418
+ var _ref6 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5(v) {
339
419
  var tables;
340
- return _regenerator["default"].wrap(function (_context3) {
341
- while (1) switch (_context3.prev = _context3.next) {
420
+ return _regenerator["default"].wrap(function (_context5) {
421
+ while (1) switch (_context5.prev = _context5.next) {
342
422
  case 0:
343
- _context3.next = 1;
423
+ _context5.next = 1;
344
424
  return fetchDataset(v.datasourceId);
345
425
  case 1:
346
- tables = _context3.sent;
347
- return _context3.abrupt("return", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v), {}, {
426
+ tables = _context5.sent;
427
+ return _context5.abrupt("return", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v), {}, {
348
428
  children: tables
349
429
  }));
350
430
  case 2:
351
431
  case "end":
352
- return _context3.stop();
432
+ return _context5.stop();
353
433
  }
354
- }, _callee3);
434
+ }, _callee5);
355
435
  }));
356
- return function (_x4) {
357
- return _ref4.apply(this, arguments);
436
+ return function (_x6) {
437
+ return _ref6.apply(this, arguments);
358
438
  };
359
439
  }()));
360
440
  case 1:
361
- results = _context4.sent;
441
+ results = _context6.sent;
362
442
  setSourceTable(results || []);
363
443
  case 2:
364
444
  case "end":
365
- return _context4.stop();
445
+ return _context6.stop();
366
446
  }
367
- }, _callee4);
447
+ }, _callee6);
368
448
  }));
369
- return function getSourceTable(_x3) {
370
- return _ref3.apply(this, arguments);
449
+ return function getSourceTable(_x5) {
450
+ return _ref5.apply(this, arguments);
371
451
  };
372
452
  }();
373
453
  var showToolbar = function showToolbar(name) {
374
454
  return !!~toolbar.indexOf(name);
375
455
  };
376
456
  var fetchDataset = function () {
377
- var _ref5 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5(datasourceId) {
457
+ var _ref7 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee7(datasourceId) {
378
458
  var tables, _tables;
379
- return _regenerator["default"].wrap(function (_context5) {
380
- while (1) switch (_context5.prev = _context5.next) {
459
+ return _regenerator["default"].wrap(function (_context7) {
460
+ while (1) switch (_context7.prev = _context7.next) {
381
461
  case 0:
382
462
  tables = getDataset(datasourceId);
383
463
  if (!tables.length) {
384
- _context5.next = 1;
464
+ _context7.next = 1;
385
465
  break;
386
466
  }
387
- return _context5.abrupt("return", tables);
467
+ return _context7.abrupt("return", tables);
388
468
  case 1:
389
- _context5.next = 2;
469
+ _context7.next = 2;
390
470
  return fetchDatasetFn.current(datasourceId, {
391
471
  isExit: isExit
392
472
  });
393
473
  case 2:
394
- _tables = _context5.sent;
474
+ _tables = _context7.sent;
395
475
  setDataset(datasourceId, _tables);
396
- return _context5.abrupt("return", _tables);
476
+ return _context7.abrupt("return", _tables);
397
477
  case 3:
398
478
  case "end":
399
- return _context5.stop();
479
+ return _context7.stop();
400
480
  }
401
- }, _callee5);
481
+ }, _callee7);
402
482
  }));
403
- return function fetchDataset(_x5) {
404
- return _ref5.apply(this, arguments);
483
+ return function fetchDataset(_x7) {
484
+ return _ref7.apply(this, arguments);
405
485
  };
406
486
  }();
407
487
  var fetchColumns = function () {
408
- var _ref6 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee6(table, datasourceId) {
488
+ var _ref8 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee8(table, datasourceId) {
409
489
  var _columns2;
410
490
  var oldColumns,
411
491
  callback,
@@ -423,15 +503,15 @@ var useStore = function useStore() {
423
503
  tableName,
424
504
  columns,
425
505
  _columns,
426
- _args6 = arguments;
427
- return _regenerator["default"].wrap(function (_context6) {
428
- while (1) switch (_context6.prev = _context6.next) {
506
+ _args8 = arguments;
507
+ return _regenerator["default"].wrap(function (_context8) {
508
+ while (1) switch (_context8.prev = _context8.next) {
429
509
  case 0:
430
- oldColumns = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : [];
431
- callback = _args6.length > 3 ? _args6[3] : undefined;
432
- isSelect = _args6.length > 4 && _args6[4] !== undefined ? _args6[4] : isSelectFields;
433
- _isSubquery = _args6.length > 5 && _args6[5] !== undefined ? _args6[5] : isSubquery;
434
- _isExit = _args6.length > 6 && _args6[6] !== undefined ? _args6[6] : isExit;
510
+ oldColumns = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : [];
511
+ callback = _args8.length > 3 ? _args8[3] : undefined;
512
+ isSelect = _args8.length > 4 && _args8[4] !== undefined ? _args8[4] : isSelectFields;
513
+ _isSubquery = _args8.length > 5 && _args8[5] !== undefined ? _args8[5] : isSubquery;
514
+ _isExit = _args8.length > 6 && _args8[6] !== undefined ? _args8[6] : isExit;
435
515
  oldObj = {};
436
516
  selectId = oldColumns.filter(function (v) {
437
517
  oldObj[v.id] = v;
@@ -449,15 +529,15 @@ var useStore = function useStore() {
449
529
  tableName = table.name;
450
530
  columns = getColumns(tableName);
451
531
  if (columns.length) {
452
- _context6.next = 2;
532
+ _context8.next = 2;
453
533
  break;
454
534
  }
455
- _context6.next = 1;
535
+ _context8.next = 1;
456
536
  return fetchColumnsFn.current(extra, datasourceId, {
457
537
  isExit: _isExit
458
538
  });
459
539
  case 1:
460
- columns = _context6.sent;
540
+ columns = _context8.sent;
461
541
  setColumns(tableName, columns);
462
542
  case 2:
463
543
  _columns = (_columns2 = columns) === null || _columns2 === void 0 ? void 0 : _columns2.map(function (v) {
@@ -473,27 +553,27 @@ var useStore = function useStore() {
473
553
  typeof callback === 'function' && callback(_columns);
474
554
  case 3:
475
555
  case "end":
476
- return _context6.stop();
556
+ return _context8.stop();
477
557
  }
478
- }, _callee6);
558
+ }, _callee8);
479
559
  }));
480
- return function fetchColumns(_x6, _x7) {
481
- return _ref6.apply(this, arguments);
560
+ return function fetchColumns(_x8, _x9) {
561
+ return _ref8.apply(this, arguments);
482
562
  };
483
563
  }();
484
564
  var setMeta = function () {
485
- var _ref7 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee7(curData, groupInd) {
565
+ var _ref9 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee9(curData, groupInd) {
486
566
  var changeObj,
487
567
  _metaList,
488
568
  prevMeta,
489
569
  newMeta,
490
570
  isChange,
491
- _args7 = arguments;
492
- return _regenerator["default"].wrap(function (_context7) {
493
- while (1) switch (_context7.prev = _context7.next) {
571
+ _args9 = arguments;
572
+ return _regenerator["default"].wrap(function (_context9) {
573
+ while (1) switch (_context9.prev = _context9.next) {
494
574
  case 0:
495
- changeObj = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : {};
496
- _metaList = _args7.length > 3 ? _args7[3] : undefined;
575
+ changeObj = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
576
+ _metaList = _args9.length > 3 ? _args9[3] : undefined;
497
577
  prevMeta = (0, _cloneDeep["default"])(_metaList || latestMetaListRef.current);
498
578
  newMeta = (0, _cloneDeep["default"])(prevMeta);
499
579
  if (newMeta[groupInd]) {
@@ -501,28 +581,28 @@ var useStore = function useStore() {
501
581
  _setMeta(newMeta);
502
582
  }
503
583
  if (!(changeObj === 'init')) {
504
- _context7.next = 1;
584
+ _context9.next = 1;
505
585
  break;
506
586
  }
507
- return _context7.abrupt("return");
587
+ return _context9.abrupt("return");
508
588
  case 1:
509
- _context7.next = 2;
589
+ _context9.next = 2;
510
590
  return fetchChangeFn.current((0, _utils.splitByUnion)(newMeta), changeObj, {
511
591
  isExit: isExit
512
592
  });
513
593
  case 2:
514
- isChange = _context7.sent;
594
+ isChange = _context9.sent;
515
595
  if (isChange === false) {
516
596
  _setMeta(prevMeta);
517
597
  }
518
598
  case 3:
519
599
  case "end":
520
- return _context7.stop();
600
+ return _context9.stop();
521
601
  }
522
- }, _callee7);
602
+ }, _callee9);
523
603
  }));
524
- return function setMeta(_x8, _x9) {
525
- return _ref7.apply(this, arguments);
604
+ return function setMeta(_x0, _x1) {
605
+ return _ref9.apply(this, arguments);
526
606
  };
527
607
  }();
528
608
  var setPreData = function setPreData(data) {
@@ -1004,10 +1084,20 @@ var useStore = function useStore() {
1004
1084
  setMetabaseCopy: setMetabaseCopy,
1005
1085
  moduleDiff: moduleDiff,
1006
1086
  setModuleDiff: setModuleDiff,
1087
+ showFormulaSql: showFormulaSql,
1088
+ setShowFormulaSql: setShowFormulaSql,
1089
+ showFormulaDiff: showFormulaDiff,
1090
+ setShowFormulaDiff: setShowFormulaDiff,
1091
+ hasFormulaSqlCode: hasFormulaSqlCode,
1092
+ hasFormulaDiffCode: hasFormulaDiffCode,
1007
1093
  sourceData: sourceData,
1008
1094
  setSourceData: setSourceData,
1009
1095
  setFetchDiffFn: setFetchDiffFn,
1010
1096
  getModuleDiffCode: getModuleDiffCode,
1097
+ setFetchFormulaSqlFn: setFetchFormulaSqlFn,
1098
+ getFormulaSqlCode: getFormulaSqlCode,
1099
+ setFetchFormulaDiffFn: setFetchFormulaDiffFn,
1100
+ getFormulaDiffCode: getFormulaDiffCode,
1011
1101
  isSubquery: isSubquery,
1012
1102
  setIsSubquery: setIsSubquery,
1013
1103
  moduleCopy: moduleCopy,
package/lib/cjs/index.js CHANGED
@@ -29,6 +29,8 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
29
29
  getColumns = props.getColumns,
30
30
  onChange = props.onChange,
31
31
  getModuleDiffCode = props.getModuleDiffCode,
32
+ getFormulaSqlCode = props.getFormulaSqlCode,
33
+ getFormulaDiffCode = props.getFormulaDiffCode,
32
34
  getExistsError = props.getExistsError,
33
35
  _props$tableNameTpl = props.tableNameTpl,
34
36
  tableNameTpl = _props$tableNameTpl === void 0 ? '${name}' : _props$tableNameTpl,
@@ -75,6 +77,10 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
75
77
  moduleDiff = _props$moduleDiff === void 0 ? false : _props$moduleDiff,
76
78
  _props$moduleCopy = props.moduleCopy,
77
79
  moduleCopy = _props$moduleCopy === void 0 ? false : _props$moduleCopy,
80
+ _props$showFormulaSql = props.showFormulaSql,
81
+ showFormulaSql = _props$showFormulaSql === void 0 ? true : _props$showFormulaSql,
82
+ _props$showFormulaDif = props.showFormulaDiff,
83
+ showFormulaDiff = _props$showFormulaDif === void 0 ? true : _props$showFormulaDif,
78
84
  _props$joinAliasConfl = props.joinAliasConflictCheck,
79
85
  joinAliasConflictCheck = _props$joinAliasConfl === void 0 ? false : _props$joinAliasConfl,
80
86
  _props$operatorList = props.operatorList,
@@ -85,13 +91,19 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
85
91
  getColumns && store.setFetchColumnsFn(getColumns);
86
92
  onChange && store.setFetchChangeFn(onChange);
87
93
  getModuleDiffCode && store.setFetchDiffFn(getModuleDiffCode);
94
+ store.setFetchFormulaSqlFn(getFormulaSqlCode);
95
+ store.setFetchFormulaDiffFn(getFormulaDiffCode);
88
96
  }, []);
97
+ (0, _react.useEffect)(function () {
98
+ store.setFetchFormulaSqlFn(getFormulaSqlCode);
99
+ store.setFetchFormulaDiffFn(getFormulaDiffCode);
100
+ }, [getFormulaSqlCode, getFormulaDiffCode]);
89
101
  (0, _react.useEffect)(function () {
90
102
  store.setProps(props);
91
103
  }, [props]);
92
104
  (0, _react.useEffect)(function () {
93
- var _value = (0, _utils.reassembleByUnion)((0, _utils.patchData)(value, constantList, formulaTemplates));
94
- var source_value = (0, _utils.patchData)(value, constantList, formulaTemplates);
105
+ var source_value = (0, _utils.normalizeAndOrStructure)((0, _utils.patchData)(value, constantList, formulaTemplates));
106
+ var _value = (0, _utils.reassembleByUnion)(source_value);
95
107
  store.setPreData((0, _cloneDeep["default"])(_value), isSubquery, isExit);
96
108
  store.setSourceData(source_value);
97
109
  getExistsError && store.setExistsErrorFn(getExistsError, value);
@@ -119,11 +131,13 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
119
131
  store.setCopyType(copyType || []);
120
132
  store.setMetabaseCopy(metabaseCopy);
121
133
  store.setModuleDiff(moduleDiff);
134
+ store.setShowFormulaSql(showFormulaSql);
135
+ store.setShowFormulaDiff(showFormulaDiff);
122
136
  store.setIsSubquery(isSubquery);
123
137
  store.setModuleCopy(moduleCopy);
124
138
  store.setJoinAliasConflictCheck(joinAliasConflictCheck);
125
139
  store.setOperatorList(operatorList || []);
126
- }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit, tableEnableAlias, fieldEnableAlias, groupByEnableAlias, isSelectFields, tableFlat, copyType, metabaseCopy, moduleDiff, isSubquery, moduleCopy, joinAliasConflictCheck, operatorList]);
140
+ }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit, tableEnableAlias, fieldEnableAlias, groupByEnableAlias, isSelectFields, tableFlat, copyType, metabaseCopy, moduleDiff, showFormulaSql, showFormulaDiff, getFormulaSqlCode, getFormulaDiffCode, isSubquery, moduleCopy, joinAliasConflictCheck, operatorList]);
127
141
  _react["default"].useImperativeHandle(ref, function () {
128
142
  return {
129
143
  reset: function reset() {