@gingkoo/pandora-metabase 1.0.14 → 1.0.16

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 (96) 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/expressions/suggest.js +1 -1
  4. package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +1 -2
  5. package/lib/cjs/components/dialog/{select-filter → expression}/index.d.ts +4 -4
  6. package/lib/cjs/components/dialog/{select-filter → expression}/index.js +345 -206
  7. package/lib/cjs/components/dialog/formula-list/enum.d.ts +9 -13
  8. package/lib/cjs/components/dialog/formula-list/enum.js +83 -39
  9. package/lib/cjs/components/dialog/formula-list/index.d.ts +4 -1
  10. package/lib/cjs/components/dialog/formula-list/index.js +110 -126
  11. package/lib/cjs/components/dialog/formula-list/utils.js +77 -46
  12. package/lib/cjs/components/dialog/index.d.ts +2 -2
  13. package/lib/cjs/components/dialog/index.js +20 -20
  14. package/lib/cjs/components/dialog/select-column/index.js +43 -12
  15. package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +54 -0
  16. package/lib/cjs/components/dialog/select-column-multiple/index.js +341 -0
  17. package/lib/cjs/components/dialog/select-column-multiple/index.less +246 -0
  18. package/lib/cjs/components/dialog/select-table/index.js +9 -7
  19. package/lib/cjs/components/icons.js +36 -36
  20. package/lib/cjs/components/metabase/index.js +6 -6
  21. package/lib/cjs/components/metabase/index.less +12 -1
  22. package/lib/cjs/components/modules/components/Wrapper.js +6 -6
  23. package/lib/cjs/components/modules/custom-column.js +12 -14
  24. package/lib/cjs/components/modules/enum/filter-enum.d.ts +34 -0
  25. package/lib/cjs/components/modules/enum/filter-enum.js +137 -0
  26. package/lib/cjs/components/modules/filter.js +43 -460
  27. package/lib/cjs/components/modules/join-data.js +863 -525
  28. package/lib/cjs/components/modules/permission-table.js +4 -0
  29. package/lib/cjs/components/modules/sort.js +102 -91
  30. package/lib/cjs/components/modules/summarize/group-by.js +47 -16
  31. package/lib/cjs/components/modules/summarize/select-index.js +48 -17
  32. package/lib/cjs/components/modules/table-data.js +13 -4
  33. package/lib/cjs/components/popup.js +1 -2
  34. package/lib/cjs/hooks/patch.d.ts +4 -0
  35. package/lib/cjs/hooks/patch.js +464 -0
  36. package/lib/cjs/hooks/use-state.js +73 -138
  37. package/lib/cjs/index.d.ts +0 -1
  38. package/lib/cjs/index.js +3 -21
  39. package/lib/cjs/locale/en.js +9 -2
  40. package/lib/cjs/locale/zh.js +11 -4
  41. package/lib/cjs/store/helper.d.ts +2 -3
  42. package/lib/cjs/store/helper.js +288 -233
  43. package/lib/cjs/store/types.d.ts +94 -71
  44. package/lib/cjs/store/types.js +17 -12
  45. package/lib/cjs/utils.d.ts +3 -3
  46. package/lib/cjs/utils.js +152 -187
  47. package/lib/es/common/SplitView/index.js +10 -10
  48. package/lib/es/components/dialog/custom-column/expressions/suggest.js +1 -1
  49. package/lib/es/components/dialog/{select-filter → expression}/index.d.ts +4 -4
  50. package/lib/es/components/dialog/{select-filter → expression}/index.js +343 -206
  51. package/lib/es/components/dialog/formula-list/enum.d.ts +9 -13
  52. package/lib/es/components/dialog/formula-list/enum.js +82 -38
  53. package/lib/es/components/dialog/formula-list/index.d.ts +4 -1
  54. package/lib/es/components/dialog/formula-list/index.js +115 -131
  55. package/lib/es/components/dialog/formula-list/utils.js +77 -46
  56. package/lib/es/components/dialog/index.d.ts +2 -2
  57. package/lib/es/components/dialog/index.js +3 -3
  58. package/lib/es/components/dialog/select-column/index.js +44 -13
  59. package/lib/es/components/dialog/select-column-multiple/index.d.ts +54 -0
  60. package/lib/es/components/dialog/select-column-multiple/index.js +335 -0
  61. package/lib/es/components/dialog/select-column-multiple/index.less +246 -0
  62. package/lib/es/components/dialog/select-table/index.js +9 -7
  63. package/lib/es/components/icons.js +36 -36
  64. package/lib/es/components/metabase/index.js +6 -6
  65. package/lib/es/components/metabase/index.less +12 -1
  66. package/lib/es/components/modules/components/Wrapper.js +6 -6
  67. package/lib/es/components/modules/custom-column.js +12 -14
  68. package/lib/es/components/modules/enum/filter-enum.d.ts +34 -0
  69. package/lib/es/components/modules/enum/filter-enum.js +131 -0
  70. package/lib/es/components/modules/filter.js +45 -463
  71. package/lib/es/components/modules/join-data.js +865 -527
  72. package/lib/es/components/modules/permission-table.js +4 -0
  73. package/lib/es/components/modules/sort.js +102 -91
  74. package/lib/es/components/modules/summarize/group-by.js +48 -17
  75. package/lib/es/components/modules/summarize/select-index.js +49 -18
  76. package/lib/es/components/modules/table-data.js +13 -4
  77. package/lib/es/hooks/patch.d.ts +4 -0
  78. package/lib/es/hooks/patch.js +457 -0
  79. package/lib/es/hooks/use-state.js +73 -138
  80. package/lib/es/index.d.ts +0 -1
  81. package/lib/es/index.js +1 -1
  82. package/lib/es/locale/en.js +9 -2
  83. package/lib/es/locale/zh.js +11 -4
  84. package/lib/es/store/helper.d.ts +2 -3
  85. package/lib/es/store/helper.js +288 -233
  86. package/lib/es/store/types.d.ts +94 -71
  87. package/lib/es/store/types.js +16 -11
  88. package/lib/es/utils.d.ts +3 -3
  89. package/lib/es/utils.js +154 -190
  90. package/package.json +1 -1
  91. package/lib/cjs/components/modules/filter copy.d.ts +0 -7
  92. package/lib/cjs/components/modules/filter copy.js +0 -178
  93. package/lib/es/components/modules/filter copy.d.ts +0 -7
  94. package/lib/es/components/modules/filter copy.js +0 -171
  95. /package/lib/cjs/components/dialog/{select-filter → expression}/index.less +0 -0
  96. /package/lib/es/components/dialog/{select-filter → expression}/index.less +0 -0
