@gingkoo/pandora-metabase 1.0.23 → 1.0.25
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/common/SplitView/index.js +12 -11
- package/lib/cjs/components/dialog/custom-column/expression-editor.js +2 -1
- package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +2 -1
- package/lib/cjs/components/dialog/custom-editor/index.js +2 -1
- package/lib/cjs/components/dialog/expression/index.js +13 -12
- package/lib/cjs/components/dialog/formula/index.d.ts +10 -0
- package/lib/cjs/components/dialog/formula/index.js +242 -0
- package/lib/cjs/components/dialog/formula/index.less +81 -0
- package/lib/cjs/components/dialog/formula/utils.d.ts +7 -0
- package/lib/cjs/components/dialog/formula/utils.js +45 -0
- package/lib/cjs/components/dialog/formula-list/index.d.ts +3 -1
- package/lib/cjs/components/dialog/formula-list/index.js +107 -43
- package/lib/cjs/components/dialog/formula-list/utils.d.ts +14 -1
- package/lib/cjs/components/dialog/formula-list/utils.js +159 -2
- package/lib/cjs/components/dialog/index.d.ts +1 -0
- package/lib/cjs/components/dialog/index.js +9 -2
- package/lib/cjs/components/dialog/select-column/index.js +6 -13
- package/lib/cjs/components/dialog/select-column-multiple/index.js +0 -1
- package/lib/cjs/components/dialog/select-table/index.js +7 -7
- package/lib/cjs/components/icons.js +36 -36
- package/lib/cjs/components/metabase/index.js +6 -6
- package/lib/cjs/components/metabase/index.less +10 -0
- package/lib/cjs/components/modules/components/Wrapper.js +6 -6
- package/lib/cjs/components/modules/custom-column.js +4 -4
- package/lib/cjs/components/modules/enum/filter-enum.d.ts +7 -2
- package/lib/cjs/components/modules/enum/filter-enum.js +8 -2
- package/lib/cjs/components/modules/join-data.js +78 -36
- package/lib/cjs/components/modules/summarize/group-by.js +6 -13
- package/lib/cjs/components/modules/summarize/select-index.js +6 -13
- package/lib/cjs/components/modules/table-data.js +9 -16
- package/lib/cjs/components/popup.js +2 -1
- package/lib/cjs/hooks/patch.js +106 -76
- package/lib/cjs/hooks/use-state.js +100 -65
- package/lib/cjs/index.js +5 -2
- package/lib/cjs/locale/en.js +6 -3
- package/lib/cjs/locale/zh.js +6 -3
- package/lib/cjs/store/helper.d.ts +1 -2
- package/lib/cjs/store/helper.js +1 -76
- package/lib/cjs/store/types.d.ts +36 -2
- package/lib/cjs/store/types.js +3 -0
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +1 -0
- package/lib/cjs/utils.js +16 -2
- package/lib/es/common/SplitView/index.js +10 -10
- package/lib/es/components/dialog/custom-editor/index.js +2 -1
- package/lib/es/components/dialog/expression/index.js +11 -11
- package/lib/es/components/dialog/formula/index.d.ts +10 -0
- package/lib/es/components/dialog/formula/index.js +236 -0
- package/lib/es/components/dialog/formula/index.less +81 -0
- package/lib/es/components/dialog/formula/utils.d.ts +7 -0
- package/lib/es/components/dialog/formula/utils.js +37 -0
- package/lib/es/components/dialog/formula-list/index.d.ts +3 -1
- package/lib/es/components/dialog/formula-list/index.js +104 -40
- package/lib/es/components/dialog/formula-list/utils.d.ts +14 -1
- package/lib/es/components/dialog/formula-list/utils.js +160 -2
- package/lib/es/components/dialog/index.d.ts +1 -0
- package/lib/es/components/dialog/index.js +2 -1
- package/lib/es/components/dialog/select-column/index.js +7 -14
- package/lib/es/components/dialog/select-column-multiple/index.js +0 -1
- package/lib/es/components/dialog/select-table/index.js +7 -7
- package/lib/es/components/icons.js +36 -36
- package/lib/es/components/metabase/index.js +6 -6
- package/lib/es/components/metabase/index.less +10 -0
- package/lib/es/components/modules/components/Wrapper.js +6 -6
- package/lib/es/components/modules/custom-column.js +4 -4
- package/lib/es/components/modules/enum/filter-enum.d.ts +7 -2
- package/lib/es/components/modules/enum/filter-enum.js +8 -2
- package/lib/es/components/modules/join-data.js +78 -36
- package/lib/es/components/modules/summarize/group-by.js +7 -14
- package/lib/es/components/modules/summarize/select-index.js +7 -14
- package/lib/es/components/modules/table-data.js +10 -17
- package/lib/es/hooks/patch.js +105 -75
- package/lib/es/hooks/use-state.js +101 -66
- package/lib/es/index.js +3 -1
- package/lib/es/locale/en.js +6 -3
- package/lib/es/locale/zh.js +6 -3
- package/lib/es/store/helper.d.ts +1 -2
- package/lib/es/store/helper.js +0 -75
- package/lib/es/store/types.d.ts +36 -2
- package/lib/es/store/types.js +3 -0
- package/lib/es/types.d.ts +2 -1
- package/lib/es/types.js +18 -1
- package/lib/es/utils.d.ts +1 -0
- package/lib/es/utils.js +13 -1
- package/package.json +2 -2
- package/lib/cjs/components/dialog/formula-list/enum.d.ts +0 -39
- package/lib/cjs/components/dialog/formula-list/enum.js +0 -123
- package/lib/es/components/dialog/formula-list/enum.d.ts +0 -39
- package/lib/es/components/dialog/formula-list/enum.js +0 -117
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AtomsTypeEnum } from '../../../store/types';
|
|
2
|
+
import { getTemplateItem } from '../formula-list/utils';
|
|
3
|
+
export var getObjTem = function getObjTem(arr) {
|
|
4
|
+
var obj = {};
|
|
5
|
+
arr === null || arr === void 0 || arr.map(function (v) {
|
|
6
|
+
if (v.name) {
|
|
7
|
+
obj[v.name] = v;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return obj;
|
|
11
|
+
};
|
|
12
|
+
export var getTemArgs = function getTemArgs(temArgs) {
|
|
13
|
+
return (temArgs === null || temArgs === void 0 ? void 0 : temArgs.map(function (v) {
|
|
14
|
+
return {
|
|
15
|
+
type: AtomsTypeEnum.COLLECTION,
|
|
16
|
+
quotes: '',
|
|
17
|
+
list: [getTemplateItem(v.type)]
|
|
18
|
+
};
|
|
19
|
+
})) || [];
|
|
20
|
+
};
|
|
21
|
+
export function getParamActions(params, arity) {
|
|
22
|
+
var len = (params === null || params === void 0 ? void 0 : params.length) || 0;
|
|
23
|
+
if (!arity) {
|
|
24
|
+
return {
|
|
25
|
+
canAdd: true,
|
|
26
|
+
canDel: true
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var effectiveMin = 'min' in arity ? arity.min : 'exact' in arity ? arity.exact : 0;
|
|
30
|
+
var effectiveMax = 'max' in arity ? arity.max : 'exact' in arity ? arity.exact // ← 这里!不能是 Infinity
|
|
31
|
+
: Infinity;
|
|
32
|
+
return {
|
|
33
|
+
canAdd: len < effectiveMax,
|
|
34
|
+
// 小于 max 才能加
|
|
35
|
+
canDel: len > effectiveMin // 大于 min 才能删
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -6,8 +6,10 @@ interface PropsType {
|
|
|
6
6
|
value: AtomsItem[];
|
|
7
7
|
data: any;
|
|
8
8
|
exitData?: any;
|
|
9
|
+
onChange?: (atoms: AtomsItem[], quotes: string) => void;
|
|
10
|
+
check?: string;
|
|
9
11
|
isCustom?: boolean;
|
|
10
|
-
|
|
12
|
+
showPreview?: boolean;
|
|
11
13
|
}
|
|
12
14
|
declare const FormulaList: React.ForwardRefExoticComponent<PropsType & React.RefAttributes<unknown>>;
|
|
13
15
|
export default FormulaList;
|
|
@@ -4,51 +4,57 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
|
|
|
4
4
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
5
|
var _excluded = ["notExistsToolbar", "toolbar"];
|
|
6
6
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
-
import {
|
|
7
|
+
import { useState, forwardRef } from 'react';
|
|
8
8
|
import cx from 'classnames';
|
|
9
9
|
// import './index.less';
|
|
10
10
|
import Metabase from '../../../index';
|
|
11
11
|
import { __ } from '../../../locale';
|
|
12
12
|
import isEqual from 'lodash/isEqual';
|
|
13
|
-
import { getTemplate } from './utils';
|
|
14
|
-
import { customTypes, operatorList } from './enum';
|
|
15
13
|
import { AtomsTypeEnum } from '../../../store/types';
|
|
16
14
|
import { ColumnsPopupThemeEnum } from '../../../store/enum';
|
|
17
15
|
import { Select, Input, Modal2, InputNumber } from '@gingkoo/pandora';
|
|
18
16
|
import cloneDeep from 'lodash/cloneDeep';
|
|
19
|
-
import { getTemItem } from '../../../store/helper';
|
|
20
17
|
import { buildSqlQuery } from '../../../utils';
|
|
18
|
+
import Formula from '../formula';
|
|
21
19
|
import { AddIcon, CloseIcon } from '../../icons';
|
|
22
20
|
import { Expression, SelectColumnMultiple } from '../../dialog';
|
|
21
|
+
import { customTypes, operatorList, insertTemplateAt, getTemplateItem } from './utils';
|
|
23
22
|
import SelectList from '../../dialog/select-list';
|
|
24
23
|
import arrow from './arrow.svg';
|
|
25
|
-
import { useStore } from '../../../hooks/use-provider';
|
|
24
|
+
import { useStore, Provider } from '../../../hooks/use-provider';
|
|
26
25
|
var FormulaList = forwardRef(function (props, ref) {
|
|
27
26
|
var value = props.value,
|
|
28
27
|
data = props.data,
|
|
29
|
-
isCustom = props.isCustom,
|
|
30
28
|
exitData = props.exitData,
|
|
31
29
|
onChange = props.onChange,
|
|
32
30
|
_props$customTypes = props.customTypes,
|
|
33
31
|
_customTypes = _props$customTypes === void 0 ? customTypes : _props$customTypes,
|
|
34
32
|
_props$operatorList = props.operatorList,
|
|
35
|
-
_operatorList = _props$operatorList === void 0 ? operatorList : _props$operatorList
|
|
36
|
-
|
|
33
|
+
_operatorList = _props$operatorList === void 0 ? operatorList : _props$operatorList,
|
|
34
|
+
_props$isCustom = props.isCustom,
|
|
35
|
+
isCustom = _props$isCustom === void 0 ? false : _props$isCustom,
|
|
36
|
+
_props$showPreview = props.showPreview,
|
|
37
|
+
showPreview = _props$showPreview === void 0 ? true : _props$showPreview,
|
|
38
|
+
check = props.check;
|
|
39
|
+
var caseList = value || [];
|
|
40
|
+
var setCaseList = function setCaseList(data) {
|
|
41
|
+
var quotes = data.map(function (v, i) {
|
|
42
|
+
if (v !== null && v !== void 0 && v.quotes) {
|
|
43
|
+
return v === null || v === void 0 ? void 0 : v.quotes;
|
|
44
|
+
} else if (v !== null && v !== void 0 && v.fieldName) {
|
|
45
|
+
return v === null || v === void 0 ? void 0 : v.fieldName;
|
|
46
|
+
} else {
|
|
47
|
+
return v.val;
|
|
48
|
+
}
|
|
49
|
+
}).join(' ');
|
|
50
|
+
onChange === null || onChange === void 0 || onChange(data, quotes);
|
|
51
|
+
};
|
|
52
|
+
var _useState = useState(-1),
|
|
37
53
|
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// useEffect(() => {
|
|
41
|
-
// setCaseList(value);
|
|
42
|
-
// }, [value]);
|
|
43
|
-
var _useState3 = useState(-1),
|
|
44
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
45
|
-
ind = _useState4[0],
|
|
46
|
-
setInd = _useState4[1];
|
|
54
|
+
ind = _useState2[0],
|
|
55
|
+
setInd = _useState2[1];
|
|
47
56
|
var store = useStore();
|
|
48
57
|
var filterCustomType = store.filterCustomType;
|
|
49
|
-
useEffect(function () {
|
|
50
|
-
onChange === null || onChange === void 0 || onChange(caseList);
|
|
51
|
-
}, [caseList]);
|
|
52
58
|
function closePopup() {
|
|
53
59
|
store.setPopup({
|
|
54
60
|
visible: false
|
|
@@ -79,7 +85,7 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
79
85
|
var _caseList = caseList.slice();
|
|
80
86
|
var oldType = _caseList[i].val;
|
|
81
87
|
_caseList[i].val = val;
|
|
82
|
-
_caseList =
|
|
88
|
+
_caseList = insertTemplateAt(oldType, val, _caseList, i);
|
|
83
89
|
setCaseList(_caseList);
|
|
84
90
|
};
|
|
85
91
|
// 表达式
|
|
@@ -89,6 +95,7 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
89
95
|
node: e.currentTarget,
|
|
90
96
|
container: ref === null || ref === void 0 ? void 0 : ref.current,
|
|
91
97
|
content: _jsx(Expression, {
|
|
98
|
+
isCustom: isCustom,
|
|
92
99
|
filterCustomType: filterCustomType,
|
|
93
100
|
data: data,
|
|
94
101
|
container: ref === null || ref === void 0 ? void 0 : ref.current,
|
|
@@ -113,7 +120,7 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
113
120
|
// 添加
|
|
114
121
|
var addOperator = function addOperator(type, index, position) {
|
|
115
122
|
var _caseList = caseList.slice() || [];
|
|
116
|
-
var temItem =
|
|
123
|
+
var temItem = getTemplateItem(type);
|
|
117
124
|
if (position === 'add') {
|
|
118
125
|
_caseList.push(temItem);
|
|
119
126
|
} else if (position === 'before') {
|
|
@@ -163,7 +170,7 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
163
170
|
type: caseList[i].type
|
|
164
171
|
};
|
|
165
172
|
caseList[i] = expression;
|
|
166
|
-
onChange === null || onChange === void 0 || onChange(caseList);
|
|
173
|
+
onChange === null || onChange === void 0 || onChange(caseList, '');
|
|
167
174
|
setCaseList(_toConsumableArray(caseList));
|
|
168
175
|
o.close();
|
|
169
176
|
} catch (e) {
|
|
@@ -195,6 +202,33 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
195
202
|
})
|
|
196
203
|
});
|
|
197
204
|
}
|
|
205
|
+
// 函数弹窗
|
|
206
|
+
var showFunction = function showFunction(e, i) {
|
|
207
|
+
var _value = caseList[i];
|
|
208
|
+
var o = Modal2.openModal({
|
|
209
|
+
title: __('customColumn.formula'),
|
|
210
|
+
transparentMask: true,
|
|
211
|
+
content: _jsx(_Fragment, {
|
|
212
|
+
children: _jsx(Provider, {
|
|
213
|
+
value: store,
|
|
214
|
+
children: _jsx(Formula, {
|
|
215
|
+
data: data,
|
|
216
|
+
value: _value,
|
|
217
|
+
onCancel: function onCancel() {
|
|
218
|
+
o.close();
|
|
219
|
+
},
|
|
220
|
+
onOk: function onOk(data) {
|
|
221
|
+
var _caseList = caseList.slice();
|
|
222
|
+
_caseList[i] = data;
|
|
223
|
+
setCaseList(_caseList);
|
|
224
|
+
o.close();
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
}),
|
|
229
|
+
onClose: function onClose() {}
|
|
230
|
+
});
|
|
231
|
+
};
|
|
198
232
|
// 分段
|
|
199
233
|
var itemDom = function itemDom(v, index) {
|
|
200
234
|
var type = v.type;
|
|
@@ -312,14 +346,22 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
312
346
|
});
|
|
313
347
|
} else if (type === AtomsTypeEnum.CONSTANT) {
|
|
314
348
|
//常量
|
|
315
|
-
return
|
|
349
|
+
return _jsxs("div", {
|
|
316
350
|
className: cx("Sqb-TableName", {
|
|
317
351
|
notSelected: !v.val
|
|
318
352
|
}),
|
|
319
353
|
"v-index": index,
|
|
320
354
|
"v-val": v.val,
|
|
321
355
|
onClick: selectConstant,
|
|
322
|
-
children: v.val ? v.val : __('SqlQueryBuilder.pickConstant')
|
|
356
|
+
children: [v.val ? v.val : __('SqlQueryBuilder.pickConstant'), _jsx("span", {
|
|
357
|
+
style: {
|
|
358
|
+
fontSize: 0
|
|
359
|
+
},
|
|
360
|
+
onClick: function onClick(e) {
|
|
361
|
+
return handleDel(e, index);
|
|
362
|
+
},
|
|
363
|
+
children: _jsx(CloseIcon, {})
|
|
364
|
+
})]
|
|
323
365
|
}, index);
|
|
324
366
|
} else if (type === AtomsTypeEnum.EXPRESSION) {
|
|
325
367
|
// 表达式
|
|
@@ -330,7 +372,7 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
330
372
|
onClick: function onClick(e) {
|
|
331
373
|
return handleExpression(e, index, v);
|
|
332
374
|
},
|
|
333
|
-
children: [
|
|
375
|
+
children: [v.quotes ? v.quotes : __('customColumn.selectExpression'), _jsx("span", {
|
|
334
376
|
style: {
|
|
335
377
|
fontSize: 0
|
|
336
378
|
},
|
|
@@ -340,6 +382,23 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
340
382
|
children: _jsx(CloseIcon, {})
|
|
341
383
|
})]
|
|
342
384
|
});
|
|
385
|
+
} else if (type === AtomsTypeEnum.FORMULA) {
|
|
386
|
+
// 公式
|
|
387
|
+
return _jsxs("div", {
|
|
388
|
+
className: "Sqb-TableName gray-name",
|
|
389
|
+
onClick: function onClick(e) {
|
|
390
|
+
return showFunction(e, index);
|
|
391
|
+
},
|
|
392
|
+
children: [v.quotes ? v.quotes : __('customColumn.selectFormula'), _jsx("span", {
|
|
393
|
+
style: {
|
|
394
|
+
fontSize: 0
|
|
395
|
+
},
|
|
396
|
+
onClick: function onClick(e) {
|
|
397
|
+
return handleDel(e, index);
|
|
398
|
+
},
|
|
399
|
+
children: _jsx(CloseIcon, {})
|
|
400
|
+
})]
|
|
401
|
+
}, index);
|
|
343
402
|
} else {
|
|
344
403
|
return _jsx(Select, {
|
|
345
404
|
triggerProps: {
|
|
@@ -374,8 +433,8 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
374
433
|
});
|
|
375
434
|
}
|
|
376
435
|
};
|
|
377
|
-
return
|
|
378
|
-
children:
|
|
436
|
+
return _jsx(_Fragment, {
|
|
437
|
+
children: _jsxs("div", {
|
|
379
438
|
className: "Sqb-NotebookCell",
|
|
380
439
|
children: [caseList === null || caseList === void 0 ? void 0 : caseList.map(function (v, i) {
|
|
381
440
|
return _jsxs("div", {
|
|
@@ -480,19 +539,24 @@ var FormulaList = forwardRef(function (props, ref) {
|
|
|
480
539
|
children: option.label
|
|
481
540
|
}, index + '' + ind);
|
|
482
541
|
})
|
|
542
|
+
}), showPreview && _jsxs("p", {
|
|
543
|
+
className: "mb-2 font-bold uppercase tracking-wider",
|
|
544
|
+
style: {
|
|
545
|
+
fontSize: 12,
|
|
546
|
+
color: '#949aab',
|
|
547
|
+
width: '100%'
|
|
548
|
+
},
|
|
549
|
+
children: ["\u9884\u89C8\uFF1A", caseList.map(function (v, i) {
|
|
550
|
+
if (v !== null && v !== void 0 && v.quotes) {
|
|
551
|
+
return v === null || v === void 0 ? void 0 : v.quotes;
|
|
552
|
+
} else if (v !== null && v !== void 0 && v.fieldName) {
|
|
553
|
+
return v === null || v === void 0 ? void 0 : v.fieldName;
|
|
554
|
+
} else {
|
|
555
|
+
return v.val;
|
|
556
|
+
}
|
|
557
|
+
}).join(' ')]
|
|
483
558
|
})]
|
|
484
|
-
})
|
|
485
|
-
className: 'Sqb-NotebookCell-preview',
|
|
486
|
-
children: ["\u9884\u89C8\uFF1A", caseList.map(function (v, i) {
|
|
487
|
-
if (v !== null && v !== void 0 && v.quotes) {
|
|
488
|
-
return v === null || v === void 0 ? void 0 : v.quotes;
|
|
489
|
-
} else if (v !== null && v !== void 0 && v.fieldName) {
|
|
490
|
-
return v === null || v === void 0 ? void 0 : v.fieldName;
|
|
491
|
-
} else {
|
|
492
|
-
return v.val;
|
|
493
|
-
}
|
|
494
|
-
}).join(' ')]
|
|
495
|
-
})]
|
|
559
|
+
})
|
|
496
560
|
});
|
|
497
561
|
});
|
|
498
562
|
export default FormulaList;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AtomsTypeEnum, AtomsItem } from '../../../store/types';
|
|
1
2
|
/**
|
|
2
3
|
*
|
|
3
4
|
* @param type 当前选择的类型
|
|
@@ -5,4 +6,16 @@
|
|
|
5
6
|
* @param index 需要讲模版插入的位置
|
|
6
7
|
* @returns
|
|
7
8
|
*/
|
|
8
|
-
export declare const
|
|
9
|
+
export declare const insertTemplateAt: (oldType: string, type: string, list: any[], index: number) => any[];
|
|
10
|
+
export declare const operatorList: string[];
|
|
11
|
+
export declare const customTypes: ({
|
|
12
|
+
value: AtomsTypeEnum;
|
|
13
|
+
label: any;
|
|
14
|
+
children?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
value: AtomsTypeEnum;
|
|
17
|
+
label: any;
|
|
18
|
+
children: string[];
|
|
19
|
+
})[];
|
|
20
|
+
export declare const getTemplateItem: (type: AtomsTypeEnum) => AtomsItem;
|
|
21
|
+
export declare const isOk: (rhsVal: AtomsItem[]) => boolean;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import { __ } from '../../../locale';
|
|
2
3
|
import { AtomsTypeEnum } from '../../../store/types';
|
|
4
|
+
// import { FUNCTION_TEMPLATES } from '../function/utils';
|
|
3
5
|
/**
|
|
4
6
|
*
|
|
5
7
|
* @param type 当前选择的类型
|
|
@@ -7,7 +9,7 @@ import { AtomsTypeEnum } from '../../../store/types';
|
|
|
7
9
|
* @param index 需要讲模版插入的位置
|
|
8
10
|
* @returns
|
|
9
11
|
*/
|
|
10
|
-
export var
|
|
12
|
+
export var insertTemplateAt = function insertTemplateAt(oldType, type, list, index) {
|
|
11
13
|
var temList = [];
|
|
12
14
|
var needChange = ['RANK()', 'DENSE_RANK()', 'ROW_NUMBER()', 'when', 'case', 'then'].includes(oldType);
|
|
13
15
|
// 只改变类型不需要插入模版
|
|
@@ -116,4 +118,160 @@ export var getTemplate = function getTemplate(oldType, type, list, index) {
|
|
|
116
118
|
}
|
|
117
119
|
list.splice.apply(list, [index + 1, 0].concat(_toConsumableArray(temList)));
|
|
118
120
|
return list;
|
|
119
|
-
};
|
|
121
|
+
};
|
|
122
|
+
export var operatorList = ['and', 'or', '(', ')', ',', '+', '-', '*', '/', '!=', '<=', '>=', '<', '>', '=', 'case', 'when', 'then', 'else', 'end', 'DESC', 'ASC', 'OVER', 'PARTITION BY', 'ORDER BY', 'RANK()', 'DENSE_RANK()', 'ROW_NUMBER()'];
|
|
123
|
+
export var customTypes = [
|
|
124
|
+
// 字段
|
|
125
|
+
{
|
|
126
|
+
value: AtomsTypeEnum.FIELD,
|
|
127
|
+
label: __('customColumn.field')
|
|
128
|
+
},
|
|
129
|
+
// 表达式
|
|
130
|
+
{
|
|
131
|
+
value: AtomsTypeEnum.EXPRESSION,
|
|
132
|
+
label: __('customColumn.expression')
|
|
133
|
+
},
|
|
134
|
+
// 输入框
|
|
135
|
+
{
|
|
136
|
+
value: AtomsTypeEnum.INPUT_STRING,
|
|
137
|
+
label: __('customColumn.input')
|
|
138
|
+
},
|
|
139
|
+
// 数字输入框
|
|
140
|
+
{
|
|
141
|
+
value: AtomsTypeEnum.INPUT_NUMBER,
|
|
142
|
+
label: __('customColumn.numberInput')
|
|
143
|
+
},
|
|
144
|
+
// 数字输入框
|
|
145
|
+
{
|
|
146
|
+
value: AtomsTypeEnum.CONSTANT,
|
|
147
|
+
label: __('customColumn.constant')
|
|
148
|
+
},
|
|
149
|
+
// 连接符
|
|
150
|
+
{
|
|
151
|
+
value: AtomsTypeEnum.OPERATOR,
|
|
152
|
+
label: __('customColumn.operator'),
|
|
153
|
+
children: operatorList
|
|
154
|
+
},
|
|
155
|
+
// 函数
|
|
156
|
+
{
|
|
157
|
+
value: AtomsTypeEnum.FORMULA,
|
|
158
|
+
label: __('customColumn.formula'),
|
|
159
|
+
children: operatorList
|
|
160
|
+
}];
|
|
161
|
+
export var getTemplateItem = function getTemplateItem(type) {
|
|
162
|
+
var temItem;
|
|
163
|
+
// 字段
|
|
164
|
+
if (type === AtomsTypeEnum.FIELD) {
|
|
165
|
+
temItem = {
|
|
166
|
+
fieldName: '',
|
|
167
|
+
// 字段名
|
|
168
|
+
fieldNameZh: '',
|
|
169
|
+
// 字段中文名
|
|
170
|
+
fieldAlias: '',
|
|
171
|
+
// 别名
|
|
172
|
+
fieldUuid: '',
|
|
173
|
+
// uuid
|
|
174
|
+
fieldId: '',
|
|
175
|
+
// 字段id
|
|
176
|
+
// quotes?: string; // 字段展示的 不知道有没有用
|
|
177
|
+
tableName: '',
|
|
178
|
+
// 表名
|
|
179
|
+
tableNameZh: '',
|
|
180
|
+
tableId: '',
|
|
181
|
+
// 表名
|
|
182
|
+
tableAlias: '',
|
|
183
|
+
// 别名
|
|
184
|
+
tableUuid: '',
|
|
185
|
+
// 表唯一标识
|
|
186
|
+
datasourceName: '',
|
|
187
|
+
// 数据源名
|
|
188
|
+
datasourceId: '',
|
|
189
|
+
// 数据源id
|
|
190
|
+
type: AtomsTypeEnum.FIELD
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
// 表达式
|
|
194
|
+
else if (type === AtomsTypeEnum.EXPRESSION || type === AtomsTypeEnum.JOIN_DEFAULT) {
|
|
195
|
+
return {
|
|
196
|
+
lhs: [],
|
|
197
|
+
rhs: [],
|
|
198
|
+
condition: '',
|
|
199
|
+
quotes: '',
|
|
200
|
+
type: type
|
|
201
|
+
};
|
|
202
|
+
} else if (type === AtomsTypeEnum.EXISTS || type === AtomsTypeEnum.NOT_EXISTS) {
|
|
203
|
+
return {
|
|
204
|
+
quotes: '',
|
|
205
|
+
// 展示用户看的 组装的文字
|
|
206
|
+
notExists: [],
|
|
207
|
+
type: type
|
|
208
|
+
};
|
|
209
|
+
} else if (type === AtomsTypeEnum.UNKNOWN) {
|
|
210
|
+
return {
|
|
211
|
+
// quotes: '', // 展示用户看的 组装的文字
|
|
212
|
+
// notExists: [],
|
|
213
|
+
val: '',
|
|
214
|
+
type: type
|
|
215
|
+
};
|
|
216
|
+
} else if (type === AtomsTypeEnum.INPUT_NUMBER) {
|
|
217
|
+
return {
|
|
218
|
+
val: 0,
|
|
219
|
+
type: type
|
|
220
|
+
};
|
|
221
|
+
} else if (type === AtomsTypeEnum.INPUT_NUMBER_LIST || type === AtomsTypeEnum.INPUT_STRING_LIST) {
|
|
222
|
+
temItem = {
|
|
223
|
+
val: [],
|
|
224
|
+
type: type
|
|
225
|
+
};
|
|
226
|
+
} else if (type === AtomsTypeEnum.FORMULA) {
|
|
227
|
+
temItem = {
|
|
228
|
+
args: [],
|
|
229
|
+
// params: FUNCTION_TEMPLATES?.[type]?.params || [],
|
|
230
|
+
// arity: FUNCTION_TEMPLATES?.[type]?.arity || {},
|
|
231
|
+
name: '',
|
|
232
|
+
quotes: '',
|
|
233
|
+
type: type
|
|
234
|
+
};
|
|
235
|
+
} else if (type === AtomsTypeEnum.COLLECTION) {
|
|
236
|
+
return {
|
|
237
|
+
list: [],
|
|
238
|
+
quotes: '',
|
|
239
|
+
type: type
|
|
240
|
+
};
|
|
241
|
+
} else {
|
|
242
|
+
// 其他
|
|
243
|
+
temItem = {
|
|
244
|
+
val: '',
|
|
245
|
+
type: type
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return temItem;
|
|
249
|
+
};
|
|
250
|
+
var _isOk = function isOk(rhsVal) {
|
|
251
|
+
return rhsVal.every(function (v) {
|
|
252
|
+
if (v.type === AtomsTypeEnum.UNKNOWN) {
|
|
253
|
+
return false;
|
|
254
|
+
} else if (v.type === AtomsTypeEnum.JOIN_DEFAULT) {
|
|
255
|
+
// 这个情况应该是不存在的
|
|
256
|
+
return true; // 或者根据业务逻辑决定是否算“有效”
|
|
257
|
+
} else if (v.type === AtomsTypeEnum.FIELD) {
|
|
258
|
+
return Boolean(v.fieldName); // 确保 fieldName 存在且非空
|
|
259
|
+
} else if (v.type === AtomsTypeEnum.EXPRESSION || v.type === AtomsTypeEnum.EXISTS || v.type === AtomsTypeEnum.NOT_EXISTS) {
|
|
260
|
+
return Boolean(v.quotes); // 确保 quotes 存在
|
|
261
|
+
} else if (v.type === AtomsTypeEnum.INPUT_STRING_LIST) {
|
|
262
|
+
return Array.isArray(v.val) && v.val.every(function (vv) {
|
|
263
|
+
return Boolean(vv);
|
|
264
|
+
});
|
|
265
|
+
} else if (v.type === AtomsTypeEnum.COLLECTION) {
|
|
266
|
+
return _isOk(v.list || []);
|
|
267
|
+
} else if (v.type === AtomsTypeEnum.FORMULA) {
|
|
268
|
+
if (!v.quotes) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
return _isOk(v.args || []);
|
|
272
|
+
} else {
|
|
273
|
+
return Boolean(v.val); // 兜底,确保 val 存在
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
export { _isOk as isOk };
|
|
@@ -8,3 +8,4 @@ export { default as SelectTable } from './select-table/index';
|
|
|
8
8
|
export { default as SelectPermissionTable } from './select-permission-table/index';
|
|
9
9
|
export { default as FormulaList } from './formula-list/index';
|
|
10
10
|
export { default as Expression } from './expression/index';
|
|
11
|
+
export { getTemplateItem } from './formula-list/utils';
|
|
@@ -7,4 +7,5 @@ export { default as SelectJoin } from './select-join/index';
|
|
|
7
7
|
export { default as SelectTable } from './select-table/index';
|
|
8
8
|
export { default as SelectPermissionTable } from './select-permission-table/index';
|
|
9
9
|
export { default as FormulaList } from './formula-list/index'; // 自定义公式列表
|
|
10
|
-
export { default as Expression } from './expression/index'; // 表达式编辑器
|
|
10
|
+
export { default as Expression } from './expression/index'; // 表达式编辑器
|
|
11
|
+
export { getTemplateItem } from './formula-list/utils'; // 表达式编辑器
|
|
@@ -18,7 +18,7 @@ import { __ } from '../../../locale';
|
|
|
18
18
|
import { NotSelectIcon, SelectIcon } from '../../icons';
|
|
19
19
|
import { useStore } from '../../../hooks/use-provider';
|
|
20
20
|
import { uuidv4 } from '../../../utils/helper';
|
|
21
|
-
import { changeFieldAlias } from '../../../utils';
|
|
21
|
+
import { changeFieldAlias, isValidSQLAlias } from '../../../utils';
|
|
22
22
|
import { SearchIcon } from '../../icons';
|
|
23
23
|
// 选择表中参数
|
|
24
24
|
var SelectColumn = function SelectColumn(_ref) {
|
|
@@ -97,23 +97,16 @@ var SelectColumn = function SelectColumn(_ref) {
|
|
|
97
97
|
onOk: function () {
|
|
98
98
|
var _onOk = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
99
99
|
var newColumns, newMetaList;
|
|
100
|
-
return _regeneratorRuntime.wrap(function (_context) {
|
|
100
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
101
101
|
while (1) switch (_context.prev = _context.next) {
|
|
102
102
|
case 0:
|
|
103
|
-
if (fieldAlias) {
|
|
104
|
-
_context.next =
|
|
103
|
+
if (isValidSQLAlias(fieldAlias)) {
|
|
104
|
+
_context.next = 3;
|
|
105
105
|
break;
|
|
106
106
|
}
|
|
107
|
-
Toast.warning(__('SqlQueryBuilder.
|
|
107
|
+
Toast.warning(__('SqlQueryBuilder.aliasForRules'));
|
|
108
108
|
return _context.abrupt("return", false);
|
|
109
|
-
case
|
|
110
|
-
if (!(fieldAlias.length > 30)) {
|
|
111
|
-
_context.next = 2;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
Toast.warning('别名长度不能超过30');
|
|
115
|
-
return _context.abrupt("return", false);
|
|
116
|
-
case 2:
|
|
109
|
+
case 3:
|
|
117
110
|
newColumns = cloneDeep(columns);
|
|
118
111
|
newMetaList = store.metaList[groupIndex].list.slice();
|
|
119
112
|
newColumns[i].fieldAlias = fieldAlias;
|
|
@@ -124,7 +117,7 @@ var SelectColumn = function SelectColumn(_ref) {
|
|
|
124
117
|
setTimeout(function () {
|
|
125
118
|
store.setClosable(true);
|
|
126
119
|
}, 0);
|
|
127
|
-
case
|
|
120
|
+
case 11:
|
|
128
121
|
case "end":
|
|
129
122
|
return _context.stop();
|
|
130
123
|
}
|
|
@@ -269,7 +269,6 @@ var SelectJoinColumn = function SelectJoinColumn(_ref) {
|
|
|
269
269
|
if (isSummarize) {
|
|
270
270
|
// console.log(v, 'v');
|
|
271
271
|
}
|
|
272
|
-
console.log('🚀 ~ SelectJoinColumn ~ tableItem:', tableItem);
|
|
273
272
|
changeValue(tableUuid, {
|
|
274
273
|
tableName: tableItem.name,
|
|
275
274
|
tableId: tableItem.id,
|
|
@@ -43,9 +43,9 @@ var SelectTable = function SelectTable(_ref) {
|
|
|
43
43
|
originList = _useState8[0],
|
|
44
44
|
setOriginList = _useState8[1];
|
|
45
45
|
var _useState9 = useState(value),
|
|
46
|
-
|
|
47
|
-
val =
|
|
48
|
-
setVal =
|
|
46
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
47
|
+
val = _useState10[0],
|
|
48
|
+
setVal = _useState10[1];
|
|
49
49
|
useEffect(function () {
|
|
50
50
|
if (value.datasourceId) {
|
|
51
51
|
getTables(value.datasourceId);
|
|
@@ -57,18 +57,18 @@ var SelectTable = function SelectTable(_ref) {
|
|
|
57
57
|
function _getTables() {
|
|
58
58
|
_getTables = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(datasourceId) {
|
|
59
59
|
var tables;
|
|
60
|
-
return _regeneratorRuntime.wrap(function (_context) {
|
|
60
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
61
61
|
while (1) switch (_context.prev = _context.next) {
|
|
62
62
|
case 0:
|
|
63
63
|
setLoading(true);
|
|
64
|
-
_context.next =
|
|
64
|
+
_context.next = 3;
|
|
65
65
|
return store.fetchDataset(datasourceId);
|
|
66
|
-
case
|
|
66
|
+
case 3:
|
|
67
67
|
tables = _context.sent;
|
|
68
68
|
setLoading(false);
|
|
69
69
|
setList(tables);
|
|
70
70
|
setOriginList(tables);
|
|
71
|
-
case
|
|
71
|
+
case 7:
|
|
72
72
|
case "end":
|
|
73
73
|
return _context.stop();
|
|
74
74
|
}
|