@gingkoo/pandora-metabase 1.0.137 → 1.0.139

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.
@@ -1,3 +1,39 @@
1
+ .scroller::-webkit-scrollbar {
2
+ width: 4px;
3
+ height: 100%;
4
+ background: transparent;
5
+ }
6
+
7
+ .scroller::-webkit-scrollbar-thumb {
8
+ background: rgba(100, 100, 100, 0.4);
9
+ border-radius: 2px;
10
+
11
+ &:hover {
12
+ background: rgba(100, 100, 100, 0.7);
13
+ }
14
+ }
15
+
16
+ .scroller-x::-webkit-scrollbar {
17
+ width: 100%;
18
+ height: 8px;
19
+ background: transparent;
20
+ }
21
+
22
+ .scroller.scroller-x::-webkit-scrollbar {
23
+ width: 4px;
24
+ height: 8px;
25
+ background: transparent;
26
+ }
27
+
28
+ .scroller-x::-webkit-scrollbar-thumb {
29
+ background: rgba(100, 100, 100, 0.4);
30
+ border-radius: 2px;
31
+
32
+ &:hover {
33
+ background: rgba(100, 100, 100, 0.7);
34
+ }
35
+ }
36
+
1
37
  .mx-4 {
2
38
  margin-left: 1rem;
3
39
  margin-right: 1rem;
@@ -17,7 +17,7 @@ import Popup from '../popup';
17
17
  import { useStore } from '../../hooks/use-provider';
18
18
  import storage from '../../utils/storage';
19
19
  var VisualBox = Styled.div.attrs({
20
- className: 'visual-box'
20
+ className: 'visual-box scroller'
21
21
  })(_templateObject || (_templateObject = _taggedTemplateLiteral([""])));
22
22
  var Metabase = function Metabase(props) {
23
23
  var _props$btnText = props.btnText,
@@ -32,7 +32,19 @@ import { SelectTable, SelectJoin, SelectColumnMultiple, SelectColumn, Expression
32
32
  import { ExclamationCircleFill } from '@gingkoo/pandora-icons';
33
33
  import { useStore } from '../../hooks/use-provider';
34
34
  var PrevResult = 'Previous results';
35
- var operators = ['AND', 'OR', '(', ')', ',', '+', '-', '*', '/', '!=', '<=', '>=', '<', '>', '='];
35
+ var normalizeJoinOperator = function normalizeJoinOperator(val) {
36
+ return String(val).toUpperCase() === 'OR' ? 'OR' : 'AND';
37
+ };
38
+ var isJoinOperator = function isJoinOperator(item) {
39
+ return (item === null || item === void 0 ? void 0 : item.type) === AtomsTypeEnum.OPERATOR;
40
+ };
41
+ var menuJoinOperator = [{
42
+ key: 'AND',
43
+ label: 'AND'
44
+ }, {
45
+ key: 'OR',
46
+ label: 'OR'
47
+ }];
36
48
  var FlagLocation;
37
49
  (function (FlagLocation) {
38
50
  FlagLocation["TABLE_1"] = "table1";
@@ -44,7 +56,7 @@ var ExpressionsEnum;
44
56
  ExpressionsEnum["RIGHT"] = "rhs";
45
57
  })(ExpressionsEnum || (ExpressionsEnum = {}));
46
58
  var getText = function getText(v) {
47
- return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, AtomsTypeEnum.JOIN_DEFAULT, 'joinData.default'), AtomsTypeEnum.EXPRESSION, 'joinData.expression'), AtomsTypeEnum.OPERATOR, 'customColumn.operator'), AtomsTypeEnum.COLLECTION, 'customColumn.collection')[v];
59
+ return _defineProperty(_defineProperty(_defineProperty({}, AtomsTypeEnum.JOIN_DEFAULT, 'joinData.default'), AtomsTypeEnum.EXPRESSION, 'joinData.expression'), AtomsTypeEnum.COLLECTION, 'customColumn.collection')[v];
48
60
  };
