@gingkoo/pandora-metabase 1.0.20 → 1.0.22

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.
@@ -54,6 +54,7 @@ var Metabase = function Metabase(props) {
54
54
  case 0:
55
55
  intercept = false; // 是否返回
56
56
  _metaList = splitByUnion(store.metaList);
57
+ _metaList[0].patchVersion = '1.0.0';
57
58
  store.metaList.map(function (v) {
58
59
  var _v$list;
59
60
  if (v.type !== 'union' && !((_v$list = v.list) === null || _v$list === void 0 ? void 0 : _v$list[0]).table.name) {
@@ -118,6 +118,9 @@ var CustomColumn = function CustomColumn(props) {
118
118
  var _prevGroupBy$group, _prevGroupBy$by;
119
119
  var _data = {
120
120
  table: prevGroupBy.alias,
121
+ name: prevGroupBy.alias,
122
+ name_zh: prevGroupBy.alias,
123
+ id: prevGroupBy.alias,
121
124
  tableId: prevGroupBy.alias,
122
125
  tableUuid: prevGroupBy.tableUuid || uuidv4('table'),
123
126
  alias: prevGroupBy.alias,
@@ -163,7 +166,7 @@ var CustomColumn = function CustomColumn(props) {
163
166
  data = data.concat(
164
167
  // @ts-ignore
165
168
  joinData.map(function (v) {
166
- return {
169
+ return _objectSpread(_objectSpread({}, v.table2), {}, {
167
170
  alias: v.table2.alias,
168
171
  table: v.table2.name,
169
172
  tableId: v.table2.id,
@@ -171,14 +174,14 @@ var CustomColumn = function CustomColumn(props) {
171
174
  columns: v.columns,
172
175
  datasourceId: mainTable.table.datasourceId,
173
176
  datasourceName: mainTable.table.datasourceName
174
- };
177
+ });
175
178
  }));
176
179
  }
177
180
  } else {
178
181
  // @ts-ignore
179
182
  data = store.metaList[groupIndex].list.slice(0, index).map(function (v) {
180
183
  if (v.type === TypeEnum.data) {
181
- return {
184
+ return _objectSpread(_objectSpread({}, v.table), {}, {
182
185
  alias: v.table.alias,
183
186
  table: v.table.name,
184
187
  tableId: v.table.id,
@@ -186,9 +189,9 @@ var CustomColumn = function CustomColumn(props) {
186
189
  columns: v.columns,
187
190
  datasourceId: mainTable.table.datasourceId,
188
191
  datasourceName: mainTable.table.datasourceName
189
- };
192
+ });
190
193
  } else if (v.type === TypeEnum.joinData) {
191
- return {
194
+ return _objectSpread(_objectSpread({}, v.table2), {}, {
192
195
  alias: v.table2.alias,
193
196
  table: v.table2.name,
194
197
  tableId: v.table2.id,
@@ -196,7 +199,7 @@ var CustomColumn = function CustomColumn(props) {
196
199
  columns: v.columns,
197
200
  datasourceId: mainTable.table.datasourceId,
198
201
  datasourceName: mainTable.table.datasourceName
199
- };
202
+ });
200
203
  } else {
201
204
  return {
202
205
  table: null
@@ -67,7 +67,7 @@ var JoinData = function JoinData(props) {
67
67
  var table1Selected = Boolean(meta.table1.name);
68
68
  var table2Selected = Boolean(meta.table2.name);
69
69
  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);
70
- var columnsSelected = meta.table1.id && meta.table2.id;
70
+ var columnsSelected = meta.table1.name && meta.table2.name;
71
71
  // useEffect(() => {
72
72
  // let newMetaList = store.metaList[groupIndex].list.slice();
73
73
  // newMetaList[index] = setQuotes(meta);
@@ -80,6 +80,7 @@ var JoinData = function JoinData(props) {
80
80
  ExistAboveGroupBy = _getHelper.ExistAboveGroupBy,
81
81
  prevList = _getHelper.prevList,
82
82
  prevGroupBy = _getHelper.prevGroupBy;
83
+ // 获取左侧表
83
84
  if (ExistAboveGroupBy) {
84
85
  var _prevGroupBy$group, _prevGroupBy$by;
85
86
  var _data = {
@@ -141,7 +142,7 @@ var JoinData = function JoinData(props) {
141
142
  } else {
142
143
  data = store.metaList[groupIndex].list.slice(0, index + 1).reduce(function (mo, v) {
143
144
  if (v.type === TypeEnum.data) {
144
- mo.push({
145
+ mo.push(_objectSpread(_objectSpread({}, v.table), {}, {
145
146
  alias: v.table.alias,
146
147
  name: v.table.name,
147
148
  name_zh: v.table.name_zh,
@@ -150,7 +151,7 @@ var JoinData = function JoinData(props) {
150
151
  columns: v.columns,
151
152
  datasourceId: v.table.datasourceId,
152
153
  datasourceName: v.table.datasourceName
153
- });
154
+ }));
154
155
  } else if (v.type === TypeEnum.joinData) {
155
156
  mo.push({
156
157
  alias: v.table2.alias,
@@ -164,9 +165,12 @@ var JoinData = function JoinData(props) {
164
165
  });
165
166
  }
166
167
  return mo;
167
- }, []);
168
+ }, []).filter(function (v) {
169
+ return v.tableUuid === meta.table1.tableUuid;
170
+ });
168
171
  }
169
- // 添加当前表
172
+ // 获取右侧表
173
+ // 添加table2
170
174
  data = data.concat([{
171
175
  alias: meta.table2.alias,
172
176
  name: meta.table2.name,
@@ -383,71 +387,77 @@ var JoinData = function JoinData(props) {
383
387
  })
384
388
  });
385
389
  }
390
+ // 切换表后重置数据
386
391
  function initExpressions() {
387
- var _newMeta$index, _newMeta$index2;
392
+ console.log(11);
388
393
  var newMeta = store.metaList[groupIndex].list.slice();
389
- if (newMeta[index].table1.name && newMeta[index].table2.name && !((_newMeta$index = newMeta[index]) !== null && _newMeta$index !== void 0 && _newMeta$index.expressions) || ((_newMeta$index2 = newMeta[index]) === null || _newMeta$index2 === void 0 || (_newMeta$index2 = _newMeta$index2.expressions) === null || _newMeta$index2 === void 0 ? void 0 : _newMeta$index2.length) < 1) {
390
- newMeta[index].expressions = [{
391
- lhs: [{
392
- fieldName: '',
393
- // 字段名
394
- fieldNameZh: '',
395
- // 字段中文名
396
- fieldAlias: '',
397
- // 别名
398
- fieldUuid: '',
399
- // uuid
400
- fieldId: '',
401
- // 字段id
402
- // quotes?: string; // 字段展示的 不知道有没有用
403
- tableName: '',
404
- // 表名
405
- tableNameZh: '',
406
- tableId: '',
407
- // 表名
408
- tableAlias: '',
409
- // 别名
410
- tableUuid: '',
411
- // 表唯一标识
412
- datasourceName: '',
413
- // 数据源名
414
- datasourceId: '',
415
- // 数据源id
416
- type: AtomsTypeEnum.FIELD
417
- }],
418
- condition: '',
419
- rhs: [{
420
- fieldName: '',
421
- // 字段名
422
- fieldNameZh: '',
423
- // 字段中文名
424
- fieldAlias: '',
425
- // 别名
426
- fieldUuid: '',
427
- // uuid
428
- fieldId: '',
429
- // 字段id
430
- // quotes?: string; // 字段展示的 不知道有没有用
431
- tableName: '',
432
- // 表名
433
- tableNameZh: '',
434
- tableId: '',
435
- // 表名
436
- tableAlias: '',
437
- // 别名
438
- tableUuid: '',
439
- // 表唯一标识
440
- datasourceName: '',
441
- // 数据源名
442
- datasourceId: '',
443
- // 数据源id
444
- type: AtomsTypeEnum.FIELD
445
- }],
446
- // quotes: '',
447
- type: AtomsTypeEnum.JOIN_DEFAULT
448
- }];
449
- store.setMeta(newMeta, groupIndex);
450
- }
394
+ newMeta[index].expressions = [{
395
+ lhs: [{
396
+ fieldName: '',
397
+ // 字段名
398
+ fieldNameZh: '',
399
+ // 字段中文名
400
+ fieldAlias: '',
401
+ // 别名
402
+ fieldUuid: '',
403
+ // uuid
404
+ fieldId: '',
405
+ // 字段id
406
+ // quotes?: string; // 字段展示的 不知道有没有用
407
+ tableName: '',
408
+ // 表名
409
+ tableNameZh: '',
410
+ tableId: '',
411
+ // 表名
412
+ tableAlias: '',
413
+ // 别名
414
+ tableUuid: '',
415
+ // 表唯一标识
416
+ datasourceName: '',
417
+ // 数据源名
418
+ datasourceId: '',
419
+ // 数据源id
420
+ type: AtomsTypeEnum.FIELD
421
+ }],
422
+ condition: '',
423
+ rhs: [{
424
+ fieldName: '',
425
+ // 字段名
426
+ fieldNameZh: '',
427
+ // 字段中文名
428
+ fieldAlias: '',
429
+ // 别名
430
+ fieldUuid: '',
431
+ // uuid
432
+ fieldId: '',
433
+ // 字段id
434
+ // quotes?: string; // 字段展示的 不知道有没有用
435
+ tableName: '',
436
+ // 表名
437
+ tableNameZh: '',
438
+ tableId: '',
439
+ // 表名
440
+ tableAlias: '',
441
+ // 别名
442
+ tableUuid: '',
443
+ // 表唯一标识
444
+ datasourceName: '',
445
+ // 数据源名
446
+ datasourceId: '',
447
+ // 数据源id
448
+ type: AtomsTypeEnum.FIELD
449
+ }],
450
+ // quotes: '',
451
+ type: AtomsTypeEnum.JOIN_DEFAULT
452
+ }];
453
+ store.setMeta(newMeta, groupIndex);
454
+ // if (
455
+ // ((newMeta[index] as MetaJoin).table1.name &&
456
+ // (newMeta[index] as MetaJoin).table2.name &&
457
+ // !(newMeta[index] as MetaJoin)?.expressions) ||
458
+ // (newMeta[index] as MetaJoin)?.expressions?.length < 1
459
+ // ) {
460
+ // }
451
461
  }
452
462
  function selectJoin(e) {
453
463
  var newMeta = store.metaList[groupIndex].list.slice();
@@ -107,7 +107,7 @@ var Sort = function Sort(props) {
107
107
  newMeta[index].sort.forEach(function (v) {
108
108
  v.expression.forEach(function (vv) {
109
109
  if (vv.type === AtomsTypeEnum.FIELD) {
110
- if (selectedSort[vv.fieldName]) {
110
+ if (selectedSort[vv.tableName]) {
111
111
  selectedSort[vv.tableAlias].push(vv.fieldName);
112
112
  } else {
113
113
  selectedSort[vv.tableAlias] = [vv.fieldName];
@@ -1,5 +1,7 @@
1
+ import { MetaListType } from '../store/types';
1
2
  export declare const dataPatch: (newMeta: any) => any;
2
3
  export declare const joinDataPatch: (newMeta: any) => any;
3
4
  export declare const filterPatch: (newMeta: any) => any;
4
5
  export declare const customColumnPatch: (newMeta: any) => any;
5
6
  export declare const sortPatch: (newMeta: any) => any;
7
+ export declare const patchMetas: (items: MetaListType[]) => MetaListType[];
@@ -1,5 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { uuidv4 } from '../utils/helper';
3
+ import { buildSqlQuery } from '../utils';
3
4
  import { AtomsTypeEnum } from '../store/types';
4
5
  import { TypeEnum } from '../store/enum';
5
6
  export var dataPatch = function dataPatch(newMeta) {
@@ -10,16 +11,25 @@ export var dataPatch = function dataPatch(newMeta) {
10
11
  return newMeta;
11
12
  }
12
13
  }
13
- newMeta.subquery = renderExists(newMeta.subquery);
14
+ newMeta.subquery = _patchMetas(newMeta.subquery);
14
15
  return newMeta;
15
16
  };
16
17
  export var joinDataPatch = function joinDataPatch(newMeta) {
17
- var _newMeta$expressions2, _fields, _fields2, _fields3, _fields4, _newMeta$expressions3, _expressions2;
18
+ var _newMeta$expressions2, _fields, _fields2, _fields3, _fields4, _newMeta$expressions3;
18
19
  var item = ((_newMeta$expressions2 = newMeta.expressions) === null || _newMeta$expressions2 === void 0 ? void 0 : _newMeta$expressions2[0]) || {};
19
20
  if (item !== null && item !== void 0 && item.type && Object.values(AtomsTypeEnum).includes(item.type)) {
20
21
  if ((item.type === AtomsTypeEnum.EXPRESSION || item.type === AtomsTypeEnum.JOIN_DEFAULT) && item.lhs) {
21
22
  return newMeta;
22
23
  }
24
+ if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
25
+ return newMeta;
26
+ }
27
+ if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
28
+ return newMeta;
29
+ }
30
+ if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
31
+ return newMeta;
32
+ }
23
33
  }
24
34
  // if (
25
35
  // newMeta.expressions?.[0]?.type &&
@@ -110,7 +120,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
110
120
  type: 'default' // 默认是字段模式
111
121
  }];
112
122
  }
113
- var expressions = (_newMeta$expressions3 = newMeta.expressions) === null || _newMeta$expressions3 === void 0 ? void 0 : _newMeta$expressions3.map(function (v) {
123
+ var expressions = ((_newMeta$expressions3 = newMeta.expressions) === null || _newMeta$expressions3 === void 0 ? void 0 : _newMeta$expressions3.map(function (v) {
114
124
  var _left_fields, _right_fields;
115
125
  var left_fields = v.left_fields || [];
116
126
  var right_fields = v.right_fields || [];
@@ -161,9 +171,10 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
161
171
  right_type: v.right_type || '',
162
172
  type: v.type || 'default' // 默认是字段模式
163
173
  };
164
- });
174
+ })) || [];
165
175
  var _expressions = beforeExpressions.concat(expressions);
166
- _expressions = (_expressions2 = _expressions) === null || _expressions2 === void 0 ? void 0 : _expressions2.map(function (v) {
176
+ var newExpressions = [];
177
+ _expressions === null || _expressions === void 0 || _expressions.map(function (v, i) {
167
178
  var lhs = [];
168
179
  var rhs = [];
169
180
  if (v.left_type === 'string') {
@@ -179,9 +190,9 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
179
190
  } else {
180
191
  var _v$left_fields;
181
192
  lhs = (_v$left_fields = v.left_fields) === null || _v$left_fields === void 0 ? void 0 : _v$left_fields.map(function (vv) {
182
- return _objectSpread(_objectSpread({}, vv), {}, {
193
+ return _objectSpread({
183
194
  fieldNameZh: newMeta.table1.name_zh,
184
- fieldName: newMeta.table1.fieldName || newMeta.table1.name,
195
+ fieldName: vv.fieldName || vv.quotes || vv.fieldAlias || newMeta.table1.fieldName || newMeta.table1.name,
185
196
  tableAlias: newMeta.table1.alias,
186
197
  tableId: newMeta.table1.id,
187
198
  tableName: newMeta.table1.name,
@@ -192,7 +203,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
192
203
  datasourceId: newMeta.table1.datasourceId,
193
204
  // 数据源id
194
205
  type: AtomsTypeEnum.FIELD
195
- });
206
+ }, vv);
196
207
  });
197
208
  }
198
209
  if (v.right_type === 'string') {
@@ -208,9 +219,9 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
208
219
  } else {
209
220
  var _v$right_fields;
210
221
  rhs = (_v$right_fields = v.right_fields) === null || _v$right_fields === void 0 ? void 0 : _v$right_fields.map(function (vv) {
211
- return _objectSpread(_objectSpread({}, vv), {}, {
222
+ return _objectSpread({
212
223
  fieldNameZh: newMeta.table2.name_zh,
213
- fieldName: newMeta.table2.fieldName || newMeta.table2.name,
224
+ fieldName: vv.fieldName || vv.quotes || vv.fieldAlias || newMeta.table2.fieldName || newMeta.table2.name,
214
225
  tableAlias: newMeta.table2.alias,
215
226
  tableId: newMeta.table2.id,
216
227
  tableName: newMeta.table2.name,
@@ -221,7 +232,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
221
232
  datasourceId: newMeta.table2.datasourceId,
222
233
  // 数据源id
223
234
  type: AtomsTypeEnum.FIELD
224
- });
235
+ }, vv);
225
236
  });
226
237
  }
227
238
  var item = {
@@ -232,14 +243,21 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
232
243
  // quotes: '',
233
244
  type: AtomsTypeEnum.JOIN_DEFAULT
234
245
  };
246
+ newExpressions.push(item);
247
+ if (_expressions.length - 1 > i) {
248
+ newExpressions.push({
249
+ val: 'AND',
250
+ type: AtomsTypeEnum.OPERATOR
251
+ });
252
+ }
235
253
  return item;
236
254
  });
237
255
  // 清除table1中不用字段
238
256
  delete newMeta.table1.fields;
239
257
  // 清除table2中不用字段
240
258
  delete newMeta.table2.fields;
241
- newMeta.subquery = renderExists(newMeta.subquery);
242
- newMeta.expressions = _expressions;
259
+ newMeta.subquery = _patchMetas(newMeta.subquery);
260
+ newMeta.expressions = newExpressions;
243
261
  return newMeta;
244
262
  };
245
263
  export var filterPatch = function filterPatch(newMeta) {
@@ -255,6 +273,9 @@ export var filterPatch = function filterPatch(newMeta) {
255
273
  if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
256
274
  return newMeta;
257
275
  }
276
+ if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
277
+ return newMeta;
278
+ }
258
279
  }
259
280
  var _filter = (_newMeta$filter2 = newMeta.filter) === null || _newMeta$filter2 === void 0 ? void 0 : _newMeta$filter2.map(function (v) {
260
281
  // 表达式
@@ -262,7 +283,7 @@ export var filterPatch = function filterPatch(newMeta) {
262
283
  if (typeof v === 'string') {
263
284
  return {
264
285
  val: v,
265
- type: AtomsTypeEnum.INPUT_STRING
286
+ type: AtomsTypeEnum.OPERATOR
266
287
  };
267
288
  } else if (v.type === 'expression') {
268
289
  var rhs;
@@ -328,15 +349,17 @@ export var filterPatch = function filterPatch(newMeta) {
328
349
  };
329
350
  return tem;
330
351
  } else if (v.type === 'notExists') {
352
+ var notExists = _patchMetas(v.notExists);
331
353
  return {
332
- notExists: renderExists(v.notExists),
333
- quotes: v.quotes,
354
+ notExists: notExists,
355
+ quotes: buildSqlQuery(notExists, v.type),
334
356
  type: AtomsTypeEnum.NOT_EXISTS
335
357
  };
336
358
  } else if (v.type === 'exists') {
359
+ var _notExists = _patchMetas(v.notExists);
337
360
  return {
338
- notExists: renderExists(v.notExists),
339
- quotes: v.quotes,
361
+ notExists: _notExists,
362
+ quotes: buildSqlQuery(_notExists, v.type),
340
363
  type: AtomsTypeEnum.EXISTS
341
364
  };
342
365
  }
@@ -346,14 +369,23 @@ export var filterPatch = function filterPatch(newMeta) {
346
369
  return newMeta;
347
370
  };
348
371
  export var customColumnPatch = function customColumnPatch(newMeta) {
349
- var _newMeta$customColumn;
372
+ var _newMeta$customColumn, _newMeta$customColumn2;
350
373
  var item = ((_newMeta$customColumn = newMeta.customColumn[0].formulaList) === null || _newMeta$customColumn === void 0 ? void 0 : _newMeta$customColumn[0]) || {};
351
- if (item.type && Object.values(AtomsTypeEnum).includes(item.type || '')) {
374
+ if (item !== null && item !== void 0 && item.type && Object.values(AtomsTypeEnum).includes(item.type)) {
352
375
  if (item.type === AtomsTypeEnum.EXPRESSION && item.lhs) {
353
376
  return newMeta;
354
377
  }
378
+ if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
379
+ return newMeta;
380
+ }
381
+ if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
382
+ return newMeta;
383
+ }
384
+ if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
385
+ return newMeta;
386
+ }
355
387
  }
356
- newMeta.customColumn = newMeta.customColumn.map(function (v) {
388
+ newMeta.customColumn = (newMeta === null || newMeta === void 0 || (_newMeta$customColumn2 = newMeta.customColumn) === null || _newMeta$customColumn2 === void 0 ? void 0 : _newMeta$customColumn2.map(function (v) {
357
389
  var _formulaList = v.formulaList.map(function (formula) {
358
390
  var tem = formula;
359
391
  if (formula.type === 'expression') {
@@ -466,7 +498,7 @@ export var customColumnPatch = function customColumnPatch(newMeta) {
466
498
  return _objectSpread(_objectSpread({}, v), {}, {
467
499
  formulaList: _formulaList
468
500
  });
469
- });
501
+ })) || newMeta.customColumn;
470
502
  return newMeta;
471
503
  };
472
504
  export var sortPatch = function sortPatch(newMeta) {
@@ -476,6 +508,15 @@ export var sortPatch = function sortPatch(newMeta) {
476
508
  if (item.type === AtomsTypeEnum.EXPRESSION && item.lhs) {
477
509
  return newMeta;
478
510
  }
511
+ if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
512
+ return newMeta;
513
+ }
514
+ if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
515
+ return newMeta;
516
+ }
517
+ if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
518
+ return newMeta;
519
+ }
479
520
  }
480
521
  var _sort = (_newMeta$sort2 = newMeta.sort) === null || _newMeta$sort2 === void 0 ? void 0 : _newMeta$sort2.map(function (v) {
481
522
  return {
@@ -500,7 +541,7 @@ export var sortPatch = function sortPatch(newMeta) {
500
541
  newMeta.sort = _sort;
501
542
  return newMeta;
502
543
  };
503
- var renderExists = function renderExists(items) {
544
+ var _patchMetas = function patchMetas(items) {
504
545
  return (items === null || items === void 0 ? void 0 : items.map(function (v) {
505
546
  if (v.type === TypeEnum.joinData) {
506
547
  v = joinDataPatch(v);
@@ -514,6 +555,10 @@ var renderExists = function renderExists(items) {
514
555
  if (v.type === TypeEnum.customColumn) {
515
556
  v = customColumnPatch(v);
516
557
  }
558
+ if (v.type === TypeEnum.union) {
559
+ v.subquery = _patchMetas(v.subquery || []);
560
+ }
517
561
  return v;
518
562
  })) || [];
519
- };
563
+ };
564
+ export { _patchMetas as patchMetas };
@@ -9,7 +9,6 @@ import { useState, useRef, useMemo } from 'react';
9
9
  import { uuidv4 } from '../utils/helper';
10
10
  import { TypeEnum, JoinEnum, UnionEnum } from '../store/enum';
11
11
  import { getSubColumns } from '../utils';
12
- import { joinDataPatch, filterPatch, sortPatch, customColumnPatch, dataPatch } from './patch';
13
12
  var metaKey = 1;
14
13
  export var SummarizeAlias = 'source';
15
14
  var useStore = function useStore() {
@@ -252,6 +251,7 @@ var useStore = function useStore() {
252
251
  return newMeta;
253
252
  };
254
253
  var setPreData = function setPreData(data) {
254
+ // let patchVersion = (data?.[0]?.list?.[0] as any)?.patchVersion || '';
255
255
  if (data.length) {
256
256
  var _metaList = data === null || data === void 0 ? void 0 : data.map(function (item, groupIndex) {
257
257
  var _item$list;
@@ -261,21 +261,24 @@ var useStore = function useStore() {
261
261
  if (v.table) {
262
262
  v.table.tableUuid = v.table.tableUuid || uuidv4('table');
263
263
  }
264
- if (v.type === TypeEnum.joinData) {
265
- newMeta[i] = joinDataPatch(newMeta[i]);
266
- }
267
- if (v.type === TypeEnum.filter) {
268
- v = filterPatch(v);
269
- }
270
- if (v.type === TypeEnum.sort) {
271
- newMeta[i] = sortPatch(newMeta[i]);
272
- }
273
- if (v.type === TypeEnum.customColumn) {
274
- newMeta[i] = customColumnPatch(newMeta[i]);
275
- }
276
- if (v.type === TypeEnum.data) {
277
- v = dataPatch(v);
278
- }
264
+ // // 兼容
265
+ // if (patchVersion != '1.0.0') {
266
+ // if (v.type === TypeEnum.joinData) {
267
+ // v = joinDataPatch(v);
268
+ // }
269
+ // if (v.type === TypeEnum.filter) {
270
+ // v = filterPatch(v);
271
+ // }
272
+ // if (v.type === TypeEnum.sort) {
273
+ // v = sortPatch(v);
274
+ // }
275
+ // if (v.type === TypeEnum.customColumn) {
276
+ // v = customColumnPatch(v);
277
+ // }
278
+ // if (v.type === TypeEnum.data) {
279
+ // v = dataPatch(v);
280
+ // }
281
+ // }
279
282
  // if (v.type === TypeEnum.filter) {
280
283
  // newMeta[i] = setFilterQuotes(newMeta[i]);
281
284
  // }
package/lib/es/index.js CHANGED
@@ -9,7 +9,7 @@ import './locale/zh';
9
9
  import { __ } from './locale';
10
10
  import Loading from './common/Loading';
11
11
  import Metabase from './components/metabase';
12
- import { reassembleByUnion } from './utils';
12
+ import { reassembleByUnion, patchData } from './utils';
13
13
  /**
14
14
  * 规则
15
15
  * 1、主表一换 下面全部删除
@@ -51,7 +51,7 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
51
51
  store.setProps(props);
52
52
  }, [props]);
53
53
  useEffect(function () {
54
- var _value = reassembleByUnion(value);
54
+ var _value = reassembleByUnion(patchData(value));
55
55
  store.setPreData(_value);
56
56
  }, [value]);
57
57
  useEffect(function () {
@@ -84,7 +84,7 @@ export interface AtomsUnknown {
84
84
  }
85
85
  export type AtomsItem = AtomsNotExists | AtomsExists | AtomsJoinDefault | AtomsExpression | AtomsField | AtomsInputString | AtomsInputStringList | AtomsInputNumberList | AtomsInputNumber | AtomsOprator | AtomsConstant | AtomsUnknown;
86
86
  export type ToolbarType = TypeEnum | 'filter' | 'summarize' | 'joinData' | 'permissionTable' | 'customColumn' | 'sort' | 'rowLimit' | 'union';
87
- export type MetaListType = MetaData | MetaJoin | MetaCustom | MetaFilter | MetaSummarize | MetaSort | MetaLimit | MetaPermissionTable;
87
+ export type MetaListType = MetaData | MetaJoin | MetaCustom | MetaFilter | MetaSummarize | MetaSort | MetaLimit | MetaPermissionTable | MetaUnion;
88
88
  export type initColumnsType = MetaData_ColumnsType;
89
89
  export interface TableColumnsMapType {
90
90
  [tableName: string]: initColumnsType[];
@@ -243,6 +243,11 @@ export interface MetaPermissionTable {
243
243
  type: TypeEnum.permissionTable;
244
244
  table: MetaData_TableType;
245
245
  }
246
+ export interface MetaUnion {
247
+ metaKey: number;
248
+ type: TypeEnum.union;
249
+ subquery: MetaListType[];
250
+ }
246
251
  export interface LooseObject {
247
252
  [TypeEnum.data]?: MetaData;
248
253
  [TypeEnum.joinData]?: MetaJoin[];
package/lib/es/utils.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare const getSubColumns: (metaList: any) => DataType[];
17
17
  export declare const changeTableAlias: (list: MetaListType[] | [], curObj: Pick<MetaData_TableType, "tableUuid" | "alias">) => MetaListType[];
18
18
  export declare const changeFieldAlias: (list: MetaListType[], curObj: Pick<MetaData_ColumnsType, "fieldUuid" | "fieldAlias">) => MetaListType[];
19
19
  export declare function splitByUnion(data: any): any[];
20
+ export declare const patchData: (metas: MetaListType[]) => MetaListType[];
20
21
  export declare function reassembleByUnion(target?: any[]): any[];
21
22
  export declare const buildSqlQuery: (data: MetaListType[] | undefined, type: string) => string;
22
23
  export {};
package/lib/es/utils.js CHANGED
@@ -9,6 +9,7 @@ import { AtomsTypeEnum } from './store/types';
9
9
  import { summarizeToSql } from './store/helper';
10
10
  import { uuidv4 } from './utils/helper';
11
11
  import cloneDeep from 'lodash/cloneDeep';
12
+ import { patchMetas } from './hooks/patch';
12
13
  export var findIndex = function findIndex(arr, item) {
13
14
  return arr.indexOf(item);
14
15
  };
@@ -437,6 +438,14 @@ export function splitByUnion(data) {
437
438
  }
438
439
  return result;
439
440
  }
441
+ export var patchData = function patchData(metas) {
442
+ var mainTable = metas[0] || {};
443
+ var version = (mainTable === null || mainTable === void 0 ? void 0 : mainTable.patchVersion) || '';
444
+ if (version != '1.0.0') {
445
+ return patchMetas(metas);
446
+ }
447
+ return metas;
448
+ };
440
449
  export function reassembleByUnion() {
441
450
  var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
442
451
  if (!target) return [];
@@ -523,7 +532,7 @@ export var buildSqlQuery = function buildSqlQuery() {
523
532
  var tables = [];
524
533
  var joins = [];
525
534
  var wheres = [];
526
- data.forEach(function (item) {
535
+ data === null || data === void 0 || data.forEach(function (item) {
527
536
  if (item.type === TypeEnum.data) {
528
537
  var meta = item;
529
538
  var tableName = "".concat(meta.table.name);
@@ -597,7 +606,7 @@ export var buildSqlQuery = function buildSqlQuery() {
597
606
  sqlClauses.push(joins.join(' '));
598
607
  }
599
608
  if (wheres.length > 0) {
600
- sqlClauses.push("WHERE ".concat(wheres.join(' AND ')));
609
+ sqlClauses.push("WHERE ".concat(wheres.join(' ')));
601
610
  }
602
611
  }
603
612
  sqlClauses.push(')');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",