@gingkoo/pandora-metabase 0.0.1-alpha.5 → 0.0.1-alpha.6

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