@gingkoo/pandora-metabase 1.0.129 → 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 +230 -210
  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 +232 -212
  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
@@ -103,7 +103,6 @@ var SelectSummarize = function SelectSummarize(_ref) {
103
103
  tableUuid: value.tableUuid || '',
104
104
  datasourceName: value.datasourceName || '',
105
105
  datasourceId: value.datasourceId || '',
106
- datasourceType: value.datasourceType || '',
107
106
  type: AtomsTypeEnum.FIELD
108
107
  };
109
108
  return [fieldAtom];
@@ -170,8 +169,7 @@ var SelectSummarize = function SelectSummarize(_ref) {
170
169
  fieldAlias: '',
171
170
  fieldUuid: '',
172
171
  datasourceId: '',
173
- datasourceName: '',
174
- datasourceType: ''
172
+ datasourceName: ''
175
173
  } : {}), record), {}, {
176
174
  condition: condition,
177
175
  quotes: quotes
@@ -6,9 +6,8 @@ interface PropsType {
6
6
  sourceTable: any[];
7
7
  value: MetaData_TableType;
8
8
  onChange: (reocrd: MetaData_TableType) => void;
9
- onDatasourceTypeChange?: (record: MetaData_TableType) => void;
10
9
  didUpdate?: Function;
11
10
  tableFlat?: boolean;
12
11
  }
13
- declare const SelectTable: ({ data, sourceTable, value, onChange, onDatasourceTypeChange, didUpdate, tableFlat, }: PropsType) => import("react/jsx-runtime").JSX.Element;
12
+ declare const SelectTable: ({ data, sourceTable, value, onChange, didUpdate, tableFlat, }: PropsType) => import("react/jsx-runtime").JSX.Element;
14
13
  export default SelectTable;
@@ -1,18 +1,73 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
6
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
6
7
  import './index.less';
7
- import React, { useState, useEffect } from 'react';
8
- import cloneDeep from 'lodash/cloneDeep';
8
+ import React, { useState, useEffect, useMemo, useRef } from 'react';
9
9
  import cx from 'classnames';
10
- import { uuidv4 } from '../../../utils/helper';
10
+ import { Tag } from '@gingkoo/pandora';
11
+ import { getTableIdFirstKey, isSameTableByIdFirst, uuidv4 } from '../../../utils/helper';
11
12
  import { useStore } from '../../../hooks/use-provider';
12
13
  import Loading from '../../../common/Loading';
13
14
  import { __ } from '../../../locale';
14
15
  import { replaceTpl } from '../../../utils/helper';
15
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
+ }
16
71
  var SelectTable = function SelectTable(_ref) {
17
72
  var _ref$data = _ref.data,
18
73
  data = _ref$data === void 0 ? [] : _ref$data,
@@ -21,7 +76,6 @@ var SelectTable = function SelectTable(_ref) {
21
76
  value = _ref.value,
22
77
  _ref$onChange = _ref.onChange,
23
78
  onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
24
- onDatasourceTypeChange = _ref.onDatasourceTypeChange,
25
79
  didUpdate = _ref.didUpdate,
26
80
  _ref$tableFlat = _ref.tableFlat,
27
81
  tableFlat = _ref$tableFlat === void 0 ? false : _ref$tableFlat;
@@ -35,218 +89,143 @@ var SelectTable = function SelectTable(_ref) {
35
89
  datasource = _useState4[0];
36
90
  var _useState5 = useState(sourceTable.slice()),
37
91
  _useState6 = _slicedToArray(_useState5, 2),
38
- originDatasourceTable = _useState6[0],
39
- setOriginDatasourceTable = _useState6[1];
40
- var _useState7 = useState(sourceTable.slice()),
92
+ datasourceTable = _useState6[0],
93
+ setDatasourceTable = _useState6[1];
94
+ var _useState7 = useState([]),
41
95
  _useState8 = _slicedToArray(_useState7, 2),
42
- datasourceTable = _useState8[0],
43
- setDatasourceTable = _useState8[1];
96
+ list = _useState8[0],
97
+ setList = _useState8[1];
44
98
  var _useState9 = useState([]),
45
99
  _useState0 = _slicedToArray(_useState9, 2),
46
- list = _useState0[0],
47
- setList = _useState0[1];
48
- var _useState1 = useState([]),
100
+ originList = _useState0[0],
101
+ setOriginList = _useState0[1];
102
+ var _useState1 = useState(''),
49
103
  _useState10 = _slicedToArray(_useState1, 2),
50
- originList = _useState10[0],
51
- setOriginList = _useState10[1];
52
- var _useState11 = useState(value),
104
+ searchVal = _useState10[0],
105
+ setSearchVal = _useState10[1];
106
+ var _useState11 = useState(''),
53
107
  _useState12 = _slicedToArray(_useState11, 2),
54
- val = _useState12[0],
55
- setVal = _useState12[1];
56
- var _useState13 = useState(''),
108
+ flatSearchVal = _useState12[0],
109
+ setFlatSearchVal = _useState12[1];
110
+ var _useState13 = useState([]),
57
111
  _useState14 = _slicedToArray(_useState13, 2),
58
- tableFilterValue = _useState14[0],
59
- 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;
60
131
  useEffect(function () {
61
132
  if (value.datasourceId) {
62
- var datasourceItem = getDatasource(value.datasourceId);
63
- var _datasourceType = value.datasourceType || getDefaultDatasourceType(datasourceItem);
64
- var nextVal = _objectSpread(_objectSpread({}, value), {}, {
65
- datasourceType: _datasourceType
66
- });
67
- setVal(nextVal);
68
- if (!value.datasourceType && _datasourceType) {
69
- emitDatasourceTypeChange(nextVal);
70
- }
71
- loadTables(value.datasourceId, _datasourceType);
133
+ getTables(value.datasourceId);
72
134
  }
73
135
  }, []);
74
- function getDefaultDatasourceType(datasource) {
75
- var _datasource$datasourc;
76
- 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) || '';
77
- }
78
- function getDatasource(datasourceId) {
79
- return datasource.find(function (v) {
80
- return v.datasourceId === datasourceId;
81
- });
82
- }
83
- function filterDatasourceTables(tables, keyword) {
84
- var searchVal = keyword.toLocaleLowerCase();
85
- if (!searchVal) return tables.slice();
86
- return cloneDeep(tables.slice()).map(function (v) {
87
- var _v$children;
88
- return _objectSpread(_objectSpread({}, v), {}, {
89
- children: v === null || v === void 0 || (_v$children = v.children) === null || _v$children === void 0 ? void 0 : _v$children.filter(function (vv) {
90
- return ~(vv.name + (vv.name_zh || '')).toLocaleLowerCase().indexOf(searchVal);
91
- })
92
- });
93
- }).filter(function (v) {
94
- return (v.children || []).length > 0;
95
- });
96
- }
97
- function loadTables(_x) {
98
- return _loadTables.apply(this, arguments);
136
+ function getTables(_x) {
137
+ return _getTables.apply(this, arguments);
99
138
  }
100
- function _loadTables() {
101
- _loadTables = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(datasourceId) {
102
- var datasourceType,
103
- force,
104
- tables,
105
- _args = arguments;
139
+ function _getTables() {
140
+ _getTables = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(datasourceId) {
141
+ var tables;
106
142
  return _regeneratorRuntime.wrap(function (_context) {
107
143
  while (1) switch (_context.prev = _context.next) {
108
144
  case 0:
109
- datasourceType = _args.length > 1 && _args[1] !== undefined ? _args[1] : '';
110
- force = _args.length > 2 && _args[2] !== undefined ? _args[2] : false;
111
145
  setLoading(true);
112
146
  _context.next = 1;
113
- return store.fetchDataset(datasourceId, datasourceType, force);
147
+ return store.fetchDataset(datasourceId);
114
148
  case 1:
115
149
  tables = _context.sent;
116
150
  setLoading(false);
117
151
  setList(tables);
118
152
  setOriginList(tables);
119
- return _context.abrupt("return", tables);
153
+ setSearchVal('');
154
+ setSelectedTableTypes([]);
120
155
  case 2:
121
156
  case "end":
122
157
  return _context.stop();
123
158
  }
124
159
  }, _callee);
125
160
  }));
126
- return _loadTables.apply(this, arguments);
127
- }
128
- function emitDatasourceTypeChange(nextVal) {
129
- if (!nextVal.datasourceId || !nextVal.name) return;
130
- onDatasourceTypeChange === null || onDatasourceTypeChange === void 0 || onDatasourceTypeChange(nextVal);
131
- }
132
- function handleSelectDatasource(datasource, datasourceType) {
133
- var force = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
134
- var nextDatasourceType = datasourceType || getDefaultDatasourceType(datasource);
135
- setVal({
136
- datasourceId: datasource.datasourceId,
137
- datasourceName: datasource.datasourceName,
138
- datasourceType: nextDatasourceType,
139
- name: '',
140
- name_zh: '',
141
- id: '',
142
- tableUuid: uuidv4('table'),
143
- alias: ''
144
- });
145
- loadTables(datasource.datasourceId, nextDatasourceType, force);
146
- }
147
- function handleDatasourceTypeChange(datasourceType) {
148
- var nextVal = _objectSpread(_objectSpread({}, val), {}, {
149
- datasourceType: datasourceType
150
- });
151
- setVal(nextVal);
152
- emitDatasourceTypeChange(nextVal);
153
- loadTables(nextVal.datasourceId, datasourceType, true);
154
- }
155
- function handleFlatDatasourceTypeChange(_x2, _x3) {
156
- return _handleFlatDatasourceTypeChange.apply(this, arguments);
157
- }
158
- function _handleFlatDatasourceTypeChange() {
159
- _handleFlatDatasourceTypeChange = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(datasourceItem, datasourceType) {
160
- var nextVal, tables, updateDatasourceTable, nextOriginDatasourceTable;
161
- return _regeneratorRuntime.wrap(function (_context2) {
162
- while (1) switch (_context2.prev = _context2.next) {
163
- case 0:
164
- if (val.datasourceId === datasourceItem.datasourceId) {
165
- nextVal = _objectSpread(_objectSpread({}, val), {}, {
166
- datasourceType: datasourceType
167
- });
168
- setVal(nextVal);
169
- emitDatasourceTypeChange(nextVal);
170
- }
171
- _context2.next = 1;
172
- return loadTables(datasourceItem.datasourceId, datasourceType, true);
173
- case 1:
174
- tables = _context2.sent;
175
- updateDatasourceTable = function updateDatasourceTable(tablesData) {
176
- return tablesData.map(function (v) {
177
- if (v.datasourceId !== datasourceItem.datasourceId) return v;
178
- return _objectSpread(_objectSpread({}, v), {}, {
179
- datasourceType: datasourceType,
180
- children: tables
181
- });
182
- });
183
- };
184
- nextOriginDatasourceTable = updateDatasourceTable(originDatasourceTable);
185
- setOriginDatasourceTable(nextOriginDatasourceTable);
186
- setDatasourceTable(filterDatasourceTables(nextOriginDatasourceTable, tableFilterValue));
187
- case 2:
188
- case "end":
189
- return _context2.stop();
190
- }
191
- }, _callee2);
192
- }));
193
- return _handleFlatDatasourceTypeChange.apply(this, arguments);
194
- }
195
- function renderDatasourceTypeSelector(datasourceItem, datasourceType, onChange) {
196
- var datasourceTypeList = datasourceItem.datasourceTypeList || [];
197
- if (!datasourceTypeList.length) return null;
198
- return _jsx("div", {
199
- className: 'Sqb-DatasourceType-radio',
200
- onClick: function onClick(e) {
201
- return e.stopPropagation();
202
- },
203
- children: datasourceTypeList.map(function (item) {
204
- var checked = datasourceType === item.value;
205
- var handleChangeType = function handleChangeType(e) {
206
- e.preventDefault();
207
- e.stopPropagation();
208
- if (!checked) onChange(item.value);
209
- };
210
- return _jsxs("label", {
211
- className: 'Sqb-DatasourceType-radio-item',
212
- onMouseDown: handleChangeType,
213
- onClick: handleChangeType,
214
- children: [_jsx("input", {
215
- type: 'radio',
216
- name: "datasourceType_".concat(datasourceItem.datasourceId || 'current'),
217
- checked: checked,
218
- readOnly: true
219
- }), _jsx("span", {
220
- children: item.label
221
- })]
222
- }, item.value);
223
- })
224
- });
161
+ return _getTables.apply(this, arguments);
225
162
  }
226
- useEffect(function () {
227
- setOriginDatasourceTable(sourceTable.slice());
228
- setDatasourceTable(filterDatasourceTables(sourceTable.slice(), tableFilterValue));
229
- }, [sourceTable]);
230
163
  useEffect(function () {
231
164
  didUpdate === null || didUpdate === void 0 || didUpdate();
232
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]);
233
200
  function onInput(e) {
234
- var val = e.target.value;
235
- var newList = cloneDeep(originList.slice());
236
- setList(newList.filter(function (v) {
237
- return ~(v.name + (v.name_zh || '')).toLocaleLowerCase().indexOf(val.toLocaleLowerCase());
238
- }));
201
+ setSearchVal(e.target.value);
239
202
  }
240
203
  function onInput1(e) {
241
- var val = e.target.value;
242
- setTableFilterValue(val);
243
- 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
+ });
244
224
  }
