@gingkoo/pandora-metabase 1.0.26 → 1.0.28

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 (66) hide show
  1. package/lib/cjs/common/SplitView/index.js +11 -12
  2. package/lib/cjs/components/dialog/custom-column/expression-editor.js +1 -2
  3. package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +1 -2
  4. package/lib/cjs/components/dialog/expression/index.js +11 -12
  5. package/lib/cjs/components/dialog/formula-list/index.js +53 -43
  6. package/lib/cjs/components/dialog/index.js +2 -2
  7. package/lib/cjs/components/dialog/select-column/index.js +4 -4
  8. package/lib/cjs/components/dialog/select-column-multiple/index.js +7 -7
  9. package/lib/cjs/components/dialog/select-join-column/index.js +4 -0
  10. package/lib/cjs/components/dialog/select-permission-table/index.js +2 -2
  11. package/lib/cjs/components/dialog/select-table/index.js +7 -7
  12. package/lib/cjs/components/icons.js +36 -36
  13. package/lib/cjs/components/metabase/index.js +41 -12
  14. package/lib/cjs/components/metabase/index.less +3 -0
  15. package/lib/cjs/components/modules/components/Wrapper.js +6 -6
  16. package/lib/cjs/components/modules/components/item-name.d.ts +7 -0
  17. package/lib/cjs/components/modules/components/item-name.js +34 -0
  18. package/lib/cjs/components/modules/components/meta-icon.js +6 -0
  19. package/lib/cjs/components/modules/custom-column.js +25 -25
  20. package/lib/cjs/components/modules/filter.js +2 -2
  21. package/lib/cjs/components/modules/join-data.js +206 -80
  22. package/lib/cjs/components/modules/permission-table.js +24 -10
  23. package/lib/cjs/components/modules/sort.js +17 -13
  24. package/lib/cjs/components/modules/summarize/group-by.js +90 -38
  25. package/lib/cjs/components/modules/summarize/select-index.js +84 -38
  26. package/lib/cjs/components/modules/table-data.js +14 -6
  27. package/lib/cjs/components/popup.js +1 -2
  28. package/lib/cjs/hooks/use-state.js +58 -65
  29. package/lib/cjs/index.js +1 -2
  30. package/lib/cjs/locale/en.js +5 -2
  31. package/lib/cjs/locale/zh.js +5 -2
  32. package/lib/cjs/utils/transformSql.d.ts +6 -0
  33. package/lib/cjs/utils/transformSql.js +968 -0
  34. package/lib/cjs/utils.d.ts +7 -1
  35. package/lib/cjs/utils.js +112 -15
  36. package/lib/es/common/SplitView/index.js +10 -10
  37. package/lib/es/components/dialog/expression/index.js +10 -10
  38. package/lib/es/components/dialog/formula-list/index.js +54 -44
  39. package/lib/es/components/dialog/select-column/index.js +4 -4
  40. package/lib/es/components/dialog/select-column-multiple/index.js +7 -7
  41. package/lib/es/components/dialog/select-join-column/index.js +4 -0
  42. package/lib/es/components/dialog/select-permission-table/index.js +2 -2
  43. package/lib/es/components/dialog/select-table/index.js +7 -7
  44. package/lib/es/components/icons.js +36 -36
  45. package/lib/es/components/metabase/index.js +42 -13
  46. package/lib/es/components/metabase/index.less +3 -0
  47. package/lib/es/components/modules/components/Wrapper.js +6 -6
  48. package/lib/es/components/modules/components/item-name.d.ts +7 -0
  49. package/lib/es/components/modules/components/item-name.js +28 -0
  50. package/lib/es/components/modules/components/meta-icon.js +6 -0
  51. package/lib/es/components/modules/custom-column.js +26 -26
  52. package/lib/es/components/modules/filter.js +2 -2
  53. package/lib/es/components/modules/join-data.js +207 -81
  54. package/lib/es/components/modules/permission-table.js +24 -10
  55. package/lib/es/components/modules/sort.js +18 -14
  56. package/lib/es/components/modules/summarize/group-by.js +92 -40
  57. package/lib/es/components/modules/summarize/select-index.js +86 -40
  58. package/lib/es/components/modules/table-data.js +14 -6
  59. package/lib/es/hooks/use-state.js +58 -65
  60. package/lib/es/locale/en.js +5 -2
  61. package/lib/es/locale/zh.js +5 -2
  62. package/lib/es/utils/transformSql.d.ts +6 -0
  63. package/lib/es/utils/transformSql.js +961 -0
  64. package/lib/es/utils.d.ts +7 -1
  65. package/lib/es/utils.js +102 -4
  66. package/package.json +1 -1
