@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,19 +1,73 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
7
7
  import './index.less';
8
- import React, { useState, useEffect, useRef } from 'react';
9
- import cloneDeep from 'lodash/cloneDeep';
8
+ import React, { useState, useEffect, useMemo, useRef } from 'react';
10
9
  import cx from 'classnames';
11
- import { uuidv4 } from '../../../utils/helper';
10
+ import { Tag } from '@gingkoo/pandora';
11
+ import { getTableIdFirstKey, isSameTableByIdFirst, uuidv4 } from '../../../utils/helper';
12
12
  import { useStore } from '../../../hooks/use-provider';
13
13
  import Loading from '../../../common/Loading';
14
14
  import { __ } from '../../../locale';
15
15
  import { replaceTpl } from '../../../utils/helper';
16
16
  import { TableIcon, SearchIcon, DataSourceIcon, LeftArrowIcon } from '../../icons';
17
+ function focusWithoutScroll(input) {
18
+ if (!input) return;
19
+ setTimeout(function () {
20
+ try {
21
+ input.focus({
22
+ preventScroll: true
23
+ });
24
+ } catch (e) {
25
+ input.focus();
26
+ }
27
+ }, 0);
28
+ }
29
+ function getTableTypeOptions(tables) {
30
+ return Array.from(new Set(tables.map(function (v) {
31
+ return v.table_type;
32
+ }).filter(function (v) {
33
+ return Boolean(v);
34
+ })));
35
+ }
36
+ function getFlatTableTypeOptions(sourceTable) {
37
+ return sourceTable.reduce(function (mo, datasource) {
38
+ if (datasource !== null && datasource !== void 0 && datasource.datasourceId && Array.isArray(datasource === null || datasource === void 0 ? void 0 : datasource.children)) {
39
+ mo[datasource.datasourceId] = getTableTypeOptions(datasource.children);
40
+ }
41
+ return mo;
42
+ }, {});
43
+ }
44
+ function matchTableName(table, searchVal) {
45
+ if (!searchVal) return true;
46
+ return Boolean(~(table.name + (table.name_zh || '')).toLocaleLowerCase().indexOf(searchVal.toLocaleLowerCase()));
47
+ }
48
+ function matchTableType(table, selectedTableTypes) {
49
+ if (!selectedTableTypes.length) {
50
+ return true;
51
+ }
52
+ return selectedTableTypes.includes(table.table_type || '');
53
+ }
54
+ function filterTables(tables, searchVal, selectedTableTypes) {
55
+ return tables.filter(function (table) {
56
+ return matchTableName(table, searchVal) && matchTableType(table, selectedTableTypes);
57
+ });
58
+ }
59
+ function filterDatasourceTable(sourceTable, searchVal, selectedTableTypesMap) {
60
+ return sourceTable.map(function (datasource) {
61
+ var children = Array.isArray(datasource === null || datasource === void 0 ? void 0 : datasource.children) ? datasource.children : [];
62
+ var selectedTableTypes = selectedTableTypesMap[datasource === null || datasource === void 0 ? void 0 : datasource.datasourceId] || [];
63
+ return _objectSpread(_objectSpread({}, datasource), {}, {
64
+ children: filterTables(children, searchVal, selectedTableTypes)
65
+ });
66
+ }).filter(function (datasource) {
67
+ var _selectedTableTypesMa;
68
+ return datasource.children.length > 0 || Boolean((_selectedTableTypesMa = selectedTableTypesMap[datasource === null || datasource === void 0 ? void 0 : datasource.datasourceId]) === null || _selectedTableTypesMa === void 0 ? void 0 : _selectedTableTypesMa.length);
69
+ });
70
+ }
17
71
  var SelectTable = function SelectTable(_ref) {
18
72
  var _ref$data = _ref.data,
19
73
  data = _ref$data === void 0 ? [] : _ref$data,
@@ -22,12 +76,10 @@ var SelectTable = function SelectTable(_ref) {
22
76
  value = _ref.value,
23
77
  _ref$onChange = _ref.onChange,
24
78
  onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
25
- onDatasourceTypeChange = _ref.onDatasourceTypeChange,
26
79
  didUpdate = _ref.didUpdate,
27
80
  _ref$tableFlat = _ref.tableFlat,
28
81
  tableFlat = _ref$tableFlat === void 0 ? false : _ref$tableFlat;
29
82
  var store = useStore();
30
- var flatTableRef = useRef(null);
31
83
  var _useState = useState(false),
32
84
  _useState2 = _slicedToArray(_useState, 2),
33
85
  loading = _useState2[0],
@@ -35,267 +87,145 @@ var SelectTable = function SelectTable(_ref) {
35
87
  var _useState3 = useState(data.slice()),
36
88
  _useState4 = _slicedToArray(_useState3, 1),
37
89
  datasource = _useState4[0];
38
- var _useState5 = useState(function () {
39
- return sortSelectedDatasourceFirst(sourceTable.slice(), value.datasourceId);
40
- }),
90
+ var _useState5 = useState(sourceTable.slice()),
41
91
  _useState6 = _slicedToArray(_useState5, 2),
42
- originDatasourceTable = _useState6[0],
43
- setOriginDatasourceTable = _useState6[1];
44
- var _useState7 = useState(function () {
45
- return sortSelectedDatasourceFirst(sourceTable.slice(), value.datasourceId);
46
- }),
92
+ datasourceTable = _useState6[0],
93
+ setDatasourceTable = _useState6[1];
94
+ var _useState7 = useState([]),
47
95
  _useState8 = _slicedToArray(_useState7, 2),
48
- datasourceTable = _useState8[0],
49
- setDatasourceTable = _useState8[1];
96
+ list = _useState8[0],
97
+ setList = _useState8[1];
50
98
  var _useState9 = useState([]),
51
99
  _useState0 = _slicedToArray(_useState9, 2),
52
- list = _useState0[0],
53
- setList = _useState0[1];
54
- var _useState1 = useState([]),
100
+ originList = _useState0[0],
101
+ setOriginList = _useState0[1];
102
+ var _useState1 = useState(''),
55
103
  _useState10 = _slicedToArray(_useState1, 2),
56
- originList = _useState10[0],
57
- setOriginList = _useState10[1];
58
- var _useState11 = useState(value),
104
+ searchVal = _useState10[0],
105
+ setSearchVal = _useState10[1];
106
+ var _useState11 = useState(''),
59
107
  _useState12 = _slicedToArray(_useState11, 2),
60
- val = _useState12[0],
61
- setVal = _useState12[1];
62
- var _useState13 = useState(''),
108
+ flatSearchVal = _useState12[0],
109
+ setFlatSearchVal = _useState12[1];
110
+ var _useState13 = useState([]),
63
111
  _useState14 = _slicedToArray(_useState13, 2),
64
- tableFilterValue = _useState14[0],
65
- setTableFilterValue = _useState14[1];
112
+ selectedTableTypes = _useState14[0],
113
+ setSelectedTableTypes = _useState14[1];
114
+ var _useState15 = useState({}),
115
+ _useState16 = _slicedToArray(_useState15, 2),
116
+ selectedFlatTableTypes = _useState16[0],
117
+ setSelectedFlatTableTypes = _useState16[1];
118
+ var _useState17 = useState(value),
119
+ _useState18 = _slicedToArray(_useState17, 2),
120
+ val = _useState18[0],
121
+ setVal = _useState18[1];
122
+ var searchInputRef = useRef(null);
123
+ var flatSearchInputRef = useRef(null);
124
+ var tableTypeOptions = useMemo(function () {
125
+ return getTableTypeOptions(originList);
126
+ }, [originList]);
127
+ var flatTableTypeOptions = useMemo(function () {
128
+ return getFlatTableTypeOptions(sourceTable);
129
+ }, [sourceTable]);
130
+ var nextPage = !val.datasourceId;
66
131
  useEffect(function () {
67
132
  if (value.datasourceId) {
68
- var datasourceItem = getDatasource(value.datasourceId);
69
- var _datasourceType = value.datasourceType || getDefaultDatasourceType(datasourceItem);
70
- var nextVal = _objectSpread(_objectSpread({}, value), {}, {
71
- datasourceType: _datasourceType
72
- });
73
- setVal(nextVal);
74
- if (!value.datasourceType && _datasourceType) {
75
- emitDatasourceTypeChange(nextVal);
76
- }
77
- loadTables(value.datasourceId, _datasourceType).then(function (tables) {
78
- if (tableFlat) {
79
- updateFlatDatasourceTables(value.datasourceId, _datasourceType, tables);
80
- }
81
- });
133
+ getTables(value.datasourceId);
82
134
  }
83
135
  }, []);
84
- function getDefaultDatasourceType(datasource) {
85
- var _datasource$datasourc;
86
- return (datasource === null || datasource === void 0 ? void 0 : datasource.defaultDatasourceType) || (datasource === null || datasource === void 0 ? void 0 : datasource.datasourceType) || (datasource === null || datasource === void 0 || (_datasource$datasourc = datasource.datasourceTypeList) === null || _datasource$datasourc === void 0 || (_datasource$datasourc = _datasource$datasourc[0]) === null || _datasource$datasourc === void 0 ? void 0 : _datasource$datasourc.value) || '';
87
- }
88
- function getDatasource(datasourceId) {
89
- return datasource.find(function (v) {
90
- return v.datasourceId === datasourceId;
91
- });
92
- }
93
- function getFlatDatasourceType(datasourceItem) {
94
- if (val.datasourceId === datasourceItem.datasourceId && val.datasourceType) {
95
- return val.datasourceType;
96
- }
97
- return datasourceItem.datasourceType || getDefaultDatasourceType(datasourceItem);
98
- }
99
- function sortSelectedDatasourceFirst(tables, datasourceId) {
100
- var selectedDatasourceId = datasourceId || value.datasourceId;
101
- if (!tableFlat || !selectedDatasourceId) return tables.slice();
102
- var selectedIndex = tables.findIndex(function (item) {
103
- return item.datasourceId === selectedDatasourceId;
104
- });
105
- if (selectedIndex <= 0) return tables.slice();
106
- var nextTables = tables.slice();
107
- var _nextTables$splice = nextTables.splice(selectedIndex, 1),
108
- _nextTables$splice2 = _slicedToArray(_nextTables$splice, 1),
109
- selectedTable = _nextTables$splice2[0];
110
- return [selectedTable].concat(_toConsumableArray(nextTables));
136
+ function getTables(_x) {
137
+ return _getTables.apply(this, arguments);
111
138
  }
112
- function updateFlatDatasourceTables(datasourceId, datasourceType, tables) {
113
- var tablesData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : originDatasourceTable;
114
- var scrollToTop = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
115
- var nextOriginDatasourceTable = sortSelectedDatasourceFirst(tablesData, datasourceId).map(function (v) {
116
- if (v.datasourceId !== datasourceId) return v;
117
- return _objectSpread(_objectSpread({}, v), {}, {
118
- datasourceType: datasourceType,
119
- children: tables
120
- });
121
- });
122
- setOriginDatasourceTable(nextOriginDatasourceTable);
123
- setDatasourceTable(filterDatasourceTables(nextOriginDatasourceTable, tableFilterValue));
124
- if (scrollToTop) {
125
- requestAnimationFrame(function () {
126
- var _flatTableRef$current;
127
- var scrollContainer = (_flatTableRef$current = flatTableRef.current) === null || _flatTableRef$current === void 0 ? void 0 : _flatTableRef$current.parentElement;
128
- if (scrollContainer) {
129
- scrollContainer.scrollTop = 0;
130
- }
131
- });
132
- }
133
- }
134
- function filterDatasourceTables(tables, keyword) {
135
- var searchVal = keyword.toLocaleLowerCase();
136
- if (!searchVal) return tables.slice();
137
- return cloneDeep(tables.slice()).map(function (v) {
138
- var _v$children;
139
- return _objectSpread(_objectSpread({}, v), {}, {
140
- children: v === null || v === void 0 || (_v$children = v.children) === null || _v$children === void 0 ? void 0 : _v$children.filter(function (vv) {
141
- return ~(vv.name + (vv.name_zh || '')).toLocaleLowerCase().indexOf(searchVal);
142
- })
143
- });
144
- }).filter(function (v) {
145
- return (v.children || []).length > 0;
146
- });
147
- }
148
- function loadTables(_x) {
149
- return _loadTables.apply(this, arguments);
150
- }
151
- function _loadTables() {
152
- _loadTables = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(datasourceId) {
153
- var datasourceType,
154
- force,
155
- tables,
156
- _args = arguments;
139
+ function _getTables() {
140
+ _getTables = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(datasourceId) {
141
+ var tables;
157
142
  return _regeneratorRuntime.wrap(function (_context) {
158
143
  while (1) switch (_context.prev = _context.next) {
159
144
  case 0:
160
- datasourceType = _args.length > 1 && _args[1] !== undefined ? _args[1] : '';
161
- force = _args.length > 2 && _args[2] !== undefined ? _args[2] : false;
162
145
  setLoading(true);
163
146
  _context.next = 1;
164
- return store.fetchDataset(datasourceId, datasourceType, force);
147
+ return store.fetchDataset(datasourceId);
165
148
  case 1:
166
149
  tables = _context.sent;
167
150
  setLoading(false);
168
151
  setList(tables);
169
152
  setOriginList(tables);
170
- return _context.abrupt("return", tables);
153
+ setSearchVal('');
154
+ setSelectedTableTypes([]);
171
155
  case 2:
172
156
  case "end":
173
157
  return _context.stop();
174
158
  }
175
159
  }, _callee);
176
160
  }));
177
- return _loadTables.apply(this, arguments);
178
- }
179
- function emitDatasourceTypeChange(nextVal) {
180
- if (!nextVal.datasourceId || !nextVal.name) return;
181
- onDatasourceTypeChange === null || onDatasourceTypeChange === void 0 || onDatasourceTypeChange(nextVal);
182
- }
183
- function handleSelectDatasource(datasource, datasourceType) {
184
- var force = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
185
- var nextDatasourceType = datasourceType || getDefaultDatasourceType(datasource);
186
- setVal({
187
- datasourceId: datasource.datasourceId,
188
- datasourceName: datasource.datasourceName,
189
- datasourceType: nextDatasourceType,
190
- name: '',
191
- name_zh: '',
192
- id: '',
193
- tableUuid: uuidv4('table'),
194
- alias: ''
195
- });
196
- loadTables(datasource.datasourceId, nextDatasourceType, force);
197
- }
198
- function handleDatasourceTypeChange(datasourceType) {
199
- var nextVal = _objectSpread(_objectSpread({}, val), {}, {
200
- datasourceType: datasourceType
201
- });
202
- setVal(nextVal);
203
- loadTables(nextVal.datasourceId, datasourceType, true);
204
- }
205
- function handleFlatDatasourceTypeChange(_x2, _x3) {
206
- return _handleFlatDatasourceTypeChange.apply(this, arguments);
207
- }
208
- function _handleFlatDatasourceTypeChange() {
209
- _handleFlatDatasourceTypeChange = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(datasourceItem, datasourceType) {
210
- var nextVal, tables;
211
- return _regeneratorRuntime.wrap(function (_context2) {
212
- while (1) switch (_context2.prev = _context2.next) {
213
- case 0:
214
- if (val.datasourceId === datasourceItem.datasourceId) {
215
- nextVal = _objectSpread(_objectSpread({}, val), {}, {
216
- datasourceType: datasourceType
217
- });
218
- setVal(nextVal);
219
- }
220
- _context2.next = 1;
221
- return loadTables(datasourceItem.datasourceId, datasourceType, true);
222
- case 1:
223
- tables = _context2.sent;
224
- updateFlatDatasourceTables(datasourceItem.datasourceId, datasourceType, tables, undefined, true);
225
- case 2:
226
- case "end":
227
- return _context2.stop();
228
- }
229
- }, _callee2);
230
- }));
231
- return _handleFlatDatasourceTypeChange.apply(this, arguments);
232
- }
233
- function renderDatasourceTypeSelector(datasourceItem, datasourceType, onChange) {
234
- var datasourceTypeList = datasourceItem.datasourceTypeList || [];
235
- if (!datasourceTypeList.length) return null;
236
- return _jsx("div", {
237
- className: 'Sqb-DatasourceType-radio',
238
- onClick: function onClick(e) {
239
- return e.stopPropagation();
240
- },
241
- children: datasourceTypeList.map(function (item) {
242
- var checked = datasourceType === item.value;
243
- var handleChangeType = function handleChangeType(e) {
244
- e.preventDefault();
245
- e.stopPropagation();
246
- if (!checked) onChange(item.value);
247
- };
248
- return _jsxs("label", {
249
- className: 'Sqb-DatasourceType-radio-item',
250
- onMouseDown: handleChangeType,
251
- onClick: handleChangeType,
252
- children: [_jsx("input", {
253
- type: 'radio',
254
- name: "datasourceType_".concat(datasourceItem.datasourceId || 'current'),
255
- checked: checked,
256
- readOnly: true
257
- }), _jsx("span", {
258
- children: item.label
259
- })]
260
- }, item.value);
261
- })
262
- });
161
+ return _getTables.apply(this, arguments);
263
162
  }
264
- useEffect(function () {
265
- var nextSourceTable = sourceTable.slice();
266
- if (tableFlat && val.datasourceId) {
267
- var _store$getDataset;
268
- var _datasourceType2 = val.datasourceType;
269
- var cachedTables = _datasourceType2 ? (_store$getDataset = store.getDataset) === null || _store$getDataset === void 0 ? void 0 : _store$getDataset.call(store, val.datasourceId, _datasourceType2) : [];
270
- if (_datasourceType2 && cachedTables !== null && cachedTables !== void 0 && cachedTables.length) {
271
- updateFlatDatasourceTables(val.datasourceId, _datasourceType2, cachedTables, nextSourceTable);
272
- return;
273
- }
274
- }
275
- var sortedSourceTable = sortSelectedDatasourceFirst(nextSourceTable, val.datasourceId);
276
- setOriginDatasourceTable(sortedSourceTable);
277
- setDatasourceTable(filterDatasourceTables(sortedSourceTable, tableFilterValue));
278
- }, [sourceTable]);
279
163
  useEffect(function () {
280
164
  didUpdate === null || didUpdate === void 0 || didUpdate();
281
165
  }, [list, loading, datasource]);
166
+ useEffect(function () {
167
+ if (tableFlat) {
168
+ focusWithoutScroll(flatSearchInputRef.current);
169
+ return;
170
+ }
171
+ if (!nextPage && !loading) {
172
+ focusWithoutScroll(searchInputRef.current);
173
+ }
174
+ }, [tableFlat, nextPage, loading]);
175
+ useEffect(function () {
176
+ setList(filterTables(originList, searchVal, selectedTableTypes));
177
+ }, [originList, searchVal, selectedTableTypes]);
178
+ useEffect(function () {
179
+ setDatasourceTable(filterDatasourceTable(sourceTable, flatSearchVal, selectedFlatTableTypes));
180
+ }, [sourceTable, flatSearchVal, selectedFlatTableTypes]);
181
+ useEffect(function () {
182
+ setSelectedTableTypes(function (prev) {
183
+ return prev.filter(function (v) {
184
+ return tableTypeOptions.includes(v);
185
+ });
186
+ });
187
+ }, [tableTypeOptions]);
188
+ useEffect(function () {
189
+ setSelectedFlatTableTypes(function (prev) {
190
+ var next = Object.keys(flatTableTypeOptions).reduce(function (mo, datasourceId) {
191
+ var selected = prev[datasourceId] || [];
192
+ mo[datasourceId] = selected.filter(function (v) {
193
+ return flatTableTypeOptions[datasourceId].includes(v);
194
+ });
195
+ return mo;
196
+ }, {});
197
+ return next;
198
+ });
199
+ }, [flatTableTypeOptions]);
282
200
  function onInput(e) {
283
- var val = e.target.value;
284
- var newList = cloneDeep(originList.slice());
285
- setList(newList.filter(function (v) {
286
- return ~(v.name + (v.name_zh || '')).toLocaleLowerCase().indexOf(val.toLocaleLowerCase());
287
- }));
201
+ setSearchVal(e.target.value);
288
202
  }
289
203
  function onInput1(e) {
290
- var val = e.target.value;
291
- setTableFilterValue(val);
292
- setDatasourceTable(filterDatasourceTables(originDatasourceTable, val));
204
+ setFlatSearchVal(e.target.value);
205
+ }
206
+ function onTableTypeChange(tableType, checked) {
207
+ setSelectedTableTypes(function (prev) {
208
+ if (checked) {
209
+ return prev.includes(tableType) ? prev : prev.concat(tableType);
210
+ }
211
+ return prev.filter(function (v) {
212
+ return v !== tableType;
213
+ });
214
+ });
215
+ }
216
+ function onFlatTableTypeChange(datasourceId, tableType, checked) {
217
+ setSelectedFlatTableTypes(function (prev) {
218
+ var selectedTableTypes = prev[datasourceId] || [];
219
+ var nextTableTypes = checked ? selectedTableTypes.includes(tableType) ? selectedTableTypes : selectedTableTypes.concat(tableType) : selectedTableTypes.filter(function (v) {
220
+ return v !== tableType;
221
+ });
222
+ return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, datasourceId, nextTableTypes));
223
+ });
293
224
  }
