@nocobase/plugin-charts 0.9.1-alpha.2

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.
Files changed (139) hide show
  1. package/client.d.ts +4 -0
  2. package/client.js +30 -0
  3. package/lib/client/ChartBlockEngine.d.ts +27 -0
  4. package/lib/client/ChartBlockEngine.js +201 -0
  5. package/lib/client/ChartBlockEngineDesigner.d.ts +3 -0
  6. package/lib/client/ChartBlockEngineDesigner.js +348 -0
  7. package/lib/client/ChartBlockInitializer.d.ts +3 -0
  8. package/lib/client/ChartBlockInitializer.js +324 -0
  9. package/lib/client/ChartQueryBlockInitializer.d.ts +9 -0
  10. package/lib/client/ChartQueryBlockInitializer.js +230 -0
  11. package/lib/client/ChartQueryMetadataProvider.d.ts +10 -0
  12. package/lib/client/ChartQueryMetadataProvider.js +118 -0
  13. package/lib/client/DataSetPreviewTable.d.ts +5 -0
  14. package/lib/client/DataSetPreviewTable.js +127 -0
  15. package/lib/client/Icons.d.ts +1 -0
  16. package/lib/client/Icons.js +226 -0
  17. package/lib/client/chartRenderComponents/index.d.ts +2 -0
  18. package/lib/client/chartRenderComponents/index.js +26 -0
  19. package/lib/client/hooks/index.d.ts +4 -0
  20. package/lib/client/hooks/index.js +52 -0
  21. package/lib/client/index.d.ts +4 -0
  22. package/lib/client/index.js +161 -0
  23. package/lib/client/locale/en-US.d.ts +23 -0
  24. package/lib/client/locale/en-US.js +29 -0
  25. package/lib/client/locale/index.d.ts +3 -0
  26. package/lib/client/locale/index.js +46 -0
  27. package/lib/client/locale/ja-JP.d.ts +2 -0
  28. package/lib/client/locale/ja-JP.js +8 -0
  29. package/lib/client/locale/ru-RU.d.ts +2 -0
  30. package/lib/client/locale/ru-RU.js +8 -0
  31. package/lib/client/locale/tr-TR.d.ts +2 -0
  32. package/lib/client/locale/tr-TR.js +8 -0
  33. package/lib/client/locale/zh-CN.d.ts +61 -0
  34. package/lib/client/locale/zh-CN.js +67 -0
  35. package/lib/client/select/CustomSelect.d.ts +11 -0
  36. package/lib/client/select/CustomSelect.js +193 -0
  37. package/lib/client/select/ReadPretty.d.ts +2 -0
  38. package/lib/client/select/ReadPretty.js +102 -0
  39. package/lib/client/select/index.d.ts +2 -0
  40. package/lib/client/select/index.js +31 -0
  41. package/lib/client/select/shared.d.ts +7 -0
  42. package/lib/client/select/shared.js +86 -0
  43. package/lib/client/settings/AddNewQuery.d.ts +2 -0
  44. package/lib/client/settings/AddNewQuery.js +321 -0
  45. package/lib/client/settings/ConfigureFields.d.ts +1 -0
  46. package/lib/client/settings/ConfigureFields.js +51 -0
  47. package/lib/client/settings/QueriesTable.d.ts +1 -0
  48. package/lib/client/settings/QueriesTable.js +108 -0
  49. package/lib/client/settings/queryTypes.d.ts +5 -0
  50. package/lib/client/settings/queryTypes.js +85 -0
  51. package/lib/client/settings/schemas/chartsQueries.d.ts +8 -0
  52. package/lib/client/settings/schemas/chartsQueries.js +378 -0
  53. package/lib/client/templates/AreaTemplate.d.ts +65 -0
  54. package/lib/client/templates/AreaTemplate.js +86 -0
  55. package/lib/client/templates/BarTemplate.d.ts +80 -0
  56. package/lib/client/templates/BarTemplate.js +103 -0
  57. package/lib/client/templates/ColumnTemplate.d.ts +80 -0
  58. package/lib/client/templates/ColumnTemplate.js +103 -0
  59. package/lib/client/templates/FunnelTemplate.d.ts +66 -0
  60. package/lib/client/templates/FunnelTemplate.js +87 -0
  61. package/lib/client/templates/LineTemplate.d.ts +67 -0
  62. package/lib/client/templates/LineTemplate.js +92 -0
  63. package/lib/client/templates/PieTemplate.d.ts +71 -0
  64. package/lib/client/templates/PieTemplate.js +92 -0
  65. package/lib/client/templates/RadarTemplate.d.ts +71 -0
  66. package/lib/client/templates/RadarTemplate.js +93 -0
  67. package/lib/client/templates/ScatterTemplate.d.ts +91 -0
  68. package/lib/client/templates/ScatterTemplate.js +112 -0
  69. package/lib/client/templates/TableTemplate.d.ts +28 -0
  70. package/lib/client/templates/TableTemplate.js +54 -0
  71. package/lib/client/templates/index.d.ts +1 -0
  72. package/lib/client/templates/index.js +33 -0
  73. package/lib/client/utils.d.ts +3 -0
  74. package/lib/client/utils.js +66 -0
  75. package/lib/index.d.ts +1 -0
  76. package/lib/index.js +15 -0
  77. package/lib/server/actions/chartsQueries.d.ts +3 -0
  78. package/lib/server/actions/chartsQueries.js +104 -0
  79. package/lib/server/actions/index.d.ts +1 -0
  80. package/lib/server/actions/index.js +1 -0
  81. package/lib/server/collections/chartsQueries.d.ts +2 -0
  82. package/lib/server/collections/chartsQueries.js +36 -0
  83. package/lib/server/index.d.ts +1 -0
  84. package/lib/server/index.js +15 -0
  85. package/lib/server/plugin.d.ts +14 -0
  86. package/lib/server/plugin.js +142 -0
  87. package/lib/server/query.d.ts +12 -0
  88. package/lib/server/query.js +91 -0
  89. package/lib/server/shared/index.d.ts +2 -0
  90. package/lib/server/shared/index.js +8 -0
  91. package/package.json +14 -0
  92. package/server.d.ts +4 -0
  93. package/server.js +30 -0
  94. package/src/client/ChartBlockEngine.tsx +120 -0
  95. package/src/client/ChartBlockEngineDesigner.tsx +238 -0
  96. package/src/client/ChartBlockInitializer.tsx +216 -0
  97. package/src/client/ChartQueryBlockInitializer.tsx +136 -0
  98. package/src/client/ChartQueryMetadataProvider.tsx +62 -0
  99. package/src/client/DataSetPreviewTable.tsx +73 -0
  100. package/src/client/Icons.tsx +99 -0
  101. package/src/client/chartRenderComponents/index.ts +7 -0
  102. package/src/client/hooks/index.ts +19 -0
  103. package/src/client/index.tsx +101 -0
  104. package/src/client/locale/en-US.ts +23 -0
  105. package/src/client/locale/index.ts +18 -0
  106. package/src/client/locale/ja-JP.ts +1 -0
  107. package/src/client/locale/ru-RU.ts +1 -0
  108. package/src/client/locale/tr-TR.ts +1 -0
  109. package/src/client/locale/zh-CN.ts +63 -0
  110. package/src/client/select/CustomSelect.tsx +127 -0
  111. package/src/client/select/ReadPretty.tsx +36 -0
  112. package/src/client/select/index.md +38 -0
  113. package/src/client/select/index.ts +2 -0
  114. package/src/client/select/shared.ts +36 -0
  115. package/src/client/settings/AddNewQuery.tsx +161 -0
  116. package/src/client/settings/ConfigureFields.tsx +18 -0
  117. package/src/client/settings/QueriesTable.tsx +26 -0
  118. package/src/client/settings/queryTypes.ts +64 -0
  119. package/src/client/settings/schemas/chartsQueries.ts +319 -0
  120. package/src/client/templates/AreaTemplate.tsx +64 -0
  121. package/src/client/templates/BarTemplate.tsx +80 -0
  122. package/src/client/templates/ColumnTemplate.tsx +81 -0
  123. package/src/client/templates/FunnelTemplate.tsx +65 -0
  124. package/src/client/templates/LineTemplate.tsx +72 -0
  125. package/src/client/templates/PieTemplate.tsx +68 -0
  126. package/src/client/templates/RadarTemplate.tsx +71 -0
  127. package/src/client/templates/ScatterTemplate.tsx +90 -0
  128. package/src/client/templates/TableTemplate.tsx +48 -0
  129. package/src/client/templates/index.ts +21 -0
  130. package/src/client/utils.ts +39 -0
  131. package/src/index.ts +1 -0
  132. package/src/server/actions/chartsQueries.ts +44 -0
  133. package/src/server/actions/index.ts +0 -0
  134. package/src/server/collections/.gitkeep +0 -0
  135. package/src/server/collections/chartsQueries.ts +24 -0
  136. package/src/server/index.ts +1 -0
  137. package/src/server/plugin.ts +61 -0
  138. package/src/server/query.ts +39 -0
  139. package/src/server/shared/index.ts +2 -0
