@gingkoo/pandora-metabase 1.0.130 → 1.0.131

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.
Files changed (65) hide show
  1. package/lib/cjs/components/dialog/expression/index.js +0 -1
  2. package/lib/cjs/components/dialog/formula-list/utils.js +0 -3
  3. package/lib/cjs/components/dialog/select-column/index.js +2 -2
  4. package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +0 -1
  5. package/lib/cjs/components/dialog/select-column-multiple/index.js +44 -19
  6. package/lib/cjs/components/dialog/select-join-column/index.js +23 -7
  7. package/lib/cjs/components/dialog/select-join-column-multiple/index.js +15 -6
  8. package/lib/cjs/components/dialog/select-permission-table/index.js +2 -2
  9. package/lib/cjs/components/dialog/select-summarize/index.js +1 -3
  10. package/lib/cjs/components/dialog/select-table/index.d.ts +1 -2
  11. package/lib/cjs/components/dialog/select-table/index.js +231 -261
  12. package/lib/cjs/components/dialog/select-table/index.less +51 -36
  13. package/lib/cjs/components/metabase/index.js +34 -16
  14. package/lib/cjs/components/modules/components/item-name.js +0 -1
  15. package/lib/cjs/components/modules/custom-column.js +3 -7
  16. package/lib/cjs/components/modules/filter.js +3 -6
  17. package/lib/cjs/components/modules/join-data.js +41 -87
  18. package/lib/cjs/components/modules/permission-table.js +5 -9
  19. package/lib/cjs/components/modules/sort.js +1 -2
  20. package/lib/cjs/components/modules/summarize/group-by.js +1 -8
  21. package/lib/cjs/components/modules/summarize/select-index.js +1 -4
  22. package/lib/cjs/components/modules/table-data.js +28 -44
  23. package/lib/cjs/hooks/use-state.js +22 -147
  24. package/lib/cjs/index.js +1 -7
  25. package/lib/cjs/locale/en.js +1 -0
  26. package/lib/cjs/locale/zh.js +1 -0
  27. package/lib/cjs/store/types.d.ts +4 -5
  28. package/lib/cjs/types.d.ts +0 -8
  29. package/lib/cjs/utils/helper.d.ts +4 -0
  30. package/lib/cjs/utils/helper.js +102 -1
  31. package/lib/cjs/utils/transformSql.js +0 -2
  32. package/lib/cjs/utils.js +38 -18
  33. package/lib/es/components/dialog/expression/index.js +0 -1
  34. package/lib/es/components/dialog/formula-list/utils.js +0 -3
  35. package/lib/es/components/dialog/select-column/index.js +3 -3
  36. package/lib/es/components/dialog/select-column-multiple/index.d.ts +0 -1
  37. package/lib/es/components/dialog/select-column-multiple/index.js +45 -21
  38. package/lib/es/components/dialog/select-join-column/index.js +24 -8
  39. package/lib/es/components/dialog/select-join-column-multiple/index.js +16 -7
  40. package/lib/es/components/dialog/select-permission-table/index.js +3 -3
  41. package/lib/es/components/dialog/select-summarize/index.js +1 -3
  42. package/lib/es/components/dialog/select-table/index.d.ts +1 -2
  43. package/lib/es/components/dialog/select-table/index.js +233 -263
  44. package/lib/es/components/dialog/select-table/index.less +51 -36
  45. package/lib/es/components/metabase/index.js +34 -16
  46. package/lib/es/components/modules/components/item-name.js +0 -1
  47. package/lib/es/components/modules/custom-column.js +3 -7
  48. package/lib/es/components/modules/filter.js +3 -6
  49. package/lib/es/components/modules/join-data.js +42 -88
  50. package/lib/es/components/modules/permission-table.js +6 -10
  51. package/lib/es/components/modules/sort.js +1 -2
  52. package/lib/es/components/modules/summarize/group-by.js +1 -8
  53. package/lib/es/components/modules/summarize/select-index.js +1 -4
  54. package/lib/es/components/modules/table-data.js +29 -45
  55. package/lib/es/hooks/use-state.js +23 -148
  56. package/lib/es/index.js +1 -7
  57. package/lib/es/locale/en.js +1 -0
  58. package/lib/es/locale/zh.js +1 -0
  59. package/lib/es/store/types.d.ts +4 -5
  60. package/lib/es/types.d.ts +0 -8
  61. package/lib/es/utils/helper.d.ts +4 -0
  62. package/lib/es/utils/helper.js +101 -0
  63. package/lib/es/utils/transformSql.js +0 -2
  64. package/lib/es/utils.js +39 -19
  65. package/package.json +1 -1