245
225
  function goPrevPage() {
246
226
  setVal({
247
227
  datasourceId: '',
248
228
  datasourceName: '',
249
- datasourceType: '',
250
229
  name: '',
251
230
  name_zh: '',
252
231
  tableUuid: '',
@@ -254,6 +233,54 @@ var SelectTable = function SelectTable(_ref) {
254
233
  alias: ''
255
234
  });
256
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
+ }
257
284
  if (tableFlat) {
258
285
  return _jsx("div", {
259
286
  className: cx("Sqb-SelectTable--box pb-2"),
@@ -273,7 +300,7 @@ var SelectTable = function SelectTable(_ref) {
273
300
  className: 'px-2',
274
301
  children: _jsx(SearchIcon, {})
275
302
  }), _jsx("input", {
276
- autoFocus: true,
303
+ ref: flatSearchInputRef,
277
304
  type: 'text',
278
305
  className: 'p-2',
279
306
  placeholder: __('data.search'),
@@ -282,36 +309,26 @@ var SelectTable = function SelectTable(_ref) {
282
309
  })
283
310
  }), datasourceTable.map(function (table) {
284
311
  var _table$children;
285
- var datasourceType = table.datasourceType || getDefaultDatasourceType(table);
286
312
  return _jsxs(React.Fragment, {
287
- children: [_jsxs("div", {
288
- className: cx("Sqb-List-title mx-4 pb-2 pt-2"),
289
- children: [_jsx("span", {
290
- children: table.datasourceName
291
- }), renderDatasourceTypeSelector(table, datasourceType, function (type) {
292
- return handleFlatDatasourceTypeChange(table, type);
293
- })]
294
- }), 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) {
295
314
  var _val = {
296
315
  datasourceId: table.datasourceId,
297
316
  datasourceName: table.datasourceName,
298
- datasourceType: datasourceType,
299
317
  name: '',
300
318
  name_zh: '',
301
319
  id: '',
302
320
  tableUuid: uuidv4('table'),
303
321
  alias: ''
304
322
  };
323
+ var tableValue = _objectSpread(_objectSpread({}, _val), v);
305
324
  return _jsx("div", {
306
325
  className: cx("Sqb-List-section"),
307
326
  children: _jsx("div", {
308
327
  className: cx("Sqb-List-item mx-2", {
309
- active: val.datasourceId === table.datasourceId && val.name === v.name && (val.datasourceType || datasourceType) === datasourceType
328
+ active: isSameTableByIdFirst(value, tableValue)
310
329
  }),
311
330
  onClick: function onClick() {
312
- onChange(_objectSpread(_objectSpread(_objectSpread({}, _val), v), {}, {
313
- datasourceType: datasourceType
314
- }));
331
+ onChange(tableValue);
315
332
  },
316
333
  children: _jsxs("a", {
317
334
  className: 'p-2',
@@ -326,15 +343,14 @@ var SelectTable = function SelectTable(_ref) {
326
343
  })]
327
344
  })
328
345
  })
329
- }, "".concat(datasourceType, "_").concat(v.name));
346
+ }, getTableIdFirstKey(tableValue));
330
347
  }))]
