@gingkoo/pandora-metabase 1.0.125 → 1.0.127

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 (65) hide show
  1. package/lib/cjs/components/dialog/expression/index.js +15 -5
  2. package/lib/cjs/components/dialog/expression/index.less +31 -16
  3. package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.d.ts +14 -5
  4. package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.js +236 -62
  5. package/lib/cjs/components/dialog/formula-list/LogicGroup.d.ts +3 -2
  6. package/lib/cjs/components/dialog/formula-list/LogicGroup.js +19 -11
  7. package/lib/cjs/components/dialog/formula-list/index.d.ts +1 -0
  8. package/lib/cjs/components/dialog/formula-list/index.js +658 -174
  9. package/lib/cjs/components/dialog/formula-list/index.less +1438 -145
  10. package/lib/cjs/components/dialog/formula-list/utils.js +50 -19
  11. package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +1 -0
  12. package/lib/cjs/components/dialog/select-column-multiple/index.js +42 -22
  13. package/lib/cjs/components/dialog/select-summarize/index.js +10 -2
  14. package/lib/cjs/components/dialog/select-table/index.d.ts +2 -1
  15. package/lib/cjs/components/dialog/select-table/index.js +197 -52
  16. package/lib/cjs/components/dialog/select-table/index.less +45 -2
  17. package/lib/cjs/components/metabase/index.less +156 -39
  18. package/lib/cjs/components/modules/custom-column.js +7 -3
  19. package/lib/cjs/components/modules/filter.js +6 -3
  20. package/lib/cjs/components/modules/join-data.js +62 -14
  21. package/lib/cjs/components/modules/permission-table.js +8 -4
  22. package/lib/cjs/components/modules/sort.js +2 -1
  23. package/lib/cjs/components/modules/summarize/group-by.js +20 -6
  24. package/lib/cjs/components/modules/summarize/select-index.js +9 -5
  25. package/lib/cjs/components/modules/table-data.js +21 -3
  26. package/lib/cjs/hooks/use-state.js +143 -17
  27. package/lib/cjs/index.js +7 -1
  28. package/lib/cjs/store/types.d.ts +14 -7
  29. package/lib/cjs/types.d.ts +8 -0
  30. package/lib/cjs/utils/transformSql.js +44 -21
  31. package/lib/cjs/utils.d.ts +2 -2
  32. package/lib/cjs/utils.js +381 -63
  33. package/lib/es/components/dialog/expression/index.js +15 -5
  34. package/lib/es/components/dialog/expression/index.less +31 -16
  35. package/lib/es/components/dialog/formula-list/CaseWhenGroup.d.ts +14 -5
  36. package/lib/es/components/dialog/formula-list/CaseWhenGroup.js +238 -64
  37. package/lib/es/components/dialog/formula-list/LogicGroup.d.ts +3 -2
  38. package/lib/es/components/dialog/formula-list/LogicGroup.js +19 -11
  39. package/lib/es/components/dialog/formula-list/index.d.ts +1 -0
  40. package/lib/es/components/dialog/formula-list/index.js +660 -176
  41. package/lib/es/components/dialog/formula-list/index.less +1438 -145
  42. package/lib/es/components/dialog/formula-list/utils.js +50 -19
  43. package/lib/es/components/dialog/select-column-multiple/index.d.ts +1 -0
  44. package/lib/es/components/dialog/select-column-multiple/index.js +42 -22
  45. package/lib/es/components/dialog/select-summarize/index.js +10 -2
  46. package/lib/es/components/dialog/select-table/index.d.ts +2 -1
  47. package/lib/es/components/dialog/select-table/index.js +197 -52
  48. package/lib/es/components/dialog/select-table/index.less +45 -2
  49. package/lib/es/components/metabase/index.less +156 -39
  50. package/lib/es/components/modules/custom-column.js +7 -3
  51. package/lib/es/components/modules/filter.js +6 -3
  52. package/lib/es/components/modules/join-data.js +62 -14
  53. package/lib/es/components/modules/permission-table.js +8 -4
  54. package/lib/es/components/modules/sort.js +2 -1
  55. package/lib/es/components/modules/summarize/group-by.js +21 -7
  56. package/lib/es/components/modules/summarize/select-index.js +10 -6
  57. package/lib/es/components/modules/table-data.js +21 -3
  58. package/lib/es/hooks/use-state.js +143 -17
  59. package/lib/es/index.js +7 -1
  60. package/lib/es/store/types.d.ts +14 -7
  61. package/lib/es/types.d.ts +8 -0
  62. package/lib/es/utils/transformSql.js +45 -22
  63. package/lib/es/utils.d.ts +2 -2
  64. package/lib/es/utils.js +382 -64
  65. package/package.json +1 -1
