@gingkoo/pandora-metabase 0.0.1-alpha.4 → 0.0.1-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/README.md +61 -26
- package/lib/es/index.js +136 -33
- package/lib/es/index.js.map +1 -1
- package/lib/es/store/index.d.ts +10 -0
- package/lib/es/store/types.d.ts +3 -1
- package/lib/es/types.d.ts +6 -1
- package/lib/es/utils/helper.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
### 主要功能
|
|
8
8
|
|
|
9
|
-
- **动态获取表字段**:使用 `
|
|
9
|
+
- **动态获取表字段**:使用 `getColumns` 方法可以动态获取指定表的最新字段信息。
|
|
10
10
|
- **可视化 SQL 构建**:通过 `MetaBase` 组件,用户能够以图形化的方式构建 SQL 查询,支持多种元数据类型,如 `MetaData`, `MetaJoin`, `MetaFilter` 等。
|
|
11
11
|
- **灵活扩展**:提供了丰富的接口和类型定义,便于根据具体需求进行定制和扩展。
|
|
12
12
|
|
|
@@ -22,11 +22,7 @@ export type MetaListType =
|
|
|
22
22
|
| MetaSort
|
|
23
23
|
| MetaLimit;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
name: string; // 表名
|
|
27
|
-
alias: string; // 别名
|
|
28
|
-
}
|
|
29
|
-
|
|
25
|
+
// Columns 集合
|
|
30
26
|
export interface MetaData_ColumnsType {
|
|
31
27
|
name: string; // 字段名
|
|
32
28
|
name_zh: string; // 字段中文名称
|
|
@@ -34,18 +30,37 @@ export interface MetaData_ColumnsType {
|
|
|
34
30
|
special_type: SpecialType | string; // 特殊类型,如主键、外键等
|
|
35
31
|
select: boolean; // 是否在查询中选中该字段
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
export type ToolbarType =
|
|
34
|
+
| 'filter'
|
|
35
|
+
| 'summarize'
|
|
36
|
+
| 'joinData'
|
|
37
|
+
| 'permissionTable'
|
|
38
|
+
| 'customColumn'
|
|
39
|
+
| 'sort'
|
|
40
|
+
| 'rowLimit';
|
|
39
41
|
|
|
40
42
|
export interface MetaBaseProps {
|
|
41
43
|
loading?: boolean; // 加载状态
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
btnText?: string; //按钮文字
|
|
45
|
+
showPermissionTable?: boolean; // 是否显示权限表
|
|
46
|
+
showFields?:boolean ; //是否显示字段
|
|
47
|
+
tableNameTpl?: string; //表名
|
|
48
|
+
fieldNameTpl?: string; //字段名
|
|
49
|
+
/**
|
|
50
|
+
* 工具栏列表
|
|
51
|
+
* 默认 ['filter','summarize','joinData','permissionTable','customColumn','sort','rowLimit']
|
|
52
|
+
*/
|
|
53
|
+
toolbar?:ToolbarType[]|false;
|
|
54
|
+
readonly?: boolean; //是否只读
|
|
55
|
+
getTables: (datasourceId: string) => Promise<any>; //获取表
|
|
56
|
+
getColumns: (table: string, datasourceId: string) => Promise<any>;//获取数据源
|
|
57
|
+
onOk: (params: any) => Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface SqlVisionBuilderRef {
|
|
61
|
+
setDatasource: (list: DatasourceType[]) => void; // 设置数据源列表
|
|
62
|
+
setPreData: (data: MetaListType[]) => void; // 设置回显数据
|
|
63
|
+
reset: () => void; // 重置到上次设置的数据
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
```
|
|
@@ -58,21 +73,41 @@ export interface MetaBaseProps {
|
|
|
58
73
|
|
|
59
74
|
<MetaBase
|
|
60
75
|
value={value}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
showFields={false}
|
|
77
|
+
toolbar={[
|
|
78
|
+
'filter',
|
|
79
|
+
'summarize',
|
|
80
|
+
'joinData',
|
|
81
|
+
'permissionTable',
|
|
82
|
+
'customColumn',
|
|
83
|
+
'sort',
|
|
84
|
+
'rowLimit',
|
|
85
|
+
]}
|
|
86
|
+
getTables={async (id: string) => {
|
|
87
|
+
let tables = [
|
|
88
|
+
'YBT_PM_BHJQTDBXY',
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
return tables.map((item) => {
|
|
92
|
+
return {
|
|
93
|
+
name: item,
|
|
94
|
+
alias: item,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}}
|
|
98
|
+
getColumns={async (name: string) => {
|
|
64
99
|
let data: MetaData_ColumnsType[] = [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
100
|
+
{
|
|
101
|
+
database_type: 'STRING',
|
|
102
|
+
name: 'C_RSV5',
|
|
103
|
+
select: true,
|
|
104
|
+
special_type: '',
|
|
105
|
+
name_zh: '备用字段(项目组可使用)',
|
|
106
|
+
},
|
|
72
107
|
];
|
|
73
108
|
return data;
|
|
74
109
|
}}
|
|
75
|
-
|
|
110
|
+
onOk={(v) => {
|
|
76
111
|
console.log(v);
|
|
77
112
|
}}
|
|
78
113
|
/>
|
package/lib/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @gingkoo/pandora-metabase v0.0.1-alpha.
|
|
2
|
+
* @gingkoo/pandora-metabase v0.0.1-alpha.6
|
|
3
3
|
*/
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import * as React from 'react';
|
|
@@ -336,7 +336,7 @@ const Loading = ({
|
|
|
336
336
|
});
|
|
337
337
|
};
|
|
338
338
|
|
|
339
|
-
var css_248z$b = ".mx-4 {\n margin-left: 1rem;\n margin-right: 1rem;\n}\n.m-2 {\n margin: 0.5rem;\n}\n.mx-2 {\n margin-left: 0.5rem;\n margin-right: 0.5rem;\n}\n.ml-2 {\n margin-left: 0.5rem;\n}\n.mt-2 {\n margin-top: 0.5rem;\n}\n.mb-2 {\n margin-bottom: 0.5rem;\n}\n.mt-4 {\n margin-top: 1rem;\n}\n.ml-4 {\n margin-left: 1rem;\n}\n.mr-4 {\n margin-right: 1rem;\n}\n.mr-2 {\n margin-right: 0.5rem;\n}\n.pt-2 {\n padding-top: 0.5rem;\n}\n.pb-2 {\n padding-bottom: 0.5rem;\n}\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n.p-4 {\n padding: 1rem;\n}\n.p-2 {\n padding: 0.5rem;\n}\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n.pb-4 {\n padding-bottom: 1rem;\n}\n.pt-4 {\n padding-top: 1rem;\n}\n.block {\n display: block;\n}\n.w-full {\n width: 100%;\n}\n.font-bold {\n font-weight: 700;\n}\n.uppercase {\n text-transform: uppercase;\n}\n.tracking-wider {\n letter-spacing: 0.05em;\n}\n.relative {\n position: relative;\n}\n.absolute {\n position: absolute;\n}\n.top-0 {\n top: 0px;\n}\n.left-0 {\n left: 0;\n}\n.rounded-lg {\n border-radius: 0.5rem;\n}\n.text-gray-500 {\n color: #6b7280;\n}\n.flex {\n display: flex;\n}\n.items-center {\n align-items: center;\n}\n.justify-center {\n justify-content: center;\n}\n.visual-box {\n position: relative;\n width: 100%;\n height: 100%;\n overflow-y: scroll;\n overflow-x: hidden;\n transition: all 0.3s;\n z-index: 3;\n background-color: #fff;\n}\n.Sqb {\n padding: 0 20px 50px;\n}\n.Sqb-list {\n padding-top: 1.5rem;\n}\n.Sqb-hover-parent {\n margin-bottom: 16px;\n padding-bottom: 16px;\n}\n.Sqb-item {\n font-size: 14px;\n}\n.Sqb-item--text {\n color: #509ee3;\n width: 66.6667%;\n box-sizing: border-box;\n margin-bottom: 8px;\n display: flex;\n align-items: center;\n font-weight: 600;\n}\n.Sqb-item--text.purple-text {\n color: #7172ad;\n}\n.Sqb-item--text.gray-text {\n color: #93a1ab;\n}\n.Sqb-item--text.green-text {\n color: #88bf4d;\n}\n.Sqb-item-close {\n width: 16px;\n height: 16px;\n color: #b8bbc3;\n margin-left: auto;\n visibility: hidden;\n cursor: pointer;\n}\n.Sqb-item--content {\n width: 66.6667%;\n box-sizing: border-box;\n}\n.Sqb-item--content .Sqb-NotebookCell {\n box-sizing: border-box;\n padding: 16px 16px 8px;\n color: #509ee3;\n display: flex;\n flex-wrap: wrap;\n -webkit-box-align: center;\n align-items: center;\n border-radius: 8px;\n background-color: rgba(80, 158, 227, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell.gray-bg {\n background-color: rgba(147, 161, 171, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell.green-bg {\n background-color: rgba(136, 191, 77, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName {\n border: 2px solid transparent;\n border-radius: 6px;\n color: white;\n background-color: #509ee3;\n transition: background 300ms linear 0s
|
|
339
|
+
var css_248z$b = ".mx-4 {\n margin-left: 1rem;\n margin-right: 1rem;\n}\n.m-2 {\n margin: 0.5rem;\n}\n.mx-2 {\n margin-left: 0.5rem;\n margin-right: 0.5rem;\n}\n.ml-2 {\n margin-left: 0.5rem;\n}\n.mt-2 {\n margin-top: 0.5rem;\n}\n.mb-2 {\n margin-bottom: 0.5rem;\n}\n.mt-4 {\n margin-top: 1rem;\n}\n.ml-4 {\n margin-left: 1rem;\n}\n.mr-4 {\n margin-right: 1rem;\n}\n.mr-2 {\n margin-right: 0.5rem;\n}\n.pt-2 {\n padding-top: 0.5rem;\n}\n.pb-2 {\n padding-bottom: 0.5rem;\n}\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n.p-4 {\n padding: 1rem;\n}\n.p-2 {\n padding: 0.5rem;\n}\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n.pb-4 {\n padding-bottom: 1rem;\n}\n.pt-4 {\n padding-top: 1rem;\n}\n.block {\n display: block;\n}\n.w-full {\n width: 100%;\n}\n.font-bold {\n font-weight: 700;\n}\n.uppercase {\n text-transform: uppercase;\n}\n.tracking-wider {\n letter-spacing: 0.05em;\n}\n.relative {\n position: relative;\n}\n.absolute {\n position: absolute;\n}\n.top-0 {\n top: 0px;\n}\n.left-0 {\n left: 0;\n}\n.rounded-lg {\n border-radius: 0.5rem;\n}\n.text-gray-500 {\n color: #6b7280;\n}\n.flex {\n display: flex;\n}\n.items-center {\n align-items: center;\n}\n.justify-center {\n justify-content: center;\n}\n.visual-box {\n position: relative;\n width: 100%;\n height: 100%;\n overflow-y: scroll;\n overflow-x: hidden;\n transition: all 0.3s;\n z-index: 3;\n background-color: #fff;\n}\n.Sqb {\n padding: 0 20px 50px;\n}\n.Sqb-list {\n padding-top: 1.5rem;\n}\n.Sqb-hover-parent {\n margin-bottom: 16px;\n padding-bottom: 16px;\n}\n.Sqb-item {\n font-size: 14px;\n}\n.Sqb-item--text {\n color: #509ee3;\n width: 66.6667%;\n box-sizing: border-box;\n margin-bottom: 8px;\n display: flex;\n align-items: center;\n font-weight: 600;\n}\n.Sqb-item--text.purple-text {\n color: #7172ad;\n}\n.Sqb-item--text.gray-text {\n color: #93a1ab;\n}\n.Sqb-item--text.green-text {\n color: #88bf4d;\n}\n.Sqb-item-close {\n width: 16px;\n height: 16px;\n color: #b8bbc3;\n margin-left: auto;\n visibility: hidden;\n cursor: pointer;\n}\n.Sqb-item--content {\n width: 66.6667%;\n box-sizing: border-box;\n}\n.Sqb-item--content .Sqb-NotebookCell {\n box-sizing: border-box;\n padding: 16px 16px 8px;\n color: #509ee3;\n display: flex;\n flex-wrap: wrap;\n -webkit-box-align: center;\n align-items: center;\n border-radius: 8px;\n background-color: rgba(80, 158, 227, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell.gray-bg {\n background-color: rgba(147, 161, 171, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell.green-bg {\n background-color: rgba(136, 191, 77, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName {\n border: 2px solid transparent;\n border-radius: 6px;\n color: white;\n background-color: #509ee3;\n transition: background 300ms linear 0s,\n border 300ms linear 0s;\n box-sizing: border-box;\n margin-bottom: 8px;\n margin-right: 8px;\n padding: 8px;\n display: flex;\n -webkit-box-align: center;\n align-items: center;\n cursor: pointer;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName::selection {\n color: #ffffff;\n background-color: #d489ac;\n text-shadow: none;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName:hover {\n background-color: rgba(80, 158, 227, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.noClick {\n cursor: default;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.noClick:hover {\n background-color: #509ee3;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.notSelected {\n border: 2px solid rgba(80, 158, 227, 0.25);\n color: #509ee3;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.notSelected:hover {\n border-color: rgba(80, 158, 227, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name {\n color: white;\n background-color: #7172ad;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name:hover {\n background-color: rgba(113, 114, 173, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name.notSelected {\n border: 2px solid rgba(113, 114, 173, 0.25);\n color: #7172ad;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name.notSelected:hover {\n border-color: rgba(113, 114, 173, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name {\n color: white;\n background-color: #93a1ab;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name:hover {\n background-color: rgba(147, 161, 171, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name svg.sort-arrow {\n margin-right: 0.5rem;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name {\n color: white;\n background-color: #88bf4d;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name:hover {\n background-color: rgba(136, 191, 77, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name.notSelected {\n border: 2px solid rgba(136, 191, 77, 0.25);\n color: #88bf4d;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name.notSelected:hover {\n border-color: rgba(136, 191, 77, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .ant-input-number {\n margin-bottom: 0.5rem;\n}\n.Sqb-item--content .Sqb-NotebookCell .ant-input-number .ant-input-number-input {\n height: 32px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-where {\n box-sizing: border-box;\n display: flex;\n -webkit-box-align: center;\n align-items: center;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableColumns {\n font-weight: 600;\n margin-bottom: 0.5rem;\n margin-left: auto;\n cursor: pointer;\n}\n.Sqb-item--content .flex-row {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n align-items: center;\n flex-direction: row;\n}\n.Sqb-item--content .flex-row .Sqb-NotebookCell {\n width: 50%;\n}\n.Sqb-item--content .flex-row .pass {\n color: #88bf4d;\n margin: 4px 16px;\n font-size: 600;\n}\n.Sqb-item--func {\n box-sizing: border-box;\n margin-top: 8px;\n}\n.Sqb-item--func .Sqb-button {\n display: inline-block;\n box-sizing: border-box;\n text-decoration: none;\n cursor: pointer;\n font-weight: bold;\n padding: 12px 16px;\n border-radius: 6px;\n margin-right: 16px;\n margin-top: 16px;\n border: none;\n transition: background 300ms ease 0s;\n flex-shrink: 0;\n color: #93a1ab;\n background-color: #ffffff;\n}\n.Sqb-item--func .Sqb-button:hover {\n color: #7e8f9b;\n background-color: #eceff0;\n}\n.Sqb-item--func .Sqb-button > div {\n min-width: 60px;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n display: flex;\n}\n.Sqb-item--func .Sqb-button > div svg {\n flex-shrink: 0;\n}\n.Sqb-item--func .Sqb-button > div div {\n margin-top: 0.5rem;\n}\n.Sqb-item--func .Sqb-button.filter {\n color: #7172ad;\n background-color: #e0e0ed;\n}\n.Sqb-item--func .Sqb-button.filter:hover {\n color: #5d5ea0;\n background-color: #cccce1;\n}\n.Sqb-item--func .Sqb-button.summarize {\n color: #88bf4d;\n background-color: #d8eac5;\n}\n.Sqb-item--func .Sqb-button.summarize:hover {\n color: #79ae3f;\n background-color: #cae2af;\n}\n.Sqb-item--func .Sqb-button.joinData {\n color: #509ee3;\n background-color: #f1f7fd;\n}\n.Sqb-item--func .Sqb-button.joinData:hover {\n color: #328dde;\n background-color: #d4e7f8;\n}\n.Sqb-item--func .Sqb-button.small {\n margin-right: 8px;\n margin-top: 0;\n padding: 0.5rem;\n}\n.Sqb-item--func .Sqb-button.small > div {\n min-width: 0;\n}\n.Sqb-item--func .Sqb-button.small > div svg {\n width: 14px;\n height: 14px;\n}\n.Sqb-item--func .Sqb-button.small > div div {\n display: none;\n}\n.Sqb-item:hover .Sqb-item-close {\n visibility: visible;\n}\n.Sqb > .Sqb-btn {\n min-width: 220px;\n height: 36px;\n border-radius: 6px;\n color: #ffffff;\n background: #509ee3;\n border: 1px solid #509ee3;\n}\n.Sqb > .Sqb-btn:hover {\n background-color: rgba(80, 158, 227, 0.8) !important;\n}\n";
|
|
340
340
|
styleInject(css_248z$b);
|
|
341
341
|
|
|
342
342
|
var SortEnum;
|
|
@@ -1901,6 +1901,11 @@ const sleep = (wait = 0) => {
|
|
|
1901
1901
|
const flatArray = arr => {
|
|
1902
1902
|
return [].concat.apply([], arr);
|
|
1903
1903
|
};
|
|
1904
|
+
const replaceTpl = (inputString, values) => {
|
|
1905
|
+
return inputString.replace(/\$\{([^}]*)\}/g, (match, variableName) => {
|
|
1906
|
+
return typeof values[variableName] !== 'undefined' ? String(values[variableName]) : match;
|
|
1907
|
+
});
|
|
1908
|
+
};
|
|
1904
1909
|
|
|
1905
1910
|
class WinResetEvent {
|
|
1906
1911
|
eventStack = {};
|
|
@@ -2165,6 +2170,11 @@ class SqlVisionStore {
|
|
|
2165
2170
|
makeAutoObservable(this);
|
|
2166
2171
|
}
|
|
2167
2172
|
showPermissionTable = false; // 开启权限表
|
|
2173
|
+
showFields = true; // 开启权限表
|
|
2174
|
+
//工具列表
|
|
2175
|
+
toolbar = ['filter', 'summarize', 'joinData', 'permissionTable', 'customColumn', 'sort', 'rowLimit'];
|
|
2176
|
+
fieldNameTpl = '${name}';
|
|
2177
|
+
tableNameTpl = '${name}';
|
|
2168
2178
|
sourceList = []; // 数据源列表
|
|
2169
2179
|
_cacheSource2TableMap = {}; // 数据源id 对应数据集列表
|
|
2170
2180
|
_cacheColumnsMap = {};
|
|
@@ -2225,8 +2235,50 @@ class SqlVisionStore {
|
|
|
2225
2235
|
// 回显
|
|
2226
2236
|
async setPreData(data) {
|
|
2227
2237
|
if (data.length) {
|
|
2228
|
-
this.metaList = data
|
|
2238
|
+
this.metaList = data.map((v, i) => {
|
|
2239
|
+
// 设置右侧column
|
|
2240
|
+
if (v.table2?.datasourceId && v.columns.length < 1) {
|
|
2241
|
+
// let newMetaList = this.metaList.slice() as MetaData[];
|
|
2242
|
+
let newMeta = data.slice();
|
|
2243
|
+
let tableName = newMeta[i].table2.name;
|
|
2244
|
+
this.fetchColumns(tableName, newMeta[i].table2.datasourceId, columns => {
|
|
2245
|
+
newMeta[i].columns = columns;
|
|
2246
|
+
this.setMeta(newMeta);
|
|
2247
|
+
});
|
|
2248
|
+
return {
|
|
2249
|
+
...v
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
// 设置column
|
|
2253
|
+
if (v.table?.datasourceId && v.columns.length < 1) {
|
|
2254
|
+
// let newMetaList = this.metaList.slice() as MetaData[];
|
|
2255
|
+
let newMeta = data.slice();
|
|
2256
|
+
let tableName = newMeta[i].table.name;
|
|
2257
|
+
this.fetchColumns(tableName, newMeta[i].table.datasourceId, columns => {
|
|
2258
|
+
newMeta[i].columns = columns;
|
|
2259
|
+
this.setMeta(newMeta);
|
|
2260
|
+
});
|
|
2261
|
+
return {
|
|
2262
|
+
...v
|
|
2263
|
+
};
|
|
2264
|
+
}
|
|
2265
|
+
return {
|
|
2266
|
+
...v
|
|
2267
|
+
};
|
|
2268
|
+
});
|
|
2229
2269
|
metaKey = Math.max.apply(null, this.metaList.map(v => Number(v.metaKey)));
|
|
2270
|
+
} else {
|
|
2271
|
+
this.setMeta([{
|
|
2272
|
+
metaKey,
|
|
2273
|
+
type: TypeEnum.data,
|
|
2274
|
+
table: {
|
|
2275
|
+
name: '',
|
|
2276
|
+
alias: '',
|
|
2277
|
+
datasourceId: '',
|
|
2278
|
+
datasourceName: ''
|
|
2279
|
+
},
|
|
2280
|
+
columns: []
|
|
2281
|
+
}]);
|
|
2230
2282
|
}
|
|
2231
2283
|
}
|
|
2232
2284
|
setSourceList(list) {
|
|
@@ -2247,6 +2299,7 @@ class SqlVisionStore {
|
|
|
2247
2299
|
};
|
|
2248
2300
|
if (index === 1) {
|
|
2249
2301
|
table1 = {
|
|
2302
|
+
...mainTable.table,
|
|
2250
2303
|
name: mainTable.table.name,
|
|
2251
2304
|
alias: mainTable.table.alias,
|
|
2252
2305
|
datasourceId: mainTable.table.datasourceId,
|
|
@@ -2364,6 +2417,18 @@ class SqlVisionStore {
|
|
|
2364
2417
|
setShowPermissionTable(show) {
|
|
2365
2418
|
this.showPermissionTable = show;
|
|
2366
2419
|
}
|
|
2420
|
+
setShowFields(show) {
|
|
2421
|
+
this.showFields = show;
|
|
2422
|
+
}
|
|
2423
|
+
setToolbar(toolbar) {
|
|
2424
|
+
this.toolbar = toolbar;
|
|
2425
|
+
}
|
|
2426
|
+
setFieldNameTpl(tpl) {
|
|
2427
|
+
this.fieldNameTpl = tpl;
|
|
2428
|
+
}
|
|
2429
|
+
setTableNameTpl(tpl) {
|
|
2430
|
+
this.tableNameTpl = tpl;
|
|
2431
|
+
}
|
|
2367
2432
|
}
|
|
2368
2433
|
const sqlVisionStore = new SqlVisionStore();
|
|
2369
2434
|
const Store = /*#__PURE__*/React__default.createContext(sqlVisionStore);
|
|
@@ -3125,7 +3190,7 @@ const SelectJoinColumn = ({
|
|
|
3125
3190
|
onGroup,
|
|
3126
3191
|
didUpdate
|
|
3127
3192
|
}) => {
|
|
3128
|
-
useStore();
|
|
3193
|
+
const store = useStore();
|
|
3129
3194
|
const [curTable, setCurTable] = useState(value.alias); // 当前选择的表
|
|
3130
3195
|
const [curColumn, setCurColumn] = useState(value.name); // 当前选择的字段
|
|
3131
3196
|
const [tableList, setTableList] = useState(_data.map((v, i) => {
|
|
@@ -3259,6 +3324,7 @@ const SelectJoinColumn = ({
|
|
|
3259
3324
|
let condition = '';
|
|
3260
3325
|
let quotes = name;
|
|
3261
3326
|
return onGroup({
|
|
3327
|
+
...v,
|
|
3262
3328
|
table,
|
|
3263
3329
|
alias: tableAlias,
|
|
3264
3330
|
name,
|
|
@@ -3269,6 +3335,7 @@ const SelectJoinColumn = ({
|
|
|
3269
3335
|
});
|
|
3270
3336
|
}
|
|
3271
3337
|
typeof onSelect === 'function' && onSelect({
|
|
3338
|
+
...v,
|
|
3272
3339
|
table,
|
|
3273
3340
|
alias: tableAlias,
|
|
3274
3341
|
name,
|
|
@@ -3287,7 +3354,7 @@ const SelectJoinColumn = ({
|
|
|
3287
3354
|
}), jsx("div", {
|
|
3288
3355
|
children: jsx("h4", {
|
|
3289
3356
|
className: 'List-item-title ml-2',
|
|
3290
|
-
children:
|
|
3357
|
+
children: replaceTpl(store.fieldNameTpl, v)
|
|
3291
3358
|
})
|
|
3292
3359
|
})]
|
|
3293
3360
|
}), OPEN_GROUP]
|
|
@@ -4158,7 +4225,7 @@ const SelectTable = ({
|
|
|
4158
4225
|
}), jsx("div", {
|
|
4159
4226
|
children: jsx("h4", {
|
|
4160
4227
|
className: 'List-item-title ml-2',
|
|
4161
|
-
children: v
|
|
4228
|
+
children: replaceTpl(store.tableNameTpl, v)
|
|
4162
4229
|
})
|
|
4163
4230
|
})]
|
|
4164
4231
|
})
|
|
@@ -4317,19 +4384,23 @@ const IconTypeMap = new Map([[TypeEnum.filter, {
|
|
|
4317
4384
|
}], [TypeEnum.joinData, {
|
|
4318
4385
|
name: __('SqlQueryBuilder.joinData'),
|
|
4319
4386
|
icon: jsx(JoinDataIcon, {}),
|
|
4320
|
-
className: '
|
|
4387
|
+
className: 'joinData'
|
|
4321
4388
|
}], [TypeEnum.permissionTable, {
|
|
4322
4389
|
name: __('SqlQueryBuilder.permissionTable'),
|
|
4323
|
-
icon: jsx(PermissionTableIcon, {})
|
|
4390
|
+
icon: jsx(PermissionTableIcon, {}),
|
|
4391
|
+
className: 'permissionTable'
|
|
4324
4392
|
}], [TypeEnum.customColumn, {
|
|
4325
4393
|
name: __('SqlQueryBuilder.customColumn'),
|
|
4326
|
-
icon: jsx(CustomColumnIcon, {})
|
|
4394
|
+
icon: jsx(CustomColumnIcon, {}),
|
|
4395
|
+
className: 'customColumn'
|
|
4327
4396
|
}], [TypeEnum.sort, {
|
|
4328
4397
|
name: __('SqlQueryBuilder.sort'),
|
|
4329
|
-
icon: jsx(SortIcon, {})
|
|
4398
|
+
icon: jsx(SortIcon, {}),
|
|
4399
|
+
className: 'sort'
|
|
4330
4400
|
}], [TypeEnum.rowLimit, {
|
|
4331
4401
|
name: __('SqlQueryBuilder.rowLimit'),
|
|
4332
|
-
icon: jsx(RowLimitIcon, {})
|
|
4402
|
+
icon: jsx(RowLimitIcon, {}),
|
|
4403
|
+
className: 'rowLimit'
|
|
4333
4404
|
}]]);
|
|
4334
4405
|
// 前端展示的icon顺序 随便改不影响逻辑
|
|
4335
4406
|
const DisplayOrder = [TypeEnum.filter, TypeEnum.summarize, TypeEnum.joinData, TypeEnum.permissionTable, TypeEnum.customColumn, TypeEnum.sort, TypeEnum.rowLimit];
|
|
@@ -4375,11 +4446,10 @@ const metaIcon = (size, handleClick) => {
|
|
|
4375
4446
|
3)特殊情况二 如果最后一个是排序,下面是small
|
|
4376
4447
|
*/
|
|
4377
4448
|
// 判断icon大小
|
|
4378
|
-
const judgeSize = (props, nextLen) => {
|
|
4449
|
+
const judgeSize = (store, props, nextLen) => {
|
|
4379
4450
|
let {
|
|
4380
4451
|
meta
|
|
4381
4452
|
} = props;
|
|
4382
|
-
const store = useStore();
|
|
4383
4453
|
let {
|
|
4384
4454
|
type
|
|
4385
4455
|
} = meta;
|
|
@@ -4403,11 +4473,10 @@ const judgeSize = (props, nextLen) => {
|
|
|
4403
4473
|
/**
|
|
4404
4474
|
* 查找模块下面能放哪些icon (参考来源:metabase.com)
|
|
4405
4475
|
*/
|
|
4406
|
-
const findNextIcon = props => {
|
|
4476
|
+
const findNextIcon = (store, props) => {
|
|
4407
4477
|
const {
|
|
4408
4478
|
meta
|
|
4409
4479
|
} = props;
|
|
4410
|
-
const store = useStore();
|
|
4411
4480
|
let {
|
|
4412
4481
|
type
|
|
4413
4482
|
} = meta;
|
|
@@ -4575,11 +4644,11 @@ const NextDom = props => {
|
|
|
4575
4644
|
const store = useStore();
|
|
4576
4645
|
// @ts-ignore
|
|
4577
4646
|
if (!store.metaList[0].table.name) return null;
|
|
4578
|
-
let available = findNextIcon(props);
|
|
4647
|
+
let available = findNextIcon(store, props);
|
|
4579
4648
|
if (!store.showPermissionTable) {
|
|
4580
4649
|
available = available.filter(v => v !== TypeEnum.permissionTable);
|
|
4581
4650
|
}
|
|
4582
|
-
let size = judgeSize(props, available.length);
|
|
4651
|
+
let size = judgeSize(store, props, available.length);
|
|
4583
4652
|
function handleClick(type) {
|
|
4584
4653
|
let index = store.metaList.indexOf(meta);
|
|
4585
4654
|
store.addMeta(type, index + 1);
|
|
@@ -4587,7 +4656,7 @@ const NextDom = props => {
|
|
|
4587
4656
|
const MetaIconDom = metaIcon(size, handleClick);
|
|
4588
4657
|
return jsx("div", {
|
|
4589
4658
|
className: `Sqb-item--func`,
|
|
4590
|
-
children: sortList(available).map(v => jsx(MetaIconDom, {
|
|
4659
|
+
children: sortList(available).filter(v => ~store.toolbar.indexOf(v)).map(v => jsx(MetaIconDom, {
|
|
4591
4660
|
type: v
|
|
4592
4661
|
}, v))
|
|
4593
4662
|
});
|
|
@@ -4671,7 +4740,7 @@ const TableData = props => {
|
|
|
4671
4740
|
}),
|
|
4672
4741
|
onClick: selectTable,
|
|
4673
4742
|
children: selected ? `${meta.table.datasourceName}.${meta.table.name}` : __('SqlQueryBuilder.pickTable')
|
|
4674
|
-
}), selected && store.showMainColumn && jsx("div", {
|
|
4743
|
+
}), selected && store.showMainColumn && store.showFields && jsx("div", {
|
|
4675
4744
|
className: `Sqb-TableColumns`,
|
|
4676
4745
|
onClick: selectColumns,
|
|
4677
4746
|
children: __('SqlQueryBuilder.columns')
|
|
@@ -4764,6 +4833,7 @@ const JoinData = props => {
|
|
|
4764
4833
|
}
|
|
4765
4834
|
}
|
|
4766
4835
|
newMeta[index].table2 = {
|
|
4836
|
+
...data,
|
|
4767
4837
|
name: tableName,
|
|
4768
4838
|
alias,
|
|
4769
4839
|
column: '',
|
|
@@ -4829,6 +4899,7 @@ const JoinData = props => {
|
|
|
4829
4899
|
if (prevGroupBy?.group?.length) {
|
|
4830
4900
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
4831
4901
|
return {
|
|
4902
|
+
...v,
|
|
4832
4903
|
name: v.quotes,
|
|
4833
4904
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
4834
4905
|
special_type: '',
|
|
@@ -4840,6 +4911,7 @@ const JoinData = props => {
|
|
|
4840
4911
|
if (prevGroupBy?.by?.length) {
|
|
4841
4912
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
4842
4913
|
return {
|
|
4914
|
+
...v,
|
|
4843
4915
|
name: v.quotes,
|
|
4844
4916
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
4845
4917
|
special_type: '',
|
|
@@ -4991,7 +5063,7 @@ const JoinData = props => {
|
|
|
4991
5063
|
onClick: selectJoinColumn,
|
|
4992
5064
|
children: meta.table2.column ? meta.table2.column : __('SqlQueryBuilder.pickTable')
|
|
4993
5065
|
})]
|
|
4994
|
-
}), columnsSelected && jsx("div", {
|
|
5066
|
+
}), columnsSelected && store.showFields && jsx("div", {
|
|
4995
5067
|
className: `Sqb-TableColumns`,
|
|
4996
5068
|
onClick: selectColumns,
|
|
4997
5069
|
children: __('SqlQueryBuilder.columns')
|
|
@@ -5169,8 +5241,10 @@ const Filter = props => {
|
|
|
5169
5241
|
if (prevGroupBy?.group?.length) {
|
|
5170
5242
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
5171
5243
|
return {
|
|
5244
|
+
name_zh: v.quotes,
|
|
5245
|
+
...v,
|
|
5172
5246
|
name: v.quotes,
|
|
5173
|
-
name_zh: '',
|
|
5247
|
+
// name_zh: '',
|
|
5174
5248
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5175
5249
|
sql: v.sql,
|
|
5176
5250
|
special_type: '',
|
|
@@ -5181,8 +5255,10 @@ const Filter = props => {
|
|
|
5181
5255
|
if (prevGroupBy?.by?.length) {
|
|
5182
5256
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
5183
5257
|
return {
|
|
5258
|
+
name_zh: v.quotes,
|
|
5259
|
+
...v,
|
|
5184
5260
|
name: v.quotes,
|
|
5185
|
-
name_zh: '',
|
|
5261
|
+
// name_zh: '',
|
|
5186
5262
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5187
5263
|
sql: v.sql,
|
|
5188
5264
|
special_type: '',
|
|
@@ -5360,9 +5436,11 @@ const GroupBy = props => {
|
|
|
5360
5436
|
if (prevGroupBy?.group?.length) {
|
|
5361
5437
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
5362
5438
|
return {
|
|
5439
|
+
name_zh: v.quotes,
|
|
5440
|
+
...v,
|
|
5363
5441
|
name: v.quotes,
|
|
5364
5442
|
realName: v.sql?.split(' AS ')?.[1] || '',
|
|
5365
|
-
name_zh: '',
|
|
5443
|
+
// name_zh: '',
|
|
5366
5444
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5367
5445
|
special_type: '',
|
|
5368
5446
|
select: true
|
|
@@ -5372,9 +5450,11 @@ const GroupBy = props => {
|
|
|
5372
5450
|
if (prevGroupBy?.by?.length) {
|
|
5373
5451
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
5374
5452
|
return {
|
|
5453
|
+
name_zh: v.quotes,
|
|
5454
|
+
...v,
|
|
5375
5455
|
name: v.quotes,
|
|
5376
5456
|
realName: v.sql?.split(' AS ')?.[1] || '',
|
|
5377
|
-
name_zh: '',
|
|
5457
|
+
// name_zh: '',
|
|
5378
5458
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5379
5459
|
special_type: '',
|
|
5380
5460
|
select: true
|
|
@@ -5434,6 +5514,7 @@ const GroupBy = props => {
|
|
|
5434
5514
|
isGroup: true,
|
|
5435
5515
|
// @ts-ignore
|
|
5436
5516
|
onGroup: data => {
|
|
5517
|
+
console.log('🚀 ~ handleUpdate ~ data:', data);
|
|
5437
5518
|
// @ts-ignore
|
|
5438
5519
|
newMeta[index].by.splice(i, 1, data);
|
|
5439
5520
|
// @ts-ignore
|
|
@@ -5474,6 +5555,7 @@ const GroupBy = props => {
|
|
|
5474
5555
|
isGroup: true,
|
|
5475
5556
|
// @ts-ignore
|
|
5476
5557
|
onGroup: data => {
|
|
5558
|
+
console.log('🚀 ~ handleAdd ~ data:', data);
|
|
5477
5559
|
// @ts-ignore
|
|
5478
5560
|
newMeta[index].by.push(data);
|
|
5479
5561
|
// @ts-ignore
|
|
@@ -5969,9 +6051,11 @@ const SelectIndex = props => {
|
|
|
5969
6051
|
if (prevGroupBy?.group?.length) {
|
|
5970
6052
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
5971
6053
|
return {
|
|
6054
|
+
name_zh: v.quotes,
|
|
6055
|
+
...v,
|
|
5972
6056
|
name: v.quotes,
|
|
5973
6057
|
realName: v.sql?.split(' AS ')?.[1] || '',
|
|
5974
|
-
name_zh: '',
|
|
6058
|
+
// name_zh: '',
|
|
5975
6059
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5976
6060
|
special_type: '',
|
|
5977
6061
|
select: true
|
|
@@ -5981,9 +6065,11 @@ const SelectIndex = props => {
|
|
|
5981
6065
|
if (prevGroupBy?.by?.length) {
|
|
5982
6066
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
5983
6067
|
return {
|
|
6068
|
+
name_zh: v.quotes,
|
|
6069
|
+
...v,
|
|
5984
6070
|
name: v.quotes,
|
|
5985
6071
|
realName: v.sql?.split(' AS ')?.[1] || '',
|
|
5986
|
-
name_zh: '',
|
|
6072
|
+
// name_zh: '',
|
|
5987
6073
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
5988
6074
|
special_type: '',
|
|
5989
6075
|
select: true
|
|
@@ -6201,8 +6287,10 @@ const Sort = props => {
|
|
|
6201
6287
|
if (prevGroupBy?.group?.length) {
|
|
6202
6288
|
_data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
|
|
6203
6289
|
return {
|
|
6290
|
+
name_zh: v.quotes,
|
|
6291
|
+
...v,
|
|
6204
6292
|
name: v.quotes,
|
|
6205
|
-
name_zh: '',
|
|
6293
|
+
// name_zh: '',
|
|
6206
6294
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
6207
6295
|
special_type: '',
|
|
6208
6296
|
sql: v.sql,
|
|
@@ -6213,8 +6301,10 @@ const Sort = props => {
|
|
|
6213
6301
|
if (prevGroupBy?.by?.length) {
|
|
6214
6302
|
_data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
|
|
6215
6303
|
return {
|
|
6304
|
+
name_zh: v.quotes,
|
|
6305
|
+
...v,
|
|
6216
6306
|
name: v.quotes,
|
|
6217
|
-
name_zh: '',
|
|
6307
|
+
// name_zh: '',
|
|
6218
6308
|
database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
|
|
6219
6309
|
special_type: '',
|
|
6220
6310
|
sql: v.sql,
|
|
@@ -6618,24 +6708,37 @@ const Metabase = observer(props => {
|
|
|
6618
6708
|
const SqlVisionBuilder = /*#__PURE__*/React__default.forwardRef((props, ref) => {
|
|
6619
6709
|
let {
|
|
6620
6710
|
loading = false,
|
|
6621
|
-
showPermissionTable,
|
|
6711
|
+
showPermissionTable = false,
|
|
6712
|
+
showFields = true,
|
|
6622
6713
|
getTables,
|
|
6623
|
-
getColumns
|
|
6714
|
+
getColumns,
|
|
6715
|
+
tableNameTpl = '${name}',
|
|
6716
|
+
fieldNameTpl = '${name}',
|
|
6717
|
+
toolbar = ['filter', 'summarize', 'joinData', 'permissionTable', 'customColumn', 'sort', 'rowLimit']
|
|
6624
6718
|
} = props;
|
|
6625
6719
|
const store = useStore();
|
|
6720
|
+
const [preData, setPreData] = useState([]);
|
|
6626
6721
|
useEffect(() => {
|
|
6627
6722
|
getTables && store.setFetchDatasetFn(getTables);
|
|
6628
6723
|
getColumns && store.setFetchColumnsFn(getColumns);
|
|
6629
|
-
if (showPermissionTable) {
|
|
6630
|
-
store.setShowPermissionTable(showPermissionTable);
|
|
6631
|
-
}
|
|
6632
6724
|
}, []);
|
|
6725
|
+
useEffect(() => {
|
|
6726
|
+
store.setShowPermissionTable(showPermissionTable);
|
|
6727
|
+
store.setShowFields(showFields);
|
|
6728
|
+
store.setToolbar(toolbar || []);
|
|
6729
|
+
store.setFieldNameTpl(fieldNameTpl || '${name}');
|
|
6730
|
+
store.setTableNameTpl(tableNameTpl || '${name}');
|
|
6731
|
+
}, [showFields, showPermissionTable, toolbar, fieldNameTpl, tableNameTpl]);
|
|
6633
6732
|
React__default.useImperativeHandle(ref, () => ({
|
|
6634
6733
|
setDatasource: list => {
|
|
6635
6734
|
store.setSourceList(list);
|
|
6636
6735
|
},
|
|
6637
6736
|
setPreData: data => {
|
|
6638
6737
|
store.setPreData(data);
|
|
6738
|
+
setPreData(data);
|
|
6739
|
+
},
|
|
6740
|
+
reset: () => {
|
|
6741
|
+
store.setPreData(preData);
|
|
6639
6742
|
}
|
|
6640
6743
|
}));
|
|
6641
6744
|
// ② 表集合没有查出来前 不加载页面
|