49
61
  var menuTypes = [{
50
62
  key: AtomsTypeEnum.JOIN_DEFAULT,
@@ -52,19 +64,10 @@ var menuTypes = [{
52
64
  }, {
53
65
  key: AtomsTypeEnum.EXPRESSION,
54
66
  label: __(getText(AtomsTypeEnum.EXPRESSION))
55
- }, {
56
- key: AtomsTypeEnum.OPERATOR,
57
- label: __(getText(AtomsTypeEnum.OPERATOR))
58
67
  }, {
59
68
  key: AtomsTypeEnum.COLLECTION,
60
69
  label: __(getText(AtomsTypeEnum.COLLECTION))
61
70
  }];
62
- var menuOperator = operators.map(function (v) {
63
- return {
64
- key: v,
65
- label: v
66
- };
67
- });
68
71
  var JoinData = function JoinData(props) {
69
72
  var _meta$subquery, _meta$subquery2, _meta$subquery3, _meta$table4, _meta$table5, _meta$table7, _meta$table8, _meta$table9, _meta$table0, _meta$expressions, _meta$table1, _meta$table10, _meta$expressions2, _store$showMainColumn, _store$showMainColumn2;
70
73
  var meta = props.meta,
@@ -125,6 +128,26 @@ var JoinData = function JoinData(props) {
125
128
  tableIsDel();
126
129
  }, 0);
127
130
  }, [meta]);
131
+ useEffect(function () {
132
+ var expressions = meta.expressions || [];
133
+ var hasInvalidOperator = expressions.some(function (item) {
134
+ return item.type === AtomsTypeEnum.OPERATOR && item.val !== normalizeJoinOperator(item.val);
135
+ });
136
+ if (!hasInvalidOperator) {
137
+ return;
138
+ }
139
+ var currentIndex = findIndex(store.metaList[groupIndex].list, meta);
140
+ var newMeta = store.metaList[groupIndex].list.slice();
141
+ newMeta[currentIndex].expressions = expressions.map(function (item) {
142
+ if (item.type !== AtomsTypeEnum.OPERATOR) {
143
+ return item;
144
+ }
145
+ return _objectSpread(_objectSpread({}, item), {}, {
146
+ val: normalizeJoinOperator(item.val)
147
+ });
148
+ });
149
+ store.setMeta(newMeta, groupIndex);
150
+ }, [meta.expressions]);
128
151
  var getTableColumns = function getTableColumns() {
129
152
  var data = [];
130
153
  var _getHelper2 = getHelper(store.metaList[groupIndex].list, meta),
@@ -968,7 +991,8 @@ var JoinData = function JoinData(props) {
968
991
  var _store$preProps3;
969
992
  newMeta[index].subquery = newList;
970
993
  newMeta[index].table2 = _objectSpread(_objectSpread({}, newList[0].table), {}, {
971
- alias: newMeta[index].table2.alias || getAlias(newList[0].table.name, newMeta, ((_store$preProps3 = store.preProps) === null || _store$preProps3 === void 0 ? void 0 : _store$preProps3.notExistsColumns) || [])
994
+ alias: newMeta[index].table2.alias || getAlias(newList[0].table.name, newMeta, ((_store$preProps3 = store.preProps) === null || _store$preProps3 === void 0 ? void 0 : _store$preProps3.notExistsColumns) || []),
995
+ tableUuid: newMeta[index].table2.tableUuid || uuidv4('table')
972
996
  });
973
997
  var items = getSubColumns(newList);
974
998
  var subQueryTable = newMeta[index].table2;
@@ -1059,10 +1083,26 @@ var JoinData = function JoinData(props) {
1059
1083
  onCancel: function onCancel() {}
1060
1084
  });
1061
1085
  };
