plugin-elastic-report 0.1.1 → 0.7.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 (60) hide show
  1. package/ai/skills/elastic-report/SKILLS.md +5 -3
  2. package/dist/client/357.0dd385384cab5dbf.js +10 -0
  3. package/dist/client/index.js +1 -1
  4. package/dist/client-v2/851.142c93fc6d666b28.js +10 -0
  5. package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
  6. package/dist/client-v2/877.f4095a3dbcadf98f.js +10 -0
  7. package/dist/client-v2/index.js +1 -1
  8. package/dist/externalVersion.js +3 -2
  9. package/dist/locale/en-US.json +100 -1
  10. package/dist/locale/vi-VN.json +100 -1
  11. package/dist/locale/zh-CN.json +100 -1
  12. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
  13. package/dist/server/acl-guard.js +97 -25
  14. package/dist/server/collections/es-report-data-views.js +6 -0
  15. package/dist/server/collections/es-reports.js +6 -0
  16. package/dist/server/mcp/ElasticReportToolCatalog.js +232 -10
  17. package/dist/server/plugin.js +153 -19
  18. package/dist/server/services/ElasticReportService.js +125 -11
  19. package/dist/server/services/ElasticsearchConnectionService.js +274 -34
  20. package/dist/server/services/ReportExportService.js +243 -0
  21. package/dist/server/services/ReportQueryCompiler.js +532 -91
  22. package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
  23. package/dist/shared/constants.js +17 -2
  24. package/package.json +3 -2
  25. package/src/client/index.tsx +16 -1
  26. package/src/client/workflow-instructions.tsx +44 -0
  27. package/src/client-v2/__tests__/elastic-report.test.tsx +519 -39
  28. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
  29. package/src/client-v2/api.ts +96 -0
  30. package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
  31. package/src/client-v2/components/ElasticBasicCharts.tsx +345 -92
  32. package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
  33. package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
  34. package/src/client-v2/components/ElasticReportBlock.tsx +157 -11
  35. package/src/client-v2/components/ElasticReportRenderer.tsx +621 -71
  36. package/src/client-v2/components/ReportSelect.tsx +39 -26
  37. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
  38. package/src/client-v2/models/ElasticReportBlockModel.tsx +36 -3
  39. package/src/client-v2/pages/ElasticReportManager.tsx +432 -26
  40. package/src/client-v2/plugin.tsx +20 -0
  41. package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
  42. package/src/client-v2/workflow/instructions.tsx +149 -0
  43. package/src/locale/en-US.json +100 -1
  44. package/src/locale/vi-VN.json +100 -1
  45. package/src/locale/zh-CN.json +100 -1
  46. package/src/server/__tests__/query-compiler.test.ts +390 -1
  47. package/src/server/__tests__/report-mcp-acl.integration.test.ts +271 -3
  48. package/src/server/acl-guard.ts +119 -28
  49. package/src/server/collections/es-report-data-views.ts +6 -0
  50. package/src/server/collections/es-reports.ts +6 -0
  51. package/src/server/mcp/ElasticReportToolCatalog.ts +255 -9
  52. package/src/server/plugin.ts +189 -21
  53. package/src/server/services/ElasticReportService.ts +165 -5
  54. package/src/server/services/ElasticsearchConnectionService.ts +375 -48
  55. package/src/server/services/ReportExportService.ts +282 -0
  56. package/src/server/services/ReportQueryCompiler.ts +629 -94
  57. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
  58. package/src/shared/constants.ts +7 -0
  59. package/src/shared/types.ts +98 -1
  60. package/dist/client-v2/851.488fdbf5bc5b6a36.js +0 -10
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import { useApp } from '@nocobase/client-v2';
11
+ import { useFlowEngine } from '@nocobase/flow-engine';
11
12
  import { Select, Tag, type SelectProps } from 'antd';
12
13
  import React, { useCallback, useEffect, useState } from 'react';
13
14
  import type { EsReportRecord, ID } from '../../shared/types';
@@ -15,14 +16,18 @@ import { fetchPublishedReports, type ApiClientLike } from '../api';
15
16
  import { useT } from '../locale';
16
17
 