@@ -0,0 +1,120 @@
1
+ import { useCompile, useRequest } from '@nocobase/client';
2
+ import { Empty, Spin } from 'antd';
3
+ import JSON5 from 'json5';
4
+ import React, { useEffect, useState } from 'react';
5
+ import { ChartBlockEngineDesigner } from './ChartBlockEngineDesigner';
6
+ import chartRenderComponentsMap from './chartRenderComponents';
7
+ import { lang } from './locale';
8
+ import { templates } from './templates';
9
+
10
+ export interface IQueryConfig {
11
+ id: number;
12
+ }
13
+ export interface IChartConfig {
14
+ type: string;
15
+ template: string;
16
+ metric: string;
17
+ dimension: string;
18
+ category?: string;
19
+ [key: string]: any;
20
+ }
21
+
22
+ export interface ChartBlockEngineMetaData {
23
+ query: IQueryConfig;
24
+ chart: IChartConfig;
25
+ }
26
+
27
+ const ChartRenderComponent = ({
28
+ chartBlockEngineMetaData,
29
+ }: {
30
+ chartBlockEngineMetaData: ChartBlockEngineMetaData;
31
+ }): JSX.Element => {
32
+ const compile = useCompile();
33
+ const chartType = chartBlockEngineMetaData.chart.type;
34
+ const renderComponent = templates.get(chartType)?.renderComponent;
35
+ const RenderComponent = chartRenderComponentsMap.get(renderComponent); //G2Plot | Echarts | D3 |Table
36
+ const chartConfig = chartBlockEngineMetaData.chart;
37
+ const { loading, dataSet, error } = useGetDataSet(chartBlockEngineMetaData.query.id);
38
+
39
+ if (error) {
40
+ return (
41
+ <>
42
+ <Empty description={<span>May be this chart block's query data has been deleted,please check!</span>} />
43
+ </>
44
+ );
45
+ }
46
+
47
+ const [currentConfig, setCurrentConfig] = useState<IChartConfig>({} as any);
48
+
49
+ useEffect(() => {
50
+ setCurrentConfig(chartConfig);
51
+ }, [JSON.stringify(chartConfig)]);
52
+
53
+ if (currentConfig.type !== chartConfig.type) {
54
+ return <></>;
55
+ }
56
+
57
+ switch (renderComponent) {
58
+ case 'G2Plot': {
59
+ let finalChartOptions;
60
+ finalChartOptions = templates.get(chartType)?.defaultChartOptions;
61
+ let template;
62
+ try {
63
+ template = JSON5.parse(chartConfig?.template);
64
+ } catch (e) {
65
+ template = {};
66
+ }
67
+ const config = compile(
68
+ {
69
+ ...finalChartOptions,
70
+ ...template,
71
+ data: dataSet,
72
+ },
73
+ { ...chartConfig, category: chartConfig?.category ?? '' },
74
+ );
75
+ if (config && chartConfig) {
76
+ const { dimension, metric, category } = chartConfig;
77
+ if (!metric || !dimension) {
78
+ return <>{lang('Please check the chart config')}</>;
79
+ }
80
+ }
81
+ return <>{loading ? <Spin /> : <RenderComponent plot={chartConfig.type} config={config} />}</>;
82
+ }
83
+ }
84
+ return <></>;
85
+ };
86
+
87
+ export const useGetDataSet = (chartQueryId: number) => {
88
+ const { data, loading, error } = useRequest({
89
+ url: `/chartsQueries:getData/${chartQueryId}`,
90
+ });
91
+ const dataSet = data?.data;
92
+ return {
93
+ loading,
94
+ dataSet: dataSet,
95
+ error,
96
+ };
97
+ };
98
+
99
+ const ChartBlockEngine = ({ chartBlockEngineMetaData }: { chartBlockEngineMetaData: ChartBlockEngineMetaData }) => {
100
+ let renderComponent;
101
+ const chartType = chartBlockEngineMetaData?.chart?.type;
102
+
103
+ if (chartType) {
104
+ renderComponent = templates.get(chartType)?.renderComponent;
105
+ }
106
+
107
+ if (!chartType || !renderComponent) {
108
+ return <>{lang('Please check the chart config')}</>;
109
+ }
110
+
111
+ return (
112
+ <>
113
+ <ChartRenderComponent chartBlockEngineMetaData={chartBlockEngineMetaData} />
114
+ </>
115
+ );
116
+ };
117
+
118
+ ChartBlockEngine.Designer = ChartBlockEngineDesigner;
119
+
120
+ export { ChartBlockEngine };
@@ -0,0 +1,238 @@
1
+ import { css } from '@emotion/css';
2
+ import { FormDialog, FormLayout } from '@formily/antd';
3
+ import { SchemaOptionsContext, useField, useFieldSchema } from '@formily/react';
4
+ import {
5
+ APIClientProvider,
6
+ GeneralSchemaDesigner,
7
+ i18n,
8
+ SchemaComponent,
9
+ SchemaComponentOptions,
10
+ SchemaSettings,
11
+ useAPIClient,
12
+ useCompile,
13
+ useDesignable,
14
+ } from '@nocobase/client';
15
+ import { Card } from 'antd';
16
+ import JSON5 from 'json5';
17
+ import React, { useContext, useEffect, useState } from 'react';
18
+ import { useTranslation } from 'react-i18next';
19
+ import { ChartBlockEngineMetaData } from './ChartBlockEngine';
20
+ import { Options } from './ChartBlockInitializer';
21
+ import DataSetPreviewTable from './DataSetPreviewTable';
22
+ import { useFieldsById } from './hooks';
23
+ import { lang } from './locale';
24
+ import { templates } from './templates';
25
+
26
+ export const jsonConfigDesc = (title: string, link: string) => {
27
+ return (
28
+ <span>
29
+ {lang('Json config references: ')}
30
+ <a href={link} target="_blank">
31
+ {lang(title)}
32
+ </a>
33
+ </span>
34
+ );
35
+ };
36
+
37
+ const validateJSON = {
38
+ validator: `{{(value, rule)=> {
39
+ if (!value) {
40
+ return '';
41
+ }
42
+ try {
43
+ const val = JSON.parse(value);
44
+ if(!isNaN(val)) {
45
+ return false;
46
+ }
47
+ return true;
48
+ } catch(error) {
49
+ console.error(error);
50
+ return false;
51
+ }
52
+ }}}`,
53
+ message: '{{t("Invalid JSON format",{ ns: "charts" })}}',
54
+ };
55
+
56
+ export const ChartBlockEngineDesigner = () => {
57
+ const fieldSchema = useFieldSchema();
58
+ const { chartBlockEngineMetaData } = fieldSchema?.['x-component-props'];
59
+ return (
60
+ <GeneralSchemaDesigner>
61
+ <ChartBlockEngineDesignerInitializer chartBlockEngineMetaData={chartBlockEngineMetaData} />
62
+ <SchemaSettings.Divider />
63
+ <SchemaSettings.Remove
64
+ removeParentsIfNoChildren
65
+ breakRemoveOn={{
66
+ 'x-component': 'Grid',
67
+ }}
68
+ />
69
+ </GeneralSchemaDesigner>
70
+ );
71
+ };
72
+
73
+ export const ChartBlockEngineDesignerInitializer = (props) => {
74
+ const { chartBlockEngineMetaData }: { chartBlockEngineMetaData: ChartBlockEngineMetaData } = props;
75
+ const { t } = useTranslation();
76
+ const options = useContext(SchemaOptionsContext);
77
+ const { dn } = useDesignable();
78
+ const fieldSchema = useFieldSchema();
79
+ const api = useAPIClient();
80
+ const field = useField();
81
+ const compile = useCompile();
82
+ const { chart, query } = chartBlockEngineMetaData;
83
+ const { fields } = useFieldsById(query.id);
84
+ const dataSource = fields.map((field) => {
85
+ return {
86
+ label: field.name,
87
+ value: field.name,
88
+ };
89
+ });
90
+ return (
91
+ <SchemaSettings.Item
92
+ onClick={async () => {
93
+ FormDialog(
94
+ {
95
+ okText: compile('{{t("Submit")}}'),
96
+ title: lang('Edit chart block'),
97
+ width: 1200,
98
+ bodyStyle: { background: '#f0f2f5', maxHeight: '65vh', overflow: 'auto' },
99
+ },
100
+ (form) => {
101
+ const [chartBlockEngineMetaData, setChartBlockEngineMetaData] = useState<ChartBlockEngineMetaData>(null);
102
+ useEffect(() => {
103
+ const chartBlockEngineMetaData = {
104
+ query: {
105
+ id: query?.id,
106
+ },
107
+ chart: form.values, //TODO
108
+ };
109
+ setChartBlockEngineMetaData(chartBlockEngineMetaData);
110
+ }, [form.values.type]);
111
+ return (
112
+ <APIClientProvider apiClient={api}>
113
+ <SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
114
+ <section
115
+ className={css`
116
+ display: flex;
117
+ gap: 24px;
118
+ `}
119
+ >
120
+ {/* left*/}
121
+ <Card
122
+ bordered={false}
123
+ title={i18n.t('Chart config')}
124
+ size={'default'}
125
+ className={css`
126
+ flex: 1;
127
+ `}
128
+ >
129
+ <FormLayout layout={'vertical'}>
130
+ <SchemaComponent
131
+ scope={{ dataSource, JSON5, jsonConfigDesc }}
132
+ components={{ Options }}
133
+ schema={{
134
+ properties: {
135
+ // title: {
136
+ // title: lang('Chart title'),
137
+ // 'x-component': 'Input',
138
+ // 'x-decorator': 'FormItem',
139
+ // },
140
+ type: {
141
+ title: t('Chart type'),
142
+ required: true,
143
+ 'x-component': 'CustomSelect',
144
+ 'x-decorator': 'FormItem',
145
+ enum: [...templates.values()].map((template) => {
146
+ return {
147
+ title: template.title,
148
+ key: template.type,
149
+ description: template.description,
150
+ group: template.group,
151
+ iconId: template.iconId,
152
+ };
153
+ }),
154
+ },
155
+ options: {
156
+ type: 'void',
157
+ 'x-component': 'Options',
158
+ },
159
+ },
160
+ }}
161
+ />
162
+ </FormLayout>
163
+ </Card>
164
+ {/* right*/}
165
+ <div
166
+ className={css`
167
+ flex: 1;
168
+ min-width: 600px;
169
+ `}
170
+ >
171
+ <Card size={'default'} title={lang('Chart preview')}>
172
+ {/* Chart Preview*/}
173
+ {chartBlockEngineMetaData && (
174
+ <>
175
+ <SchemaComponent
176
+ schema={{
177
+ properties: {
178
+ chartPreview: {
179
+ type: 'void',
180
+ 'x-decorator': 'CardItem',
181
+ 'x-component': 'ChartBlockEngine',
182
+ 'x-component-props': {
183
+ chartBlockEngineMetaData: chartBlockEngineMetaData,
184
+ },
185
+ },
186
+ },
187
+ }}
188
+ />
189
+ </>
190
+ )}
191
+ </Card>
192
+ <Card
193
+ size={'default'}
194
+ title={lang('Data preview')}
195
+ className={css`
196
+ margin-top: 24px;
197
+ overflow: scroll;
198
+ `}
199
+ >
200
+ {/*Data preview*/}
201
+ {chartBlockEngineMetaData?.query?.id && (
202
+ <DataSetPreviewTable queryId={chartBlockEngineMetaData?.query?.id} fields={fields} />
203
+ )}
204
+ </Card>
205
+ </div>
206
+ </section>
207
+ </SchemaComponentOptions>
208
+ </APIClientProvider>
209
+ );
210
+ },
211
+ )
212
+ .open({
213
+ initialValues: { ...chart }, //reset before chartBlockMetaData
214
+ })
215
+ .then((values) => {
216
+ //patch updates
217
+ values = {
218
+ query,
219
+ chart: values,
220
+ };
221
+ field.title = values.chart.title;
222
+ fieldSchema['title'] = values.chart.title;
223
+ field.componentProps.chartBlockEngineMetaData = values;
224
+ fieldSchema['x-component-props'].chartBlockEngineMetaData = values;
225
+ dn.emit('patch', {
226
+ schema: {
227
+ 'x-uid': fieldSchema['x-uid'],
228
+ 'x-component-props': fieldSchema['x-component-props'],
229
+ },
230
+ });
231
+ dn.refresh();
232
+ });
233
+ }}
234
+ >
235
+ {props.children || props.title || lang('Edit chart block')}
236
+ </SchemaSettings.Item>
237
+ );
238
+ };
@@ -0,0 +1,216 @@
1
+ import { css } from '@emotion/css';
2
+ import { FormDialog, FormLayout } from '@formily/antd';
3
+ import { Field } from '@formily/core';
4
+ import { observer, RecursionField, Schema, SchemaOptionsContext, useField, useForm } from '@formily/react';
5
+ import {
6
+ APIClientProvider,
7
+ FormProvider,
8
+ SchemaComponent,
9
+ SchemaComponentOptions,
10
+ useAPIClient,
11
+ useCompile,
12
+ } from '@nocobase/client';
13
+ import { Card } from 'antd';
14
+ import JSON5 from 'json5';
15
+ import React, { useContext, useEffect, useState } from 'react';
16
+ import { ChartBlockEngineMetaData } from './ChartBlockEngine';
17
+ import { jsonConfigDesc } from './ChartBlockEngineDesigner';
18
+ import { ChartQueryBlockInitializer, ChartQueryMetadata } from './ChartQueryBlockInitializer';
19
+ import DataSetPreviewTable from './DataSetPreviewTable';
20
+ import { lang, useChartsTranslation } from './locale';
21
+ import { templates } from './templates';
22
+
23
+ export const Options = observer((props) => {
24
+ const form = useForm<ChartFormInterface>();
25
+ const field = useField<Field>();
26
+ const [s, setSchema] = useState(new Schema({}));
27
+ const [chartType, setChartType] = useState(form.values.type);
28
+ useEffect(() => {
29
+ // form.clearFormGraph('options.*');
30
+ setChartType(form?.values?.type);
31
+ if (chartType !== form?.values?.type) {
32
+ form.clearFormGraph('options.*');
33
+ }
34
+ if (form.values.type) {
35
+ const template = templates.get(form.values.type);
36
+ setSchema(new Schema(template.configurableProperties || {}));
37
+ }
38
+ }, [form.values.type]);
39
+ return <RecursionField schema={s} />;
40
+ });
41
+
42
+ interface ChartFormInterface {
43
+ type: string;
44
+ template: string;
45
+ metric: string;
46
+ dimension: string;
47
+ category?: string;
48
+
49
+ [key: string]: string;
50
+ }
51
+
52
+ export const ChartBlockInitializer = (props) => {
53
+ const { insert } = props;
54
+ const options = useContext(SchemaOptionsContext);
55
+ const api = useAPIClient();
56
+ const compile = useCompile();
57
+ const { t } = useChartsTranslation();
58
+ return (
59
+ <ChartQueryBlockInitializer
60
+ {...props}
61
+ componentType={'Charts'}
62
+ onCreateBlockSchema={async ({ item: chartQueryMetadata }: { item: ChartQueryMetadata }) => {
63
+ const dataSource = chartQueryMetadata?.fields.map((field) => {
64
+ return {
65
+ label: field.name,
66
+ value: field.name,
67
+ };
68
+ });
69
+ let values = await FormDialog(
70
+ {
71
+ okText: compile('{{t("Submit")}}'),
72
+ title: lang('Create chart block'),
73
+ width: 1200,
74
+ bodyStyle: { background: '#f0f2f5', maxHeight: '65vh', overflow: 'auto' },
75
+ },
76
+ () => {
77
+ const form = useForm<ChartFormInterface>();
78
+ const [chartBlockEngineMetaData, setChartBlockEngineMetaData] = useState<ChartBlockEngineMetaData>(null);
79
+ useEffect(() => {
80
+ const chartBlockEngineMetaData = {
81
+ query: {
82
+ id: chartQueryMetadata?.id,
83
+ },
84
+ chart: form.values, //TODO
85
+ };
86
+ setChartBlockEngineMetaData(chartBlockEngineMetaData);
87
+ }, [form.values.type]);
88
+ return (
89
+ <APIClientProvider apiClient={api}>
90
+ <SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
91
+ <section
92
+ className={css`
93
+ display: flex;
94
+ gap: 24px;
95
+ `}
96
+ >
97
+ {/* left*/}
98
+ <Card
99
+ title={lang('Chart config')}
100
+ size={'default'}
101
+ className={css`
102
+ flex: 1;
103
+ `}
104
+ >
105
+ <FormProvider form={form}>
106
+ <FormLayout layout={'vertical'}>
107
+ <SchemaComponent
108
+ scope={{ dataSource, JSON5, jsonConfigDesc }}
109
+ components={{ Options }}
110
+ schema={{
111
+ properties: {
112
+ // title: {
113
+ // title: lang('Chart title'),
114
+ // 'x-component': 'Input',
115
+ // 'x-decorator': 'FormItem',
116
+ // },
117
+ type: {
118
+ title: lang('Chart type'),
119
+ required: true,
120
+ 'x-component': 'CustomSelect',
121
+ 'x-decorator': 'FormItem',
122
+ enum: [...templates.values()].map((template) => {
123
+ return {
124
+ title: template.title,
125
+ key: template.type,
126
+ description: template.description,
127
+ group: template.group,
128
+ iconId: template.iconId,
129
+ };
130
+ }),
131
+ },
132
+ options: {
133
+ type: 'void',
134
+ 'x-component': 'Options',
135
+ },
136
+ },
137
+ }}
138
+ />
139
+ </FormLayout>
140
+ </FormProvider>
141
+ </Card>
142
+ {/* right*/}
143
+ <div
144
+ className={css`
145
+ flex: 1;
146
+ min-width: 600px;
147
+ `}
148
+ >
149
+ <Card size={'default'} title={lang('Chart preview')}>
150
+ {/* Chart Preview*/}
151
+ {chartBlockEngineMetaData && (
152
+ <>
153
+ <SchemaComponent
154
+ schema={{
155
+ properties: {
156
+ chartPreview: {
157
+ type: 'void',
158
+ 'x-decorator': 'CardItem',
159
+ 'x-component': 'ChartBlockEngine',
160
+ 'x-component-props': {
161
+ chartBlockEngineMetaData,
162
+ },
163
+ },
164
+ },
165
+ }}
166
+ />
167
+ </>
168
+ )}
169
+ </Card>
170
+ <Card
171
+ size={'default'}
172
+ title={lang('Data preview')}
173
+ className={css`
174
+ margin-top: 24px;
175
+ overflow: scroll;
176
+ `}
177
+ >
178
+ {/*Data preview*/}
179
+ {chartBlockEngineMetaData?.query?.id && (
180
+ <DataSetPreviewTable
181
+ queryId={chartBlockEngineMetaData?.query?.id}
182
+ fields={chartQueryMetadata?.fields}
183
+ />
184
+ )}
185
+ </Card>
186
+ </div>
187
+ </section>
188
+ </SchemaComponentOptions>
189
+ </APIClientProvider>
190
+ );
191
+ },
192
+ ).open({
193
+ initialValues: {},
194
+ });
195
+ if (values) {
196
+ const chartBlockEngineMetaData: ChartBlockEngineMetaData = {
197
+ query: {
198
+ id: chartQueryMetadata.id,
199
+ },
200
+ chart: values,
201
+ };
202
+ insert({
203
+ type: 'void',
204
+ title: values?.title,
205
+ 'x-designer': 'ChartBlockEngine.Designer',
206
+ 'x-decorator': 'CardItem',
207
+ 'x-component': 'ChartBlockEngine',
208
+ 'x-component-props': {
209
+ chartBlockEngineMetaData,
210
+ },
211
+ });
212
+ }
213
+ }}
214
+ />
215
+ );
216
+ };