@gingkoo/pandora-metabase 1.0.118 → 1.0.119
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/Portal/index.js +0 -2
- package/lib/cjs/common/SplitView/index.d.ts +0 -4
- package/lib/cjs/common/SplitView/index.js +0 -10
- package/lib/cjs/components/dialog/custom-column/config.js +4 -48
- package/lib/cjs/components/dialog/custom-column/expression-editor.js +3 -14
- package/lib/cjs/components/dialog/custom-column/expressions/suggest.d.ts +2 -34
- package/lib/cjs/components/dialog/custom-column/expressions/suggest.js +2 -43
- package/lib/cjs/components/dialog/custom-column/expressions/tokenizer.js +8 -65
- package/lib/cjs/components/dialog/custom-column/index.js +2 -4
- package/lib/cjs/components/dialog/custom-column/tokenized-expression.js +2 -3
- package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +1 -1
- package/lib/cjs/components/dialog/custom-editor/index.js +2 -7
- package/lib/cjs/components/dialog/diff-viewer/index copy.js +1 -16
- package/lib/cjs/components/dialog/expression/date-format-picker.js +2 -20
- package/lib/cjs/components/dialog/expression/date-format.js +2 -8
- package/lib/cjs/components/dialog/expression/index.d.ts +0 -3
- package/lib/cjs/components/dialog/expression/index.js +2 -83
- package/lib/cjs/components/dialog/formula/index.js +1 -30
- package/lib/cjs/components/dialog/formula/utils.js +2 -10
- package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.d.ts +19 -0
- package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.js +109 -0
- package/lib/cjs/components/dialog/formula-list/LogicGroup.d.ts +9 -0
- package/lib/cjs/components/dialog/formula-list/LogicGroup.js +43 -0
- package/lib/cjs/components/dialog/formula-list/index.d.ts +3 -0
- package/lib/cjs/components/dialog/formula-list/index.js +967 -503
- package/lib/cjs/components/dialog/formula-list/index.less +724 -0
- package/lib/cjs/components/dialog/formula-list/utils.d.ts +0 -7
- package/lib/cjs/components/dialog/formula-list/utils.js +117 -113
- package/lib/cjs/components/dialog/select-column/index.d.ts +0 -6
- package/lib/cjs/components/dialog/select-column/index.js +4 -15
- package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +0 -8
- package/lib/cjs/components/dialog/select-column-multiple/index.js +6 -45
- package/lib/cjs/components/dialog/select-join/index.d.ts +0 -5
- package/lib/cjs/components/dialog/select-join/index.js +0 -6
- package/lib/cjs/components/dialog/select-join-column/index.d.ts +0 -8
- package/lib/cjs/components/dialog/select-join-column/index.js +7 -21
- package/lib/cjs/components/dialog/select-join-column-multiple/index.d.ts +0 -8
- package/lib/cjs/components/dialog/select-join-column-multiple/index.js +5 -35
- package/lib/cjs/components/dialog/select-permission-table/index.d.ts +0 -5
- package/lib/cjs/components/dialog/select-permission-table/index.js +0 -6
- package/lib/cjs/components/dialog/select-summarize/index.d.ts +3 -3
- package/lib/cjs/components/dialog/select-summarize/index.js +105 -18
- package/lib/cjs/components/dialog/select-summarize/index.less +23 -0
- package/lib/cjs/components/dialog/select-table/index.d.ts +0 -6
- package/lib/cjs/components/dialog/select-table/index.js +1 -9
- package/lib/cjs/components/metabase/index.js +72 -86
- package/lib/cjs/components/metabase/index.less +7 -7
- package/lib/cjs/components/modules/components/Wrapper.js +1 -1
- package/lib/cjs/components/modules/components/header.js +2 -2
- package/lib/cjs/components/modules/components/meta-icon.d.ts +0 -3
- package/lib/cjs/components/modules/components/meta-icon.js +2 -47
- package/lib/cjs/components/modules/custom-column.js +3 -29
- package/lib/cjs/components/modules/enum/filter-enum.js +9 -88
- package/lib/cjs/components/modules/filter.js +2 -20
- package/lib/cjs/components/modules/index.d.ts +4 -2
- package/lib/cjs/components/modules/index.js +24 -1
- package/lib/cjs/components/modules/join-data.js +13 -291
- package/lib/cjs/components/modules/row-limit.js +0 -1
- package/lib/cjs/components/modules/sort.js +1 -61
- package/lib/cjs/components/modules/summarize/group-by.d.ts +0 -5
- package/lib/cjs/components/modules/summarize/group-by.js +231 -76
- package/lib/cjs/components/modules/summarize/select-index.js +96 -46
- package/lib/cjs/components/modules/table-data.js +11 -64
- package/lib/cjs/components/popup.js +26 -32
- package/lib/cjs/hooks/patch.d.ts +1 -0
- package/lib/cjs/hooks/patch.js +104 -6
- package/lib/cjs/hooks/patch2.js +3 -165
- package/lib/cjs/hooks/use-provider.js +0 -3
- package/lib/cjs/hooks/use-state.js +55 -135
- package/lib/cjs/index.js +0 -15
- package/lib/cjs/locale/en.js +5 -0
- package/lib/cjs/locale/index.js +1 -4
- package/lib/cjs/locale/zh.js +5 -0
- package/lib/cjs/sql-formula.js +0 -1
- package/lib/cjs/store/enum.d.ts +6 -6
- package/lib/cjs/store/enum.js +0 -13
- package/lib/cjs/store/helper.d.ts +2 -1
- package/lib/cjs/store/helper.js +15 -225
- package/lib/cjs/store/types.d.ts +45 -67
- package/lib/cjs/store/types.js +3 -49
- package/lib/cjs/types.d.ts +1 -0
- package/lib/cjs/utils/cookies.js +0 -3
- package/lib/cjs/utils/event.js +1 -1
- package/lib/cjs/utils/helper-dom.d.ts +1 -0
- package/lib/cjs/utils/helper-dom.js +17 -10
- package/lib/cjs/utils/helper.js +1 -24
- package/lib/cjs/utils/keydown.js +4 -7
- package/lib/cjs/utils/platform.d.ts +0 -9
- package/lib/cjs/utils/platform.js +0 -10
- package/lib/cjs/utils/selection.js +0 -6
- package/lib/cjs/utils/storage.d.ts +0 -9
- package/lib/cjs/utils/storage.js +1 -11
- package/lib/cjs/utils/transformSql.d.ts +5 -0
- package/lib/cjs/utils/transformSql.js +42 -113
- package/lib/cjs/utils.d.ts +1 -6
- package/lib/cjs/utils.js +115 -255
- package/lib/es/common/Portal/index.js +0 -2
- package/lib/es/common/SplitView/index.d.ts +0 -4
- package/lib/es/common/SplitView/index.js +0 -10
- package/lib/es/components/dialog/custom-column/config.js +4 -48
- package/lib/es/components/dialog/custom-column/expression-editor.js +3 -14
- package/lib/es/components/dialog/custom-column/expressions/suggest.d.ts +2 -34
- package/lib/es/components/dialog/custom-column/expressions/suggest.js +2 -43
- package/lib/es/components/dialog/custom-column/expressions/tokenizer.js +8 -65
- package/lib/es/components/dialog/custom-column/index.js +2 -4
- package/lib/es/components/dialog/custom-column/tokenized-expression.js +1 -3
- package/lib/es/components/dialog/custom-column/tokenizedI-input.js +1 -1
- package/lib/es/components/dialog/custom-editor/index.js +1 -7
- package/lib/es/components/dialog/diff-viewer/index copy.js +1 -15
- package/lib/es/components/dialog/expression/date-format-picker.js +2 -20
- package/lib/es/components/dialog/expression/date-format.js +2 -8
- package/lib/es/components/dialog/expression/index.d.ts +0 -3
- package/lib/es/components/dialog/expression/index.js +2 -82
- package/lib/es/components/dialog/formula/index.js +0 -30
- package/lib/es/components/dialog/formula/utils.js +2 -10
- package/lib/es/components/dialog/formula-list/CaseWhenGroup.d.ts +19 -0
- package/lib/es/components/dialog/formula-list/CaseWhenGroup.js +102 -0
- package/lib/es/components/dialog/formula-list/LogicGroup.d.ts +9 -0
- package/lib/es/components/dialog/formula-list/LogicGroup.js +36 -0
- package/lib/es/components/dialog/formula-list/index.d.ts +3 -0
- package/lib/es/components/dialog/formula-list/index.js +966 -503
- package/lib/es/components/dialog/formula-list/index.less +724 -0
- package/lib/es/components/dialog/formula-list/utils.d.ts +0 -7
- package/lib/es/components/dialog/formula-list/utils.js +117 -113
- package/lib/es/components/dialog/index.js +3 -3
- package/lib/es/components/dialog/select-column/index.d.ts +0 -6
- package/lib/es/components/dialog/select-column/index.js +4 -14
- package/lib/es/components/dialog/select-column-multiple/index.d.ts +0 -8
- package/lib/es/components/dialog/select-column-multiple/index.js +7 -47
- package/lib/es/components/dialog/select-join/index.d.ts +0 -5
- package/lib/es/components/dialog/select-join/index.js +0 -5
- package/lib/es/components/dialog/select-join-column/index.d.ts +0 -8
- package/lib/es/components/dialog/select-join-column/index.js +7 -20
- package/lib/es/components/dialog/select-join-column-multiple/index.d.ts +0 -8
- package/lib/es/components/dialog/select-join-column-multiple/index.js +5 -34
- package/lib/es/components/dialog/select-permission-table/index.d.ts +0 -5
- package/lib/es/components/dialog/select-permission-table/index.js +0 -5
- package/lib/es/components/dialog/select-summarize/index.d.ts +3 -3
- package/lib/es/components/dialog/select-summarize/index.js +106 -18
- package/lib/es/components/dialog/select-summarize/index.less +23 -0
- package/lib/es/components/dialog/select-table/index.d.ts +0 -6
- package/lib/es/components/dialog/select-table/index.js +1 -8
- package/lib/es/components/metabase/index.js +72 -87
- package/lib/es/components/metabase/index.less +7 -7
- package/lib/es/components/modules/components/Wrapper.js +1 -1
- package/lib/es/components/modules/components/header.js +2 -2
- package/lib/es/components/modules/components/meta-icon.d.ts +0 -3
- package/lib/es/components/modules/components/meta-icon.js +2 -46
- package/lib/es/components/modules/custom-column.js +3 -29
- package/lib/es/components/modules/enum/filter-enum.js +9 -88
- package/lib/es/components/modules/filter.js +2 -19
- package/lib/es/components/modules/index.d.ts +4 -2
- package/lib/es/components/modules/index.js +24 -1
- package/lib/es/components/modules/join-data.js +13 -291
- package/lib/es/components/modules/row-limit.js +0 -1
- package/lib/es/components/modules/sort.js +1 -61
- package/lib/es/components/modules/summarize/group-by.d.ts +0 -5
- package/lib/es/components/modules/summarize/group-by.js +233 -78
- package/lib/es/components/modules/summarize/select-index.js +96 -46
- package/lib/es/components/modules/table-data.js +11 -64
- package/lib/es/components/popup.js +27 -33
- package/lib/es/hooks/patch.d.ts +1 -0
- package/lib/es/hooks/patch.js +103 -5
- package/lib/es/hooks/patch2.js +2 -164
- package/lib/es/hooks/use-provider.js +0 -3
- package/lib/es/hooks/use-state.js +55 -135
- package/lib/es/index.js +0 -14
- package/lib/es/locale/en.js +5 -0
- package/lib/es/locale/index.js +1 -4
- package/lib/es/locale/zh.js +5 -0
- package/lib/es/sql-formula.js +0 -1
- package/lib/es/store/enum.d.ts +6 -6
- package/lib/es/store/enum.js +0 -13
- package/lib/es/store/helper.d.ts +2 -1
- package/lib/es/store/helper.js +13 -224
- package/lib/es/store/types.d.ts +45 -67
- package/lib/es/store/types.js +3 -49
- package/lib/es/types.d.ts +1 -0
- package/lib/es/types.js +1 -18
- package/lib/es/utils/cookies.js +0 -3
- package/lib/es/utils/event.js +1 -1
- package/lib/es/utils/helper-dom.d.ts +1 -0
- package/lib/es/utils/helper-dom.js +16 -9
- package/lib/es/utils/helper.js +1 -24
- package/lib/es/utils/keydown.js +4 -7
- package/lib/es/utils/platform.d.ts +0 -9
- package/lib/es/utils/platform.js +0 -10
- package/lib/es/utils/selection.js +0 -6
- package/lib/es/utils/storage.d.ts +0 -9
- package/lib/es/utils/storage.js +1 -10
- package/lib/es/utils/transformSql.d.ts +5 -0
- package/lib/es/utils/transformSql.js +42 -112
- package/lib/es/utils.d.ts +1 -6
- package/lib/es/utils.js +116 -255
- package/package.json +1 -1
package/lib/es/hooks/patch.js
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import { TypeEnum } from '../store/enum';
|
|
3
|
+
var SQL_ALIAS_MAX_LENGTH = 30;
|
|
4
|
+
var normalizeSqlAlias = function normalizeSqlAlias() {
|
|
5
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
6
|
+
var index = arguments.length > 1 ? arguments[1] : undefined;
|
|
7
|
+
var fallbackAlias = "group_by_".concat(index + 1);
|
|
8
|
+
var alias = value.replace(/[^a-zA-Z0-9_]/g, '_').replace(/_+/g, '_').replace(/^_+|_+$/g, '');
|
|
9
|
+
if (!/^[a-zA-Z]/.test(alias)) {
|
|
10
|
+
alias = "a_".concat(alias.replace(/^[^a-zA-Z]+/, ''));
|
|
11
|
+
}
|
|
12
|
+
if (!/^[a-zA-Z]/.test(alias)) {
|
|
13
|
+
alias = fallbackAlias;
|
|
14
|
+
}
|
|
15
|
+
if (alias.length > SQL_ALIAS_MAX_LENGTH) {
|
|
16
|
+
var uniqueSuffix = "_".concat(index + 1);
|
|
17
|
+
var maxBaseLength = Math.max(1, SQL_ALIAS_MAX_LENGTH - uniqueSuffix.length);
|
|
18
|
+
alias = "".concat(alias.slice(0, maxBaseLength)).concat(uniqueSuffix);
|
|
19
|
+
}
|
|
20
|
+
return alias.slice(0, SQL_ALIAS_MAX_LENGTH);
|
|
21
|
+
};
|
|
22
|
+
var isValidSqlAlias = function isValidSqlAlias() {
|
|
23
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
24
|
+
if (!value) return true;
|
|
25
|
+
return /^[a-zA-Z][a-zA-Z0-9_]{0,29}$/.test(value);
|
|
26
|
+
};
|
|
3
27
|
var setConstantId = function setConstantId(item, constantList) {
|
|
4
28
|
constantList === null || constantList === void 0 || constantList.map(function (v) {
|
|
5
29
|
if (v.label === item.val) {
|
|
@@ -15,7 +39,6 @@ var setFormulaId = function setFormulaId(item, formulaTemplates) {
|
|
|
15
39
|
}
|
|
16
40
|
return item;
|
|
17
41
|
};
|
|
18
|
-
// 关联
|
|
19
42
|
export var joinDataPatch = function joinDataPatch(newMeta, constantList, formulaTemplates) {
|
|
20
43
|
var _newMeta$expressions;
|
|
21
44
|
newMeta.expressions = (_newMeta$expressions = newMeta.expressions) === null || _newMeta$expressions === void 0 ? void 0 : _newMeta$expressions.map(function (v, i) {
|
|
@@ -36,7 +59,6 @@ export var joinDataPatch = function joinDataPatch(newMeta, constantList, formula
|
|
|
36
59
|
});
|
|
37
60
|
return newMeta;
|
|
38
61
|
};
|
|
39
|
-
// 过滤器
|
|
40
62
|
export var filterPatch = function filterPatch(newMeta, constantList, formulaTemplates) {
|
|
41
63
|
var _newMeta$filter;
|
|
42
64
|
var _filter = (_newMeta$filter = newMeta.filter) === null || _newMeta$filter === void 0 ? void 0 : _newMeta$filter.map(function (v) {
|
|
@@ -72,7 +94,6 @@ export var filterPatch = function filterPatch(newMeta, constantList, formulaTemp
|
|
|
72
94
|
return arg;
|
|
73
95
|
});
|
|
74
96
|
return _v;
|
|
75
|
-
// return setFormulaId(v, formulaTemplates);
|
|
76
97
|
}
|
|
77
98
|
if (v.type === 'exists' || v.type === 'notExists') {
|
|
78
99
|
v.notExists = _patchMetas(v.notExists, constantList, formulaTemplates);
|
|
@@ -82,7 +103,6 @@ export var filterPatch = function filterPatch(newMeta, constantList, formulaTemp
|
|
|
82
103
|
newMeta.filter = _filter;
|
|
83
104
|
return newMeta;
|
|
84
105
|
};
|
|
85
|
-
// 自定义
|
|
86
106
|
export var customColumnPatch = function customColumnPatch(newMeta, constantList, formulaTemplates) {
|
|
87
107
|
var _newMeta$customColumn;
|
|
88
108
|
newMeta.customColumn = (newMeta === null || newMeta === void 0 || (_newMeta$customColumn = newMeta.customColumn) === null || _newMeta$customColumn === void 0 ? void 0 : _newMeta$customColumn.map(function (v) {
|
|
@@ -119,7 +139,82 @@ export var customColumnPatch = function customColumnPatch(newMeta, constantList,
|
|
|
119
139
|
})) || newMeta.customColumn;
|
|
120
140
|
return newMeta;
|
|
121
141
|
};
|
|
122
|
-
|
|
142
|
+
export var summarizePatch = function summarizePatch(newMeta, constantList, formulaTemplates) {
|
|
143
|
+
var _newMeta$group, _newMeta$by;
|
|
144
|
+
newMeta.group = ((_newMeta$group = newMeta.group) === null || _newMeta$group === void 0 ? void 0 : _newMeta$group.map(function (item, index) {
|
|
145
|
+
var _item$atoms;
|
|
146
|
+
var atoms = (_item$atoms = item.atoms) === null || _item$atoms === void 0 ? void 0 : _item$atoms.map(function (formula) {
|
|
147
|
+
if (formula.type === 'expression') {
|
|
148
|
+
var _formula$lhs2, _formula$rhs2;
|
|
149
|
+
formula.lhs = (_formula$lhs2 = formula.lhs) === null || _formula$lhs2 === void 0 ? void 0 : _formula$lhs2.map(function (vv) {
|
|
150
|
+
if (vv.type === 'constant' && !vv.id) {
|
|
151
|
+
return setConstantId(vv, constantList);
|
|
152
|
+
}
|
|
153
|
+
return vv;
|
|
154
|
+
});
|
|
155
|
+
formula.rhs = (_formula$rhs2 = formula.rhs) === null || _formula$rhs2 === void 0 ? void 0 : _formula$rhs2.map(function (vv) {
|
|
156
|
+
if (vv.type === 'constant' && !vv.id) {
|
|
157
|
+
return setConstantId(vv, constantList);
|
|
158
|
+
}
|
|
159
|
+
return vv;
|
|
160
|
+
});
|
|
161
|
+
} else if (formula.type === 'constant' && !formula.id) {
|
|
162
|
+
return setConstantId(formula, constantList);
|
|
163
|
+
} else if (formula.type === 'FORMULA' && !formula.id) {
|
|
164
|
+
return setFormulaId(formula, formulaTemplates);
|
|
165
|
+
} else if (formula.type === 'exists' || formula.type === 'notExists') {
|
|
166
|
+
return _objectSpread(_objectSpread({}, formula), {}, {
|
|
167
|
+
notExists: _patchMetas(formula.notExists, constantList, formulaTemplates)
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return formula;
|
|
171
|
+
});
|
|
172
|
+
var nextItem = _objectSpread(_objectSpread({}, item), {}, {
|
|
173
|
+
atoms: atoms
|
|
174
|
+
});
|
|
175
|
+
if (!isValidSqlAlias(nextItem.fieldAlias)) {
|
|
176
|
+
nextItem.fieldAlias = normalizeSqlAlias(nextItem.fieldAlias || nextItem.name || "group_".concat(index + 1), index);
|
|
177
|
+
}
|
|
178
|
+
return nextItem;
|
|
179
|
+
})) || newMeta.group;
|
|
180
|
+
newMeta.by = ((_newMeta$by = newMeta.by) === null || _newMeta$by === void 0 ? void 0 : _newMeta$by.map(function (item, index) {
|
|
181
|
+
var _item$atoms2;
|
|
182
|
+
var atoms = (_item$atoms2 = item.atoms) === null || _item$atoms2 === void 0 ? void 0 : _item$atoms2.map(function (formula) {
|
|
183
|
+
if (formula.type === 'expression') {
|
|
184
|
+
var _formula$lhs3, _formula$rhs3;
|
|
185
|
+
formula.lhs = (_formula$lhs3 = formula.lhs) === null || _formula$lhs3 === void 0 ? void 0 : _formula$lhs3.map(function (vv) {
|
|
186
|
+
if (vv.type === 'constant' && !vv.id) {
|
|
187
|
+
return setConstantId(vv, constantList);
|
|
188
|
+
}
|
|
189
|
+
return vv;
|
|
190
|
+
});
|
|
191
|
+
formula.rhs = (_formula$rhs3 = formula.rhs) === null || _formula$rhs3 === void 0 ? void 0 : _formula$rhs3.map(function (vv) {
|
|
192
|
+
if (vv.type === 'constant' && !vv.id) {
|
|
193
|
+
return setConstantId(vv, constantList);
|
|
194
|
+
}
|
|
195
|
+
return vv;
|
|
196
|
+
});
|
|
197
|
+
} else if (formula.type === 'constant' && !formula.id) {
|
|
198
|
+
return setConstantId(formula, constantList);
|
|
199
|
+
} else if (formula.type === 'FORMULA' && !formula.id) {
|
|
200
|
+
return setFormulaId(formula, formulaTemplates);
|
|
201
|
+
} else if (formula.type === 'exists' || formula.type === 'notExists') {
|
|
202
|
+
return _objectSpread(_objectSpread({}, formula), {}, {
|
|
203
|
+
notExists: _patchMetas(formula.notExists, constantList, formulaTemplates)
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return formula;
|
|
207
|
+
});
|
|
208
|
+
var nextItem = _objectSpread(_objectSpread({}, item), {}, {
|
|
209
|
+
atoms: atoms
|
|
210
|
+
});
|
|
211
|
+
if (!isValidSqlAlias(nextItem.fieldAlias)) {
|
|
212
|
+
nextItem.fieldAlias = normalizeSqlAlias(nextItem.fieldAlias || nextItem.name || "group_by_".concat(index + 1), index);
|
|
213
|
+
}
|
|
214
|
+
return nextItem;
|
|
215
|
+
})) || newMeta.by;
|
|
216
|
+
return newMeta;
|
|
217
|
+
};
|
|
123
218
|
var _patchMetas = function patchMetas(items, constantList, formulaTemplates) {
|
|
124
219
|
return (items === null || items === void 0 ? void 0 : items.map(function (v) {
|
|
125
220
|
if (v.type === TypeEnum.joinData) {
|
|
@@ -131,6 +226,9 @@ var _patchMetas = function patchMetas(items, constantList, formulaTemplates) {
|
|
|
131
226
|
if (v.type === TypeEnum.customColumn) {
|
|
132
227
|
v = customColumnPatch(v, constantList, formulaTemplates);
|
|
133
228
|
}
|
|
229
|
+
if (v.type === TypeEnum.summarize) {
|
|
230
|
+
v = summarizePatch(v, constantList, formulaTemplates);
|
|
231
|
+
}
|
|
134
232
|
if (v.type === TypeEnum.union) {
|
|
135
233
|
v.subquery = _patchMetas(v.subquery || [], constantList, formulaTemplates);
|
|
136
234
|
}
|
package/lib/es/hooks/patch2.js
CHANGED
|
@@ -4,54 +4,19 @@ import { buildSqlQuery } from '../utils';
|
|
|
4
4
|
import { AtomsTypeEnum } from '../store/types';
|
|
5
5
|
import { TypeEnum } from '../store/enum';
|
|
6
6
|
export var dataPatch = function dataPatch(newMeta) {
|
|
7
|
-
// let item = newMeta.expressions?.[0] || {};
|
|
8
|
-
// if (item?.type && Object.values(AtomsTypeEnum).includes(item.type)) {
|
|
9
|
-
// if (item.type === AtomsTypeEnum.EXPRESSION && item.lhs) {
|
|
10
|
-
// return newMeta;
|
|
11
|
-
// }
|
|
12
|
-
// }
|
|
13
7
|
newMeta.subquery = _patchMetas(newMeta.subquery);
|
|
14
8
|
return newMeta;
|
|
15
9
|
};
|
|
16
10
|
export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
17
11
|
var _fields, _fields2, _fields3, _fields4, _newMeta$expressions;
|
|
18
|
-
// let item = newMeta.expressions?.[0] || {};
|
|
19
|
-
// if (item?.type && Object.values(AtomsTypeEnum).includes(item.type)) {
|
|
20
|
-
// if (
|
|
21
|
-
// (item.type === AtomsTypeEnum.EXPRESSION || item.type === AtomsTypeEnum.JOIN_DEFAULT) &&
|
|
22
|
-
// item.lhs
|
|
23
|
-
// ) {
|
|
24
|
-
// return newMeta;
|
|
25
|
-
// }
|
|
26
|
-
// if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
|
|
27
|
-
// return newMeta;
|
|
28
|
-
// }
|
|
29
|
-
// if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
|
|
30
|
-
// return newMeta;
|
|
31
|
-
// }
|
|
32
|
-
// if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
|
|
33
|
-
// return newMeta;
|
|
34
|
-
// }
|
|
35
|
-
// }
|
|
36
|
-
// if (
|
|
37
|
-
// newMeta.expressions?.[0]?.type &&
|
|
38
|
-
// Object.values(AtomsTypeEnum).includes(newMeta.expressions[0].type)
|
|
39
|
-
// ) {
|
|
40
|
-
// return newMeta;
|
|
41
|
-
// }
|
|
42
12
|
var fields1 = newMeta.table1.fields || [];
|
|
43
13
|
var fields2 = newMeta.table2.fields || [];
|
|
44
|
-
// 处理老字段
|
|
45
14
|
var field1 = {
|
|
46
15
|
fieldAlias: newMeta.table1.fieldAlias || newMeta.table1.column || newMeta.table1.name,
|
|
47
16
|
fieldUuid: newMeta.table1.fieldUuid || uuidv4('field'),
|
|
48
17
|
fieldId: newMeta.table1.fieldId,
|
|
49
18
|
fieldNameZh: newMeta.table1.name_zh,
|
|
50
19
|
fieldName: newMeta.table1.fieldName || newMeta.table1.name
|
|
51
|
-
// quotes: newMeta.table1.quotes || newMeta.table1.column,
|
|
52
|
-
// tableUuid: newMeta.table1.tableUuid,
|
|
53
|
-
// tableId: newMeta.table1.datasourceId,
|
|
54
|
-
// tableAlias: newMeta.table1.alias,
|
|
55
20
|
};
|
|
56
21
|
var field2 = {
|
|
57
22
|
fieldAlias: newMeta.table2.fieldAlias || newMeta.table2.column || newMeta.table2.name,
|
|
@@ -60,53 +25,20 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
60
25
|
fieldNameZh: newMeta.table2.name_zh,
|
|
61
26
|
fieldName: newMeta.table2.fieldName || newMeta.table2.name
|
|
62
27
|
};
|
|
63
|
-
// 处理多选
|
|
64
28
|
if (field1.fieldAlias && ((_fields = fields1) === null || _fields === void 0 ? void 0 : _fields.length) < 1) {
|
|
65
29
|
fields1 = [_objectSpread(_objectSpread({}, field1), {}, {
|
|
66
|
-
// quotes: field1.quotes,
|
|
67
30
|
fieldUuid: field1.fieldUuid,
|
|
68
31
|
fieldAlias: field1.fieldAlias,
|
|
69
32
|
fieldId: field1.fieldId
|
|
70
|
-
// fieldNameZh: newMeta.table1.name_zh,
|
|
71
|
-
// fieldName: newMeta.table1.fieldName || newMeta.table1.name,
|
|
72
|
-
// tableAlias: newMeta.table1.alias,
|
|
73
|
-
// tableId: newMeta.table1.id,
|
|
74
|
-
// tableName: newMeta.table1.name,
|
|
75
|
-
// tableNameZh: newMeta.table1.name_zh,
|
|
76
|
-
// tableUuid: newMeta.table1.tableUuid,
|
|
77
|
-
// datasourceName: newMeta.table1.datasourceName, // 数据源名
|
|
78
|
-
// datasourceId: newMeta.table1.datasourceId, // 数据源id
|
|
79
33
|
})];
|
|
80
34
|
}
|
|
81
35
|
if (field2.fieldAlias && ((_fields2 = fields2) === null || _fields2 === void 0 ? void 0 : _fields2.length) < 1) {
|
|
82
36
|
fields2 = [_objectSpread(_objectSpread({}, field2), {}, {
|
|
83
|
-
// quotes: field2.quotes,
|
|
84
37
|
fieldUuid: field2.fieldUuid,
|
|
85
38
|
fieldAlias: field2.fieldAlias,
|
|
86
39
|
fieldId: field2.fieldId
|
|
87
|
-
// fieldNameZh: newMeta.table2.name_zh,
|
|
88
|
-
// fieldName: newMeta.table2.fieldName || newMeta.table2.name,
|
|
89
|
-
// tableAlias: newMeta.table2.alias,
|
|
90
|
-
// tableId: newMeta.table2.id,
|
|
91
|
-
// tableName: newMeta.table2.name,
|
|
92
|
-
// tableNameZh: newMeta.table2.name_zh,
|
|
93
|
-
// tableUuid: newMeta.table2.tableUuid,
|
|
94
|
-
// datasourceName: newMeta.table2.datasourceName, // 数据源名
|
|
95
|
-
// datasourceId: newMeta.table2.datasourceId, // 数据源id
|
|
96
40
|
})];
|
|
97
41
|
}
|
|
98
|
-
// newMeta.table1 = {
|
|
99
|
-
// ...newMeta.table1,
|
|
100
|
-
// ...field1,
|
|
101
|
-
// tableUuid: newMeta.table1.tableUuid || uuidv4('table'),
|
|
102
|
-
// fields: fields1,
|
|
103
|
-
// };
|
|
104
|
-
// newMeta.table2 = {
|
|
105
|
-
// ...newMeta.table2,
|
|
106
|
-
// ...field2,
|
|
107
|
-
// tableUuid: newMeta.table2.tableUuid || uuidv4('table'),
|
|
108
|
-
// fields: fields2,
|
|
109
|
-
// };
|
|
110
42
|
var beforeExpressions = [];
|
|
111
43
|
if (((_fields3 = fields1) === null || _fields3 === void 0 ? void 0 : _fields3.length) > 0 || ((_fields4 = fields2) === null || _fields4 === void 0 ? void 0 : _fields4.length) > 0) {
|
|
112
44
|
beforeExpressions = [{
|
|
@@ -119,17 +51,13 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
119
51
|
right_string: '',
|
|
120
52
|
right_fields: fields2 || [],
|
|
121
53
|
right_type: 'field',
|
|
122
|
-
type: 'default'
|
|
54
|
+
type: 'default'
|
|
123
55
|
}];
|
|
124
56
|
}
|
|
125
57
|
var expressions = ((_newMeta$expressions = newMeta.expressions) === null || _newMeta$expressions === void 0 ? void 0 : _newMeta$expressions.map(function (v) {
|
|
126
58
|
var _left_fields, _right_fields;
|
|
127
59
|
var left_fields = v.left_fields || [];
|
|
128
60
|
var right_fields = v.right_fields || [];
|
|
129
|
-
// if (v.type !== 'default') {
|
|
130
|
-
// return v;
|
|
131
|
-
// }
|
|
132
|
-
// 先处理老数据的字段
|
|
133
61
|
var left_field = {
|
|
134
62
|
left_fieldAlias: v.left_fieldAlias || v.left_column,
|
|
135
63
|
left_fieldUuid: v.left_fieldUuid || uuidv4('field'),
|
|
@@ -140,15 +68,11 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
140
68
|
right_fieldUuid: v.right_fieldUuid || uuidv4('field'),
|
|
141
69
|
right_quotes: v.right_quotes || v.right_column
|
|
142
70
|
};
|
|
143
|
-
// 再处理多选
|
|
144
71
|
if (left_field.left_fieldAlias && ((_left_fields = left_fields) === null || _left_fields === void 0 ? void 0 : _left_fields.length) < 1) {
|
|
145
72
|
left_fields = [{
|
|
146
73
|
fieldAlias: left_field.left_fieldAlias,
|
|
147
74
|
fieldUuid: left_field.left_fieldUuid,
|
|
148
75
|
quotes: left_field.left_quotes
|
|
149
|
-
// tableUuid: newMeta.table1.tableUuid,
|
|
150
|
-
// tableId: newMeta.table1.datasourceId,
|
|
151
|
-
// tableAlias: newMeta.table1.alias,
|
|
152
76
|
}];
|
|
153
77
|
}
|
|
154
78
|
if (right_field.right_fieldAlias && ((_right_fields = right_fields) === null || _right_fields === void 0 ? void 0 : _right_fields.length) < 1) {
|
|
@@ -156,9 +80,6 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
156
80
|
fieldAlias: right_field.right_fieldAlias,
|
|
157
81
|
fieldUuid: right_field.right_fieldUuid,
|
|
158
82
|
quotes: right_field.right_quotes
|
|
159
|
-
// tableUuid: newMeta.table2.tableUuid,
|
|
160
|
-
// tableId: newMeta.table2.datasourceId,
|
|
161
|
-
// tableAlias: newMeta.table2.alias,
|
|
162
83
|
}];
|
|
163
84
|
}
|
|
164
85
|
return {
|
|
@@ -171,7 +92,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
171
92
|
right_string: v.right_string || '',
|
|
172
93
|
right_fields: right_fields,
|
|
173
94
|
right_type: v.right_type || '',
|
|
174
|
-
type: v.type || 'default'
|
|
95
|
+
type: v.type || 'default'
|
|
175
96
|
};
|
|
176
97
|
})) || [];
|
|
177
98
|
var _expressions = beforeExpressions.concat(expressions);
|
|
@@ -201,9 +122,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
201
122
|
tableNameZh: newMeta.table1.name_zh,
|
|
202
123
|
tableUuid: newMeta.table1.tableUuid,
|
|
203
124
|
datasourceName: newMeta.table1.datasourceName,
|
|
204
|
-
// 数据源名
|
|
205
125
|
datasourceId: newMeta.table1.datasourceId,
|
|
206
|
-
// 数据源id
|
|
207
126
|
type: AtomsTypeEnum.FIELD
|
|
208
127
|
}, vv);
|
|
209
128
|
});
|
|
@@ -230,9 +149,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
230
149
|
tableNameZh: newMeta.table2.name_zh,
|
|
231
150
|
tableUuid: newMeta.table2.tableUuid,
|
|
232
151
|
datasourceName: newMeta.table2.datasourceName,
|
|
233
|
-
// 数据源名
|
|
234
152
|
datasourceId: newMeta.table2.datasourceId,
|
|
235
|
-
// 数据源id
|
|
236
153
|
type: AtomsTypeEnum.FIELD
|
|
237
154
|
}, vv);
|
|
238
155
|
});
|
|
@@ -240,9 +157,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
240
157
|
var item = {
|
|
241
158
|
lhs: lhs,
|
|
242
159
|
rhs: rhs,
|
|
243
|
-
// database_type: '',
|
|
244
160
|
condition: '',
|
|
245
|
-
// quotes: '',
|
|
246
161
|
type: AtomsTypeEnum.JOIN_DEFAULT
|
|
247
162
|
};
|
|
248
163
|
newExpressions.push(item);
|
|
@@ -254,9 +169,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
254
169
|
}
|
|
255
170
|
return item;
|
|
256
171
|
});
|
|
257
|
-
// 清除table1中不用字段
|
|
258
172
|
delete newMeta.table1.fields;
|
|
259
|
-
// 清除table2中不用字段
|
|
260
173
|
delete newMeta.table2.fields;
|
|
261
174
|
newMeta.subquery = _patchMetas(newMeta.subquery);
|
|
262
175
|
newMeta.expressions = newExpressions;
|
|
@@ -264,23 +177,7 @@ export var joinDataPatch = function joinDataPatch(newMeta) {
|
|
|
264
177
|
};
|
|
265
178
|
export var filterPatch = function filterPatch(newMeta) {
|
|
266
179
|
var _newMeta$filter;
|
|
267
|
-
// let item = newMeta.filter?.[0] || {};
|
|
268
|
-
// if (item?.type && Object.values(AtomsTypeEnum).includes(item.type)) {
|
|
269
|
-
// if (item.type === AtomsTypeEnum.EXPRESSION && item.lhs) {
|
|
270
|
-
// return newMeta;
|
|
271
|
-
// }
|
|
272
|
-
// if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
|
|
273
|
-
// return newMeta;
|
|
274
|
-
// }
|
|
275
|
-
// if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
|
|
276
|
-
// return newMeta;
|
|
277
|
-
// }
|
|
278
|
-
// if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
|
|
279
|
-
// return newMeta;
|
|
280
|
-
// }
|
|
281
|
-
// }
|
|
282
180
|
var _filter = (_newMeta$filter = newMeta.filter) === null || _newMeta$filter === void 0 ? void 0 : _newMeta$filter.map(function (v) {
|
|
283
|
-
// 表达式
|
|
284
181
|
var tem;
|
|
285
182
|
if (typeof v === 'string') {
|
|
286
183
|
return {
|
|
@@ -372,21 +269,6 @@ export var filterPatch = function filterPatch(newMeta) {
|
|
|
372
269
|
};
|
|
373
270
|
export var customColumnPatch = function customColumnPatch(newMeta) {
|
|
374
271
|
var _newMeta$customColumn;
|
|
375
|
-
// let item = newMeta.customColumn?.[0]?.formulaList?.[0] || {};
|
|
376
|
-
// if (item?.type && Object.values(AtomsTypeEnum).includes(item.type)) {
|
|
377
|
-
// if (item.type === AtomsTypeEnum.EXPRESSION && item.lhs) {
|
|
378
|
-
// return newMeta;
|
|
379
|
-
// }
|
|
380
|
-
// if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
|
|
381
|
-
// return newMeta;
|
|
382
|
-
// }
|
|
383
|
-
// if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
|
|
384
|
-
// return newMeta;
|
|
385
|
-
// }
|
|
386
|
-
// if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
|
|
387
|
-
// return newMeta;
|
|
388
|
-
// }
|
|
389
|
-
// }
|
|
390
272
|
newMeta.customColumn = (newMeta === null || newMeta === void 0 || (_newMeta$customColumn = newMeta.customColumn) === null || _newMeta$customColumn === void 0 ? void 0 : _newMeta$customColumn.map(function (v) {
|
|
391
273
|
var _formulaList = v.formulaList.map(function (formula) {
|
|
392
274
|
var tem = formula;
|
|
@@ -406,7 +288,6 @@ export var customColumnPatch = function customColumnPatch(newMeta) {
|
|
|
406
288
|
tableUuid: formula.expression.table2.tableUuid,
|
|
407
289
|
datasourceName: formula.expression.table2.datasourceName,
|
|
408
290
|
datasourceId: formula.expression.table2.datasourceId,
|
|
409
|
-
// quotes: formula.expression.table2.quotes,
|
|
410
291
|
type: AtomsTypeEnum.FIELD
|
|
411
292
|
}];
|
|
412
293
|
} else if (formula.expression.valType === 'constant') {
|
|
@@ -444,7 +325,6 @@ export var customColumnPatch = function customColumnPatch(newMeta) {
|
|
|
444
325
|
tableUuid: formula.expression.tableUuid,
|
|
445
326
|
datasourceName: formula.expression.datasourceName,
|
|
446
327
|
datasourceId: formula.expression.datasourceId,
|
|
447
|
-
// quotes: formula.expression.name,
|
|
448
328
|
type: AtomsTypeEnum.FIELD
|
|
449
329
|
}],
|
|
450
330
|
rhs: rhs,
|
|
@@ -468,7 +348,6 @@ export var customColumnPatch = function customColumnPatch(newMeta) {
|
|
|
468
348
|
tableUuid: formula.expression.tableUuid,
|
|
469
349
|
datasourceName: formula.expression.datasourceName,
|
|
470
350
|
datasourceId: formula.expression.datasourceId,
|
|
471
|
-
// quotes: formula.expression.quotes,
|
|
472
351
|
type: AtomsTypeEnum.FIELD
|
|
473
352
|
};
|
|
474
353
|
} else if (formula.type === 'operator') {
|
|
@@ -487,7 +366,6 @@ export var customColumnPatch = function customColumnPatch(newMeta) {
|
|
|
487
366
|
type: AtomsTypeEnum.INPUT_STRING
|
|
488
367
|
};
|
|
489
368
|
} else if (formula.type === 'notExists') {
|
|
490
|
-
//应该是多余
|
|
491
369
|
return {
|
|
492
370
|
notExists: v.expression.notExists,
|
|
493
371
|
quotes: v.expression.quotes,
|
|
@@ -505,21 +383,6 @@ export var customColumnPatch = function customColumnPatch(newMeta) {
|
|
|
505
383
|
};
|
|
506
384
|
export var sortPatch = function sortPatch(newMeta) {
|
|
507
385
|
var _newMeta$sort;
|
|
508
|
-
// let item = newMeta.sort?.[0].expression?.[0] || {};
|
|
509
|
-
// if (item?.type && Object.values(AtomsTypeEnum).includes(item.type)) {
|
|
510
|
-
// if (item.type === AtomsTypeEnum.EXPRESSION && item.lhs) {
|
|
511
|
-
// return newMeta;
|
|
512
|
-
// }
|
|
513
|
-
// if (item.type === AtomsTypeEnum.EXISTS && !item.tableUuid) {
|
|
514
|
-
// return newMeta;
|
|
515
|
-
// }
|
|
516
|
-
// if (item.type === AtomsTypeEnum.NOT_EXISTS && !item.tableUuid) {
|
|
517
|
-
// return newMeta;
|
|
518
|
-
// }
|
|
519
|
-
// if (item.type === AtomsTypeEnum.FIELD && item.fieldName) {
|
|
520
|
-
// return newMeta;
|
|
521
|
-
// }
|
|
522
|
-
// }
|
|
523
386
|
var _sort = (_newMeta$sort = newMeta.sort) === null || _newMeta$sort === void 0 ? void 0 : _newMeta$sort.map(function (v) {
|
|
524
387
|
return {
|
|
525
388
|
expression: [{
|
|
@@ -566,29 +429,4 @@ var _patchMetas = function patchMetas(items) {
|
|
|
566
429
|
return v;
|
|
567
430
|
})) || [];
|
|
568
431
|
};
|
|
569
|
-
// export const patchMetas1 = (items: MetaListType[]) => {
|
|
570
|
-
// return (
|
|
571
|
-
// items?.map((v: MetaListType): MetaListType => {
|
|
572
|
-
// // if (v.type === TypeEnum.data) {
|
|
573
|
-
// // v = dataPatch(v);
|
|
574
|
-
// // }
|
|
575
|
-
// // if (v.type === TypeEnum.joinData) {
|
|
576
|
-
// // v = joinDataPatch(v);
|
|
577
|
-
// // }
|
|
578
|
-
// // if (v.type === TypeEnum.filter) {
|
|
579
|
-
// // v = filterPatch(v);
|
|
580
|
-
// // }
|
|
581
|
-
// // if (v.type === TypeEnum.sort) {
|
|
582
|
-
// // v = sortPatch(v);
|
|
583
|
-
// // }
|
|
584
|
-
// // if (v.type === TypeEnum.customColumn) {
|
|
585
|
-
// // v = customColumnPatch(v);
|
|
586
|
-
// // }
|
|
587
|
-
// if (v.type === TypeEnum.union) {
|
|
588
|
-
// v.subquery = patchMetas(v.subquery || []);
|
|
589
|
-
// }
|
|
590
|
-
// return v;
|
|
591
|
-
// }) || []
|
|
592
|
-
// );
|
|
593
|
-
// };
|
|
594
432
|
export { _patchMetas as patchMetas };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext } from 'react';
|
|
3
|
-
// 创建 Context
|
|
4
3
|
var Context = createContext({});
|
|
5
|
-
// 创建 Provider 组件
|
|
6
4
|
export var Provider = function Provider(_ref) {
|
|
7
5
|
var value = _ref.value,
|
|
8
6
|
children = _ref.children;
|
|
@@ -11,7 +9,6 @@ export var Provider = function Provider(_ref) {
|
|
|
11
9
|
children: children
|
|
12
10
|
});
|
|
13
11
|
};
|
|
14
|
-
// 自定义 Hook 来使用 Context
|
|
15
12
|
export var useStore = function useStore() {
|
|
16
13
|
return useContext(Context);
|
|
17
14
|
};
|