@gingkoo/pandora-metabase 0.0.1-alpha.5 → 0.0.1-alpha.7
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/README.md +3 -1
- package/lib/es/index.js +110 -27
- package/lib/es/index.js.map +1 -1
- package/lib/es/store/index.d.ts +6 -2
- package/lib/es/store/types.d.ts +2 -1
- package/lib/es/types.d.ts +3 -1
- package/lib/es/utils/helper.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,8 +42,9 @@ export type ToolbarType =
|
|
|
42
42
|
export interface MetaBaseProps {
|
|
43
43
|
loading?: boolean; // 加载状态
|
|
44
44
|
btnText?: string; //按钮文字
|
|
45
|
-
showPermissionTable?: boolean; // 是否显示权限表
|
|
46
45
|
showFields?:boolean ; //是否显示字段
|
|
46
|
+
tableNameTpl?: string; //表名
|
|
47
|
+
fieldNameTpl?: string; //字段名
|
|
47
48
|
/**
|
|
48
49
|
* 工具栏列表
|
|
49
50
|
* 默认 ['filter','summarize','joinData','permissionTable','customColumn','sort','rowLimit']
|
|
@@ -58,6 +59,7 @@ export interface MetaBaseProps {
|
|
|
58
59
|
export interface SqlVisionBuilderRef {
|
|
59
60
|
setDatasource: (list: DatasourceType[]) => void; // 设置数据源列表
|
|
60
61
|
setPreData: (data: MetaListType[]) => void; // 设置回显数据
|
|
62
|
+
reset: () => void; // 重置到上次设置的数据
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
```
|
package/lib/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @gingkoo/pandora-metabase v0.0.1-alpha.
|
|
2
|
+
* @gingkoo/pandora-metabase v0.0.1-alpha.7
|
|
3
3
|
*/
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import * as React from 'react';
|
|
@@ -1901,6 +1901,11 @@ const sleep = (wait = 0) => {
|
|
|
1901
1901
|
const flatArray = arr => {
|
|
1902
1902
|
return [].concat.apply([], arr);
|
|
1903
1903
|
};
|
|
1904
|
+
const replaceTpl = (inputString, values) => {
|
|
1905
|
+
return inputString.replace(/\$\{([^}]*)\}/g, (match, variableName) => {
|
|
1906
|
+
return typeof values[variableName] !== 'undefined' ? String(values[variableName]) : match;
|
|
1907
|
+
});
|
|
1908
|
+
};
|
|
1904
1909
|
|
|
1905
1910
|
class WinResetEvent {
|
|
1906
1911
|
eventStack = {};
|
|
@@ -2164,10 +2169,11 @@ class SqlVisionStore {
|
|
|
2164
2169
|
constructor() {
|
|
2165
2170
|
makeAutoObservable(this);
|
|
2166
2171
|
}
|
|
2167
|
-
showPermissionTable = false; // 开启权限表
|
|
2168
2172
|
showFields = true; // 开启权限表
|
|
2169
2173
|
//工具列表
|
|
2170
2174
|
toolbar = ['filter', 'summarize', 'joinData', 'permissionTable', 'customColumn', 'sort', 'rowLimit'];
|
|
2175
|
+
fieldNameTpl = '${name}';
|
|
2176
|
+
tableNameTpl = '${name}';
|
|
2171
2177
|
sourceList = []; // 数据源列表
|
|
2172
2178
|
_cacheSource2TableMap = {}; // 数据源id 对应数据集列表
|
|
2173
2179
|
_cacheColumnsMap = {};
|
|
@@ -2196,6 +2202,9 @@ class SqlVisionStore {
|
|
|
2196
2202
|
}
|
|
2197
2203
|
return false;
|
|
2198
2204
|
}
|
|
2205
|
+
showToolbar(name) {
|
|
2206
|
+
return !!~this.toolbar.indexOf(name);
|
|
2207
|
+
}
|
|
2199
2208
|
fetchDatasetFn = async () => {};
|
|
2200
2209
|
fetchColumnsFn = async () => {};
|
|
2201
2210
|
setFetchDatasetFn(fn) {
|
|
@@ -2228,8 +2237,50 @@ class SqlVisionStore {
|
|
|
2228
2237
|
// 回显
|
|
2229
2238
|
async setPreData(data) {
|
|
2230
2239
|
if (data.length) {
|
|
2231
|
-
this.metaList = data
|
|
2240
|
+
this.metaList = data.map((v, i) => {
|
|
2241
|
+
// 设置右侧column
|
|
2242
|
+
if (v.table2?.datasourceId && v.columns.length < 1) {
|
|
2243
|
+
// let newMetaList = this.metaList.slice() as MetaData[];
|
|
2244
|
+
let newMeta = data.slice();
|
|
2245
|
+
let tableName = newMeta[i].table2.name;
|
|
2246
|
+
this.fetchColumns(tableName, newMeta[i].table2.datasourceId, columns => {
|
|
2247
|
+
newMeta[i].columns = columns;
|
|
2248
|
+
this.setMeta(newMeta);
|
|
2249
|
+
});
|
|
2250
|
+
return {
|
|
2251
|
+
...v
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
// 设置column
|
|
2255
|
+
if (v.table?.datasourceId && v.columns.length < 1) {
|
|
2256
|
+
// let newMetaList = this.metaList.slice() as MetaData[];
|
|
2257
|
+
let newMeta = data.slice();
|
|
2258
|
+
let tableName = newMeta[i].table.name;
|
|
2259
|
+
this.fetchColumns(tableName, newMeta[i].table.datasourceId, columns => {
|
|
2260
|
+
newMeta[i].columns = columns;
|
|
2261
|
+
this.setMeta(newMeta);
|
|
2262
|
+
});
|
|
2263
|
+
return {
|
|
2264
|
+
...v
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
return {
|
|
2268
|
+
...v
|
|
2269
|
+
};
|
|
2270
|
+
});
|
|
2232
2271
|
metaKey = Math.max.apply(null, this.metaList.map(v => Number(v.metaKey)));
|
|
2272
|
+
} else {
|
|
2273
|
+
this.setMeta([{
|
|
2274
|
+
metaKey,
|
|
2275
|
+
type: TypeEnum.data,
|
|
2276
|
+
table: {
|
|
2277
|
+
name: '',
|
|
2278
|
+
alias: '',
|
|
2279
|
+
datasourceId: '',
|
|
2280
|
+
datasourceName: ''
|
|
2281
|
+
},
|
|
2282
|
+
columns: []
|
|
2283
|
+
}]);
|
|
2233
2284
|
}
|
|
2234
2285
|
}
|
|
2235
2286
|
setSourceList(list) {
|
|
@@ -2250,6 +2301,7 @@ class SqlVisionStore {
|
|
|
2250
2301
|
};
|
|
2251
2302
|
if (index === 1) {
|
|
2252
2303
|
table1 = {
|
|
2304
|
+
...mainTable.table,
|
|
2253
2305
|
name: mainTable.table.name,
|
|
2254
2306
|
alias: mainTable.table.alias,
|
|
2255
2307
|
datasourceId: mainTable.table.datasourceId,
|
|
@@ -2364,15 +2416,18 @@ class SqlVisionStore {
|
|
|
2364
2416
|
setClosable(payload) {
|
|
2365
2417
|
this.popupClosable = payload;
|
|
2366
2418
|
}
|
|
2367
|
-
setShowPermissionTable(show) {
|
|
2368
|
-
this.showPermissionTable = show;
|
|
2369
|
-
}
|
|
2370
2419
|
setShowFields(show) {
|
|
2371
2420
|
this.showFields = show;
|
|
2372
2421
|
}
|
|
2373
2422
|
setToolbar(toolbar) {
|
|
2374
2423
|
this.toolbar = toolbar;
|
|
2375
2424
|
}
|
|
2425
|
+
setFieldNameTpl(tpl) {
|
|
2426
|
+
this.fieldNameTpl = tpl;
|
|
2427
|
+
}
|
|
2428
|
+
setTableNameTpl(tpl) {
|
|
2429
|
+
this.tableNameTpl = tpl;
|
|
2430
|
+
}
|
|
2376
2431
|
}
|
|
2377
2432
|
const sqlVisionStore = new SqlVisionStore();
|
|
2378
2433
|
const Store = /*#__PURE__*/React__default.createContext(sqlVisionStore);
|
|
@@ -3134,7 +3189,7 @@ const SelectJoinColumn = ({
|
|
|
3134
3189
|
onGroup,
|
|
3135
3190
|
didUpdate
|
|
3136
3191
|
}) => {
|
|
3137
|
-
useStore();
|
|
3192
|
+
const store = useStore();
|
|
3138
3193
|
const [curTable, setCurTable] = useState(value.alias); // 当前选择的表
|
|
3139
3194
|
const [curColumn, setCurColumn] = useState(value.name); // 当前选择的字段
|
|
3140
3195
|
const [tableList, setTableList] = useState(_data.map((v, i) => {
|
|
@@ -3268,6 +3323,7 @@ const SelectJoinColumn = ({
|
|
|
3268
3323
|
let condition = '';
|
|
3269
3324
|
let quotes = name;
|
|
3270
3325
|
return onGroup({
|
|
3326
|
+
...v,
|
|
3271
3327
|
table,
|
|
3272
3328
|
alias: tableAlias,
|
|
3273
3329
|
name,
|
|
@@ -3278,6 +3334,7 @@ const SelectJoinColumn = ({
|
|
|
3278
3334
|
});
|
|
3279
3335
|
}
|
|
3280
3336
|
typeof onSelect === 'function' && onSelect({
|
|
3337
|
+
...v,
|
|
3281
3338
|
table,
|
|
3282
3339
|
alias: tableAlias,
|
|
3283
3340
|
name,
|
|
@@ -3296,7 +3353,7 @@ const SelectJoinColumn = ({
|
|
|
3296
3353
|
}), jsx("div", {
|
|
3297
3354
|
children: jsx("h4", {
|
|
3298
3355
|
className: 'List-item-title ml-2',
|
|
3299
|
-
children:
|
|
3356
|
+
children: replaceTpl(store.fieldNameTpl, v)
|
|
3300
3357
|
})
|
|
3301
3358
|
})]
|
|
3302
3359
|
}), OPEN_GROUP]
|
|
@@ -4167,7 +4224,7 @@ const SelectTable = ({
|
|
|
4167
4224
|
}), jsx("div", {
|
|
4168
4225
|
children: jsx("h4", {
|
|
4169
4226
|
className: 'List-item-title ml-2',
|
|
4170
|
-
children: v
|
|
4227
|
+
children: replaceTpl(store.tableNameTpl, v)
|
|
4171
4228
|
})
|
|
4172
4229
|
})]
|
|
4173
4230
|
})
|
|
@@ -4388,11 +4445,10 @@ const metaIcon = (size, handleClick) => {
|
|
|
4388
4445
|
3)特殊情况二 如果最后一个是排序,下面是small
|
|
4389
4446
|
*/
|
|
4390
4447
|
// 判断icon大小
|
|
4391
|
-
const judgeSize = (props, nextLen) => {
|
|
4448
|
+
const judgeSize = (store, props, nextLen) => {
|
|
4392
4449
|
let {
|
|
4393
4450
|
meta
|
|
4394
4451
|
} = props;
|
|
4395
|
-
const store = useStore();
|
|
4396
4452
|
let {
|
|
4397
4453
|
type
|
|
4398
4454
|
} = meta;
|
|
@@ -4416,11 +4472,10 @@ const judgeSize = (props, nextLen) => {
|
|
|
4416
4472
|
/**
|
|
4417
4473
|
* 查找模块下面能放哪些icon (参考来源:metabase.com)
|
|
4418
4474
|
*/
|
|
4419
|
-
const findNextIcon = props => {
|
|
4475
|
+
const findNextIcon = (store, props) => {
|
|
4420
4476
|
const {
|
|
4421
4477
|
meta
|
|
4422
4478
|
} = props;
|
|
4423
|
-
const store = useStore();
|
|
4424
4479
|
let {
|
|
4425
4480
|
type
|
|
4426
4481
|
} = meta;
|
|
@@ -4588,11 +4643,11 @@ const NextDom = props => {
|
|
|
4588
4643
|
const store = useStore();
|
|
4589
4644
|
// @ts-ignore
|
|
4590
4645
|
if (!store.metaList[0].table.name) return null;
|
|
4591
|
-
let available = findNextIcon(props);
|
|
4592
|
-
if (!store.
|
|
4646
|
+
let available = findNextIcon(store, props);
|
|
4647
|
+
if (!store.showToolbar(TypeEnum.permissionTable)) {
|
|
4593
4648
|
available = available.filter(v => v !== TypeEnum.permissionTable);
|
|
4594
4649
|
}
|
|
4595
|
-
let size = judgeSize(props, available.length);
|
|
4650
|
+
let size = judgeSize(store, props, available.length);
|
|
4596
4651
|
function handleClick(type) {
|
|
4597
4652
|
let index = store.metaList.indexOf(meta);
|
|
4598
4653
|
store.addMeta(type, index + 1);
|
|
@@ -4777,6 +4832,7 @@ const JoinData = props => {
|
|
|
4777
4832
|
}
|
|
4778
4833
|
}
|
|
4779
4834
|
newMeta[index].table2 = {
|
|
4835
|
+
...data,
|
|
4780
4836
|
name: tableName,
|
|
4781
4837
|
alias,
|
|
4782
4838
|
column: '',
|
|
@@ -4842,6 +4898,7 @@ const JoinData = props => {
|
|
|
4842
4898
|
if (prevGroupBy?.group?.length) {
|
|
4843
4899
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
4844
4900
|
return {
|
|
4901
|
+
...v,
|
|
4845
4902
|
name: v.quotes,
|
|
4846
4903
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
4847
4904
|
special_type: '',
|
|
@@ -4853,6 +4910,7 @@ const JoinData = props => {
|
|
|
4853
4910
|
if (prevGroupBy?.by?.length) {
|
|
4854
4911
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
4855
4912
|
return {
|
|
4913
|
+
...v,
|
|
4856
4914
|
name: v.quotes,
|
|
4857
4915
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
4858
4916
|
special_type: '',
|
|
@@ -5182,8 +5240,10 @@ const Filter = props => {
|
|
|
5182
5240
|
if (prevGroupBy?.group?.length) {
|
|
5183
5241
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
5184
5242
|
return {
|
|
5243
|
+
name_zh: v.quotes,
|
|
5244
|
+
...v,
|
|
5185
5245
|
name: v.quotes,
|
|
5186
|
-
name_zh: '',
|
|
5246
|
+
// name_zh: '',
|
|
5187
5247
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5188
5248
|
sql: v.sql,
|
|
5189
5249
|
special_type: '',
|
|
@@ -5194,8 +5254,10 @@ const Filter = props => {
|
|
|
5194
5254
|
if (prevGroupBy?.by?.length) {
|
|
5195
5255
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
5196
5256
|
return {
|
|
5257
|
+
name_zh: v.quotes,
|
|
5258
|
+
...v,
|
|
5197
5259
|
name: v.quotes,
|
|
5198
|
-
name_zh: '',
|
|
5260
|
+
// name_zh: '',
|
|
5199
5261
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5200
5262
|
sql: v.sql,
|
|
5201
5263
|
special_type: '',
|
|
@@ -5373,9 +5435,11 @@ const GroupBy = props => {
|
|
|
5373
5435
|
if (prevGroupBy?.group?.length) {
|
|
5374
5436
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
5375
5437
|
return {
|
|
5438
|
+
name_zh: v.quotes,
|
|
5439
|
+
...v,
|
|
5376
5440
|
name: v.quotes,
|
|
5377
5441
|
realName: v.sql?.split(' AS ')?.[1] || '',
|
|
5378
|
-
name_zh: '',
|
|
5442
|
+
// name_zh: '',
|
|
5379
5443
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5380
5444
|
special_type: '',
|
|
5381
5445
|
select: true
|
|
@@ -5385,9 +5449,11 @@ const GroupBy = props => {
|
|
|
5385
5449
|
if (prevGroupBy?.by?.length) {
|
|
5386
5450
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
5387
5451
|
return {
|
|
5452
|
+
name_zh: v.quotes,
|
|
5453
|
+
...v,
|
|
5388
5454
|
name: v.quotes,
|
|
5389
5455
|
realName: v.sql?.split(' AS ')?.[1] || '',
|
|
5390
|
-
name_zh: '',
|
|
5456
|
+
// name_zh: '',
|
|
5391
5457
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5392
5458
|
special_type: '',
|
|
5393
5459
|
select: true
|
|
@@ -5447,6 +5513,7 @@ const GroupBy = props => {
|
|
|
5447
5513
|
isGroup: true,
|
|
5448
5514
|
// @ts-ignore
|
|
5449
5515
|
onGroup: data => {
|
|
5516
|
+
console.log('🚀 ~ handleUpdate ~ data:', data);
|
|
5450
5517
|
// @ts-ignore
|
|
5451
5518
|
newMeta[index].by.splice(i, 1, data);
|
|
5452
5519
|
// @ts-ignore
|
|
@@ -5487,6 +5554,7 @@ const GroupBy = props => {
|
|
|
5487
5554
|
isGroup: true,
|
|
5488
5555
|
// @ts-ignore
|
|
5489
5556
|
onGroup: data => {
|
|
5557
|
+
console.log('🚀 ~ handleAdd ~ data:', data);
|
|
5490
5558
|
// @ts-ignore
|
|
5491
5559
|
newMeta[index].by.push(data);
|
|
5492
5560
|
// @ts-ignore
|
|
@@ -5982,9 +6050,11 @@ const SelectIndex = props => {
|
|
|
5982
6050
|
if (prevGroupBy?.group?.length) {
|
|
5983
6051
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
5984
6052
|
return {
|
|
6053
|
+
name_zh: v.quotes,
|
|
6054
|
+
...v,
|
|
5985
6055
|
name: v.quotes,
|
|
5986
6056
|
realName: v.sql?.split(' AS ')?.[1] || '',
|
|
5987
|
-
name_zh: '',
|
|
6057
|
+
// name_zh: '',
|
|
5988
6058
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5989
6059
|
special_type: '',
|
|
5990
6060
|
select: true
|
|
@@ -5994,9 +6064,11 @@ const SelectIndex = props => {
|
|
|
5994
6064
|
if (prevGroupBy?.by?.length) {
|
|
5995
6065
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
5996
6066
|
return {
|
|
6067
|
+
name_zh: v.quotes,
|
|
6068
|
+
...v,
|
|
5997
6069
|
name: v.quotes,
|
|
5998
6070
|
realName: v.sql?.split(' AS ')?.[1] || '',
|
|
5999
|
-
name_zh: '',
|
|
6071
|
+
// name_zh: '',
|
|
6000
6072
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
6001
6073
|
special_type: '',
|
|
6002
6074
|
select: true
|
|
@@ -6214,8 +6286,10 @@ const Sort = props => {
|
|
|
6214
6286
|
if (prevGroupBy?.group?.length) {
|
|
6215
6287
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
6216
6288
|
return {
|
|
6289
|
+
name_zh: v.quotes,
|
|
6290
|
+
...v,
|
|
6217
6291
|
name: v.quotes,
|
|
6218
|
-
name_zh: '',
|
|
6292
|
+
// name_zh: '',
|
|
6219
6293
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
6220
6294
|
special_type: '',
|
|
6221
6295
|
sql: v.sql,
|
|
@@ -6226,8 +6300,10 @@ const Sort = props => {
|
|
|
6226
6300
|
if (prevGroupBy?.by?.length) {
|
|
6227
6301
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
6228
6302
|
return {
|
|
6303
|
+
name_zh: v.quotes,
|
|
6304
|
+
...v,
|
|
6229
6305
|
name: v.quotes,
|
|
6230
|
-
name_zh: '',
|
|
6306
|
+
// name_zh: '',
|
|
6231
6307
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
6232
6308
|
special_type: '',
|
|
6233
6309
|
sql: v.sql,
|
|
@@ -6631,28 +6707,35 @@ const Metabase = observer(props => {
|
|
|
6631
6707
|
const SqlVisionBuilder = /*#__PURE__*/React__default.forwardRef((props, ref) => {
|
|
6632
6708
|
let {
|
|
6633
6709
|
loading = false,
|
|
6634
|
-
showPermissionTable = false,
|
|
6635
6710
|
showFields = true,
|
|
6636
6711
|
getTables,
|
|
6637
6712
|
getColumns,
|
|
6713
|
+
tableNameTpl = '${name}',
|
|
6714
|
+
fieldNameTpl = '${name}',
|
|
6638
6715
|
toolbar = ['filter', 'summarize', 'joinData', 'permissionTable', 'customColumn', 'sort', 'rowLimit']
|
|
6639
6716
|
} = props;
|
|
6640
6717
|
const store = useStore();
|
|
6718
|
+
const [preData, setPreData] = useState([]);
|
|
6641
6719
|
useEffect(() => {
|
|
6642
6720
|
getTables && store.setFetchDatasetFn(getTables);
|
|
6643
6721
|
getColumns && store.setFetchColumnsFn(getColumns);
|
|
6644
6722
|
}, []);
|
|
6645
6723
|
useEffect(() => {
|
|
6646
|
-
store.setShowPermissionTable(showPermissionTable);
|
|
6647
6724
|
store.setShowFields(showFields);
|
|
6648
6725
|
store.setToolbar(toolbar || []);
|
|
6649
|
-
|
|
6726
|
+
store.setFieldNameTpl(fieldNameTpl || '${name}');
|
|
6727
|
+
store.setTableNameTpl(tableNameTpl || '${name}');
|
|
6728
|
+
}, [showFields, toolbar, fieldNameTpl, tableNameTpl]);
|
|
6650
6729
|
React__default.useImperativeHandle(ref, () => ({
|
|
6651
6730
|
setDatasource: list => {
|
|
6652
6731
|
store.setSourceList(list);
|
|
6653
6732
|
},
|
|
6654
6733
|
setPreData: data => {
|
|
6655
6734
|
store.setPreData(data);
|
|
6735
|
+
setPreData(data);
|
|
6736
|
+
},
|
|
6737
|
+
reset: () => {
|
|
6738
|
+
store.setPreData(preData);
|
|
6656
6739
|
}
|
|
6657
6740
|
}));
|
|
6658
6741
|
// ② 表集合没有查出来前 不加载页面
|