@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.
- 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 +67 -16
- 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 +26 -5
- 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 +349 -58
- 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 +67 -16
- 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 +26 -5
- 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 +350 -59
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
|
|
|
5
5
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
6
6
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
7
7
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
8
|
-
var _excluded = ["alias", "datasourceName", "datasourceId", "column"];
|
|
8
|
+
var _excluded = ["alias", "datasourceName", "datasourceId", "datasourceType", "column"];
|
|
9
9
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
10
10
|
import { useEffect, useState, useRef, useMemo } from 'react';
|
|
11
11
|
import { uuidv4, getAlias } from '../utils/helper';
|
|
@@ -28,6 +28,7 @@ var useStore = function useStore() {
|
|
|
28
28
|
alias: '',
|
|
29
29
|
datasourceId: '',
|
|
30
30
|
datasourceName: '',
|
|
31
|
+
datasourceType: '',
|
|
31
32
|
tableUuid: uuidv4('table')
|
|
32
33
|
},
|
|
33
34
|
columns: []
|
|
@@ -312,10 +313,97 @@ var useStore = function useStore() {
|
|
|
312
313
|
});
|
|
313
314
|
}, [metaList]);
|
|
314
315
|
useEffect(function () {
|
|
316
|
+
if (sourceList.length) {
|
|
317
|
+
var metaListWithDefaultType = fillDefaultDatasourceTypeInMetaList(metaList, isExit);
|
|
318
|
+
if (metaListWithDefaultType !== metaList) {
|
|
319
|
+
setPreData(metaListWithDefaultType, isSubquery, isExit);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
315
322
|
if (tableFlat) {
|
|
316
323
|
getSourceTable(sourceList);
|
|
317
324
|
}
|
|
318
325
|
}, [sourceList, isExit, tableFlat]);
|
|
326
|
+
var getDefaultDatasourceType = function getDefaultDatasourceType(datasource) {
|
|
327
|
+
var _datasource$datasourc;
|
|
328
|
+
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) || '';
|
|
329
|
+
};
|
|
330
|
+
var getActiveSourceList = function getActiveSourceList() {
|
|
331
|
+
var _props$exitSourceList, _props$sourceList;
|
|
332
|
+
var _isExit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : isExit;
|
|
333
|
+
var props = preProps.current || {};
|
|
334
|
+
if (_isExit && (_props$exitSourceList = props.exitSourceList) !== null && _props$exitSourceList !== void 0 && _props$exitSourceList.length) {
|
|
335
|
+
return props.exitSourceList;
|
|
336
|
+
}
|
|
337
|
+
if ((_props$sourceList = props.sourceList) !== null && _props$sourceList !== void 0 && _props$sourceList.length) {
|
|
338
|
+
return props.sourceList;
|
|
339
|
+
}
|
|
340
|
+
return sourceList;
|
|
341
|
+
};
|
|
342
|
+
var getDefaultDatasourceTypeById = function getDefaultDatasourceTypeById(datasourceId) {
|
|
343
|
+
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
344
|
+
if (!datasourceId) return '';
|
|
345
|
+
var datasource = getActiveSourceList(_isExit).find(function (item) {
|
|
346
|
+
return item.datasourceId === datasourceId;
|
|
347
|
+
});
|
|
348
|
+
return getDefaultDatasourceType(datasource);
|
|
349
|
+
};
|
|
350
|
+
var fillDefaultDatasourceTypeInTable = function fillDefaultDatasourceTypeInTable(table) {
|
|
351
|
+
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
352
|
+
if (!(table !== null && table !== void 0 && table.datasourceId) || table.datasourceType) return false;
|
|
353
|
+
var defaultDatasourceType = getDefaultDatasourceTypeById(table.datasourceId, _isExit);
|
|
354
|
+
if (!defaultDatasourceType) return false;
|
|
355
|
+
table.datasourceType = defaultDatasourceType;
|
|
356
|
+
return true;
|
|
357
|
+
};
|
|
358
|
+
var fillDefaultDatasourceTypeInColumns = function fillDefaultDatasourceTypeInColumns(columns, datasourceType) {
|
|
359
|
+
if (!datasourceType || !Array.isArray(columns)) return false;
|
|
360
|
+
var changed = false;
|
|
361
|
+
columns.forEach(function (column) {
|
|
362
|
+
if (!column.datasourceType) {
|
|
363
|
+
column.datasourceType = datasourceType;
|
|
364
|
+
changed = true;
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
return changed;
|
|
368
|
+
};
|
|
369
|
+
var _fillDefaultDatasourceTypeInList = function fillDefaultDatasourceTypeInList(list) {
|
|
370
|
+
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
371
|
+
if (!Array.isArray(list)) return false;
|
|
372
|
+
var changed = false;
|
|
373
|
+
list.forEach(function (item) {
|
|
374
|
+
if (item.table) {
|
|
375
|
+
changed = fillDefaultDatasourceTypeInTable(item.table, _isExit) || changed;
|
|
376
|
+
changed = fillDefaultDatasourceTypeInColumns(item.columns, item.table.datasourceType) || changed;
|
|
377
|
+
}
|
|
378
|
+
if (item.table1) {
|
|
379
|
+
changed = fillDefaultDatasourceTypeInTable(item.table1, _isExit) || changed;
|
|
380
|
+
}
|
|
381
|
+
if (item.table2) {
|
|
382
|
+
changed = fillDefaultDatasourceTypeInTable(item.table2, _isExit) || changed;
|
|
383
|
+
changed = fillDefaultDatasourceTypeInColumns(item.columns, item.table2.datasourceType) || changed;
|
|
384
|
+
}
|
|
385
|
+
if (Array.isArray(item.subquery)) {
|
|
386
|
+
changed = _fillDefaultDatasourceTypeInList(item.subquery, _isExit) || changed;
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
return changed;
|
|
390
|
+
};
|
|
391
|
+
var fillDefaultDatasourceTypeInMetaList = function fillDefaultDatasourceTypeInMetaList() {
|
|
392
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
393
|
+
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
394
|
+
if (!data.length) return data;
|
|
395
|
+
var nextData = cloneDeep(data);
|
|
396
|
+
var changed = false;
|
|
397
|
+
nextData.forEach(function (group) {
|
|
398
|
+
changed = _fillDefaultDatasourceTypeInList(group.list, _isExit) || changed;
|
|
399
|
+
changed = _fillDefaultDatasourceTypeInList(group.subquery, _isExit) || changed;
|
|
400
|
+
});
|
|
401
|
+
return changed ? nextData : data;
|
|
402
|
+
};
|
|
403
|
+
var getDatasetCacheKey = function getDatasetCacheKey(datasourceId) {
|
|
404
|
+
var datasourceType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
405
|
+
return datasourceType ? "".concat(datasourceId, "__").concat(datasourceType) : datasourceId;
|
|
406
|
+
};
|
|
319
407
|
var getSourceTable = function () {
|
|
320
408
|
var _ref3 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(source) {
|
|
321
409
|
var results;
|
|
@@ -325,15 +413,17 @@ var useStore = function useStore() {
|
|
|
325
413
|
_context4.next = 1;
|
|
326
414
|
return Promise.all(source.map(function () {
|
|
327
415
|
var _ref4 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(v) {
|
|
328
|
-
var tables;
|
|
416
|
+
var datasourceType, tables;
|
|
329
417
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
330
418
|
while (1) switch (_context3.prev = _context3.next) {
|
|
331
419
|
case 0:
|
|
420
|
+
datasourceType = getDefaultDatasourceType(v);
|
|
332
421
|
_context3.next = 1;
|
|
333
|
-
return fetchDataset(v.datasourceId);
|
|
422
|
+
return fetchDataset(v.datasourceId, datasourceType);
|
|
334
423
|
case 1:
|
|
335
424
|
tables = _context3.sent;
|
|
336
425
|
return _context3.abrupt("return", _objectSpread(_objectSpread({}, v), {}, {
|
|
426
|
+
datasourceType: datasourceType,
|
|
337
427
|
children: tables
|
|
338
428
|
}));
|
|
339
429
|
case 2:
|
|
@@ -364,24 +454,34 @@ var useStore = function useStore() {
|
|
|
364
454
|
};
|
|
365
455
|
var fetchDataset = function () {
|
|
366
456
|
var _ref5 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(datasourceId) {
|
|
367
|
-
var
|
|
457
|
+
var _preProps$current;
|
|
458
|
+
var datasourceType,
|
|
459
|
+
force,
|
|
460
|
+
tables,
|
|
461
|
+
fetchTables,
|
|
462
|
+
_tables,
|
|
463
|
+
_args5 = arguments;
|
|
368
464
|
return _regeneratorRuntime.wrap(function (_context5) {
|
|
369
465
|
while (1) switch (_context5.prev = _context5.next) {
|
|
370
466
|
case 0:
|
|
371
|
-
|
|
372
|
-
|
|
467
|
+
datasourceType = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : '';
|
|
468
|
+
force = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : false;
|
|
469
|
+
tables = getDataset(datasourceId, datasourceType);
|
|
470
|
+
if (!(!force && tables.length)) {
|
|
373
471
|
_context5.next = 1;
|
|
374
472
|
break;
|
|
375
473
|
}
|
|
376
474
|
return _context5.abrupt("return", tables);
|
|
377
475
|
case 1:
|
|
476
|
+
fetchTables = ((_preProps$current = preProps.current) === null || _preProps$current === void 0 ? void 0 : _preProps$current.getTables) || fetchDatasetFn.current;
|
|
378
477
|
_context5.next = 2;
|
|
379
|
-
return
|
|
380
|
-
isExit: isExit
|
|
478
|
+
return fetchTables(datasourceId, {
|
|
479
|
+
isExit: isExit,
|
|
480
|
+
datasourceType: datasourceType
|
|
381
481
|
});
|
|
382
482
|
case 2:
|
|
383
483
|
_tables = _context5.sent;
|
|
384
|
-
setDataset(datasourceId, _tables);
|
|
484
|
+
setDataset(datasourceId, _tables, datasourceType);
|
|
385
485
|
return _context5.abrupt("return", _tables);
|
|
386
486
|
case 3:
|
|
387
487
|
case "end":
|
|
@@ -407,9 +507,11 @@ var useStore = function useStore() {
|
|
|
407
507
|
alias,
|
|
408
508
|
datasourceName,
|
|
409
509
|
did,
|
|
510
|
+
datasourceType,
|
|
410
511
|
column,
|
|
411
512
|
extra,
|
|
412
513
|
tableName,
|
|
514
|
+
tableCacheKey,
|
|
413
515
|
columns,
|
|
414
516
|
_columns,
|
|
415
517
|
_args6 = arguments;
|
|
@@ -434,26 +536,31 @@ var useStore = function useStore() {
|
|
|
434
536
|
selectId = [];
|
|
435
537
|
isSelect = false;
|
|
436
538
|
}
|
|
437
|
-
_table$alias = table.alias, alias = _table$alias === void 0 ? '' : _table$alias, datasourceName = table.datasourceName, did = table.datasourceId, column = table.column, extra = _objectWithoutProperties(table, _excluded);
|
|
539
|
+
_table$alias = table.alias, alias = _table$alias === void 0 ? '' : _table$alias, datasourceName = table.datasourceName, did = table.datasourceId, datasourceType = table.datasourceType, column = table.column, extra = _objectWithoutProperties(table, _excluded);
|
|
438
540
|
tableName = table.name;
|
|
439
|
-
|
|
541
|
+
tableCacheKey = getDatasetCacheKey("".concat(datasourceId, "_").concat(tableName), datasourceType || '');
|
|
542
|
+
columns = getColumns(tableCacheKey);
|
|
440
543
|
if (columns.length) {
|
|
441
544
|
_context6.next = 2;
|
|
442
545
|
break;
|
|
443
546
|
}
|
|
444
547
|
_context6.next = 1;
|
|
445
548
|
return fetchColumnsFn.current(extra, datasourceId, {
|
|
446
|
-
isExit: _isExit
|
|
549
|
+
isExit: _isExit,
|
|
550
|
+
datasourceType: datasourceType
|
|
447
551
|
});
|
|
448
552
|
case 1:
|
|
449
553
|
columns = _context6.sent;
|
|
450
|
-
setColumns(
|
|
554
|
+
setColumns(tableCacheKey, columns);
|
|
451
555
|
case 2:
|
|
452
556
|
_columns = (_columns2 = columns) === null || _columns2 === void 0 ? void 0 : _columns2.map(function (v) {
|
|
453
557
|
var select = selectId.includes(v.id);
|
|
454
558
|
var obj = {};
|
|
455
559
|
obj = oldObj[v.id] || {};
|
|
456
560
|
return _objectSpread(_objectSpread(_objectSpread({}, obj), v), {}, {
|
|
561
|
+
datasourceId: obj.datasourceId || v.datasourceId || did || datasourceId || '',
|
|
562
|
+
datasourceName: obj.datasourceName || v.datasourceName || datasourceName || '',
|
|
563
|
+
datasourceType: obj.datasourceType || v.datasourceType || datasourceType || '',
|
|
457
564
|
select: isSelect || select,
|
|
458
565
|
fieldUuid: obj.fieldUuid || v.fieldUuid || uuidv4('field')
|
|
459
566
|
});
|
|
@@ -521,7 +628,16 @@ var useStore = function useStore() {
|
|
|
521
628
|
var _v$table, _v$table2;
|
|
522
629
|
var newMeta = item.list;
|
|
523
630
|
if (v.table) {
|
|
631
|
+
fillDefaultDatasourceTypeInTable(v.table, _isExit);
|
|
524
632
|
v.table.tableUuid = v.table.tableUuid || uuidv4('table');
|
|
633
|
+
fillDefaultDatasourceTypeInColumns(v.columns, v.table.datasourceType);
|
|
634
|
+
}
|
|
635
|
+
if (v.table1) {
|
|
636
|
+
fillDefaultDatasourceTypeInTable(v.table1, _isExit);
|
|
637
|
+
}
|
|
638
|
+
if (v.table2) {
|
|
639
|
+
fillDefaultDatasourceTypeInTable(v.table2, _isExit);
|
|
640
|
+
fillDefaultDatasourceTypeInColumns(v.columns, v.table2.datasourceType);
|
|
525
641
|
}
|
|
526
642
|
if ((_v$table = v.table2) !== null && _v$table !== void 0 && _v$table.datasourceId) {
|
|
527
643
|
fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, v.columns, function () {
|
|
@@ -529,6 +645,8 @@ var useStore = function useStore() {
|
|
|
529
645
|
if (v.isSubquery) {} else {
|
|
530
646
|
newMeta[i].columns = columns || [];
|
|
531
647
|
}
|
|
648
|
+
fillDefaultDatasourceTypeInTable(newMeta[i].table2, _isExit);
|
|
649
|
+
fillDefaultDatasourceTypeInColumns(newMeta[i].columns, newMeta[i].table2.datasourceType);
|
|
532
650
|
setMeta(newMeta, groupIndex, 'init', data);
|
|
533
651
|
}, false, _isSubquery, _isExit);
|
|
534
652
|
return _objectSpread({}, v);
|
|
@@ -539,6 +657,8 @@ var useStore = function useStore() {
|
|
|
539
657
|
if (v.isSubquery) {} else {
|
|
540
658
|
newMeta[i].columns = columns || [];
|
|
541
659
|
}
|
|
660
|
+
fillDefaultDatasourceTypeInTable(newMeta[i].table, _isExit);
|
|
661
|
+
fillDefaultDatasourceTypeInColumns(newMeta[i].columns, newMeta[i].table.datasourceType);
|
|
542
662
|
setMeta(newMeta, groupIndex, 'init', data);
|
|
543
663
|
}, false, _isSubquery, _isExit);
|
|
544
664
|
return _objectSpread({}, v);
|
|
@@ -657,6 +777,7 @@ var useStore = function useStore() {
|
|
|
657
777
|
tableUuid: '',
|
|
658
778
|
datasourceId: '',
|
|
659
779
|
datasourceName: '',
|
|
780
|
+
datasourceType: '',
|
|
660
781
|
fieldAlias: '',
|
|
661
782
|
fieldUuid: '',
|
|
662
783
|
fields: []
|
|
@@ -668,6 +789,7 @@ var useStore = function useStore() {
|
|
|
668
789
|
name_zh: mainTable.table.name_zh,
|
|
669
790
|
datasourceId: mainTable.table.datasourceId,
|
|
670
791
|
datasourceName: mainTable.table.datasourceName,
|
|
792
|
+
datasourceType: mainTable.table.datasourceType || '',
|
|
671
793
|
fieldAlias: '',
|
|
672
794
|
fieldUuid: '',
|
|
673
795
|
fields: []
|
|
@@ -685,7 +807,8 @@ var useStore = function useStore() {
|
|
|
685
807
|
alias: '',
|
|
686
808
|
tableUuid: '',
|
|
687
809
|
datasourceId: '',
|
|
688
|
-
datasourceName: ''
|
|
810
|
+
datasourceName: '',
|
|
811
|
+
datasourceType: ''
|
|
689
812
|
},
|
|
690
813
|
columns: [],
|
|
691
814
|
expressions: []
|
|
@@ -740,7 +863,8 @@ var useStore = function useStore() {
|
|
|
740
863
|
alias: '',
|
|
741
864
|
tableUuid: '',
|
|
742
865
|
datasourceId: '',
|
|
743
|
-
datasourceName: ''
|
|
866
|
+
datasourceName: '',
|
|
867
|
+
datasourceType: ''
|
|
744
868
|
}
|
|
745
869
|
};
|
|
746
870
|
}
|
|
@@ -895,12 +1019,14 @@ var useStore = function useStore() {
|
|
|
895
1019
|
return _cacheColumnsMap[tableId] || [];
|
|
896
1020
|
};
|
|
897
1021
|
var setDataset = function setDataset(datasourceId, tables) {
|
|
1022
|
+
var datasourceType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
898
1023
|
var map = _objectSpread({}, _cacheSource2TableMap);
|
|
899
|
-
map[datasourceId] = tables;
|
|
1024
|
+
map[getDatasetCacheKey(datasourceId, datasourceType)] = tables;
|
|
900
1025
|
set_cacheSource2TableMap(map);
|
|
901
1026
|
};
|
|
902
1027
|
var getDataset = function getDataset(datasourceId) {
|
|
903
|
-
|
|
1028
|
+
var datasourceType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
1029
|
+
return _cacheSource2TableMap[getDatasetCacheKey(datasourceId, datasourceType)] || [];
|
|
904
1030
|
};
|
|
905
1031
|
var reset = function reset() {
|
|
906
1032
|
_setMeta(defaultMeta);
|
package/lib/es/index.js
CHANGED
|
@@ -73,10 +73,16 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
|
|
|
73
73
|
var store = useData();
|
|
74
74
|
useEffect(function () {
|
|
75
75
|
getTables && store.setFetchDatasetFn(getTables);
|
|
76
|
+
}, [getTables]);
|
|
77
|
+
useEffect(function () {
|
|
76
78
|
getColumns && store.setFetchColumnsFn(getColumns);
|
|
79
|
+
}, [getColumns]);
|
|
80
|
+
useEffect(function () {
|
|
77
81
|
onChange && store.setFetchChangeFn(onChange);
|
|
82
|
+
}, [onChange]);
|
|
83
|
+
useEffect(function () {
|
|
78
84
|
getModuleDiffCode && store.setFetchDiffFn(getModuleDiffCode);
|
|
79
|
-
}, []);
|
|
85
|
+
}, [getModuleDiffCode]);
|
|
80
86
|
useEffect(function () {
|
|
81
87
|
store.setProps(props);
|
|
82
88
|
}, [props]);
|
package/lib/es/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/es/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;
|
|
@@ -32,7 +32,8 @@ var BlockTypeEnum = {
|
|
|
32
32
|
notExists: 'notExists',
|
|
33
33
|
exists: 'exists',
|
|
34
34
|
FORMULA: 'FORMULA',
|
|
35
|
-
collection: 'collection'
|
|
35
|
+
collection: 'collection',
|
|
36
|
+
andOr: 'andOr'
|
|
36
37
|
};
|
|
37
38
|
var SummarizeAlias = 'source';
|
|
38
39
|
var SQL_GROUP_TYPE = {
|
|
@@ -65,7 +66,7 @@ var _recursionArr2 = function _recursionArr(arr) {
|
|
|
65
66
|
}
|
|
66
67
|
return obj;
|
|
67
68
|
};
|
|
68
|
-
var
|
|
69
|
+
var _handleBaseType2Sql1 = function handleBaseType2Sql(list) {
|
|
69
70
|
var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
|
|
70
71
|
var sql = '';
|
|
71
72
|
var constants = [];
|
|
@@ -127,11 +128,11 @@ var _handleBaseType2Sql8 = function handleBaseType2Sql(list) {
|
|
|
127
128
|
if (type === BlockTypeEnum.joinDefault) {
|
|
128
129
|
var lhs = item.lhs,
|
|
129
130
|
rhs = item.rhs;
|
|
130
|
-
var _handleBaseType2Sql =
|
|
131
|
+
var _handleBaseType2Sql = _handleBaseType2Sql1(lhs, db),
|
|
131
132
|
leftSql = _handleBaseType2Sql.sql,
|
|
132
133
|
leftSqlItems = _handleBaseType2Sql.sql_items,
|
|
133
134
|
joinDefaultLeftConstants = _handleBaseType2Sql.constants;
|
|
134
|
-
var _handleBaseType2Sql2 =
|
|
135
|
+
var _handleBaseType2Sql2 = _handleBaseType2Sql1(rhs, db),
|
|
135
136
|
rightSql = _handleBaseType2Sql2.sql,
|
|
136
137
|
rightSqlItems = _handleBaseType2Sql2.sql_items,
|
|
137
138
|
joinDefaultRightConstants = _handleBaseType2Sql2.constants;
|
|
@@ -169,11 +170,11 @@ var _handleBaseType2Sql8 = function handleBaseType2Sql(list) {
|
|
|
169
170
|
condition = item.condition,
|
|
170
171
|
database_type = item.database_type,
|
|
171
172
|
formula = item.formula;
|
|
172
|
-
var _handleBaseType2Sql3 =
|
|
173
|
+
var _handleBaseType2Sql3 = _handleBaseType2Sql1(_lhs, db),
|
|
173
174
|
_leftSql = _handleBaseType2Sql3.sql,
|
|
174
175
|
_leftSqlItems = _handleBaseType2Sql3.sql_items,
|
|
175
176
|
_joinDefaultLeftConstants = _handleBaseType2Sql3.constants;
|
|
176
|
-
var _handleBaseType2Sql4 =
|
|
177
|
+
var _handleBaseType2Sql4 = _handleBaseType2Sql1(_rhs, db),
|
|
177
178
|
_rightSql = _handleBaseType2Sql4.sql,
|
|
178
179
|
_rightSqlItems = _handleBaseType2Sql4.sql_items,
|
|
179
180
|
_joinDefaultRightConstants = _handleBaseType2Sql4.constants;
|
|
@@ -445,13 +446,13 @@ var _handleBaseType2Sql8 = function handleBaseType2Sql(list) {
|
|
|
445
446
|
if (type === BlockTypeEnum.FORMULA) {
|
|
446
447
|
var argSqlList = (Array.isArray(item.args) ? item.args : []).map(function (arg) {
|
|
447
448
|
if ((arg === null || arg === void 0 ? void 0 : arg.type) === BlockTypeEnum.collection) {
|
|
448
|
-
var _handleBaseType2Sql5 =
|
|
449
|
+
var _handleBaseType2Sql5 = _handleBaseType2Sql1(arg.list, db),
|
|
449
450
|
collectionSql = _handleBaseType2Sql5.sql,
|
|
450
451
|
collectionConstants = _handleBaseType2Sql5.constants;
|
|
451
452
|
constants.push.apply(constants, _toConsumableArray(collectionConstants));
|
|
452
453
|
return collectionSql.trim();
|
|
453
454
|
}
|
|
454
|
-
var _handleBaseType2Sql6 =
|
|
455
|
+
var _handleBaseType2Sql6 = _handleBaseType2Sql1([arg], db),
|
|
455
456
|
nestedSql = _handleBaseType2Sql6.sql,
|
|
456
457
|
nestedConstants = _handleBaseType2Sql6.constants;
|
|
457
458
|
constants.push.apply(constants, _toConsumableArray(nestedConstants));
|
|
@@ -460,12 +461,32 @@ var _handleBaseType2Sql8 = function handleBaseType2Sql(list) {
|
|
|
460
461
|
sql += " ".concat(item.name, "(").concat(argSqlList.join(', '), ")");
|
|
461
462
|
}
|
|
462
463
|
if (type === BlockTypeEnum.collection) {
|
|
463
|
-
var _handleBaseType2Sql7 =
|
|
464
|
+
var _handleBaseType2Sql7 = _handleBaseType2Sql1(item.list, db),
|
|
464
465
|
collectionSql = _handleBaseType2Sql7.sql,
|
|
465
466
|
collectionConstants = _handleBaseType2Sql7.constants;
|
|
466
467
|
sql += " ".concat(collectionSql);
|
|
467
468
|
constants.push.apply(constants, _toConsumableArray(collectionConstants));
|
|
468
469
|
}
|
|
470
|
+
if (type === BlockTypeEnum.andOr) {
|
|
471
|
+
var hasBinarySides = Array.isArray(item.leftAtoms) || Array.isArray(item.rightAtoms);
|
|
472
|
+
if (hasBinarySides) {
|
|
473
|
+
var _handleBaseType2Sql8 = _handleBaseType2Sql1(item.leftAtoms || [], db),
|
|
474
|
+
_leftSql2 = _handleBaseType2Sql8.sql,
|
|
475
|
+
leftConstants = _handleBaseType2Sql8.constants;
|
|
476
|
+
var _handleBaseType2Sql9 = _handleBaseType2Sql1(item.rightAtoms || [], db),
|
|
477
|
+
_rightSql2 = _handleBaseType2Sql9.sql,
|
|
478
|
+
rightConstants = _handleBaseType2Sql9.constants;
|
|
479
|
+
constants.push.apply(constants, _toConsumableArray(leftConstants).concat(_toConsumableArray(rightConstants)));
|
|
480
|
+
var operator = (item.operator || 'and').toUpperCase();
|
|
481
|
+
sql += " (".concat(_leftSql2.trim(), " ").concat(operator, " ").concat(_rightSql2.trim(), ")");
|
|
482
|
+
} else {
|
|
483
|
+
var _handleBaseType2Sql0 = _handleBaseType2Sql1(item.atoms || [], db),
|
|
484
|
+
atomsSql = _handleBaseType2Sql0.sql,
|
|
485
|
+
nestedConstants = _handleBaseType2Sql0.constants;
|
|
486
|
+
constants.push.apply(constants, _toConsumableArray(nestedConstants));
|
|
487
|
+
sql += " ".concat((item.operator || 'and').toUpperCase(), " (").concat(atomsSql.trim(), ")");
|
|
488
|
+
}
|
|
489
|
+
}
|
|
469
490
|
});
|
|
470
491
|
return {
|
|
471
492
|
sql: sql,
|
|
@@ -473,7 +494,7 @@ var _handleBaseType2Sql8 = function handleBaseType2Sql(list) {
|
|
|
473
494
|
constants: constants
|
|
474
495
|
};
|
|
475
496
|
};
|
|
476
|
-
export {
|
|
497
|
+
export { _handleBaseType2Sql1 as handleBaseType2Sql };
|
|
477
498
|
var _handleJoinData = function _handleJoinData(joinData) {
|
|
478
499
|
var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
|
|
479
500
|
var constants = [];
|
|
@@ -487,9 +508,9 @@ var _handleJoinData = function _handleJoinData(joinData) {
|
|
|
487
508
|
if (isSubquery) {
|
|
488
509
|
subQuery = subquery;
|
|
489
510
|
}
|
|
490
|
-
var
|
|
491
|
-
sql =
|
|
492
|
-
joinConstants =
|
|
511
|
+
var _handleBaseType2Sql10 = _handleBaseType2Sql1(expressions, db),
|
|
512
|
+
sql = _handleBaseType2Sql10.sql,
|
|
513
|
+
joinConstants = _handleBaseType2Sql10.constants;
|
|
493
514
|
var joinCondition = "on ".concat(sql);
|
|
494
515
|
constants = joinConstants;
|
|
495
516
|
return {
|
|
@@ -498,6 +519,7 @@ var _handleJoinData = function _handleJoinData(joinData) {
|
|
|
498
519
|
tableName_zh: v.table2.name_zh,
|
|
499
520
|
datasourceId: v.table2.datasourceId || '',
|
|
500
521
|
datasourceName: v.table2.datasourceName || '',
|
|
522
|
+
datasourceType: v.table2.datasourceType || '',
|
|
501
523
|
joinCondition: joinCondition,
|
|
502
524
|
joinType: v.joinType,
|
|
503
525
|
subQuery: subQuery,
|
|
@@ -541,6 +563,7 @@ var _handleNesting = function handleNesting(data) {
|
|
|
541
563
|
obj.tableId = tableData.table.id;
|
|
542
564
|
obj.datasourceId = tableData.table.datasourceId;
|
|
543
565
|
obj.datasourceName = tableData.table.datasourceName;
|
|
566
|
+
obj.datasourceType = tableData.table.datasourceType;
|
|
544
567
|
if (tableData.isSubquery && Array.isArray(tableData.subquery)) {
|
|
545
568
|
obj.tableSubQuery = tableData.subquery;
|
|
546
569
|
}
|
|
@@ -572,9 +595,9 @@ var _handleNesting = function handleNesting(data) {
|
|
|
572
595
|
var customColumnsConstants = [];
|
|
573
596
|
var handleCustomColumn = function handleCustomColumn(data) {
|
|
574
597
|
return data.map(function (it) {
|
|
575
|
-
var
|
|
576
|
-
field_sql =
|
|
577
|
-
constants =
|
|
598
|
+
var _handleBaseType2Sql11 = _handleBaseType2Sql1(it.formulaList, db),
|
|
599
|
+
field_sql = _handleBaseType2Sql11.sql,
|
|
600
|
+
constants = _handleBaseType2Sql11.constants;
|
|
578
601
|
customColumnsConstants.push.apply(customColumnsConstants, _toConsumableArray(constants));
|
|
579
602
|
return {
|
|
580
603
|
field_sql: "".concat(field_sql, " as ").concat(it.name),
|
|
@@ -589,9 +612,9 @@ var _handleNesting = function handleNesting(data) {
|
|
|
589
612
|
obj.customColumnsConstants = customColumnsConstants;
|
|
590
613
|
}
|
|
591
614
|
if (filterData && filterData.filter.length) {
|
|
592
|
-
var
|
|
593
|
-
sql =
|
|
594
|
-
constants =
|
|
615
|
+
var _handleBaseType2Sql12 = _handleBaseType2Sql1(filterData.filter, db),
|
|
616
|
+
sql = _handleBaseType2Sql12.sql,
|
|
617
|
+
constants = _handleBaseType2Sql12.constants;
|
|
595
618
|
obj.filters = 'WHERE ' + sql;
|
|
596
619
|
obj.filtersConstants = constants;
|
|
597
620
|
}
|
|
@@ -616,7 +639,7 @@ var _handleNesting = function handleNesting(data) {
|
|
|
616
639
|
if (summarize.by.length) {
|
|
617
640
|
obj.groupBy.groupColumns = summarize.by.map(function (v) {
|
|
618
641
|
var _v$atoms;
|
|
619
|
-
var fieldSql = (_v$atoms = v.atoms) !== null && _v$atoms !== void 0 && _v$atoms.length ?
|
|
642
|
+
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);
|
|
620
643
|
queryColumns.push({
|
|
621
644
|
field_sql: "".concat(fieldSql, " as ").concat(v.fieldAlias),
|
|
622
645
|
read_name: '',
|
|
@@ -634,8 +657,8 @@ var _handleNesting = function handleNesting(data) {
|
|
|
634
657
|
}
|
|
635
658
|
if (sortData && sortData.sort.length) {
|
|
636
659
|
obj.orderInfos = "ORDER BY ".concat(sortData.sort.map(function (v) {
|
|
637
|
-
var
|
|
638
|
-
sql =
|
|
660
|
+
var _handleBaseType2Sql13 = _handleBaseType2Sql1(v.expression, db),
|
|
661
|
+
sql = _handleBaseType2Sql13.sql;
|
|
639
662
|
return "".concat(sql, " ").concat(v.sort);
|
|
640
663
|
}).join(', '));
|
|
641
664
|
}
|
package/lib/es/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;
|