@nocobase/plugin-charts 0.11.1-alpha.4 → 0.12.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +2 -3
- package/client.js +1 -1
- package/{lib → dist}/client/index.d.ts +1 -0
- package/dist/client/index.js +3234 -0
- package/{lib → dist}/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/locale/en-US.js +26 -0
- package/{src/locale/es-ES.ts → dist/locale/es-ES.js} +22 -18
- package/dist/locale/fr-FR.js +5 -0
- package/dist/locale/ja-JP.js +5 -0
- package/dist/locale/pt-BR.js +26 -0
- package/dist/locale/ru-RU.js +5 -0
- package/dist/locale/tr-TR.js +5 -0
- package/dist/locale/zh-CN.js +65 -0
- package/dist/node_modules/json5/dist/index.js +1737 -0
- package/dist/node_modules/json5/dist/index.min.js +1 -0
- package/dist/node_modules/json5/lib/cli.js +152 -0
- package/dist/node_modules/json5/lib/index.d.ts +4 -0
- package/dist/node_modules/json5/lib/index.js +1 -0
- package/dist/node_modules/json5/lib/parse.d.ts +15 -0
- package/dist/node_modules/json5/lib/parse.js +1114 -0
- package/dist/node_modules/json5/lib/register.js +13 -0
- package/dist/node_modules/json5/lib/require.js +4 -0
- package/dist/node_modules/json5/lib/stringify.d.ts +89 -0
- package/dist/node_modules/json5/lib/stringify.js +261 -0
- package/dist/node_modules/json5/lib/unicode.d.ts +3 -0
- package/dist/node_modules/json5/lib/unicode.js +4 -0
- package/dist/node_modules/json5/lib/util.d.ts +5 -0
- package/dist/node_modules/json5/lib/util.js +35 -0
- package/dist/node_modules/json5/package.json +1 -0
- package/dist/server/actions/chartsQueries.js +57 -0
- package/dist/server/actions/index.js +2 -0
- package/dist/server/collections/chartsQueries.js +30 -0
- package/dist/server/index.js +11 -0
- package/dist/server/plugin.js +66 -0
- package/dist/server/query.js +39 -0
- package/dist/server/shared/index.js +5 -0
- package/package.json +17 -28
- package/server.d.ts +2 -3
- package/server.js +1 -1
- package/lib/client/ChartBlockEngine.js +0 -146
- package/lib/client/ChartBlockEngineDesigner.js +0 -293
- package/lib/client/ChartBlockInitializer.js +0 -263
- package/lib/client/ChartQueryBlockInitializer.js +0 -191
- package/lib/client/ChartQueryMetadataProvider.js +0 -91
- package/lib/client/DataSetPreviewTable.js +0 -113
- package/lib/client/Icons.js +0 -210
- package/lib/client/chartRenderComponents/index.js +0 -20
- package/lib/client/hooks/index.js +0 -38
- package/lib/client/index.js +0 -143
- package/lib/client/locale/index.js +0 -37
- package/lib/client/select/CustomSelect.js +0 -148
- package/lib/client/select/ReadPretty.js +0 -77
- package/lib/client/select/index.js +0 -27
- package/lib/client/select/shared.js +0 -66
- package/lib/client/settings/AddNewQuery.js +0 -270
- package/lib/client/settings/ConfigureFields.js +0 -39
- package/lib/client/settings/QueriesTable.js +0 -77
- package/lib/client/settings/queryTypes.js +0 -77
- package/lib/client/settings/schemas/chartsQueries.js +0 -353
- package/lib/client/templates/AreaTemplate.js +0 -81
- package/lib/client/templates/BarTemplate.js +0 -98
- package/lib/client/templates/ColumnTemplate.js +0 -98
- package/lib/client/templates/FunnelTemplate.js +0 -82
- package/lib/client/templates/LineTemplate.js +0 -89
- package/lib/client/templates/PieTemplate.js +0 -87
- package/lib/client/templates/RadarTemplate.js +0 -88
- package/lib/client/templates/ScatterTemplate.js +0 -107
- package/lib/client/templates/TableTemplate.js +0 -54
- package/lib/client/templates/index.js +0 -25
- package/lib/client/utils.js +0 -50
- package/lib/index.js +0 -13
- package/lib/locale/en-US.js +0 -29
- package/lib/locale/es-ES.js +0 -59
- package/lib/locale/fr-FR.js +0 -8
- package/lib/locale/ja-JP.js +0 -8
- package/lib/locale/pt-BR.js +0 -29
- package/lib/locale/ru-RU.js +0 -8
- package/lib/locale/tr-TR.js +0 -8
- package/lib/locale/zh-CN.js +0 -68
- package/lib/server/actions/chartsQueries.js +0 -89
- package/lib/server/actions/index.js +0 -1
- package/lib/server/collections/chartsQueries.js +0 -33
- package/lib/server/index.js +0 -13
- package/lib/server/plugin.js +0 -106
- package/lib/server/query.js +0 -71
- package/lib/server/shared/index.js +0 -8
- package/src/client/ChartBlockEngine.tsx +0 -121
- package/src/client/ChartBlockEngineDesigner.tsx +0 -248
- package/src/client/ChartBlockInitializer.tsx +0 -223
- package/src/client/ChartQueryBlockInitializer.tsx +0 -156
- package/src/client/ChartQueryMetadataProvider.tsx +0 -64
- package/src/client/DataSetPreviewTable.tsx +0 -71
- package/src/client/Icons.tsx +0 -99
- package/src/client/chartRenderComponents/index.ts +0 -7
- package/src/client/hooks/index.ts +0 -19
- package/src/client/index.tsx +0 -115
- package/src/client/locale/index.ts +0 -18
- package/src/client/select/CustomSelect.tsx +0 -126
- package/src/client/select/ReadPretty.tsx +0 -39
- package/src/client/select/index.md +0 -31
- package/src/client/select/index.ts +0 -2
- package/src/client/select/shared.ts +0 -37
- package/src/client/settings/AddNewQuery.tsx +0 -176
- package/src/client/settings/ConfigureFields.tsx +0 -18
- package/src/client/settings/QueriesTable.tsx +0 -26
- package/src/client/settings/queryTypes.ts +0 -65
- package/src/client/settings/schemas/chartsQueries.ts +0 -319
- package/src/client/templates/AreaTemplate.tsx +0 -64
- package/src/client/templates/BarTemplate.tsx +0 -80
- package/src/client/templates/ColumnTemplate.tsx +0 -81
- package/src/client/templates/FunnelTemplate.tsx +0 -65
- package/src/client/templates/LineTemplate.tsx +0 -72
- package/src/client/templates/PieTemplate.tsx +0 -68
- package/src/client/templates/RadarTemplate.tsx +0 -71
- package/src/client/templates/ScatterTemplate.tsx +0 -90
- package/src/client/templates/TableTemplate.tsx +0 -48
- package/src/client/templates/index.ts +0 -21
- package/src/client/utils.ts +0 -39
- package/src/index.ts +0 -1
- package/src/locale/en-US.ts +0 -23
- package/src/locale/fr-FR.ts +0 -1
- package/src/locale/ja-JP.ts +0 -1
- package/src/locale/pt-BR.ts +0 -23
- package/src/locale/ru-RU.ts +0 -1
- package/src/locale/tr-TR.ts +0 -1
- package/src/locale/zh-CN.ts +0 -64
- package/src/server/actions/chartsQueries.ts +0 -49
- package/src/server/actions/index.ts +0 -0
- package/src/server/collections/.gitkeep +0 -0
- package/src/server/collections/chartsQueries.ts +0 -26
- package/src/server/index.ts +0 -1
- package/src/server/plugin.ts +0 -61
- package/src/server/query.ts +0 -39
- package/src/server/shared/index.ts +0 -2
- /package/{lib → dist}/client/ChartBlockEngine.d.ts +0 -0
- /package/{lib → dist}/client/ChartBlockEngineDesigner.d.ts +0 -0
- /package/{lib → dist}/client/ChartBlockInitializer.d.ts +0 -0
- /package/{lib → dist}/client/ChartQueryBlockInitializer.d.ts +0 -0
- /package/{lib → dist}/client/ChartQueryMetadataProvider.d.ts +0 -0
- /package/{lib → dist}/client/DataSetPreviewTable.d.ts +0 -0
- /package/{lib → dist}/client/Icons.d.ts +0 -0
- /package/{lib → dist}/client/chartRenderComponents/index.d.ts +0 -0
- /package/{lib → dist}/client/hooks/index.d.ts +0 -0
- /package/{lib → dist}/client/locale/index.d.ts +0 -0
- /package/{lib → dist}/client/select/CustomSelect.d.ts +0 -0
- /package/{lib → dist}/client/select/ReadPretty.d.ts +0 -0
- /package/{lib → dist}/client/select/index.d.ts +0 -0
- /package/{lib → dist}/client/select/shared.d.ts +0 -0
- /package/{lib → dist}/client/settings/AddNewQuery.d.ts +0 -0
- /package/{lib → dist}/client/settings/ConfigureFields.d.ts +0 -0
- /package/{lib → dist}/client/settings/QueriesTable.d.ts +0 -0
- /package/{lib → dist}/client/settings/queryTypes.d.ts +0 -0
- /package/{lib → dist}/client/settings/schemas/chartsQueries.d.ts +0 -0
- /package/{lib → dist}/client/templates/AreaTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/BarTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/ColumnTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/FunnelTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/LineTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/PieTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/RadarTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/ScatterTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/TableTemplate.d.ts +0 -0
- /package/{lib → dist}/client/templates/index.d.ts +0 -0
- /package/{lib → dist}/client/utils.d.ts +0 -0
- /package/{lib → dist}/locale/en-US.d.ts +0 -0
- /package/{lib → dist}/locale/es-ES.d.ts +0 -0
- /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
- /package/{lib → dist}/locale/ja-JP.d.ts +0 -0
- /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
- /package/{lib → dist}/locale/ru-RU.d.ts +0 -0
- /package/{lib → dist}/locale/tr-TR.d.ts +0 -0
- /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/actions/chartsQueries.d.ts +0 -0
- /package/{lib → dist}/server/actions/index.d.ts +0 -0
- /package/{lib → dist}/server/collections/chartsQueries.d.ts +0 -0
- /package/{lib → dist}/server/index.d.ts +0 -0
- /package/{lib → dist}/server/plugin.d.ts +0 -0
- /package/{lib → dist}/server/query.d.ts +0 -0
- /package/{lib → dist}/server/shared/index.d.ts +0 -0
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { FormLayout } from '@formily/antd-v5';
|
|
2
|
-
import { SchemaOptionsContext, useField, useFieldSchema } from '@formily/react';
|
|
3
|
-
import {
|
|
4
|
-
APIClientProvider,
|
|
5
|
-
FormDialog,
|
|
6
|
-
GeneralSchemaDesigner,
|
|
7
|
-
SchemaComponent,
|
|
8
|
-
SchemaComponentOptions,
|
|
9
|
-
SchemaSettings,
|
|
10
|
-
css,
|
|
11
|
-
i18n,
|
|
12
|
-
useAPIClient,
|
|
13
|
-
useCompile,
|
|
14
|
-
useDesignable,
|
|
15
|
-
useGlobalTheme,
|
|
16
|
-
} from '@nocobase/client';
|
|
17
|
-
import { error } from '@nocobase/utils/client';
|
|
18
|
-
import { Card } from 'antd';
|
|
19
|
-
import JSON5 from 'json5';
|
|
20
|
-
import React, { useContext, useEffect, useState } from 'react';
|
|
21
|
-
import { useTranslation } from 'react-i18next';
|
|
22
|
-
import { ChartBlockEngineMetaData } from './ChartBlockEngine';
|
|
23
|
-
import { Options } from './ChartBlockInitializer';
|
|
24
|
-
import DataSetPreviewTable from './DataSetPreviewTable';
|
|
25
|
-
import { useFieldsById } from './hooks';
|
|
26
|
-
import { lang } from './locale';
|
|
27
|
-
import { templates } from './templates';
|
|
28
|
-
|
|
29
|
-
export const jsonConfigDesc = (title: string, link: string) => {
|
|
30
|
-
return (
|
|
31
|
-
<span>
|
|
32
|
-
{lang('Json config references: ')}
|
|
33
|
-
<a href={link} target="_blank" rel="noreferrer">
|
|
34
|
-
{lang(title)}
|
|
35
|
-
</a>
|
|
36
|
-
</span>
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const validateJSON = {
|
|
41
|
-
validator: `{{(value, rule)=> {
|
|
42
|
-
if (!value) {
|
|
43
|
-
return '';
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
const val = JSON.parse(value);
|
|
47
|
-
if(!isNaN(val)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
} catch(error) {
|
|
52
|
-
console.error(error);
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}}}`,
|
|
56
|
-
message: '{{t("Invalid JSON format",{ ns: "charts" })}}',
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const ChartBlockEngineDesigner = () => {
|
|
60
|
-
const fieldSchema = useFieldSchema();
|
|
61
|
-
const { chartBlockEngineMetaData } = fieldSchema?.['x-component-props'];
|
|
62
|
-
return (
|
|
63
|
-
<GeneralSchemaDesigner>
|
|
64
|
-
<ChartBlockEngineDesignerInitializer chartBlockEngineMetaData={chartBlockEngineMetaData} />
|
|
65
|
-
<SchemaSettings.Divider />
|
|
66
|
-
<SchemaSettings.Remove
|
|
67
|
-
removeParentsIfNoChildren
|
|
68
|
-
breakRemoveOn={{
|
|
69
|
-
'x-component': 'Grid',
|
|
70
|
-
}}
|
|
71
|
-
/>
|
|
72
|
-
</GeneralSchemaDesigner>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const ChartBlockEngineDesignerInitializer = (props) => {
|
|
77
|
-
const { chartBlockEngineMetaData }: { chartBlockEngineMetaData: ChartBlockEngineMetaData } = props;
|
|
78
|
-
const { t } = useTranslation();
|
|
79
|
-
const options = useContext(SchemaOptionsContext);
|
|
80
|
-
const { dn } = useDesignable();
|
|
81
|
-
const fieldSchema = useFieldSchema();
|
|
82
|
-
const api = useAPIClient();
|
|
83
|
-
const field = useField();
|
|
84
|
-
const compile = useCompile();
|
|
85
|
-
const { chart, query } = chartBlockEngineMetaData;
|
|
86
|
-
const { fields } = useFieldsById(query.id);
|
|
87
|
-
const { theme } = useGlobalTheme();
|
|
88
|
-
|
|
89
|
-
const dataSource = fields.map((field) => {
|
|
90
|
-
return {
|
|
91
|
-
label: field.name,
|
|
92
|
-
value: field.name,
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<SchemaSettings.Item
|
|
98
|
-
onClick={async () => {
|
|
99
|
-
FormDialog(
|
|
100
|
-
{
|
|
101
|
-
okText: compile('{{t("Submit")}}'),
|
|
102
|
-
title: lang('Edit chart block'),
|
|
103
|
-
width: 1200,
|
|
104
|
-
bodyStyle: { background: 'var(--nb-box-bg)', maxHeight: '65vh', overflow: 'auto' },
|
|
105
|
-
},
|
|
106
|
-
function Com(form) {
|
|
107
|
-
const [chartBlockEngineMetaData, setChartBlockEngineMetaData] = useState<ChartBlockEngineMetaData>(null);
|
|
108
|
-
useEffect(() => {
|
|
109
|
-
const chartBlockEngineMetaData = {
|
|
110
|
-
query: {
|
|
111
|
-
id: query?.id,
|
|
112
|
-
},
|
|
113
|
-
chart: form.values, //TODO
|
|
114
|
-
};
|
|
115
|
-
setChartBlockEngineMetaData(chartBlockEngineMetaData);
|
|
116
|
-
}, [form.values.type]);
|
|
117
|
-
return (
|
|
118
|
-
<APIClientProvider apiClient={api}>
|
|
119
|
-
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
|
120
|
-
<section
|
|
121
|
-
className={css`
|
|
122
|
-
display: flex;
|
|
123
|
-
gap: 24px;
|
|
124
|
-
`}
|
|
125
|
-
>
|
|
126
|
-
{/* left*/}
|
|
127
|
-
<Card
|
|
128
|
-
bordered={false}
|
|
129
|
-
title={i18n.t('Chart config')}
|
|
130
|
-
size={'default'}
|
|
131
|
-
className={css`
|
|
132
|
-
flex: 1;
|
|
133
|
-
`}
|
|
134
|
-
>
|
|
135
|
-
<FormLayout layout={'vertical'}>
|
|
136
|
-
<SchemaComponent
|
|
137
|
-
scope={{ dataSource, JSON5, jsonConfigDesc }}
|
|
138
|
-
components={{ Options }}
|
|
139
|
-
schema={{
|
|
140
|
-
properties: {
|
|
141
|
-
// title: {
|
|
142
|
-
// title: lang('Chart title'),
|
|
143
|
-
// 'x-component': 'Input',
|
|
144
|
-
// 'x-decorator': 'FormItem',
|
|
145
|
-
// },
|
|
146
|
-
type: {
|
|
147
|
-
title: t('Chart type'),
|
|
148
|
-
required: true,
|
|
149
|
-
'x-component': 'CustomSelect',
|
|
150
|
-
'x-decorator': 'FormItem',
|
|
151
|
-
enum: [...templates.values()].map((template) => {
|
|
152
|
-
return {
|
|
153
|
-
title: template.title,
|
|
154
|
-
key: template.type,
|
|
155
|
-
description: template.description,
|
|
156
|
-
group: template.group,
|
|
157
|
-
iconId: template.iconId,
|
|
158
|
-
};
|
|
159
|
-
}),
|
|
160
|
-
},
|
|
161
|
-
options: {
|
|
162
|
-
type: 'void',
|
|
163
|
-
'x-component': 'Options',
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
}}
|
|
167
|
-
/>
|
|
168
|
-
</FormLayout>
|
|
169
|
-
</Card>
|
|
170
|
-
{/* right*/}
|
|
171
|
-
<div
|
|
172
|
-
className={css`
|
|
173
|
-
flex: 1;
|
|
174
|
-
min-width: 600px;
|
|
175
|
-
`}
|
|
176
|
-
>
|
|
177
|
-
<Card size={'default'} title={lang('Chart preview')}>
|
|
178
|
-
{/* Chart Preview*/}
|
|
179
|
-
{chartBlockEngineMetaData && (
|
|
180
|
-
<>
|
|
181
|
-
<SchemaComponent
|
|
182
|
-
schema={{
|
|
183
|
-
properties: {
|
|
184
|
-
chartPreview: {
|
|
185
|
-
type: 'void',
|
|
186
|
-
'x-decorator': 'CardItem',
|
|
187
|
-
'x-component': 'ChartBlockEngine',
|
|
188
|
-
'x-component-props': {
|
|
189
|
-
chartBlockEngineMetaData: chartBlockEngineMetaData,
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
}}
|
|
194
|
-
/>
|
|
195
|
-
</>
|
|
196
|
-
)}
|
|
197
|
-
</Card>
|
|
198
|
-
<Card
|
|
199
|
-
size={'default'}
|
|
200
|
-
title={lang('Data preview')}
|
|
201
|
-
className={css`
|
|
202
|
-
margin-top: 24px;
|
|
203
|
-
overflow: scroll;
|
|
204
|
-
`}
|
|
205
|
-
>
|
|
206
|
-
{/*Data preview*/}
|
|
207
|
-
{chartBlockEngineMetaData?.query?.id && (
|
|
208
|
-
<DataSetPreviewTable queryId={chartBlockEngineMetaData?.query?.id} fields={fields} />
|
|
209
|
-
)}
|
|
210
|
-
</Card>
|
|
211
|
-
</div>
|
|
212
|
-
</section>
|
|
213
|
-
</SchemaComponentOptions>
|
|
214
|
-
</APIClientProvider>
|
|
215
|
-
);
|
|
216
|
-
},
|
|
217
|
-
theme,
|
|
218
|
-
)
|
|
219
|
-
.open({
|
|
220
|
-
initialValues: { ...chart }, //reset before chartBlockMetaData
|
|
221
|
-
})
|
|
222
|
-
.then((values) => {
|
|
223
|
-
//patch updates
|
|
224
|
-
values = {
|
|
225
|
-
query,
|
|
226
|
-
chart: values,
|
|
227
|
-
};
|
|
228
|
-
field.title = values.chart.title;
|
|
229
|
-
fieldSchema['title'] = values.chart.title;
|
|
230
|
-
field.componentProps.chartBlockEngineMetaData = values;
|
|
231
|
-
fieldSchema['x-component-props'].chartBlockEngineMetaData = values;
|
|
232
|
-
dn.emit('patch', {
|
|
233
|
-
schema: {
|
|
234
|
-
'x-uid': fieldSchema['x-uid'],
|
|
235
|
-
'x-component-props': fieldSchema['x-component-props'],
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
dn.refresh();
|
|
239
|
-
})
|
|
240
|
-
.catch((err) => {
|
|
241
|
-
error(err);
|
|
242
|
-
});
|
|
243
|
-
}}
|
|
244
|
-
>
|
|
245
|
-
{props.children || props.title || lang('Edit chart block')}
|
|
246
|
-
</SchemaSettings.Item>
|
|
247
|
-
);
|
|
248
|
-
};
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { FormLayout } from '@formily/antd-v5';
|
|
2
|
-
import { Field } from '@formily/core';
|
|
3
|
-
import { RecursionField, Schema, SchemaOptionsContext, observer, useField, useForm } from '@formily/react';
|
|
4
|
-
import {
|
|
5
|
-
APIClientProvider,
|
|
6
|
-
FormDialog,
|
|
7
|
-
FormProvider,
|
|
8
|
-
SchemaComponent,
|
|
9
|
-
SchemaComponentOptions,
|
|
10
|
-
css,
|
|
11
|
-
useAPIClient,
|
|
12
|
-
useCompile,
|
|
13
|
-
useGlobalTheme,
|
|
14
|
-
} from '@nocobase/client';
|
|
15
|
-
import { Card } from 'antd';
|
|
16
|
-
import JSON5 from 'json5';
|
|
17
|
-
import React, { useContext, useEffect, useState } from 'react';
|
|
18
|
-
import { ChartBlockEngineMetaData } from './ChartBlockEngine';
|
|
19
|
-
import { jsonConfigDesc } from './ChartBlockEngineDesigner';
|
|
20
|
-
import { ChartQueryBlockInitializer, ChartQueryMetadata } from './ChartQueryBlockInitializer';
|
|
21
|
-
import DataSetPreviewTable from './DataSetPreviewTable';
|
|
22
|
-
import { lang } from './locale';
|
|
23
|
-
import { templates } from './templates';
|
|
24
|
-
|
|
25
|
-
export const Options = observer(
|
|
26
|
-
(props) => {
|
|
27
|
-
const form = useForm<ChartFormInterface>();
|
|
28
|
-
const field = useField<Field>();
|
|
29
|
-
const [s, setSchema] = useState(new Schema({}));
|
|
30
|
-
const [chartType, setChartType] = useState(form.values.type);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
// form.clearFormGraph('options.*');
|
|
33
|
-
setChartType(form?.values?.type);
|
|
34
|
-
if (chartType !== form?.values?.type) {
|
|
35
|
-
form.clearFormGraph('options.*');
|
|
36
|
-
}
|
|
37
|
-
if (form.values.type) {
|
|
38
|
-
const template = templates.get(form.values.type);
|
|
39
|
-
setSchema(new Schema(template.configurableProperties || {}));
|
|
40
|
-
}
|
|
41
|
-
}, [form.values.type]);
|
|
42
|
-
return <RecursionField schema={s} />;
|
|
43
|
-
},
|
|
44
|
-
{ displayName: 'Options' },
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
interface ChartFormInterface {
|
|
48
|
-
type: string;
|
|
49
|
-
template: string;
|
|
50
|
-
metric: string;
|
|
51
|
-
dimension: string;
|
|
52
|
-
category?: string;
|
|
53
|
-
|
|
54
|
-
[key: string]: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const ChartBlockInitializer = (props) => {
|
|
58
|
-
const { insert } = props;
|
|
59
|
-
const options = useContext(SchemaOptionsContext);
|
|
60
|
-
const api = useAPIClient();
|
|
61
|
-
const compile = useCompile();
|
|
62
|
-
const { theme } = useGlobalTheme();
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<ChartQueryBlockInitializer
|
|
66
|
-
{...props}
|
|
67
|
-
componentType={'Charts'}
|
|
68
|
-
onCreateBlockSchema={async ({ item: chartQueryMetadata }: { item: ChartQueryMetadata }) => {
|
|
69
|
-
const dataSource = chartQueryMetadata?.fields.map((field) => {
|
|
70
|
-
return {
|
|
71
|
-
label: field.name,
|
|
72
|
-
value: field.name,
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
const values = await FormDialog(
|
|
76
|
-
{
|
|
77
|
-
okText: compile('{{t("Submit")}}'),
|
|
78
|
-
title: lang('Create chart block'),
|
|
79
|
-
width: 1200,
|
|
80
|
-
bodyStyle: { background: 'var(--nb-box-bg)', maxHeight: '65vh', overflow: 'auto' },
|
|
81
|
-
},
|
|
82
|
-
function Com() {
|
|
83
|
-
const form = useForm<ChartFormInterface>();
|
|
84
|
-
const [chartBlockEngineMetaData, setChartBlockEngineMetaData] = useState<ChartBlockEngineMetaData>(null);
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
const chartBlockEngineMetaData = {
|
|
87
|
-
query: {
|
|
88
|
-
id: chartQueryMetadata?.id,
|
|
89
|
-
},
|
|
90
|
-
chart: form.values, //TODO
|
|
91
|
-
};
|
|
92
|
-
setChartBlockEngineMetaData(chartBlockEngineMetaData);
|
|
93
|
-
}, [form.values.type]);
|
|
94
|
-
return (
|
|
95
|
-
<APIClientProvider apiClient={api}>
|
|
96
|
-
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
|
97
|
-
<section
|
|
98
|
-
className={css`
|
|
99
|
-
display: flex;
|
|
100
|
-
gap: 24px;
|
|
101
|
-
`}
|
|
102
|
-
>
|
|
103
|
-
{/* left*/}
|
|
104
|
-
<Card
|
|
105
|
-
title={lang('Chart config')}
|
|
106
|
-
size={'default'}
|
|
107
|
-
className={css`
|
|
108
|
-
flex: 1;
|
|
109
|
-
`}
|
|
110
|
-
>
|
|
111
|
-
<FormProvider form={form}>
|
|
112
|
-
<FormLayout layout={'vertical'}>
|
|
113
|
-
<SchemaComponent
|
|
114
|
-
scope={{ dataSource, JSON5, jsonConfigDesc }}
|
|
115
|
-
components={{ Options }}
|
|
116
|
-
schema={{
|
|
117
|
-
properties: {
|
|
118
|
-
// title: {
|
|
119
|
-
// title: lang('Chart title'),
|
|
120
|
-
// 'x-component': 'Input',
|
|
121
|
-
// 'x-decorator': 'FormItem',
|
|
122
|
-
// },
|
|
123
|
-
type: {
|
|
124
|
-
title: lang('Chart type'),
|
|
125
|
-
required: true,
|
|
126
|
-
'x-component': 'CustomSelect',
|
|
127
|
-
'x-decorator': 'FormItem',
|
|
128
|
-
enum: [...templates.values()].map((template) => {
|
|
129
|
-
return {
|
|
130
|
-
title: template.title,
|
|
131
|
-
key: template.type,
|
|
132
|
-
description: template.description,
|
|
133
|
-
group: template.group,
|
|
134
|
-
iconId: template.iconId,
|
|
135
|
-
};
|
|
136
|
-
}),
|
|
137
|
-
},
|
|
138
|
-
options: {
|
|
139
|
-
type: 'void',
|
|
140
|
-
'x-component': 'Options',
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
}}
|
|
144
|
-
/>
|
|
145
|
-
</FormLayout>
|
|
146
|
-
</FormProvider>
|
|
147
|
-
</Card>
|
|
148
|
-
{/* right*/}
|
|
149
|
-
<div
|
|
150
|
-
className={css`
|
|
151
|
-
flex: 1;
|
|
152
|
-
min-width: 600px;
|
|
153
|
-
`}
|
|
154
|
-
>
|
|
155
|
-
<Card size={'default'} title={lang('Chart preview')}>
|
|
156
|
-
{/* Chart Preview*/}
|
|
157
|
-
{chartBlockEngineMetaData && (
|
|
158
|
-
<>
|
|
159
|
-
<SchemaComponent
|
|
160
|
-
schema={{
|
|
161
|
-
properties: {
|
|
162
|
-
chartPreview: {
|
|
163
|
-
type: 'void',
|
|
164
|
-
'x-decorator': 'CardItem',
|
|
165
|
-
'x-component': 'ChartBlockEngine',
|
|
166
|
-
'x-component-props': {
|
|
167
|
-
chartBlockEngineMetaData,
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
}}
|
|
172
|
-
/>
|
|
173
|
-
</>
|
|
174
|
-
)}
|
|
175
|
-
</Card>
|
|
176
|
-
<Card
|
|
177
|
-
size={'default'}
|
|
178
|
-
title={lang('Data preview')}
|
|
179
|
-
className={css`
|
|
180
|
-
margin-top: 24px;
|
|
181
|
-
overflow: scroll;
|
|
182
|
-
`}
|
|
183
|
-
>
|
|
184
|
-
{/*Data preview*/}
|
|
185
|
-
{chartBlockEngineMetaData?.query?.id && (
|
|
186
|
-
<DataSetPreviewTable
|
|
187
|
-
queryId={chartBlockEngineMetaData?.query?.id}
|
|
188
|
-
fields={chartQueryMetadata?.fields}
|
|
189
|
-
/>
|
|
190
|
-
)}
|
|
191
|
-
</Card>
|
|
192
|
-
</div>
|
|
193
|
-
</section>
|
|
194
|
-
</SchemaComponentOptions>
|
|
195
|
-
</APIClientProvider>
|
|
196
|
-
);
|
|
197
|
-
},
|
|
198
|
-
theme,
|
|
199
|
-
).open({
|
|
200
|
-
initialValues: {},
|
|
201
|
-
});
|
|
202
|
-
if (values) {
|
|
203
|
-
const chartBlockEngineMetaData: ChartBlockEngineMetaData = {
|
|
204
|
-
query: {
|
|
205
|
-
id: chartQueryMetadata.id,
|
|
206
|
-
},
|
|
207
|
-
chart: values,
|
|
208
|
-
};
|
|
209
|
-
insert({
|
|
210
|
-
type: 'void',
|
|
211
|
-
title: values?.title,
|
|
212
|
-
'x-designer': 'ChartBlockEngine.Designer',
|
|
213
|
-
'x-decorator': 'CardItem',
|
|
214
|
-
'x-component': 'ChartBlockEngine',
|
|
215
|
-
'x-component-props': {
|
|
216
|
-
chartBlockEngineMetaData,
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
}}
|
|
221
|
-
/>
|
|
222
|
-
);
|
|
223
|
-
};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { TableOutlined } from '@ant-design/icons';
|
|
2
|
-
import { FormLayout } from '@formily/antd-v5';
|
|
3
|
-
import { SchemaOptionsContext } from '@formily/react';
|
|
4
|
-
import {
|
|
5
|
-
FormDialog,
|
|
6
|
-
SchemaComponent,
|
|
7
|
-
SchemaComponentOptions,
|
|
8
|
-
SchemaInitializer,
|
|
9
|
-
SchemaInitializerButtonContext,
|
|
10
|
-
useAPIClient,
|
|
11
|
-
useGlobalTheme,
|
|
12
|
-
} from '@nocobase/client';
|
|
13
|
-
import { error } from '@nocobase/utils/client';
|
|
14
|
-
import React, { useCallback, useContext, useMemo } from 'react';
|
|
15
|
-
import { useChartQueryMetadataContext } from './ChartQueryMetadataProvider';
|
|
16
|
-
import { lang } from './locale';
|
|
17
|
-
import { getQueryTypeSchema } from './settings/queryTypes';
|
|
18
|
-
|
|
19
|
-
export interface ChartQueryMetadata {
|
|
20
|
-
id: number;
|
|
21
|
-
title: string;
|
|
22
|
-
type: string;
|
|
23
|
-
fields: { name: string }[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const ChartQueryBlockInitializer = (props) => {
|
|
27
|
-
const { templateWrap, onCreateBlockSchema, componentType, createBlockSchema, insert, ...others } = props;
|
|
28
|
-
const { setVisible } = useContext(SchemaInitializerButtonContext);
|
|
29
|
-
const apiClient = useAPIClient();
|
|
30
|
-
const ctx = useChartQueryMetadataContext();
|
|
31
|
-
const options = useContext(SchemaOptionsContext);
|
|
32
|
-
const { theme } = useGlobalTheme();
|
|
33
|
-
|
|
34
|
-
const onAddQuery = useCallback(
|
|
35
|
-
(info) => {
|
|
36
|
-
FormDialog(
|
|
37
|
-
{
|
|
38
|
-
sql: lang('Add SQL query'),
|
|
39
|
-
json: lang('Add JSON query'),
|
|
40
|
-
}[info.key],
|
|
41
|
-
() => {
|
|
42
|
-
return (
|
|
43
|
-
<div>
|
|
44
|
-
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
|
45
|
-
<FormLayout layout={'vertical'}>
|
|
46
|
-
<SchemaComponent
|
|
47
|
-
schema={{
|
|
48
|
-
type: 'object',
|
|
49
|
-
properties: {
|
|
50
|
-
title: {
|
|
51
|
-
title: lang('Title'),
|
|
52
|
-
required: true,
|
|
53
|
-
'x-component': 'Input',
|
|
54
|
-
'x-decorator': 'FormItem',
|
|
55
|
-
},
|
|
56
|
-
options: getQueryTypeSchema(info.key),
|
|
57
|
-
},
|
|
58
|
-
}}
|
|
59
|
-
/>
|
|
60
|
-
</FormLayout>
|
|
61
|
-
</SchemaComponentOptions>
|
|
62
|
-
</div>
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
|
-
theme,
|
|
66
|
-
)
|
|
67
|
-
.open({
|
|
68
|
-
initialValues: {
|
|
69
|
-
type: info.key,
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
.then(async (values) => {
|
|
73
|
-
try {
|
|
74
|
-
if (apiClient.resource('chartsQueries')?.create) {
|
|
75
|
-
const { data } = await apiClient.resource('chartsQueries').create({ values });
|
|
76
|
-
const items = (await ctx.refresh()) as any;
|
|
77
|
-
const item = items.find((item) => item.id === data?.data?.id);
|
|
78
|
-
onCreateBlockSchema({ item });
|
|
79
|
-
}
|
|
80
|
-
setVisible(false);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
error(err);
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
.catch((err) => {
|
|
86
|
-
error(err);
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
[apiClient, ctx, onCreateBlockSchema, options.components, options.scope, setVisible],
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const items = useMemo(() => {
|
|
93
|
-
const defaultItems: any = [
|
|
94
|
-
{
|
|
95
|
-
type: 'itemGroup',
|
|
96
|
-
title: lang('Select query data'),
|
|
97
|
-
children: [],
|
|
98
|
-
},
|
|
99
|
-
];
|
|
100
|
-
const chartQueryMetadata = ctx.data;
|
|
101
|
-
if (chartQueryMetadata && Array.isArray(chartQueryMetadata)) {
|
|
102
|
-
const item1 =
|
|
103
|
-
chartQueryMetadata.length > 0
|
|
104
|
-
? {
|
|
105
|
-
type: 'itemGroup',
|
|
106
|
-
title: '{{t("Select chart query", {ns: "charts"})}}',
|
|
107
|
-
children: chartQueryMetadata,
|
|
108
|
-
}
|
|
109
|
-
: null;
|
|
110
|
-
const item2 =
|
|
111
|
-
chartQueryMetadata.length > 0
|
|
112
|
-
? {
|
|
113
|
-
type: 'divider',
|
|
114
|
-
}
|
|
115
|
-
: null;
|
|
116
|
-
|
|
117
|
-
return [
|
|
118
|
-
item1,
|
|
119
|
-
item2,
|
|
120
|
-
{
|
|
121
|
-
type: 'subMenu',
|
|
122
|
-
title: lang('Add chart query'),
|
|
123
|
-
// component: AddChartQuery,
|
|
124
|
-
children: [
|
|
125
|
-
{
|
|
126
|
-
key: 'sql',
|
|
127
|
-
type: 'item',
|
|
128
|
-
title: 'SQL',
|
|
129
|
-
onClick: onAddQuery,
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
key: 'json',
|
|
133
|
-
type: 'item',
|
|
134
|
-
title: 'JSON',
|
|
135
|
-
onClick: onAddQuery,
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
},
|
|
139
|
-
].filter(Boolean);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return defaultItems;
|
|
143
|
-
}, [ctx.data, onAddQuery]);
|
|
144
|
-
|
|
145
|
-
return (
|
|
146
|
-
<SchemaInitializer.Item
|
|
147
|
-
icon={<TableOutlined />}
|
|
148
|
-
{...others}
|
|
149
|
-
onClick={async ({ item }) => {
|
|
150
|
-
onCreateBlockSchema({ item });
|
|
151
|
-
setVisible(false);
|
|
152
|
-
}}
|
|
153
|
-
items={items}
|
|
154
|
-
/>
|
|
155
|
-
);
|
|
156
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { useAPIClient, useRequest } from '@nocobase/client';
|
|
2
|
-
import { Spin } from 'antd';
|
|
3
|
-
import React, { createContext, useContext, useEffect } from 'react';
|
|
4
|
-
import { useLocation } from 'react-router-dom';
|
|
5
|
-
|
|
6
|
-
export const ChartQueryMetadataContext = createContext({
|
|
7
|
-
refresh: () => {},
|
|
8
|
-
data: [] as any[],
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
export const ChartQueryMetadataProvider: React.FC = (props) => {
|
|
12
|
-
const api = useAPIClient();
|
|
13
|
-
|
|
14
|
-
const options = {
|
|
15
|
-
resource: 'chartsQueries',
|
|
16
|
-
action: 'listMetadata',
|
|
17
|
-
params: {
|
|
18
|
-
paginate: false,
|
|
19
|
-
sort: ['-id'],
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const location = useLocation();
|
|
24
|
-
|
|
25
|
-
const service = useRequest<{
|
|
26
|
-
data: any;
|
|
27
|
-
}>(options, {
|
|
28
|
-
manual: true,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const isAdminPage = location.pathname.startsWith('/admin');
|
|
32
|
-
const token = api.auth.getToken() || '';
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (isAdminPage && token) {
|
|
36
|
-
service.run();
|
|
37
|
-
}
|
|
38
|
-
}, [isAdminPage, token]);
|
|
39
|
-
|
|
40
|
-
const refresh = async () => {
|
|
41
|
-
const { data } = await api.request(options);
|
|
42
|
-
service.mutate(data);
|
|
43
|
-
return data?.data || [];
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
if (service.loading) {
|
|
47
|
-
return <Spin />;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<ChartQueryMetadataContext.Provider
|
|
52
|
-
value={{
|
|
53
|
-
refresh,
|
|
54
|
-
data: service.data?.data,
|
|
55
|
-
}}
|
|
56
|
-
>
|
|
57
|
-
{props.children}
|
|
58
|
-
</ChartQueryMetadataContext.Provider>
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const useChartQueryMetadataContext = () => {
|
|
63
|
-
return useContext(ChartQueryMetadataContext);
|
|
64
|
-
};
|