1086
+ var cleanJoinOperators = function cleanJoinOperators(expressions) {
1087
+ for (var i = expressions.length - 1; i >= 0; i--) {
1088
+ if (isJoinOperator(expressions[i]) && (i === 0 || i === expressions.length - 1 || isJoinOperator(expressions[i - 1]))) {
1089
+ expressions.splice(i, 1);
1090
+ }
1091
+ }
1092
+ };
1062
1093
  var changeOperator = function changeOperator(key, i) {
1063
1094
  var index = findIndex(store.metaList[groupIndex].list, meta);
1064
1095
  var newMeta = store.metaList[groupIndex].list.slice();
1065
- newMeta[index].expressions[i].val = key;
1096
+ var operator = newMeta[index].expressions[i];
1097
+ operator.val = normalizeJoinOperator(key);
1098
+ store.setMeta(newMeta, groupIndex);
1099
+ };
1100
+ var removeExpression = function removeExpression(i) {
1101
+ var index = findIndex(store.metaList[groupIndex].list, meta);
1102
+ var newMeta = store.metaList[groupIndex].list.slice();
1103
+ var expressions = newMeta[index].expressions;
1104
+ expressions.splice(i, 1);
1105
+ cleanJoinOperators(expressions);
1066
1106
  store.setMeta(newMeta, groupIndex);
1067
1107
  };
1068
1108
  var changeExpression = function changeExpression(e, i) {
@@ -1128,19 +1168,15 @@ var JoinData = function JoinData(props) {
1128
1168
  }],
1129
1169
  type: type
1130
1170
  };
1131
- store.setMeta(newMeta, groupIndex);
1132
- }
1133
- if (type === AtomsTypeEnum.OPERATOR) {
1134
- item = {
1135
- val: 'AND',
1136
- type: type
1137
- };
1138
1171
  }
1139
1172
  if (!item) {
1140
1173
  return;
1141
1174
  }
1142
1175
  if (i >= 0) {
1143
- newMeta[index].expressions.splice(i + 1, 0, item);
1176
+ newMeta[index].expressions.splice(i + 1, 0, {
1177
+ val: 'AND',
1178
+ type: AtomsTypeEnum.OPERATOR
1179
+ }, item);
1144
1180
  } else {
1145
1181
  newMeta[index].expressions.push(item);
1146
1182
  }
@@ -1455,16 +1491,14 @@ var JoinData = function JoinData(props) {
1455
1491
  className: 'mr-2 operator-icon',
1456
1492
  icon: _jsx(FfLine, {}),
1457
1493
  onClick: function onClick() {
1458
- var index = findIndex(store.metaList[groupIndex].list, meta);
1459
- var newMeta = store.metaList[groupIndex].list.slice();
1460
- newMeta[index].expressions.splice(i, 1);
1461
- store.setMeta(newMeta, groupIndex);
1494
+ removeExpression(i);
1462
1495
  }
1463
1496
  })
1464
1497
  })]
1465
1498
  }, i);
1466
1499
  }
