@gingkoo/pandora-metabase 1.0.156 → 1.0.157-alpha.2
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/formula-list/index.js +16 -8
- package/lib/cjs/components/dialog/select-summarize/index.d.ts +4 -0
- package/lib/cjs/components/dialog/select-summarize/index.js +136 -15
- package/lib/cjs/components/dialog/select-summarize/index.less +34 -1
- package/lib/cjs/components/metabase/index.js +8 -0
- package/lib/cjs/components/metabase/index.less +5 -0
- package/lib/cjs/components/modules/components/item-name.js +16 -2
- package/lib/cjs/components/modules/summarize/group-by.js +12 -1
- package/lib/cjs/components/modules/summarize/select-index.js +12 -1
- package/lib/cjs/hooks/use-state.js +1 -13
- package/lib/cjs/locale/en.js +3 -0
- package/lib/cjs/locale/zh.js +3 -0
- package/lib/cjs/store/helper.js +25 -2
- package/lib/cjs/store/types.d.ts +4 -0
- package/lib/cjs/utils/helper.js +20 -0
- package/lib/cjs/utils.js +23 -2
- package/lib/es/components/dialog/formula-list/index.js +16 -8
- package/lib/es/components/dialog/select-summarize/index.d.ts +4 -0
- package/lib/es/components/dialog/select-summarize/index.js +140 -19
- package/lib/es/components/dialog/select-summarize/index.less +34 -1
- package/lib/es/components/metabase/index.js +8 -0
- package/lib/es/components/metabase/index.less +5 -0
- package/lib/es/components/modules/components/item-name.js +16 -2
- package/lib/es/components/modules/summarize/group-by.js +12 -1
- package/lib/es/components/modules/summarize/select-index.js +12 -1
- package/lib/es/hooks/use-state.js +1 -13
- package/lib/es/locale/en.js +3 -0
- package/lib/es/locale/zh.js +3 -0
- package/lib/es/store/helper.js +25 -2
- package/lib/es/store/types.d.ts +4 -0
- package/lib/es/utils/helper.js +20 -0
- package/lib/es/utils.js +23 -2
- package/package.json +1 -1
package/lib/cjs/utils.js
CHANGED
|
@@ -1244,15 +1244,27 @@ var changeTableAlias = exports.changeTableAlias = function changeTableAlias(list
|
|
|
1244
1244
|
}
|
|
1245
1245
|
if (v.type === _enum.TypeEnum.summarize) {
|
|
1246
1246
|
v.group.map(function (group) {
|
|
1247
|
+
var _group$orderBy;
|
|
1247
1248
|
var groupAtoms = group.atoms;
|
|
1249
|
+
var shouldRefreshSql = false;
|
|
1248
1250
|
if (groupAtoms && groupAtoms.length > 0) {
|
|
1249
1251
|
group.atoms = _changeAlias(groupAtoms, {
|
|
1250
1252
|
uuid: tableUuid,
|
|
1251
1253
|
alias: alias
|
|
1252
1254
|
}, AliasType.table);
|
|
1253
|
-
|
|
1255
|
+
shouldRefreshSql = true;
|
|
1254
1256
|
} else if (group.tableUuid === tableUuid) {
|
|
1255
1257
|
group.alias = alias;
|
|
1258
|
+
shouldRefreshSql = true;
|
|
1259
|
+
}
|
|
1260
|
+
if ((_group$orderBy = group.orderBy) !== null && _group$orderBy !== void 0 && _group$orderBy.length) {
|
|
1261
|
+
group.orderBy = _changeAlias(group.orderBy, {
|
|
1262
|
+
uuid: tableUuid,
|
|
1263
|
+
alias: alias
|
|
1264
|
+
}, AliasType.table);
|
|
1265
|
+
shouldRefreshSql = true;
|
|
1266
|
+
}
|
|
1267
|
+
if (shouldRefreshSql) {
|
|
1256
1268
|
group.sql = (0, _helper.summarizeToSql)(v.group, group).sql;
|
|
1257
1269
|
}
|
|
1258
1270
|
});
|
|
@@ -1330,12 +1342,21 @@ var changeFieldAlias = exports.changeFieldAlias = function changeFieldAlias(list
|
|
|
1330
1342
|
if (v.type === _enum.TypeEnum.rowLimit) {}
|
|
1331
1343
|
if (v.type === _enum.TypeEnum.summarize) {
|
|
1332
1344
|
v.group.map(function (group) {
|
|
1345
|
+
var _group$orderBy2;
|
|
1333
1346
|
var groupAtoms = group.atoms;
|
|
1347
|
+
var shouldRefreshSql = false;
|
|
1334
1348
|
if (groupAtoms && groupAtoms.length > 0) {
|
|
1335
1349
|
group.atoms = _changeAlias(groupAtoms, aliasTarget, AliasType.field);
|
|
1336
|
-
|
|
1350
|
+
shouldRefreshSql = true;
|
|
1337
1351
|
} else if (isAliasTargetSummarizeRecord(group, aliasTarget)) {
|
|
1338
1352
|
group.fieldAlias = alias;
|
|
1353
|
+
shouldRefreshSql = true;
|
|
1354
|
+
}
|
|
1355
|
+
if ((_group$orderBy2 = group.orderBy) !== null && _group$orderBy2 !== void 0 && _group$orderBy2.length) {
|
|
1356
|
+
group.orderBy = _changeAlias(group.orderBy, aliasTarget, AliasType.field);
|
|
1357
|
+
shouldRefreshSql = true;
|
|
1358
|
+
}
|
|
1359
|
+
if (shouldRefreshSql) {
|
|
1339
1360
|
group.sql = (0, _helper.summarizeToSql)(v.group, group).sql;
|
|
1340
1361
|
}
|
|
1341
1362
|
});
|
|
@@ -39,6 +39,7 @@ import { getTopLayerZIndex } from '../../../utils/helper-dom';
|
|
|
39
39
|
import CaseWhenGroup from './CaseWhenGroup';
|
|
40
40
|
import LogicGroup from './LogicGroup';
|
|
41
41
|
import { SummarizeAlias } from '../../../store/helper';
|
|
42
|
+
var parentPopupLockCounts = new WeakMap();
|
|
42
43
|
var CASE_FIXED_OPERATORS = ['case', 'when', 'then', 'else', 'end'];
|
|
43
44
|
var LOGIC_FIXED_OPERATORS = ['(', ')'];
|
|
44
45
|
var LOGIC_REQUIRED_OPERATORS = ['(', ')'];
|
|
@@ -190,6 +191,16 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
190
191
|
}
|
|
191
192
|
store.setClosable(closable);
|
|
192
193
|
};
|
|
194
|
+
var changeSharedParentLockCount = function changeSharedParentLockCount(delta) {
|
|
195
|
+
if (!parentPopupChannel) return;
|
|
196
|
+
var counts = parentPopupLockCounts.get(store) || {
|
|
197
|
+
primary: 0,
|
|
198
|
+
secondary: 0
|
|
199
|
+
};
|
|
200
|
+
counts[parentPopupChannel] = Math.max(0, counts[parentPopupChannel] + delta);
|
|
201
|
+
parentPopupLockCounts.set(store, counts);
|
|
202
|
+
setParentClosable(counts[parentPopupChannel] === 0);
|
|
203
|
+
};
|
|
193
204
|
var lockParentPopup = function lockParentPopup() {
|
|
194
205
|
if (!parentPopupChannel) return;
|
|
195
206
|
if (parentPopupUnlockTimerRef.current) {
|
|
@@ -197,19 +208,16 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
197
208
|
parentPopupUnlockTimerRef.current = null;
|
|
198
209
|
}
|
|
199
210
|
parentPopupLockCountRef.current += 1;
|
|
200
|
-
|
|
201
|
-
setParentClosable(false);
|
|
202
|
-
}
|
|
211
|
+
changeSharedParentLockCount(1);
|
|
203
212
|
};
|
|
204
213
|
var unlockParentPopup = function unlockParentPopup() {
|
|
205
214
|
var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
206
215
|
if (!parentPopupChannel) return;
|
|
207
216
|
var runUnlock = function runUnlock() {
|
|
208
217
|
parentPopupUnlockTimerRef.current = null;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
218
|
+
if (parentPopupLockCountRef.current === 0) return;
|
|
219
|
+
parentPopupLockCountRef.current -= 1;
|
|
220
|
+
changeSharedParentLockCount(-1);
|
|
213
221
|
};
|
|
214
222
|
if (delay > 0) {
|
|
215
223
|
if (parentPopupUnlockTimerRef.current) {
|
|
@@ -259,8 +267,8 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
259
267
|
parentPopupUnlockTimerRef.current = null;
|
|
260
268
|
}
|
|
261
269
|
if (parentPopupLockCountRef.current > 0) {
|
|
270
|
+
changeSharedParentLockCount(-parentPopupLockCountRef.current);
|
|
262
271
|
parentPopupLockCountRef.current = 0;
|
|
263
|
-
setParentClosable(true);
|
|
264
272
|
}
|
|
265
273
|
};
|
|
266
274
|
}, [parentPopupChannel]);
|
|
@@ -10,6 +10,10 @@ export type ValueType = Partial<ColumnType> & {
|
|
|
10
10
|
condition: string;
|
|
11
11
|
quotes: string;
|
|
12
12
|
atoms?: AtomsItem[];
|
|
13
|
+
delimiter?: string;
|
|
14
|
+
distinct?: boolean;
|
|
15
|
+
orderBy?: AtomsItem[];
|
|
16
|
+
orderDirection?: 'ASC' | 'DESC';
|
|
13
17
|
};
|
|
14
18
|
interface PropsType {
|
|
15
19
|
data: DataType[];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
4
|
import './index.less';
|
|
5
|
-
import { useState } from 'react';
|
|
6
|
-
import { Tooltip, Button } from '@gingkoo/pandora';
|
|
5
|
+
import { useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { Tooltip, Button, Checkbox, Input, Select } from '@gingkoo/pandora';
|
|
7
7
|
import cx from 'classnames';
|
|
8
8
|
import { ColumnsPopupThemeEnum } from '../../../store/enum';
|
|
9
|
-
import { NUMBER_GROUP, DATE_GROUP } from '../const';
|
|
9
|
+
import { NUMBER_GROUP, STRING_GROUP, DATE_GROUP } from '../const';
|
|
10
10
|
import { __ } from '../../../locale';
|
|
11
11
|
import { TableIcon, LeftArrowIcon } from '../../icons';
|
|
12
12
|
import FormulaList from '../formula-list';
|
|
@@ -40,8 +40,11 @@ var metricOptions = [{
|
|
|
40
40
|
}, {
|
|
41
41
|
name: '最大值',
|
|
42
42
|
tip: '一个字段的最大值'
|
|
43
|
+
}, {
|
|
44
|
+
name: '聚合字符串拼接',
|
|
45
|
+
tip: '按分组跨行拼接字符串,支持自定义分隔符。'
|
|
43
46
|
}];
|
|
44
|
-
var QuotesMap = new Map([['总行数', '计数'], ['总和', '求和 的'], ['平均值', '平均 的'], ['不重复值的总数', '不重复的值 的'], ['累积求和', '累积和 的'], ['累积行数', '累积计数'], ['标准差', '标准偏差 的'], ['最小值', '最小 的'], ['最大值', '最大 的']]);
|
|
47
|
+
var QuotesMap = new Map([['总行数', '计数'], ['总和', '求和 的'], ['平均值', '平均 的'], ['不重复值的总数', '不重复的值 的'], ['累积求和', '累积和 的'], ['累积行数', '累积计数'], ['标准差', '标准偏差 的'], ['最小值', '最小 的'], ['最大值', '最大 的'], ['聚合字符串拼接', 'STRING_AGG']]);
|
|
45
48
|
var localeMap = {
|
|
46
49
|
总行数: 'summarize.totalNumberOfRows',
|
|
47
50
|
计数: 'summarize.count',
|
|
@@ -61,6 +64,8 @@ var localeMap = {
|
|
|
61
64
|
'最小 的': 'summarize.theSmallestYes',
|
|
62
65
|
最大值: 'summarize.maximumCalue',
|
|
63
66
|
'最大 的': 'summarize.biggestYes',
|
|
67
|
+
聚合字符串拼接: 'summarize.stringAgg',
|
|
68
|
+
STRING_AGG: 'summarize.stringAggExpression',
|
|
64
69
|
总的数据行数: 'summarize.totalNumberOfRowsOfData',
|
|
65
70
|
一个字段所有数值的总和: 'summarize.theSumOfAllValuesInAField',
|
|
66
71
|
一个字段所有数值的平均值: 'summarize.theAverageOfAllValuesInAfield',
|
|
@@ -69,21 +74,51 @@ var localeMap = {
|
|
|
69
74
|
'行数的加法统计。如;x段时间内的销售总额': 'summarize.additiveStatisticsOfTheNumberOfRows',
|
|
70
75
|
一个字段所有数值的标准差: 'summarize.theStandardDeviationOfAllValuesInAfield',
|
|
71
76
|
一个字段的最小值: 'summarize.theMinimumValueOfAfield',
|
|
72
|
-
一个字段的最大值: 'summarize.TheMaximumValueOfAfield'
|
|
77
|
+
一个字段的最大值: 'summarize.TheMaximumValueOfAfield',
|
|
78
|
+
'按分组跨行拼接字符串,支持自定义分隔符。': 'summarize.stringAggDescription'
|
|
73
79
|
};
|
|
74
80
|
var Special = ['总行数', '累积行数'];
|
|
75
81
|
var SelectSummarize = function SelectSummarize(_ref) {
|
|
82
|
+
var _value$delimiter, _value$distinct;
|
|
76
83
|
var data = _ref.data,
|
|
77
84
|
value = _ref.value,
|
|
78
85
|
onChange = _ref.onChange,
|
|
79
86
|
didUpdate = _ref.didUpdate,
|
|
80
87
|
ignoreGroupByType = _ref.ignoreGroupByType,
|
|
81
88
|
readonly = _ref.readonly;
|
|
89
|
+
var formulaRootRef = useRef(null);
|
|
82
90
|
var _useState = useState(value.condition),
|
|
83
91
|
_useState2 = _slicedToArray(_useState, 2),
|
|
84
92
|
condition = _useState2[0],
|
|
85
93
|
setCondition = _useState2[1];
|
|
86
|
-
var _useState3 = useState(
|
|
94
|
+
var _useState3 = useState((_value$delimiter = value.delimiter) !== null && _value$delimiter !== void 0 ? _value$delimiter : ','),
|
|
95
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
96
|
+
delimiter = _useState4[0],
|
|
97
|
+
setDelimiter = _useState4[1];
|
|
98
|
+
var _useState5 = useState((_value$distinct = value.distinct) !== null && _value$distinct !== void 0 ? _value$distinct : false),
|
|
99
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
100
|
+
distinct = _useState6[0],
|
|
101
|
+
setDistinct = _useState6[1];
|
|
102
|
+
var _useState7 = useState(value.orderBy || []),
|
|
103
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
104
|
+
orderBy = _useState8[0],
|
|
105
|
+
setOrderBy = _useState8[1];
|
|
106
|
+
var _useState9 = useState(value.orderDirection || 'ASC'),
|
|
107
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
108
|
+
orderDirection = _useState0[0],
|
|
109
|
+
setOrderDirection = _useState0[1];
|
|
110
|
+
useEffect(function () {
|
|
111
|
+
var _formulaRootRef$curre;
|
|
112
|
+
if (condition !== '聚合字符串拼接') return;
|
|
113
|
+
var popup = (_formulaRootRef$curre = formulaRootRef.current) === null || _formulaRootRef$curre === void 0 ? void 0 : _formulaRootRef$curre.parentElement;
|
|
114
|
+
if (!popup) return;
|
|
115
|
+
var previousOverflowY = popup.style.overflowY;
|
|
116
|
+
popup.style.overflowY = 'hidden';
|
|
117
|
+
return function () {
|
|
118
|
+
popup.style.overflowY = previousOverflowY;
|
|
119
|
+
};
|
|
120
|
+
}, [condition]);
|
|
121
|
+
var _useState1 = useState(function () {
|
|
87
122
|
if (Special.includes(value.condition)) {
|
|
88
123
|
return [];
|
|
89
124
|
}
|
|
@@ -110,9 +145,9 @@ var SelectSummarize = function SelectSummarize(_ref) {
|
|
|
110
145
|
}
|
|
111
146
|
return [];
|
|
112
147
|
}),
|
|
113
|
-
|
|
114
|
-
atoms =
|
|
115
|
-
setAtoms =
|
|
148
|
+
_useState10 = _slicedToArray(_useState1, 2),
|
|
149
|
+
atoms = _useState10[0],
|
|
150
|
+
setAtoms = _useState10[1];
|
|
116
151
|
function goPrevPage() {
|
|
117
152
|
if (readonly) return;
|
|
118
153
|
setCondition('');
|
|
@@ -190,7 +225,7 @@ var SelectSummarize = function SelectSummarize(_ref) {
|
|
|
190
225
|
availableData = data.map(function (v) {
|
|
191
226
|
return _objectSpread(_objectSpread({}, v), {}, {
|
|
192
227
|
columns: v.columns.filter(function (o) {
|
|
193
|
-
return o.database_type && (NUMBER_GROUP.includes(o.database_type) || (condition === '最大值' || condition === '最小值') && DATE_GROUP.includes(o.database_type));
|
|
228
|
+
return o.database_type && ((condition === '聚合字符串拼接' ? STRING_GROUP.includes(o.database_type) : NUMBER_GROUP.includes(o.database_type)) || (condition === '最大值' || condition === '最小值') && DATE_GROUP.includes(o.database_type));
|
|
194
229
|
})
|
|
195
230
|
});
|
|
196
231
|
}).filter(function (v) {
|
|
@@ -199,9 +234,16 @@ var SelectSummarize = function SelectSummarize(_ref) {
|
|
|
199
234
|
}
|
|
200
235
|
return availableData;
|
|
201
236
|
}
|
|
237
|
+
var getCurrentPopupContainer = function getCurrentPopupContainer(node) {
|
|
238
|
+
var _node$closest;
|
|
239
|
+
return (node === null || node === void 0 || (_node$closest = node.closest) === null || _node$closest === void 0 ? void 0 : _node$closest.call(node, '[data-sqb-popup-container="true"]')) || document.body;
|
|
240
|
+
};
|
|
202
241
|
if (condition && !~Special.indexOf(condition)) {
|
|
203
242
|
return _jsxs("div", {
|
|
204
|
-
|
|
243
|
+
ref: formulaRootRef,
|
|
244
|
+
className: cx('Sqb-SelectSummarize-formula', {
|
|
245
|
+
'is-string-agg': condition === '聚合字符串拼接'
|
|
246
|
+
}),
|
|
205
247
|
children: [_jsx("div", {
|
|
206
248
|
className: 'back-title',
|
|
207
249
|
children: _jsxs("div", {
|
|
@@ -210,11 +252,25 @@ var SelectSummarize = function SelectSummarize(_ref) {
|
|
|
210
252
|
children: [" ", __(localeMap[condition]), " "]
|
|
211
253
|
})]
|
|
212
254
|
})
|
|
213
|
-
}),
|
|
255
|
+
}), _jsxs("div", {
|
|
214
256
|
className: 'Sqb-SelectSummarize-formula-body',
|
|
215
|
-
children:
|
|
257
|
+
children: [condition === '聚合字符串拼接' && _jsxs("div", {
|
|
258
|
+
className: 'Sqb-item Sqb-string-agg-distinct',
|
|
259
|
+
children: [_jsx(Checkbox, {
|
|
260
|
+
checked: distinct,
|
|
261
|
+
disabled: readonly,
|
|
262
|
+
onChange: setDistinct,
|
|
263
|
+
children: "\u662F\u5426\u5F00\u542F\u53BB\u91CD"
|
|
264
|
+
}), _jsx("span", {
|
|
265
|
+
className: 'Sqb-string-agg-distinct-tip',
|
|
266
|
+
children: "SQL Server \u4E0D\u652F\u6301\u914D\u7F6E DISTINCT\uFF0C\u8BF7\u5728\u5B50\u67E5\u8BE2\u91CC\u9762\u53BB\u91CD\u5B8C\u518D\u62FC\u63A5"
|
|
267
|
+
})]
|
|
268
|
+
}), _jsxs("div", {
|
|
216
269
|
className: 'Sqb-item',
|
|
217
|
-
children: _jsx("div", {
|
|
270
|
+
children: [condition === '聚合字符串拼接' && _jsx("div", {
|
|
271
|
+
className: 'Sqb-item--label',
|
|
272
|
+
children: "\u9009\u62E9\u62FC\u63A5\u5B57\u6BB5"
|
|
273
|
+
}), _jsx("div", {
|
|
218
274
|
className: 'Sqb-item--content',
|
|
219
275
|
children: _jsx(FormulaList, {
|
|
220
276
|
value: atoms,
|
|
@@ -227,17 +283,82 @@ var SelectSummarize = function SelectSummarize(_ref) {
|
|
|
227
283
|
didUpdate === null || didUpdate === void 0 || didUpdate();
|
|
228
284
|
}
|
|
229
285
|
})
|
|
230
|
-
})
|
|
231
|
-
})
|
|
286
|
+
})]
|
|
287
|
+
}), condition === '聚合字符串拼接' && _jsxs(_Fragment, {
|
|
288
|
+
children: [_jsxs("div", {
|
|
289
|
+
className: 'Sqb-item',
|
|
290
|
+
children: [_jsx("div", {
|
|
291
|
+
className: 'Sqb-item--label',
|
|
292
|
+
children: "\u5206\u9694\u7B26"
|
|
293
|
+
}), _jsx("div", {
|
|
294
|
+
className: 'Sqb-item--content',
|
|
295
|
+
children: _jsx(Input, {
|
|
296
|
+
value: delimiter,
|
|
297
|
+
placeholder: "\u8BF7\u8F93\u5165\u5206\u9694\u7B26",
|
|
298
|
+
size: 'large',
|
|
299
|
+
onChange: function onChange(val) {
|
|
300
|
+
return setDelimiter(val);
|
|
301
|
+
}
|
|
302
|
+
})
|
|
303
|
+
})]
|
|
304
|
+
}), _jsxs("div", {
|
|
305
|
+
className: 'Sqb-item',
|
|
306
|
+
children: [_jsx("div", {
|
|
307
|
+
className: 'Sqb-item--label',
|
|
308
|
+
children: "\u9009\u62E9\u6392\u5E8F\u5B57\u6BB5"
|
|
309
|
+
}), _jsx("div", {
|
|
310
|
+
className: 'Sqb-item--content',
|
|
311
|
+
children: _jsx(FormulaList, {
|
|
312
|
+
value: orderBy,
|
|
313
|
+
data: data,
|
|
314
|
+
exitData: data,
|
|
315
|
+
enableCopy: false,
|
|
316
|
+
parentPopupChannel: 'secondary',
|
|
317
|
+
onChange: function onChange(nextValue) {
|
|
318
|
+
setOrderBy(nextValue);
|
|
319
|
+
didUpdate === null || didUpdate === void 0 || didUpdate();
|
|
320
|
+
}
|
|
321
|
+
})
|
|
322
|
+
})]
|
|
323
|
+
}), _jsxs("div", {
|
|
324
|
+
className: 'Sqb-item',
|
|
325
|
+
children: [_jsx("div", {
|
|
326
|
+
className: 'Sqb-item--label',
|
|
327
|
+
children: "\u9009\u62E9\u6392\u5E8F\u89C4\u5219"
|
|
328
|
+
}), _jsx("div", {
|
|
329
|
+
className: 'Sqb-item--content',
|
|
330
|
+
children: _jsxs(Select, {
|
|
331
|
+
value: orderDirection,
|
|
332
|
+
size: 'large',
|
|
333
|
+
getPopupContainer: getCurrentPopupContainer,
|
|
334
|
+
onChange: function onChange(val) {
|
|
335
|
+
return setOrderDirection(val);
|
|
336
|
+
},
|
|
337
|
+
children: [_jsx(Select.Option, {
|
|
338
|
+
value: 'ASC',
|
|
339
|
+
children: "ASC"
|
|
340
|
+
}), _jsx(Select.Option, {
|
|
341
|
+
value: 'DESC',
|
|
342
|
+
children: "DESC"
|
|
343
|
+
})]
|
|
344
|
+
})
|
|
345
|
+
})]
|
|
346
|
+
})]
|
|
347
|
+
})]
|
|
232
348
|
}), !readonly && _jsx("div", {
|
|
233
349
|
className: 'Sqb-SelectSummarize-formula-footer',
|
|
234
350
|
children: _jsx(Button, {
|
|
235
351
|
primary: true,
|
|
236
352
|
disabled: !atoms.length,
|
|
237
353
|
onClick: function onClick() {
|
|
238
|
-
handleSelect(condition, {
|
|
354
|
+
handleSelect(condition, _objectSpread({
|
|
239
355
|
atoms: atoms
|
|
240
|
-
}
|
|
356
|
+
}, condition === '聚合字符串拼接' ? {
|
|
357
|
+
distinct: distinct,
|
|
358
|
+
delimiter: delimiter,
|
|
359
|
+
orderBy: orderBy,
|
|
360
|
+
orderDirection: orderDirection
|
|
361
|
+
} : {}));
|
|
241
362
|
},
|
|
242
363
|
children: "\u786E\u5B9A"
|
|
243
364
|
})
|
|
@@ -156,6 +156,26 @@
|
|
|
156
156
|
width: min(760px, calc(100vw - 64px));
|
|
157
157
|
max-width: 100%;
|
|
158
158
|
background: #fff;
|
|
159
|
+
|
|
160
|
+
&.is-string-agg {
|
|
161
|
+
display: flex;
|
|
162
|
+
flex-direction: column;
|
|
163
|
+
height: min(680px, calc(100vh - 20px));
|
|
164
|
+
max-height: inherit;
|
|
165
|
+
overflow: hidden;
|
|
166
|
+
|
|
167
|
+
.back-title,
|
|
168
|
+
.Sqb-SelectSummarize-formula-footer {
|
|
169
|
+
flex: none;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.Sqb-SelectSummarize-formula-body {
|
|
173
|
+
flex: 1;
|
|
174
|
+
min-height: 0;
|
|
175
|
+
max-height: none;
|
|
176
|
+
overflow-y: auto;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
159
179
|
}
|
|
160
180
|
|
|
161
181
|
.Sqb-SelectSummarize-formula-body {
|
|
@@ -167,10 +187,23 @@
|
|
|
167
187
|
.Sqb-item--content {
|
|
168
188
|
width: 100%;
|
|
169
189
|
}
|
|
190
|
+
|
|
191
|
+
.Sqb-item--label {
|
|
192
|
+
margin: 12px 0 6px;
|
|
193
|
+
color: #5f6575;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.Sqb-string-agg-distinct-tip {
|
|
197
|
+
margin-left: 8px;
|
|
198
|
+
color: #949aab;
|
|
199
|
+
font-size: 12px;
|
|
200
|
+
}
|
|
170
201
|
}
|
|
171
202
|
|
|
172
203
|
.Sqb-SelectSummarize-formula-footer {
|
|
173
204
|
display: flex;
|
|
174
205
|
justify-content: flex-end;
|
|
175
|
-
padding:
|
|
206
|
+
padding: 8px 16px;
|
|
207
|
+
box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.05);
|
|
208
|
+
background: #fff;
|
|
176
209
|
}
|
|
@@ -233,8 +233,16 @@ var Metabase = function Metabase(props) {
|
|
|
233
233
|
e.preventDefault();
|
|
234
234
|
e.stopPropagation();
|
|
235
235
|
};
|
|
236
|
+
var stopTooltipInteraction = function stopTooltipInteraction(e) {
|
|
237
|
+
var _target$closest2;
|
|
238
|
+
var target = e.target;
|
|
239
|
+
if (!(target !== null && target !== void 0 && (_target$closest2 = target.closest) !== null && _target$closest2 !== void 0 && _target$closest2.call(target, '.pd-Tooltip'))) return;
|
|
240
|
+
e.stopPropagation();
|
|
241
|
+
};
|
|
236
242
|
return _jsx(VisualBox, {
|
|
237
243
|
ref: store.popupContainer,
|
|
244
|
+
onMouseDownCapture: stopTooltipInteraction,
|
|
245
|
+
onClickCapture: stopTooltipInteraction,
|
|
238
246
|
onContextMenu: function onContextMenu(e) {
|
|
239
247
|
if (readonlyMode) {
|
|
240
248
|
e.preventDefault();
|
|
@@ -11,7 +11,15 @@ var ItemName = function ItemName(props) {
|
|
|
11
11
|
var showError = isError && !store.snapshotMode;
|
|
12
12
|
return _jsx(Badge, {
|
|
13
13
|
count: showError ? _jsx(Tooltip, {
|
|
14
|
-
title:
|
|
14
|
+
title: _jsx("span", {
|
|
15
|
+
onMouseDown: function onMouseDown(e) {
|
|
16
|
+
return e.stopPropagation();
|
|
17
|
+
},
|
|
18
|
+
onClick: function onClick(e) {
|
|
19
|
+
return e.stopPropagation();
|
|
20
|
+
},
|
|
21
|
+
children: message || __('metabase.verify')
|
|
22
|
+
}),
|
|
15
23
|
children: _jsx(Button, {
|
|
16
24
|
className: 'isError',
|
|
17
25
|
style: {
|
|
@@ -22,7 +30,13 @@ var ItemName = function ItemName(props) {
|
|
|
22
30
|
danger: true,
|
|
23
31
|
size: 'small',
|
|
24
32
|
icon: _jsx(ExclamationCircleFill, {}),
|
|
25
|
-
iconOnly: true
|
|
33
|
+
iconOnly: true,
|
|
34
|
+
onMouseDown: function onMouseDown(e) {
|
|
35
|
+
return e.stopPropagation();
|
|
36
|
+
},
|
|
37
|
+
onClick: function onClick(e) {
|
|
38
|
+
return e.stopPropagation();
|
|
39
|
+
}
|
|
26
40
|
})
|
|
27
41
|
}) : '',
|
|
28
42
|
children: children
|
|
@@ -528,7 +528,18 @@ var GroupBy = function GroupBy(props) {
|
|
|
528
528
|
children: [v.quotes && _jsx(_Fragment, {
|
|
529
529
|
children: store.groupByEnableAlias && !store.snapshotMode && _jsx(_Fragment, {
|
|
530
530
|
children: _jsx(Tooltip, {
|
|
531
|
-
|
|
531
|
+
triggerProps: {
|
|
532
|
+
duration: 0
|
|
533
|
+
},
|
|
534
|
+
title: _jsx("span", {
|
|
535
|
+
onMouseDown: function onMouseDown(e) {
|
|
536
|
+
return e.stopPropagation();
|
|
537
|
+
},
|
|
538
|
+
onClick: function onClick(e) {
|
|
539
|
+
return e.stopPropagation();
|
|
540
|
+
},
|
|
541
|
+
children: __(existsError ? 'SqlQueryBuilder.existsErrorAliasAction' : aliasError ? 'SqlQueryBuilder.aliasForRulesAction' : 'SqlQueryBuilder.alias')
|
|
542
|
+
}),
|
|
532
543
|
children: _jsx(Button, {
|
|
533
544
|
danger: existsError || aliasError,
|
|
534
545
|
className: cx(':Sqb-TableName-as :Sqb-TableName green-name', {
|
|
@@ -426,7 +426,18 @@ var SelectIndex = function SelectIndex(props) {
|
|
|
426
426
|
children: [v.quotes && _jsx(_Fragment, {
|
|
427
427
|
children: store.groupByEnableAlias && !store.snapshotMode && _jsx(_Fragment, {
|
|
428
428
|
children: _jsx(Tooltip, {
|
|
429
|
-
|
|
429
|
+
triggerProps: {
|
|
430
|
+
duration: 0
|
|
431
|
+
},
|
|
432
|
+
title: _jsx("span", {
|
|
433
|
+
onMouseDown: function onMouseDown(e) {
|
|
434
|
+
return e.stopPropagation();
|
|
435
|
+
},
|
|
436
|
+
onClick: function onClick(e) {
|
|
437
|
+
return e.stopPropagation();
|
|
438
|
+
},
|
|
439
|
+
children: __(existsError ? 'SqlQueryBuilder.existsErrorAliasAction' : aliasError ? 'SqlQueryBuilder.aliasForRulesAction' : 'SqlQueryBuilder.alias')
|
|
440
|
+
}),
|
|
430
441
|
children: _jsx(Button, {
|
|
431
442
|
danger: existsError || aliasError,
|
|
432
443
|
className: cx(':Sqb-TableName-as :Sqb-TableName green-name', {
|
|
@@ -519,8 +519,6 @@ var useStore = function useStore() {
|
|
|
519
519
|
isSelect,
|
|
520
520
|
_isSubquery,
|
|
521
521
|
_isExit,
|
|
522
|
-
oldObj,
|
|
523
|
-
selectId,
|
|
524
522
|
_table$alias,
|
|
525
523
|
alias,
|
|
526
524
|
datasourceName,
|
|
@@ -539,17 +537,7 @@ var useStore = function useStore() {
|
|
|
539
537
|
isSelect = _args8.length > 4 && _args8[4] !== undefined ? _args8[4] : isSelectFields;
|
|
540
538
|
_isSubquery = _args8.length > 5 && _args8[5] !== undefined ? _args8[5] : isSubquery;
|
|
541
539
|
_isExit = _args8.length > 6 && _args8[6] !== undefined ? _args8[6] : isExit;
|
|
542
|
-
oldObj = {};
|
|
543
|
-
selectId = oldColumns.filter(function (v) {
|
|
544
|
-
oldObj[v.id] = v;
|
|
545
|
-
return v.select;
|
|
546
|
-
}).map(function (v) {
|
|
547
|
-
return v.id;
|
|
548
|
-
}).filter(function (v) {
|
|
549
|
-
return v;
|
|
550
|
-
});
|
|
551
540
|
if (_isSubquery && oldColumns.length < 1) {
|
|
552
|
-
selectId = [];
|
|
553
541
|
isSelect = false;
|
|
554
542
|
}
|
|
555
543
|
_table$alias = table.alias, alias = _table$alias === void 0 ? '' : _table$alias, datasourceName = table.datasourceName, did = table.datasourceId, column = table.column, extra = _objectWithoutProperties(table, _excluded);
|
|
@@ -572,7 +560,7 @@ var useStore = function useStore() {
|
|
|
572
560
|
var obj = oldColumns.find(function (oldColumn) {
|
|
573
561
|
return isSameColumnByIdFirst(oldColumn, v);
|
|
574
562
|
});
|
|
575
|
-
var select =
|
|
563
|
+
var select = Boolean(obj === null || obj === void 0 ? void 0 : obj.select);
|
|
576
564
|
return _objectSpread(_objectSpread(_objectSpread({}, obj), v), {}, {
|
|
577
565
|
select: isSelect || select,
|
|
578
566
|
fieldAlias: (_ref9 = (_obj$fieldAlias = obj === null || obj === void 0 ? void 0 : obj.fieldAlias) !== null && _obj$fieldAlias !== void 0 ? _obj$fieldAlias : v.fieldAlias) !== null && _ref9 !== void 0 ? _ref9 : '',
|
package/lib/es/locale/en.js
CHANGED
|
@@ -144,6 +144,8 @@ export default register('en', {
|
|
|
144
144
|
'summarize.theSmallestYes': 'the smallest, yes',
|
|
145
145
|
'summarize.maximumCalue': 'maximum value',
|
|
146
146
|
'summarize.biggestYes': 'biggest, yes',
|
|
147
|
+
'summarize.stringAgg': 'Aggregate string concatenation',
|
|
148
|
+
'summarize.stringAggExpression': 'STRING_AGG',
|
|
147
149
|
'summarize.totalNumberOfRowsOfData': 'total number of rows of data',
|
|
148
150
|
'summarize.theSumOfAllValuesInAField': 'the sum of all values in a field',
|
|
149
151
|
'summarize.theAverageOfAllValuesInAfield': 'the average of all values in a field',
|
|
@@ -153,6 +155,7 @@ export default register('en', {
|
|
|
153
155
|
'summarize.theStandardDeviationOfAllValuesInAfield': 'the standard deviation of all values in a field',
|
|
154
156
|
'summarize.theMinimumValueOfAfield': 'the minimum value of a field',
|
|
155
157
|
'summarize.TheMaximumValueOfAfield': 'the maximum value of a field',
|
|
158
|
+
'summarize.stringAggDescription': 'Concatenate strings across rows within each group, with a custom delimiter.',
|
|
156
159
|
'rowLimit.pleaseEnter': 'please enter',
|
|
157
160
|
'result.TheSQLStatementForThisQuery': 'The SQL statement for this query',
|
|
158
161
|
'result.closePanel': 'close panel',
|
package/lib/es/locale/zh.js
CHANGED
|
@@ -144,6 +144,8 @@ export default register('zh', {
|
|
|
144
144
|
'summarize.theSmallestYes': '最小 的',
|
|
145
145
|
'summarize.maximumCalue': '最大值',
|
|
146
146
|
'summarize.biggestYes': '最大 的',
|
|
147
|
+
'summarize.stringAgg': '聚合字符串拼接',
|
|
148
|
+
'summarize.stringAggExpression': 'STRING_AGG',
|
|
147
149
|
'summarize.totalNumberOfRowsOfData': '总的数据行数',
|
|
148
150
|
'summarize.theSumOfAllValuesInAField': '一个字段所有数值的总和',
|
|
149
151
|
'summarize.theAverageOfAllValuesInAfield': '一个字段所有数值的平均值',
|
|
@@ -153,6 +155,7 @@ export default register('zh', {
|
|
|
153
155
|
'summarize.theStandardDeviationOfAllValuesInAfield': '一个字段所有数值的标准差',
|
|
154
156
|
'summarize.theMinimumValueOfAfield': '一个字段的最小值',
|
|
155
157
|
'summarize.TheMaximumValueOfAfield': '一个字段的最大值',
|
|
158
|
+
'summarize.stringAggDescription': '按分组跨行拼接字符串,支持自定义分隔符。',
|
|
156
159
|
'rowLimit.pleaseEnter': '请输入',
|
|
157
160
|
'result.TheSQLStatementForThisQuery': '这个查询的SQL语句',
|
|
158
161
|
'result.closePanel': '关闭面板',
|
package/lib/es/store/helper.js
CHANGED
|
@@ -2,6 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["children"],
|
|
4
4
|
_excluded2 = ["metaKey"];
|
|
5
|
+
import { AtomsTypeEnum } from './types';
|
|
5
6
|
import { TypeEnum, SQL_COLUMN_TYPE } from './enum';
|
|
6
7
|
import { handleBaseType2Sql } from '../utils/transformSql';
|
|
7
8
|
export var SummarizeAlias = 'source';
|
|
@@ -54,6 +55,25 @@ export var summarizeToSql = function summarizeToSql(arr, record) {
|
|
|
54
55
|
sql = "max(".concat(field, ")");
|
|
55
56
|
as = 'max';
|
|
56
57
|
break;
|
|
58
|
+
case '聚合字符串拼接':
|
|
59
|
+
if (typeof record.delimiter === 'string') {
|
|
60
|
+
var _record$atoms2, _record$atoms3, _record$orderBy;
|
|
61
|
+
var delimiterIndex = (_record$atoms2 = record.atoms) === null || _record$atoms2 === void 0 ? void 0 : _record$atoms2.findIndex(function (atom) {
|
|
62
|
+
return atom.type === AtomsTypeEnum.OPERATOR && atom.val === ',';
|
|
63
|
+
});
|
|
64
|
+
var expressionAtoms = typeof delimiterIndex === 'number' && delimiterIndex >= 0 ? (_record$atoms3 = record.atoms) === null || _record$atoms3 === void 0 ? void 0 : _record$atoms3.slice(0, delimiterIndex) : record.atoms;
|
|
65
|
+
var expression = expressionAtoms !== null && expressionAtoms !== void 0 && expressionAtoms.length ? handleBaseType2Sql(expressionAtoms).sql.trim() : field;
|
|
66
|
+
var orderExpression = (_record$orderBy = record.orderBy) !== null && _record$orderBy !== void 0 && _record$orderBy.length ? handleBaseType2Sql(record.orderBy).sql.trim() : '';
|
|
67
|
+
var orderSql = orderExpression ? " order by ".concat(orderExpression, " ").concat(record.orderDirection || 'ASC') : '';
|
|
68
|
+
sql = "string_agg(".concat(record.distinct ? 'distinct ' : '').concat(expression, ", '").concat(record.delimiter.replace(/'/g, "''"), "'").concat(orderSql, ")");
|
|
69
|
+
} else {
|
|
70
|
+
var _record$atoms4;
|
|
71
|
+
sql = "string_agg(".concat(field).concat((_record$atoms4 = record.atoms) !== null && _record$atoms4 !== void 0 && _record$atoms4.some(function (atom) {
|
|
72
|
+
return atom.type === AtomsTypeEnum.OPERATOR && atom.val === ',';
|
|
73
|
+
}) ? '' : ", ','", ")");
|
|
74
|
+
}
|
|
75
|
+
as = 'string_agg';
|
|
76
|
+
break;
|
|
57
77
|
}
|
|
58
78
|
var count = 0;
|
|
59
79
|
prevList.forEach(function (v) {
|
|
@@ -75,6 +95,9 @@ export var summarizeToSql = function summarizeToSql(arr, record) {
|
|
|
75
95
|
if (condition === '最大值' && v.condition === '最大值') {
|
|
76
96
|
count++;
|
|
77
97
|
}
|
|
98
|
+
if (condition === '聚合字符串拼接' && v.condition === '聚合字符串拼接') {
|
|
99
|
+
count++;
|
|
100
|
+
}
|
|
78
101
|
});
|
|
79
102
|
as = as + (count ? '_' + (count + 1) : '');
|
|
80
103
|
return {
|
|
@@ -83,9 +106,9 @@ export var summarizeToSql = function summarizeToSql(arr, record) {
|
|
|
83
106
|
};
|
|
84
107
|
};
|
|
85
108
|
export var summarizeByToSql = function summarizeByToSql(record) {
|
|
86
|
-
var _record$
|
|
109
|
+
var _record$atoms5;
|
|
87
110
|
var sql = "".concat(record.alias, ".").concat(record.realName || record.name);
|
|
88
|
-
if ((_record$
|
|
111
|
+
if ((_record$atoms5 = record.atoms) !== null && _record$atoms5 !== void 0 && _record$atoms5.length) {
|
|
89
112
|
sql = handleBaseType2Sql(record.atoms).sql.trim() || sql;
|
|
90
113
|
}
|
|
91
114
|
return sql;
|
package/lib/es/store/types.d.ts
CHANGED
|
@@ -293,6 +293,10 @@ export interface MetaSummarize_Group {
|
|
|
293
293
|
datasourceId: string;
|
|
294
294
|
datasourceName: string;
|
|
295
295
|
atoms?: AtomsItem[];
|
|
296
|
+
delimiter?: string;
|
|
297
|
+
distinct?: boolean;
|
|
298
|
+
orderBy?: AtomsItem[];
|
|
299
|
+
orderDirection?: SortEnum;
|
|
296
300
|
summarizeType: MetaSummarize_Enum;
|
|
297
301
|
[params: string]: any;
|
|
298
302
|
}
|