@gingkoo/pandora-metabase 1.0.156 → 1.0.157-alpha.1

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 (29) hide show
  1. package/lib/cjs/components/dialog/formula-list/index.js +16 -8
  2. package/lib/cjs/components/dialog/select-summarize/index.d.ts +4 -0
  3. package/lib/cjs/components/dialog/select-summarize/index.js +136 -15
  4. package/lib/cjs/components/dialog/select-summarize/index.less +34 -1
  5. package/lib/cjs/components/metabase/index.js +8 -0
  6. package/lib/cjs/components/metabase/index.less +5 -0
  7. package/lib/cjs/components/modules/components/item-name.js +16 -2
  8. package/lib/cjs/components/modules/summarize/group-by.js +12 -1
  9. package/lib/cjs/components/modules/summarize/select-index.js +12 -1
  10. package/lib/cjs/locale/en.js +3 -0
  11. package/lib/cjs/locale/zh.js +3 -0
  12. package/lib/cjs/store/helper.js +25 -2
  13. package/lib/cjs/store/types.d.ts +4 -0
  14. package/lib/cjs/utils.js +23 -2
  15. package/lib/es/components/dialog/formula-list/index.js +16 -8
  16. package/lib/es/components/dialog/select-summarize/index.d.ts +4 -0
  17. package/lib/es/components/dialog/select-summarize/index.js +140 -19
  18. package/lib/es/components/dialog/select-summarize/index.less +34 -1
  19. package/lib/es/components/metabase/index.js +8 -0
  20. package/lib/es/components/metabase/index.less +5 -0
  21. package/lib/es/components/modules/components/item-name.js +16 -2
  22. package/lib/es/components/modules/summarize/group-by.js +12 -1
  23. package/lib/es/components/modules/summarize/select-index.js +12 -1
  24. package/lib/es/locale/en.js +3 -0
  25. package/lib/es/locale/zh.js +3 -0
  26. package/lib/es/store/helper.js +25 -2
  27. package/lib/es/store/types.d.ts +4 -0
  28. package/lib/es/utils.js +23 -2
  29. package/package.json +1 -1
@@ -48,6 +48,7 @@ var _excluded = ["operator", "leftAtoms", "rightAtoms", "atoms"],
48
48
  _excluded2 = ["notExistsToolbar", "toolbar"],
49
49
  _excluded3 = ["subToolbar", "notExistsColumns", "showFields", "isExit", "toolbar"];
50
50
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); }
51
+ var parentPopupLockCounts = new WeakMap();
51
52
  var CASE_FIXED_OPERATORS = ['case', 'when', 'then', 'else', 'end'];
52
53
  var LOGIC_FIXED_OPERATORS = ['(', ')'];
53
54
  var LOGIC_REQUIRED_OPERATORS = ['(', ')'];
@@ -199,6 +200,16 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
199
200
  }
200
201
  store.setClosable(closable);
201
202
  };
203
+ var changeSharedParentLockCount = function changeSharedParentLockCount(delta) {
204
+ if (!parentPopupChannel) return;
205
+ var counts = parentPopupLockCounts.get(store) || {
206
+ primary: 0,
207
+ secondary: 0
208
+ };
209
+ counts[parentPopupChannel] = Math.max(0, counts[parentPopupChannel] + delta);
210
+ parentPopupLockCounts.set(store, counts);
211
+ setParentClosable(counts[parentPopupChannel] === 0);
212
+ };
202
213
  var lockParentPopup = function lockParentPopup() {
203
214
  if (!parentPopupChannel) return;
204
215
  if (parentPopupUnlockTimerRef.current) {
@@ -206,19 +217,16 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
206
217
  parentPopupUnlockTimerRef.current = null;
207
218
  }
208
219
  parentPopupLockCountRef.current += 1;
209
- if (parentPopupLockCountRef.current === 1) {
210
- setParentClosable(false);
211
- }
220
+ changeSharedParentLockCount(1);
212
221
  };