1467
1500
  if (v.type === AtomsTypeEnum.OPERATOR) {
1501
+ var operator = normalizeJoinOperator(v.val);
1468
1502
  return _jsxs("div", {
1469
1503
  className: cx("Sqb-where block"),
1470
1504
  children: [i == 0 && _jsx("span", {
@@ -1475,41 +1509,12 @@ var JoinData = function JoinData(props) {
1475
1509
  onChange: function onChange(key) {
1476
1510
  changeOperator(key, i);
1477
1511
  },
1478
- droplist: menuOperator,
1512
+ droplist: menuJoinOperator,
1479
1513
  children: _jsx(Button, {
1514
+ disabled: meta.readonly,
1480
1515
  className: 'ml-2 mr-4 text-gray-500',
1481
1516
  type: 'link',
1482
- children: v.val
1483
- })
1484
- }), _jsx(Tooltip, {
1485
- title: __('SqlQueryBuilder.add'),
1486
- children: _jsx(Dropdown, {
1487
- trigger: ['click'],
1488
- onChange: function onChange(key) {
1489
- addExpression(key, i);
1490
- },
1491
- droplist: menuTypes,
1492
- children: _jsx(Button, {
1493
- disabled: meta.readonly,
1494
- primary: true,
1495
- ghost: true,
1496
- className: 'mr-2 operator-icon',
1497
- icon: _jsx(FfPlus, {})
1498
- })
1499
- })
1500
- }), _jsx(Tooltip, {
1501
- title: __('SqlQueryBuilder.del'),
1502
- children: _jsx(Button, {
1503
- disabled: meta.readonly,
1504
- danger: true,
1505
- className: 'mr-2 operator-icon',
1506
- icon: _jsx(FfLine, {}),
1507
- onClick: function onClick() {
1508
- var index = findIndex(store.metaList[groupIndex].list, meta);
1509
- var newMeta = store.metaList[groupIndex].list.slice();
1510
- newMeta[index].expressions.splice(i, 1);
1511
- store.setMeta(newMeta, groupIndex);
1512
- }
1517
+ children: operator
1513
1518
  })
1514
1519
  })]
1515
1520
  }, i);
@@ -1555,10 +1560,7 @@ var JoinData = function JoinData(props) {
1555
1560
  className: 'mr-2 operator-icon',
1556
1561
  icon: _jsx(FfLine, {}),
1557
1562
  onClick: function onClick() {
1558
- var index = findIndex(store.metaList[groupIndex].list, meta);
1559
- var newMeta = store.metaList[groupIndex].list.slice();
1560
- newMeta[index].expressions.splice(i, 1);
1561
- store.setMeta(newMeta, groupIndex);
1563
+ removeExpression(i);
1562
1564
  }
1563
1565
  })
1564
1566
  })]
@@ -1609,10 +1611,7 @@ var JoinData = function JoinData(props) {
1609
1611
  className: 'mr-2 operator-icon',
1610
1612
  icon: _jsx(FfLine, {}),
1611
1613
  onClick: function onClick() {
1612
- var index = findIndex(store.metaList[groupIndex].list, meta);
1613
- var newMeta = store.metaList[groupIndex].list.slice();
1614
- newMeta[index].expressions.splice(i, 1);
1615
- store.setMeta(newMeta, groupIndex);
1614
+ removeExpression(i);
1616
1615
  }
1617
1616
  })
1618
1617
  })]
