@gingkoo/pandora-metabase 1.0.157-alpha.4 → 1.0.157-alpha.6
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/custom-editor/index.js +56 -3
- package/lib/cjs/components/dialog/expression/index.js +14 -2
- package/lib/cjs/components/dialog/formula/index.js +3 -1
- package/lib/cjs/components/dialog/formula/utils.d.ts +1 -0
- package/lib/cjs/components/dialog/formula/utils.js +20 -2
- package/lib/cjs/components/dialog/formula-list/index.d.ts +1 -0
- package/lib/cjs/components/dialog/formula-list/index.js +309 -134
- package/lib/cjs/components/dialog/formula-list/index.less +52 -0
- package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +2 -1
- package/lib/cjs/components/dialog/select-column-multiple/index.js +4 -2
- package/lib/cjs/index.d.ts +3 -2
- package/lib/cjs/index.js +7 -0
- package/lib/cjs/locale/en.js +4 -0
- package/lib/cjs/locale/zh.js +4 -0
- package/lib/cjs/types.d.ts +10 -1
- package/lib/es/components/dialog/custom-editor/index.js +56 -3
- package/lib/es/components/dialog/expression/index.js +14 -2
- package/lib/es/components/dialog/formula/index.js +4 -2
- package/lib/es/components/dialog/formula/utils.d.ts +1 -0
- package/lib/es/components/dialog/formula/utils.js +18 -1
- package/lib/es/components/dialog/formula-list/index.d.ts +1 -0
- package/lib/es/components/dialog/formula-list/index.js +307 -132
- package/lib/es/components/dialog/formula-list/index.less +52 -0
- package/lib/es/components/dialog/select-column-multiple/index.d.ts +2 -1
- package/lib/es/components/dialog/select-column-multiple/index.js +4 -2
- package/lib/es/index.d.ts +3 -2
- package/lib/es/index.js +3 -1
- package/lib/es/locale/en.js +4 -0
- package/lib/es/locale/zh.js +4 -0
- package/lib/es/types.d.ts +10 -1
- package/package.json +1 -1
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
p {
|
|
13
13
|
margin: 0;
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
.Sqb-FormulaAddSqlAction {
|
|
17
|
+
order: 999;
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
.isSqlError {
|
|
@@ -39,6 +43,54 @@
|
|
|
39
43
|
// }
|
|
40
44
|
}
|
|
41
45
|
|
|
46
|
+
.Sqb-FormulaSqlImport {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex: 1 1 auto;
|
|
49
|
+
flex-direction: column;
|
|
50
|
+
gap: 16px;
|
|
51
|
+
width: 100%;
|
|
52
|
+
height: 100%;
|
|
53
|
+
min-height: 0;
|
|
54
|
+
box-sizing: border-box;
|
|
55
|
+
padding: 12px;
|
|
56
|
+
|
|
57
|
+
&-editor {
|
|
58
|
+
flex: 1 1 auto;
|
|
59
|
+
width: 100%;
|
|
60
|
+
min-height: 0;
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
border: 1px solid rgba(83, 92, 112, 0.14);
|
|
63
|
+
border-radius: 6px;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&-actions {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex: 0 0 auto;
|
|
69
|
+
justify-content: flex-end;
|
|
70
|
+
gap: 8px;
|
|
71
|
+
padding-top: 12px;
|
|
72
|
+
border-top: 1px solid rgba(83, 92, 112, 0.12);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&-actions .pd-Button {
|
|
76
|
+
min-width: 72px;
|
|
77
|
+
height: 30px;
|
|
78
|
+
border-radius: 6px;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.Sqb-FormulaSqlImportModal .pd-Viewer-modal-main {
|
|
83
|
+
display: flex;
|
|
84
|
+
min-height: 0;
|
|
85
|
+
overflow: hidden;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.Sqb-FormulaSqlImport-editor > .pd-Editor,
|
|
89
|
+
.Sqb-FormulaSqlImport-editor .pd-Editor-main,
|
|
90
|
+
.Sqb-FormulaSqlImport-editor .CodeMirror {
|
|
91
|
+
height: 100%;
|
|
92
|
+
}
|
|
93
|
+
|
|
42
94
|
.Sqb-Filter-item {
|
|
43
95
|
--sqb-item-shell-margin-x: 14px;
|
|
44
96
|
--sqb-item-gap-x: 8px;
|
|
@@ -34,6 +34,7 @@ interface PropsType {
|
|
|
34
34
|
theme: ColumnsPopupThemeEnum;
|
|
35
35
|
isGroup?: boolean;
|
|
36
36
|
onSelect?: (fields: AtomsField[], quotes: string) => void;
|
|
37
|
+
onValueSync?: (fields: AtomsField[], quotes: string) => void;
|
|
37
38
|
onGroup?: (record: ColumnType & ColumnGroupType & {
|
|
38
39
|
realName?: string;
|
|
39
40
|
}) => void;
|
|
@@ -44,5 +45,5 @@ interface PropsType {
|
|
|
44
45
|
onNextStep?: () => void;
|
|
45
46
|
readonly?: boolean;
|
|
46
47
|
}
|
|
47
|
-
declare const SelectJoinColumn: ({ data, value: _value, theme, onSelect, isGroup, onGroup, didUpdate, multiple, showNextBtn, nextBtnText, onNextStep, readonly, }: PropsType) => React.JSX.Element;
|
|
48
|
+
declare const SelectJoinColumn: ({ data, value: _value, theme, onSelect, onValueSync, isGroup, onGroup, didUpdate, multiple, showNextBtn, nextBtnText, onNextStep, readonly, }: PropsType) => React.JSX.Element;
|
|
48
49
|
export default SelectJoinColumn;
|
|
@@ -46,6 +46,7 @@ var SelectJoinColumn = function SelectJoinColumn(_ref) {
|
|
|
46
46
|
_ref$theme = _ref.theme,
|
|
47
47
|
theme = _ref$theme === void 0 ? _enum.ColumnsPopupThemeEnum.skyBlue : _ref$theme,
|
|
48
48
|
onSelect = _ref.onSelect,
|
|
49
|
+
onValueSync = _ref.onValueSync,
|
|
49
50
|
isGroup = _ref.isGroup,
|
|
50
51
|
onGroup = _ref.onGroup,
|
|
51
52
|
didUpdate = _ref.didUpdate,
|
|
@@ -271,9 +272,10 @@ var SelectJoinColumn = function SelectJoinColumn(_ref) {
|
|
|
271
272
|
});
|
|
272
273
|
setValue(syncedValue);
|
|
273
274
|
if (!readonly && !(0, _isEqual["default"])(syncedValue, _value || [])) {
|
|
274
|
-
|
|
275
|
+
var _ref2;
|
|
276
|
+
(_ref2 = onValueSync || onSelect) === null || _ref2 === void 0 || _ref2(syncedValue, getQuotes(syncedValue));
|
|
275
277
|
}
|
|
276
|
-
}, [data, _value]);
|
|
278
|
+
}, [data, _value, onValueSync]);
|
|
277
279
|
var changeValue = function changeValue(tableUuid, val) {
|
|
278
280
|
if (readonly) return;
|
|
279
281
|
if (!multiple) {
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import './locale/en';
|
|
3
3
|
import './locale/zh';
|
|
4
|
-
import type { MetabaseProps, SqlVisionBuilderRef, DatasourceType, MetabaseRightClickMenuItem, MetabaseRightClickMenuClickParams } from './types';
|
|
4
|
+
import type { MetabaseProps, SqlVisionBuilderRef, DatasourceType, MetabaseRightClickMenuItem, MetabaseRightClickMenuClickParams, FormulaSqlParseParams, FormulaSqlParseResult } from './types';
|
|
5
5
|
import type { MetaListType, ToolbarType } from './store/types';
|
|
6
|
+
import { AtomsTypeEnum } from './store/types';
|
|
6
7
|
declare const SqlVisionBuilder: React.ForwardRefExoticComponent<MetabaseProps & React.RefAttributes<SqlVisionBuilderRef>>;
|
|
7
8
|
export default SqlVisionBuilder;
|
|
8
|
-
export { MetabaseProps, DatasourceType, MetaListType, ToolbarType, SqlVisionBuilderRef, MetabaseRightClickMenuItem, MetabaseRightClickMenuClickParams, };
|
|
9
|
+
export { MetabaseProps, DatasourceType, MetaListType, ToolbarType, SqlVisionBuilderRef, MetabaseRightClickMenuItem, MetabaseRightClickMenuClickParams, FormulaSqlParseParams, FormulaSqlParseResult, AtomsTypeEnum, };
|
package/lib/cjs/index.js
CHANGED
|
@@ -5,6 +5,12 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
Object.defineProperty(exports, "AtomsTypeEnum", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _types.AtomsTypeEnum;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
exports["default"] = void 0;
|
|
9
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
10
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -16,6 +22,7 @@ require("./locale/zh");
|
|
|
16
22
|
var _locale = require("./locale");
|
|
17
23
|
var _Loading = _interopRequireDefault(require("./common/Loading"));
|
|
18
24
|
var _metabase = _interopRequireDefault(require("./components/metabase"));
|
|
25
|
+
var _types = require("./store/types");
|
|
19
26
|
var _utils = require("./utils");
|
|
20
27
|
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
21
28
|
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" != _typeof(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 _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
package/lib/cjs/locale/en.js
CHANGED
|
@@ -41,6 +41,10 @@ var _default = exports["default"] = (0, _index.register)('en', {
|
|
|
41
41
|
'SqlQueryBuilder.pickConstant': 'Select constant...',
|
|
42
42
|
'customColumn.input': 'Input',
|
|
43
43
|
'customColumn.numberInput': 'Number input',
|
|
44
|
+
'customColumn.addSql': 'Add SQL',
|
|
45
|
+
'customColumn.parseSql': 'Parse with AI',
|
|
46
|
+
'customColumn.sqlParseInvalid': 'AI returned an invalid custom column configuration',
|
|
47
|
+
'customColumn.sqlParseFailed': 'Failed to parse SQL. Please try again',
|
|
44
48
|
'customColumn.formula': 'Formula',
|
|
45
49
|
'customColumn.selectFormula': 'Select formula...',
|
|
46
50
|
'SqlQueryBuilder.switchSubQuery': 'Open subquery',
|
package/lib/cjs/locale/zh.js
CHANGED
|
@@ -86,6 +86,10 @@ var _default = exports["default"] = (0, _index.register)('zh', {
|
|
|
86
86
|
'customColumn.selectFormula': '选择公式...',
|
|
87
87
|
'customColumn.input': '输入框',
|
|
88
88
|
'customColumn.numberInput': '数字输入框',
|
|
89
|
+
'customColumn.addSql': '添加 SQL',
|
|
90
|
+
'customColumn.parseSql': 'AI 解析',
|
|
91
|
+
'customColumn.sqlParseInvalid': 'AI 返回的自定义列结构无效',
|
|
92
|
+
'customColumn.sqlParseFailed': 'SQL 解析失败,请重试',
|
|
89
93
|
'filter.addFilter': '添加过滤器',
|
|
90
94
|
'filter.confirm': '确认',
|
|
91
95
|
'filter.pleaseEnter': '请输入',
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MetaListType, ToolbarType, FormulaTemplatesItem, ChangeType, FormulaTypeEnum, AtomsItem } from './store/types';
|
|
2
2
|
import { UnionEnum } from './store/enum';
|
|
3
|
-
import { DataType } from './components/dialog/select-
|
|
3
|
+
import { DataType } from './components/dialog/select-column-multiple';
|
|
4
4
|
export interface MetaListProps {
|
|
5
5
|
name: string;
|
|
6
6
|
type: 'group' | 'union';
|
|
@@ -26,6 +26,14 @@ export interface FormulaDiffCodeParams {
|
|
|
26
26
|
oldCode: AtomsItem[];
|
|
27
27
|
newCode: AtomsItem[];
|
|
28
28
|
}
|
|
29
|
+
export interface FormulaSqlParseParams {
|
|
30
|
+
sql: string;
|
|
31
|
+
availableTables: DataType[];
|
|
32
|
+
}
|
|
33
|
+
export interface FormulaSqlParseResult {
|
|
34
|
+
name?: string;
|
|
35
|
+
formulaList: AtomsItem[];
|
|
36
|
+
}
|
|
29
37
|
export interface MetabaseRightClickMenuItem {
|
|
30
38
|
label: React.ReactNode;
|
|
31
39
|
value: React.Key;
|
|
@@ -97,6 +105,7 @@ export interface MetabaseProps {
|
|
|
97
105
|
}>;
|
|
98
106
|
getFormulaSqlCode?: (value: AtomsItem[]) => Promise<FormulaSqlCodeResult> | FormulaSqlCodeResult;
|
|
99
107
|
getFormulaDiffCode?: (params: FormulaDiffCodeParams) => Promise<FormulaDiffCodeResult> | FormulaDiffCodeResult;
|
|
108
|
+
parseFormulaSql?: (params: FormulaSqlParseParams) => Promise<FormulaSqlParseResult> | FormulaSqlParseResult;
|
|
100
109
|
getExistsError?: (params: MetaListType[]) => Promise<any[]>;
|
|
101
110
|
operatorList?: any[];
|
|
102
111
|
otherTypes?: any[];
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
1
2
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
4
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
4
5
|
var _templateObject;
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
7
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
8
|
import { useState, useMemo, useRef } from 'react';
|
|
7
9
|
import cx from 'classnames';
|
|
@@ -18,7 +20,7 @@ var VisualBox = Styled.div.attrs({
|
|
|
18
20
|
className: 'visual-box'
|
|
19
21
|
})(_templateObject || (_templateObject = _taggedTemplateLiteral([""])));
|
|
20
22
|
var CaseEditor = function CaseEditor(props) {
|
|
21
|
-
var _store$preProps;
|
|
23
|
+
var _store$preProps, _store$preProps2;
|
|
22
24
|
var value = props.value,
|
|
23
25
|
data = props.data,
|
|
24
26
|
exitData = props.exitData,
|
|
@@ -53,6 +55,56 @@ var CaseEditor = function CaseEditor(props) {
|
|
|
53
55
|
formulaList: caseList
|
|
54
56
|
})));
|
|
55
57
|
};
|
|
58
|
+
var parseFormulaSql = (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.parseFormulaSql;
|
|
59
|
+
var handleParseSql = function () {
|
|
60
|
+
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(sql) {
|
|
61
|
+
var normalizedSql, result, _t;
|
|
62
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
63
|
+
while (1) switch (_context.prev = _context.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
normalizedSql = sql.trim();
|
|
66
|
+
if (!(!normalizedSql || typeof parseFormulaSql !== 'function')) {
|
|
67
|
+
_context.next = 1;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
return _context.abrupt("return");
|
|
71
|
+
case 1:
|
|
72
|
+
_context.prev = 1;
|
|
73
|
+
_context.next = 2;
|
|
74
|
+
return parseFormulaSql({
|
|
75
|
+
sql: normalizedSql,
|
|
76
|
+
availableTables: data
|
|
77
|
+
});
|
|
78
|
+
case 2:
|
|
79
|
+
result = _context.sent;
|
|
80
|
+
if (!(!result || !Array.isArray(result.formulaList))) {
|
|
81
|
+
_context.next = 3;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
Toast.warning(__('customColumn.sqlParseInvalid'));
|
|
85
|
+
throw new Error('INVALID_CUSTOM_COLUMN_SQL_RESULT');
|
|
86
|
+
case 3:
|
|
87
|
+
return _context.abrupt("return", function () {
|
|
88
|
+
setName(result.name || name);
|
|
89
|
+
setCaseList(result.formulaList);
|
|
90
|
+
});
|
|
91
|
+
case 4:
|
|
92
|
+
_context.prev = 4;
|
|
93
|
+
_t = _context["catch"](1);
|
|
94
|
+
if ((_t === null || _t === void 0 ? void 0 : _t.message) !== 'INVALID_CUSTOM_COLUMN_SQL_RESULT') {
|
|
95
|
+
Toast.warning(__('customColumn.sqlParseFailed'));
|
|
96
|
+
}
|
|
97
|
+
throw _t;
|
|
98
|
+
case 5:
|
|
99
|
+
case "end":
|
|
100
|
+
return _context.stop();
|
|
101
|
+
}
|
|
102
|
+
}, _callee, null, [[1, 4]]);
|
|
103
|
+
}));
|
|
104
|
+
return function handleParseSql(_x) {
|
|
105
|
+
return _ref.apply(this, arguments);
|
|
106
|
+
};
|
|
107
|
+
}();
|
|
56
108
|
return _jsxs("div", {
|
|
57
109
|
className: 'custom-box',
|
|
58
110
|
ref: ref,
|
|
@@ -84,7 +136,7 @@ var CaseEditor = function CaseEditor(props) {
|
|
|
84
136
|
})]
|
|
85
137
|
}), _jsx(FormulaList, {
|
|
86
138
|
isCustom: true,
|
|
87
|
-
otherTypes: (_store$
|
|
139
|
+
otherTypes: (_store$preProps2 = store.preProps) === null || _store$preProps2 === void 0 ? void 0 : _store$preProps2.otherTypes,
|
|
88
140
|
value: caseList,
|
|
89
141
|
data: data,
|
|
90
142
|
exitData: exitData,
|
|
@@ -93,7 +145,8 @@ var CaseEditor = function CaseEditor(props) {
|
|
|
93
145
|
if (readonly) return;
|
|
94
146
|
setCaseList(nextList);
|
|
95
147
|
},
|
|
96
|
-
_type: FormulaTypeEnum.CUSTOM
|
|
148
|
+
_type: FormulaTypeEnum.CUSTOM,
|
|
149
|
+
onAddSql: !readonly && typeof parseFormulaSql === 'function' ? handleParseSql : undefined
|
|
97
150
|
})]
|
|
98
151
|
})
|
|
99
152
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
import './index.less';
|
|
6
6
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
@@ -22,6 +22,16 @@ import cloneDeep from 'lodash/cloneDeep';
|
|
|
22
22
|
import { getConstantLabel } from '../formula-list/utils';
|
|
23
23
|
import ItemName from '../../modules/components/item-name';
|
|
24
24
|
import { DateFormatPicker, DateRangeFormatPicker } from './date-format-picker';
|
|
25
|
+
var normalizeExpressionRhs = function normalizeExpressionRhs() {
|
|
26
|
+
var rhs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
27
|
+
return rhs.map(function (item) {
|
|
28
|
+
if ((item === null || item === void 0 ? void 0 : item.type) !== AtomsTypeEnum.INPUT_NUMBER) return item;
|
|
29
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
30
|
+
type: AtomsTypeEnum.INPUT_STRING,
|
|
31
|
+
val: item.val || item.val === 0 ? String(item.val) : ''
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
25
35
|
var NUMBER_LIST = ['等于', '不等于', '大于', '小于', '介于之间', '大于或等于', '小于或等于', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
|
|
26
36
|
var STRING_LIST = ['等于', '不等于', '包含', '不包含', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
|
|
27
37
|
var DATE_LIST = ['等于', '早于', '晚于', '介于之间', '是空的', '不为空'];
|
|
@@ -57,7 +67,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
|
|
|
57
67
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
58
68
|
condition = _useState4[0],
|
|
59
69
|
setCondition = _useState4[1];
|
|
60
|
-
var _useState5 = useState(
|
|
70
|
+
var _useState5 = useState(function () {
|
|
71
|
+
return cloneDeep(normalizeExpressionRhs(value.rhs || []));
|
|
72
|
+
}),
|
|
61
73
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
62
74
|
rhsVal = _useState6[0],
|
|
63
75
|
setRhsVal = _useState6[1];
|
|
@@ -12,7 +12,7 @@ import { AddIcon, CloseIcon } from '../../icons';
|
|
|
12
12
|
import { isOk } from '../formula-list/utils';
|
|
13
13
|
import ItemName from '../../modules/components/item-name';
|
|
14
14
|
import { __ } from '../../../locale';
|
|
15
|
-
import { getTemArgs, getObjTem, getParamActions, getQuotes, formulaName, formulaIsError } from './utils';
|
|
15
|
+
import { getTemArgs, getObjTem, getParamActions, getQuotes, formulaName, formulaIsError, normalizeFormulaArgs } from './utils';
|
|
16
16
|
import Styled from 'styled-components';
|
|
17
17
|
import { AtomsTypeEnum, FormulaTypeEnum } from '../../../store/types';
|
|
18
18
|
import { Select, Button } from '@gingkoo/pandora';
|
|
@@ -35,7 +35,8 @@ var CaseEditor = React.forwardRef(function (props, ref) {
|
|
|
35
35
|
readonly = _props$readonly === void 0 ? false : _props$readonly;
|
|
36
36
|
var _useState = useState(function () {
|
|
37
37
|
return _objectSpread(_objectSpread({}, value), {}, {
|
|
38
|
-
id: value.id || value.name
|
|
38
|
+
id: value.id || value.name,
|
|
39
|
+
args: normalizeFormulaArgs(value.args || [])
|
|
39
40
|
});
|
|
40
41
|
}),
|
|
41
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -92,6 +93,7 @@ var CaseEditor = React.forwardRef(function (props, ref) {
|
|
|
92
93
|
arity: effectiveArity,
|
|
93
94
|
id: currentFormulaKey,
|
|
94
95
|
name: (currentFormulaTemplate === null || currentFormulaTemplate === void 0 ? void 0 : currentFormulaTemplate.name) || fun.name,
|
|
96
|
+
args: normalizeFormulaArgs(fun.args || []),
|
|
95
97
|
quotes: getQuotes(fun, fun.args, formulaList)
|
|
96
98
|
})));
|
|
97
99
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Arity, AtomsItem, AtomsCollection } from '../../../store/types';
|
|
2
2
|
export declare const getObjTem: (arr: any[]) => any;
|
|
3
3
|
export declare const getTemArgs: (temArgs: any[], arity?: Arity) => AtomsCollection[];
|
|
4
|
+
export declare const normalizeFormulaArgs: (args?: AtomsItem[]) => AtomsCollection[];
|
|
4
5
|
export declare function getParamActions(params: AtomsItem[], arity?: Arity): {
|
|
5
6
|
canAdd: boolean;
|
|
6
7
|
canDel: boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import { AtomsTypeEnum } from '../../../store/types';
|
|
2
3
|
import { getTemplateItem } from '../formula-list/utils';
|
|
3
4
|
export var getObjTem = function getObjTem(arr) {
|
|
@@ -35,6 +36,21 @@ export var getTemArgs = function getTemArgs(temArgs, arity) {
|
|
|
35
36
|
}
|
|
36
37
|
return _temArgs;
|
|
37
38
|
};
|
|
39
|
+
export var normalizeFormulaArgs = function normalizeFormulaArgs() {
|
|
40
|
+
var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
41
|
+
return args.map(function (arg) {
|
|
42
|
+
if ((arg === null || arg === void 0 ? void 0 : arg.type) === AtomsTypeEnum.COLLECTION) {
|
|
43
|
+
return _objectSpread(_objectSpread({}, arg), {}, {
|
|
44
|
+
list: arg.list || []
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
type: AtomsTypeEnum.COLLECTION,
|
|
49
|
+
quotes: '',
|
|
50
|
+
list: arg ? [arg] : []
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
};
|
|
38
54
|
export function getParamActions(params, arity) {
|
|
39
55
|
var len = (params === null || params === void 0 ? void 0 : params.length) || 0;
|
|
40
56
|
if (!arity) {
|
|
@@ -55,7 +71,8 @@ export var formulaName = function formulaName(fun, formulaList) {
|
|
|
55
71
|
return (obj === null || obj === void 0 ? void 0 : obj.name) || fun.name;
|
|
56
72
|
};
|
|
57
73
|
export var getQuotes = function getQuotes(fun, _args, formulaList) {
|
|
58
|
-
var
|
|
74
|
+
var _normalizeFormulaArgs;
|
|
75
|
+
var quotes = (_normalizeFormulaArgs = normalizeFormulaArgs(_args)) === null || _normalizeFormulaArgs === void 0 ? void 0 : _normalizeFormulaArgs.map(function (v) {
|
|
59
76
|
var quotes = v.list.map(function (vv, i) {
|
|
60
77
|
if (vv !== null && vv !== void 0 && vv.quotes) {
|
|
61
78
|
return vv === null || vv === void 0 ? void 0 : vv.quotes;
|
|
@@ -17,6 +17,7 @@ interface PropsType {
|
|
|
17
17
|
enableCopy?: boolean;
|
|
18
18
|
enableZoom?: boolean;
|
|
19
19
|
parentPopupChannel?: 'primary' | 'secondary';
|
|
20
|
+
onAddSql?: (sql: string) => Promise<void | (() => void)> | void | (() => void);
|
|
20
21
|
}
|
|
21
22
|
declare const FormulaList: React.ForwardRefExoticComponent<PropsType & React.RefAttributes<unknown>>;
|
|
22
23
|
export default FormulaList;
|