package/lib/es/utils.js CHANGED
@@ -5,7 +5,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
5
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
6
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
7
7
  var _excluded = ["list"];
8
- import { __ } from './locale';
8
+ import { __, isEn } from './locale';
9
9
  import { TypeEnum, SQL_COLUMN_TYPE } from './store/enum';
10
10
  import { AtomsTypeEnum } from './store/types';
11
11
  import { summarizeByToSql, summarizeToSql } from './store/helper';
@@ -240,44 +240,348 @@ var AliasType;
240
240
  AliasType["table"] = "table";
241
241
  AliasType["field"] = "field";
242
242
  })(AliasType || (AliasType = {}));
243
+ var normalizeAtomQuotes = function normalizeAtomQuotes(quotes) {
244
+ return quotes.replace(/\s+/g, ' ').trim();
245
+ };
246
+ var getExpressionConditionText = function getExpressionConditionText(condition) {
247
+ var localeKey = {
248
+ 等于: 'filter.equal',
249
+ 不等于: 'filter.notEqual',
250
+ 大于: 'filter.greaterThan',
251
+ 小于: 'filter.lessThan',
252
+ 介于之间: 'filter.inBetween',
253
+ 大于或等于: 'filter.greaterThanOrEqualTo',
254
+ 小于或等于: 'filter.lessThanOrEqualTo',
255
+ 为空: 'filter.empty',
256
+ 不为空: 'filter.notEmpty',
257
+ 包含: 'filter.contain',
258
+ 不包含: 'filter.notInclude',
259
+ '以...开始': 'filter.startWith',
260
+ '以...结束': 'filter.endWith',
261
+ '不以...开始': 'filter.notStartWith',
262
+ '不以...结束': 'filter.notEndWith',
263
+ 早于: 'filter.earlierThan',
264
+ 晚于: 'filter.laterThan',
265
+ 是空的: 'filter.isEmpty',
266
+ In: 'filter.within',
267
+ 'Not In': 'filter.withnotin',
268
+ 无需结果: 'filter.notresults',
269
+ 正则匹配: 'filter.regularMatch'
270
+ }[condition];
271
+ return localeKey ? __(localeKey) : condition;
272
+ };
273
+ var getSelectAtomText = function getSelectAtomText(item) {
274
+ var displayField = item.displayField || 'value';
275
+ var getOptionText = function getOptionText(value) {
276
+ var _ref, _option$displayField;
277
+ var option = (item.options || []).find(function (currentOption) {
278
+ return currentOption.value === value;
279
+ });
280
+ if (!option) return value || '';
281
+ return String((_ref = (_option$displayField = option[displayField]) !== null && _option$displayField !== void 0 ? _option$displayField : option.value) !== null && _ref !== void 0 ? _ref : '');
282
+ };
283
+ if (Array.isArray(item.val)) {
284
+ return item.val.map(function (currentValue) {
285
+ return getOptionText(String(currentValue));
286
+ }).join(', ');
287
+ }
288
+ return getOptionText(String(item.val || ''));
289
+ };
290
+ var _getAtomDisplayText = function getAtomDisplayText(item) {
291
+ if (!item) return '';
292
+ if (item.type === AtomsTypeEnum.FIELD) {
293
+ return item.fieldAlias || item.fieldName || '';
294
+ }
295
+ if (item.type === AtomsTypeEnum.CASE_WHEN) {
296
+ return buildCaseWhenQuotes(item);
297
+ }
298
+ if (item.type === AtomsTypeEnum.AND_OR) {
299
+ return buildAndOrQuotes(item);
300
+ }
301
+ if (item.type === AtomsTypeEnum.EXPRESSION) {
302
+ return buildExpressionQuotes(item);
303
+ }
304
+ if (item.type === AtomsTypeEnum.FORMULA) {
305
+ return buildFormulaQuotes(item);
306
+ }
307
+ if (item.type === AtomsTypeEnum.COLLECTION) {
308
+ return (item.list || []).map(_getAtomDisplayText).join(' ');
309
+ }
310
+ if (item.type === AtomsTypeEnum.SELECT) {
311
+ return getSelectAtomText(item);
312
+ }
313
+ if (item.type === AtomsTypeEnum.EXISTS || item.type === AtomsTypeEnum.NOT_EXISTS || item.type === AtomsTypeEnum.SUB_QUERY) {
314
+ return item.quotes || '';
315
+ }
316
+ var val = item.val;
317
+ if (Array.isArray(val)) return val.join(', ');
318
+ return val || val === 0 ? String(val) : '';
319
+ };
320
+ var buildFormulaQuotes = function buildFormulaQuotes(item) {
321
+ var argsText = (item.args || []).map(_getAtomDisplayText).join(' , ');
322
+ return normalizeAtomQuotes("".concat(item.name || '', " ( ").concat(argsText, " )"));
323
+ };
324
+ var buildAndOrQuotes = function buildAndOrQuotes(item) {
325
+ var hasBinarySides = Array.isArray(item.leftAtoms) || Array.isArray(item.rightAtoms);
326
+ if (hasBinarySides) {
327
+ var leftText = (item.leftAtoms || []).map(_getAtomDisplayText).join(' ');
328
+ var rightText = (item.rightAtoms || []).map(_getAtomDisplayText).join(' ');
329
+ return normalizeAtomQuotes("( ".concat(leftText, " ").concat(item.operator || 'and', " ").concat(rightText, " )"));
330
+ }
331
+ var atomsText = (item.atoms || []).map(_getAtomDisplayText).join(' ');
332
+ return normalizeAtomQuotes("".concat(item.operator || 'and', " ( ").concat(atomsText, " )"));
333
+ };
334
+ var buildCaseWhenQuotes = function buildCaseWhenQuotes(item) {
335
+ var caseAtomsText = (item.caseAtoms || []).map(_getAtomDisplayText).join(' ');
336
+ var whenClausesText = (item.whenClauses || []).map(function (clause) {
337
+ var whenText = (clause.whenAtoms || []).map(_getAtomDisplayText).join(' ');
338
+ var thenText = (clause.thenAtoms || []).map(_getAtomDisplayText).join(' ');
339
+ return "when ".concat(whenText, " then ").concat(thenText).trim();
340
+ }).join(' ');
341
+ var elseAtomsText = (item.elseAtoms || []).length ? " else ".concat((item.elseAtoms || []).map(_getAtomDisplayText).join(' ')) : '';
342
+ return normalizeAtomQuotes("case ".concat(caseAtomsText, " ").concat(whenClausesText).concat(elseAtomsText, " end"));
343
+ };
344
+ var getExpressionAtomsText = function getExpressionAtomsText() {
345
+ var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
346
+ var formula = arguments.length > 1 ? arguments[1] : undefined;
347
+ var names = items.map(_getAtomDisplayText).join(' || ');
348
+ if ((formula === null || formula === void 0 ? void 0 : formula.type) === 'SUBSTR') {
349
+ var _formula$params, _formula$params2;
350
+ return "SUBSTR(".concat(names, ",").concat(formula === null || formula === void 0 || (_formula$params = formula.params) === null || _formula$params === void 0 ? void 0 : _formula$params[1], ",").concat(formula === null || formula === void 0 || (_formula$params2 = formula.params) === null || _formula$params2 === void 0 ? void 0 : _formula$params2[2], ")");
351
+ }
352
+ return names;
353
+ };
354
+ var getExpressionFirstValue = function getExpressionFirstValue() {
355
+ var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
356
+ var firstItem = items[0];
357
+ if (!firstItem) {
358
+ return {
359
+ firstVal: '',
360
+ secondVal: ''
361
+ };
362
+ }
363
+ if (Array.isArray(firstItem.val)) {
364
+ return {
365
+ firstVal: firstItem.val[0] || '',
366
+ secondVal: firstItem.val[1] || ''
367
+ };
368
+ }
369
+ return {
370
+ firstVal: firstItem.val || firstItem.val === 0 ? String(firstItem.val) : _getAtomDisplayText(firstItem),
371
+ secondVal: ''
372
+ };
373
+ };
374
+ var buildExpressionQuotes = function buildExpressionQuotes(item) {
375
+ var condition = item.condition || '';
376
+ var lhsText = getExpressionAtomsText(item.lhs || [], item.formula);
377
+ var rhsText = getExpressionAtomsText(item.rhs || [], item.formula);
378
+ var _getExpressionFirstVa = getExpressionFirstValue(item.rhs || []),
379
+ firstVal = _getExpressionFirstVa.firstVal,
380
+ secondVal = _getExpressionFirstVa.secondVal;
381
+ if (condition === '以...开始') {
382
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? "startWith ".concat(firstVal) : "\u4EE5 ".concat(firstVal, " \u5F00\u59CB")));
383
+ }
384
+ if (condition === '不以...开始') {
385
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? "not startWith ".concat(firstVal) : "\u4E0D\u4EE5 ".concat(firstVal, " \u5F00\u59CB")));
386
+ }
387
+ if (condition === '以...结束') {
388
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? "endWith ".concat(firstVal) : "\u4EE5 ".concat(firstVal, " \u7ED3\u675F")));
389
+ }
390
+ if (condition === '不以...结束') {
391
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? "not endWith ".concat(firstVal) : "\u4E0D\u4EE5 ".concat(firstVal, " \u7ED3\u675F")));
392
+ }
393
+ if (condition === '介于之间') {
394
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? "Between ".concat(firstVal, " and ").concat(secondVal) : "\u4ECB\u4E8E".concat(firstVal, "\u548C").concat(secondVal, "\u4E4B\u95F4")));
395
+ }
396
+ if (condition === '前') {
397
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? "previous ".concat(firstVal).concat(secondVal) : "\u4E0A\u4E00\u4E2A".concat(firstVal).concat(secondVal)));
398
+ }
399
+ if (condition === '下一个') {
400
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? "next ".concat(firstVal).concat(secondVal) : "\u4E0B\u4E00\u4E2A".concat(firstVal).concat(secondVal)));
401
+ }
402
+ if (condition === '在') {
403
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? 'is' : '是', " ").concat(firstVal));
404
+ }
405
+ if (condition === '是空的') {
406
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? 'is empty' : '为空'));
407
+ }
408
+ if (condition === '不是空的') {
409
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? 'not empty' : '不为空'));
410
+ }
411
+ if (condition === '当前') {
412
+ if (firstVal === '天') {
413
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? 'today' : '今天'));
414
+ }
415
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(isEn ? "this is ".concat(firstVal) : "\u8FD9\u4E2A".concat(firstVal)));
416
+ }
417
+ if (condition === 'In' || condition === 'Not In') {
418
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(getExpressionConditionText(condition), " (").concat(firstVal, ")"));
419
+ }
420
+ return normalizeAtomQuotes("".concat(lhsText, " ").concat(getExpressionConditionText(condition), " ").concat(rhsText || firstVal));
421
+ };
422
+ var syncAtomQuotes = function syncAtomQuotes(item) {
423
+ if (item.type === AtomsTypeEnum.JOIN_DEFAULT) {
424
+ return _objectSpread(_objectSpread({}, item), {}, {
425
+ lhs: syncAtomQuotesList(item.lhs || []),
426
+ rhs: syncAtomQuotesList(item.rhs || [])
427
+ });
428
+ }
429
+ if (item.type === AtomsTypeEnum.EXPRESSION) {
430
+ var nextItem = _objectSpread(_objectSpread({}, item), {}, {
431
+ lhs: syncAtomQuotesList(item.lhs || []),
432
+ rhs: syncAtomQuotesList(item.rhs || [])
433
+ });
434
+ return _objectSpread(_objectSpread({}, nextItem), {}, {
435
+ quotes: buildExpressionQuotes(nextItem)
436
+ });
437
+ }
438
+ if (item.type === AtomsTypeEnum.FORMULA) {
439
+ var _nextItem = _objectSpread(_objectSpread({}, item), {}, {
440
+ args: syncAtomQuotesList(item.args || [])
441
+ });
442
+ return _objectSpread(_objectSpread({}, _nextItem), {}, {
443
+ quotes: buildFormulaQuotes(_nextItem)
444
+ });
445
+ }
446
+ if (item.type === AtomsTypeEnum.COLLECTION) {
447
+ var _nextItem2 = _objectSpread(_objectSpread({}, item), {}, {
448
+ list: syncAtomQuotesList(item.list || [])
449
+ });
450
+ return _objectSpread(_objectSpread({}, _nextItem2), {}, {
451
+ quotes: (_nextItem2.list || []).map(_getAtomDisplayText).join(' ')
452
+ });
453
+ }
454
+ if (item.type === AtomsTypeEnum.CASE_WHEN) {
455
+ var _nextItem3 = _objectSpread(_objectSpread({}, item), {}, {
456
+ caseAtoms: syncAtomQuotesList(item.caseAtoms || []),
457
+ whenClauses: (item.whenClauses || []).map(function (clause) {
458
+ return _objectSpread(_objectSpread({}, clause), {}, {
459
+ whenAtoms: syncAtomQuotesList(clause.whenAtoms || []),
460
+ thenAtoms: syncAtomQuotesList(clause.thenAtoms || [])
461
+ });
462
+ }),
463
+ elseAtoms: syncAtomQuotesList(item.elseAtoms || [])
464
+ });
465
+ return _objectSpread(_objectSpread({}, _nextItem3), {}, {
466
+ quotes: buildCaseWhenQuotes(_nextItem3)
467
+ });
468
+ }
469
+ if (item.type === AtomsTypeEnum.AND_OR) {
470
+ var hasBinarySides = Array.isArray(item.leftAtoms) || Array.isArray(item.rightAtoms);
471
+ var _nextItem4 = _objectSpread(_objectSpread({}, item), hasBinarySides ? {
472
+ atoms: undefined,
473
+ leftAtoms: syncAtomQuotesList(item.leftAtoms || []),
474
+ rightAtoms: syncAtomQuotesList(item.rightAtoms || [])
475
+ } : {
476
+ atoms: syncAtomQuotesList(item.atoms || [])
477
+ });
478
+ return _objectSpread(_objectSpread({}, _nextItem4), {}, {
479
+ quotes: buildAndOrQuotes(_nextItem4)
480
+ });
481
+ }
482
+ return item;
483
+ };
484
+ var syncAtomQuotesList = function syncAtomQuotesList(items) {
485
+ return items.map(syncAtomQuotes);
486
+ };
487
+ var isSameAliasTargetTable = function isSameAliasTargetTable(item, target) {
488
+ if (target.tableUuid && item.tableUuid && item.tableUuid === target.tableUuid) {
489
+ return true;
490
+ }
491
+ if (target.datasourceId && item.datasourceId && item.datasourceId !== target.datasourceId) {
492
+ return false;
493
+ }
494
+ if (target.tableId && item.tableId && item.tableId === target.tableId) {
495
+ return true;
496
+ }
497
+ return Boolean(target.tableName && item.tableName && item.tableName === target.tableName);
498
+ };
499
+ var isAliasTargetField = function isAliasTargetField(item, target) {
500
+ if (target.uuid && item.fieldUuid && item.fieldUuid === target.uuid) {
501
+ return true;
502
+ }
503
+ var sameTable = isSameAliasTargetTable(item, target);
504
+ if (target.fieldId && item.fieldId && item.fieldId === target.fieldId) {
505
+ return sameTable || !target.tableId;
506
+ }
507
+ return Boolean(target.fieldName && item.fieldName && item.fieldName === target.fieldName && sameTable);
508
+ };
243
509
  var _changeAlias = function changeAlias(items, val, type) {
244
510
  return items.map(function (v) {
511
+ var nextItem;
245
512
  if (v.type === AtomsTypeEnum.JOIN_DEFAULT || v.type === AtomsTypeEnum.EXPRESSION) {
246
- return _objectSpread(_objectSpread({}, v), {}, {
513
+ nextItem = _objectSpread(_objectSpread({}, v), {}, {
247
514
  lhs: _changeAlias(v.lhs, val, type),
248
515
  rhs: _changeAlias(v.rhs, val, type)
249
516
  });
250
517
  } else if (v.type === AtomsTypeEnum.FIELD) {
518
+ nextItem = _objectSpread({}, v);
251
519
  if (type === AliasType.table && v.tableUuid === val.uuid) {
252
- v.tableAlias = val.alias;
520
+ nextItem.tableAlias = val.alias;
253
521
  }
254
- if (type === AliasType.field && v.fieldUuid === val.uuid) {
255
- v.fieldAlias = val.alias;
522
+ if (type === AliasType.field && isAliasTargetField(v, val)) {
523
+ nextItem.fieldAlias = val.alias;
256
524
  }
257
- return v;
258
525
  } else if (v.type === AtomsTypeEnum.EXISTS || v.type === AtomsTypeEnum.NOT_EXISTS) {
526
+ nextItem = _objectSpread({}, v);
259
527
  if (type === AliasType.table) {
260
- v.notExists = changeTableAlias(v.notExists || [], {
261
- tableUuid: val.uuid,
528
+ nextItem.notExists = changeTableAlias(v.notExists || [], {
529
+ tableUuid: val.uuid || '',
262
530
  alias: val.alias
263
531
  });
264
532
  }
265
533
  if (type === AliasType.field) {
266
- v.notExists = changeFieldAlias(v.notExists || [], {
267
- fieldUuid: val.uuid,
534
+ nextItem.notExists = changeFieldAlias(v.notExists || [], {
535
+ fieldUuid: val.uuid || '',
536
+ fieldAlias: val.alias
537
+ });
538
+ }
539
+ } else if (v.type === AtomsTypeEnum.SUB_QUERY) {
540
+ nextItem = _objectSpread({}, v);
541
+ if (type === AliasType.table) {
542
+ nextItem.subQuery = changeTableAlias(v.subQuery || [], {
543
+ tableUuid: val.uuid || '',
544
+ alias: val.alias
545
+ });
546
+ }
547
+ if (type === AliasType.field) {
548
+ nextItem.subQuery = changeFieldAlias(v.subQuery || [], {
549
+ fieldUuid: val.uuid || '',
268
550
  fieldAlias: val.alias
269
551
  });
270
552
  }
271
- return v;
272
553
  } else if (v.type === AtomsTypeEnum.FORMULA) {
273
- v.args = _changeAlias(v.args, val, type);
274
- return v;
554
+ nextItem = _objectSpread(_objectSpread({}, v), {}, {
555
+ args: _changeAlias(v.args || [], val, type)
556
+ });
275
557
  } else if (v.type === AtomsTypeEnum.COLLECTION) {
276
- v.list = _changeAlias(v.list, val, type);
277
- return v;
558
+ nextItem = _objectSpread(_objectSpread({}, v), {}, {
559
+ list: _changeAlias(v.list || [], val, type)
560
+ });
561
+ } else if (v.type === AtomsTypeEnum.CASE_WHEN) {
562
+ nextItem = _objectSpread(_objectSpread({}, v), {}, {
563
+ caseAtoms: _changeAlias(v.caseAtoms || [], val, type),
564
+ whenClauses: (v.whenClauses || []).map(function (clause) {
565
+ return _objectSpread(_objectSpread({}, clause), {}, {
566
+ whenAtoms: _changeAlias(clause.whenAtoms || [], val, type),
567
+ thenAtoms: _changeAlias(clause.thenAtoms || [], val, type)
568
+ });
569
+ }),
570
+ elseAtoms: _changeAlias(v.elseAtoms || [], val, type)
571
+ });
572
+ } else if (v.type === AtomsTypeEnum.AND_OR) {
573
+ var hasBinarySides = Array.isArray(v.leftAtoms) || Array.isArray(v.rightAtoms);
574
+ nextItem = _objectSpread(_objectSpread({}, v), hasBinarySides ? {
575
+ atoms: undefined,
576
+ leftAtoms: _changeAlias(v.leftAtoms || [], val, type),
577
+ rightAtoms: _changeAlias(v.rightAtoms || [], val, type)
578
+ } : {
579
+ atoms: _changeAlias(v.atoms || [], val, type)
580
+ });
278
581
  } else {
279
- return v;
582
+ nextItem = v;
280
583
  }
584
+ return syncAtomQuotes(nextItem);
281
585
  });
282
586
  };
283
587
  export function isValidSQLAlias(str) {
@@ -340,27 +644,27 @@ export var changeTableAlias = function changeTableAlias(list, curObj) {
340
644
  }
341
645
  if (v.type === TypeEnum.summarize) {
342
646
  v.group.map(function (group) {
343
- if (group.tableUuid === tableUuid) {
647
+ var groupAtoms = group.atoms;
648
+ if (groupAtoms && groupAtoms.length > 0) {
649
+ group.atoms = _changeAlias(groupAtoms, {
650
+ uuid: tableUuid,
651
+ alias: alias
652
+ }, AliasType.table);
653
+ group.sql = summarizeToSql(v.group, group).sql;
654
+ } else if (group.tableUuid === tableUuid) {
344
655
  group.alias = alias;
345
- var groupAtoms = group.atoms;
346
- if (groupAtoms && groupAtoms.length > 0) {
347
- group.atoms = _changeAlias(groupAtoms, {
348
- uuid: tableUuid,
349
- alias: alias
350
- }, AliasType.table);
351
- }
352
656
  group.sql = summarizeToSql(v.group, group).sql;
353
657
  }
354
658
  });
355
659
  v.by.map(function (by) {
356
- if (by.tableUuid === tableUuid) {
660
+ if (by.atoms && by.atoms.length > 0) {
661
+ by.atoms = _changeAlias(by.atoms, {
662
+ uuid: tableUuid,
663
+ alias: alias
664
+ }, AliasType.table);
665
+ by.sql = summarizeByToSql(by);
666
+ } else if (by.tableUuid === tableUuid) {
357
667
  by.alias = alias;
358
- if (by.atoms && by.atoms.length > 0) {
359
- by.atoms = _changeAlias(by.atoms, {
360
- uuid: tableUuid,
361
- alias: alias
362
- }, AliasType.table);
363
- }
364
668
  by.sql = summarizeByToSql(by);
365
669
  }
366
670
  });
@@ -377,74 +681,76 @@ export var changeTableAlias = function changeTableAlias(list, curObj) {
377
681
  })) || [];
378
682
  };
379
683
  export var changeFieldAlias = function changeFieldAlias(list, curObj) {
684
+ var _firstData$table, _firstData$table2, _firstData$table3, _firstData$table4;
380
685
  var _cloneDeep2 = cloneDeep(curObj),
381
686
  uuid = _cloneDeep2.fieldUuid,
382
- alias = _cloneDeep2.fieldAlias;
687
+ alias = _cloneDeep2.fieldAlias,
688
+ fieldId = _cloneDeep2.id,
689
+ fieldName = _cloneDeep2.name,
690
+ datasourceId = _cloneDeep2.datasourceId,
691
+ table = _cloneDeep2.table,
692
+ tableId = _cloneDeep2.tableId,
693
+ tableUuid = _cloneDeep2.tableUuid;
694
+ var firstData = list.find(function (item) {
695
+ return item.type === TypeEnum.data;
696
+ });
697
+ var aliasTarget = {
698
+ uuid: uuid,
699
+ alias: alias,
700
+ fieldId: curObj.fieldId || fieldId,
701
+ fieldName: fieldName,
702
+ tableId: tableId || (firstData === null || firstData === void 0 || (_firstData$table = firstData.table) === null || _firstData$table === void 0 ? void 0 : _firstData$table.id),
703
+ tableName: table || (firstData === null || firstData === void 0 || (_firstData$table2 = firstData.table) === null || _firstData$table2 === void 0 ? void 0 : _firstData$table2.name),
704
+ tableUuid: tableUuid || (firstData === null || firstData === void 0 || (_firstData$table3 = firstData.table) === null || _firstData$table3 === void 0 ? void 0 : _firstData$table3.tableUuid),
705
+ datasourceId: datasourceId || (firstData === null || firstData === void 0 || (_firstData$table4 = firstData.table) === null || _firstData$table4 === void 0 ? void 0 : _firstData$table4.datasourceId)
706
+ };
383
707
  var newList = cloneDeep(list);
384
708
  return (newList === null || newList === void 0 ? void 0 : newList.map(function (v) {
385
709
  if (v.type === TypeEnum.data) {}
386
710
  if (v.type === TypeEnum.joinData) {
387
711
  if (v.expressions && v.expressions.length > 0) {
388
- v.expressions = _changeAlias(v.expressions, {
389
- uuid: uuid,
390
- alias: alias
391
- }, AliasType.field);
712
+ v.expressions = _changeAlias(v.expressions, aliasTarget, AliasType.field);
392
713
  }
393
714
  }
394
715
  if (v.type === TypeEnum.customColumn) {
395
716
  v.customColumn.map(function (item) {
396
717
  if (item.formulaList && item.formulaList.length > 0) {
397
- item.formulaList = _changeAlias(item.formulaList, {
398
- uuid: uuid,
399
- alias: alias
400
- }, AliasType.field);
718
+ item.formulaList = _changeAlias(item.formulaList, aliasTarget, AliasType.field);
401
719
  }
402
720
  });
403
721
  }
404
722
  if (v.type === TypeEnum.rowLimit) {}
405
723
  if (v.type === TypeEnum.summarize) {
406
724
  v.group.map(function (group) {
407
- if (group.fieldUuid === uuid) {
725
+ var groupAtoms = group.atoms;
726
+ if (groupAtoms && groupAtoms.length > 0) {
727
+ group.atoms = _changeAlias(groupAtoms, aliasTarget, AliasType.field);
728
+ group.sql = summarizeToSql(v.group, group).sql;
729
+ } else if (group.fieldUuid === uuid) {
408
730
  group.fieldAlias = alias;
409
- var groupAtoms = group.atoms;
410
- if (groupAtoms && groupAtoms.length > 0) {
411
- group.atoms = _changeAlias(groupAtoms, {
412
- uuid: uuid,
413
- alias: alias
414
- }, AliasType.field);
415
- }
416
731
  group.sql = summarizeToSql(v.group, group).sql;
417
732
  }
418
733
  });
419
734
  v.by.map(function (by) {
420
- if (by.fieldUuid === uuid) {
735
+ if (by.atoms && by.atoms.length > 0) {
736
+ by.atoms = _changeAlias(by.atoms, aliasTarget, AliasType.field);
737
+ by.sql = summarizeByToSql(by);
738
+ } else if (by.fieldUuid === uuid) {
421
739
  by.fieldAlias = alias;
422
- if (by.atoms && by.atoms.length > 0) {
423
- by.atoms = _changeAlias(by.atoms, {
424
- uuid: uuid,
425
- alias: alias
426
- }, AliasType.field);
427
- }
428
740
  by.sql = summarizeByToSql(by);
429
741
  }
430
742
  });
431
743
  }
432
744
  if (v.type === TypeEnum.filter) {
433
745
  if (v.filter && v.filter.length > 0) {
434
- v.filter = _changeAlias(v.filter, {
435
- uuid: uuid,
436
- alias: alias
437
- }, AliasType.field);
746
+ v.filter = _changeAlias(v.filter, aliasTarget, AliasType.field);
438
747
  }
439
748
  }
440
749
  if (v.type === TypeEnum.sort) {
441
750
  if (v.sort && v.sort.length > 0) {
442
751
  v.sort = v.sort.map(function (sort) {
443
752
  return _objectSpread(_objectSpread({}, sort), {}, {
444
- expression: _changeAlias(sort.expression, {
445
- uuid: uuid,
446
- alias: alias
447
- }, AliasType.field)
753
+ expression: _changeAlias(sort.expression, aliasTarget, AliasType.field)
448
754
  });
449
755
  });
450
756
  }
@@ -502,7 +808,8 @@ var stripSummarizeTableFields = function stripSummarizeTableFields(record) {
502
808
  tableUuid: '',
503
809
  alias: '',
504
810
  datasourceId: '',
505
- datasourceName: ''
811
+ datasourceName: '',
812
+ datasourceType: ''
506
813
  });
507
814
  };
508
815
  var createSummarizeFieldAtom = function createSummarizeFieldAtom(record) {
@@ -520,6 +827,7 @@ var createSummarizeFieldAtom = function createSummarizeFieldAtom(record) {
520
827
  tableUuid: record.tableUuid || '',
521
828
  datasourceName: record.datasourceName || '',
522
829
  datasourceId: record.datasourceId || '',
830
+ datasourceType: record.datasourceType || '',
523
831
  type: AtomsTypeEnum.FIELD
524
832
  };
525
833
  };
@@ -782,6 +1090,7 @@ function setNewField(field, data) {
782
1090
  }
783
1091
  field.datasourceId = table.datasourceId || '';
784
1092
  field.datasourceName = table.datasourceName || '';
1093
+ field.datasourceType = table.datasourceType || '';
785
1094
  field.tableId = table.id || '';
786
1095
  field.tableName = table.name || '';
787
1096
  field.tableAlias = table.alias || '';
@@ -821,6 +1130,15 @@ var _changeCopyField = function changeCopyField(items, data) {
821
1130
  } else if (v.type === AtomsTypeEnum.FORMULA) {
822
1131
  v.args = _changeCopyField(v.args, data);
823
1132
  return v;
1133
+ } else if (v.type === AtomsTypeEnum.AND_OR) {
1134
+ var hasBinarySides = Array.isArray(v.leftAtoms) || Array.isArray(v.rightAtoms);
1135
+ return _objectSpread(_objectSpread({}, v), hasBinarySides ? {
1136
+ atoms: undefined,
1137
+ leftAtoms: _changeCopyField(v.leftAtoms || [], data),
1138
+ rightAtoms: _changeCopyField(v.rightAtoms || [], data)
1139
+ } : {
1140
+ atoms: _changeCopyField(v.atoms || [], data)
1141
+ });
824
1142
  } else if (v.type === AtomsTypeEnum.COLLECTION) {
825
1143
  v.list = _changeCopyField(v.list, data);
826
1144
  return v;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.125",
3
+ "version": "1.0.127",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",