@@ -112,11 +112,7 @@ export var isSameColumnByIdFirst = function isSameColumnByIdFirst() {
112
112
  var leftTableUuid = normalizeId(left.tableUuid);
113
113
  var rightTableUuid = normalizeId(right.tableUuid);
114
114
  if (hasBoth(leftTableUuid, rightTableUuid) && leftTableUuid !== rightTableUuid) {
115
- var leftTableName = normalizeId(left.tableName || left.table);
116
- var rightTableName = normalizeId(right.tableName || right.table);
117
- if (!hasBoth(leftTableName, rightTableName) || leftTableName !== rightTableName) {
118
- return false;
119
- }
115
+ return false;
120
116
  }
121
117
  var leftFieldId = normalizeId(left.fieldId || left.id);
122
118
  var rightFieldId = normalizeId(right.fieldId || right.id);
package/lib/es/utils.d.ts CHANGED
@@ -4,6 +4,7 @@ import { DataType } from './components/dialog/select-column-multiple';
4
4
  export declare const findIndex: <T>(arr: T[], item: T) => number;
5
5
  export declare const findMetaKey: <T>(arr: T[], item: T) => number;
6
6
  export declare const getMetaTabels: (data: MetaListType[]) => any;
7
+ export declare const getSubQueryColumnInstanceUuid: (column: any, tableUuid?: string) => string;
7
8
  export declare const getColumnsTables: (data: DataType[]) => any;
8
9
  interface HelperResultType {
9
10
  ExistAboveGroupBy: boolean;
package/lib/es/utils.js CHANGED
@@ -7,7 +7,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
7
7
  var _excluded = ["list"];
8
8
  import { __, isEn } from './locale';
9
9
  import { TypeEnum, SQL_COLUMN_TYPE } from './store/enum';
10
- import { AtomsTypeEnum } from './store/types';
10
+ import { MetaSummarize_Enum, AtomsTypeEnum } from './store/types';
11
11
  import { SummarizeAlias, summarizeByToSql, summarizeToSql } from './store/helper';
12
12
  import { transformSql } from './utils/transformSql';
13
13
  import { isSameColumnByIdFirst, isSameTableByIdFirst, uuidv4 } from './utils/helper';
@@ -40,6 +40,15 @@ var SUB_QUERY_OUTPUT_COLUMN_KEY = '__subQueryOutputColumn';
40
40
  var isSubQueryOutputColumn = function isSubQueryOutputColumn(column) {
41
41
  return Boolean((column === null || column === void 0 ? void 0 : column.summarizeType) && (column === null || column === void 0 ? void 0 : column[SUB_QUERY_OUTPUT_COLUMN_KEY]));
42
42
  };
43
+ var getSubQueryColumnSourceKey = function getSubQueryColumnSourceKey(column) {
44
+ var columnMeta = column;
45
+ return [column.datasourceId || '', column.tableUuid || '', column.tableId || '', column.table || columnMeta.tableName || '', columnMeta.fieldId || column.id || '', column.name || '', column.realName || ''].join('|');
46
+ };
47
+ export var getSubQueryColumnInstanceUuid = function getSubQueryColumnInstanceUuid(column) {
48
+ var tableUuid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
49
+ var sourceKey = getSubQueryColumnSourceKey(column);
50
+ return [tableUuid || column.tableUuid || '', column.summarizeType || '', sourceKey].join('|');
51
+ };
43
52
  export var getColumnsTables = function getColumnsTables(data) {
44
53
  var obj = {};
45
54
  data.map(function (v) {
@@ -137,7 +146,8 @@ var normalizeSubQueryColumn = function normalizeSubQueryColumn(column) {
137
146
  name_zh: column.name_zh || column.quotes || '',
138
147
  id: column.id || column.fieldId || outputName,
139
148
  realName: column.realName || column.name || '',
140
- fieldAlias: ''
149
+ fieldAlias: '',
150
+ fieldUuid: column.fieldUuid || getSubQueryColumnInstanceUuid(column)
141
151
  });
142
152
  };
143
153
  var getOuterSubQueryFieldAlias = function getOuterSubQueryFieldAlias(existingCol, newCol) {
@@ -171,6 +181,20 @@ var isSameSubQueryOutputColumn = function isSameSubQueryOutputColumn(oldCol, new
171
181
  var newIdentity = getSubQueryOutputIdentity(newCol);
172
182
  return Boolean(oldIdentity && newIdentity && oldIdentity === newIdentity);
173
183
  };
184
+ var isSameColumnTableInstance = function isSameColumnTableInstance(oldCol, newCol) {
185
+ var oldColumn = oldCol;
186
+ var newColumn = newCol;
187
+ if (oldColumn.tableUuid && newColumn.tableUuid) {
188
+ return oldColumn.tableUuid === newColumn.tableUuid;
189
+ }
190
+ if (oldColumn.datasourceId && newColumn.datasourceId && oldColumn.datasourceId !== newColumn.datasourceId) {
191
+ return false;
192
+ }
193
+ if (oldColumn.tableId && newColumn.tableId && oldColumn.tableId !== newColumn.tableId) {
194
+ return false;
195
+ }
196
+ return true;
197
+ };
174
198
  export var mergeSubQueryColumns = function mergeSubQueryColumns(columns) {
175
199
  var oldColumns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
176
200
  var isSelectFields = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -178,6 +202,9 @@ export var mergeSubQueryColumns = function mergeSubQueryColumns(columns) {
178
202
  var newColumn = newCol;
179
203
  var existingCol = oldColumns.find(function (oldCol) {
180
204
  var oldColumn = oldCol;
205
+ if (!isSameColumnTableInstance(oldCol, newCol)) {
206
+ return false;
207
+ }
181
208
  if (oldColumn.fieldUuid && newColumn.fieldUuid) {
182
209
  return oldColumn.fieldUuid === newColumn.fieldUuid;
183
210
  }
@@ -392,6 +419,7 @@ export var getSubColumns = function getSubColumns(metaList) {
392
419
  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]) || '',
393
420
  database_type: (v === null || v === void 0 ? void 0 : v.database_type) || SQL_COLUMN_TYPE.FLOAT,
394
421
  special_type: '',
422
+ summarizeType: MetaSummarize_Enum.GROUP,
395
423
  select: true
396
424
  }));
397
425
  }));
@@ -404,6 +432,7 @@ export var getSubColumns = function getSubColumns(metaList) {
404
432
  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]) || '',
