@gingkoo/pandora-metabase 1.0.0-alpha.16 → 1.0.0-alpha.18
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/es/index.js +39 -99
- package/lib/es/index.js.map +1 -1
- package/lib/es/utils.d.ts +1 -1
- package/package.json +1 -1
package/lib/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @gingkoo/pandora-metabase v1.0.0-alpha.
|
|
2
|
+
* @gingkoo/pandora-metabase v1.0.0-alpha.18
|
|
3
3
|
*/
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import * as React from 'react';
|
|
@@ -924,6 +924,7 @@ const changeFieldAlias = (list, curObj) => {
|
|
|
924
924
|
return newList;
|
|
925
925
|
};
|
|
926
926
|
function splitByUnion(data) {
|
|
927
|
+
if (!data) return [];
|
|
927
928
|
const original = cloneDeep(data);
|
|
928
929
|
const result = [];
|
|
929
930
|
let i = 0;
|
|
@@ -959,7 +960,8 @@ function splitByUnion(data) {
|
|
|
959
960
|
}
|
|
960
961
|
return result;
|
|
961
962
|
}
|
|
962
|
-
function reassembleByUnion(target) {
|
|
963
|
+
function reassembleByUnion(target = []) {
|
|
964
|
+
if (!target) return [];
|
|
963
965
|
const result = [];
|
|
964
966
|
let i = 0;
|
|
965
967
|
const len = target.length;
|
|
@@ -1074,7 +1076,7 @@ const useStore = () => {
|
|
|
1074
1076
|
};
|
|
1075
1077
|
// 是否显示主表后面的字段按钮 (如果下面 没有聚合,或者选了聚合但是聚合里面没有选值的时候显示 主表字段按钮)
|
|
1076
1078
|
const showMainColumn = useMemo(() => {
|
|
1077
|
-
return metaList
|
|
1079
|
+
return metaList?.map((item, groupIndex) => {
|
|
1078
1080
|
// 过滤出所有汇总类型的项
|
|
1079
1081
|
const summarizeItems = item.list.filter(v => v.type === TypeEnum.summarize);
|
|
1080
1082
|
// 如果没有汇总项,默认显示主列
|
|
@@ -1129,7 +1131,7 @@ const useStore = () => {
|
|
|
1129
1131
|
columns = await fetchColumnsFn.current(extra, datasourceId);
|
|
1130
1132
|
setColumns(tableName, columns);
|
|
1131
1133
|
}
|
|
1132
|
-
const _columns = columns
|
|
1134
|
+
const _columns = columns?.map(v => {
|
|
1133
1135
|
return {
|
|
1134
1136
|
...v,
|
|
1135
1137
|
fieldUuid: v.fieldAlias || uuidv4('field')
|
|
@@ -1144,28 +1146,29 @@ const useStore = () => {
|
|
|
1144
1146
|
};
|
|
1145
1147
|
// 回显
|
|
1146
1148
|
// 设置column
|
|
1147
|
-
const setQuotes =
|
|
1148
|
-
let newMeta = cloneDeep(_meta);
|
|
1149
|
+
const setQuotes = newMeta => {
|
|
1149
1150
|
newMeta.table1 = {
|
|
1150
1151
|
...newMeta.table1,
|
|
1151
1152
|
fieldAlias: newMeta.table1.fieldAlias || newMeta.table1.column,
|
|
1152
|
-
fieldUuid: newMeta.table1.fieldUuid ||
|
|
1153
|
-
quotes: newMeta.table1.quotes || newMeta.table1.column
|
|
1153
|
+
fieldUuid: newMeta.table1.fieldUuid || uuidv4('field'),
|
|
1154
|
+
quotes: newMeta.table1.quotes || newMeta.table1.column,
|
|
1155
|
+
tableUuid: newMeta.table1.tableUuid || uuidv4('table')
|
|
1154
1156
|
};
|
|
1155
1157
|
newMeta.table2 = {
|
|
1156
1158
|
...newMeta.table2,
|
|
1157
1159
|
fieldAlias: newMeta.table2.fieldAlias || newMeta.table2.column,
|
|
1158
|
-
fieldUuid: newMeta.table2.fieldUuid ||
|
|
1159
|
-
quotes: newMeta.table2.quotes || newMeta.table2.column
|
|
1160
|
+
fieldUuid: newMeta.table2.fieldUuid || uuidv4('field'),
|
|
1161
|
+
quotes: newMeta.table2.quotes || newMeta.table2.column,
|
|
1162
|
+
tableUuid: newMeta.table2.tableUuid || uuidv4('table')
|
|
1160
1163
|
};
|
|
1161
1164
|
newMeta.expressions = newMeta.expressions?.map(v => {
|
|
1162
1165
|
return {
|
|
1163
1166
|
...v,
|
|
1164
1167
|
left_fieldAlias: v.fieldAlias || v.left_column,
|
|
1165
|
-
left_fieldUuid: v.fieldUuid ||
|
|
1168
|
+
left_fieldUuid: v.fieldUuid || uuidv4('field'),
|
|
1166
1169
|
left_quotes: v.left_quotes || v.left_column,
|
|
1167
1170
|
right_fieldAlias: v.right_fieldAlias || v.right_column,
|
|
1168
|
-
right_fieldUuid: v.right_fieldUuid ||
|
|
1171
|
+
right_fieldUuid: v.right_fieldUuid || uuidv4('field'),
|
|
1169
1172
|
right_quotes: v.right_quotes || v.right_column
|
|
1170
1173
|
};
|
|
1171
1174
|
});
|
|
@@ -1173,22 +1176,25 @@ const useStore = () => {
|
|
|
1173
1176
|
};
|
|
1174
1177
|
const setPreData = data => {
|
|
1175
1178
|
if (data.length) {
|
|
1176
|
-
let _metaList = data
|
|
1179
|
+
let _metaList = data?.map((item, groupIndex) => {
|
|
1177
1180
|
let newList = item.list?.map((v, i) => {
|
|
1178
1181
|
let newMeta = item.list;
|
|
1182
|
+
if (v.table) {
|
|
1183
|
+
v.table.tableUuid = v.table.tableUuid || uuidv4('table');
|
|
1184
|
+
}
|
|
1185
|
+
if (v.type === TypeEnum.joinData) {
|
|
1186
|
+
newMeta[i] = setQuotes(newMeta[i]);
|
|
1187
|
+
}
|
|
1179
1188
|
// 设置右侧column
|
|
1180
1189
|
if (v.table2?.datasourceId && v.columns.length < 1) {
|
|
1181
|
-
fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, columns => {
|
|
1190
|
+
fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, (columns = []) => {
|
|
1182
1191
|
if (v.isSubquery) {
|
|
1183
1192
|
let newColumns = [];
|
|
1184
1193
|
const items = getSubColumns(v.subquery);
|
|
1185
|
-
newColumns = items
|
|
1186
|
-
newMeta[i].columns = newColumns;
|
|
1194
|
+
newColumns = items?.flatMap(item => item.columns);
|
|
1195
|
+
newMeta[i].columns = newColumns || [];
|
|
1187
1196
|
} else {
|
|
1188
|
-
newMeta[i].columns = columns;
|
|
1189
|
-
}
|
|
1190
|
-
if (v.type === TypeEnum.joinData) {
|
|
1191
|
-
newMeta[i] = setQuotes(newMeta[i]);
|
|
1197
|
+
newMeta[i].columns = columns || [];
|
|
1192
1198
|
}
|
|
1193
1199
|
setMeta(newMeta, groupIndex);
|
|
1194
1200
|
});
|
|
@@ -1198,20 +1204,18 @@ const useStore = () => {
|
|
|
1198
1204
|
}
|
|
1199
1205
|
// 设置column
|
|
1200
1206
|
if (v.table?.datasourceId && v.columns.length < 1) {
|
|
1201
|
-
fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, columns => {
|
|
1207
|
+
fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, (columns = []) => {
|
|
1202
1208
|
if (v.isSubquery) {
|
|
1203
1209
|
let newColumns = [];
|
|
1204
1210
|
const items = getSubColumns(v.subquery);
|
|
1205
1211
|
newColumns = items.flatMap(item => item.columns);
|
|
1206
|
-
newMeta[i].columns = newColumns;
|
|
1207
|
-
v.columns = newColumns;
|
|
1212
|
+
newMeta[i].columns = newColumns || [];
|
|
1208
1213
|
} else {
|
|
1209
|
-
newMeta[i].columns = columns;
|
|
1210
|
-
v.columns = columns;
|
|
1211
|
-
}
|
|
1212
|
-
if (v.type === TypeEnum.joinData) {
|
|
1213
|
-
newMeta[i] = setQuotes(newMeta[i]);
|
|
1214
|
+
newMeta[i].columns = columns || [];
|
|
1214
1215
|
}
|
|
1216
|
+
// if (v.type === TypeEnum.joinData) {
|
|
1217
|
+
// newMeta[i] = setQuotes(newMeta[i]);
|
|
1218
|
+
// }
|
|
1215
1219
|
setMeta(newMeta, groupIndex);
|
|
1216
1220
|
});
|
|
1217
1221
|
return {
|
|
@@ -1385,7 +1389,7 @@ const useStore = () => {
|
|
|
1385
1389
|
setMeta(_metaList, groupIndex);
|
|
1386
1390
|
};
|
|
1387
1391
|
const setColumns = (tableId, columns) => {
|
|
1388
|
-
const _columns = columns
|
|
1392
|
+
const _columns = columns?.map(v => {
|
|
1389
1393
|
return {
|
|
1390
1394
|
...v,
|
|
1391
1395
|
fieldUuid: v.fieldUuid || uuidv4('field')
|
|
@@ -1410,46 +1414,10 @@ const useStore = () => {
|
|
|
1410
1414
|
const getDataset = datasourceId => {
|
|
1411
1415
|
return _cacheSource2TableMap[datasourceId] || [];
|
|
1412
1416
|
};
|
|
1413
|
-
const changeAlias = (groupIndex, alias) => {
|
|
1414
|
-
let newMetaList = metaList.slice();
|
|
1415
|
-
const _list = newMetaList[groupIndex].list;
|
|
1416
|
-
if (_list.length > 0) {
|
|
1417
|
-
_list.forEach(item => {
|
|
1418
|
-
if (item.type === TypeEnum.joinData && item.table2.alias === alias) {
|
|
1419
|
-
item.table2.alias = alias;
|
|
1420
|
-
} else if (item.type === TypeEnum.data && item.table.alias === alias) {
|
|
1421
|
-
item.table.alias = alias;
|
|
1422
|
-
} else if (item.type === TypeEnum.filter) {
|
|
1423
|
-
//过滤器
|
|
1424
|
-
item.filter.forEach(filterItem => {
|
|
1425
|
-
if (filterItem.alias === alias) {
|
|
1426
|
-
filterItem.alias = alias;
|
|
1427
|
-
}
|
|
1428
|
-
});
|
|
1429
|
-
} else if (item.type === TypeEnum.summarize) {
|
|
1430
|
-
// 汇总
|
|
1431
|
-
item.alias = alias;
|
|
1432
|
-
item.by.forEach(byItem => {
|
|
1433
|
-
if (byItem.alias === alias) {
|
|
1434
|
-
byItem.alias = alias;
|
|
1435
|
-
}
|
|
1436
|
-
});
|
|
1437
|
-
item.group.forEach(groupItem => {
|
|
1438
|
-
if (groupItem.alias === alias) {
|
|
1439
|
-
groupItem.alias = alias;
|
|
1440
|
-
groupItem.sql = alias;
|
|
1441
|
-
}
|
|
1442
|
-
});
|
|
1443
|
-
}
|
|
1444
|
-
});
|
|
1445
|
-
newMetaList[groupIndex].list = _list;
|
|
1446
|
-
_setMeta(newMetaList);
|
|
1447
|
-
}
|
|
1448
|
-
};
|
|
1449
1417
|
const reset = () => {
|
|
1450
1418
|
// setSourceList([]);
|
|
1451
1419
|
_setMeta(defaultMeta);
|
|
1452
|
-
setToolbar(defaultToolbar);
|
|
1420
|
+
// setToolbar(defaultToolbar);
|
|
1453
1421
|
set_cacheSource2TableMap({});
|
|
1454
1422
|
set_cacheColumnsMap({});
|
|
1455
1423
|
};
|
|
@@ -1503,7 +1471,6 @@ const useStore = () => {
|
|
|
1503
1471
|
_setShowSubquery,
|
|
1504
1472
|
constantList,
|
|
1505
1473
|
setConstantList,
|
|
1506
|
-
changeAlias,
|
|
1507
1474
|
popupContainer
|
|
1508
1475
|
};
|
|
1509
1476
|
};
|
|
@@ -5631,33 +5598,6 @@ const TableData = props => {
|
|
|
5631
5598
|
};
|
|
5632
5599
|
|
|
5633
5600
|
const PrevResult$1 = 'Previous results';
|
|
5634
|
-
function setQuotes(_meta) {
|
|
5635
|
-
let newMeta = cloneDeep(_meta);
|
|
5636
|
-
newMeta.table1 = {
|
|
5637
|
-
...newMeta.table1,
|
|
5638
|
-
fieldAlias: newMeta.table1.fieldAlias || newMeta.table1.column,
|
|
5639
|
-
fieldUuid: newMeta.table1.fieldUuid || newMeta.table1.column_id,
|
|
5640
|
-
quotes: newMeta.table1.quotes || newMeta.table1.column
|
|
5641
|
-
};
|
|
5642
|
-
newMeta.table2 = {
|
|
5643
|
-
...newMeta.table2,
|
|
5644
|
-
fieldAlias: newMeta.table2.fieldAlias || newMeta.table2.column,
|
|
5645
|
-
fieldUuid: newMeta.table2.fieldUuid || newMeta.table2.column_id,
|
|
5646
|
-
quotes: newMeta.table2.quotes || newMeta.table2.column
|
|
5647
|
-
};
|
|
5648
|
-
newMeta.expressions = newMeta.expressions?.map(v => {
|
|
5649
|
-
return {
|
|
5650
|
-
...v,
|
|
5651
|
-
left_fieldAlias: v.fieldAlias || v.left_column,
|
|
5652
|
-
left_fieldUuid: v.fieldUuid || v.left_column_id,
|
|
5653
|
-
left_quotes: v.left_quotes || v.left_column,
|
|
5654
|
-
right_fieldAlias: v.right_fieldAlias || v.right_column,
|
|
5655
|
-
right_fieldUuid: v.right_fieldUuid || v.right_column_id,
|
|
5656
|
-
right_quotes: v.right_quotes || v.right_column
|
|
5657
|
-
};
|
|
5658
|
-
});
|
|
5659
|
-
return newMeta;
|
|
5660
|
-
}
|
|
5661
5601
|
var FlagLocation;
|
|
5662
5602
|
(function (FlagLocation) {
|
|
5663
5603
|
FlagLocation["TABLE_1"] = "table1";
|
|
@@ -5682,11 +5622,11 @@ const JoinData = props => {
|
|
|
5682
5622
|
let table2Selected = Boolean(meta.table2.name);
|
|
5683
5623
|
let subQuerySelected = Boolean(meta.subquery?.[0]?.table?.name);
|
|
5684
5624
|
let columnsSelected = meta.table1.quotes && meta.table2.quotes;
|
|
5685
|
-
useEffect(() => {
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
}, []);
|
|
5625
|
+
// useEffect(() => {
|
|
5626
|
+
// let newMetaList = store.metaList[groupIndex].list.slice();
|
|
5627
|
+
// newMetaList[index] = setQuotes(meta);
|
|
5628
|
+
// store.setMeta(newMetaList, groupIndex);
|
|
5629
|
+
// }, []);
|
|
5690
5630
|
function selectColumns(e) {
|
|
5691
5631
|
let columns = meta.columns;
|
|
5692
5632
|
!meta.readonly && store.setPopup({
|