@gingkoo/pandora-metabase 1.0.19 → 1.0.21

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.
@@ -24,6 +24,7 @@ var _selectList = _interopRequireDefault(require("../select-list"));
24
24
  var _selectColumnMultiple = _interopRequireDefault(require("../select-column-multiple"));
25
25
  var _icons = require("../../icons");
26
26
  var _useProvider = require("../../../hooks/use-provider");
27
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
27
28
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
28
29
  /**
29
30
  * 关联模块 选择表字段
@@ -74,7 +75,7 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
74
75
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
75
76
  condition = _useState4[0],
76
77
  setCondition = _useState4[1];
77
- var _useState5 = (0, _react.useState)(value.rhs || []),
78
+ var _useState5 = (0, _react.useState)((0, _cloneDeep["default"])(value.rhs || [])),
78
79
  _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
79
80
  rhsVal = _useState6[0],
80
81
  setRhsVal = _useState6[1];
@@ -122,6 +122,9 @@ var CustomColumn = function CustomColumn(props) {
122
122
  var _prevGroupBy$group, _prevGroupBy$by;
123
123
  var _data = {
124
124
  table: prevGroupBy.alias,
125
+ name: prevGroupBy.alias,
126
+ name_zh: prevGroupBy.alias,
127
+ id: prevGroupBy.alias,
125
128
  tableId: prevGroupBy.alias,
126
129
  tableUuid: prevGroupBy.tableUuid || (0, _helper.uuidv4)('table'),
127
130
  alias: prevGroupBy.alias,
@@ -167,7 +170,7 @@ var CustomColumn = function CustomColumn(props) {
167
170
  data = data.concat(
168
171
  // @ts-ignore
169
172
  joinData.map(function (v) {
170
- return {
173
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v.table2), {}, {
171
174
  alias: v.table2.alias,
172
175
  table: v.table2.name,
173
176
  tableId: v.table2.id,
@@ -175,14 +178,14 @@ var CustomColumn = function CustomColumn(props) {
175
178
  columns: v.columns,
176
179
  datasourceId: mainTable.table.datasourceId,
177
180
  datasourceName: mainTable.table.datasourceName
178
- };
181
+ });
179
182
  }));
180
183
  }
181
184
  } else {
182
185
  // @ts-ignore
183
186
  data = store.metaList[groupIndex].list.slice(0, index).map(function (v) {
184
187
  if (v.type === _enum.TypeEnum.data) {
185
- return {
188
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v.table), {}, {
186
189
  alias: v.table.alias,
187
190
  table: v.table.name,
188
191
  tableId: v.table.id,
@@ -190,9 +193,9 @@ var CustomColumn = function CustomColumn(props) {
190
193
  columns: v.columns,
191
194
  datasourceId: mainTable.table.datasourceId,
192
195
  datasourceName: mainTable.table.datasourceName
193
- };
196
+ });
194
197
  } else if (v.type === _enum.TypeEnum.joinData) {
195
- return {
198
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v.table2), {}, {
196
199
  alias: v.table2.alias,
197
200
  table: v.table2.name,
198
201
  tableId: v.table2.id,
@@ -200,7 +203,7 @@ var CustomColumn = function CustomColumn(props) {
200
203
  columns: v.columns,
201
204
  datasourceId: mainTable.table.datasourceId,
202
205
  datasourceName: mainTable.table.datasourceName
203
- };
206
+ });
204
207
  } else {
205
208
  return {
206
209
  table: null
@@ -86,6 +86,7 @@ var JoinData = function JoinData(props) {
86
86
  ExistAboveGroupBy = _getHelper.ExistAboveGroupBy,
87
87
  prevList = _getHelper.prevList,
88
88
  prevGroupBy = _getHelper.prevGroupBy;
89
+ // 获取左侧表
89
90
  if (ExistAboveGroupBy) {
90
91
  var _prevGroupBy$group, _prevGroupBy$by;
91
92
  var _data = {
@@ -147,7 +148,7 @@ var JoinData = function JoinData(props) {
147
148
  } else {
148
149
  data = store.metaList[groupIndex].list.slice(0, index + 1).reduce(function (mo, v) {
149
150
  if (v.type === _enum.TypeEnum.data) {
150
- mo.push({
151
+ mo.push((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v.table), {}, {
151
152
  alias: v.table.alias,
152
153
  name: v.table.name,
153
154
  name_zh: v.table.name_zh,
@@ -156,7 +157,7 @@ var JoinData = function JoinData(props) {
156
157
  columns: v.columns,
157
158
  datasourceId: v.table.datasourceId,
158
159
  datasourceName: v.table.datasourceName
159
- });
160
+ }));
160
161
  } else if (v.type === _enum.TypeEnum.joinData) {
161
162
  mo.push({
162
163
  alias: v.table2.alias,
@@ -170,9 +171,12 @@ var JoinData = function JoinData(props) {
170
171
  });
171
172
  }
172
173
  return mo;
173
- }, []);
174
+ }, []).filter(function (v) {
175
+ return v.tableUuid === meta.table1.tableUuid;
176
+ });
174
177
  }
175
- // 添加当前表
178
+ // 获取右侧表
179
+ // 添加table2
176
180
  data = data.concat([{
177
181
  alias: meta.table2.alias,
178
182
  name: meta.table2.name,
@@ -389,71 +393,77 @@ var JoinData = function JoinData(props) {
389
393
  })
390
394
  });
391
395
  }
396
+ // 切换表后重置数据
392
397
  function initExpressions() {
393
- var _newMeta$index, _newMeta$index2;
398
+ console.log(11);
394
399
  var newMeta = store.metaList[groupIndex].list.slice();
395
- 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) {
396
- newMeta[index].expressions = [{
397
- lhs: [{
398
- fieldName: '',
399
- // 字段名
400
- fieldNameZh: '',
401
- // 字段中文名
402
- fieldAlias: '',
403
- // 别名
404
- fieldUuid: '',
405
- // uuid
406
- fieldId: '',
407
- // 字段id
408
- // quotes?: string; // 字段展示的 不知道有没有用
409
- tableName: '',
410
- // 表名
411
- tableNameZh: '',
412
- tableId: '',
413
- // 表名
414
- tableAlias: '',
415
- // 别名
416
- tableUuid: '',
417
- // 表唯一标识
418
- datasourceName: '',
419
- // 数据源名
420
- datasourceId: '',
421
- // 数据源id
422
- type: _types.AtomsTypeEnum.FIELD
423
- }],
424
- condition: '',
425
- rhs: [{
426
- fieldName: '',
427
- // 字段名
428
- fieldNameZh: '',
429
- // 字段中文名
430
- fieldAlias: '',
431
- // 别名
432
- fieldUuid: '',
433
- // uuid
434
- fieldId: '',
435
- // 字段id
436
- // quotes?: string; // 字段展示的 不知道有没有用
437
- tableName: '',
438
- // 表名
439
- tableNameZh: '',
440
- tableId: '',
441
- // 表名
442
- tableAlias: '',
443
- // 别名
444
- tableUuid: '',
445
- // 表唯一标识
446
- datasourceName: '',
447
- // 数据源名
448
- datasourceId: '',
449
- // 数据源id
450
- type: _types.AtomsTypeEnum.FIELD
451
- }],
452
- // quotes: '',
453
- type: _types.AtomsTypeEnum.JOIN_DEFAULT
454
- }];
455
- store.setMeta(newMeta, groupIndex);
456
- }
400
+ newMeta[index].expressions = [{
401
+ lhs: [{
402
+ fieldName: '',
403
+ // 字段名
404
+ fieldNameZh: '',
405
+ // 字段中文名
406
+ fieldAlias: '',
407
+ // 别名
408
+ fieldUuid: '',
409
+ // uuid
410
+ fieldId: '',
411
+ // 字段id
412
+ // quotes?: string; // 字段展示的 不知道有没有用
413
+ tableName: '',
414
+ // 表名
415
+ tableNameZh: '',
416
+ tableId: '',
417
+ // 表名
418
+ tableAlias: '',
419
+ // 别名
420
+ tableUuid: '',
421
+ // 表唯一标识
422
+ datasourceName: '',
423
+ // 数据源名
424
+ datasourceId: '',
425
+ // 数据源id
426
+ type: _types.AtomsTypeEnum.FIELD
427
+ }],
428
+ condition: '',
429
+ rhs: [{
430
+ fieldName: '',
431
+ // 字段名
432
+ fieldNameZh: '',
433
+ // 字段中文名
434
+ fieldAlias: '',
435
+ // 别名
436
+ fieldUuid: '',
437
+ // uuid
438
+ fieldId: '',
439
+ // 字段id
440
+ // quotes?: string; // 字段展示的 不知道有没有用
441
+ tableName: '',
442
+ // 表名
443
+ tableNameZh: '',
444
+ tableId: '',
445
+ // 表名
446
+ tableAlias: '',
447
+ // 别名
448
+ tableUuid: '',
449
+ // 表唯一标识
450
+ datasourceName: '',
451
+ // 数据源名
452
+ datasourceId: '',
453
+ // 数据源id
454
+ type: _types.AtomsTypeEnum.FIELD
455
+ }],
456
+ // quotes: '',
457
+ type: _types.AtomsTypeEnum.JOIN_DEFAULT
458
+ }];
459
+ store.setMeta(newMeta, groupIndex);
460
+ // if (
461
+ // ((newMeta[index] as MetaJoin).table1.name &&
462
+ // (newMeta[index] as MetaJoin).table2.name &&
463
+ // !(newMeta[index] as MetaJoin)?.expressions) ||
464
+ // (newMeta[index] as MetaJoin)?.expressions?.length < 1
465
+ // ) {
466
+ // }
457
467
  }
458
468
  function selectJoin(e) {
459
469
  var newMeta = store.metaList[groupIndex].list.slice();
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.sortPatch = exports.joinDataPatch = exports.filterPatch = exports.dataPatch = exports.customColumnPatch = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
9
9
  var _helper = require("../utils/helper");
10
+ var _utils = require("../utils");
10
11
  var _types = require("../store/types");
11
12
  var _enum = require("../store/enum");
12
13
  var dataPatch = exports.dataPatch = function dataPatch(newMeta) {
@@ -27,6 +28,15 @@ var joinDataPatch = exports.joinDataPatch = function joinDataPatch(newMeta) {
27
28
  if ((item.type === _types.AtomsTypeEnum.EXPRESSION || item.type === _types.AtomsTypeEnum.JOIN_DEFAULT) && item.lhs) {
28
29
  return newMeta;
29
30
  }
31
+ if (item.type === _types.AtomsTypeEnum.EXISTS && !item.tableUuid) {
32
+ return newMeta;
33
+ }
34
+ if (item.type === _types.AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
35
+ return newMeta;
36
+ }
37
+ if (item.type === _types.AtomsTypeEnum.FIELD && item.fieldName) {
38
+ return newMeta;
39
+ }
30
40
  }
31
41
  // if (
32
42
  // newMeta.expressions?.[0]?.type &&
@@ -262,6 +272,9 @@ var filterPatch = exports.filterPatch = function filterPatch(newMeta) {
262
272
  if (item.type === _types.AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
263
273
  return newMeta;
264
274
  }
275
+ if (item.type === _types.AtomsTypeEnum.FIELD && item.fieldName) {
276
+ return newMeta;
277
+ }
265
278
  }
266
279
  var _filter = (_newMeta$filter2 = newMeta.filter) === null || _newMeta$filter2 === void 0 ? void 0 : _newMeta$filter2.map(function (v) {
267
280
  // 表达式
@@ -335,15 +348,17 @@ var filterPatch = exports.filterPatch = function filterPatch(newMeta) {
335
348
  };
336
349
  return tem;
337
350
  } else if (v.type === 'notExists') {
351
+ var notExists = renderExists(v.notExists);
338
352
  return {
339
- notExists: renderExists(v.notExists),
340
- quotes: v.quotes,
353
+ notExists: notExists,
354
+ quotes: (0, _utils.buildSqlQuery)(notExists, v.type),
341
355
  type: _types.AtomsTypeEnum.NOT_EXISTS
342
356
  };
343
357
  } else if (v.type === 'exists') {
358
+ var _notExists = renderExists(v.notExists);
344
359
  return {
345
- notExists: renderExists(v.notExists),
346
- quotes: v.quotes,
360
+ notExists: _notExists,
361
+ quotes: (0, _utils.buildSqlQuery)(_notExists, v.type),
347
362
  type: _types.AtomsTypeEnum.EXISTS
348
363
  };
349
364
  }
@@ -353,14 +368,23 @@ var filterPatch = exports.filterPatch = function filterPatch(newMeta) {
353
368
  return newMeta;
354
369
  };
355
370
  var customColumnPatch = exports.customColumnPatch = function customColumnPatch(newMeta) {
356
- var _newMeta$customColumn;
371
+ var _newMeta$customColumn, _newMeta$customColumn2;
357
372
  var item = ((_newMeta$customColumn = newMeta.customColumn[0].formulaList) === null || _newMeta$customColumn === void 0 ? void 0 : _newMeta$customColumn[0]) || {};
358
- if (item.type && Object.values(_types.AtomsTypeEnum).includes(item.type || '')) {
373
+ if (item !== null && item !== void 0 && item.type && Object.values(_types.AtomsTypeEnum).includes(item.type)) {
359
374
  if (item.type === _types.AtomsTypeEnum.EXPRESSION && item.lhs) {
360
375
  return newMeta;
361
376
  }
377
+ if (item.type === _types.AtomsTypeEnum.EXISTS && !item.tableUuid) {
378
+ return newMeta;
379
+ }
380
+ if (item.type === _types.AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
381
+ return newMeta;
382
+ }
383
+ if (item.type === _types.AtomsTypeEnum.FIELD && item.fieldName) {
384
+ return newMeta;
385
+ }
362
386
  }
363
- newMeta.customColumn = newMeta.customColumn.map(function (v) {
387
+ newMeta.customColumn = (newMeta === null || newMeta === void 0 || (_newMeta$customColumn2 = newMeta.customColumn) === null || _newMeta$customColumn2 === void 0 ? void 0 : _newMeta$customColumn2.map(function (v) {
364
388
  var _formulaList = v.formulaList.map(function (formula) {
365
389
  var tem = formula;
366
390
  if (formula.type === 'expression') {
@@ -473,7 +497,7 @@ var customColumnPatch = exports.customColumnPatch = function customColumnPatch(n
473
497
  return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v), {}, {
474
498
  formulaList: _formulaList
475
499
  });
476
- });
500
+ })) || newMeta.customColumn;
477
501
  return newMeta;
478
502
  };
479
503
  var sortPatch = exports.sortPatch = function sortPatch(newMeta) {
@@ -483,6 +507,15 @@ var sortPatch = exports.sortPatch = function sortPatch(newMeta) {
483
507
  if (item.type === _types.AtomsTypeEnum.EXPRESSION && item.lhs) {
484
508
  return newMeta;
485
509
  }
510
+ if (item.type === _types.AtomsTypeEnum.EXISTS && !item.tableUuid) {
511
+ return newMeta;
512
+ }
513
+ if (item.type === _types.AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
514
+ return newMeta;
515
+ }
516
+ if (item.type === _types.AtomsTypeEnum.FIELD && item.fieldName) {
517
+ return newMeta;
518
+ }
486
519
  }
487
520
  var _sort = (_newMeta$sort2 = newMeta.sort) === null || _newMeta$sort2 === void 0 ? void 0 : _newMeta$sort2.map(function (v) {
488
521
  return {
package/lib/cjs/utils.js CHANGED
@@ -532,7 +532,7 @@ var buildSqlQuery = exports.buildSqlQuery = function buildSqlQuery() {
532
532
  var tables = [];
533
533
  var joins = [];
534
534
  var wheres = [];
535
- data.forEach(function (item) {
535
+ data === null || data === void 0 || data.forEach(function (item) {
536
536
  if (item.type === _enum.TypeEnum.data) {
537
537
  var meta = item;
538
538
  var tableName = "".concat(meta.table.name);
@@ -606,7 +606,7 @@ var buildSqlQuery = exports.buildSqlQuery = function buildSqlQuery() {
606
606
  sqlClauses.push(joins.join(' '));
607
607
  }
608
608
  if (wheres.length > 0) {
609
- sqlClauses.push("WHERE ".concat(wheres.join(' AND ')));
609
+ sqlClauses.push("WHERE ".concat(wheres.join(' ')));
610
610
  }
611
611
  }
612
612
  sqlClauses.push(')');
@@ -20,6 +20,7 @@ import SelectList from '../select-list';
20
20
  import SelectColumnMultiple from '../select-column-multiple';
21
21
  import { LeftArrowIcon } from '../../icons';
22
22
  import { useStore } from '../../../hooks/use-provider';
23
+ import cloneDeep from 'lodash/cloneDeep';
23
24
  var RangePicker = DatePicker.RangePicker;
24
25
  var NUMBER_LIST = ['等于', '不等于', '大于', '小于', '介于之间', '大于或等于', '小于或等于', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
25
26
  var STRING_LIST = ['等于', '不等于', '包含', '不包含', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
@@ -65,7 +66,7 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
65
66
  _useState4 = _slicedToArray(_useState3, 2),
66
67
  condition = _useState4[0],
67
68
  setCondition = _useState4[1];
68
- var _useState5 = useState(value.rhs || []),
69
+ var _useState5 = useState(cloneDeep(value.rhs || [])),
69
70
  _useState6 = _slicedToArray(_useState5, 2),
70
71
  rhsVal = _useState6[0],
71
72
  setRhsVal = _useState6[1];
@@ -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
@@ -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();
@@ -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) {
@@ -20,6 +21,15 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
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 &&
@@ -255,6 +265,9 @@ export var filterPatch = function filterPatch(newMeta) {
255
265
  if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
256
266
  return newMeta;
257
267
  }
268
+ if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
269
+ return newMeta;
270
+ }
258
271
  }
259
272
  var _filter = (_newMeta$filter2 = newMeta.filter) === null || _newMeta$filter2 === void 0 ? void 0 : _newMeta$filter2.map(function (v) {
260
273
  // 表达式
@@ -328,15 +341,17 @@ export var filterPatch = function filterPatch(newMeta) {
328
341
  };
329
342
  return tem;
330
343
  } else if (v.type === 'notExists') {
344
+ var notExists = renderExists(v.notExists);
331
345
  return {
332
- notExists: renderExists(v.notExists),
333
- quotes: v.quotes,
346
+ notExists: notExists,
347
+ quotes: buildSqlQuery(notExists, v.type),
334
348
  type: AtomsTypeEnum.NOT_EXISTS
335
349
  };
336
350
  } else if (v.type === 'exists') {
351
+ var _notExists = renderExists(v.notExists);
337
352
  return {
338
- notExists: renderExists(v.notExists),
339
- quotes: v.quotes,
353
+ notExists: _notExists,
354
+ quotes: buildSqlQuery(_notExists, v.type),
340
355
  type: AtomsTypeEnum.EXISTS
341
356
  };
342
357
  }
@@ -346,14 +361,23 @@ export var filterPatch = function filterPatch(newMeta) {
346
361
  return newMeta;
347
362
  };
348
363
  export var customColumnPatch = function customColumnPatch(newMeta) {
349
- var _newMeta$customColumn;
364
+ var _newMeta$customColumn, _newMeta$customColumn2;
350
365
  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 || '')) {
366
+ if (item !== null && item !== void 0 && item.type && Object.values(AtomsTypeEnum).includes(item.type)) {
352
367
  if (item.type === AtomsTypeEnum.EXPRESSION && item.lhs) {
353
368
  return newMeta;
354
369
  }
370
+ if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
371
+ return newMeta;
372
+ }
373
+ if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
374
+ return newMeta;
375
+ }
376
+ if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
377
+ return newMeta;
378
+ }
355
379
  }
356
- newMeta.customColumn = newMeta.customColumn.map(function (v) {
380
+ newMeta.customColumn = (newMeta === null || newMeta === void 0 || (_newMeta$customColumn2 = newMeta.customColumn) === null || _newMeta$customColumn2 === void 0 ? void 0 : _newMeta$customColumn2.map(function (v) {
357
381
  var _formulaList = v.formulaList.map(function (formula) {
358
382
  var tem = formula;
359
383
  if (formula.type === 'expression') {
@@ -466,7 +490,7 @@ export var customColumnPatch = function customColumnPatch(newMeta) {
466
490
  return _objectSpread(_objectSpread({}, v), {}, {
467
491
  formulaList: _formulaList
468
492
  });
469
- });
493
+ })) || newMeta.customColumn;
470
494
  return newMeta;
471
495
  };
472
496
  export var sortPatch = function sortPatch(newMeta) {
@@ -476,6 +500,15 @@ export var sortPatch = function sortPatch(newMeta) {
476
500
  if (item.type === AtomsTypeEnum.EXPRESSION && item.lhs) {
477
501
  return newMeta;
478
502
  }
503
+ if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
504
+ return newMeta;
505
+ }
506
+ if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
507
+ return newMeta;
508
+ }
509
+ if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
510
+ return newMeta;
511
+ }
479
512
  }
480
513
  var _sort = (_newMeta$sort2 = newMeta.sort) === null || _newMeta$sort2 === void 0 ? void 0 : _newMeta$sort2.map(function (v) {
481
514
  return {
package/lib/es/utils.js CHANGED
@@ -523,7 +523,7 @@ export var buildSqlQuery = function buildSqlQuery() {
523
523
  var tables = [];
524
524
  var joins = [];
525
525
  var wheres = [];
526
- data.forEach(function (item) {
526
+ data === null || data === void 0 || data.forEach(function (item) {
527
527
  if (item.type === TypeEnum.data) {
528
528
  var meta = item;
529
529
  var tableName = "".concat(meta.table.name);
@@ -597,7 +597,7 @@ export var buildSqlQuery = function buildSqlQuery() {
597
597
  sqlClauses.push(joins.join(' '));
598
598
  }
599
599
  if (wheres.length > 0) {
600
- sqlClauses.push("WHERE ".concat(wheres.join(' AND ')));
600
+ sqlClauses.push("WHERE ".concat(wheres.join(' ')));
601
601
  }
602
602
  }
603
603
  sqlClauses.push(')');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",