294
225
  function goPrevPage() {
295
226
  setVal({
296
227
  datasourceId: '',
297
228
  datasourceName: '',
298
- datasourceType: '',
299
229
  name: '',
300
230
  name_zh: '',
301
231
  tableUuid: '',
@@ -303,10 +233,57 @@ var SelectTable = function SelectTable(_ref) {
303
233
  alias: ''
304
234
  });
305
235
  }
236
+ function renderTableTypeFilter(tableTypes) {
237
+ if (tableTypes.length <= 1) return null;
238
+ return _jsx("div", {
239
+ className: 'Sqb-TableType-tag-group',
240
+ children: tableTypes.map(function (tableType) {
241
+ var checked = selectedTableTypes.includes(tableType);
242
+ return _jsx(Tag, {
243
+ className: ':Sqb-TableType-filter-tag',
244
+ checkable: true,
245
+ checked: checked,
246
+ size: 'mini',
247
+ onChange: function onChange(checked) {
248
+ return onTableTypeChange(tableType, checked);
249
+ },
250
+ children: tableType
251
+ }, tableType);
252
+ })
253
+ });
254
+ }
255
+ function renderFlatTableTypeFilter(datasourceId, tableTypes) {
256
+ if (tableTypes.length <= 1) return null;
257
+ var selectedTableTypes = selectedFlatTableTypes[datasourceId] || [];
258
+ return _jsx("div", {
259
+ className: 'Sqb-TableType-tag-group',
260
+ children: tableTypes.map(function (tableType) {
261
+ var checked = selectedTableTypes.includes(tableType);
262
+ return _jsx(Tag, {
263
+ className: ':Sqb-TableType-filter-tag',
264
+ checkable: true,
265
+ checked: checked,
266
+ size: 'mini',
267
+ onChange: function onChange(checked) {
268
+ return onFlatTableTypeChange(datasourceId, tableType, checked);
269
+ },
270
+ children: tableType
271
+ }, tableType);
272
+ })
273
+ });
274
+ }
275
+ function renderDatasourceTitle(table) {
276
+ return _jsxs("div", {
277
+ className: cx("Sqb-List-title Sqb-List-title-with-filter mx-4 pb-2 pt-2"),
278
+ children: [_jsx("span", {
279
+ className: 'Sqb-List-title-text',
280
+ children: table.datasourceName
281
+ }), renderFlatTableTypeFilter(table.datasourceId, flatTableTypeOptions[table.datasourceId] || [])]
282
+ });
283
+ }
306
284
  if (tableFlat) {
307
285
  return _jsx("div", {
308
286
  className: cx("Sqb-SelectTable--box pb-2"),
309
- ref: flatTableRef,
310
287
  children: _jsx("div", {
311
288
  style: {
312
289
  minWidth: 300
@@ -323,7 +300,7 @@ var SelectTable = function SelectTable(_ref) {
323
300
  className: 'px-2',
324
301
  children: _jsx(SearchIcon, {})
325
302
  }), _jsx("input", {
326
- autoFocus: true,
303
+ ref: flatSearchInputRef,
327
304
  type: 'text',
328
305
  className: 'p-2',
329
306
  placeholder: __('data.search'),
@@ -332,36 +309,26 @@ var SelectTable = function SelectTable(_ref) {
332
309
  })
333
310
  }), datasourceTable.map(function (table) {
334
311
  var _table$children;
335
- var datasourceType = getFlatDatasourceType(table);
336
312
  return _jsxs(React.Fragment, {
337
- children: [_jsxs("div", {
338
- className: cx("Sqb-List-title mx-4 pb-2 pt-2"),
339
- children: [_jsx("span", {
340
- children: table.datasourceName
341
- }), renderDatasourceTypeSelector(table, datasourceType, function (type) {
342
- return handleFlatDatasourceTypeChange(table, type);
343
- })]
344
- }), Array.isArray(table.children) && (table === null || table === void 0 || (_table$children = table.children) === null || _table$children === void 0 ? void 0 : _table$children.map(function (v) {
313
+ children: [renderDatasourceTitle(table), Array.isArray(table.children) && (table === null || table === void 0 || (_table$children = table.children) === null || _table$children === void 0 ? void 0 : _table$children.map(function (v) {
345
314
  var _val = {
346
315
  datasourceId: table.datasourceId,
347
316
  datasourceName: table.datasourceName,
348
- datasourceType: datasourceType,
349
317
  name: '',
350
318
  name_zh: '',
351
319
  id: '',
352
320
  tableUuid: uuidv4('table'),
353
321
  alias: ''
354
322
  };
323
+ var tableValue = _objectSpread(_objectSpread({}, _val), v);
355
324
  return _jsx("div", {
356
325
  className: cx("Sqb-List-section"),
357
326
  children: _jsx("div", {
358
327
  className: cx("Sqb-List-item mx-2", {
359
- active: val.datasourceId === table.datasourceId && val.id === v.id && (val.datasourceType || datasourceType) === datasourceType
328
+ active: isSameTableByIdFirst(value, tableValue)
360
329
  }),
361
330
  onClick: function onClick() {
362
- onChange(_objectSpread(_objectSpread(_objectSpread({}, _val), v), {}, {
363
- datasourceType: datasourceType
364
- }));
331
+ onChange(tableValue);
365
332
  },
366
333
  children: _jsxs("a", {
367
334
  className: 'p-2',
@@ -376,15 +343,14 @@ var SelectTable = function SelectTable(_ref) {
376
343
  })]
377
344
  })
378
345
  })
379
- }, "".concat(datasourceType, "_").concat(v.name));
346
+ }, getTableIdFirstKey(tableValue));
380
347
  }))]
381
- }, "".concat(table.datasourceId, "_").concat(datasourceType));
348
+ }, table.datasourceId);
382
349
  })]
383
350
  })