17
18
  export const ReportSelect: React.FC<SelectProps<ID>> = (props) => {
19
+ const { style, ...restProps } = props;
18
20
  const t = useT();
19
21
  const app = useApp();
20
- const api = app.apiClient as unknown as ApiClientLike;
22
+ const flowEngine = useFlowEngine();
23
+ const api = ((app as { apiClient?: unknown } | undefined)?.apiClient ??
24
+ (flowEngine as { context?: { api?: unknown } } | undefined)?.context?.api) as ApiClientLike;
21
25
  const [reports, setReports] = useState<EsReportRecord[]>([]);
22
26
  const [loading, setLoading] = useState(false);
23
27
 
24
28
  const loadReports = useCallback(
25
29
  async (search?: string) => {
30
+ if (!api) return;
26
31
  setLoading(true);
27
32
  try {
28
33
  const list = await fetchPublishedReports(api, search);
@@ -41,32 +46,40 @@ export const ReportSelect: React.FC<SelectProps<ID>> = (props) => {
41
46
  }, [loadReports]);
42
47
 
43
48
  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 }}>
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 }}>
64
77
  {item.visualization.toUpperCase()}
65
78
  </Tag>
66
- </span>
67
- </div>
68
- );
69
- }}
70
- />
79
+ </div>
80
+ );
81
+ }}
82
+ />
83
+ </div>
71
84
  );
72
85
  };
@@ -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;
@@ -10,25 +10,35 @@
10
10
  import { BlockModel } from '@nocobase/client-v2';
11
11
  import React from 'react';
12
12
  import type { ID } from '../../shared/types';
13
+ import { resolveFlowRootScopeId } from '../bus/DashboardFilterBus';
13
14
  import { ElasticReportBlock } from '../components/ElasticReportBlock';
14
- import { ReportSelect } from '../components/ReportSelect';
15
15
  import { tExpr } from '../locale';
16
16
 
17
17
  export interface ElasticReportBlockModelProps {
18
18
  reportId?: ID;
19
19
  showToolbar?: boolean;
20
20
  compact?: boolean;
21
+ subscribeDashboardFilters?: boolean;
22
+ syncGroup?: string;
21
23
  }
22
24
 
23
25
  export class ElasticReportBlockModel extends BlockModel {
24
26
  declare props: ElasticReportBlockModelProps;
25
27
 
26
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;
27
34
  return (
28
35
  <ElasticReportBlock
29
36
  reportId={this.props.reportId}
30
37
  showToolbar={this.props.showToolbar !== false}
31
38
  compact={this.props.compact === true}
39
+ scopeKey={scopeKey}
40
+ subscribeDashboardFilters={this.props.subscribeDashboardFilters !== false}
41
+ contextRecord={contextRecord}
32
42
  />
33
43
  );
34
44
  }
@@ -46,12 +56,19 @@ ElasticReportBlockModel.registerFlow({
46
56
  steps: {
47
57
  editReport: {
48
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
+ },
49
67
  uiSchema: {
50
68
  reportId: {
51
69
  title: tExpr('Report'),
52
- type: 'string',
53
70
  'x-decorator': 'FormItem',
54
- 'x-component': ReportSelect,
71
+ 'x-component': 'ElasticReportSelect',
55
72
  required: true,
56
73
  },
57
74
  showToolbar: {
@@ -66,16 +83,32 @@ ElasticReportBlockModel.registerFlow({
66
83
  'x-decorator': 'FormItem',
67
84
  'x-component': 'Switch',
68
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
+ },
69
98
  },
70
99
  defaultParams: {
71
100
  showToolbar: true,
72
101
  compact: false,
102
+ subscribeDashboardFilters: true,
103
+ syncGroup: '',
73
104
  },
74
105
  handler(ctx, params) {
75
106
  ctx.model.setProps({
76
107
  reportId: params.reportId,
77
108
  showToolbar: params.showToolbar !== false,
78
109
  compact: params.compact === true,
110
+ subscribeDashboardFilters: params.subscribeDashboardFilters !== false,
111
+ syncGroup: typeof params.syncGroup === 'string' ? params.syncGroup : '',
79
112
  });
80
113
  },
81
114
  },