plugin-elastic-report 0.1.1 → 0.9.0

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 (80) hide show
  1. package/client-v2.d.ts +2 -2
  2. package/client-v2.js +1 -1
  3. package/client.d.ts +2 -2
  4. package/client.js +1 -1
  5. package/dist/ai/skills/elastic-report/SKILLS.md +52 -0
  6. package/dist/client/357.0dd385384cab5dbf.js +10 -0
  7. package/dist/client/index.js +1 -1
  8. package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
  9. package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
  10. package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
  11. package/dist/client-v2/index.js +1 -1
  12. package/dist/externalVersion.js +5 -3
  13. package/dist/locale/en-US.json +213 -99
  14. package/dist/locale/vi-VN.json +213 -99
  15. package/dist/locale/zh-CN.json +213 -99
  16. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
  17. package/dist/server/acl-guard.js +97 -25
  18. package/dist/server/collections/es-report-data-views.js +6 -0
  19. package/dist/server/collections/es-reports.js +6 -0
  20. package/dist/server/mcp/ElasticReportToolCatalog.js +238 -14
  21. package/dist/server/plugin.js +156 -22
  22. package/dist/server/report-block-tools.js +340 -0
  23. package/dist/server/services/ElasticReportService.js +137 -17
  24. package/dist/server/services/ElasticsearchConnectionService.js +274 -34
  25. package/dist/server/services/ReportExportService.js +243 -0
  26. package/dist/server/services/ReportQueryCompiler.js +532 -91
  27. package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
  28. package/dist/shared/constants.js +26 -2
  29. package/package.json +3 -3
  30. package/server.d.ts +2 -2
  31. package/server.js +1 -1
  32. package/src/ai/skills/elastic-report/SKILLS.md +52 -0
  33. package/src/client/index.tsx +34 -19
  34. package/src/client/workflow-instructions.tsx +44 -0
  35. package/src/client-v2/__tests__/elastic-report.test.tsx +879 -311
  36. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
  37. package/src/client-v2/api.ts +320 -224
  38. package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
  39. package/src/client-v2/components/ElasticBasicCharts.tsx +652 -399
  40. package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
  41. package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
  42. package/src/client-v2/components/ElasticReportBlock.tsx +306 -160
  43. package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -707
  44. package/src/client-v2/components/HighlightText.tsx +50 -50
  45. package/src/client-v2/components/ReportSelect.tsx +85 -72
  46. package/src/client-v2/index.tsx +14 -14
  47. package/src/client-v2/locale.ts +23 -23
  48. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
  49. package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -85
  50. package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1047
  51. package/src/client-v2/plugin.tsx +107 -52
  52. package/src/client-v2/report-destination.tsx +126 -0
  53. package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
  54. package/src/client-v2/workflow/instructions.tsx +149 -0
  55. package/src/index.ts +11 -11
  56. package/src/locale/en-US.json +213 -99
  57. package/src/locale/vi-VN.json +213 -99
  58. package/src/locale/zh-CN.json +213 -99
  59. package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
  60. package/src/server/__tests__/query-compiler.test.ts +620 -231
  61. package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -377
  62. package/src/server/acl-guard.ts +194 -103
  63. package/src/server/collections/es-report-data-views.ts +64 -58
  64. package/src/server/collections/es-reports.ts +80 -74
  65. package/src/server/index.ts +15 -15
  66. package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
  67. package/src/server/mcp/ElasticReportToolCatalog.ts +667 -417
  68. package/src/server/plugin.ts +599 -431
  69. package/src/server/report-block-tools.ts +400 -0
  70. package/src/server/services/ElasticReportService.ts +494 -326
  71. package/src/server/services/ElasticsearchConnectionService.ts +728 -401
  72. package/src/server/services/ReportExportService.ts +282 -0
  73. package/src/server/services/ReportQueryCompiler.ts +1552 -1017
  74. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
  75. package/src/shared/constants.ts +39 -29
  76. package/src/shared/types.ts +272 -175
  77. package/ai/skills/elastic-report/SKILLS.md +0 -32
  78. package/dist/client-v2/851.488fdbf5bc5b6a36.js +0 -10
  79. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +0 -15
  80. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +0 -7