384
351
  })
385
352
  });
386
353
  }
387
- var nextPage = !val.datasourceId;
388
354
  if (nextPage) {
389
355
  return _jsx("div", {
390
356
  className: cx("Sqb-SelectDataSource--box pb-2 pt-2"),
@@ -404,7 +370,16 @@ var SelectTable = function SelectTable(_ref) {
404
370
  active: val.datasourceId === v.datasourceId
405
371
  }),
406
372
  onClick: function onClick() {
407
- handleSelectDatasource(v);
373
+ setVal({
374
+ datasourceId: v.datasourceId,
375
+ datasourceName: v.datasourceName,
376
+ name: '',
377
+ name_zh: '',
378
+ id: '',
379
+ tableUuid: uuidv4('table'),
380
+ alias: ''
381
+ });
382
+ getTables(v.datasourceId);
408
383
  },
409
384
  children: _jsxs("a", {
410
385
  className: 'p-2',
@@ -425,8 +400,6 @@ var SelectTable = function SelectTable(_ref) {
425
400
  })
426
401
  });
427
402
  }
428
- var selectedDatasource = getDatasource(val.datasourceId) || val;
429
- var datasourceType = val.datasourceType || getDefaultDatasourceType(selectedDatasource);
430
403
  return _jsx("div", {
431
404
  className: cx("Sqb-SelectTable--box pb-2"),
432
405
  children: _jsx("div", {
@@ -437,17 +410,15 @@ var SelectTable = function SelectTable(_ref) {
437
410
  style: {
438
411
  width: '100%'
439
412
  },
440
- children: [_jsx("div", {
413
+ children: [_jsxs("div", {
441
414
  className: 'header',
442
- children: _jsxs("div", {
415
+ children: [_jsx("div", {
443
416
  className: 'left-info',
444
- children: [_jsxs("span", {
417
+ children: _jsxs("span", {
445
418
  onClick: goPrevPage,
446
419
  children: [_jsx(LeftArrowIcon, {}), val.datasourceName]
447
- }), renderDatasourceTypeSelector(selectedDatasource, datasourceType, function (type) {
448
- return handleDatasourceTypeChange(type);
449
- })]
450
- })
420
+ })
421
+ }), renderTableTypeFilter(tableTypeOptions)]
451
422
  }), loading ? _jsx("div", {
452
423
  className: 'Sqb-SelectTable-loading',
453
424
  children: _jsx(Loading, {
@@ -463,7 +434,7 @@ var SelectTable = function SelectTable(_ref) {
463
434
  className: 'px-2',
464
435
  children: _jsx(SearchIcon, {})
465
436
  }), _jsx("input", {
466
- autoFocus: true,
437
+ ref: searchInputRef,
467
438
  type: 'text',
468
439
  className: 'p-2',
469
440
  placeholder: __('data.search'),
@@ -471,16 +442,15 @@ var SelectTable = function SelectTable(_ref) {
471
442
  })]
472
443
  })
473
444
  }), Array.isArray(list) && list.map(function (v) {
445
+ var tableValue = _objectSpread(_objectSpread({}, val), v);
474
446
  return _jsx("div", {
475
447
  className: cx("Sqb-List-section"),
476
448
  children: _jsx("div", {
477
449
  className: cx("Sqb-List-item mx-2", {
478
- active: val.datasourceId === value.datasourceId && val.id === v.id && (val.datasourceType || datasourceType) === datasourceType
450
+ active: isSameTableByIdFirst(value, tableValue)
479
451
  }),
480
452
  onClick: function onClick() {
481
- onChange(_objectSpread(_objectSpread(_objectSpread({}, val), v), {}, {
482
- datasourceType: datasourceType
483
- }));
453
+ onChange(tableValue);
484
454
  },
485
455
  children: _jsxs("a", {
486
456
  className: 'p-2',
@@ -495,7 +465,7 @@ var SelectTable = function SelectTable(_ref) {
495
465
  })]
496
466
  })
497
467
  })
498
- }, v.name);
468
+ }, getTableIdFirstKey(tableValue));
499
469
  })]
500
470
  })]
501
471
  })