@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.
- package/lib/cjs/components/dialog/expression/index.js +15 -5
- package/lib/cjs/components/dialog/expression/index.less +31 -16
- package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.d.ts +14 -5
- package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.js +236 -62
- package/lib/cjs/components/dialog/formula-list/LogicGroup.d.ts +3 -2
- package/lib/cjs/components/dialog/formula-list/LogicGroup.js +19 -11
- package/lib/cjs/components/dialog/formula-list/index.d.ts +1 -0
- package/lib/cjs/components/dialog/formula-list/index.js +658 -174
- package/lib/cjs/components/dialog/formula-list/index.less +1438 -145
- package/lib/cjs/components/dialog/formula-list/utils.js +50 -19
- package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +1 -0
- package/lib/cjs/components/dialog/select-column-multiple/index.js +42 -22
- package/lib/cjs/components/dialog/select-summarize/index.js +10 -2
- package/lib/cjs/components/dialog/select-table/index.d.ts +2 -1
- package/lib/cjs/components/dialog/select-table/index.js +197 -52
- package/lib/cjs/components/dialog/select-table/index.less +45 -2
- package/lib/cjs/components/metabase/index.less +156 -39
- package/lib/cjs/components/modules/custom-column.js +7 -3
- package/lib/cjs/components/modules/filter.js +6 -3
- package/lib/cjs/components/modules/join-data.js +62 -14
- package/lib/cjs/components/modules/permission-table.js +8 -4
- package/lib/cjs/components/modules/sort.js +2 -1
- package/lib/cjs/components/modules/summarize/group-by.js +20 -6
- package/lib/cjs/components/modules/summarize/select-index.js +9 -5
- package/lib/cjs/components/modules/table-data.js +21 -3
- package/lib/cjs/hooks/use-state.js +143 -17
- package/lib/cjs/index.js +7 -1
- package/lib/cjs/store/types.d.ts +14 -7
- package/lib/cjs/types.d.ts +8 -0
- package/lib/cjs/utils/transformSql.js +44 -21
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +381 -63
- package/lib/es/components/dialog/expression/index.js +15 -5
- package/lib/es/components/dialog/expression/index.less +31 -16
- package/lib/es/components/dialog/formula-list/CaseWhenGroup.d.ts +14 -5
- package/lib/es/components/dialog/formula-list/CaseWhenGroup.js +238 -64
- package/lib/es/components/dialog/formula-list/LogicGroup.d.ts +3 -2
- package/lib/es/components/dialog/formula-list/LogicGroup.js +19 -11
- package/lib/es/components/dialog/formula-list/index.d.ts +1 -0
- package/lib/es/components/dialog/formula-list/index.js +660 -176
- package/lib/es/components/dialog/formula-list/index.less +1438 -145
- package/lib/es/components/dialog/formula-list/utils.js +50 -19
- package/lib/es/components/dialog/select-column-multiple/index.d.ts +1 -0
- package/lib/es/components/dialog/select-column-multiple/index.js +42 -22
- package/lib/es/components/dialog/select-summarize/index.js +10 -2
- package/lib/es/components/dialog/select-table/index.d.ts +2 -1
- package/lib/es/components/dialog/select-table/index.js +197 -52
- package/lib/es/components/dialog/select-table/index.less +45 -2
- package/lib/es/components/metabase/index.less +156 -39
- package/lib/es/components/modules/custom-column.js +7 -3
- package/lib/es/components/modules/filter.js +6 -3
- package/lib/es/components/modules/join-data.js +62 -14
- package/lib/es/components/modules/permission-table.js +8 -4
- package/lib/es/components/modules/sort.js +2 -1
- package/lib/es/components/modules/summarize/group-by.js +21 -7
- package/lib/es/components/modules/summarize/select-index.js +10 -6
- package/lib/es/components/modules/table-data.js +21 -3
- package/lib/es/hooks/use-state.js +143 -17
- package/lib/es/index.js +7 -1
- package/lib/es/store/types.d.ts +14 -7
- package/lib/es/types.d.ts +8 -0
- package/lib/es/utils/transformSql.js +45 -22
- package/lib/es/utils.d.ts +2 -2
- package/lib/es/utils.js +382 -64
- package/package.json +1 -1
|
@@ -19,7 +19,7 @@ var _enum = require("../store/enum");
|
|
|
19
19
|
var _utils = require("../utils");
|
|
20
20
|
var _storage = _interopRequireDefault(require("../utils/storage"));
|
|
21
21
|
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
22
|
-
var _excluded = ["alias", "datasourceName", "datasourceId", "column"];
|
|
22
|
+
var _excluded = ["alias", "datasourceName", "datasourceId", "datasourceType", "column"];
|
|
23
23
|
var metaKey = 1;
|
|
24
24
|
var SummarizeAlias = exports.SummarizeAlias = 'source';
|
|
25
25
|
var useStore = function useStore() {
|
|
@@ -34,6 +34,7 @@ var useStore = function useStore() {
|
|
|
34
34
|
alias: '',
|
|
35
35
|
datasourceId: '',
|
|
36
36
|
datasourceName: '',
|
|
37
|
+
datasourceType: '',
|
|
37
38
|
tableUuid: (0, _helper.uuidv4)('table')
|
|
38
39
|
},
|
|
39
40
|
columns: []
|
|
@@ -318,10 +319,97 @@ var useStore = function useStore() {
|
|
|
318
319
|
});
|
|
319
320
|
}, [metaList]);
|
|
320
321
|
(0, _react.useEffect)(function () {
|
|
322
|
+
if (sourceList.length) {
|
|
323
|
+
var metaListWithDefaultType = fillDefaultDatasourceTypeInMetaList(metaList, isExit);
|
|
324
|
+
if (metaListWithDefaultType !== metaList) {
|
|
325
|
+
setPreData(metaListWithDefaultType, isSubquery, isExit);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
321
328
|
if (tableFlat) {
|
|
322
329
|
getSourceTable(sourceList);
|
|
323
330
|
}
|
|
324
331
|
}, [sourceList, isExit, tableFlat]);
|
|
332
|
+
var getDefaultDatasourceType = function getDefaultDatasourceType(datasource) {
|
|
333
|
+
var _datasource$datasourc;
|
|
334
|
+
return (datasource === null || datasource === void 0 ? void 0 : datasource.defaultDatasourceType) || (datasource === null || datasource === void 0 ? void 0 : datasource.datasourceType) || (datasource === null || datasource === void 0 || (_datasource$datasourc = datasource.datasourceTypeList) === null || _datasource$datasourc === void 0 || (_datasource$datasourc = _datasource$datasourc[0]) === null || _datasource$datasourc === void 0 ? void 0 : _datasource$datasourc.value) || '';
|
|
335
|
+
};
|
|
336
|
+
var getActiveSourceList = function getActiveSourceList() {
|
|
337
|
+
var _props$exitSourceList, _props$sourceList;
|
|
338
|
+
var _isExit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : isExit;
|
|
339
|
+
var props = preProps.current || {};
|
|
340
|
+
if (_isExit && (_props$exitSourceList = props.exitSourceList) !== null && _props$exitSourceList !== void 0 && _props$exitSourceList.length) {
|
|
341
|
+
return props.exitSourceList;
|
|
342
|
+
}
|
|
343
|
+
if ((_props$sourceList = props.sourceList) !== null && _props$sourceList !== void 0 && _props$sourceList.length) {
|
|
344
|
+
return props.sourceList;
|
|
345
|
+
}
|
|
346
|
+
return sourceList;
|
|
347
|
+
};
|
|
348
|
+
var getDefaultDatasourceTypeById = function getDefaultDatasourceTypeById(datasourceId) {
|
|
349
|
+
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
350
|
+
if (!datasourceId) return '';
|
|
351
|
+
var datasource = getActiveSourceList(_isExit).find(function (item) {
|
|
352
|
+
return item.datasourceId === datasourceId;
|
|
353
|
+
});
|
|
354
|
+
return getDefaultDatasourceType(datasource);
|
|
355
|
+
};
|
|
356
|
+
var fillDefaultDatasourceTypeInTable = function fillDefaultDatasourceTypeInTable(table) {
|
|
357
|
+
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
358
|
+
if (!(table !== null && table !== void 0 && table.datasourceId) || table.datasourceType) return false;
|
|
359
|
+
var defaultDatasourceType = getDefaultDatasourceTypeById(table.datasourceId, _isExit);
|
|
360
|
+
if (!defaultDatasourceType) return false;
|
|
361
|
+
table.datasourceType = defaultDatasourceType;
|
|
362
|
+
return true;
|
|
363
|
+
};
|
|
364
|
+
var fillDefaultDatasourceTypeInColumns = function fillDefaultDatasourceTypeInColumns(columns, datasourceType) {
|
|
365
|
+
if (!datasourceType || !Array.isArray(columns)) return false;
|
|
366
|
+
var changed = false;
|
|
367
|
+
columns.forEach(function (column) {
|
|
368
|
+
if (!column.datasourceType) {
|
|
369
|
+
column.datasourceType = datasourceType;
|
|
370
|
+
changed = true;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
return changed;
|
|
374
|
+
};
|
|
375
|
+
var _fillDefaultDatasourceTypeInList = function fillDefaultDatasourceTypeInList(list) {
|
|
376
|
+
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
377
|
+
if (!Array.isArray(list)) return false;
|
|
378
|
+
var changed = false;
|
|
379
|
+
list.forEach(function (item) {
|
|
380
|
+
if (item.table) {
|
|
381
|
+
changed = fillDefaultDatasourceTypeInTable(item.table, _isExit) || changed;
|
|
382
|
+
changed = fillDefaultDatasourceTypeInColumns(item.columns, item.table.datasourceType) || changed;
|
|
383
|
+
}
|
|
384
|
+
if (item.table1) {
|
|
385
|
+
changed = fillDefaultDatasourceTypeInTable(item.table1, _isExit) || changed;
|
|
386
|
+
}
|
|
387
|
+
if (item.table2) {
|
|
388
|
+
changed = fillDefaultDatasourceTypeInTable(item.table2, _isExit) || changed;
|
|
389
|
+
changed = fillDefaultDatasourceTypeInColumns(item.columns, item.table2.datasourceType) || changed;
|
|
390
|
+
}
|
|
391
|
+
if (Array.isArray(item.subquery)) {
|
|
392
|
+
changed = _fillDefaultDatasourceTypeInList(item.subquery, _isExit) || changed;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
return changed;
|
|
396
|
+
};
|
|
397
|
+
var fillDefaultDatasourceTypeInMetaList = function fillDefaultDatasourceTypeInMetaList() {
|
|
398
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
399
|
+
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
400
|
+
if (!data.length) return data;
|
|
401
|
+
var nextData = (0, _cloneDeep["default"])(data);
|
|
402
|
+
var changed = false;
|
|
403
|
+
nextData.forEach(function (group) {
|
|
404
|
+
changed = _fillDefaultDatasourceTypeInList(group.list, _isExit) || changed;
|
|
405
|
+
changed = _fillDefaultDatasourceTypeInList(group.subquery, _isExit) || changed;
|
|
406
|
+
});
|
|
407
|
+
return changed ? nextData : data;
|
|
408
|
+
};
|
|
409
|
+
var getDatasetCacheKey = function getDatasetCacheKey(datasourceId) {
|
|
410
|
+
var datasourceType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
411
|
+
return datasourceType ? "".concat(datasourceId, "__").concat(datasourceType) : datasourceId;
|
|
412
|
+
};
|
|
325
413
|
var getSourceTable = function () {
|
|
326
414
|
var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4(source) {
|
|
327
415
|
var results;
|
|
@@ -331,15 +419,17 @@ var useStore = function useStore() {
|
|
|
331
419
|
_context4.next = 1;
|
|
332
420
|
return Promise.all(source.map(function () {
|
|
333
421
|
var _ref4 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3(v) {
|
|
334
|
-
var tables;
|
|
422
|
+
var datasourceType, tables;
|
|
335
423
|
return _regenerator["default"].wrap(function (_context3) {
|
|
336
424
|
while (1) switch (_context3.prev = _context3.next) {
|
|
337
425
|
case 0:
|
|
426
|
+
datasourceType = getDefaultDatasourceType(v);
|
|
338
427
|
_context3.next = 1;
|
|
339
|
-
return fetchDataset(v.datasourceId);
|
|
428
|
+
return fetchDataset(v.datasourceId, datasourceType);
|
|
340
429
|
case 1:
|
|
341
430
|
tables = _context3.sent;
|
|
342
431
|
return _context3.abrupt("return", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v), {}, {
|
|
432
|
+
datasourceType: datasourceType,
|
|
343
433
|
children: tables
|
|
344
434
|
}));
|
|
345
435
|
case 2:
|
|
@@ -370,24 +460,34 @@ var useStore = function useStore() {
|
|
|
370
460
|
};
|
|
371
461
|
var fetchDataset = function () {
|
|
372
462
|
var _ref5 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5(datasourceId) {
|
|
373
|
-
var
|
|
463
|
+
var _preProps$current;
|
|
464
|
+
var datasourceType,
|
|
465
|
+
force,
|
|
466
|
+
tables,
|
|
467
|
+
fetchTables,
|
|
468
|
+
_tables,
|
|
469
|
+
_args5 = arguments;
|
|
374
470
|
return _regenerator["default"].wrap(function (_context5) {
|
|
375
471
|
while (1) switch (_context5.prev = _context5.next) {
|
|
376
472
|
case 0:
|
|
377
|
-
|
|
378
|
-
|
|
473
|
+
datasourceType = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : '';
|
|
474
|
+
force = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : false;
|
|
475
|
+
tables = getDataset(datasourceId, datasourceType);
|
|
476
|
+
if (!(!force && tables.length)) {
|
|
379
477
|
_context5.next = 1;
|
|
380
478
|
break;
|
|
381
479
|
}
|
|
382
480
|
return _context5.abrupt("return", tables);
|
|
383
481
|
case 1:
|
|
482
|
+
fetchTables = ((_preProps$current = preProps.current) === null || _preProps$current === void 0 ? void 0 : _preProps$current.getTables) || fetchDatasetFn.current;
|
|
384
483
|
_context5.next = 2;
|
|
385
|
-
return
|
|
386
|
-
isExit: isExit
|
|
484
|
+
return fetchTables(datasourceId, {
|
|
485
|
+
isExit: isExit,
|
|
486
|
+
datasourceType: datasourceType
|
|
387
487
|
});
|
|
388
488
|
case 2:
|
|
389
489
|
_tables = _context5.sent;
|
|
390
|
-
setDataset(datasourceId, _tables);
|
|
490
|
+
setDataset(datasourceId, _tables, datasourceType);
|
|
391
491
|
return _context5.abrupt("return", _tables);
|
|
392
492
|
case 3:
|
|
393
493
|
case "end":
|
|
@@ -413,9 +513,11 @@ var useStore = function useStore() {
|
|
|
413
513
|
alias,
|
|
414
514
|
datasourceName,
|
|
415
515
|
did,
|
|
516
|
+
datasourceType,
|
|
416
517
|
column,
|
|
417
518
|
extra,
|
|
418
519
|
tableName,
|
|
520
|
+
tableCacheKey,
|
|
419
521
|
columns,
|
|
420
522
|
_columns,
|
|
421
523
|
_args6 = arguments;
|
|
@@ -440,26 +542,31 @@ var useStore = function useStore() {
|
|
|
440
542
|
selectId = [];
|
|
441
543
|
isSelect = false;
|
|
442
544
|
}
|
|
443
|
-
_table$alias = table.alias, alias = _table$alias === void 0 ? '' : _table$alias, datasourceName = table.datasourceName, did = table.datasourceId, column = table.column, extra = (0, _objectWithoutProperties2["default"])(table, _excluded);
|
|
545
|
+
_table$alias = table.alias, alias = _table$alias === void 0 ? '' : _table$alias, datasourceName = table.datasourceName, did = table.datasourceId, datasourceType = table.datasourceType, column = table.column, extra = (0, _objectWithoutProperties2["default"])(table, _excluded);
|
|
444
546
|
tableName = table.name;
|
|
445
|
-
|
|
547
|
+
tableCacheKey = getDatasetCacheKey("".concat(datasourceId, "_").concat(tableName), datasourceType || '');
|
|
548
|
+
columns = getColumns(tableCacheKey);
|
|
446
549
|
if (columns.length) {
|
|
447
550
|
_context6.next = 2;
|
|
448
551
|
break;
|
|
449
552
|
}
|
|
450
553
|
_context6.next = 1;
|
|
451
554
|
return fetchColumnsFn.current(extra, datasourceId, {
|
|
452
|
-
isExit: _isExit
|
|
555
|
+
isExit: _isExit,
|
|
556
|
+
datasourceType: datasourceType
|
|
453
557
|
});
|
|
454
558
|
case 1:
|
|
455
559
|
columns = _context6.sent;
|
|
456
|
-
setColumns(
|
|
560
|
+
setColumns(tableCacheKey, columns);
|
|
457
561
|
case 2:
|
|
458
562
|
_columns = (_columns2 = columns) === null || _columns2 === void 0 ? void 0 : _columns2.map(function (v) {
|
|
459
563
|
var select = selectId.includes(v.id);
|
|
460
564
|
var obj = {};
|
|
461
565
|
obj = oldObj[v.id] || {};
|
|
462
566
|
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, obj), v), {}, {
|
|
567
|
+
datasourceId: obj.datasourceId || v.datasourceId || did || datasourceId || '',
|
|
568
|
+
datasourceName: obj.datasourceName || v.datasourceName || datasourceName || '',
|
|
569
|
+
datasourceType: obj.datasourceType || v.datasourceType || datasourceType || '',
|
|
463
570
|
select: isSelect || select,
|
|
464
571
|
fieldUuid: obj.fieldUuid || v.fieldUuid || (0, _helper.uuidv4)('field')
|
|
465
572
|
});
|
|
@@ -527,7 +634,16 @@ var useStore = function useStore() {
|
|
|
527
634
|
var _v$table, _v$table2;
|
|
528
635
|
var newMeta = item.list;
|
|
529
636
|
if (v.table) {
|
|
637
|
+
fillDefaultDatasourceTypeInTable(v.table, _isExit);
|
|
530
638
|
v.table.tableUuid = v.table.tableUuid || (0, _helper.uuidv4)('table');
|
|
639
|
+
fillDefaultDatasourceTypeInColumns(v.columns, v.table.datasourceType);
|
|
640
|
+
}
|
|
641
|
+
if (v.table1) {
|
|
642
|
+
fillDefaultDatasourceTypeInTable(v.table1, _isExit);
|
|
643
|
+
}
|
|
644
|
+
if (v.table2) {
|
|
645
|
+
fillDefaultDatasourceTypeInTable(v.table2, _isExit);
|
|
646
|
+
fillDefaultDatasourceTypeInColumns(v.columns, v.table2.datasourceType);
|
|
531
647
|
}
|
|
532
648
|
if ((_v$table = v.table2) !== null && _v$table !== void 0 && _v$table.datasourceId) {
|
|
533
649
|
fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, v.columns, function () {
|
|
@@ -535,6 +651,8 @@ var useStore = function useStore() {
|
|
|
535
651
|
if (v.isSubquery) {} else {
|
|
536
652
|
newMeta[i].columns = columns || [];
|
|
537
653
|
}
|
|
654
|
+
fillDefaultDatasourceTypeInTable(newMeta[i].table2, _isExit);
|
|
655
|
+
fillDefaultDatasourceTypeInColumns(newMeta[i].columns, newMeta[i].table2.datasourceType);
|
|
538
656
|
setMeta(newMeta, groupIndex, 'init', data);
|
|
539
657
|
}, false, _isSubquery, _isExit);
|
|
540
658
|
return (0, _objectSpread2["default"])({}, v);
|
|
@@ -545,6 +663,8 @@ var useStore = function useStore() {
|
|
|
545
663
|
if (v.isSubquery) {} else {
|
|
546
664
|
newMeta[i].columns = columns || [];
|
|
547
665
|
}
|
|
666
|
+
fillDefaultDatasourceTypeInTable(newMeta[i].table, _isExit);
|
|
667
|
+
fillDefaultDatasourceTypeInColumns(newMeta[i].columns, newMeta[i].table.datasourceType);
|
|
548
668
|
setMeta(newMeta, groupIndex, 'init', data);
|
|
549
669
|
}, false, _isSubquery, _isExit);
|
|
550
670
|
return (0, _objectSpread2["default"])({}, v);
|
|
@@ -663,6 +783,7 @@ var useStore = function useStore() {
|
|
|
663
783
|
tableUuid: '',
|
|
664
784
|
datasourceId: '',
|
|
665
785
|
datasourceName: '',
|
|
786
|
+
datasourceType: '',
|
|
666
787
|
fieldAlias: '',
|
|
667
788
|
fieldUuid: '',
|
|
668
789
|
fields: []
|
|
@@ -674,6 +795,7 @@ var useStore = function useStore() {
|
|
|
674
795
|
name_zh: mainTable.table.name_zh,
|
|
675
796
|
datasourceId: mainTable.table.datasourceId,
|
|
676
797
|
datasourceName: mainTable.table.datasourceName,
|
|
798
|
+
datasourceType: mainTable.table.datasourceType || '',
|
|
677
799
|
fieldAlias: '',
|
|
678
800
|
fieldUuid: '',
|
|
679
801
|
fields: []
|
|
@@ -691,7 +813,8 @@ var useStore = function useStore() {
|
|
|
691
813
|
alias: '',
|
|
692
814
|
tableUuid: '',
|
|
693
815
|
datasourceId: '',
|
|
694
|
-
datasourceName: ''
|
|
816
|
+
datasourceName: '',
|
|
817
|
+
datasourceType: ''
|
|
695
818
|
},
|
|
696
819
|
columns: [],
|
|
697
820
|
expressions: []
|
|
@@ -746,7 +869,8 @@ var useStore = function useStore() {
|
|
|
746
869
|
alias: '',
|
|
747
870
|
tableUuid: '',
|
|
748
871
|
datasourceId: '',
|
|
749
|
-
datasourceName: ''
|
|
872
|
+
datasourceName: '',
|
|
873
|
+
datasourceType: ''
|
|
750
874
|
}
|
|
751
875
|
};
|
|
752
876
|
}
|
|
@@ -901,12 +1025,14 @@ var useStore = function useStore() {
|
|
|
901
1025
|
return _cacheColumnsMap[tableId] || [];
|
|
902
1026
|
};
|
|
903
1027
|
var setDataset = function setDataset(datasourceId, tables) {
|
|
1028
|
+
var datasourceType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
904
1029
|
var map = (0, _objectSpread2["default"])({}, _cacheSource2TableMap);
|
|
905
|
-
map[datasourceId] = tables;
|
|
1030
|
+
map[getDatasetCacheKey(datasourceId, datasourceType)] = tables;
|
|
906
1031
|
set_cacheSource2TableMap(map);
|
|
907
1032
|
};
|
|
908
1033
|
var getDataset = function getDataset(datasourceId) {
|
|
909
|
-
|
|
1034
|
+
var datasourceType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
1035
|
+
return _cacheSource2TableMap[getDatasetCacheKey(datasourceId, datasourceType)] || [];
|
|
910
1036
|
};
|
|
911
1037
|
var reset = function reset() {
|
|
912
1038
|
_setMeta(defaultMeta);
|
package/lib/cjs/index.js
CHANGED
|
@@ -82,10 +82,16 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
|
|
|
82
82
|
var store = (0, _useState["default"])();
|
|
83
83
|
(0, _react.useEffect)(function () {
|
|
84
84
|
getTables && store.setFetchDatasetFn(getTables);
|
|
85
|
+
}, [getTables]);
|
|
86
|
+
(0, _react.useEffect)(function () {
|
|
85
87
|
getColumns && store.setFetchColumnsFn(getColumns);
|
|
88
|
+
}, [getColumns]);
|
|
89
|
+
(0, _react.useEffect)(function () {
|
|
86
90
|
onChange && store.setFetchChangeFn(onChange);
|
|
91
|
+
}, [onChange]);
|
|
92
|
+
(0, _react.useEffect)(function () {
|
|
87
93
|
getModuleDiffCode && store.setFetchDiffFn(getModuleDiffCode);
|
|
88
|
-
}, []);
|
|
94
|
+
}, [getModuleDiffCode]);
|
|
89
95
|
(0, _react.useEffect)(function () {
|
|
90
96
|
store.setProps(props);
|
|
91
97
|
}, [props]);
|
package/lib/cjs/store/types.d.ts
CHANGED
|
@@ -85,20 +85,22 @@ export interface AtomsExpression {
|
|
|
85
85
|
formula?: Filter_Formula;
|
|
86
86
|
type: AtomsTypeEnum.EXPRESSION;
|
|
87
87
|
}
|
|
88
|
-
export interface
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
export interface AtomsCaseWhenClause {
|
|
89
|
+
whenAtoms: AtomsItem[];
|
|
90
|
+
thenAtoms: AtomsItem[];
|
|
91
91
|
}
|
|
92
92
|
export interface AtomsCaseWhen {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
caseAtoms?: AtomsItem[];
|
|
94
|
+
whenClauses: AtomsCaseWhenClause[];
|
|
95
|
+
elseAtoms?: AtomsItem[];
|
|
96
96
|
quotes: string;
|
|
97
97
|
type: AtomsTypeEnum.CASE_WHEN;
|
|
98
98
|
}
|
|
99
99
|
export interface AtomsAndOr {
|
|
100
100
|
operator: 'and' | 'or';
|
|
101
|
-
|
|
101
|
+
leftAtoms?: AtomsItem[];
|
|
102
|
+
rightAtoms?: AtomsItem[];
|
|
103
|
+
atoms?: AtomsItem[];
|
|
102
104
|
quotes: string;
|
|
103
105
|
type: AtomsTypeEnum.AND_OR;
|
|
104
106
|
}
|
|
@@ -121,6 +123,7 @@ export interface AtomsField {
|
|
|
121
123
|
tableUuid: string;
|
|
122
124
|
datasourceName: string;
|
|
123
125
|
datasourceId: string;
|
|
126
|
+
datasourceType?: string;
|
|
124
127
|
type: AtomsTypeEnum.FIELD;
|
|
125
128
|
}
|
|
126
129
|
export interface AtomsInputString {
|
|
@@ -199,6 +202,7 @@ export interface MetaData_ColumnsType {
|
|
|
199
202
|
special_type: SpecialType | '';
|
|
200
203
|
datasourceId: string;
|
|
201
204
|
datasourceName: string;
|
|
205
|
+
datasourceType?: string;
|
|
202
206
|
select: boolean;
|
|
203
207
|
summarizeType?: MetaSummarize_Enum;
|
|
204
208
|
}
|
|
@@ -227,6 +231,7 @@ export interface MetaJoin_TalbeType {
|
|
|
227
231
|
alias: string;
|
|
228
232
|
datasourceName: string;
|
|
229
233
|
datasourceId: string;
|
|
234
|
+
datasourceType?: string;
|
|
230
235
|
quotes?: string;
|
|
231
236
|
columns?: MetaData_ColumnsType[];
|
|
232
237
|
}
|
|
@@ -286,6 +291,7 @@ export interface MetaSummarize_Group {
|
|
|
286
291
|
quotes: string;
|
|
287
292
|
datasourceId: string;
|
|
288
293
|
datasourceName: string;
|
|
294
|
+
datasourceType?: string;
|
|
289
295
|
atoms?: AtomsItem[];
|
|
290
296
|
summarizeType: MetaSummarize_Enum;
|
|
291
297
|
[params: string]: any;
|
|
@@ -303,6 +309,7 @@ export interface MetaSummarize_By {
|
|
|
303
309
|
id: string;
|
|
304
310
|
datasourceId: string;
|
|
305
311
|
datasourceName: string;
|
|
312
|
+
datasourceType?: string;
|
|
306
313
|
realName?: string;
|
|
307
314
|
sql: string;
|
|
308
315
|
database_type: SQL_COLUMN_TYPE | '';
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface MetaListProps {
|
|
|
10
10
|
}
|
|
11
11
|
export interface FetchOptions {
|
|
12
12
|
isExit: boolean;
|
|
13
|
+
datasourceType?: string;
|
|
13
14
|
}
|
|
14
15
|
export interface MetabaseProps {
|
|
15
16
|
loading?: boolean;
|
|
@@ -70,9 +71,16 @@ export interface OptionItem {
|
|
|
70
71
|
label: string;
|
|
71
72
|
icon?: React.ReactNode;
|
|
72
73
|
}
|
|
74
|
+
export interface DatasourceTypeOption {
|
|
75
|
+
value: string;
|
|
76
|
+
label: string;
|
|
77
|
+
}
|
|
73
78
|
export interface DatasourceType {
|
|
74
79
|
datasourceId: string;
|
|
75
80
|
datasourceName: string;
|
|
81
|
+
defaultDatasourceType?: string;
|
|
82
|
+
datasourceType?: string;
|
|
83
|
+
datasourceTypeList?: DatasourceTypeOption[];
|
|
76
84
|
}
|
|
77
85
|
export interface SqlVisionBuilderRef {
|
|
78
86
|
reset: () => void;
|
|
@@ -39,7 +39,8 @@ var BlockTypeEnum = {
|
|
|
39
39
|
notExists: 'notExists',
|
|
40
40
|
exists: 'exists',
|
|
41
41
|
FORMULA: 'FORMULA',
|
|
42
|
-
collection: 'collection'
|
|
42
|
+
collection: 'collection',
|
|
43
|
+
andOr: 'andOr'
|
|
43
44
|
};
|
|
44
45
|
var SummarizeAlias = 'source';
|
|
45
46
|
var SQL_GROUP_TYPE = {
|
|
@@ -72,7 +73,7 @@ var _recursionArr2 = function _recursionArr(arr) {
|
|
|
72
73
|
}
|
|
73
74
|
return obj;
|
|
74
75
|
};
|
|
75
|
-
var
|
|
76
|
+
var _handleBaseType2Sql1 = exports.handleBaseType2Sql = function handleBaseType2Sql(list) {
|
|
76
77
|
var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
|
|
77
78
|
var sql = '';
|
|
78
79
|
var constants = [];
|
|
@@ -134,11 +135,11 @@ var _handleBaseType2Sql8 = exports.handleBaseType2Sql = function handleBaseType2
|
|
|
134
135
|
if (type === BlockTypeEnum.joinDefault) {
|
|
135
136
|
var lhs = item.lhs,
|
|
136
137
|
rhs = item.rhs;
|
|
137
|
-
var _handleBaseType2Sql =
|
|
138
|
+
var _handleBaseType2Sql = _handleBaseType2Sql1(lhs, db),
|
|
138
139
|
leftSql = _handleBaseType2Sql.sql,
|
|
139
140
|
leftSqlItems = _handleBaseType2Sql.sql_items,
|
|
140
141
|
joinDefaultLeftConstants = _handleBaseType2Sql.constants;
|
|
141
|
-
var _handleBaseType2Sql2 =
|
|
142
|
+
var _handleBaseType2Sql2 = _handleBaseType2Sql1(rhs, db),
|
|
142
143
|
rightSql = _handleBaseType2Sql2.sql,
|
|
143
144
|
rightSqlItems = _handleBaseType2Sql2.sql_items,
|
|
144
145
|
joinDefaultRightConstants = _handleBaseType2Sql2.constants;
|
|
@@ -176,11 +177,11 @@ var _handleBaseType2Sql8 = exports.handleBaseType2Sql = function handleBaseType2
|
|
|
176
177
|
condition = item.condition,
|
|
177
178
|
database_type = item.database_type,
|
|
178
179
|
formula = item.formula;
|
|
179
|
-
var _handleBaseType2Sql3 =
|
|
180
|
+
var _handleBaseType2Sql3 = _handleBaseType2Sql1(_lhs, db),
|
|
180
181
|
_leftSql = _handleBaseType2Sql3.sql,
|
|
181
182
|
_leftSqlItems = _handleBaseType2Sql3.sql_items,
|
|
182
183
|
_joinDefaultLeftConstants = _handleBaseType2Sql3.constants;
|
|
183
|
-
var _handleBaseType2Sql4 =
|
|
184
|
+
var _handleBaseType2Sql4 = _handleBaseType2Sql1(_rhs, db),
|
|
184
185
|
_rightSql = _handleBaseType2Sql4.sql,
|
|
185
186
|
_rightSqlItems = _handleBaseType2Sql4.sql_items,
|
|
186
187
|
_joinDefaultRightConstants = _handleBaseType2Sql4.constants;
|
|
@@ -452,13 +453,13 @@ var _handleBaseType2Sql8 = exports.handleBaseType2Sql = function handleBaseType2
|
|
|
452
453
|
if (type === BlockTypeEnum.FORMULA) {
|
|
453
454
|
var argSqlList = (Array.isArray(item.args) ? item.args : []).map(function (arg) {
|
|
454
455
|
if ((arg === null || arg === void 0 ? void 0 : arg.type) === BlockTypeEnum.collection) {
|
|
455
|
-
var _handleBaseType2Sql5 =
|
|
456
|
+
var _handleBaseType2Sql5 = _handleBaseType2Sql1(arg.list, db),
|
|
456
457
|
collectionSql = _handleBaseType2Sql5.sql,
|
|
457
458
|
collectionConstants = _handleBaseType2Sql5.constants;
|
|
458
459
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(collectionConstants));
|
|
459
460
|
return collectionSql.trim();
|
|
460
461
|
}
|
|
461
|
-
var _handleBaseType2Sql6 =
|
|
462
|
+
var _handleBaseType2Sql6 = _handleBaseType2Sql1([arg], db),
|
|
462
463
|
nestedSql = _handleBaseType2Sql6.sql,
|
|
463
464
|
nestedConstants = _handleBaseType2Sql6.constants;
|
|
464
465
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(nestedConstants));
|
|
@@ -467,12 +468,32 @@ var _handleBaseType2Sql8 = exports.handleBaseType2Sql = function handleBaseType2
|
|
|
467
468
|
sql += " ".concat(item.name, "(").concat(argSqlList.join(', '), ")");
|
|
468
469
|
}
|
|
469
470
|
if (type === BlockTypeEnum.collection) {
|
|
470
|
-
var _handleBaseType2Sql7 =
|
|
471
|
+
var _handleBaseType2Sql7 = _handleBaseType2Sql1(item.list, db),
|
|
471
472
|
collectionSql = _handleBaseType2Sql7.sql,
|
|
472
473
|
collectionConstants = _handleBaseType2Sql7.constants;
|
|
473
474
|
sql += " ".concat(collectionSql);
|
|
474
475
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(collectionConstants));
|
|
475
476
|
}
|
|
477
|
+
if (type === BlockTypeEnum.andOr) {
|
|
478
|
+
var hasBinarySides = Array.isArray(item.leftAtoms) || Array.isArray(item.rightAtoms);
|
|
479
|
+
if (hasBinarySides) {
|
|
480
|
+
var _handleBaseType2Sql8 = _handleBaseType2Sql1(item.leftAtoms || [], db),
|
|
481
|
+
_leftSql2 = _handleBaseType2Sql8.sql,
|
|
482
|
+
leftConstants = _handleBaseType2Sql8.constants;
|
|
483
|
+
var _handleBaseType2Sql9 = _handleBaseType2Sql1(item.rightAtoms || [], db),
|
|
484
|
+
_rightSql2 = _handleBaseType2Sql9.sql,
|
|
485
|
+
rightConstants = _handleBaseType2Sql9.constants;
|
|
486
|
+
constants.push.apply(constants, (0, _toConsumableArray2["default"])(leftConstants).concat((0, _toConsumableArray2["default"])(rightConstants)));
|
|
487
|
+
var operator = (item.operator || 'and').toUpperCase();
|
|
488
|
+
sql += " (".concat(_leftSql2.trim(), " ").concat(operator, " ").concat(_rightSql2.trim(), ")");
|
|
489
|
+
} else {
|
|
490
|
+
var _handleBaseType2Sql0 = _handleBaseType2Sql1(item.atoms || [], db),
|
|
491
|
+
atomsSql = _handleBaseType2Sql0.sql,
|
|
492
|
+
nestedConstants = _handleBaseType2Sql0.constants;
|
|
493
|
+
constants.push.apply(constants, (0, _toConsumableArray2["default"])(nestedConstants));
|
|
494
|
+
sql += " ".concat((item.operator || 'and').toUpperCase(), " (").concat(atomsSql.trim(), ")");
|
|
495
|
+
}
|
|
496
|
+
}
|
|
476
497
|
});
|
|
477
498
|
return {
|
|
478
499
|
sql: sql,
|
|
@@ -493,9 +514,9 @@ var _handleJoinData = function _handleJoinData(joinData) {
|
|
|
493
514
|
if (isSubquery) {
|
|
494
515
|
subQuery = subquery;
|
|
495
516
|
}
|
|
496
|
-
var
|
|
497
|
-
sql =
|
|
498
|
-
joinConstants =
|
|
517
|
+
var _handleBaseType2Sql10 = _handleBaseType2Sql1(expressions, db),
|
|
518
|
+
sql = _handleBaseType2Sql10.sql,
|
|
519
|
+
joinConstants = _handleBaseType2Sql10.constants;
|
|
499
520
|
var joinCondition = "on ".concat(sql);
|
|
500
521
|
constants = joinConstants;
|
|
501
522
|
return {
|
|
@@ -504,6 +525,7 @@ var _handleJoinData = function _handleJoinData(joinData) {
|
|
|
504
525
|
tableName_zh: v.table2.name_zh,
|
|
505
526
|
datasourceId: v.table2.datasourceId || '',
|
|
506
527
|
datasourceName: v.table2.datasourceName || '',
|
|
528
|
+
datasourceType: v.table2.datasourceType || '',
|
|
507
529
|
joinCondition: joinCondition,
|
|
508
530
|
joinType: v.joinType,
|
|
509
531
|
subQuery: subQuery,
|
|
@@ -547,6 +569,7 @@ var _handleNesting = function handleNesting(data) {
|
|
|
547
569
|
obj.tableId = tableData.table.id;
|
|
548
570
|
obj.datasourceId = tableData.table.datasourceId;
|
|
549
571
|
obj.datasourceName = tableData.table.datasourceName;
|
|
572
|
+
obj.datasourceType = tableData.table.datasourceType;
|
|
550
573
|
if (tableData.isSubquery && Array.isArray(tableData.subquery)) {
|
|
551
574
|
obj.tableSubQuery = tableData.subquery;
|
|
552
575
|
}
|
|
@@ -578,9 +601,9 @@ var _handleNesting = function handleNesting(data) {
|
|
|
578
601
|
var customColumnsConstants = [];
|
|
579
602
|
var handleCustomColumn = function handleCustomColumn(data) {
|
|
580
603
|
return data.map(function (it) {
|
|
581
|
-
var
|
|
582
|
-
field_sql =
|
|
583
|
-
constants =
|
|
604
|
+
var _handleBaseType2Sql11 = _handleBaseType2Sql1(it.formulaList, db),
|
|
605
|
+
field_sql = _handleBaseType2Sql11.sql,
|
|
606
|
+
constants = _handleBaseType2Sql11.constants;
|
|
584
607
|
customColumnsConstants.push.apply(customColumnsConstants, (0, _toConsumableArray2["default"])(constants));
|
|
585
608
|
return {
|
|
586
609
|
field_sql: "".concat(field_sql, " as ").concat(it.name),
|
|
@@ -595,9 +618,9 @@ var _handleNesting = function handleNesting(data) {
|
|
|
595
618
|
obj.customColumnsConstants = customColumnsConstants;
|
|
596
619
|
}
|
|
597
620
|
if (filterData && filterData.filter.length) {
|
|
598
|
-
var
|
|
599
|
-
sql =
|
|
600
|
-
constants =
|
|
621
|
+
var _handleBaseType2Sql12 = _handleBaseType2Sql1(filterData.filter, db),
|
|
622
|
+
sql = _handleBaseType2Sql12.sql,
|
|
623
|
+
constants = _handleBaseType2Sql12.constants;
|
|
601
624
|
obj.filters = 'WHERE ' + sql;
|
|
602
625
|
obj.filtersConstants = constants;
|
|
603
626
|
}
|
|
@@ -622,7 +645,7 @@ var _handleNesting = function handleNesting(data) {
|
|
|
622
645
|
if (summarize.by.length) {
|
|
623
646
|
obj.groupBy.groupColumns = summarize.by.map(function (v) {
|
|
624
647
|
var _v$atoms;
|
|
625
|
-
var fieldSql = (_v$atoms = v.atoms) !== null && _v$atoms !== void 0 && _v$atoms.length ?
|
|
648
|
+
var fieldSql = (_v$atoms = v.atoms) !== null && _v$atoms !== void 0 && _v$atoms.length ? _handleBaseType2Sql1(v.atoms, db).sql.trim() || v.sql : v.sql || "".concat(v.alias, ".").concat(v.realName || v.name);
|
|
626
649
|
queryColumns.push({
|
|
627
650
|
field_sql: "".concat(fieldSql, " as ").concat(v.fieldAlias),
|
|
628
651
|
read_name: '',
|
|
@@ -640,8 +663,8 @@ var _handleNesting = function handleNesting(data) {
|
|
|
640
663
|
}
|
|
641
664
|
if (sortData && sortData.sort.length) {
|
|
642
665
|
obj.orderInfos = "ORDER BY ".concat(sortData.sort.map(function (v) {
|
|
643
|
-
var
|
|
644
|
-
sql =
|
|
666
|
+
var _handleBaseType2Sql13 = _handleBaseType2Sql1(v.expression, db),
|
|
667
|
+
sql = _handleBaseType2Sql13.sql;
|
|
645
668
|
return "".concat(sql, " ").concat(v.sort);
|
|
646
669
|
}).join(', '));
|
|
647
670
|
}
|
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypeEnum } from './store/enum';
|
|
2
|
-
import { MetaListType, MetaSummarize, MetaData_TableType, MetaData_ColumnsType, AtomsItem } from './store/types';
|
|
2
|
+
import { MetaListType, MetaSummarize, MetaSummarize_Group, MetaSummarize_By, MetaData_TableType, MetaData_ColumnsType, AtomsItem } from './store/types';
|
|
3
3
|
import { DataType } from './components/dialog/select-column-multiple';
|
|
4
4
|
export declare const findIndex: <T>(arr: T[], item: T) => number;
|
|
5
5
|
export declare const findMetaKey: <T>(arr: T[], item: T) => number;
|
|
@@ -24,7 +24,7 @@ export declare const getHelper: (list: MetaListType[], item: MetaListType) => He
|
|
|
24
24
|
export declare const getSubColumns: (metaList: any) => DataType[];
|
|
25
25
|
export declare function isValidSQLAlias(str: string): boolean;
|
|
26
26
|
export declare const changeTableAlias: (list: MetaListType[] | [], curObj: Pick<MetaData_TableType, "tableUuid" | "alias">) => MetaListType[];
|
|
27
|
-
export declare const changeFieldAlias: (list: MetaListType[], curObj: Pick<MetaData_ColumnsType, "fieldUuid" | "fieldAlias">) => MetaListType[];
|
|
27
|
+
export declare const changeFieldAlias: (list: MetaListType[], curObj: Pick<MetaData_ColumnsType, "fieldUuid" | "fieldAlias"> & Partial<Pick<MetaData_ColumnsType, "id" | "name" | "datasourceId">> & Partial<Pick<MetaSummarize_Group | MetaSummarize_By, "table" | "tableId" | "tableUuid" | "fieldId" | "name">>) => MetaListType[];
|
|
28
28
|
export declare function splitByUnion(data: any): any[];
|
|
29
29
|
export declare const normalizeLegacySummarizeForSave: (metas?: MetaListType[]) => MetaListType[];
|
|
30
30
|
export declare const getObjTem: (arr: any[]) => any;
|