@@ -1,5 +1,5 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import { OptionsTypeEnum } from './enum';
2
+ import { AtomsTypeEnum } from '../../../store/types';
3
3
  /**
4
4
  *
5
5
  * @param type 当前选择的类型
@@ -16,71 +16,102 @@ export var getTemplate = function getTemplate(oldType, type, list, index) {
16
16
  }
17
17
  if (type === 'case') {
18
18
  temList = [{
19
- operator: 'when',
20
- type: OptionsTypeEnum.OTHER,
21
- expression: ''
19
+ val: 'when',
20
+ type: AtomsTypeEnum.OPERATOR
22
21
  }, {
23
- operator: '',
24
- type: '',
25
- expression: ''
22
+ val: '',
23
+ type: AtomsTypeEnum.UNKNOWN
26
24
  }, {
27
- operator: 'then',
28
- type: OptionsTypeEnum.OTHER,
29
- expression: ''
25
+ val: 'then',
26
+ type: AtomsTypeEnum.OPERATOR
30
27
  }, {
31
- operator: '',
32
- type: '',
33
- expression: ''
28
+ val: '',
29
+ type: AtomsTypeEnum.UNKNOWN
34
30
  }, {
35
- operator: 'end',
36
- type: OptionsTypeEnum.OTHER,
37
- expression: ''
31
+ val: 'end',
32
+ type: AtomsTypeEnum.OPERATOR
38
33
  }];
39
34
  }
40
35
  if (type === 'when') {
41
36
  temList = [{
42
- operator: '',
43
- type: '',
44
- expression: ''
37
+ val: '',
38
+ type: AtomsTypeEnum.UNKNOWN
45
39
  }, {
46
- operator: 'then',
47
- type: OptionsTypeEnum.OTHER,
48
- expression: ''
40
+ val: 'then',
41
+ type: AtomsTypeEnum.OPERATOR
49
42
  }, {
50
- operator: '',
51
- type: '',
52
- expression: ''
43
+ val: '',
44
+ type: AtomsTypeEnum.UNKNOWN
53
45
  }];
54
46
  }
55
47
  if (type === 'RANK()' || type === 'DENSE_RANK()' || type === 'ROW_NUMBER()') {
56
48
  temList = [{
57
- operator: 'OVER',
58
- type: OptionsTypeEnum.OPERATOR,
59
- expression: ''
49
+ val: 'OVER',
50
+ type: AtomsTypeEnum.OPERATOR
60
51
  }, {
61
- operator: '(',
62
- type: OptionsTypeEnum.OPERATOR,
63
- expression: ''
52
+ val: '(',
53
+ type: AtomsTypeEnum.OPERATOR
64
54
  }, {
65
- operator: 'PARTITION BY',
66
- type: OptionsTypeEnum.OPERATOR,
67
- expression: ''
55
+ val: 'PARTITION BY',
56
+ type: AtomsTypeEnum.OPERATOR
68
57
  }, {
69
- operator: '',
70
- type: OptionsTypeEnum.FIELD,
71
- expression: ''
58
+ fieldName: '',
59
+ // 字段名
60
+ fieldNameZh: '',
61
+ // 字段中文名
62
+ fieldAlias: '',
63
+ // 别名
64
+ fieldUuid: '',
65
+ // uuid
66
+ fieldId: '',
67
+ // 字段id
68
+ // quotes?: string; // 字段展示的 不知道有没有用
69
+ tableName: '',
70
+ // 表名
71
+ tableNameZh: '',
72
+ tableId: '',
73
+ // 表名
74
+ tableAlias: '',
75
+ // 别名
76
+ tableUuid: '',
77
+ // 表唯一标识
78
+ datasourceName: '',
79
+ // 数据源名
80
+ datasourceId: '',
81
+ // 数据源id
82
+ type: AtomsTypeEnum.FIELD
72
83
  }, {
73
- operator: 'ORDER BY',
74
- type: OptionsTypeEnum.OPERATOR,
75
- expression: ''
84
+ val: 'ORDER BY',
85
+ type: AtomsTypeEnum.OPERATOR
76
86
  }, {
77
- operator: '',
78
- type: OptionsTypeEnum.FIELD,
79
- expression: ''
87
+ fieldName: '',
88
+ // 字段名
89
+ fieldNameZh: '',
90
+ // 字段中文名
91
+ fieldAlias: '',
92
+ // 别名
93
+ fieldUuid: '',
94
+ // uuid
95
+ fieldId: '',
96
+ // 字段id
97
+ // quotes?: string; // 字段展示的 不知道有没有用
98
+ tableName: '',
99
+ // 表名
100
+ tableNameZh: '',
101
+ tableId: '',
102
+ // 表名
103
+ tableAlias: '',
104
+ // 别名
105
+ tableUuid: '',
106
+ // 表唯一标识
107
+ datasourceName: '',
108
+ // 数据源名
109
+ datasourceId: '',
110
+ // 数据源id
111
+ type: AtomsTypeEnum.FIELD
80
112
  }, {
81
- operator: ')',
82
- type: OptionsTypeEnum.OPERATOR,
83
- expression: ''
113
+ val: ')',
114
+ type: AtomsTypeEnum.OPERATOR
84
115
  }];
85
116
  }
86
117
  list.splice.apply(list, [index + 1, 0].concat(_toConsumableArray(temList)));
@@ -1,10 +1,10 @@
1
1
  export { default as CustomColumnPopup } from './custom-column/index';
2
2
  export { default as SelectColumn } from './select-column/index';
3
3
  export { default as SelectJoinColumn } from './select-join-column/index';
4
- export { default as SelectJoinColumnMultiple } from './select-join-column-multiple/index';
5
- export { default as SelectFilter } from './select-filter/index';
4
+ export { default as SelectColumnMultiple } from './select-column-multiple/index';
6
5
  export { default as SelectSummarize } from './select-summarize/index';
7
6
  export { default as SelectJoin } from './select-join/index';
8
7
  export { default as SelectTable } from './select-table/index';
9
8
  export { default as SelectPermissionTable } from './select-permission-table/index';
10
9
  export { default as FormulaList } from './formula-list/index';
10
+ export { default as Expression } from './expression/index';
@@ -1,10 +1,10 @@
1
1
  export { default as CustomColumnPopup } from './custom-column/index';
2
2
  export { default as SelectColumn } from './select-column/index';
3
3
  export { default as SelectJoinColumn } from './select-join-column/index';
4
- export { default as SelectJoinColumnMultiple } from './select-join-column-multiple/index';
5
- export { default as SelectFilter } from './select-filter/index';
4
+ export { default as SelectColumnMultiple } from './select-column-multiple/index';
6
5
  export { default as SelectSummarize } from './select-summarize/index';
7
6
  export { default as SelectJoin } from './select-join/index';
8
7
  export { default as SelectTable } from './select-table/index';
9
8
  export { default as SelectPermissionTable } from './select-permission-table/index';
10
- export { default as FormulaList } from './formula-list/index';
9
+ export { default as FormulaList } from './formula-list/index'; // 自定义公式列表
10
+ export { default as Expression } from './expression/index'; // 表达式编辑器
@@ -1,5 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
5
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
4
6
  /**
5
7
  * 选择保留哪些表字段
@@ -11,7 +13,7 @@ import './index.less';
11
13
  import { useEffect, useMemo, useState } from 'react';
12
14
  import cloneDeep from 'lodash/cloneDeep';
13
15
  import cx from 'classnames';
14
- import { Button, Modal, Input, Tooltip } from '@gingkoo/pandora';
16
+ import { Button, Modal, Input, Tooltip, Toast } from '@gingkoo/pandora';
15
17
  import { __ } from '../../../locale';
16
18
  import { NotSelectIcon, SelectIcon } from '../../icons';
17
19
  import { useStore } from '../../../hooks/use-provider';
@@ -92,18 +94,47 @@ var SelectColumn = function SelectColumn(_ref) {
92
94
  fieldAlias = val;
93
95
  }
94
96
  }),
95
- onOk: function onOk() {
96
- var newColumns = cloneDeep(columns);
97
- var newMetaList = store.metaList[groupIndex].list.slice();
98
- newColumns[i].fieldAlias = fieldAlias;
99
- newColumns[i].fieldUuid = newColumns[i].fieldUuid || uuidv4('field');
100
- newMetaList = changeFieldAlias(newMetaList, newColumns[i]);
101
- store.setMeta(newMetaList, groupIndex);
102
- onSelect(newColumns);
103
- setTimeout(function () {
104
- store.setClosable(true);
105
- }, 0);
106
- },
97
+ onOk: function () {
98
+ var _onOk = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
99
+ var newColumns, newMetaList;
100
+ return _regeneratorRuntime.wrap(function (_context) {
101
+ while (1) switch (_context.prev = _context.next) {
102
+ case 0:
103
+ if (fieldAlias) {
104
+ _context.next = 1;
105
+ break;
106
+ }
107
+ Toast.warning(__('SqlQueryBuilder.aliasCannotEmpty'));
108
+ return _context.abrupt("return", false);
109
+ case 1:
110
+ if (!(fieldAlias.length > 30)) {
111
+ _context.next = 2;
112
+ break;
113
+ }
114
+ Toast.warning('别名长度不能超过30');
115
+ return _context.abrupt("return", false);
116
+ case 2:
117
+ newColumns = cloneDeep(columns);
118
+ newMetaList = store.metaList[groupIndex].list.slice();
119
+ newColumns[i].fieldAlias = fieldAlias;
120
+ newColumns[i].fieldUuid = newColumns[i].fieldUuid || uuidv4('field');
121
+ newMetaList = changeFieldAlias(newMetaList, newColumns[i]);
122
+ store.setMeta(newMetaList, groupIndex);
123
+ onSelect(newColumns);
124
+ setTimeout(function () {
125
+ store.setClosable(true);
126
+ }, 0);
127
+ case 3:
128
+ case "end":
129
+ return _context.stop();
130
+ }
131
+ }, _callee);
132
+ }));
133
+ function onOk() {
134
+ return _onOk.apply(this, arguments);
135
+ }
136
+ return onOk;
137
+ }(),
107
138
  onCancel: function onCancel() {
108
139
  setTimeout(function () {
109
140
  store.setClosable(true);
@@ -0,0 +1,54 @@
1
+ /**
2
+ * 选择表字段当条件
3
+ * 谁在用?
4
+ * 1、关联模块
5
+ * 2、过滤器模块
6
+ * 3、聚合模块
7
+ * 4、排序模块
8
+ */
9
+ import './index.less';
10
+ import { ColumnsPopupThemeEnum, SQL_COLUMN_TYPE } from '../../../store/enum';
11
+ import { MetaData_ColumnsType, MetaJoin_TalbeType, AtomsField } from '../../../store/types';
12
+ import { DatasourceType } from '../../../types';
13
+ export declare const DATE_GROUP_MAP: Map<string, string>;
14
+ export declare const NUMBER_GROUP_MAP: Map<string, string>;
15
+ export interface ColumnType {
16
+ fieldUuid: string;
17
+ fieldAlias: string;
18
+ alias: string;
19
+ name: string;
20
+ database_type: SQL_COLUMN_TYPE | string;
21
+ sql?: string;
22
+ id: string;
23
+ datasourceId: string;
24
+ datasourceName: string;
25
+ table2?: Omit<MetaJoin_TalbeType, 'column' | 'column_id'> | null;
26
+ }
27
+ export interface ColumnGroupType {
28
+ condition: string;
29
+ }
30
+ export type DataType = Partial<DatasourceType> & {
31
+ name: string;
32
+ id: string;
33
+ name_zh: string;
34
+ tableUuid: string;
35
+ alias: string;
36
+ columns: MetaData_ColumnsType[];
37
+ };
38
+ interface PropsType {
39
+ data: DataType[];
40
+ value: AtomsField[];
41
+ theme: ColumnsPopupThemeEnum;
42
+ isGroup?: boolean;
43
+ onSelect?: (fields: AtomsField[], quotes: string) => void;
44
+ onGroup?: (record: ColumnType & ColumnGroupType & {
45
+ realName?: string;
46
+ }) => void;
47
+ didUpdate?: Function;
48
+ multiple?: boolean;
49
+ showNextBtn?: boolean;
50
+ nextBtnText?: string;
51
+ onNextStep?: () => void;
52
+ }
53
+ declare const SelectJoinColumn: ({ data, value: _value, theme, onSelect, isGroup, onGroup, didUpdate, multiple, showNextBtn, nextBtnText, onNextStep, }: PropsType) => import("react/jsx-runtime").JSX.Element;
54
+ export default SelectJoinColumn;
@@ -0,0 +1,335 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
4
+ /**
5
+ * 选择表字段当条件
6
+ * 谁在用?
7
+ * 1、关联模块
8
+ * 2、过滤器模块
9
+ * 3、聚合模块
10
+ * 4、排序模块
11
+ */
12
+ import './index.less';
13
+ import { useEffect, useState } from 'react';
14
+ import { Button } from '@gingkoo/pandora';
15
+ import cloneDeep from 'lodash/cloneDeep';
16
+ import cx from 'classnames';
17
+ import { ColumnsPopupThemeEnum, SQL_GROUP_TYPE } from '../../../store/enum';
18
+ import { SummarizeAlias } from '../../../store/helper';
19
+ import {
20
+ // AtomsField,
21
+ AtomsTypeEnum } from '../../../store/types';
22
+ import { __ } from '../../../locale';
23
+ import { NUMBER_GROUP, DATE_GROUP } from '../const';
24
+ import { useStore } from '../../../hooks/use-provider';
25
+ import { replaceTpl } from '../../../utils/helper';
26
+ import { SearchIcon, TableIcon, CircleIcon, LetterAaIcon, CalendarIcon, WellIcon, ForeignKeyIcon, UpArrowIcon2, DownArrowIcon2 } from '../../icons';
27
+ export var DATE_GROUP_MAP = new Map([['分', '分'], ['时', '时'], ['天', '天'], ['周', '周'], ['月', '月'], ['季度', '季度'], ['一小时内的分钟数', '一小时内的分钟数'], ['一天内的小时数', '一天内的小时数'], ['一周内的天数', '一周内的天数'], ['一月内的天数', '一月内的天数'], ['一年内的天数', '一年内的天数'], ['一年的星期数', '一年的星期数'], ['一年的月数', '一年的月数']]);
28
+ export var NUMBER_GROUP_MAP = new Map([['自动间隔', '自动分组'], ['10个刻度间隔', '10 刻度间隔'], ['间隔50', '50 刻度间隔'], ['间隔100', '100 刻度间隔'], ['无间隔', '']]);
29
+ var IconMap = {
30
+ CHAR: _jsx(LetterAaIcon, {}),
31
+ VARCHAR: _jsx(LetterAaIcon, {}),
32
+ CLOB: _jsx(LetterAaIcon, {}),
33
+ DOUBLE: _jsx(WellIcon, {}),
34
+ SMALLINT: _jsx(WellIcon, {}),
35
+ BIGINT: _jsx(WellIcon, {}),
36
+ INTEGER: _jsx(WellIcon, {}),
37
+ TIMESTAMP: _jsx(CalendarIcon, {}),
38
+ PK: _jsx(CircleIcon, {}),
39
+ FK: _jsx(ForeignKeyIcon, {})
40
+ };
41
+ var OPEN_GROUP = false; // mr.chen 说不弄这块 弄个开关防止后面要用
42
+ var SelectJoinColumn = function SelectJoinColumn(_ref) {
43
+ var _value$;
44
+ var _ref$data = _ref.data,
45
+ data = _ref$data === void 0 ? [] : _ref$data,
46
+ _value = _ref.value,
47
+ _ref$theme = _ref.theme,
48
+ theme = _ref$theme === void 0 ? ColumnsPopupThemeEnum.skyBlue : _ref$theme,
49
+ onSelect = _ref.onSelect,
50
+ isGroup = _ref.isGroup,
51
+ onGroup = _ref.onGroup,
52
+ didUpdate = _ref.didUpdate,
53
+ _ref$multiple = _ref.multiple,
54
+ multiple = _ref$multiple === void 0 ? true : _ref$multiple,
55
+ _ref$showNextBtn = _ref.showNextBtn,
56
+ showNextBtn = _ref$showNextBtn === void 0 ? false : _ref$showNextBtn,
57
+ _ref$nextBtnText = _ref.nextBtnText,
58
+ nextBtnText = _ref$nextBtnText === void 0 ? __('metabase.nextBtn') : _ref$nextBtnText,
59
+ onNextStep = _ref.onNextStep;
60
+ var store = useStore();
61
+ var _useState = useState(_value),
62
+ _useState2 = _slicedToArray(_useState, 2),
63
+ value = _useState2[0],
64
+ setValue = _useState2[1]; // 当前选择的字段
65
+ var _useState3 = useState(_value === null || _value === void 0 || (_value$ = _value[0]) === null || _value$ === void 0 ? void 0 : _value$.tableUuid),
66
+ _useState4 = _slicedToArray(_useState3, 2),
67
+ curTable = _useState4[0],
68
+ setCurTable = _useState4[1]; // 当前选择的表
69
+ // const [curColumn, setCurColumn] = useState(_value); // 当前选择的字段
70
+ var _useState5 = useState(data.map(function (v, i) {
71
+ var open = !i && !curTable ? true : v.tableUuid === curTable; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
72
+ return _objectSpread(_objectSpread({}, v), {}, {
73
+ open: open,
74
+ searchText: '',
75
+ columns: v.columns.slice()
76
+ });
77
+ })),
78
+ _useState6 = _slicedToArray(_useState5, 2),
79
+ tableList = _useState6[0],
80
+ setTableList = _useState6[1];
81
+ // useEffect(() => {
82
+ // setCurTable(tableInfo);
83
+ // }, [tableInfo]);
84
+ useEffect(function () {
85
+ // setCurColumn(_value);
86
+ setValue(_value);
87
+ }, [_value]);
88
+ var isActive = function isActive(fieldUuid) {
89
+ return (value === null || value === void 0 ? void 0 : value.filter(function (v) {
90
+ return v.fieldUuid === fieldUuid;
91
+ }).length) > 0;
92
+ };
93
+ useEffect(function () {
94
+ setTableList(data.map(function (v, i) {
95
+ var open = !i && !curTable ? true : v.tableUuid === curTable; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
96
+ return _objectSpread(_objectSpread({}, v), {}, {
97
+ open: open,
98
+ searchText: '',
99
+ columns: v.columns.slice()
100
+ });
101
+ }));
102
+ }, [data, curTable]);
103
+ useEffect(function () {
104
+ didUpdate === null || didUpdate === void 0 || didUpdate();
105
+ }, [tableList]);
106
+ function _onInput(val, tableAlias) {
107
+ var newData = cloneDeep(tableList).map(function (v, i) {
108
+ if (v.alias === tableAlias) {
109
+ var _data$i;
110
+ return _objectSpread(_objectSpread({}, v), {}, {
111
+ columns: (_data$i = data[i]) === null || _data$i === void 0 ? void 0 : _data$i.columns.filter(function (v) {
112
+ return ~(v.name + (v.name_zh || '')).toLocaleLowerCase().indexOf(val.toLocaleLowerCase());
113
+ }),
114
+ searchText: val
115
+ });
116
+ }
117
+ return v;
118
+ });
119
+ setTableList(newData);
120
+ }
121
+ var getQuotes = function getQuotes(items) {
122
+ return items.map(function (v) {
123
+ return v.fieldName;
124
+ }).join(' || ');
125
+ };
126
+ var changeValue = function changeValue(tableUuid, val) {
127
+ var _value$filter;
128
+ if (!multiple) {
129
+ var _data = val ? [val] : [];
130
+ setValue(_data);
131
+ setCurTable(tableUuid);
132
+ onSelect === null || onSelect === void 0 || onSelect(_data, getQuotes(_data));
133
+ return;
134
+ }
135
+ var isHas = (value === null || value === void 0 || (_value$filter = value.filter(function (v) {
136
+ return v.fieldUuid === (val === null || val === void 0 ? void 0 : val.fieldUuid);
137
+ })) === null || _value$filter === void 0 ? void 0 : _value$filter.length) > 0;
138
+ var _value = value;
139
+ if (tableUuid != curTable) {
140
+ _value = [];
141
+ }
142
+ if (!isHas && val) {
143
+ _value.push(val);
144
+ } else {
145
+ _value = _value.filter(function (v) {
146
+ return v.fieldUuid != (val === null || val === void 0 ? void 0 : val.fieldUuid);
147
+ });
148
+ }
149
+ setValue(_value);
150
+ setCurTable(tableUuid);
151
+ onSelect === null || onSelect === void 0 || onSelect(_value, getQuotes(_value));
152
+ };
153
+ // const _condition = value?.condition || '';
154
+ return _jsxs(_Fragment, {
155
+ children: [_jsx("div", {
156
+ className: cx("Sqb-SelectColumns--box ".concat(theme)),
157
+ children: _jsx("div", {
158
+ style: {
159
+ width: 300
160
+ },
161
+ children: tableList.map(function (tableItem) {
162
+ var tableAlias = tableItem.alias,
163
+ tableName = tableItem.name,
164
+ columns = tableItem.columns,
165
+ open = tableItem.open,
166
+ searchText = tableItem.searchText,
167
+ _tableItem$datasource = tableItem.datasourceName,
168
+ datasourceName = _tableItem$datasource === void 0 ? '' : _tableItem$datasource,
169
+ _tableItem$datasource2 = tableItem.datasourceId,
170
+ datasourceId = _tableItem$datasource2 === void 0 ? '' : _tableItem$datasource2,
171
+ _tableItem$tableUuid = tableItem.tableUuid,
172
+ tableUuid = _tableItem$tableUuid === void 0 ? '' : _tableItem$tableUuid;
173
+ var isMultiple = tableList.length > 1;
174
+ var isSummarize = tableAlias === SummarizeAlias;
175
+ return _jsxs("div", {
176
+ children: [!isSummarize && _jsx("div", {
177
+ className: cx("Sqb-List-section"),
178
+ children: _jsx("div", {
179
+ className: cx("Sqb-List-title mx-4 pb-4 pt-4", {
180
+ shrink: isMultiple,
181
+ active: open
182
+ }),
183
+ onClick: function onClick() {
184
+ if (isGroup) {
185
+ changeValue(tableUuid);
186
+ }
187
+ if (!isMultiple) return void 0;
188
+ var newTables = cloneDeep(tableList);
189
+ if (open) {
190
+ setTableList(newTables.map(function (v) {
191
+ return _objectSpread(_objectSpread({}, v), {}, {
192
+ open: tableUuid === v.tableUuid ? false : v.open
193
+ });
194
+ }));
195
+ } else {
196
+ setTableList(newTables.map(function (v) {
197
+ return _objectSpread(_objectSpread({}, v), {}, {
198
+ open: tableUuid === v.tableUuid || v.alias === SummarizeAlias
199
+ });
200
+ }));
201
+ }
202
+ },
203
+ children: _jsxs("div", {
204
+ className: 'List-item',
205
+ children: [_jsx("span", {
206
+ className: 'List-item-icon',
207
+ children: _jsx(TableIcon, {})
208
+ }), _jsx("div", {
209
+ style: {
210
+ overflow: 'hidden'
211
+ },
212
+ children: _jsx("h3", {
213
+ className: 'List-item-title ml-2',
214
+ title: datasourceName ? "".concat(datasourceName, ".").concat(tableAlias || tableName) : tableAlias || tableName,
215
+ children: datasourceName ? "".concat(datasourceName, ".").concat(tableAlias || tableName) : tableAlias || tableName
216
+ })
217
+ }), isMultiple && !isGroup && _jsx("span", {
218
+ className: 'List-title-arrow',
219
+ children: open ? _jsx(UpArrowIcon2, {}) : _jsx(DownArrowIcon2, {})
220
+ })]
221
+ })
222
+ })
223
+ }), (open || isSummarize) && _jsxs(_Fragment, {
224
+ children: [!isSummarize && !isGroup && _jsx("div", {
225
+ className: cx("Sqb-List-section"),
226
+ children: _jsxs("div", {
227
+ className: cx("Sqb-List-search m-2 rounded-lg"),
228
+ children: [_jsx("span", {
229
+ className: 'px-2',
230
+ children: _jsx(SearchIcon, {})
231
+ }), _jsx("input", {
232
+ type: 'text',
233
+ className: 'p-2',
234
+ autoFocus: true,
235
+ value: searchText,
236
+ placeholder: __('joinData.search'),
237
+ onChange: function onChange() {},
238
+ onInput: function onInput(e) {
239
+ return _onInput(e.target.value, tableAlias);
240
+ }
241
+ })]
242
+ })
243
+ }), Array.isArray(columns) && columns.map(function (v, i) {
244
+ var special_type = v.special_type,
245
+ _v$database_type = v.database_type,
246
+ database_type = _v$database_type === void 0 ? '' : _v$database_type,
247
+ name = v.name,
248
+ _v$realName = v.realName,
249
+ realName = _v$realName === void 0 ? '' : _v$realName,
250
+ fieldId = v.id;
251
+ var groupe = SQL_GROUP_TYPE.STRING;
252
+ // @ts-ignore
253
+ if (~NUMBER_GROUP.indexOf(database_type)) {
254
+ groupe = SQL_GROUP_TYPE.NUMBER;
255
+ }
256
+ // @ts-ignore
257
+ if (~DATE_GROUP.indexOf(database_type)) {
258
+ groupe = SQL_GROUP_TYPE.DATE;
259
+ }
260
+ // let showCondition =
261
+ // curColumn === name && curTable === tableUuid && _condition;
262
+ return _jsx("div", {
263
+ className: cx("Sqb-List-section"),
264
+ children: _jsx("div", {
265
+ className: cx("Sqb-List-item mx-2", {
266
+ active: isActive(v.fieldUuid)
267
+ }),
268
+ onClick: function onClick() {
269
+ if (isSummarize) {
270
+ // console.log(v, 'v');
271
+ }
272
+ console.log('🚀 ~ SelectJoinColumn ~ tableItem:', tableItem);
273
+ changeValue(tableUuid, {
274
+ tableName: tableItem.name,
275
+ tableId: tableItem.id,
276
+ tableNameZh: tableItem.name_zh,
277
+ tableAlias: tableItem.alias,
278
+ tableUuid: tableItem.tableUuid,
279
+ datasourceName: tableItem.datasourceName || '',
280
+ datasourceId: tableItem.datasourceId || '',
281
+ fieldName: v.name,
282
+ fieldId: v.id,
283
+ fieldNameZh: v.name_zh || '',
284
+ fieldAlias: v.fieldAlias,
285
+ fieldUuid: v.fieldUuid,
286
+ type: AtomsTypeEnum.FIELD
287
+ // quotes: v.fieldAlias || v.name,
288
+ });
289
+ // setCurTable(tableUuid);
290
+ // typeof onSelect === 'function' &&
291
+ // onSelect({
292
+ // ...v,
293
+ // table,
294
+ // tableId,
295
+ // alias: tableAlias,
296
+ // name,
297
+ // database_type,
298
+ // sql: v.sql || '',
299
+ // datasourceId,
300
+ // datasourceName,
301
+ // realName,
302
+ // });
303
+ },
304
+ children: _jsxs("div", {
305
+ className: 'p-2 List-item',
306
+ children: [_jsx("span", {
307
+ className: 'List-item-icon',
308
+ children: IconMap[special_type || database_type] || _jsx(LetterAaIcon, {})
309
+ }), _jsx("div", {
310
+ children: _jsx("h4", {
311
+ className: 'List-item-title ml-2',
312
+ children: replaceTpl(store.fieldNameTpl, v)
313
+ })
314
+ })]
315
+ })
316
+ })
317
+ }, i);
318
+ })]
319
+ })]
320
+ }, tableUuid || tableAlias);
321
+ })
322
+ })
323
+ }), showNextBtn && multiple && _jsx(Button, {
324
+ block: true,
325
+ disabled: (value === null || value === void 0 ? void 0 : value.length) < 1,
326
+ primary: true,
327
+ className: 'mt-4 :Sqb-SelectColumns-btn',
328
+ onClick: function onClick() {
329
+ return onNextStep === null || onNextStep === void 0 ? void 0 : onNextStep();
330
+ },
331
+ children: nextBtnText
332
+ })]
333
+ });
334
+ };
335
+ export default SelectJoinColumn;