331
- }, "".concat(table.datasourceId, "_").concat(datasourceType));
348
+ }, table.datasourceId);
332
349
  })]
333
350
  })
334
351
  })
335
352
  });
336
353
  }
337
- var nextPage = !val.datasourceId;
338
354
  if (nextPage) {
339
355
  return _jsx("div", {
340
356
  className: cx("Sqb-SelectDataSource--box pb-2 pt-2"),
@@ -354,7 +370,16 @@ var SelectTable = function SelectTable(_ref) {
354
370
  active: val.datasourceId === v.datasourceId
355
371
  }),
356
372
  onClick: function onClick() {
357
- 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);
358
383
  },
359
384
  children: _jsxs("a", {
360
385
  className: 'p-2',
@@ -375,8 +400,6 @@ var SelectTable = function SelectTable(_ref) {
375
400
  })
376
401
  });
377
402
  }
378
- var selectedDatasource = getDatasource(val.datasourceId) || val;
379
- var datasourceType = val.datasourceType || getDefaultDatasourceType(selectedDatasource);
380
403
  return _jsx("div", {
381
404
  className: cx("Sqb-SelectTable--box pb-2"),
382
405
  children: _jsx("div", {
@@ -387,17 +410,15 @@ var SelectTable = function SelectTable(_ref) {
387
410
  style: {
388
411
  width: '100%'
389
412
  },
390
- children: [_jsx("div", {
413
+ children: [_jsxs("div", {
391
414
  className: 'header',
392
- children: _jsxs("div", {
415
+ children: [_jsx("div", {
393
416
  className: 'left-info',
394
- children: [_jsxs("span", {
417
+ children: _jsxs("span", {
395
418
  onClick: goPrevPage,
396
419
  children: [_jsx(LeftArrowIcon, {}), val.datasourceName]
397
- }), renderDatasourceTypeSelector(selectedDatasource, datasourceType, function (type) {
398
- return handleDatasourceTypeChange(type);
399
- })]
400
- })
420
+ })
421
+ }), renderTableTypeFilter(tableTypeOptions)]
401
422
  }), loading ? _jsx("div", {
402
423
  className: 'Sqb-SelectTable-loading',
403
424
  children: _jsx(Loading, {
@@ -413,7 +434,7 @@ var SelectTable = function SelectTable(_ref) {
413
434
  className: 'px-2',
414
435
  children: _jsx(SearchIcon, {})
415
436
  }), _jsx("input", {
416
- autoFocus: true,
437
+ ref: searchInputRef,
417
438
  type: 'text',
418
439
  className: 'p-2',
419
440
  placeholder: __('data.search'),
@@ -421,16 +442,15 @@ var SelectTable = function SelectTable(_ref) {
421
442
  })]
422
443
  })
423
444
  }), Array.isArray(list) && list.map(function (v) {
445
+ var tableValue = _objectSpread(_objectSpread({}, val), v);
424
446
  return _jsx("div", {
425
447
  className: cx("Sqb-List-section"),
426
448
  children: _jsx("div", {
427
449
  className: cx("Sqb-List-item mx-2", {
428
- active: val.datasourceId === value.datasourceId && val.name === v.name && (val.datasourceType || datasourceType) === datasourceType
450
+ active: isSameTableByIdFirst(value, tableValue)
429
451
  }),
430
452
  onClick: function onClick() {
431
- onChange(_objectSpread(_objectSpread(_objectSpread({}, val), v), {}, {
432
- datasourceType: datasourceType
433
- }));
453
+ onChange(tableValue);
434
454
  },
435
455
  children: _jsxs("a", {
436
456
  className: 'p-2',
@@ -445,7 +465,7 @@ var SelectTable = function SelectTable(_ref) {
445
465
  })]
446
466
  })
447
467
  })
448
- }, v.name);
468
+ }, getTableIdFirstKey(tableValue));
449
469
  })]
450
470
  })]
451
471
  })