@@ -1,5 +1,106 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import { TypeEnum } from '../store/enum';
3
+ var normalizeId = function normalizeId(val) {
4
+ if (val === undefined || val === null) return '';
5
+ return "".concat(val);
6
+ };
7
+ var hasBoth = function hasBoth(left, right) {
8
+ return Boolean(left && right);
9
+ };
10
+ export var getTableIdFirstKey = function getTableIdFirstKey() {
11
+ var table = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
12
+ var datasourceId = normalizeId(table.datasourceId);
13
+ var tableId = normalizeId(table.id || table.tableId);
14
+ if (tableId) return "".concat(datasourceId, "|id:").concat(tableId);
15
+ var tableUuid = normalizeId(table.tableUuid);
16
+ if (tableUuid) return "".concat(datasourceId, "|uuid:").concat(tableUuid);
17
+ var tableName = normalizeId(table.name || table.tableName);
18
+ var tableAlias = normalizeId(table.alias || table.tableAlias);
19
+ return tableName ? "".concat(datasourceId, "|name:").concat(tableName, "|alias:").concat(tableAlias) : datasourceId;
20
+ };
21
+ export var isSameTableByIdFirst = function isSameTableByIdFirst() {
22
+ var left = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
23
+ var right = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24
+ var leftDatasourceId = normalizeId(left.datasourceId);
25
+ var rightDatasourceId = normalizeId(right.datasourceId);
26
+ if (hasBoth(leftDatasourceId, rightDatasourceId) && leftDatasourceId !== rightDatasourceId) {
27
+ return false;
28
+ }
29
+ var leftTableId = normalizeId(left.id || left.tableId);
30
+ var rightTableId = normalizeId(right.id || right.tableId);
31
+ if (hasBoth(leftTableId, rightTableId)) {
32
+ return leftTableId === rightTableId;
33
+ }
34
+ var leftTableName = normalizeId(left.name || left.tableName);
35
+ var rightTableName = normalizeId(right.name || right.tableName);
36
+ if (hasBoth(leftTableName, rightTableName)) {
37
+ if (leftTableName !== rightTableName) {
38
+ return false;
39
+ }
40
+ var leftTableAlias = normalizeId(left.alias || left.tableAlias);
41
+ var rightTableAlias = normalizeId(right.alias || right.tableAlias);
42
+ if (hasBoth(leftTableAlias, rightTableAlias)) {
43
+ return leftTableAlias === rightTableAlias;
44
+ }
45
+ return true;
46
+ }
47
+ var leftTableUuid = normalizeId(left.tableUuid);
48
+ var rightTableUuid = normalizeId(right.tableUuid);
49
+ if (hasBoth(leftTableUuid, rightTableUuid)) {
50
+ return leftTableUuid === rightTableUuid;
51
+ }
52
+ return false;
53
+ };
54
+ export var getColumnIdFirstKey = function getColumnIdFirstKey() {
55
+ var column = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
56
+ var tableKey = getTableIdFirstKey(column);
57
+ var fieldId = normalizeId(column.fieldId || column.id);
58
+ if (fieldId) return "".concat(tableKey, "|fieldId:").concat(fieldId);
59
+ var fieldUuid = normalizeId(column.fieldUuid);
60
+ if (fieldUuid) return "".concat(tableKey, "|fieldUuid:").concat(fieldUuid);
61
+ var fieldName = normalizeId(column.fieldName || column.name);
62
+ var fieldAlias = normalizeId(column.fieldAlias);
63
+ return fieldName ? "".concat(tableKey, "|fieldName:").concat(fieldName, "|alias:").concat(fieldAlias) : tableKey;
64
+ };
65
+ export var isSameColumnByIdFirst = function isSameColumnByIdFirst() {
66
+ var left = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
67
+ var right = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
68
+ var leftDatasourceId = normalizeId(left.datasourceId);
69
+ var rightDatasourceId = normalizeId(right.datasourceId);
70
+ if (hasBoth(leftDatasourceId, rightDatasourceId) && leftDatasourceId !== rightDatasourceId) {
71
+ return false;
72
+ }
73
+ var leftTableId = normalizeId(left.tableId);
74
+ var rightTableId = normalizeId(right.tableId);
75
+ if (hasBoth(leftTableId, rightTableId) && leftTableId !== rightTableId) {
76
+ return false;
77
+ }
78
+ var leftTableUuid = normalizeId(left.tableUuid);
79
+ var rightTableUuid = normalizeId(right.tableUuid);
80
+ if (hasBoth(leftTableUuid, rightTableUuid) && leftTableUuid !== rightTableUuid) {
81
+ var leftTableName = normalizeId(left.tableName || left.table);
82
+ var rightTableName = normalizeId(right.tableName || right.table);
83
+ if (!hasBoth(leftTableName, rightTableName) || leftTableName !== rightTableName) {
84
+ return false;
85
+ }
86
+ }
87
+ var leftFieldId = normalizeId(left.fieldId || left.id);
88
+ var rightFieldId = normalizeId(right.fieldId || right.id);
89
+ if (hasBoth(leftFieldId, rightFieldId)) {
90
+ return leftFieldId === rightFieldId;
91
+ }
92
+ var leftFieldUuid = normalizeId(left.fieldUuid);
93
+ var rightFieldUuid = normalizeId(right.fieldUuid);
94
+ if (hasBoth(leftFieldUuid, rightFieldUuid)) {
95
+ return leftFieldUuid === rightFieldUuid;
96
+ }
97
+ var leftFieldName = normalizeId(left.fieldName || left.name);
98
+ var rightFieldName = normalizeId(right.fieldName || right.name);
99
+ if (hasBoth(leftFieldName, rightFieldName)) {
100
+ return leftFieldName === rightFieldName;
101
+ }
102
+ return false;
103
+ };
3
104
  export var throttle = function throttle(fn) {
4
105
  var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
5
106
  if (typeof fn !== 'function') return function () {
@@ -519,7 +519,6 @@ var _handleJoinData = function _handleJoinData(joinData) {
519
519
  tableName_zh: v.table2.name_zh,
520
520
  datasourceId: v.table2.datasourceId || '',
521
521
  datasourceName: v.table2.datasourceName || '',
522
- datasourceType: v.table2.datasourceType || '',
523
522
  joinCondition: joinCondition,
524
523
  joinType: v.joinType,
525
524
  subQuery: subQuery,
@@ -563,7 +562,6 @@ var _handleNesting = function handleNesting(data) {
563
562
  obj.tableId = tableData.table.id;
564
563
  obj.datasourceId = tableData.table.datasourceId;
565
564
  obj.datasourceName = tableData.table.datasourceName;
566
- obj.datasourceType = tableData.table.datasourceType;
567
565
  if (tableData.isSubquery && Array.isArray(tableData.subquery)) {
568
566
  obj.tableSubQuery = tableData.subquery;
569
567
  }
package/lib/es/utils.js CHANGED
@@ -10,7 +10,7 @@ import { TypeEnum, SQL_COLUMN_TYPE } from './store/enum';
10
10
  import { AtomsTypeEnum } from './store/types';
11
11
  import { summarizeByToSql, summarizeToSql } from './store/helper';
12
12
  import { transformSql } from './utils/transformSql';
13
- import { uuidv4 } from './utils/helper';
13
+ import { isSameColumnByIdFirst, isSameTableByIdFirst, uuidv4 } from './utils/helper';
14
14
  import cloneDeep from 'lodash/cloneDeep';
15
15
  import { patchMetas } from './hooks/patch';
16
16
  export var findIndex = function findIndex(arr, item) {
@@ -131,7 +131,7 @@ export var getSubColumns = function getSubColumns(metaList) {
131
131
  _data.columns = _data.columns.concat(prevGroupBy.group.map(function (v) {
132
132
  var _v$sql;
133
133
  return _objectSpread(_objectSpread({}, v), {}, {
134
- name: v.fieldAlias || v.name || v.quotes,
134
+ name: v.name || v.quotes,
135
135
  name_zh: v.name_zh || v.quotes,
136
136
  id: v.id || v.fieldId,
137
137
  realName: ((_v$sql = v.sql) === null || _v$sql === void 0 || (_v$sql = _v$sql.split(' AS ')) === null || _v$sql === void 0 ? void 0 : _v$sql[1]) || '',
@@ -145,7 +145,7 @@ export var getSubColumns = function getSubColumns(metaList) {
145
145
  _data.columns = _data.columns.concat(prevGroupBy.by.map(function (v) {
146
146
  var _v$sql2;
147
147
  return _objectSpread(_objectSpread({}, v), {}, {
148
- name: v.fieldAlias || v.name || v.quotes,
148
+ name: v.name || v.quotes,
149
149
  name_zh: v.name_zh || v.quotes,
150
150
  id: v.id || v.fieldId,
151
151
  realName: ((_v$sql2 = v.sql) === null || _v$sql2 === void 0 || (_v$sql2 = _v$sql2.split(' AS ')) === null || _v$sql2 === void 0 ? void 0 : _v$sql2[1]) || '',
@@ -171,7 +171,11 @@ export var getSubColumns = function getSubColumns(metaList) {
171
171
  });
172
172
  return {
173
173
  alias: v.table2.alias,
174
- table: v.table2.name,
174
+ name: v.table2.name,
175
+ id: v.table2.id,
176
+ tableUuid: v.table2.tableUuid,
177
+ datasourceId: v.table2.datasourceId,
178
+ datasourceName: v.table2.datasourceName,
175
179
  columns: columns
176
180
  };
177
181
  }));
@@ -189,7 +193,11 @@ export var getSubColumns = function getSubColumns(metaList) {
189
193
  });
190
194
  return {
191
195
  alias: v.table.alias,
192
- table: v.table.name,
196
+ name: v.table.name,
197
+ id: v.table.id,
198
+ tableUuid: v.table.tableUuid,
199
+ datasourceId: v.table.datasourceId,
200
+ datasourceName: v.table.datasourceName,
193
201
  columns: columns
194
202
  };
195
203
  } else if (v.type === TypeEnum.joinData) {
@@ -203,7 +211,11 @@ export var getSubColumns = function getSubColumns(metaList) {
203
211
  });
204
212
  return {
205
213
  alias: v.table2.alias,
206
- table: v.table2.name,
214
+ name: v.table2.name,
215
+ id: v.table2.id,
216
+ tableUuid: v.table2.tableUuid,
217
+ datasourceId: v.table2.datasourceId,
218
+ datasourceName: v.table2.datasourceName,
207
219
  columns: _columns
208
220
  };
209
221
  } else if (v.type === TypeEnum.customColumn) {
@@ -222,7 +234,8 @@ export var getSubColumns = function getSubColumns(metaList) {
222
234
  return {
223
235
  columns: _columns2,
224
236
  alias: '',
225
- table: __('SqlQueryBuilder.customColumn')
237
+ name: __('SqlQueryBuilder.customColumn'),
238
+ id: __('SqlQueryBuilder.customColumn')
226
239
  };
227
240
  } else {
228
241
  return {
@@ -808,8 +821,7 @@ var stripSummarizeTableFields = function stripSummarizeTableFields(record) {
808
821
  tableUuid: '',
809
822
  alias: '',
810
823
  datasourceId: '',
811
- datasourceName: '',
812
- datasourceType: ''
824
+ datasourceName: ''
813
825
  });
814
826
  };
815
827
  var createSummarizeFieldAtom = function createSummarizeFieldAtom(record) {
@@ -827,7 +839,6 @@ var createSummarizeFieldAtom = function createSummarizeFieldAtom(record) {
827
839
  tableUuid: record.tableUuid || '',
828
840
  datasourceName: record.datasourceName || '',
829
841
  datasourceId: record.datasourceId || '',
830
- datasourceType: record.datasourceType || '',
831
842
  type: AtomsTypeEnum.FIELD
832
843
  };
833
844
  };
@@ -986,17 +997,21 @@ var _isError = function isError(item, data) {
986
997
  return true;
987
998
  } else {
988
999
  var _tables$_datasourceId2;
989
- return tables === null || tables === void 0 || (_tables$_datasourceId2 = tables[_datasourceId]) === null || _tables$_datasourceId2 === void 0 || (_tables$_datasourceId2 = _tables$_datasourceId2[tableId]) === null || _tables$_datasourceId2 === void 0 ? void 0 : _tables$_datasourceId2.every(function (field) {
990
- if (field.id === undefined) {
991
- return field.name !== fieldName;
992
- }
993
- return field.name !== fieldName || field.id !== fieldId;
1000
+ var fields = (tables === null || tables === void 0 || (_tables$_datasourceId2 = tables[_datasourceId]) === null || _tables$_datasourceId2 === void 0 ? void 0 : _tables$_datasourceId2[tableId + tableAlias]) || [];
1001
+ return fields.every(function (field) {
1002
+ return !isSameColumnByIdFirst(_objectSpread(_objectSpread({}, field), {}, {
1003
+ datasourceId: _datasourceId,
1004
+ tableId: tableId
1005
+ }), item);
994
1006
  });
995
1007
  }
996
1008
  } else {
997
1009
  var _tables$_datasourceId3, _tables$_datasourceId4;
998
1010
  var hasField = (_tables$_datasourceId3 = tables === null || tables === void 0 || (_tables$_datasourceId4 = tables[_datasourceId]) === null || _tables$_datasourceId4 === void 0 || (_tables$_datasourceId4 = _tables$_datasourceId4[tableId + tableAlias]) === null || _tables$_datasourceId4 === void 0 ? void 0 : _tables$_datasourceId4.some(function (v) {
999
- return v.name === fieldName && (v.id === undefined || v.id === fieldId);
1011
+ return isSameColumnByIdFirst(_objectSpread(_objectSpread({}, v), {}, {
1012
+ datasourceId: _datasourceId,
1013
+ tableId: tableId
1014
+ }), item);
1000
1015
  })) !== null && _tables$_datasourceId3 !== void 0 ? _tables$_datasourceId3 : false;
1001
1016
  return !hasField;
1002
1017
  }
@@ -1085,19 +1100,24 @@ function setNewField(field, data) {
1085
1100
  try {
1086
1101
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1087
1102
  var table = _step3.value;
1088
- if (table.name !== field.tableName) {
1103
+ if (!isSameTableByIdFirst(table, {
1104
+ datasourceId: field.datasourceId,
1105
+ id: field.tableId,
1106
+ name: field.tableName,
1107
+ alias: field.tableAlias,
1108
+ tableUuid: field.tableUuid
1109
+ })) {
1089
1110
  continue;
1090
1111
  }
1091
1112
  field.datasourceId = table.datasourceId || '';
1092
1113
  field.datasourceName = table.datasourceName || '';
1093
- field.datasourceType = table.datasourceType || '';
1094
1114
  field.tableId = table.id || '';
1095
1115
  field.tableName = table.name || '';
1096
1116
  field.tableAlias = table.alias || '';
1097
1117
  field.tableUuid = table.tableUuid || '';
1098
1118
  field.tableNameZh = table.name_zh || '';
1099
1119
  var matchedColumn = table.columns.find(function (col) {
1100
- return col.name === field.fieldName;
1120
+ return isSameColumnByIdFirst(col, field);
1101
1121
  });
1102
1122
  if (matchedColumn) {
1103
1123
  field.fieldId = matchedColumn.id || '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.130",
3
+ "version": "1.0.131",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",