@gingkoo/pandora-metabase 1.0.126 → 1.0.128

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 +67 -16
  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 +26 -5
  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 +349 -58
  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 +67 -16
  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 +26 -5
  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 +350 -59
  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';
@@ -131,7 +131,7 @@ export var getSubColumns = function getSubColumns(metaList) {
131
131
  _data.columns = _data.columns.concat(prevGroupBy.group.map(function (v) {
132
132
  var _v$sql;
133
133
  return _objectSpread(_objectSpread({}, v), {}, {
134
- name: v.name || v.quotes,
134
+ name: v.fieldAlias || v.name || v.quotes,
135
135
  name_zh: v.name_zh || v.quotes,
136
136
  id: v.id || v.fieldId,
137
137
  realName: ((_v$sql = v.sql) === null || _v$sql === void 0 || (_v$sql = _v$sql.split(' AS ')) === null || _v$sql === void 0 ? void 0 : _v$sql[1]) || '',
@@ -145,7 +145,7 @@ export var getSubColumns = function getSubColumns(metaList) {
145
145
  _data.columns = _data.columns.concat(prevGroupBy.by.map(function (v) {
146
146
  var _v$sql2;
147
147
  return _objectSpread(_objectSpread({}, v), {}, {
148
- name: v.name || v.quotes,
148
+ name: v.fieldAlias || v.name || v.quotes,
149
149
  name_zh: v.name_zh || v.quotes,
150
150
  id: v.id || v.fieldId,
151
151
  realName: ((_v$sql2 = v.sql) === null || _v$sql2 === void 0 || (_v$sql2 = _v$sql2.split(' AS ')) === null || _v$sql2 === void 0 ? void 0 : _v$sql2[1]) || '',
@@ -240,71 +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 || '',
268
536
  fieldAlias: val.alias
269
537
  });
270
538
  }
271
- return v;
272
539
  } else if (v.type === AtomsTypeEnum.SUB_QUERY) {
540
+ nextItem = _objectSpread({}, v);
273
541
  if (type === AliasType.table) {
274
- v.subQuery = changeTableAlias(v.subQuery || [], {
275
- tableUuid: val.uuid,
542
+ nextItem.subQuery = changeTableAlias(v.subQuery || [], {
543
+ tableUuid: val.uuid || '',
276
544
  alias: val.alias
277
545
  });
278
546
  }
279
547
  if (type === AliasType.field) {
280
- v.subQuery = changeFieldAlias(v.subQuery || [], {
281
- fieldUuid: val.uuid,
548
+ nextItem.subQuery = changeFieldAlias(v.subQuery || [], {
549
+ fieldUuid: val.uuid || '',
282
550
  fieldAlias: val.alias
283
551
  });
284
552
  }
285
- return v;
286
553
  } else if (v.type === AtomsTypeEnum.FORMULA) {
287
- v.args = _changeAlias(v.args, val, type);
288
- return v;
554
+ nextItem = _objectSpread(_objectSpread({}, v), {}, {
555
+ args: _changeAlias(v.args || [], val, type)
556
+ });
289
557
  } else if (v.type === AtomsTypeEnum.COLLECTION) {
290
- v.list = _changeAlias(v.list, val, type);
291
- return v;
558
+ nextItem = _objectSpread(_objectSpread({}, v), {}, {
559
+ list: _changeAlias(v.list || [], val, type)
560
+ });
292
561
  } else if (v.type === AtomsTypeEnum.CASE_WHEN) {
293
- v.caseValue = _changeAlias(v.caseValue || [], val, type);
294
- v.branches = (v.branches || []).map(function (branch) {
295
- return _objectSpread(_objectSpread({}, branch), {}, {
296
- when: _changeAlias(branch.when || [], val, type),
297
- then: _changeAlias(branch.then || [], val, type)
298
- });
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)
299
571
  });
300
- v.elseValue = _changeAlias(v.elseValue || [], val, type);
301
- return v;
302
572
  } else if (v.type === AtomsTypeEnum.AND_OR) {
303
- v.list = _changeAlias(v.list || [], val, type);
304
- return v;
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
+ });
305
581
  } else {
306
- return v;
582
+ nextItem = v;
307
583
  }
584
+ return syncAtomQuotes(nextItem);
308
585
  });
309
586
  };
310
587
  export function isValidSQLAlias(str) {
@@ -404,27 +681,41 @@ export var changeTableAlias = function changeTableAlias(list, curObj) {
404
681
  })) || [];
405
682
  };
406
683
  export var changeFieldAlias = function changeFieldAlias(list, curObj) {
684
+ var _firstData$table, _firstData$table2, _firstData$table3, _firstData$table4;
407
685
  var _cloneDeep2 = cloneDeep(curObj),
408
686
  uuid = _cloneDeep2.fieldUuid,
409
- 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
+ };
410
707
  var newList = cloneDeep(list);
411
708
  return (newList === null || newList === void 0 ? void 0 : newList.map(function (v) {
412
709
  if (v.type === TypeEnum.data) {}
413
710
  if (v.type === TypeEnum.joinData) {
414
711
  if (v.expressions && v.expressions.length > 0) {
415
- v.expressions = _changeAlias(v.expressions, {
416
- uuid: uuid,
417
- alias: alias
418
- }, AliasType.field);
712
+ v.expressions = _changeAlias(v.expressions, aliasTarget, AliasType.field);
419
713
  }
420
714
  }
421
715
  if (v.type === TypeEnum.customColumn) {
422
716
  v.customColumn.map(function (item) {
423
717
  if (item.formulaList && item.formulaList.length > 0) {
424
- item.formulaList = _changeAlias(item.formulaList, {
425
- uuid: uuid,
426
- alias: alias
427
- }, AliasType.field);
718
+ item.formulaList = _changeAlias(item.formulaList, aliasTarget, AliasType.field);
428
719
  }
429
720
  });
430
721
  }
@@ -433,10 +724,7 @@ export var changeFieldAlias = function changeFieldAlias(list, curObj) {
433
724
  v.group.map(function (group) {
434
725
  var groupAtoms = group.atoms;
435
726
  if (groupAtoms && groupAtoms.length > 0) {
436
- group.atoms = _changeAlias(groupAtoms, {
437
- uuid: uuid,
438
- alias: alias
439
- }, AliasType.field);
727
+ group.atoms = _changeAlias(groupAtoms, aliasTarget, AliasType.field);
440
728
  group.sql = summarizeToSql(v.group, group).sql;
441
729
  } else if (group.fieldUuid === uuid) {
442
730
  group.fieldAlias = alias;
@@ -445,10 +733,7 @@ export var changeFieldAlias = function changeFieldAlias(list, curObj) {
445
733
  });
446
734
  v.by.map(function (by) {
447
735
  if (by.atoms && by.atoms.length > 0) {
448
- by.atoms = _changeAlias(by.atoms, {
449
- uuid: uuid,
450
- alias: alias
451
- }, AliasType.field);
736
+ by.atoms = _changeAlias(by.atoms, aliasTarget, AliasType.field);
452
737
  by.sql = summarizeByToSql(by);
453
738
  } else if (by.fieldUuid === uuid) {
454
739
  by.fieldAlias = alias;
@@ -458,20 +743,14 @@ export var changeFieldAlias = function changeFieldAlias(list, curObj) {
458
743
  }
459
744
  if (v.type === TypeEnum.filter) {
460
745
  if (v.filter && v.filter.length > 0) {
461
- v.filter = _changeAlias(v.filter, {
462
- uuid: uuid,
463
- alias: alias
464
- }, AliasType.field);
746
+ v.filter = _changeAlias(v.filter, aliasTarget, AliasType.field);
465
747
  }
466
748
  }
467
749
  if (v.type === TypeEnum.sort) {
468
750
  if (v.sort && v.sort.length > 0) {
469
751
  v.sort = v.sort.map(function (sort) {
470
752
  return _objectSpread(_objectSpread({}, sort), {}, {
471
- expression: _changeAlias(sort.expression, {
472
- uuid: uuid,
473
- alias: alias
474
- }, AliasType.field)
753
+ expression: _changeAlias(sort.expression, aliasTarget, AliasType.field)
475
754
  });
476
755
  });
477
756
  }
@@ -529,7 +808,8 @@ var stripSummarizeTableFields = function stripSummarizeTableFields(record) {
529
808
  tableUuid: '',
530
809
  alias: '',
531
810
  datasourceId: '',
532
- datasourceName: ''
811
+ datasourceName: '',
812
+ datasourceType: ''
533
813
  });
534
814
  };
535
815
  var createSummarizeFieldAtom = function createSummarizeFieldAtom(record) {
@@ -547,6 +827,7 @@ var createSummarizeFieldAtom = function createSummarizeFieldAtom(record) {
547
827
  tableUuid: record.tableUuid || '',
548
828
  datasourceName: record.datasourceName || '',
549
829
  datasourceId: record.datasourceId || '',
830
+ datasourceType: record.datasourceType || '',
550
831
  type: AtomsTypeEnum.FIELD
551
832
  };
552
833
  };
@@ -809,6 +1090,7 @@ function setNewField(field, data) {
809
1090
  }
810
1091
  field.datasourceId = table.datasourceId || '';
811
1092
  field.datasourceName = table.datasourceName || '';
1093
+ field.datasourceType = table.datasourceType || '';
812
1094
  field.tableId = table.id || '';
813
1095
  field.tableName = table.name || '';
814
1096
  field.tableAlias = table.alias || '';
@@ -848,6 +1130,15 @@ var _changeCopyField = function changeCopyField(items, data) {
848
1130
  } else if (v.type === AtomsTypeEnum.FORMULA) {
849
1131
  v.args = _changeCopyField(v.args, data);
850
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
+ });
851
1142
  } else if (v.type === AtomsTypeEnum.COLLECTION) {
852
1143
  v.list = _changeCopyField(v.list, data);
853
1144
  return v;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.126",
3
+ "version": "1.0.128",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",