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,52 +1,107 @@
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 { Application, Plugin } from '@nocobase/client-v2';
11
- import { ACL_SNIPPET, PLUGIN_NAME, SETTINGS_MENU_KEY } from '../shared/constants';
12
-
13
- export class PluginElasticReportClient extends Plugin<Record<string, never>, Application> {
14
- async load() {
15
- this.flowEngine.registerModelLoaders({
16
- ElasticReportBlockModel: {
17
- extends: 'BlockModel',
18
- loader: () => import('./models/ElasticReportBlockModel'),
19
- },
20
- });
21
-
22
- const title = this.t('Elastic Report');
23
-
24
- this.pluginSettingsManager.addMenuItem({
25
- key: SETTINGS_MENU_KEY,
26
- title,
27
- icon: 'BarChartOutlined',
28
- aclSnippet: ACL_SNIPPET,
29
- });
30
-
31
- this.pluginSettingsManager.addPageTabItem({
32
- menuKey: SETTINGS_MENU_KEY,
33
- key: 'index',
34
- title,
35
- aclSnippet: ACL_SNIPPET,
36
- componentLoader: () => import('./pages/ElasticReportManager'),
37
- });
38
-
39
- if (typeof this.pluginSettingsManager.setPluginSettingsLink === 'function') {
40
- const names = new Set(
41
- [PLUGIN_NAME, SETTINGS_MENU_KEY, this.options?.name, this.options?.packageName].filter(
42
- (item): item is string => typeof item === 'string' && item.trim().length > 0,
43
- ),
44
- );
45
- for (const pluginName of names) {
46
- this.pluginSettingsManager.setPluginSettingsLink(pluginName, SETTINGS_MENU_KEY);
47
- }
48
- }
49
- }
50
- }
51
-
52
- export default PluginElasticReportClient;
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 { Application, Plugin } from '@nocobase/client-v2';
11
+ import type PluginAIClient from '@nocobase/plugin-ai/client-v2';
12
+ import {
13
+ ACL_SNIPPET,
14
+ BLOCK_ADDED_EVENT,
15
+ BLOCK_SETTINGS_EVENT,
16
+ PLUGIN_NAME,
17
+ REPORT_DESTINATION_CONTEXT,
18
+ SETTINGS_MENU_KEY,
19
+ } from '../shared/constants';
20
+ import { ReportSelect } from './components/ReportSelect';
21
+ import { reportDestinationContext } from './report-destination';
22
+ import type { ElasticReportBlockModelProps } from './models/ElasticReportBlockModel';
23
+ import type { WorkflowClientRegistry } from './workflow/instructions';
24
+
25
+ export class PluginElasticReportClient extends Plugin<Record<string, never>, Application> {
26
+ async load() {
27
+ this.app.pm
28
+ ?.get<PluginAIClient>('ai')
29
+ ?.aiManager?.registerWorkContext(REPORT_DESTINATION_CONTEXT, reportDestinationContext);
30
+ this.app.eventBus?.addEventListener(`ws:message:${BLOCK_ADDED_EVENT}`, async (event: Event) => {
31
+ const detail = (event as CustomEvent<{ gridUid: string; blockUid: string }>).detail;
32
+ const grid = detail && this.flowEngine.getModel(detail.gridUid, true);
33
+ if (grid?.use !== 'BlockGridModel' || grid.findSubModel('items', (item) => item.uid === detail.blockUid)) return;
34
+ const child = await grid.flowEngine.loadModel({ uid: detail.blockUid });
35
+ if (
36
+ child?.use === 'ElasticReportBlockModel' &&
37
+ child.parentId === grid.uid &&
38
+ !grid.findSubModel('items', (item) => item.uid === child.uid)
39
+ ) {
40
+ grid.addSubModel('items', child);
41
+ grid.refresh();
42
+ }
43
+ });
44
+ this.app.eventBus?.addEventListener(`ws:message:${BLOCK_SETTINGS_EVENT}`, (event: Event) => {
45
+ const detail = (event as CustomEvent<{ blockUid: string; changes: ElasticReportBlockModelProps }>).detail;
46
+ const model = detail && this.flowEngine.getModel(detail.blockUid, true);
47
+ if (model?.use === 'ElasticReportBlockModel') {
48
+ model.setStepParams('elasticReportBlockSettings', 'editReport', { ...detail.changes });
49
+ model.setProps(detail.changes);
50
+ }
51
+ });
52
+ this.flowEngine.flowSettings?.registerComponents?.({
53
+ ElasticReportSelect: ReportSelect,
54
+ });
55
+
56
+ this.flowEngine.registerModelLoaders({
57
+ ElasticReportBlockModel: {
58
+ extends: 'BlockModel',
59
+ loader: () => import('./models/ElasticReportBlockModel'),
60
+ },
61
+ ElasticFilterBarBlockModel: {
62
+ extends: 'BlockModel',
63
+ loader: () => import('./models/ElasticFilterBarBlockModel'),
64
+ },
65
+ });
66
+
67
+ const title = this.t('Elastic Report');
68
+
69
+ this.pluginSettingsManager.addMenuItem({
70
+ key: SETTINGS_MENU_KEY,
71
+ title,
72
+ icon: 'BarChartOutlined',
73
+ aclSnippet: ACL_SNIPPET,
74
+ });
75
+
76
+ this.pluginSettingsManager.addPageTabItem({
77
+ menuKey: SETTINGS_MENU_KEY,
78
+ key: 'index',
79
+ title,
80
+ aclSnippet: ACL_SNIPPET,
81
+ componentLoader: () => import('./pages/ElasticReportManager'),
82
+ });
83
+
84
+ if (typeof this.pluginSettingsManager.setPluginSettingsLink === 'function') {
85
+ const names = new Set(
86
+ [PLUGIN_NAME, SETTINGS_MENU_KEY, this.options?.name, this.options?.packageName].filter(
87
+ (item): item is string => typeof item === 'string' && item.trim().length > 0,
88
+ ),
89
+ );
90
+ for (const pluginName of names) {
91
+ this.pluginSettingsManager.setPluginSettingsLink(pluginName, SETTINGS_MENU_KEY);
92
+ }
93
+ }
94
+
95
+ const workflow = (
96
+ this.app as unknown as {
97
+ pm?: { get?: (name: string) => WorkflowClientRegistry | undefined };
98
+ }
99
+ ).pm?.get?.('workflow');
100
+ if (workflow && typeof workflow.registerInstruction === 'function') {
101
+ const { registerElasticReportWorkflowInstructions } = await import('./workflow/instructions');
102
+ registerElasticReportWorkflowInstructions(workflow);
103
+ }
104
+ }
105
+ }
106
+
107
+ export default PluginElasticReportClient;
@@ -0,0 +1,126 @@
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
+ /**
11
+ * This file is part of the NocoBase (R) project.
12
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
13
+ * Authors: NocoBase Team.
14
+ *
15
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
16
+ * For more information, please refer to: https://www.nocobase.com/agreement.
17
+ */
18
+
19
+ import type { AIManager } from '@nocobase/plugin-ai/client-v2';
20
+ import { Button, Form, Select } from 'antd';
21
+ import React, { useState } from 'react';
22
+ import { REPORT_DESTINATION_CONTEXT } from '../shared/constants';
23
+ import type { ID } from '../shared/types';
24
+ import { ReportSelect } from './components/ReportSelect';
25
+ import { useT } from './locale';
26
+
27
+ type WorkContext = Parameters<AIManager['registerWorkContext']>[1];
28
+ type PickerProps = Parameters<NonNullable<NonNullable<WorkContext['menu']>['onClick']>>[0];
29
+ type Route = {
30
+ type?: string;
31
+ title?: string;
32
+ schemaUid?: string;
33
+ children?: Route[];
34
+ enableTabs?: boolean;
35
+ hidden?: boolean;
36
+ };
37
+
38
+ function destinationTabs(routes: Route[], path: string[] = []): { label: string; value: string; pageUid: string }[] {
39
+ return routes.flatMap((route) => {
40
+ const names = [...path, route.title || route.schemaUid || ''];
41
+ if (route.type === 'group') return destinationTabs(route.children || [], names);
42
+ const pageUid = route.schemaUid;
43
+ if (route.type !== 'flowPage' || !pageUid) return [];
44
+ const tabs = (route.children || []).filter(
45
+ (tab): tab is Route & { schemaUid: string } => tab.type === 'tabs' && !!tab.schemaUid,
46
+ );
47
+ // With tabs disabled, PageModel renders the first tab even when its navigation entry is hidden.
48
+ return (route.enableTabs ? tabs.filter((tab) => !tab.hidden) : tabs.slice(0, 1)).map((tab) => ({
49
+ pageUid,
50
+ value: tab.schemaUid,
51
+ label: (route.enableTabs ? [...names, tab.title || tab.schemaUid] : names).join(' / '),
52
+ }));
53
+ });
54
+ }
55
+
56
+ function DestinationPicker({
57
+ tabs,
58
+ contextItems,
59
+ onAdd,
60
+ onRemove,
61
+ close,
62
+ }: Omit<PickerProps, 'ctx'> & {
63
+ tabs: ReturnType<typeof destinationTabs>;
64
+ close: () => void;
65
+ }) {
66
+ const t = useT();
67
+ const [tabUid, setTabUid] = useState<string>();
68
+ const [report, setReport] = useState<{ id: ID; label: string }>();
69
+ const tab = tabs.find((item) => item.value === tabUid);
70
+ return (
71
+ <Form
72
+ layout="vertical"
73
+ onFinish={() => {
74
+ if (!tab || !report) return;
75
+ for (const item of contextItems || []) if (item.type === REPORT_DESTINATION_CONTEXT) onRemove(item.uid);
76
+ onAdd({
77
+ uid: tab.value,
78
+ title: [tab.label, report.label].join(' / '),
79
+ content: { pageUid: tab.pageUid, tabUid: tab.value, reportId: report.id },
80
+ });
81
+ close();
82
+ }}
83
+ >
84
+ <Form.Item label={t('Page and tab')}>
85
+ <Select
86
+ aria-label={t('Page and tab')}
87
+ showSearch
88
+ optionFilterProp="label"
89
+ options={tabs}
90
+ value={tabUid}
91
+ onChange={setTabUid}
92
+ />
93
+ </Form.Item>
94
+ <Form.Item label={t('Report')}>
95
+ <ReportSelect
96
+ aria-label={t('Report')}
97
+ value={report?.id}
98
+ onChange={(id, option) => {
99
+ setReport(id == null ? undefined : { id, label: String((!Array.isArray(option) && option?.label) || id) });
100
+ }}
101
+ />
102
+ </Form.Item>
103
+ <Button type="primary" htmlType="submit" disabled={!tab || !report}>
104
+ {t('Attach destination')}
105
+ </Button>
106
+ </Form>
107
+ );
108
+ }
109
+
110
+ export const reportDestinationContext: WorkContext = {
111
+ name: REPORT_DESTINATION_CONTEXT,
112
+ menu: {
113
+ Component: function DestinationLabel() {
114
+ const t = useT();
115
+ return <span>{t('Report block destination')}</span>;
116
+ },
117
+ onClick: ({ ctx, ...props }) => {
118
+ const tabs = destinationTabs(ctx.routeRepository.listAccessible());
119
+ ctx.viewer.dialog({
120
+ title: ctx.t('Report block destination', { ns: 'plugin-elastic-report' }),
121
+ content: (view) => <DestinationPicker {...props} tabs={tabs} close={() => view.close()} />,
122
+ });
123
+ },
124
+ },
125
+ tag: { Component: ({ item }) => <span>{item.title}</span> },
126
+ };