213
222
  var unlockParentPopup = function unlockParentPopup() {
214
223
  var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
215
224
  if (!parentPopupChannel) return;
216
225
  var runUnlock = function runUnlock() {
217
226
  parentPopupUnlockTimerRef.current = null;
218
- parentPopupLockCountRef.current = Math.max(0, parentPopupLockCountRef.current - 1);
219
- if (parentPopupLockCountRef.current === 0) {
220
- setParentClosable(true);
221
- }
227
+ if (parentPopupLockCountRef.current === 0) return;
228
+ parentPopupLockCountRef.current -= 1;
229
+ changeSharedParentLockCount(-1);
222
230
  };
223
231
  if (delay > 0) {
224
232
  if (parentPopupUnlockTimerRef.current) {
@@ -268,8 +276,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
268
276
  parentPopupUnlockTimerRef.current = null;
269
277
  }
270
278
  if (parentPopupLockCountRef.current > 0) {
279
+ changeSharedParentLockCount(-parentPopupLockCountRef.current);
271
280
  parentPopupLockCountRef.current = 0;
272
- setParentClosable(true);
273
281
  }
274
282
  };
275
283
  }, [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[];
@@ -47,8 +47,11 @@ var metricOptions = [{
47
47
  }, {
48
48
  name: '最大值',
49
49
  tip: '一个字段的最大值'
50
+ }, {
51
+ name: '聚合字符串拼接',
52
+ tip: '按分组跨行拼接字符串,支持自定义分隔符。'
50
53
  }];
51
- var QuotesMap = new Map([['总行数', '计数'], ['总和', '求和 的'], ['平均值', '平均 的'], ['不重复值的总数', '不重复的值 的'], ['累积求和', '累积和 的'], ['累积行数', '累积计数'], ['标准差', '标准偏差 的'], ['最小值', '最小 的'], ['最大值', '最大 的']]);
54
+ var QuotesMap = new Map([['总行数', '计数'], ['总和', '求和 的'], ['平均值', '平均 的'], ['不重复值的总数', '不重复的值 的'], ['累积求和', '累积和 的'], ['累积行数', '累积计数'], ['标准差', '标准偏差 的'], ['最小值', '最小 的'], ['最大值', '最大 的'], ['聚合字符串拼接', 'STRING_AGG']]);
52
55
  var localeMap = {
53
56
  总行数: 'summarize.totalNumberOfRows',
54
57
  计数: 'summarize.count',
@@ -68,6 +71,8 @@ var localeMap = {
68
71
  '最小 的': 'summarize.theSmallestYes',
69
72
  最大值: 'summarize.maximumCalue',
70
73
  '最大 的': 'summarize.biggestYes',
74
+ 聚合字符串拼接: 'summarize.stringAgg',
75
+ STRING_AGG: 'summarize.stringAggExpression',
71
76
  总的数据行数: 'summarize.totalNumberOfRowsOfData',
72
77
  一个字段所有数值的总和: 'summarize.theSumOfAllValuesInAField',
73
78
  一个字段所有数值的平均值: 'summarize.theAverageOfAllValuesInAfield',
@@ -76,21 +81,51 @@ var localeMap = {
76
81
  '行数的加法统计。如;x段时间内的销售总额': 'summarize.additiveStatisticsOfTheNumberOfRows',
77
82
  一个字段所有数值的标准差: 'summarize.theStandardDeviationOfAllValuesInAfield',
78
83
  一个字段的最小值: 'summarize.theMinimumValueOfAfield',
79
- 一个字段的最大值: 'summarize.TheMaximumValueOfAfield'
84
+ 一个字段的最大值: 'summarize.TheMaximumValueOfAfield',
85
+ '按分组跨行拼接字符串,支持自定义分隔符。': 'summarize.stringAggDescription'
80
86
  };
81
87
  var Special = ['总行数', '累积行数'];
82
88
  var SelectSummarize = function SelectSummarize(_ref) {
89
+ var _value$delimiter, _value$distinct;
83
90
  var data = _ref.data,
84
91
  value = _ref.value,
85
92
  onChange = _ref.onChange,
86
93
  didUpdate = _ref.didUpdate,
87
94
  ignoreGroupByType = _ref.ignoreGroupByType,
88
95
  readonly = _ref.readonly;
96
+ var formulaRootRef = (0, _react.useRef)(null);
89
97
  var _useState = (0, _react.useState)(value.condition),
90
98
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
91
99
  condition = _useState2[0],
92
100
  setCondition = _useState2[1];
93
- var _useState3 = (0, _react.useState)(function () {
101
+ var _useState3 = (0, _react.useState)((_value$delimiter = value.delimiter) !== null && _value$delimiter !== void 0 ? _value$delimiter : ','),
102
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
103
+ delimiter = _useState4[0],
104
+ setDelimiter = _useState4[1];
105
+ var _useState5 = (0, _react.useState)((_value$distinct = value.distinct) !== null && _value$distinct !== void 0 ? _value$distinct : false),
106
+ _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
107
+ distinct = _useState6[0],
108
+ setDistinct = _useState6[1];
109
+ var _useState7 = (0, _react.useState)(value.orderBy || []),
110
+ _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
111
+ orderBy = _useState8[0],
112
+ setOrderBy = _useState8[1];
113
+ var _useState9 = (0, _react.useState)(value.orderDirection || 'ASC'),
114
+ _useState0 = (0, _slicedToArray2["default"])(_useState9, 2),
115
+ orderDirection = _useState0[0],
116
+ setOrderDirection = _useState0[1];
117
+ (0, _react.useEffect)(function () {
118
+ var _formulaRootRef$curre;
119
+ if (condition !== '聚合字符串拼接') return;
120
+ var popup = (_formulaRootRef$curre = formulaRootRef.current) === null || _formulaRootRef$curre === void 0 ? void 0 : _formulaRootRef$curre.parentElement;
121
+ if (!popup) return;
122
+ var previousOverflowY = popup.style.overflowY;
123
+ popup.style.overflowY = 'hidden';
124
+ return function () {
125
+ popup.style.overflowY = previousOverflowY;
126
+ };
127
+ }, [condition]);
128
+ var _useState1 = (0, _react.useState)(function () {
94
129
  if (Special.includes(value.condition)) {
95
130
  return [];
96
131
  }
@@ -117,9 +152,9 @@ var SelectSummarize = function SelectSummarize(_ref) {
117
152
  }
118
153
  return [];
119
154
  }),
120
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
121
- atoms = _useState4[0],
122
- setAtoms = _useState4[1];
155
+ _useState10 = (0, _slicedToArray2["default"])(_useState1, 2),
156
+ atoms = _useState10[0],
157
+ setAtoms = _useState10[1];
123
158
  function goPrevPage() {
124
159
  if (readonly) return;
125
160
  setCondition('');
@@ -197,7 +232,7 @@ var SelectSummarize = function SelectSummarize(_ref) {
197
232
  availableData = data.map(function (v) {
198
233
  return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v), {}, {
199
234
  columns: v.columns.filter(function (o) {
200
- return o.database_type && (_const.NUMBER_GROUP.includes(o.database_type) || (condition === '最大值' || condition === '最小值') && _const.DATE_GROUP.includes(o.database_type));
235
+ return o.database_type && ((condition === '聚合字符串拼接' ? _const.STRING_GROUP.includes(o.database_type) : _const.NUMBER_GROUP.includes(o.database_type)) || (condition === '最大值' || condition === '最小值') && _const.DATE_GROUP.includes(o.database_type));
201
236
  })
202
237
  });
203
238
  }).filter(function (v) {
@@ -206,9 +241,16 @@ var SelectSummarize = function SelectSummarize(_ref) {
206
241
  }
207
242
  return availableData;
208
243
  }
244
+ var getCurrentPopupContainer = function getCurrentPopupContainer(node) {
245
+ var _node$closest;
246
+ 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;
247
+ };
209
248
  if (condition && !~Special.indexOf(condition)) {
210
249
  return (0, _jsxRuntime.jsxs)("div", {
211
- className: 'Sqb-SelectSummarize-formula',
250
+ ref: formulaRootRef,
251
+ className: (0, _classnames["default"])('Sqb-SelectSummarize-formula', {
252
+ 'is-string-agg': condition === '聚合字符串拼接'
253
+ }),
212
254
  children: [(0, _jsxRuntime.jsx)("div", {
213
255
  className: 'back-title',
214
256
  children: (0, _jsxRuntime.jsxs)("div", {
@@ -217,11 +259,25 @@ var SelectSummarize = function SelectSummarize(_ref) {
217
259
  children: [" ", (0, _locale.__)(localeMap[condition]), " "]
218
260
  })]
219
261
  })
220
- }), (0, _jsxRuntime.jsx)("div", {
262
+ }), (0, _jsxRuntime.jsxs)("div", {
221
263
  className: 'Sqb-SelectSummarize-formula-body',
222
- children: (0, _jsxRuntime.jsx)("div", {
264
+ children: [condition === '聚合字符串拼接' && (0, _jsxRuntime.jsxs)("div", {
265
+ className: 'Sqb-item Sqb-string-agg-distinct',
266
+ children: [(0, _jsxRuntime.jsx)(_pandora.Checkbox, {
267
+ checked: distinct,
268
+ disabled: readonly,
269
+ onChange: setDistinct,
270
+ children: "\u662F\u5426\u5F00\u542F\u53BB\u91CD"
271
+ }), (0, _jsxRuntime.jsx)("span", {
272
+ className: 'Sqb-string-agg-distinct-tip',
273
+ children: "SQL Server \u4E0D\u652F\u6301\u914D\u7F6E DISTINCT\uFF0C\u8BF7\u5728\u5B50\u67E5\u8BE2\u91CC\u9762\u53BB\u91CD\u5B8C\u518D\u62FC\u63A5"
274
+ })]
275
+ }), (0, _jsxRuntime.jsxs)("div", {
223
276
  className: 'Sqb-item',
224
- children: (0, _jsxRuntime.jsx)("div", {
277
+ children: [condition === '聚合字符串拼接' && (0, _jsxRuntime.jsx)("div", {
278
+ className: 'Sqb-item--label',
279
+ children: "\u9009\u62E9\u62FC\u63A5\u5B57\u6BB5"
280
+ }), (0, _jsxRuntime.jsx)("div", {
225
281
  className: 'Sqb-item--content',
226
282
  children: (0, _jsxRuntime.jsx)(_formulaList["default"], {
227
283
  value: atoms,
@@ -234,17 +290,82 @@ var SelectSummarize = function SelectSummarize(_ref) {
234
290
  didUpdate === null || didUpdate === void 0 || didUpdate();
235
291
  }
236
292
  })
237
- })
238
- })
293
+ })]
294
+ }), condition === '聚合字符串拼接' && (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
295
+ children: [(0, _jsxRuntime.jsxs)("div", {
296
+ className: 'Sqb-item',
297
+ children: [(0, _jsxRuntime.jsx)("div", {
298
+ className: 'Sqb-item--label',
299
+ children: "\u5206\u9694\u7B26"
300
+ }), (0, _jsxRuntime.jsx)("div", {
301
+ className: 'Sqb-item--content',
302
+ children: (0, _jsxRuntime.jsx)(_pandora.Input, {
303
+ value: delimiter,
304
+ placeholder: "\u8BF7\u8F93\u5165\u5206\u9694\u7B26",
305
+ size: 'large',
306
+ onChange: function onChange(val) {
307
+ return setDelimiter(val);
308
+ }
309
+ })
310
+ })]
311
+ }), (0, _jsxRuntime.jsxs)("div", {
312
+ className: 'Sqb-item',
313
+ children: [(0, _jsxRuntime.jsx)("div", {
314
+ className: 'Sqb-item--label',
315
+ children: "\u9009\u62E9\u6392\u5E8F\u5B57\u6BB5"
316
+ }), (0, _jsxRuntime.jsx)("div", {
317
+ className: 'Sqb-item--content',
318
+ children: (0, _jsxRuntime.jsx)(_formulaList["default"], {
319
+ value: orderBy,
320
+ data: data,
321
+ exitData: data,
322
+ enableCopy: false,
323
+ parentPopupChannel: 'secondary',
324
+ onChange: function onChange(nextValue) {
325
+ setOrderBy(nextValue);
326
+ didUpdate === null || didUpdate === void 0 || didUpdate();
327
+ }
328
+ })
329
+ })]
330
+ }), (0, _jsxRuntime.jsxs)("div", {
331
+ className: 'Sqb-item',
332
+ children: [(0, _jsxRuntime.jsx)("div", {
333
+ className: 'Sqb-item--label',
334
+ children: "\u9009\u62E9\u6392\u5E8F\u89C4\u5219"
335
+ }), (0, _jsxRuntime.jsx)("div", {
336
+ className: 'Sqb-item--content',
337
+ children: (0, _jsxRuntime.jsxs)(_pandora.Select, {
338
+ value: orderDirection,
339
+ size: 'large',
340
+ getPopupContainer: getCurrentPopupContainer,
341
+ onChange: function onChange(val) {
342
+ return setOrderDirection(val);
343
+ },
344
+ children: [(0, _jsxRuntime.jsx)(_pandora.Select.Option, {
345
+ value: 'ASC',
346
+ children: "ASC"
347
+ }), (0, _jsxRuntime.jsx)(_pandora.Select.Option, {
348
+ value: 'DESC',
349
+ children: "DESC"
350
+ })]
351
+ })
352
+ })]
353
+ })]
354
+ })]
239
355
  }), !readonly && (0, _jsxRuntime.jsx)("div", {
240
356
  className: 'Sqb-SelectSummarize-formula-footer',
241
357
  children: (0, _jsxRuntime.jsx)(_pandora.Button, {
242
358
  primary: true,
243
359
  disabled: !atoms.length,
244
360
  onClick: function onClick() {
245
- handleSelect(condition, {
361
+ handleSelect(condition, (0, _objectSpread2["default"])({
246
362
  atoms: atoms
247
- });
363
+ }, condition === '聚合字符串拼接' ? {
364
+ distinct: distinct,
365
+ delimiter: delimiter,
366
+ orderBy: orderBy,
367
+ orderDirection: orderDirection
368
+ } : {}));
248
369
  },
249
370
  children: "\u786E\u5B9A"
250
371
  })
@@ -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: 0 16px 16px;
206
+ padding: 8px 16px;
207
+ box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.05);
208
+ background: #fff;
176
209
  }
@@ -242,8 +242,16 @@ var Metabase = function Metabase(props) {
242
242
  e.preventDefault();
243
243
  e.stopPropagation();
244
244
  };
245
+ var stopTooltipInteraction = function stopTooltipInteraction(e) {
246
+ var _target$closest2;
247
+ var target = e.target;
248
+ if (!(target !== null && target !== void 0 && (_target$closest2 = target.closest) !== null && _target$closest2 !== void 0 && _target$closest2.call(target, '.pd-Tooltip'))) return;
249
+ e.stopPropagation();
250
+ };
245
251
  return (0, _jsxRuntime.jsx)(VisualBox, {
246
252
  ref: store.popupContainer,
253
+ onMouseDownCapture: stopTooltipInteraction,
254
+ onClickCapture: stopTooltipInteraction,
247
255
  onContextMenu: function onContextMenu(e) {
248
256
  if (readonlyMode) {
249
257
  e.preventDefault();
@@ -1,5 +1,10 @@
1
1
  @import './helper.less';
2
2
 
3
+ // Tooltip 动画期间组件库会临时关闭 pointer-events,导致点击穿透到下层按钮。
4
+ .pd-Trigger.pd-Tooltip {
5
+ pointer-events: auto !important;
6
+ }
7
+
3
8
  .visual-box {
4
9
  position: relative;
5
10
  width: 100%;
@@ -17,7 +17,15 @@ var ItemName = function ItemName(props) {
17
17
  var showError = isError && !store.snapshotMode;
18
18
  return (0, _jsxRuntime.jsx)(_pandora.Badge, {
19
19
  count: showError ? (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
20
- title: message || (0, _locale.__)('metabase.verify'),
20
+ title: (0, _jsxRuntime.jsx)("span", {
21
+ onMouseDown: function onMouseDown(e) {
22
+ return e.stopPropagation();
23
+ },
24
+ onClick: function onClick(e) {
25
+ return e.stopPropagation();
26
+ },
27
+ children: message || (0, _locale.__)('metabase.verify')
28
+ }),
21
29
  children: (0, _jsxRuntime.jsx)(_pandora.Button, {
22
30
  className: 'isError',
23
31
  style: {
@@ -28,7 +36,13 @@ var ItemName = function ItemName(props) {
28
36
  danger: true,
29
37
  size: 'small',
30
38
  icon: (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}),
31
- iconOnly: true
39
+ iconOnly: true,
40
+ onMouseDown: function onMouseDown(e) {
41
+ return e.stopPropagation();
42
+ },
43
+ onClick: function onClick(e) {
44
+ return e.stopPropagation();
45
+ }
32
46
  })
33
47
  }) : '',
34
48
  children: children
@@ -534,7 +534,18 @@ var GroupBy = function GroupBy(props) {
534
534
  children: [v.quotes && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
535
535
  children: store.groupByEnableAlias && !store.snapshotMode && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
536
536
  children: (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
537
- title: (0, _locale.__)(existsError ? 'SqlQueryBuilder.existsErrorAliasAction' : aliasError ? 'SqlQueryBuilder.aliasForRulesAction' : 'SqlQueryBuilder.alias'),
537
+ triggerProps: {
538
+ duration: 0
539
+ },
540
+ title: (0, _jsxRuntime.jsx)("span", {
541
+ onMouseDown: function onMouseDown(e) {
542
+ return e.stopPropagation();
543
+ },
544
+ onClick: function onClick(e) {
545
+ return e.stopPropagation();
546
+ },
547
+ children: (0, _locale.__)(existsError ? 'SqlQueryBuilder.existsErrorAliasAction' : aliasError ? 'SqlQueryBuilder.aliasForRulesAction' : 'SqlQueryBuilder.alias')
548
+ }),
538
549
  children: (0, _jsxRuntime.jsx)(_pandora.Button, {
539
550
  danger: existsError || aliasError,
540
551
  className: (0, _classnames["default"])(':Sqb-TableName-as :Sqb-TableName green-name', {
@@ -432,7 +432,18 @@ var SelectIndex = function SelectIndex(props) {
432
432
  children: [v.quotes && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
433
433
  children: store.groupByEnableAlias && !store.snapshotMode && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
434
434
  children: (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
435
- title: (0, _locale.__)(existsError ? 'SqlQueryBuilder.existsErrorAliasAction' : aliasError ? 'SqlQueryBuilder.aliasForRulesAction' : 'SqlQueryBuilder.alias'),
435
+ triggerProps: {
436
+ duration: 0
437
+ },
438
+ title: (0, _jsxRuntime.jsx)("span", {
439
+ onMouseDown: function onMouseDown(e) {
440
+ return e.stopPropagation();
441
+ },
442
+ onClick: function onClick(e) {
443
+ return e.stopPropagation();
444
+ },
445
+ children: (0, _locale.__)(existsError ? 'SqlQueryBuilder.existsErrorAliasAction' : aliasError ? 'SqlQueryBuilder.aliasForRulesAction' : 'SqlQueryBuilder.alias')
446
+ }),
436
447
  children: (0, _jsxRuntime.jsx)(_pandora.Button, {
437
448
  danger: existsError || aliasError,
438
449
  className: (0, _classnames["default"])(':Sqb-TableName-as :Sqb-TableName green-name', {
@@ -150,6 +150,8 @@ var _default = exports["default"] = (0, _index.register)('en', {
150
150
  'summarize.theSmallestYes': 'the smallest, yes',
151
151
  'summarize.maximumCalue': 'maximum value',
152
152
  'summarize.biggestYes': 'biggest, yes',
153
+ 'summarize.stringAgg': 'Aggregate string concatenation',
154
+ 'summarize.stringAggExpression': 'STRING_AGG',
153
155
  'summarize.totalNumberOfRowsOfData': 'total number of rows of data',
154
156
  'summarize.theSumOfAllValuesInAField': 'the sum of all values in a field',
155
157
  'summarize.theAverageOfAllValuesInAfield': 'the average of all values in a field',
@@ -159,6 +161,7 @@ var _default = exports["default"] = (0, _index.register)('en', {
159
161
  'summarize.theStandardDeviationOfAllValuesInAfield': 'the standard deviation of all values in a field',
160
162
  'summarize.theMinimumValueOfAfield': 'the minimum value of a field',
161
163
  'summarize.TheMaximumValueOfAfield': 'the maximum value of a field',
164
+ 'summarize.stringAggDescription': 'Concatenate strings across rows within each group, with a custom delimiter.',
162
165
  'rowLimit.pleaseEnter': 'please enter',
163
166
  'result.TheSQLStatementForThisQuery': 'The SQL statement for this query',
164
167
  'result.closePanel': 'close panel',
@@ -150,6 +150,8 @@ var _default = exports["default"] = (0, _index.register)('zh', {
150
150
  'summarize.theSmallestYes': '最小 的',
151
151
  'summarize.maximumCalue': '最大值',
152
152
  'summarize.biggestYes': '最大 的',
153
+ 'summarize.stringAgg': '聚合字符串拼接',
154
+ 'summarize.stringAggExpression': 'STRING_AGG',
153
155
  'summarize.totalNumberOfRowsOfData': '总的数据行数',
154
156
  'summarize.theSumOfAllValuesInAField': '一个字段所有数值的总和',
155
157
  'summarize.theAverageOfAllValuesInAfield': '一个字段所有数值的平均值',
@@ -159,6 +161,7 @@ var _default = exports["default"] = (0, _index.register)('zh', {
159
161
  'summarize.theStandardDeviationOfAllValuesInAfield': '一个字段所有数值的标准差',
160
162
  'summarize.theMinimumValueOfAfield': '一个字段的最小值',
161
163
  'summarize.TheMaximumValueOfAfield': '一个字段的最大值',
164
+ 'summarize.stringAggDescription': '按分组跨行拼接字符串,支持自定义分隔符。',
162
165
  'rowLimit.pleaseEnter': '请输入',
163
166
  'result.TheSQLStatementForThisQuery': '这个查询的SQL语句',
164
167
  'result.closePanel': '关闭面板',
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.summarizeToSql = exports.summarizeByToSql = exports.restoreStructure = exports.compressionStructure = exports.SummarizeAlias = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
10
+ var _types = require("./types");
10
11
  var _enum = require("./enum");
11
12
  var _transformSql = require("../utils/transformSql");
12
13
  var _excluded = ["children"],
@@ -61,6 +62,25 @@ var summarizeToSql = exports.summarizeToSql = function summarizeToSql(arr, recor
61
62
  sql = "max(".concat(field, ")");
62
63
  as = 'max';
63
64
  break;
65
+ case '聚合字符串拼接':
66
+ if (typeof record.delimiter === 'string') {
67
+ var _record$atoms2, _record$atoms3, _record$orderBy;
68
+ var delimiterIndex = (_record$atoms2 = record.atoms) === null || _record$atoms2 === void 0 ? void 0 : _record$atoms2.findIndex(function (atom) {
69
+ return atom.type === _types.AtomsTypeEnum.OPERATOR && atom.val === ',';
70
+ });
71
+ 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;
72
+ var expression = expressionAtoms !== null && expressionAtoms !== void 0 && expressionAtoms.length ? (0, _transformSql.handleBaseType2Sql)(expressionAtoms).sql.trim() : field;
73
+ var orderExpression = (_record$orderBy = record.orderBy) !== null && _record$orderBy !== void 0 && _record$orderBy.length ? (0, _transformSql.handleBaseType2Sql)(record.orderBy).sql.trim() : '';
74
+ var orderSql = orderExpression ? " order by ".concat(orderExpression, " ").concat(record.orderDirection || 'ASC') : '';
75
+ sql = "string_agg(".concat(record.distinct ? 'distinct ' : '').concat(expression, ", '").concat(record.delimiter.replace(/'/g, "''"), "'").concat(orderSql, ")");
76
+ } else {
77
+ var _record$atoms4;
78
+ sql = "string_agg(".concat(field).concat((_record$atoms4 = record.atoms) !== null && _record$atoms4 !== void 0 && _record$atoms4.some(function (atom) {
79
+ return atom.type === _types.AtomsTypeEnum.OPERATOR && atom.val === ',';
80
+ }) ? '' : ", ','", ")");
81
+ }
82
+ as = 'string_agg';
83
+ break;
64
84
  }
65
85
  var count = 0;
66
86
  prevList.forEach(function (v) {
@@ -82,6 +102,9 @@ var summarizeToSql = exports.summarizeToSql = function summarizeToSql(arr, recor
82
102
  if (condition === '最大值' && v.condition === '最大值') {
83
103
  count++;
84
104
  }
105
+ if (condition === '聚合字符串拼接' && v.condition === '聚合字符串拼接') {
106
+ count++;
107
+ }
85
108
  });
86
109
  as = as + (count ? '_' + (count + 1) : '');
87
110
  return {
@@ -90,9 +113,9 @@ var summarizeToSql = exports.summarizeToSql = function summarizeToSql(arr, recor
90
113
  };
91
114
  };
92
115
  var summarizeByToSql = exports.summarizeByToSql = function summarizeByToSql(record) {
93
- var _record$atoms2;
116
+ var _record$atoms5;
94
117
  var sql = "".concat(record.alias, ".").concat(record.realName || record.name);
95
- if ((_record$atoms2 = record.atoms) !== null && _record$atoms2 !== void 0 && _record$atoms2.length) {
118
+ if ((_record$atoms5 = record.atoms) !== null && _record$atoms5 !== void 0 && _record$atoms5.length) {
96
119
  sql = (0, _transformSql.handleBaseType2Sql)(record.atoms).sql.trim() || sql;
97
120
  }
98
121
  return sql;
@@ -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
  }
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
- group.sql = (0, _helper.summarizeToSql)(v.group, group).sql;
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
- group.sql = (0, _helper.summarizeToSql)(v.group, group).sql;
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
- if (parentPopupLockCountRef.current === 1) {
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
- parentPopupLockCountRef.current = Math.max(0, parentPopupLockCountRef.current - 1);
210
- if (parentPopupLockCountRef.current === 0) {
211
- setParentClosable(true);
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(function () {
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
- _useState4 = _slicedToArray(_useState3, 2),
114
- atoms = _useState4[0],
115
- setAtoms = _useState4[1];
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
- className: 'Sqb-SelectSummarize-formula',
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
- }), _jsx("div", {
255
+ }), _jsxs("div", {
214
256
  className: 'Sqb-SelectSummarize-formula-body',
215
- children: _jsx("div", {
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: 0 16px 16px;
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();
@@ -1,5 +1,10 @@
1
1
  @import './helper.less';
2
2
 
3
+ // Tooltip 动画期间组件库会临时关闭 pointer-events,导致点击穿透到下层按钮。
4
+ .pd-Trigger.pd-Tooltip {
5
+ pointer-events: auto !important;
6
+ }
7
+
3
8
  .visual-box {
4
9
  position: relative;
5
10
  width: 100%;
@@ -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: message || __('metabase.verify'),
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
- title: __(existsError ? 'SqlQueryBuilder.existsErrorAliasAction' : aliasError ? 'SqlQueryBuilder.aliasForRulesAction' : 'SqlQueryBuilder.alias'),
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
- title: __(existsError ? 'SqlQueryBuilder.existsErrorAliasAction' : aliasError ? 'SqlQueryBuilder.aliasForRulesAction' : 'SqlQueryBuilder.alias'),
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', {
@@ -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',
@@ -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': '关闭面板',
@@ -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$atoms2;
109
+ var _record$atoms5;
87
110
  var sql = "".concat(record.alias, ".").concat(record.realName || record.name);
88
- if ((_record$atoms2 = record.atoms) !== null && _record$atoms2 !== void 0 && _record$atoms2.length) {
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;
@@ -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
  }
package/lib/es/utils.js CHANGED
@@ -1231,15 +1231,27 @@ export var changeTableAlias = function changeTableAlias(list, curObj) {
1231
1231
  }
1232
1232
  if (v.type === TypeEnum.summarize) {
1233
1233
  v.group.map(function (group) {
1234
+ var _group$orderBy;
1234
1235
  var groupAtoms = group.atoms;
1236
+ var shouldRefreshSql = false;
1235
1237
  if (groupAtoms && groupAtoms.length > 0) {
1236
1238
  group.atoms = _changeAlias(groupAtoms, {
1237
1239
  uuid: tableUuid,
1238
1240
  alias: alias
1239
1241
  }, AliasType.table);
1240
- group.sql = summarizeToSql(v.group, group).sql;
1242
+ shouldRefreshSql = true;
1241
1243
  } else if (group.tableUuid === tableUuid) {
1242
1244
  group.alias = alias;
1245
+ shouldRefreshSql = true;
1246
+ }
1247
+ if ((_group$orderBy = group.orderBy) !== null && _group$orderBy !== void 0 && _group$orderBy.length) {
1248
+ group.orderBy = _changeAlias(group.orderBy, {
1249
+ uuid: tableUuid,
1250
+ alias: alias
1251
+ }, AliasType.table);
1252
+ shouldRefreshSql = true;
1253
+ }
1254
+ if (shouldRefreshSql) {
1243
1255
  group.sql = summarizeToSql(v.group, group).sql;
1244
1256
  }
1245
1257
  });
@@ -1317,12 +1329,21 @@ export var changeFieldAlias = function changeFieldAlias(list, curObj) {
1317
1329
  if (v.type === TypeEnum.rowLimit) {}
1318
1330
  if (v.type === TypeEnum.summarize) {
1319
1331
  v.group.map(function (group) {
1332
+ var _group$orderBy2;
1320
1333
  var groupAtoms = group.atoms;
1334
+ var shouldRefreshSql = false;
1321
1335
  if (groupAtoms && groupAtoms.length > 0) {
1322
1336
  group.atoms = _changeAlias(groupAtoms, aliasTarget, AliasType.field);
1323
- group.sql = summarizeToSql(v.group, group).sql;
1337
+ shouldRefreshSql = true;
1324
1338
  } else if (isAliasTargetSummarizeRecord(group, aliasTarget)) {
1325
1339
  group.fieldAlias = alias;
1340
+ shouldRefreshSql = true;
1341
+ }
1342
+ if ((_group$orderBy2 = group.orderBy) !== null && _group$orderBy2 !== void 0 && _group$orderBy2.length) {
1343
+ group.orderBy = _changeAlias(group.orderBy, aliasTarget, AliasType.field);
1344
+ shouldRefreshSql = true;
1345
+ }
1346
+ if (shouldRefreshSql) {
1326
1347
  group.sql = summarizeToSql(v.group, group).sql;
1327
1348
  }
1328
1349
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.156",
3
+ "version": "1.0.157-alpha.1",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",