@@ -1,50 +1,50 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- import { HIGHLIGHT_POST_TAG, HIGHLIGHT_PRE_TAG } from '../../shared/constants';
11
- import React from 'react';
12
-
13
- export interface HighlightTextProps {
14
- text: string;
15
- }
16
-
17
- /**
18
- * Safely render Elasticsearch highlight snippets with semantic `<mark>` tags
19
- * without ever invoking `dangerouslySetInnerHTML`.
20
- */
21
- export const HighlightText: React.FC<HighlightTextProps> = ({ text }) => {
22
- if (!text || !text.includes(HIGHLIGHT_PRE_TAG)) {
23
- return <>{text}</>;
24
- }
25
-
26
- const segments: React.ReactNode[] = [];
27
- let cursor = 0;
28
- let keyIdx = 0;
29
-
30
- while (cursor < text.length) {
31
- const startIdx = text.indexOf(HIGHLIGHT_PRE_TAG, cursor);
32
- if (startIdx === -1) {
33
- segments.push(text.slice(cursor));
34
- break;
35
- }
36
- if (startIdx > cursor) {
37
- segments.push(text.slice(cursor, startIdx));
38
- }
39
- const contentStart = startIdx + HIGHLIGHT_PRE_TAG.length;
40
- const endIdx = text.indexOf(HIGHLIGHT_POST_TAG, contentStart);
41
- if (endIdx === -1) {
42
- segments.push(text.slice(contentStart));
43
- break;
44
- }
45
- segments.push(<mark key={`hl-${keyIdx++}`}>{text.slice(contentStart, endIdx)}</mark>);
46
- cursor = endIdx + HIGHLIGHT_POST_TAG.length;
47
- }
48
-
49
- return <>{segments}</>;
50
- };
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { HIGHLIGHT_POST_TAG, HIGHLIGHT_PRE_TAG } from '../../shared/constants';
11
+ import React from 'react';
12
+
13
+ export interface HighlightTextProps {
14
+ text: string;
15
+ }
16
+
17
+ /**
18
+ * Safely render Elasticsearch highlight snippets with semantic `<mark>` tags
19
+ * without ever invoking `dangerouslySetInnerHTML`.
20
+ */
21
+ export const HighlightText: React.FC<HighlightTextProps> = ({ text }) => {
22
+ if (!text || !text.includes(HIGHLIGHT_PRE_TAG)) {
23
+ return <>{text}</>;
24
+ }
25
+
26
+ const segments: React.ReactNode[] = [];
27
+ let cursor = 0;
28
+ let keyIdx = 0;
29
+
30
+ while (cursor < text.length) {
31
+ const startIdx = text.indexOf(HIGHLIGHT_PRE_TAG, cursor);
32
+ if (startIdx === -1) {
33
+ segments.push(text.slice(cursor));
34
+ break;
35
+ }
36
+ if (startIdx > cursor) {
37
+ segments.push(text.slice(cursor, startIdx));
38
+ }
39
+ const contentStart = startIdx + HIGHLIGHT_PRE_TAG.length;
40
+ const endIdx = text.indexOf(HIGHLIGHT_POST_TAG, contentStart);
41
+ if (endIdx === -1) {
42
+ segments.push(text.slice(contentStart));
43
+ break;
44
+ }
45
+ segments.push(<mark key={`hl-${keyIdx++}`}>{text.slice(contentStart, endIdx)}</mark>);
46
+ cursor = endIdx + HIGHLIGHT_POST_TAG.length;
47
+ }
48
+
49
+ return <>{segments}</>;
50
+ };
@@ -1,72 +1,85 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- import { useApp } from '@nocobase/client-v2';
11
- import { Select, Tag, type SelectProps } from 'antd';
12
- import React, { useCallback, useEffect, useState } from 'react';
13
- import type { EsReportRecord, ID } from '../../shared/types';
14
- import { fetchPublishedReports, type ApiClientLike } from '../api';
15
- import { useT } from '../locale';
16
-
17
- export const ReportSelect: React.FC<SelectProps<ID>> = (props) => {
18
- const t = useT();
19
- const app = useApp();
20
- const api = app.apiClient as unknown as ApiClientLike;
21
- const [reports, setReports] = useState<EsReportRecord[]>([]);
22
- const [loading, setLoading] = useState(false);
23
-
24
- const loadReports = useCallback(
25
- async (search?: string) => {
26
- setLoading(true);
27
- try {
28
- const list = await fetchPublishedReports(api, search);
29
- setReports(list);
30
- } catch {
31
- setReports([]);
32
- } finally {
33
- setLoading(false);
34
- }
35
- },
36
- [api],
37
- );
38
-
39
- useEffect(() => {
40
- loadReports();
41
- }, [loadReports]);
42
-
43
- return (
44
- <Select
45
- {...props}
46
- loading={loading}
47
- showSearch
48
- allowClear
49
- placeholder={t('Select report')}
50
- optionFilterProp="label"
51
- options={reports.map((report) => ({
52
- value: report.id,
53
- label: `${report.title} (${report.visualization.toUpperCase()})`,
54
- report,
55
- }))}
56
- optionRender={(option) => {
57
- const item = (option.data as { report?: EsReportRecord }).report;
58
- if (!item) return option.label;
59
- return (
60
- <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8 }}>
61
- <span>{item.title}</span>
62
- <span>
63
- <Tag color="blue" style={{ marginInlineEnd: 0 }}>
64
- {item.visualization.toUpperCase()}
65
- </Tag>
66
- </span>
67
- </div>
68
- );
69
- }}
70
- />
71
- );
72
- };
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { useApp } from '@nocobase/client-v2';
11
+ import { useFlowEngine } from '@nocobase/flow-engine';
12
+ import { Select, Tag, type SelectProps } from 'antd';
13
+ import React, { useCallback, useEffect, useState } from 'react';
14
+ import type { EsReportRecord, ID } from '../../shared/types';
15
+ import { fetchPublishedReports, type ApiClientLike } from '../api';
16
+ import { useT } from '../locale';
17
+
18
+ export const ReportSelect: React.FC<SelectProps<ID>> = (props) => {
19
+ const { style, ...restProps } = props;
20
+ const t = useT();
21
+ const app = useApp();
22
+ const flowEngine = useFlowEngine();
23
+ const api = ((app as { apiClient?: unknown } | undefined)?.apiClient ??
24
+ (flowEngine as { context?: { api?: unknown } } | undefined)?.context?.api) as ApiClientLike;
25
+ const [reports, setReports] = useState<EsReportRecord[]>([]);
26
+ const [loading, setLoading] = useState(false);
27
+
28
+ const loadReports = useCallback(
29
+ async (search?: string) => {
30
+ if (!api) return;
31
+ setLoading(true);
32
+ try {
33
+ const list = await fetchPublishedReports(api, search);
34
+ setReports(list);
35
+ } catch {
36
+ setReports([]);
37
+ } finally {
38
+ setLoading(false);
39
+ }
40
+ },
41
+ [api],
42
+ );
43
+
44
+ useEffect(() => {
45
+ loadReports();
46
+ }, [loadReports]);
47
+
48
+ return (
49
+ <div style={{ width: '100%', maxWidth: '100%', minWidth: 0 }}>
50
+ <Select
51
+ {...restProps}
52
+ popupMatchSelectWidth={true}
53
+ style={{ width: '100%', maxWidth: '100%', minWidth: 0, ...style }}
54
+ loading={loading}
55
+ showSearch
56
+ allowClear
57
+ placeholder={t('Select report')}
58
+ optionFilterProp="label"
59
+ options={reports.map((report) => ({
60
+ value: report.id,
61
+ label: `${report.title} (${report.visualization.toUpperCase()})`,
62
+ report,
63
+ }))}
64
+ optionRender={(option) => {
65
+ const item = (option.data as { report?: EsReportRecord }).report;
66
+ if (!item) return option.label;
67
+ return (
68
+ <div
69
+ style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8, minWidth: 0 }}
70
+ >
71
+ <span
72
+ style={{ flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}
73
+ >
74
+ {item.title}
75
+ </span>
76
+ <Tag color="blue" style={{ marginInlineEnd: 0, flexShrink: 0 }}>
77
+ {item.visualization.toUpperCase()}
78
+ </Tag>
79
+ </div>
80
+ );
81
+ }}
82
+ />
83
+ </div>
84
+ );
85
+ };
@@ -1,14 +1,14 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- export { PluginElasticReportClient, default } from './plugin';
11
- export * from './models/ElasticReportBlockModel';
12
- export * from './components/ElasticReportBlock';
13
- export * from './components/ElasticReportRenderer';
14
- export * from './components/ReportSelect';
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ export { PluginElasticReportClient, default } from './plugin';
11
+ export * from './models/ElasticReportBlockModel';
12
+ export * from './components/ElasticReportBlock';
13
+ export * from './components/ElasticReportRenderer';
14
+ export * from './components/ReportSelect';
@@ -1,23 +1,23 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- import { tExpr as flowTExpr, useFlowEngine } from '@nocobase/flow-engine';
11
- import { PLUGIN_NAME } from '../shared/constants';
12
-
13
- export const NAMESPACE = PLUGIN_NAME;
14
-
15
- export function useT() {
16
- const engine = useFlowEngine();
17
- return (key: string, options?: Record<string, unknown>) =>
18
- engine.context.t(key, { ns: [NAMESPACE, 'client'], ...options });
19
- }
20
-
21
- export function tExpr(key: string) {
22
- return flowTExpr(key, { ns: [NAMESPACE, 'client'] });
23
- }
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { tExpr as flowTExpr, useFlowEngine } from '@nocobase/flow-engine';
11
+ import { PLUGIN_NAME } from '../shared/constants';
12
+
13
+ export const NAMESPACE = PLUGIN_NAME;
14
+
15
+ export function useT() {
16
+ const engine = useFlowEngine();
17
+ return (key: string, options?: Record<string, unknown>) =>
18
+ engine.context.t(key, { ns: [NAMESPACE, 'client'], ...options });
19
+ }
20
+
21
+ export function tExpr(key: string) {
22
+ return flowTExpr(key, { ns: [NAMESPACE, 'client'] });
23
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { BlockModel } from '@nocobase/client-v2';
11
+ import React from 'react';
12
+ import type { ID } from '../../shared/types';
13
+ import { resolveFlowRootScopeId } from '../bus/DashboardFilterBus';
14
+ import { ElasticFilterBar } from '../components/ElasticFilterBar';
15
+ import { tExpr } from '../locale';
16
+
17
+ export interface ElasticFilterBarBlockModelProps {
18
+ referenceReportId?: ID;
19
+ filterFieldsCsv?: string;
20
+ showGlobalKql?: boolean;
21
+ showGlobalTimeRange?: boolean;
22
+ syncGroup?: string;
23
+ }
24
+
25
+ export class ElasticFilterBarBlockModel extends BlockModel {
26
+ declare props: ElasticFilterBarBlockModelProps;
27
+
28
+ renderComponent() {
29
+ const scopeKey = resolveFlowRootScopeId(
30
+ this as unknown as { uid?: string; parent?: unknown },
31
+ this.props.syncGroup,
32
+ );
33
+ return (
34
+ <ElasticFilterBar
35
+ scopeKey={scopeKey}
36
+ referenceReportId={this.props.referenceReportId}
37
+ filterFieldsCsv={this.props.filterFieldsCsv ?? ''}
38
+ showGlobalKql={this.props.showGlobalKql !== false}
39
+ showGlobalTimeRange={this.props.showGlobalTimeRange !== false}
40
+ />
41
+ );
42
+ }
43
+ }
44
+
45
+ ElasticFilterBarBlockModel.define({
46
+ label: tExpr('Elastic Filter Bar'),
47
+ createModelOptions: { use: 'ElasticFilterBarBlockModel' },
48
+ });
49
+
50
+ ElasticFilterBarBlockModel.registerFlow({
51
+ key: 'elasticFilterBarBlockSettings',
52
+ title: tExpr('Elastic filter bar settings'),
53
+ on: 'beforeRender',
54
+ steps: {
55
+ editFilterBar: {
56
+ title: tExpr('Elastic filter bar settings'),
57
+ uiMode: {
58
+ type: 'dialog',
59
+ props: {
60
+ width: 520,
61
+ style: { maxWidth: 'calc(100vw - 32px)' },
62
+ centered: true,
63
+ },
64
+ },
65
+ uiSchema: {
66
+ referenceReportId: {
67
+ title: tExpr('Report'),
68
+ 'x-decorator': 'FormItem',
69
+ 'x-component': 'ElasticReportSelect',
70
+ },
71
+ filterFieldsCsv: {
72
+ title: tExpr('Filter Fields (comma-separated, e.g. service, region)'),
73
+ type: 'string',
74
+ 'x-decorator': 'FormItem',
75
+ 'x-component': 'Input',
76
+ },
77
+ showGlobalKql: {
78
+ title: tExpr('Show global KQL input'),
79
+ type: 'boolean',
80
+ 'x-decorator': 'FormItem',
81
+ 'x-component': 'Switch',
82
+ },
83
+ showGlobalTimeRange: {
84
+ title: tExpr('Show global time range'),
85
+ type: 'boolean',
86
+ 'x-decorator': 'FormItem',
87
+ 'x-component': 'Switch',
88
+ },
89
+ syncGroup: {
90
+ title: tExpr('Sync Group'),
91
+ type: 'string',
92
+ 'x-decorator': 'FormItem',
93
+ 'x-component': 'Input',
94
+ },
95
+ },
96
+ defaultParams: {
97
+ showGlobalKql: true,
98
+ showGlobalTimeRange: true,
99
+ filterFieldsCsv: '',
100
+ syncGroup: '',
101
+ },
102
+ handler(ctx, params) {
103
+ ctx.model.setProps({
104
+ referenceReportId: params.referenceReportId,
105
+ filterFieldsCsv: typeof params.filterFieldsCsv === 'string' ? params.filterFieldsCsv : '',
106
+ showGlobalKql: params.showGlobalKql !== false,
107
+ showGlobalTimeRange: params.showGlobalTimeRange !== false,
108
+ syncGroup: typeof params.syncGroup === 'string' ? params.syncGroup : '',
109
+ });
110
+ },
111
+ },
112
+ },
113
+ });
114
+
115
+ export default ElasticFilterBarBlockModel;
@@ -1,85 +1,118 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- import { BlockModel } from '@nocobase/client-v2';
11
- import React from 'react';
12
- import type { ID } from '../../shared/types';
13
- import { ElasticReportBlock } from '../components/ElasticReportBlock';
14
- import { ReportSelect } from '../components/ReportSelect';
15
- import { tExpr } from '../locale';
16
-
17
- export interface ElasticReportBlockModelProps {
18
- reportId?: ID;
19
- showToolbar?: boolean;
20
- compact?: boolean;
21
- }
22
-
23
- export class ElasticReportBlockModel extends BlockModel {
24
- declare props: ElasticReportBlockModelProps;
25
-
26
- renderComponent() {
27
- return (
28
- <ElasticReportBlock
29
- reportId={this.props.reportId}
30
- showToolbar={this.props.showToolbar !== false}
31
- compact={this.props.compact === true}
32
- />
33
- );
34
- }
35
- }
36
-
37
- ElasticReportBlockModel.define({
38
- label: tExpr('Elastic Report'),
39
- createModelOptions: { use: 'ElasticReportBlockModel' },
40
- });
41
-
42
- ElasticReportBlockModel.registerFlow({
43
- key: 'elasticReportBlockSettings',
44
- title: tExpr('Elastic report settings'),
45
- on: 'beforeRender',
46
- steps: {
47
- editReport: {
48
- title: tExpr('Select report'),
49
- uiSchema: {
50
- reportId: {
51
- title: tExpr('Report'),
52
- type: 'string',
53
- 'x-decorator': 'FormItem',
54
- 'x-component': ReportSelect,
55
- required: true,
56
- },
57
- showToolbar: {
58
- title: tExpr('Show interactive toolbar'),
59
- type: 'boolean',
60
- 'x-decorator': 'FormItem',
61
- 'x-component': 'Switch',
62
- },
63
- compact: {
64
- title: tExpr('Compact layout'),
65
- type: 'boolean',
66
- 'x-decorator': 'FormItem',
67
- 'x-component': 'Switch',
68
- },
69
- },
70
- defaultParams: {
71
- showToolbar: true,
72
- compact: false,
73
- },
74
- handler(ctx, params) {
75
- ctx.model.setProps({
76
- reportId: params.reportId,
77
- showToolbar: params.showToolbar !== false,
78
- compact: params.compact === true,
79
- });
80
- },
81
- },
82
- },
83
- });
84
-
85
- export default ElasticReportBlockModel;
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { BlockModel } from '@nocobase/client-v2';
11
+ import React from 'react';
12
+ import type { ID } from '../../shared/types';
13
+ import { resolveFlowRootScopeId } from '../bus/DashboardFilterBus';
14
+ import { ElasticReportBlock } from '../components/ElasticReportBlock';
15
+ import { tExpr } from '../locale';
16
+
17
+ export interface ElasticReportBlockModelProps {
18
+ reportId?: ID;
19
+ showToolbar?: boolean;
20
+ compact?: boolean;
21
+ subscribeDashboardFilters?: boolean;
22
+ syncGroup?: string;
23
+ }
24
+
25
+ export class ElasticReportBlockModel extends BlockModel {
26
+ declare props: ElasticReportBlockModelProps;
27
+
28
+ renderComponent() {
29
+ const scopeKey = resolveFlowRootScopeId(
30
+ this as unknown as { uid?: string; parent?: unknown },
31
+ this.props.syncGroup,
32
+ );
33
+ const contextRecord = (this as unknown as { context?: { record?: unknown } }).context?.record;
34
+ return (
35
+ <ElasticReportBlock
36
+ reportId={this.props.reportId}
37
+ showToolbar={this.props.showToolbar !== false}
38
+ compact={this.props.compact === true}
39
+ scopeKey={scopeKey}
40
+ subscribeDashboardFilters={this.props.subscribeDashboardFilters !== false}
41
+ contextRecord={contextRecord}
42
+ />
43
+ );
44
+ }
45
+ }
46
+
47
+ ElasticReportBlockModel.define({
48
+ label: tExpr('Elastic Report'),
49
+ createModelOptions: { use: 'ElasticReportBlockModel' },
50
+ });
51
+
52
+ ElasticReportBlockModel.registerFlow({
53
+ key: 'elasticReportBlockSettings',
54
+ title: tExpr('Elastic report settings'),
55
+ on: 'beforeRender',
56
+ steps: {
57
+ editReport: {
58
+ title: tExpr('Select report'),
59
+ uiMode: {
60
+ type: 'dialog',
61
+ props: {
62
+ width: 520,
63
+ style: { maxWidth: 'calc(100vw - 32px)' },
64
+ centered: true,
65
+ },
66
+ },
67
+ uiSchema: {
68
+ reportId: {
69
+ title: tExpr('Report'),
70
+ 'x-decorator': 'FormItem',
71
+ 'x-component': 'ElasticReportSelect',
72
+ required: true,
73
+ },
74
+ showToolbar: {
75
+ title: tExpr('Show interactive toolbar'),
76
+ type: 'boolean',
77
+ 'x-decorator': 'FormItem',
78
+ 'x-component': 'Switch',
79
+ },
80
+ compact: {
81
+ title: tExpr('Compact layout'),
82
+ type: 'boolean',
83
+ 'x-decorator': 'FormItem',
84
+ 'x-component': 'Switch',
85
+ },
86
+ subscribeDashboardFilters: {
87
+ title: tExpr('Subscribe to dashboard filter bar'),
88
+ type: 'boolean',
89
+ 'x-decorator': 'FormItem',
90
+ 'x-component': 'Switch',
91
+ },
92
+ syncGroup: {
93
+ title: tExpr('Sync Group'),
94
+ type: 'string',
95
+ 'x-decorator': 'FormItem',
96
+ 'x-component': 'Input',
97
+ },
98
+ },
99
+ defaultParams: {
100
+ showToolbar: true,
101
+ compact: false,
102
+ subscribeDashboardFilters: true,
103
+ syncGroup: '',
104
+ },
105
+ handler(ctx, params) {
106
+ ctx.model.setProps({
107
+ reportId: params.reportId,
108
+ showToolbar: params.showToolbar !== false,
109
+ compact: params.compact === true,
110
+ subscribeDashboardFilters: params.subscribeDashboardFilters !== false,
111
+ syncGroup: typeof params.syncGroup === 'string' ? params.syncGroup : '',
112
+ });
113
+ },
114
+ },
115
+ },
116
+ });
117
+
118
+ export default ElasticReportBlockModel;