package/lib/es/utils.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { TypeEnum } from './store/enum';
2
- import { MetaListType, MetaSummarize, MetaData_TableType, MetaData_ColumnsType } from './store/types';
2
+ import { MetaListType, MetaSummarize, MetaData_TableType, MetaData_ColumnsType, AtomsItem } from './store/types';
3
3
  import { DataType } from './components/dialog/select-column-multiple';
4
4
  export declare const findIndex: <T>(arr: T[], item: T) => number;
5
+ export declare const getMetaTabels: (data: MetaListType[]) => any;
6
+ export declare const getColumnsTables: (data: DataType[]) => any;
5
7
  interface HelperResultType {
6
8
  ExistAboveGroupBy: boolean;
7
9
  ExistBelowGroupBy: boolean;
@@ -11,6 +13,9 @@ interface HelperResultType {
11
13
  nextList: MetaListType[];
12
14
  prevGroupBy: MetaSummarize | undefined;
13
15
  nextGroupBy: MetaSummarize | undefined;
16
+ prevTables: {
17
+ [params: string]: any;
18
+ };
14
19
  }
15
20
  export declare const getHelper: (list: MetaListType[], item: MetaListType) => HelperResultType;
16
21
  export declare const getSubColumns: (metaList: any) => DataType[];
@@ -21,4 +26,5 @@ export declare function splitByUnion(data: any): any[];
21
26
  export declare const patchData: (metas: MetaListType[]) => MetaListType[];
22
27
  export declare function reassembleByUnion(target?: any[]): any[];
23
28
  export declare const buildSqlQuery: (data: MetaListType[] | undefined, type: string) => string;
29
+ export declare const isError: (item: AtomsItem | AtomsItem[], data: DataType[]) => boolean;
24
30
  export {};
package/lib/es/utils.js CHANGED
@@ -1,18 +1,50 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
6
  var _excluded = ["list"];
6
7
  import { __ } from './locale';
7
8
  import { TypeEnum, SQL_COLUMN_TYPE } from './store/enum';
8
9
  import { AtomsTypeEnum } from './store/types';
9
10
  import { summarizeToSql } from './store/helper';
11
+ import { transformSql } from './utils/transformSql';
10
12
  import { uuidv4 } from './utils/helper';
11
13
  import cloneDeep from 'lodash/cloneDeep';
12
14
  import { patchMetas } from './hooks/patch';
13
15
  export var findIndex = function findIndex(arr, item) {
14
16
  return arr.indexOf(item);
15
17
  };
18
+ export var getMetaTabels = function getMetaTabels(data) {
19
+ var obj = {};
20
+ data.map(function (v) {
21
+ if (v.type === TypeEnum.data) {
22
+ var _v$table, _v$table2;
23
+ obj[(_v$table = v.table) === null || _v$table === void 0 ? void 0 : _v$table.datasourceId] = _objectSpread(_objectSpread({}, obj[(_v$table2 = v.table) === null || _v$table2 === void 0 ? void 0 : _v$table2.datasourceId]), {}, _defineProperty({}, v.table.id, v.columns));
24
+ }
25
+ if (v.type === TypeEnum.joinData) {
26
+ var _v$table3, _v$table4, _v$table5, _v$table6;
27
+ obj[((_v$table3 = v.table1) === null || _v$table3 === void 0 ? void 0 : _v$table3.datasourceId) || 'source'] = _objectSpread(_objectSpread({}, obj[(_v$table4 = v.table1) === null || _v$table4 === void 0 ? void 0 : _v$table4.datasourceId]), {}, _defineProperty({}, v.table1.id, v.columns));
28
+ obj[((_v$table5 = v.table2) === null || _v$table5 === void 0 ? void 0 : _v$table5.datasourceId) || 'source'] = _objectSpread(_objectSpread({}, obj[(_v$table6 = v.table2) === null || _v$table6 === void 0 ? void 0 : _v$table6.datasourceId]), {}, _defineProperty({}, v.table2.id, v.columns));
29
+ }
30
+ });
31
+ return obj;
32
+ };
33
+ export var getColumnsTables = function getColumnsTables(data) {
34
+ var obj = {};
35
+ data.map(function (v) {
36
+ // data也可直接是下拉框
37
+ var _v$datasourceId = v.datasourceId,
38
+ datasourceId = _v$datasourceId === void 0 ? 'source' : _v$datasourceId,
39
+ _v$id = v.id,
40
+ id = _v$id === void 0 ? '' : _v$id,
41
+ _v$columns = v.columns,
42
+ columns = _v$columns === void 0 ? [] : _v$columns;
43
+ var _datasourceId = datasourceId || 'source';
44
+ obj[_datasourceId] = _objectSpread(_objectSpread({}, obj[_datasourceId]), {}, _defineProperty({}, id, columns));
45
+ });
46
+ return obj;
47
+ };
16
48
  export var getHelper = function getHelper(list, item) {
17
49
  var types = list.map(function (v) {
18
50
  return v.type;
@@ -22,6 +54,7 @@ export var getHelper = function getHelper(list, item) {
22
54
  var rightTypes = types.slice(curIndex + 1); // 当前元素下面的所有元素 (不包含自己)
23
55
  var leftList = list.slice(0, curIndex);
24
56
  var rightList = list.slice(curIndex + 1);
57
+ var topList = leftList; // 包含自己
25
58
  var ExistAboveGroupBy = false;
26
59
  var ExistBelowGroupBy = false;
27
60
  var prevTypes = [];
@@ -30,12 +63,14 @@ export var getHelper = function getHelper(list, item) {
30
63
  var nextList = [];
31
64
  var prevGroupBy;
32
65
  var nextGroupBy;
66
+ var prevTables = {};
33
67
  if (~leftTypes.indexOf(TypeEnum.summarize)) {
34
68
  ExistAboveGroupBy = true;
35
69
  var i = leftTypes.lastIndexOf(TypeEnum.summarize);
36
70
  prevTypes = leftTypes.slice(i + 1);
37
71
  prevList = leftList.slice(i + 1);
38
72
  prevGroupBy = list[i];
73
+ topList = topList.slice(i + 1);
39
74
  }
40
75
  if (~rightTypes.indexOf(TypeEnum.summarize)) {
41
76
  ExistBelowGroupBy = true;
@@ -44,6 +79,7 @@ export var getHelper = function getHelper(list, item) {
44
79
  nextList = rightList.slice(0, _i);
45
80
  nextGroupBy = list[curIndex + _i + 1];
46
81
  }
82
+ prevTables = getMetaTabels(topList);
47
83
  return {
48
84
  ExistAboveGroupBy: ExistAboveGroupBy,
49
85
  ExistBelowGroupBy: ExistBelowGroupBy,
@@ -52,7 +88,8 @@ export var getHelper = function getHelper(list, item) {
52
88
  prevList: prevList,
53
89
  nextList: nextList,
54
90
  prevGroupBy: prevGroupBy,
55
- nextGroupBy: nextGroupBy
91
+ nextGroupBy: nextGroupBy,
92
+ prevTables: prevTables
56
93
  };
57
94
  };
58
95
  // 获取子查询的字段
@@ -254,7 +291,7 @@ var _changeAlias = function changeAlias(items, val, type) {
254
291
  };
255
292
  export function isValidSQLAlias(str) {
256
293
  if (!str) return false;
257
- var regex = /^[A-Za-z_]{0,30}$/;
294
+ var regex = /^[a-zA-Z][a-zA-Z0-9_]{0,30}$/;
258
295
  return regex.test(str);
259
296
  }
260
297
  export var changeTableAlias = function changeTableAlias(list, curObj) {
@@ -538,6 +575,10 @@ export function reassembleByUnion() {
538
575
  export var buildSqlQuery = function buildSqlQuery() {
539
576
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
540
577
  var type = arguments.length > 1 ? arguments[1] : undefined;
578
+ var typeName = type === AtomsTypeEnum.EXISTS ? 'EXISTS' : 'NOT EXISTS';
579
+ var _transformSql = transformSql(data),
580
+ sql = _transformSql.sql;
581
+ return "".concat(typeName, " (").concat(sql, ") ");
541
582
  if (!data || data.length === 0) return '';
542
583
  var name = type === AtomsTypeEnum.EXISTS ? 'EXISTS' : 'NOT EXISTS';
543
584
  var sqlClauses = ["".concat(name, " (")];
@@ -623,4 +664,61 @@ export var buildSqlQuery = function buildSqlQuery() {
623
664
  }
624
665
  sqlClauses.push(')');
625
666
  return sqlClauses.join(' ');
626
- };
667
+ };
668
+ var _isError = function isError(item, data) {
669
+ var tables = getColumnsTables(data);
670
+ // 不存在
671
+ if (!item) {
672
+ return false;
673
+ }
674
+ if (Array.isArray(item)) {
675
+ return item.some(function (v) {
676
+ return _isError(v, data);
677
+ }); // item可能为数组关联的时候有多选情况,只要有一个错,整体就错
678
+ }
679
+ // 字段类型
680
+ if (item.type === AtomsTypeEnum.FIELD) {
681
+ var datasourceId = item.datasourceId,
682
+ _item$tableId = item.tableId,
683
+ tableId = _item$tableId === void 0 ? '' : _item$tableId,
684
+ fieldName = item.fieldName;
685
+ var _datasourceId = datasourceId || 'source'; // 默认为source
686
+ if (tableId === 'source') {
687
+ _datasourceId = 'source';
688
+ }
689
+ if (!tableId) {
690
+ return false; // 未选不报错
691
+ }
692
+ if (_datasourceId === 'source') {
693
+ var _tables$_datasourceId;
694
+ // 检查是否所有字段的 name 都不等于 fieldName
695
+ if (!(tables !== null && tables !== void 0 && (_tables$_datasourceId = tables[_datasourceId]) !== null && _tables$_datasourceId !== void 0 && _tables$_datasourceId[tableId])) {
696
+ return true;
697
+ } else {
698
+ var _tables$_datasourceId2;
699
+ 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) {
700
+ return field.name !== fieldName;
701
+ });
702
+ }
703
+ } else {
704
+ var _tables$_datasourceId3;
705
+ return !(tables !== null && tables !== void 0 && (_tables$_datasourceId3 = tables[_datasourceId]) !== null && _tables$_datasourceId3 !== void 0 && _tables$_datasourceId3[tableId]); // 注意:返回 true 表示“有错误”
706
+ }
707
+ }
708
+ // 表达式类型
709
+ if (item.type === AtomsTypeEnum.EXPRESSION) {
710
+ var lhsHasError = _isError(item.lhs, data);
711
+ var rhsHasError = _isError(item.rhs, data);
712
+ return lhsHasError || rhsHasError;
713
+ }
714
+ // 公式
715
+ if (item.type === AtomsTypeEnum.FORMULA) {
716
+ return _isError(item.args, data);
717
+ }
718
+ // 公式
719
+ if (item.type === AtomsTypeEnum.COLLECTION) {
720
+ return _isError(item.list, data);
721
+ }
722
+ return false; // 其他类型默认无错误
723
+ };
724
+ export { _isError as isError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",