@gingkoo/pandora-metabase 1.0.27 → 1.0.29
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/common/SplitView/index.js +11 -12
- package/lib/cjs/components/dialog/custom-column/expression-editor.js +1 -2
- package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +1 -2
- package/lib/cjs/components/dialog/expression/index.js +11 -12
- package/lib/cjs/components/dialog/formula-list/index.js +53 -43
- package/lib/cjs/components/dialog/index.js +2 -2
- package/lib/cjs/components/dialog/select-column/index.js +4 -4
- package/lib/cjs/components/dialog/select-column-multiple/index.js +21 -10
- package/lib/cjs/components/dialog/select-join-column/index.js +13 -2
- package/lib/cjs/components/dialog/select-permission-table/index.js +2 -2
- package/lib/cjs/components/dialog/select-table/index.js +7 -7
- package/lib/cjs/components/icons.js +36 -36
- package/lib/cjs/components/metabase/index.js +41 -12
- package/lib/cjs/components/metabase/index.less +3 -0
- package/lib/cjs/components/modules/components/Wrapper.js +6 -6
- package/lib/cjs/components/modules/components/item-name.d.ts +7 -0
- package/lib/cjs/components/modules/components/item-name.js +34 -0
- package/lib/cjs/components/modules/components/meta-icon.js +6 -0
- package/lib/cjs/components/modules/custom-column.js +25 -25
- package/lib/cjs/components/modules/filter.js +2 -2
- package/lib/cjs/components/modules/join-data.js +215 -81
- package/lib/cjs/components/modules/permission-table.js +24 -10
- package/lib/cjs/components/modules/sort.js +17 -13
- package/lib/cjs/components/modules/summarize/group-by.js +90 -38
- package/lib/cjs/components/modules/summarize/select-index.js +84 -38
- package/lib/cjs/components/modules/table-data.js +14 -6
- package/lib/cjs/components/popup.js +1 -2
- package/lib/cjs/hooks/use-state.js +58 -65
- package/lib/cjs/index.js +1 -2
- package/lib/cjs/locale/en.js +5 -2
- package/lib/cjs/locale/zh.js +5 -2
- package/lib/cjs/utils/transformSql.d.ts +6 -0
- package/lib/cjs/utils/transformSql.js +968 -0
- package/lib/cjs/utils.d.ts +7 -1
- package/lib/cjs/utils.js +112 -15
- package/lib/es/common/SplitView/index.js +10 -10
- package/lib/es/components/dialog/expression/index.js +10 -10
- package/lib/es/components/dialog/formula-list/index.js +54 -44
- package/lib/es/components/dialog/select-column/index.js +4 -4
- package/lib/es/components/dialog/select-column-multiple/index.js +21 -10
- package/lib/es/components/dialog/select-join-column/index.js +13 -2
- package/lib/es/components/dialog/select-permission-table/index.js +2 -2
- package/lib/es/components/dialog/select-table/index.js +7 -7
- package/lib/es/components/icons.js +36 -36
- package/lib/es/components/metabase/index.js +42 -13
- package/lib/es/components/metabase/index.less +3 -0
- package/lib/es/components/modules/components/Wrapper.js +6 -6
- package/lib/es/components/modules/components/item-name.d.ts +7 -0
- package/lib/es/components/modules/components/item-name.js +28 -0
- package/lib/es/components/modules/components/meta-icon.js +6 -0
- package/lib/es/components/modules/custom-column.js +26 -26
- package/lib/es/components/modules/filter.js +2 -2
- package/lib/es/components/modules/join-data.js +216 -82
- package/lib/es/components/modules/permission-table.js +24 -10
- package/lib/es/components/modules/sort.js +18 -14
- package/lib/es/components/modules/summarize/group-by.js +92 -40
- package/lib/es/components/modules/summarize/select-index.js +86 -40
- package/lib/es/components/modules/table-data.js +14 -6
- package/lib/es/hooks/use-state.js +58 -65
- package/lib/es/locale/en.js +5 -2
- package/lib/es/locale/zh.js +5 -2
- package/lib/es/utils/transformSql.d.ts +6 -0
- package/lib/es/utils/transformSql.js +961 -0
- package/lib/es/utils.d.ts +7 -1
- package/lib/es/utils.js +102 -4
- package/package.json +1 -1
|
@@ -17,7 +17,8 @@ import { findIndex, getSubColumns } from '../../utils';
|
|
|
17
17
|
import { TypeEnum, ColumnsPopupThemeEnum, JoinEnum, SQL_COLUMN_TYPE } from '../../store/enum';
|
|
18
18
|
import { AtomsTypeEnum } from '../../store/types';
|
|
19
19
|
import { SummarizeAlias } from '../../store/helper';
|
|
20
|
-
import { getHelper, changeTableAlias, isValidSQLAlias } from '../../utils';
|
|
20
|
+
import { getHelper, changeTableAlias, isValidSQLAlias, isError } from '../../utils';
|
|
21
|
+
import ItemName from './components/item-name';
|
|
21
22
|
import Wrapper from './components/Wrapper';
|
|
22
23
|
import NextDom from './components/meta-icon';
|
|
23
24
|
import Header from './components/header';
|
|
@@ -60,7 +61,7 @@ var menuOperator = operators.map(function (v) {
|
|
|
60
61
|
};
|
|
61
62
|
});
|
|
62
63
|
var JoinData = function JoinData(props) {
|
|
63
|
-
var _meta$subquery, _meta$subquery2, _meta$subquery3, _meta$table2, _meta$table3, _meta$table5, _meta$table6, _meta$table7, _meta$table8, _meta$expressions, _meta$table9, _meta$
|
|
64
|
+
var _meta$subquery, _meta$subquery2, _meta$subquery3, _meta$table2, _meta$table3, _meta$table5, _meta$table6, _meta$table7, _meta$table8, _meta$expressions, _meta$table9, _meta$table0, _meta$expressions2, _store$showMainColumn, _store$showMainColumn2;
|
|
64
65
|
var meta = props.meta,
|
|
65
66
|
groupIndex = props.groupIndex;
|
|
66
67
|
var store = useStore();
|
|
@@ -71,6 +72,8 @@ var JoinData = function JoinData(props) {
|
|
|
71
72
|
var table2Selected = Boolean(meta.table2.name);
|
|
72
73
|
var subQuerySelected = Boolean((_meta$subquery = meta.subquery) === null || _meta$subquery === void 0 || (_meta$subquery = _meta$subquery[0]) === null || _meta$subquery === void 0 || (_meta$subquery = _meta$subquery.table) === null || _meta$subquery === void 0 ? void 0 : _meta$subquery.name);
|
|
73
74
|
var columnsSelected = meta.table1.name && meta.table2.name;
|
|
75
|
+
var _getHelper = getHelper(store.metaList[groupIndex].list, meta),
|
|
76
|
+
prevTables = _getHelper.prevTables;
|
|
74
77
|
// const ref = useRef(null);
|
|
75
78
|
// useEffect(() => {
|
|
76
79
|
// let newMetaList = store.metaList[groupIndex].list.slice();
|
|
@@ -80,10 +83,10 @@ var JoinData = function JoinData(props) {
|
|
|
80
83
|
// 获取表格列
|
|
81
84
|
var getTableColumns = function getTableColumns() {
|
|
82
85
|
var data = [];
|
|
83
|
-
var
|
|
84
|
-
ExistAboveGroupBy =
|
|
85
|
-
prevList =
|
|
86
|
-
prevGroupBy =
|
|
86
|
+
var _getHelper2 = getHelper(store.metaList[groupIndex].list, meta),
|
|
87
|
+
ExistAboveGroupBy = _getHelper2.ExistAboveGroupBy,
|
|
88
|
+
prevList = _getHelper2.prevList,
|
|
89
|
+
prevGroupBy = _getHelper2.prevGroupBy;
|
|
87
90
|
// 获取左侧表
|
|
88
91
|
if (ExistAboveGroupBy) {
|
|
89
92
|
var _prevGroupBy$group, _prevGroupBy$by;
|
|
@@ -216,10 +219,10 @@ var JoinData = function JoinData(props) {
|
|
|
216
219
|
var index = findIndex(store.metaList[groupIndex].list, meta);
|
|
217
220
|
var table_type = FlagLocation.TABLE_1;
|
|
218
221
|
var data = [];
|
|
219
|
-
var
|
|
220
|
-
ExistAboveGroupBy =
|
|
221
|
-
prevList =
|
|
222
|
-
prevGroupBy =
|
|
222
|
+
var _getHelper3 = getHelper(store.metaList[groupIndex].list, meta),
|
|
223
|
+
ExistAboveGroupBy = _getHelper3.ExistAboveGroupBy,
|
|
224
|
+
prevList = _getHelper3.prevList,
|
|
225
|
+
prevGroupBy = _getHelper3.prevGroupBy;
|
|
223
226
|
if (ExistAboveGroupBy) {
|
|
224
227
|
var _prevGroupBy$group2, _prevGroupBy$by2;
|
|
225
228
|
var _data = {
|
|
@@ -328,12 +331,12 @@ var JoinData = function JoinData(props) {
|
|
|
328
331
|
data: data,
|
|
329
332
|
value: newMeta[index][table_type],
|
|
330
333
|
onChange: function onChange(data) {
|
|
331
|
-
if (table_type === FlagLocation.TABLE_1) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
334
|
+
// if (table_type === FlagLocation.TABLE_1) {
|
|
335
|
+
if (newMeta[index][table_type].datasourceId !== data.datasourceId || newMeta[index][table_type].name !== data.name) {
|
|
336
|
+
newMeta[index][table_type] = data;
|
|
337
|
+
initExpressions();
|
|
336
338
|
}
|
|
339
|
+
// }
|
|
337
340
|
store.setMeta(newMeta, groupIndex);
|
|
338
341
|
store.setPopup({
|
|
339
342
|
visible: false
|
|
@@ -378,10 +381,8 @@ var JoinData = function JoinData(props) {
|
|
|
378
381
|
store.fetchColumns(_table2, data.datasourceId, [], function (columns) {
|
|
379
382
|
newMeta[index].columns = columns;
|
|
380
383
|
// 关联表变了 下面模块全部删除
|
|
381
|
-
newMeta = newMeta.filter(
|
|
382
|
-
|
|
383
|
-
});
|
|
384
|
-
store.setMeta(newMeta, groupIndex);
|
|
384
|
+
// newMeta = newMeta.filter((v: MetaListType, i: number) => i <= index);
|
|
385
|
+
// store.setMeta(newMeta, groupIndex);
|
|
385
386
|
});
|
|
386
387
|
}
|
|
387
388
|
store.setPopup({
|
|
@@ -393,8 +394,10 @@ var JoinData = function JoinData(props) {
|
|
|
393
394
|
}
|
|
394
395
|
// 切换表后重置数据
|
|
395
396
|
function initExpressions() {
|
|
396
|
-
console.log(11);
|
|
397
397
|
var newMeta = store.metaList[groupIndex].list.slice();
|
|
398
|
+
if (newMeta[index].expressions && newMeta[index].expressions.length > 0) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
398
401
|
newMeta[index].expressions = [{
|
|
399
402
|
lhs: [{
|
|
400
403
|
fieldName: '',
|
|
@@ -481,6 +484,120 @@ var JoinData = function JoinData(props) {
|
|
|
481
484
|
})
|
|
482
485
|
});
|
|
483
486
|
}
|
|
487
|
+
function getColumns(_position) {
|
|
488
|
+
var data = [];
|
|
489
|
+
var _getHelper4 = getHelper(store.metaList[groupIndex].list, meta),
|
|
490
|
+
ExistAboveGroupBy = _getHelper4.ExistAboveGroupBy,
|
|
491
|
+
prevList = _getHelper4.prevList,
|
|
492
|
+
prevGroupBy = _getHelper4.prevGroupBy;
|
|
493
|
+
if (_position === ExpressionsEnum.LEFT) {
|
|
494
|
+
if (ExistAboveGroupBy) {
|
|
495
|
+
var _prevGroupBy$group3, _prevGroupBy$by3;
|
|
496
|
+
var _data = {
|
|
497
|
+
name: prevGroupBy.alias,
|
|
498
|
+
name_zh: prevGroupBy.alias,
|
|
499
|
+
id: prevGroupBy.alias,
|
|
500
|
+
tableUuid: prevGroupBy.tableUuid || uuidv4('table'),
|
|
501
|
+
alias: prevGroupBy.alias,
|
|
502
|
+
datasourceId: '',
|
|
503
|
+
datasourceName: '',
|
|
504
|
+
columns: []
|
|
505
|
+
};
|
|
506
|
+
if (prevGroupBy !== null && prevGroupBy !== void 0 && (_prevGroupBy$group3 = prevGroupBy.group) !== null && _prevGroupBy$group3 !== void 0 && _prevGroupBy$group3.length) {
|
|
507
|
+
_data.columns = _data.columns.concat(prevGroupBy.group.map(function (v) {
|
|
508
|
+
return _objectSpread(_objectSpread({}, v), {}, {
|
|
509
|
+
name: v.name || v.quotes,
|
|
510
|
+
name_zh: v.name_zh || v.quotes,
|
|
511
|
+
id: v.id || v.fieldId,
|
|
512
|
+
database_type: (v === null || v === void 0 ? void 0 : v.database_type) || SQL_COLUMN_TYPE.FLOAT,
|
|
513
|
+
special_type: '',
|
|
514
|
+
sql: v.sql,
|
|
515
|
+
select: true
|
|
516
|
+
});
|
|
517
|
+
}));
|
|
518
|
+
}
|
|
519
|
+
if (prevGroupBy !== null && prevGroupBy !== void 0 && (_prevGroupBy$by3 = prevGroupBy.by) !== null && _prevGroupBy$by3 !== void 0 && _prevGroupBy$by3.length) {
|
|
520
|
+
_data.columns = _data.columns.concat(prevGroupBy.by.map(function (v) {
|
|
521
|
+
return _objectSpread(_objectSpread({}, v), {}, {
|
|
522
|
+
name: v.name || v.quotes,
|
|
523
|
+
name_zh: v.name_zh || v.quotes,
|
|
524
|
+
id: v.id || v.fieldId,
|
|
525
|
+
database_type: (v === null || v === void 0 ? void 0 : v.database_type) || SQL_COLUMN_TYPE.FLOAT,
|
|
526
|
+
special_type: '',
|
|
527
|
+
sql: v.sql,
|
|
528
|
+
select: true
|
|
529
|
+
});
|
|
530
|
+
}));
|
|
531
|
+
}
|
|
532
|
+
data = [_data];
|
|
533
|
+
var joinData = prevList.filter(function (v) {
|
|
534
|
+
return v.type === TypeEnum.joinData;
|
|
535
|
+
}).filter(function (v) {
|
|
536
|
+
return v && v.table2.name;
|
|
537
|
+
});
|
|
538
|
+
if (joinData !== null && joinData !== void 0 && joinData.length) {
|
|
539
|
+
data = data.concat(joinData.map(function (v) {
|
|
540
|
+
return {
|
|
541
|
+
alias: v.table2.alias,
|
|
542
|
+
name: v.table2.name,
|
|
543
|
+
name_zh: v.table2.name_zh,
|
|
544
|
+
id: v.table2.id,
|
|
545
|
+
tableUuid: v.table2.tableUuid || uuidv4('table'),
|
|
546
|
+
datasourceId: v.table2.datasourceId,
|
|
547
|
+
datasourceName: v.table2.datasourceName,
|
|
548
|
+
columns: v.columns
|
|
549
|
+
};
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
} else {
|
|
553
|
+
data = store.metaList[groupIndex].list.slice(0, index).reduce(function (mo, v) {
|
|
554
|
+
if (v.type === TypeEnum.data) {
|
|
555
|
+
mo.push({
|
|
556
|
+
alias: v.table.alias,
|
|
557
|
+
name: v.table.name,
|
|
558
|
+
name_zh: v.table.name_zh,
|
|
559
|
+
id: v.table.id,
|
|
560
|
+
tableUuid: v.table.tableUuid || uuidv4('table'),
|
|
561
|
+
columns: v.columns,
|
|
562
|
+
datasourceId: v.table.datasourceId,
|
|
563
|
+
datasourceName: v.table.datasourceName
|
|
564
|
+
});
|
|
565
|
+
} else if (v.type === TypeEnum.joinData) {
|
|
566
|
+
mo.push({
|
|
567
|
+
alias: v.table2.alias,
|
|
568
|
+
name: v.table2.name,
|
|
569
|
+
name_zh: v.table2.name_zh,
|
|
570
|
+
id: v.table2.id,
|
|
571
|
+
tableUuid: v.table2.tableUuid || uuidv4('table'),
|
|
572
|
+
columns: v.columns,
|
|
573
|
+
datasourceId: v.table2.datasourceId,
|
|
574
|
+
datasourceName: v.table2.datasourceName
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
return mo;
|
|
578
|
+
}, []);
|
|
579
|
+
}
|
|
580
|
+
// 过滤为table1选中的表
|
|
581
|
+
var newMeta = store.metaList[groupIndex].list.slice();
|
|
582
|
+
if (newMeta[index][FlagLocation.TABLE_1].name) {
|
|
583
|
+
data = data.filter(function (v) {
|
|
584
|
+
return newMeta[index][FlagLocation.TABLE_1].tableUuid == v.tableUuid || newMeta[index][FlagLocation.TABLE_1].name === SummarizeAlias && newMeta[index][FlagLocation.TABLE_1].id == v.id;
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
data = [{
|
|
589
|
+
alias: meta.table2.alias,
|
|
590
|
+
name: meta.table2.name,
|
|
591
|
+
name_zh: meta.table2.name_zh,
|
|
592
|
+
id: meta.table2.id,
|
|
593
|
+
tableUuid: meta.table2.tableUuid || uuidv4('table'),
|
|
594
|
+
datasourceId: meta.table2.datasourceId,
|
|
595
|
+
datasourceName: meta.table2.datasourceName,
|
|
596
|
+
columns: meta.columns
|
|
597
|
+
}];
|
|
598
|
+
}
|
|
599
|
+
return data;
|
|
600
|
+
}
|
|
484
601
|
function selectMoreJoinColumn(e) {
|
|
485
602
|
var node = e.currentTarget;
|
|
486
603
|
var _position = node.getAttribute('v-position');
|
|
@@ -488,13 +605,13 @@ var JoinData = function JoinData(props) {
|
|
|
488
605
|
var _ind2 = Number(node.getAttribute('v-index2'));
|
|
489
606
|
var index = findIndex(store.metaList[groupIndex].list, meta);
|
|
490
607
|
var data = [];
|
|
491
|
-
var
|
|
492
|
-
ExistAboveGroupBy =
|
|
493
|
-
prevList =
|
|
494
|
-
prevGroupBy =
|
|
608
|
+
var _getHelper5 = getHelper(store.metaList[groupIndex].list, meta),
|
|
609
|
+
ExistAboveGroupBy = _getHelper5.ExistAboveGroupBy,
|
|
610
|
+
prevList = _getHelper5.prevList,
|
|
611
|
+
prevGroupBy = _getHelper5.prevGroupBy;
|
|
495
612
|
if (_position === ExpressionsEnum.LEFT) {
|
|
496
613
|
if (ExistAboveGroupBy) {
|
|
497
|
-
var _prevGroupBy$
|
|
614
|
+
var _prevGroupBy$group4, _prevGroupBy$by4;
|
|
498
615
|
var _data = {
|
|
499
616
|
name: prevGroupBy.alias,
|
|
500
617
|
name_zh: prevGroupBy.alias,
|
|
@@ -505,7 +622,7 @@ var JoinData = function JoinData(props) {
|
|
|
505
622
|
datasourceName: '',
|
|
506
623
|
columns: []
|
|
507
624
|
};
|
|
508
|
-
if (prevGroupBy !== null && prevGroupBy !== void 0 && (_prevGroupBy$
|
|
625
|
+
if (prevGroupBy !== null && prevGroupBy !== void 0 && (_prevGroupBy$group4 = prevGroupBy.group) !== null && _prevGroupBy$group4 !== void 0 && _prevGroupBy$group4.length) {
|
|
509
626
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(function (v) {
|
|
510
627
|
return _objectSpread(_objectSpread({}, v), {}, {
|
|
511
628
|
name: v.name || v.quotes,
|
|
@@ -518,7 +635,7 @@ var JoinData = function JoinData(props) {
|
|
|
518
635
|
});
|
|
519
636
|
}));
|
|
520
637
|
}
|
|
521
|
-
if (prevGroupBy !== null && prevGroupBy !== void 0 && (_prevGroupBy$
|
|
638
|
+
if (prevGroupBy !== null && prevGroupBy !== void 0 && (_prevGroupBy$by4 = prevGroupBy.by) !== null && _prevGroupBy$by4 !== void 0 && _prevGroupBy$by4.length) {
|
|
522
639
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(function (v) {
|
|
523
640
|
return _objectSpread(_objectSpread({}, v), {}, {
|
|
524
641
|
name: v.name || v.quotes,
|
|
@@ -583,7 +700,7 @@ var JoinData = function JoinData(props) {
|
|
|
583
700
|
var newMeta = store.metaList[groupIndex].list.slice();
|
|
584
701
|
if (newMeta[index][FlagLocation.TABLE_1].name) {
|
|
585
702
|
data = data.filter(function (v) {
|
|
586
|
-
return newMeta[index][FlagLocation.TABLE_1].tableUuid == v.tableUuid || newMeta[index][FlagLocation.TABLE_1].name === SummarizeAlias;
|
|
703
|
+
return newMeta[index][FlagLocation.TABLE_1].tableUuid == v.tableUuid || newMeta[index][FlagLocation.TABLE_1].name === SummarizeAlias && newMeta[index][FlagLocation.TABLE_1].id == v.id;
|
|
587
704
|
});
|
|
588
705
|
}
|
|
589
706
|
} else {
|
|
@@ -784,7 +901,7 @@ var JoinData = function JoinData(props) {
|
|
|
784
901
|
showSubquery: store._showSubquery,
|
|
785
902
|
toolbar: _toolbar,
|
|
786
903
|
btnText: __('SqlQueryBuilder.confirm'),
|
|
787
|
-
value: val,
|
|
904
|
+
value: cloneDeep(val),
|
|
788
905
|
onOk: function onOk(newList) {
|
|
789
906
|
try {
|
|
790
907
|
// 子查询未改变不做操作
|
|
@@ -801,12 +918,18 @@ var JoinData = function JoinData(props) {
|
|
|
801
918
|
var newColumns = items.flatMap(function (item) {
|
|
802
919
|
return item.columns;
|
|
803
920
|
});
|
|
804
|
-
newMeta[index].columns = newColumns
|
|
921
|
+
newMeta[index].columns = newColumns.map(function (newCol) {
|
|
922
|
+
// 查找旧列中是否有相同 name 的列
|
|
923
|
+
var existingCol = newMeta[index].columns.find(function (oldCol) {
|
|
924
|
+
return oldCol.name === newCol.name;
|
|
925
|
+
});
|
|
926
|
+
// 如果存在,返回旧列;否则返回新列
|
|
927
|
+
return existingCol ? existingCol : newCol;
|
|
928
|
+
});
|
|
929
|
+
// (newMeta[index] as MetaJoin).columns = newColumns;
|
|
805
930
|
initExpressions();
|
|
806
931
|
// 关联表变了 下面模块全部删除
|
|
807
|
-
newMeta = newMeta.filter(
|
|
808
|
-
return i <= index;
|
|
809
|
-
});
|
|
932
|
+
// newMeta = newMeta.filter((v: MetaListType, i: number) => i <= index);
|
|
810
933
|
store.setMeta(newMeta, groupIndex);
|
|
811
934
|
o.close();
|
|
812
935
|
} catch (e) {
|
|
@@ -825,24 +948,19 @@ var JoinData = function JoinData(props) {
|
|
|
825
948
|
var index = findIndex(store.metaList[groupIndex].list, meta);
|
|
826
949
|
var newMeta = store.metaList[groupIndex].list.slice();
|
|
827
950
|
newMeta[index].isSubquery = !newMeta[index].isSubquery;
|
|
828
|
-
newMeta[index].table2 = {
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
datasourceId: '' // 数据源id
|
|
842
|
-
// groupSql: '', //如果table1 是结果集 那么这个字段 就有值,放结果集的别名
|
|
843
|
-
};
|
|
844
|
-
newMeta[index].expressions = [];
|
|
845
|
-
newMeta[index].subquery = [];
|
|
951
|
+
// (newMeta[index] as MetaJoin).table2 = {
|
|
952
|
+
// quotes: '',
|
|
953
|
+
// name: '', // 表名
|
|
954
|
+
// name_zh: '', // 表名
|
|
955
|
+
// tableUuid: '',
|
|
956
|
+
// id: '', // 表名
|
|
957
|
+
// alias: '', // 表别名
|
|
958
|
+
// datasourceName: '', // 数据源名
|
|
959
|
+
// datasourceId: '', // 数据源id
|
|
960
|
+
// // groupSql: '', //如果table1 是结果集 那么这个字段 就有值,放结果集的别名
|
|
961
|
+
// };
|
|
962
|
+
// (newMeta[index] as MetaJoin).expressions = [];
|
|
963
|
+
// (newMeta[index] as MetaJoin).subquery = [];
|
|
846
964
|
store.setMeta(newMeta, groupIndex);
|
|
847
965
|
};
|
|
848
966
|
var onChangeTableAlias = function onChangeTableAlias(val) {
|
|
@@ -859,22 +977,22 @@ var JoinData = function JoinData(props) {
|
|
|
859
977
|
onOk: function () {
|
|
860
978
|
var _onOk = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
861
979
|
var index, newMeta;
|
|
862
|
-
return _regeneratorRuntime.wrap(function
|
|
980
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
863
981
|
while (1) switch (_context.prev = _context.next) {
|
|
864
982
|
case 0:
|
|
865
983
|
if (isValidSQLAlias(alias)) {
|
|
866
|
-
_context.next =
|
|
984
|
+
_context.next = 1;
|
|
867
985
|
break;
|
|
868
986
|
}
|
|
869
987
|
Toast.warning(__('SqlQueryBuilder.aliasForRules'));
|
|
870
988
|
return _context.abrupt("return", false);
|
|
871
|
-
case
|
|
989
|
+
case 1:
|
|
872
990
|
index = findIndex(store.metaList[groupIndex].list, meta);
|
|
873
991
|
newMeta = store.metaList[groupIndex].list.slice();
|
|
874
992
|
newMeta[index].table2.alias = alias;
|
|
875
993
|
newMeta = changeTableAlias(newMeta, newMeta[index].table2);
|
|
876
994
|
store.setMeta(newMeta, groupIndex);
|
|
877
|
-
case
|
|
995
|
+
case 2:
|
|
878
996
|
case "end":
|
|
879
997
|
return _context.stop();
|
|
880
998
|
}
|
|
@@ -1011,21 +1129,31 @@ var JoinData = function JoinData(props) {
|
|
|
1011
1129
|
return '';
|
|
1012
1130
|
}
|
|
1013
1131
|
};
|
|
1132
|
+
var leftTableIsError = function leftTableIsError() {
|
|
1133
|
+
var _prevTables$meta$tabl;
|
|
1134
|
+
if (!meta.table1.datasourceId || !meta.table1.id || meta.table1.datasourceId === SummarizeAlias) {
|
|
1135
|
+
return false;
|
|
1136
|
+
}
|
|
1137
|
+
return !(prevTables !== null && prevTables !== void 0 && (_prevTables$meta$tabl = prevTables[meta.table1.datasourceId]) !== null && _prevTables$meta$tabl !== void 0 && _prevTables$meta$tabl[meta.table1.id]);
|
|
1138
|
+
};
|
|
1014
1139
|
var renderItem = function renderItem(items, type, i) {
|
|
1015
1140
|
var _items$;
|
|
1016
1141
|
if ((items === null || items === void 0 || (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.type) === AtomsTypeEnum.FIELD) {
|
|
1017
1142
|
var _items$2, _items$3;
|
|
1018
|
-
return _jsx(
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1143
|
+
return _jsx(ItemName, {
|
|
1144
|
+
isError: isError(items, getColumns(type)),
|
|
1145
|
+
children: _jsx("div", {
|
|
1146
|
+
className: cx("Sqb-TableName", {
|
|
1147
|
+
notSelected: !((_items$2 = items[0]) !== null && _items$2 !== void 0 && _items$2.fieldName)
|
|
1148
|
+
}),
|
|
1149
|
+
"v-position": type,
|
|
1150
|
+
"v-index": i,
|
|
1151
|
+
"v-index2": index,
|
|
1152
|
+
onClick: selectMoreJoinColumn,
|
|
1153
|
+
children: (_items$3 = items[0]) !== null && _items$3 !== void 0 && _items$3.fieldName ? items.map(function (field) {
|
|
1154
|
+
return field.fieldName;
|
|
1155
|
+
}).join(' || ') : __('SqlQueryBuilder.pickTable')
|
|
1156
|
+
})
|
|
1029
1157
|
}, type + i);
|
|
1030
1158
|
} else {
|
|
1031
1159
|
return items === null || items === void 0 ? void 0 : items.map(function (item, index) {
|
|
@@ -1096,12 +1224,15 @@ var JoinData = function JoinData(props) {
|
|
|
1096
1224
|
className: cx("Sqb-item--content"),
|
|
1097
1225
|
children: _jsxs("div", {
|
|
1098
1226
|
className: cx("Sqb-NotebookCell"),
|
|
1099
|
-
children: [_jsx(
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1227
|
+
children: [_jsx(ItemName, {
|
|
1228
|
+
isError: leftTableIsError(),
|
|
1229
|
+
children: _jsx("div", {
|
|
1230
|
+
className: cx("Sqb-TableName", {
|
|
1231
|
+
notSelected: !table1Selected
|
|
1232
|
+
}),
|
|
1233
|
+
onClick: selectLeftTable,
|
|
1234
|
+
children: getTable1Name() || __('SqlQueryBuilder.pickTable')
|
|
1235
|
+
})
|
|
1105
1236
|
}), _jsx("div", {
|
|
1106
1237
|
onClick: selectJoin,
|
|
1107
1238
|
children: meta.joinType === JoinEnum.left ? _jsx(LeftJoinIcon, {
|
|
@@ -1304,15 +1435,18 @@ var JoinData = function JoinData(props) {
|
|
|
1304
1435
|
children: [i == 0 && _jsx("span", {
|
|
1305
1436
|
className: 'ml-2 mr-4 text-gray-500',
|
|
1306
1437
|
children: "on"
|
|
1307
|
-
}), _jsx(
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1438
|
+
}), _jsx(ItemName, {
|
|
1439
|
+
isError: isError(v, getTableColumns()),
|
|
1440
|
+
children: _jsx("div", {
|
|
1441
|
+
className: cx("Sqb-TableName purple-name", {
|
|
1442
|
+
notSelected: !v.quotes
|
|
1443
|
+
}),
|
|
1444
|
+
onClick: function onClick(e) {
|
|
1445
|
+
return changeExpression(e, i);
|
|
1446
|
+
},
|
|
1447
|
+
children: v.quotes || __('joinData.selectExpression')
|
|
1448
|
+
}, i)
|
|
1449
|
+
}), _jsx(Tooltip, {
|
|
1316
1450
|
title: __('SqlQueryBuilder.add'),
|
|
1317
1451
|
children: _jsx(Dropdown, {
|
|
1318
1452
|
trigger: ['click'],
|
|
@@ -1398,7 +1532,7 @@ var JoinData = function JoinData(props) {
|
|
|
1398
1532
|
})]
|
|
1399
1533
|
}, i);
|
|
1400
1534
|
}
|
|
1401
|
-
})), ((_meta$table9 = meta.table2) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.name) && ((_meta$
|
|
1535
|
+
})), ((_meta$table9 = meta.table2) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.name) && ((_meta$table0 = meta.table1) === null || _meta$table0 === void 0 ? void 0 : _meta$table0.name) && (((_meta$expressions2 = meta.expressions) === null || _meta$expressions2 === void 0 ? void 0 : _meta$expressions2.length) || 0) < 1 && _jsx(Tooltip, {
|
|
1402
1536
|
title: __('SqlQueryBuilder.add'),
|
|
1403
1537
|
children: _jsx(Dropdown, {
|
|
1404
1538
|
trigger: ['click'],
|
|
@@ -10,17 +10,21 @@ import NextDom from './components/meta-icon';
|
|
|
10
10
|
import Header from './components/header';
|
|
11
11
|
import { useStore } from '../../hooks/use-provider';
|
|
12
12
|
import { uuidv4 } from '../../utils/helper';
|
|
13
|
+
import ItemName from './components/item-name';
|
|
14
|
+
import { SummarizeAlias } from '../../store/helper';
|
|
13
15
|
var PrevResult = 'Previous results';
|
|
14
16
|
var PermissionTable = function PermissionTable(props) {
|
|
15
17
|
var meta = props.meta,
|
|
16
18
|
groupIndex = props.groupIndex;
|
|
17
19
|
var store = useStore();
|
|
18
20
|
var index = findIndex(store.metaList[groupIndex].list, meta);
|
|
21
|
+
var _getHelper = getHelper(store.metaList[groupIndex].list, meta),
|
|
22
|
+
prevTables = _getHelper.prevTables;
|
|
19
23
|
function selectTable(e) {
|
|
20
|
-
var
|
|
21
|
-
ExistAboveGroupBy =
|
|
22
|
-
prevList =
|
|
23
|
-
prevGroupBy =
|
|
24
|
+
var _getHelper2 = getHelper(store.metaList[groupIndex].list, meta),
|
|
25
|
+
ExistAboveGroupBy = _getHelper2.ExistAboveGroupBy,
|
|
26
|
+
prevList = _getHelper2.prevList,
|
|
27
|
+
prevGroupBy = _getHelper2.prevGroupBy;
|
|
24
28
|
var data = [];
|
|
25
29
|
if (ExistAboveGroupBy) {
|
|
26
30
|
var _data = {
|
|
@@ -95,6 +99,13 @@ var PermissionTable = function PermissionTable(props) {
|
|
|
95
99
|
});
|
|
96
100
|
}
|
|
97
101
|
var selected = Boolean(meta.table.name);
|
|
102
|
+
var tableIsError = function tableIsError() {
|
|
103
|
+
var _prevTables$meta$tabl;
|
|
104
|
+
if (!meta.table.datasourceId && !meta.table.id) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return !(prevTables !== null && prevTables !== void 0 && (_prevTables$meta$tabl = prevTables[meta.table.datasourceId]) !== null && _prevTables$meta$tabl !== void 0 && _prevTables$meta$tabl[meta.table.id]);
|
|
108
|
+
};
|
|
98
109
|
return _jsx(Wrapper, {
|
|
99
110
|
className: "Sqb-item",
|
|
100
111
|
children: _jsxs("div", {
|
|
@@ -109,12 +120,15 @@ var PermissionTable = function PermissionTable(props) {
|
|
|
109
120
|
className: "Sqb-item--content",
|
|
110
121
|
children: _jsx("div", {
|
|
111
122
|
className: "Sqb-NotebookCell gray-bg",
|
|
112
|
-
children: _jsx(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
123
|
+
children: _jsx(ItemName, {
|
|
124
|
+
isError: tableIsError(),
|
|
125
|
+
children: _jsx("div", {
|
|
126
|
+
className: cx("Sqb-TableName", {
|
|
127
|
+
notSelected: !selected
|
|
128
|
+
}),
|
|
129
|
+
onClick: selectTable,
|
|
130
|
+
children: selected ? "".concat(meta.table.datasourceName ? "".concat(meta.table.datasourceName, ".") : '').concat(meta.table.name === SummarizeAlias ? PrevResult : meta.table.name) : __('SqlQueryBuilder.pickPermissionTable')
|
|
131
|
+
})
|
|
118
132
|
})
|
|
119
133
|
})
|
|
120
134
|
}), _jsx(NextDom, {
|
|
@@ -3,7 +3,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
import cx from 'classnames';
|
|
5
5
|
import { __ } from '../../locale';
|
|
6
|
-
import { findIndex, getHelper } from '../../utils';
|
|
6
|
+
import { findIndex, getHelper, isError } from '../../utils';
|
|
7
7
|
import { ColumnsPopupThemeEnum, TypeEnum, SortEnum, SQL_COLUMN_TYPE } from '../../store/enum';
|
|
8
8
|
import { AtomsTypeEnum } from '../../store/types';
|
|
9
9
|
import { uuidv4 } from '../../utils/helper';
|
|
@@ -13,6 +13,7 @@ import Wrapper from './components/Wrapper';
|
|
|
13
13
|
import NextDom from './components/meta-icon';
|
|
14
14
|
import Header from './components/header';
|
|
15
15
|
import { useStore } from '../../hooks/use-provider';
|
|
16
|
+
import ItemName from './components/item-name';
|
|
16
17
|
var Sort = function Sort(props) {
|
|
17
18
|
var meta = props.meta,
|
|
18
19
|
groupIndex = props.groupIndex;
|
|
@@ -243,20 +244,23 @@ var Sort = function Sort(props) {
|
|
|
243
244
|
children: _jsxs("div", {
|
|
244
245
|
className: cx("Sqb-NotebookCell gray-bg"),
|
|
245
246
|
children: [sort.map(function (v, i) {
|
|
246
|
-
return
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
style: {
|
|
253
|
-
fontSize: 0
|
|
247
|
+
return _jsx(ItemName, {
|
|
248
|
+
isError: isError(v.expression, getColumns()),
|
|
249
|
+
children: _jsxs("div", {
|
|
250
|
+
className: "Sqb-TableName gray-name",
|
|
251
|
+
onClick: function onClick() {
|
|
252
|
+
return handleSort(i);
|
|
254
253
|
},
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
254
|
+
children: [v.sort === SortEnum.asc ? _jsx(UpArrowIcon, {}) : _jsx(DownArrowIcon, {}), getName(v.expression), _jsx("span", {
|
|
255
|
+
style: {
|
|
256
|
+
fontSize: 0
|
|
257
|
+
},
|
|
258
|
+
onClick: function onClick(e) {
|
|
259
|
+
return delSortColumn(e, i);
|
|
260
|
+
},
|
|
261
|
+
children: _jsx(CloseIcon, {})
|
|
262
|
+
})]
|
|
263
|
+
}, i)
|
|
260
264
|
}, i);
|
|
261
265
|
}), _jsx("div", {
|
|
262
266
|
className: "Sqb-TableName gray-name",
|