405
433
  database_type: (v === null || v === void 0 ? void 0 : v.database_type) || SQL_COLUMN_TYPE.FLOAT,
406
434
  special_type: '',
435
+ summarizeType: MetaSummarize_Enum.BY,
407
436
  select: true
408
437
  }));
409
438
  }));
@@ -754,8 +783,8 @@ var syncAtomQuotesList = function syncAtomQuotesList(items) {
754
783
  return items.map(syncAtomQuotes);
755
784
  };
756
785
  var isSameAliasTargetTable = function isSameAliasTargetTable(item, target) {
757
- if (target.tableUuid && item.tableUuid && item.tableUuid === target.tableUuid) {
758
- return true;
786
+ if (target.tableUuid && item.tableUuid) {
787
+ return item.tableUuid === target.tableUuid;
759
788
  }
760
789
  if (target.datasourceId && item.datasourceId && item.datasourceId !== target.datasourceId) {
761
790
  return false;
@@ -766,15 +795,32 @@ var isSameAliasTargetTable = function isSameAliasTargetTable(item, target) {
766
795
  return Boolean(target.tableName && item.tableName && item.tableName === target.tableName);
767
796
  };
768
797
  var isAliasTargetField = function isAliasTargetField(item, target) {
798
+ var sameTable = isSameAliasTargetTable(item, target);
769
799
  if (target.uuid && item.fieldUuid && item.fieldUuid === target.uuid) {
770
- return true;
800
+ return sameTable || !(target.tableUuid || target.tableId || target.tableName);
771
801
  }
772
- var sameTable = isSameAliasTargetTable(item, target);
773
802
  if (target.fieldId && item.fieldId && item.fieldId === target.fieldId) {
774
803
  return sameTable || !target.tableId;
775
804
  }
776
805
  return Boolean(target.fieldName && item.fieldName && item.fieldName === target.fieldName && sameTable);
777
806
  };
807
+ var isAliasTargetSummarizeRecord = function isAliasTargetSummarizeRecord(record, target) {
808
+ return isAliasTargetField({
809
+ fieldName: record.name || '',
810
+ fieldNameZh: record.name_zh || '',
811
+ fieldAlias: record.fieldAlias || '',
812
+ fieldUuid: record.fieldUuid || '',
813
+ fieldId: record.fieldId || record.id || '',
814
+ tableName: record.table || '',
815
+ tableNameZh: '',
816
+ tableId: record.tableId || '',
817
+ tableAlias: record.alias || '',
818
+ tableUuid: record.tableUuid || '',
819
+ datasourceName: record.datasourceName || '',
820
+ datasourceId: record.datasourceId || '',
821
+ type: AtomsTypeEnum.FIELD
822
+ }, target);
823
+ };
778
824
  var _changeAlias = function changeAlias(items, val, type) {
779
825
  return items.map(function (v) {
780
826
  var nextItem;
@@ -1004,7 +1050,7 @@ export var changeFieldAlias = function changeFieldAlias(list, curObj) {
1004
1050
  if (groupAtoms && groupAtoms.length > 0) {
1005
1051
  group.atoms = _changeAlias(groupAtoms, aliasTarget, AliasType.field);
1006
1052
  group.sql = summarizeToSql(v.group, group).sql;
1007
- } else if (group.fieldUuid === uuid) {
1053
+ } else if (isAliasTargetSummarizeRecord(group, aliasTarget)) {
1008
1054
  group.fieldAlias = alias;
1009
1055
  group.sql = summarizeToSql(v.group, group).sql;
1010
1056
  }
@@ -1013,7 +1059,7 @@ export var changeFieldAlias = function changeFieldAlias(list, curObj) {
1013
1059
  if (by.atoms && by.atoms.length > 0) {
1014
1060
  by.atoms = _changeAlias(by.atoms, aliasTarget, AliasType.field);
1015
1061
  by.sql = summarizeByToSql(by);
1016
- } else if (by.fieldUuid === uuid) {
1062
+ } else if (isAliasTargetSummarizeRecord(by, aliasTarget)) {
1017
1063
  by.fieldAlias = alias;
1018
1064
  by.sql = summarizeByToSql(by);
1019
1065
  }
@@ -1237,12 +1283,60 @@ var hasLoadedColumnData = function hasLoadedColumnData() {
1237
1283
  return Array.isArray(table === null || table === void 0 ? void 0 : table.columns) && table.columns.length > 0;
1238
1284
  });
1239
1285
  };
1286
+ var normalizeIdentityValue = function normalizeIdentityValue(val) {
1287
+ if (val === undefined || val === null) return '';
1288
+ return "".concat(val);
1289
+ };
1290
+ var isSourceLikeDatasource = function isSourceLikeDatasource(datasourceId) {
1291
+ return !datasourceId || datasourceId === 'source';
1292
+ };
1293
+ var isSameErrorCheckTable = function isSameErrorCheckTable(table, item) {
1294
+ var itemDatasourceId = normalizeIdentityValue(item.datasourceId);
1295
+ var tableDatasourceId = normalizeIdentityValue(table.datasourceId);
1296
+ if (!isSourceLikeDatasource(itemDatasourceId) && !isSourceLikeDatasource(tableDatasourceId) && itemDatasourceId !== tableDatasourceId) {
1297
+ return false;
1298
+ }
1299
+ var itemTableId = normalizeIdentityValue(item.tableId);
1300
+ var tableId = normalizeIdentityValue(table.id);
1301
+ if (itemTableId && tableId && itemTableId !== tableId) {
1302
+ return false;
1303
+ }
1304
+ var itemTableAlias = normalizeIdentityValue(item.tableAlias);
1305
+ var tableAlias = normalizeIdentityValue(table.alias);
1306
+ if (itemTableAlias && tableAlias && itemTableAlias !== tableAlias) {
1307
+ return false;
1308
+ }
1309
+ var itemTableName = normalizeIdentityValue(item.tableName);
1310
+ var tableName = normalizeIdentityValue(table.name);
1311
+ return Boolean(itemTableId && tableId && itemTableId === tableId || itemTableAlias && tableAlias && itemTableAlias === tableAlias || item.tableUuid && table.tableUuid && item.tableUuid === table.tableUuid || itemTableName && tableName && itemTableName === tableName);
1312
+ };
1313
+ var isSameErrorCheckColumn = function isSameErrorCheckColumn(field, item) {
1314
+ if (isSameColumnByIdFirst(field, item)) {
1315
+ return true;
1316
+ }
1317
+ if (!(field !== null && field !== void 0 && field.summarizeType)) {
1318
+ return false;
1319
+ }
1320
+ var itemValues = [item.fieldId, item.id, item.fieldUuid, item.fieldName, item.fieldAlias].map(normalizeIdentityValue).filter(Boolean);
1321
+ var fieldValues = [field.fieldId, field.id, field.fieldUuid, field.fieldName, field.name, field.fieldAlias, field.realName].map(normalizeIdentityValue).filter(Boolean);
1322
+ return itemValues.some(function (value) {
1323
+ return fieldValues.includes(value);
1324
+ });
1325
+ };
1326
+ var getErrorCheckFields = function getErrorCheckFields(item, data) {
1327
+ var tables = data.filter(function (table) {
1328
+ return isSameErrorCheckTable(table, item);
1329
+ });
1330
+ if (!tables.length) return null;
1331
+ return tables.flatMap(function (table) {
1332
+ return table.columns || [];
1333
+ });
1334
+ };
1240
1335
  var _isError = function isError(item) {
1241
1336
  var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1242
1337
  if (!hasLoadedColumnData(data)) {
1243
1338
  return false;
1244
1339
  }
1245
- var tables = getColumnsTables(data);
1246
1340
  if (!item) {
1247
1341
  return false;
1248
1342
  }
@@ -1252,49 +1346,21 @@ var _isError = function isError(item) {
1252
1346
  });
1253
1347
  }
1254
1348
  if (item.type === AtomsTypeEnum.FIELD) {
1255
- var datasourceId = item.datasourceId,
1256
- _item$tableId = item.tableId,
1257
- tableId = _item$tableId === void 0 ? '' : _item$tableId,
1258
- _item$tableAlias = item.tableAlias,
1259
- tableAlias = _item$tableAlias === void 0 ? '' : _item$tableAlias,
1260
- fieldName = item.fieldName,
1261
- fieldId = item.fieldId;
1262
- var _datasourceId = datasourceId || 'source';
1263
- if (tableId === 'source') {
1264
- _datasourceId = 'source';
1265
- }
1349
+ var _item$tableId = item.tableId,
1350
+ tableId = _item$tableId === void 0 ? '' : _item$tableId;
1266
1351
  if (!tableId) {
1267
1352
  return false;
1268
1353
  }
1269
- if (_datasourceId === 'source') {
1270
- var _tables$_datasourceId;
1271
- var fields = tables === null || tables === void 0 || (_tables$_datasourceId = tables[_datasourceId]) === null || _tables$_datasourceId === void 0 ? void 0 : _tables$_datasourceId[tableId + tableAlias];
1272
- if (!fields) {
1273
- return true;
1274
- } else if (!fields.length) {
1275
- return false;
1276
- } else {
1277
- return fields.every(function (field) {
1278
- return !isSameColumnByIdFirst(_objectSpread(_objectSpread({}, field), {}, {
1279
- datasourceId: _datasourceId,
1280
- tableId: tableId
1281
- }), item);
1282
- });
1283
- }
1284
- } else {
1285
- var _tables$_datasourceId2, _fields$some;
1286
- var _fields = tables === null || tables === void 0 || (_tables$_datasourceId2 = tables[_datasourceId]) === null || _tables$_datasourceId2 === void 0 ? void 0 : _tables$_datasourceId2[tableId + tableAlias];
1287
- if (_fields && !_fields.length) {
1288
- return false;
1289
- }
1290
- var hasField = (_fields$some = _fields === null || _fields === void 0 ? void 0 : _fields.some(function (v) {
1291
- return isSameColumnByIdFirst(_objectSpread(_objectSpread({}, v), {}, {
1292
- datasourceId: _datasourceId,
1293
- tableId: tableId
1294
- }), item);
1295
- })) !== null && _fields$some !== void 0 ? _fields$some : false;
1296
- return !hasField;
1354
+ var fields = getErrorCheckFields(item, data);
1355
+ if (!fields) {
1356
+ return true;
1297
1357
  }
1358
+ if (!fields.length) {
1359
+ return false;
1360
+ }
1361
+ return !fields.some(function (field) {
1362
+ return isSameErrorCheckColumn(field, item);
1363
+ });
1298
1364
  }
1299
1365
  if (item.type === AtomsTypeEnum.EXPRESSION) {
1300
1366
  var lhsHasError = _isError(item.lhs, data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.137",
3
+ "version": "1.0.139",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",