@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.
- package/lib/cjs/components/dialog/expression/index.js +0 -1
- package/lib/cjs/components/dialog/formula-list/utils.js +0 -3
- package/lib/cjs/components/dialog/select-column/index.js +2 -2
- package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +0 -1
- package/lib/cjs/components/dialog/select-column-multiple/index.js +44 -19
- package/lib/cjs/components/dialog/select-join-column/index.js +23 -7
- package/lib/cjs/components/dialog/select-join-column-multiple/index.js +15 -6
- package/lib/cjs/components/dialog/select-permission-table/index.js +2 -2
- package/lib/cjs/components/dialog/select-summarize/index.js +1 -3
- package/lib/cjs/components/dialog/select-table/index.d.ts +1 -2
- package/lib/cjs/components/dialog/select-table/index.js +231 -261
- package/lib/cjs/components/dialog/select-table/index.less +51 -36
- package/lib/cjs/components/metabase/index.js +34 -16
- package/lib/cjs/components/modules/components/item-name.js +0 -1
- package/lib/cjs/components/modules/custom-column.js +3 -7
- package/lib/cjs/components/modules/filter.js +3 -6
- package/lib/cjs/components/modules/join-data.js +41 -87
- package/lib/cjs/components/modules/permission-table.js +5 -9
- package/lib/cjs/components/modules/sort.js +1 -2
- package/lib/cjs/components/modules/summarize/group-by.js +1 -8
- package/lib/cjs/components/modules/summarize/select-index.js +1 -4
- package/lib/cjs/components/modules/table-data.js +28 -44
- package/lib/cjs/hooks/use-state.js +22 -147
- package/lib/cjs/index.js +1 -7
- package/lib/cjs/locale/en.js +1 -0
- package/lib/cjs/locale/zh.js +1 -0
- package/lib/cjs/store/types.d.ts +4 -5
- package/lib/cjs/types.d.ts +0 -8
- package/lib/cjs/utils/helper.d.ts +4 -0
- package/lib/cjs/utils/helper.js +102 -1
- package/lib/cjs/utils/transformSql.js +0 -2
- package/lib/cjs/utils.js +38 -18
- package/lib/es/components/dialog/expression/index.js +0 -1
- package/lib/es/components/dialog/formula-list/utils.js +0 -3
- package/lib/es/components/dialog/select-column/index.js +3 -3
- package/lib/es/components/dialog/select-column-multiple/index.d.ts +0 -1
- package/lib/es/components/dialog/select-column-multiple/index.js +45 -21
- package/lib/es/components/dialog/select-join-column/index.js +24 -8
- package/lib/es/components/dialog/select-join-column-multiple/index.js +16 -7
- package/lib/es/components/dialog/select-permission-table/index.js +3 -3
- package/lib/es/components/dialog/select-summarize/index.js +1 -3
- package/lib/es/components/dialog/select-table/index.d.ts +1 -2
- package/lib/es/components/dialog/select-table/index.js +233 -263
- package/lib/es/components/dialog/select-table/index.less +51 -36
- package/lib/es/components/metabase/index.js +34 -16
- package/lib/es/components/modules/components/item-name.js +0 -1
- package/lib/es/components/modules/custom-column.js +3 -7
- package/lib/es/components/modules/filter.js +3 -6
- package/lib/es/components/modules/join-data.js +42 -88
- package/lib/es/components/modules/permission-table.js +6 -10
- package/lib/es/components/modules/sort.js +1 -2
- package/lib/es/components/modules/summarize/group-by.js +1 -8
- package/lib/es/components/modules/summarize/select-index.js +1 -4
- package/lib/es/components/modules/table-data.js +29 -45
- package/lib/es/hooks/use-state.js +23 -148
- package/lib/es/index.js +1 -7
- package/lib/es/locale/en.js +1 -0
- package/lib/es/locale/zh.js +1 -0
- package/lib/es/store/types.d.ts +4 -5
- package/lib/es/types.d.ts +0 -8
- package/lib/es/utils/helper.d.ts +4 -0
- package/lib/es/utils/helper.js +101 -0
- package/lib/es/utils/transformSql.js +0 -2
- package/lib/es/utils.js +39 -19
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ import { __ } from '../../locale';
|
|
|
12
12
|
import { ChangeType } from '../../store/types';
|
|
13
13
|
import { Tooltip, Button, Modal, Modal2, Input, Toast } from '@gingkoo/pandora';
|
|
14
14
|
import Metabase from '../../index';
|
|
15
|
-
import { uuidv4, getAlias } from '../../utils/helper';
|
|
15
|
+
import { uuidv4, getAlias, isSameColumnByIdFirst, isSameTableByIdFirst } from '../../utils/helper';
|
|
16
16
|
import { getTopLayerZIndex } from '../../utils/helper-dom';
|
|
17
17
|
import { changeTableAlias, getSubColumns, isValidSQLAlias, isExistsError } from '../../utils';
|
|
18
18
|
import { RelatedWork } from '@gingkoo/pandora-icons';
|
|
@@ -27,7 +27,7 @@ import ItemWrapper from './components/item-wrapper';
|
|
|
27
27
|
import { ExclamationCircleFill } from '@gingkoo/pandora-icons';
|
|
28
28
|
import { useStore } from '../../hooks/use-provider';
|
|
29
29
|
var TableData = function TableData(props) {
|
|
30
|
-
var _meta$subquery, _meta$subquery2, _meta$subquery3, _meta$
|
|
30
|
+
var _meta$subquery, _meta$subquery2, _meta$subquery3, _meta$table4, _meta$table5, _meta$table7, _meta$table8, _store$showMainColumn;
|
|
31
31
|
var meta = props.meta,
|
|
32
32
|
groupIndex = props.groupIndex;
|
|
33
33
|
var store = useStore();
|
|
@@ -39,13 +39,13 @@ var TableData = function TableData(props) {
|
|
|
39
39
|
setIsDel = _useState2[1];
|
|
40
40
|
var tableIsDel = function () {
|
|
41
41
|
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
|
|
42
|
-
var _meta$table
|
|
43
|
-
var
|
|
42
|
+
var _meta$table;
|
|
43
|
+
var tableInfo, tables;
|
|
44
44
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
45
45
|
while (1) switch (_context.prev = _context.next) {
|
|
46
46
|
case 0:
|
|
47
|
-
|
|
48
|
-
if (meta !== null && meta !== void 0 && (_meta$
|
|
47
|
+
tableInfo = meta.table;
|
|
48
|
+
if (meta !== null && meta !== void 0 && (_meta$table = meta.table) !== null && _meta$table !== void 0 && _meta$table.datasourceId) {
|
|
49
49
|
_context.next = 1;
|
|
50
50
|
break;
|
|
51
51
|
}
|
|
@@ -53,13 +53,12 @@ var TableData = function TableData(props) {
|
|
|
53
53
|
return _context.abrupt("return");
|
|
54
54
|
case 1:
|
|
55
55
|
_context.next = 2;
|
|
56
|
-
return store === null || store === void 0 ? void 0 : store.fetchDataset(meta.table.datasourceId
|
|
56
|
+
return store === null || store === void 0 ? void 0 : store.fetchDataset(meta.table.datasourceId);
|
|
57
57
|
case 2:
|
|
58
58
|
tables = _context.sent;
|
|
59
|
-
|
|
60
|
-
return v
|
|
61
|
-
}))
|
|
62
|
-
if (!names.includes(tableName)) {
|
|
59
|
+
if (!(tables !== null && tables !== void 0 && tables.some(function (v) {
|
|
60
|
+
return isSameTableByIdFirst(tableInfo, v);
|
|
61
|
+
}))) {
|
|
63
62
|
setIsDel(true);
|
|
64
63
|
} else {
|
|
65
64
|
setIsDel(false);
|
|
@@ -88,25 +87,8 @@ var TableData = function TableData(props) {
|
|
|
88
87
|
data: store.sourceList,
|
|
89
88
|
sourceTable: store.sourceTable || [],
|
|
90
89
|
value: meta.table,
|
|
91
|
-
onDatasourceTypeChange: function onDatasourceTypeChange(data) {
|
|
92
|
-
var newMetas = store.metaList[groupIndex].list.slice();
|
|
93
|
-
var newMetaList = newMetas[0];
|
|
94
|
-
newMetaList.table = _objectSpread(_objectSpread(_objectSpread({}, newMetaList.table), data), {}, {
|
|
95
|
-
datasourceType: data.datasourceType
|
|
96
|
-
});
|
|
97
|
-
newMetaList.columns = newMetaList.columns.map(function (column) {
|
|
98
|
-
return _objectSpread(_objectSpread({}, column), {}, {
|
|
99
|
-
datasourceType: data.datasourceType
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
newMetas[0] = newMetaList;
|
|
103
|
-
store.setMeta(newMetas, groupIndex, {
|
|
104
|
-
obj: data,
|
|
105
|
-
type: ChangeType.datasource
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
90
|
onChange: function onChange(data) {
|
|
109
|
-
if (meta.table
|
|
91
|
+
if (!isSameTableByIdFirst(meta.table, data)) {
|
|
110
92
|
var _store$preProps;
|
|
111
93
|
var newMetaList = store.metaList[groupIndex].list.slice()[0];
|
|
112
94
|
newMetaList.table = _objectSpread(_objectSpread({}, data), {}, {
|
|
@@ -233,20 +215,23 @@ var TableData = function TableData(props) {
|
|
|
233
215
|
});
|
|
234
216
|
var items = getSubColumns(newList);
|
|
235
217
|
var newColumns = items.flatMap(function (item) {
|
|
236
|
-
return item.columns
|
|
218
|
+
return item.columns.map(function (column) {
|
|
219
|
+
return _objectSpread(_objectSpread({}, column), {}, {
|
|
220
|
+
tableId: column.tableId || column.id || item.id,
|
|
221
|
+
tableUuid: column.tableUuid || item.tableUuid,
|
|
222
|
+
datasourceId: column.datasourceId || item.datasourceId || ''
|
|
223
|
+
});
|
|
224
|
+
});
|
|
237
225
|
}).map(function (v) {
|
|
238
226
|
return _objectSpread(_objectSpread({}, v), {}, {
|
|
239
227
|
select: false
|
|
240
228
|
});
|
|
241
229
|
});
|
|
242
230
|
newMetaList.columns = newColumns.map(function (newCol) {
|
|
243
|
-
var _existingCol$select;
|
|
244
231
|
var existingCol = newMetaList.columns.find(function (oldCol) {
|
|
245
|
-
return
|
|
246
|
-
});
|
|
247
|
-
var _column = _objectSpread(_objectSpread({}, newCol), {}, {
|
|
248
|
-
select: (_existingCol$select = existingCol === null || existingCol === void 0 ? void 0 : existingCol.select) !== null && _existingCol$select !== void 0 ? _existingCol$select : newCol.select
|
|
232
|
+
return isSameColumnByIdFirst(oldCol, newCol);
|
|
249
233
|
});
|
|
234
|
+
var _column = existingCol ? existingCol : newCol;
|
|
250
235
|
_column.select = store.isSelectFields || _column.select;
|
|
251
236
|
return _column;
|
|
252
237
|
});
|
|
@@ -278,17 +263,16 @@ var TableData = function TableData(props) {
|
|
|
278
263
|
id: '',
|
|
279
264
|
alias: '',
|
|
280
265
|
datasourceName: '',
|
|
281
|
-
datasourceId: ''
|
|
282
|
-
datasourceType: ''
|
|
266
|
+
datasourceId: ''
|
|
283
267
|
};
|
|
284
268
|
store.setMeta(newMetaList, groupIndex);
|
|
285
269
|
};
|
|
286
270
|
var tableIsError = function tableIsError() {
|
|
287
|
-
var _store$preProps3, _meta$
|
|
271
|
+
var _store$preProps3, _meta$table2;
|
|
288
272
|
var aliass = ((_store$preProps3 = store.preProps) === null || _store$preProps3 === void 0 || (_store$preProps3 = _store$preProps3.notExistsColumns) === null || _store$preProps3 === void 0 ? void 0 : _store$preProps3.map(function (v) {
|
|
289
273
|
return v.alias;
|
|
290
274
|
})) || [];
|
|
291
|
-
var tableAlias = (_meta$
|
|
275
|
+
var tableAlias = (_meta$table2 = meta.table) === null || _meta$table2 === void 0 ? void 0 : _meta$table2.alias;
|
|
292
276
|
if (tableAlias && aliass.includes(tableAlias) || isDel) {
|
|
293
277
|
return true;
|
|
294
278
|
}
|
|
@@ -343,15 +327,15 @@ var TableData = function TableData(props) {
|
|
|
343
327
|
size: 'small',
|
|
344
328
|
onClick: function onClick(e) {
|
|
345
329
|
if (store.tableEnableAlias) {
|
|
346
|
-
var _meta$
|
|
330
|
+
var _meta$table3;
|
|
347
331
|
e.stopPropagation();
|
|
348
|
-
onChangeTableAlias(((_meta$
|
|
332
|
+
onChangeTableAlias(((_meta$table3 = meta.table) === null || _meta$table3 === void 0 ? void 0 : _meta$table3.alias) || '');
|
|
349
333
|
}
|
|
350
334
|
}
|
|
351
335
|
})
|
|
352
336
|
}) : null;
|
|
353
337
|
}()
|
|
354
|
-
}), subQuerySelected ? "".concat(((_meta$subquery2 = meta.subquery) === null || _meta$subquery2 === void 0 ? void 0 : _meta$subquery2[0]).table.datasourceName, ".").concat(((_meta$subquery3 = meta.subquery) === null || _meta$subquery3 === void 0 ? void 0 : _meta$subquery3[0]).table.name, " ").concat((_meta$
|
|
338
|
+
}), subQuerySelected ? "".concat(((_meta$subquery2 = meta.subquery) === null || _meta$subquery2 === void 0 ? void 0 : _meta$subquery2[0]).table.datasourceName, ".").concat(((_meta$subquery3 = meta.subquery) === null || _meta$subquery3 === void 0 ? void 0 : _meta$subquery3[0]).table.name, " ").concat((_meta$table4 = meta.table) !== null && _meta$table4 !== void 0 && _meta$table4.alias && store.tableEnableAlias ? "as ".concat((_meta$table5 = meta.table) === null || _meta$table5 === void 0 ? void 0 : _meta$table5.alias) : '', " ") : __('SqlQueryBuilder.setSubQuery')]
|
|
355
339
|
})
|
|
356
340
|
}) : _jsxs("div", {
|
|
357
341
|
className: cx("Sqb-TableName", {
|
|
@@ -382,15 +366,15 @@ var TableData = function TableData(props) {
|
|
|
382
366
|
size: 'small',
|
|
383
367
|
onClick: function onClick(e) {
|
|
384
368
|
if (store.tableEnableAlias) {
|
|
385
|
-
var _meta$
|
|
369
|
+
var _meta$table6;
|
|
386
370
|
e.stopPropagation();
|
|
387
|
-
onChangeTableAlias(((_meta$
|
|
371
|
+
onChangeTableAlias(((_meta$table6 = meta.table) === null || _meta$table6 === void 0 ? void 0 : _meta$table6.alias) || '');
|
|
388
372
|
}
|
|
389
373
|
}
|
|
390
374
|
})
|
|
391
375
|
}) : null;
|
|
392
376
|
}()
|
|
393
|
-
}), selected ? "".concat(meta.table.datasourceName, ".").concat(meta.table.name, " ").concat((_meta$
|
|
377
|
+
}), selected ? "".concat(meta.table.datasourceName, ".").concat(meta.table.name, " ").concat((_meta$table7 = meta.table) !== null && _meta$table7 !== void 0 && _meta$table7.alias && store.tableEnableAlias ? "as ".concat((_meta$table8 = meta.table) === null || _meta$table8 === void 0 ? void 0 : _meta$table8.alias) : '') : __('SqlQueryBuilder.pickTable')]
|
|
394
378
|
}), store.showSubquery && _jsx(Tooltip, {
|
|
395
379
|
title: __('SqlQueryBuilder.switchSubQuery'),
|
|
396
380
|
children: _jsx(Button, {
|
|
@@ -5,10 +5,10 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
|
|
|
5
5
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
6
6
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
7
7
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
8
|
-
var _excluded = ["alias", "datasourceName", "datasourceId", "
|
|
8
|
+
var _excluded = ["alias", "datasourceName", "datasourceId", "column"];
|
|
9
9
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
10
10
|
import { useEffect, useState, useRef, useMemo } from 'react';
|
|
11
|
-
import { uuidv4, getAlias } from '../utils/helper';
|
|
11
|
+
import { uuidv4, getAlias, isSameColumnByIdFirst } from '../utils/helper';
|
|
12
12
|
import { TypeEnum, JoinEnum, UnionEnum } from '../store/enum';
|
|
13
13
|
import { splitByUnion } from '../utils';
|
|
14
14
|
import storage from '../utils/storage';
|
|
@@ -28,7 +28,6 @@ var useStore = function useStore() {
|
|
|
28
28
|
alias: '',
|
|
29
29
|
datasourceId: '',
|
|
30
30
|
datasourceName: '',
|
|
31
|
-
datasourceType: '',
|
|
32
31
|
tableUuid: uuidv4('table')
|
|
33
32
|
},
|
|
34
33
|
columns: []
|
|
@@ -313,97 +312,10 @@ var useStore = function useStore() {
|
|
|
313
312
|
});
|
|
314
313
|
}, [metaList]);
|
|
315
314
|
useEffect(function () {
|
|
316
|
-
if (sourceList.length) {
|
|
317
|
-
var metaListWithDefaultType = fillDefaultDatasourceTypeInMetaList(metaList, isExit);
|
|
318
|
-
if (metaListWithDefaultType !== metaList) {
|
|
319
|
-
setPreData(metaListWithDefaultType, isSubquery, isExit);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
315
|
if (tableFlat) {
|
|
323
316
|
getSourceTable(sourceList);
|
|
324
317
|
}
|
|
325
318
|
}, [sourceList, isExit, tableFlat]);
|
|
326
|
-
var getDefaultDatasourceType = function getDefaultDatasourceType(datasource) {
|
|
327
|
-
var _datasource$datasourc;
|
|
328
|
-
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) || '';
|
|
329
|
-
};
|
|
330
|
-
var getActiveSourceList = function getActiveSourceList() {
|
|
331
|
-
var _props$exitSourceList, _props$sourceList;
|
|
332
|
-
var _isExit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : isExit;
|
|
333
|
-
var props = preProps.current || {};
|
|
334
|
-
if (_isExit && (_props$exitSourceList = props.exitSourceList) !== null && _props$exitSourceList !== void 0 && _props$exitSourceList.length) {
|
|
335
|
-
return props.exitSourceList;
|
|
336
|
-
}
|
|
337
|
-
if ((_props$sourceList = props.sourceList) !== null && _props$sourceList !== void 0 && _props$sourceList.length) {
|
|
338
|
-
return props.sourceList;
|
|
339
|
-
}
|
|
340
|
-
return sourceList;
|
|
341
|
-
};
|
|
342
|
-
var getDefaultDatasourceTypeById = function getDefaultDatasourceTypeById(datasourceId) {
|
|
343
|
-
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
344
|
-
if (!datasourceId) return '';
|
|
345
|
-
var datasource = getActiveSourceList(_isExit).find(function (item) {
|
|
346
|
-
return item.datasourceId === datasourceId;
|
|
347
|
-
});
|
|
348
|
-
return getDefaultDatasourceType(datasource);
|
|
349
|
-
};
|
|
350
|
-
var fillDefaultDatasourceTypeInTable = function fillDefaultDatasourceTypeInTable(table) {
|
|
351
|
-
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
352
|
-
if (!(table !== null && table !== void 0 && table.datasourceId) || table.datasourceType) return false;
|
|
353
|
-
var defaultDatasourceType = getDefaultDatasourceTypeById(table.datasourceId, _isExit);
|
|
354
|
-
if (!defaultDatasourceType) return false;
|
|
355
|
-
table.datasourceType = defaultDatasourceType;
|
|
356
|
-
return true;
|
|
357
|
-
};
|
|
358
|
-
var fillDefaultDatasourceTypeInColumns = function fillDefaultDatasourceTypeInColumns(columns, datasourceType) {
|
|
359
|
-
if (!datasourceType || !Array.isArray(columns)) return false;
|
|
360
|
-
var changed = false;
|
|
361
|
-
columns.forEach(function (column) {
|
|
362
|
-
if (!column.datasourceType) {
|
|
363
|
-
column.datasourceType = datasourceType;
|
|
364
|
-
changed = true;
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
return changed;
|
|
368
|
-
};
|
|
369
|
-
var _fillDefaultDatasourceTypeInList = function fillDefaultDatasourceTypeInList(list) {
|
|
370
|
-
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
371
|
-
if (!Array.isArray(list)) return false;
|
|
372
|
-
var changed = false;
|
|
373
|
-
list.forEach(function (item) {
|
|
374
|
-
if (item.table) {
|
|
375
|
-
changed = fillDefaultDatasourceTypeInTable(item.table, _isExit) || changed;
|
|
376
|
-
changed = fillDefaultDatasourceTypeInColumns(item.columns, item.table.datasourceType) || changed;
|
|
377
|
-
}
|
|
378
|
-
if (item.table1) {
|
|
379
|
-
changed = fillDefaultDatasourceTypeInTable(item.table1, _isExit) || changed;
|
|
380
|
-
}
|
|
381
|
-
if (item.table2) {
|
|
382
|
-
changed = fillDefaultDatasourceTypeInTable(item.table2, _isExit) || changed;
|
|
383
|
-
changed = fillDefaultDatasourceTypeInColumns(item.columns, item.table2.datasourceType) || changed;
|
|
384
|
-
}
|
|
385
|
-
if (Array.isArray(item.subquery)) {
|
|
386
|
-
changed = _fillDefaultDatasourceTypeInList(item.subquery, _isExit) || changed;
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
return changed;
|
|
390
|
-
};
|
|
391
|
-
var fillDefaultDatasourceTypeInMetaList = function fillDefaultDatasourceTypeInMetaList() {
|
|
392
|
-
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
393
|
-
var _isExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isExit;
|
|
394
|
-
if (!data.length) return data;
|
|
395
|
-
var nextData = cloneDeep(data);
|
|
396
|
-
var changed = false;
|
|
397
|
-
nextData.forEach(function (group) {
|
|
398
|
-
changed = _fillDefaultDatasourceTypeInList(group.list, _isExit) || changed;
|
|
399
|
-
changed = _fillDefaultDatasourceTypeInList(group.subquery, _isExit) || changed;
|
|
400
|
-
});
|
|
401
|
-
return changed ? nextData : data;
|
|
402
|
-
};
|
|
403
|
-
var getDatasetCacheKey = function getDatasetCacheKey(datasourceId) {
|
|
404
|
-
var datasourceType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
405
|
-
return datasourceType ? "".concat(datasourceId, "__").concat(datasourceType) : datasourceId;
|
|
406
|
-
};
|
|
407
319
|
var getSourceTable = function () {
|
|
408
320
|
var _ref3 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(source) {
|
|
409
321
|
var results;
|
|
@@ -413,17 +325,15 @@ var useStore = function useStore() {
|
|
|
413
325
|
_context4.next = 1;
|
|
414
326
|
return Promise.all(source.map(function () {
|
|
415
327
|
var _ref4 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(v) {
|
|
416
|
-
var
|
|
328
|
+
var tables;
|
|
417
329
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
418
330
|
while (1) switch (_context3.prev = _context3.next) {
|
|
419
331
|
case 0:
|
|
420
|
-
datasourceType = getDefaultDatasourceType(v);
|
|
421
332
|
_context3.next = 1;
|
|
422
|
-
return fetchDataset(v.datasourceId
|
|
333
|
+
return fetchDataset(v.datasourceId);
|
|
423
334
|
case 1:
|
|
424
335
|
tables = _context3.sent;
|
|
425
336
|
return _context3.abrupt("return", _objectSpread(_objectSpread({}, v), {}, {
|
|
426
|
-
datasourceType: datasourceType,
|
|
427
337
|
children: tables
|
|
428
338
|
}));
|
|
429
339
|
case 2:
|
|
@@ -454,34 +364,24 @@ var useStore = function useStore() {
|
|
|
454
364
|
};
|
|
455
365
|
var fetchDataset = function () {
|
|
456
366
|
var _ref5 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(datasourceId) {
|
|
457
|
-
var
|
|
458
|
-
var datasourceType,
|
|
459
|
-
force,
|
|
460
|
-
tables,
|
|
461
|
-
fetchTables,
|
|
462
|
-
_tables,
|
|
463
|
-
_args5 = arguments;
|
|
367
|
+
var tables, _tables;
|
|
464
368
|
return _regeneratorRuntime.wrap(function (_context5) {
|
|
465
369
|
while (1) switch (_context5.prev = _context5.next) {
|
|
466
370
|
case 0:
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
tables = getDataset(datasourceId, datasourceType);
|
|
470
|
-
if (!(!force && tables.length)) {
|
|
371
|
+
tables = getDataset(datasourceId);
|
|
372
|
+
if (!tables.length) {
|
|
471
373
|
_context5.next = 1;
|
|
472
374
|
break;
|
|
473
375
|
}
|
|
474
376
|
return _context5.abrupt("return", tables);
|
|
475
377
|
case 1:
|
|
476
|
-
fetchTables = ((_preProps$current = preProps.current) === null || _preProps$current === void 0 ? void 0 : _preProps$current.getTables) || fetchDatasetFn.current;
|
|
477
378
|
_context5.next = 2;
|
|
478
|
-
return
|
|
479
|
-
isExit: isExit
|
|
480
|
-
datasourceType: datasourceType
|
|
379
|
+
return fetchDatasetFn.current(datasourceId, {
|
|
380
|
+
isExit: isExit
|
|
481
381
|
});
|
|
482
382
|
case 2:
|
|
483
383
|
_tables = _context5.sent;
|
|
484
|
-
setDataset(datasourceId, _tables
|
|
384
|
+
setDataset(datasourceId, _tables);
|
|
485
385
|
return _context5.abrupt("return", _tables);
|
|
486
386
|
case 3:
|
|
487
387
|
case "end":
|
|
@@ -507,11 +407,9 @@ var useStore = function useStore() {
|
|
|
507
407
|
alias,
|
|
508
408
|
datasourceName,
|
|
509
409
|
did,
|
|
510
|
-
datasourceType,
|
|
511
410
|
column,
|
|
512
411
|
extra,
|
|
513
412
|
tableName,
|
|
514
|
-
tableCacheKey,
|
|
515
413
|
columns,
|
|
516
414
|
_columns,
|
|
517
415
|
_args6 = arguments;
|
|
@@ -536,33 +434,29 @@ var useStore = function useStore() {
|
|
|
536
434
|
selectId = [];
|
|
537
435
|
isSelect = false;
|
|
538
436
|
}
|
|
539
|
-
_table$alias = table.alias, alias = _table$alias === void 0 ? '' : _table$alias, datasourceName = table.datasourceName, did = table.datasourceId,
|
|
437
|
+
_table$alias = table.alias, alias = _table$alias === void 0 ? '' : _table$alias, datasourceName = table.datasourceName, did = table.datasourceId, column = table.column, extra = _objectWithoutProperties(table, _excluded);
|
|
540
438
|
tableName = table.name;
|
|
541
|
-
|
|
542
|
-
columns = getColumns(tableCacheKey);
|
|
439
|
+
columns = getColumns(tableName);
|
|
543
440
|
if (columns.length) {
|
|
544
441
|
_context6.next = 2;
|
|
545
442
|
break;
|
|
546
443
|
}
|
|
547
444
|
_context6.next = 1;
|
|
548
445
|
return fetchColumnsFn.current(extra, datasourceId, {
|
|
549
|
-
isExit: _isExit
|
|
550
|
-
datasourceType: datasourceType
|
|
446
|
+
isExit: _isExit
|
|
551
447
|
});
|
|
552
448
|
case 1:
|
|
553
449
|
columns = _context6.sent;
|
|
554
|
-
setColumns(
|
|
450
|
+
setColumns(tableName, columns);
|
|
555
451
|
case 2:
|
|
556
452
|
_columns = (_columns2 = columns) === null || _columns2 === void 0 ? void 0 : _columns2.map(function (v) {
|
|
557
|
-
var
|
|
558
|
-
|
|
559
|
-
|
|
453
|
+
var obj = oldColumns.find(function (oldColumn) {
|
|
454
|
+
return isSameColumnByIdFirst(oldColumn, v);
|
|
455
|
+
});
|
|
456
|
+
var select = selectId.includes(v.id) || Boolean(obj === null || obj === void 0 ? void 0 : obj.select);
|
|
560
457
|
return _objectSpread(_objectSpread(_objectSpread({}, obj), v), {}, {
|
|
561
|
-
datasourceId: obj.datasourceId || v.datasourceId || did || datasourceId || '',
|
|
562
|
-
datasourceName: obj.datasourceName || v.datasourceName || datasourceName || '',
|
|
563
|
-
datasourceType: obj.datasourceType || v.datasourceType || datasourceType || '',
|
|
564
458
|
select: isSelect || select,
|
|
565
|
-
fieldUuid: obj.fieldUuid || v.fieldUuid || uuidv4('field')
|
|
459
|
+
fieldUuid: (obj === null || obj === void 0 ? void 0 : obj.fieldUuid) || v.fieldUuid || uuidv4('field')
|
|
566
460
|
});
|
|
567
461
|
});
|
|
568
462
|
typeof callback === 'function' && callback(_columns);
|
|
@@ -628,16 +522,7 @@ var useStore = function useStore() {
|
|
|
628
522
|
var _v$table, _v$table2;
|
|
629
523
|
var newMeta = item.list;
|
|
630
524
|
if (v.table) {
|
|
631
|
-
fillDefaultDatasourceTypeInTable(v.table, _isExit);
|
|
632
525
|
v.table.tableUuid = v.table.tableUuid || uuidv4('table');
|
|
633
|
-
fillDefaultDatasourceTypeInColumns(v.columns, v.table.datasourceType);
|
|
634
|
-
}
|
|
635
|
-
if (v.table1) {
|
|
636
|
-
fillDefaultDatasourceTypeInTable(v.table1, _isExit);
|
|
637
|
-
}
|
|
638
|
-
if (v.table2) {
|
|
639
|
-
fillDefaultDatasourceTypeInTable(v.table2, _isExit);
|
|
640
|
-
fillDefaultDatasourceTypeInColumns(v.columns, v.table2.datasourceType);
|
|
641
526
|
}
|
|
642
527
|
if ((_v$table = v.table2) !== null && _v$table !== void 0 && _v$table.datasourceId) {
|
|
643
528
|
fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, v.columns, function () {
|
|
@@ -645,8 +530,6 @@ var useStore = function useStore() {
|
|
|
645
530
|
if (v.isSubquery) {} else {
|
|
646
531
|
newMeta[i].columns = columns || [];
|
|
647
532
|
}
|
|
648
|
-
fillDefaultDatasourceTypeInTable(newMeta[i].table2, _isExit);
|
|
649
|
-
fillDefaultDatasourceTypeInColumns(newMeta[i].columns, newMeta[i].table2.datasourceType);
|
|
650
533
|
setMeta(newMeta, groupIndex, 'init', data);
|
|
651
534
|
}, false, _isSubquery, _isExit);
|
|
652
535
|
return _objectSpread({}, v);
|
|
@@ -657,8 +540,6 @@ var useStore = function useStore() {
|
|
|
657
540
|
if (v.isSubquery) {} else {
|
|
658
541
|
newMeta[i].columns = columns || [];
|
|
659
542
|
}
|
|
660
|
-
fillDefaultDatasourceTypeInTable(newMeta[i].table, _isExit);
|
|
661
|
-
fillDefaultDatasourceTypeInColumns(newMeta[i].columns, newMeta[i].table.datasourceType);
|
|
662
543
|
setMeta(newMeta, groupIndex, 'init', data);
|
|
663
544
|
}, false, _isSubquery, _isExit);
|
|
664
545
|
return _objectSpread({}, v);
|
|
@@ -777,7 +658,6 @@ var useStore = function useStore() {
|
|
|
777
658
|
tableUuid: '',
|
|
778
659
|
datasourceId: '',
|
|
779
660
|
datasourceName: '',
|
|
780
|
-
datasourceType: '',
|
|
781
661
|
fieldAlias: '',
|
|
782
662
|
fieldUuid: '',
|
|
783
663
|
fields: []
|
|
@@ -789,7 +669,6 @@ var useStore = function useStore() {
|
|
|
789
669
|
name_zh: mainTable.table.name_zh,
|
|
790
670
|
datasourceId: mainTable.table.datasourceId,
|
|
791
671
|
datasourceName: mainTable.table.datasourceName,
|
|
792
|
-
datasourceType: mainTable.table.datasourceType || '',
|
|
793
672
|
fieldAlias: '',
|
|
794
673
|
fieldUuid: '',
|
|
795
674
|
fields: []
|
|
@@ -807,8 +686,7 @@ var useStore = function useStore() {
|
|
|
807
686
|
alias: '',
|
|
808
687
|
tableUuid: '',
|
|
809
688
|
datasourceId: '',
|
|
810
|
-
datasourceName: ''
|
|
811
|
-
datasourceType: ''
|
|
689
|
+
datasourceName: ''
|
|
812
690
|
},
|
|
813
691
|
columns: [],
|
|
814
692
|
expressions: []
|
|
@@ -863,8 +741,7 @@ var useStore = function useStore() {
|
|
|
863
741
|
alias: '',
|
|
864
742
|
tableUuid: '',
|
|
865
743
|
datasourceId: '',
|
|
866
|
-
datasourceName: ''
|
|
867
|
-
datasourceType: ''
|
|
744
|
+
datasourceName: ''
|
|
868
745
|
}
|
|
869
746
|
};
|
|
870
747
|
}
|
|
@@ -1019,14 +896,12 @@ var useStore = function useStore() {
|
|
|
1019
896
|
return _cacheColumnsMap[tableId] || [];
|
|
1020
897
|
};
|
|
1021
898
|
var setDataset = function setDataset(datasourceId, tables) {
|
|
1022
|
-
var datasourceType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
1023
899
|
var map = _objectSpread({}, _cacheSource2TableMap);
|
|
1024
|
-
map[
|
|
900
|
+
map[datasourceId] = tables;
|
|
1025
901
|
set_cacheSource2TableMap(map);
|
|
1026
902
|
};
|
|
1027
903
|
var getDataset = function getDataset(datasourceId) {
|
|
1028
|
-
|
|
1029
|
-
return _cacheSource2TableMap[getDatasetCacheKey(datasourceId, datasourceType)] || [];
|
|
904
|
+
return _cacheSource2TableMap[datasourceId] || [];
|
|
1030
905
|
};
|
|
1031
906
|
var reset = function reset() {
|
|
1032
907
|
_setMeta(defaultMeta);
|
package/lib/es/index.js
CHANGED
|
@@ -73,16 +73,10 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
|
|
|
73
73
|
var store = useData();
|
|
74
74
|
useEffect(function () {
|
|
75
75
|
getTables && store.setFetchDatasetFn(getTables);
|
|
76
|
-
}, [getTables]);
|
|
77
|
-
useEffect(function () {
|
|
78
76
|
getColumns && store.setFetchColumnsFn(getColumns);
|
|
79
|
-
}, [getColumns]);
|
|
80
|
-
useEffect(function () {
|
|
81
77
|
onChange && store.setFetchChangeFn(onChange);
|
|
82
|
-
}, [onChange]);
|
|
83
|
-
useEffect(function () {
|
|
84
78
|
getModuleDiffCode && store.setFetchDiffFn(getModuleDiffCode);
|
|
85
|
-
}, [
|
|
79
|
+
}, []);
|
|
86
80
|
useEffect(function () {
|
|
87
81
|
store.setProps(props);
|
|
88
82
|
}, [props]);
|
package/lib/es/locale/en.js
CHANGED
|
@@ -169,6 +169,7 @@ export default register('en', {
|
|
|
169
169
|
'metabase.validationFailed': 'Validation failed. Do you still want to save?',
|
|
170
170
|
'metabase.validationFilter': 'The filter configuration is incorrect. Saving is prohibited!',
|
|
171
171
|
'metabase.validationFormula': 'The formula configuration is incorrect. Saving is prohibited!',
|
|
172
|
+
'metabase.validationFormulaSave': 'The formula configuration is incorrect. Do you still want to save?',
|
|
172
173
|
'metabase.prompt': 'Prompt',
|
|
173
174
|
'metabase.copy': 'Copy',
|
|
174
175
|
'metabase.copySuccess': 'Copy success',
|
package/lib/es/locale/zh.js
CHANGED
|
@@ -169,6 +169,7 @@ export default register('zh', {
|
|
|
169
169
|
'metabase.validationFailed': '校验未通过,是否依然保存?',
|
|
170
170
|
'metabase.validationFilter': '过滤器配置有误,禁止保存!',
|
|
171
171
|
'metabase.validationFormula': '公式配置有误,禁止保存!',
|
|
172
|
+
'metabase.validationFormulaSave': '公式配置有误,是否依然保存?',
|
|
172
173
|
'metabase.prompt': '提示',
|
|
173
174
|
'metabase.copy': '复制',
|
|
174
175
|
'metabase.copySuccess': '复制成功',
|
package/lib/es/store/types.d.ts
CHANGED
|
@@ -123,7 +123,6 @@ export interface AtomsField {
|
|
|
123
123
|
tableUuid: string;
|
|
124
124
|
datasourceName: string;
|
|
125
125
|
datasourceId: string;
|
|
126
|
-
datasourceType?: string;
|
|
127
126
|
type: AtomsTypeEnum.FIELD;
|
|
128
127
|
}
|
|
129
128
|
export interface AtomsInputString {
|
|
@@ -189,20 +188,23 @@ export interface TableType {
|
|
|
189
188
|
id: string;
|
|
190
189
|
alias: string;
|
|
191
190
|
tableUuid: string;
|
|
191
|
+
table_type?: string;
|
|
192
192
|
}
|
|
193
193
|
export type MetaData_TableType = TableType & DatasourceType;
|
|
194
194
|
export interface MetaData_ColumnsType {
|
|
195
195
|
name: string;
|
|
196
196
|
id: string;
|
|
197
|
+
fieldId?: string;
|
|
197
198
|
name_zh?: string;
|
|
198
199
|
fieldAlias: string;
|
|
199
200
|
fieldUuid: string;
|
|
201
|
+
tableId?: string;
|
|
202
|
+
tableUuid?: string;
|
|
200
203
|
realName?: string;
|
|
201
204
|
database_type: SQL_COLUMN_TYPE | '';
|
|
202
205
|
special_type: SpecialType | '';
|
|
203
206
|
datasourceId: string;
|
|
204
207
|
datasourceName: string;
|
|
205
|
-
datasourceType?: string;
|
|
206
208
|
select: boolean;
|
|
207
209
|
summarizeType?: MetaSummarize_Enum;
|
|
208
210
|
}
|
|
@@ -231,7 +233,6 @@ export interface MetaJoin_TalbeType {
|
|
|
231
233
|
alias: string;
|
|
232
234
|
datasourceName: string;
|
|
233
235
|
datasourceId: string;
|
|
234
|
-
datasourceType?: string;
|
|
235
236
|
quotes?: string;
|
|
236
237
|
columns?: MetaData_ColumnsType[];
|
|
237
238
|
}
|
|
@@ -291,7 +292,6 @@ export interface MetaSummarize_Group {
|
|
|
291
292
|
quotes: string;
|
|
292
293
|
datasourceId: string;
|
|
293
294
|
datasourceName: string;
|
|
294
|
-
datasourceType?: string;
|
|
295
295
|
atoms?: AtomsItem[];
|
|
296
296
|
summarizeType: MetaSummarize_Enum;
|
|
297
297
|
[params: string]: any;
|
|
@@ -309,7 +309,6 @@ export interface MetaSummarize_By {
|
|
|
309
309
|
id: string;
|
|
310
310
|
datasourceId: string;
|
|
311
311
|
datasourceName: string;
|
|
312
|
-
datasourceType?: string;
|
|
313
312
|
realName?: string;
|
|
314
313
|
sql: string;
|
|
315
314
|
database_type: SQL_COLUMN_TYPE | '';
|
package/lib/es/types.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export interface MetaListProps {
|
|
|
10
10
|
}
|
|
11
11
|
export interface FetchOptions {
|
|
12
12
|
isExit: boolean;
|
|
13
|
-
datasourceType?: string;
|
|
14
13
|
}
|
|
15
14
|
export interface MetabaseProps {
|
|
16
15
|
loading?: boolean;
|
|
@@ -71,16 +70,9 @@ export interface OptionItem {
|
|
|
71
70
|
label: string;
|
|
72
71
|
icon?: React.ReactNode;
|
|
73
72
|
}
|
|
74
|
-
export interface DatasourceTypeOption {
|
|
75
|
-
value: string;
|
|
76
|
-
label: string;
|
|
77
|
-
}
|
|
78
73
|
export interface DatasourceType {
|
|
79
74
|
datasourceId: string;
|
|
80
75
|
datasourceName: string;
|
|
81
|
-
defaultDatasourceType?: string;
|
|
82
|
-
datasourceType?: string;
|
|
83
|
-
datasourceTypeList?: DatasourceTypeOption[];
|
|
84
76
|
}
|
|
85
77
|
export interface SqlVisionBuilderRef {
|
|
86
78
|
reset: () => void;
|
package/lib/es/utils/helper.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { MetaListType } from '../store/types';
|
|
2
|
+
export declare const getTableIdFirstKey: (table?: any) => string;
|
|
3
|
+
export declare const isSameTableByIdFirst: (left?: any, right?: any) => boolean;
|
|
4
|
+
export declare const getColumnIdFirstKey: (column?: any) => string;
|
|
5
|
+
export declare const isSameColumnByIdFirst: (left?: any, right?: any) => boolean;
|
|
2
6
|
export declare const throttle: (fn: Function, wait?: number) => Function;
|
|
3
7
|
export declare const debounce: (fn: Function, wait?: number) => () => void;
|
|
4
8
|
export type ScreenType = {
|