plugin-elastic-report 0.7.0 → 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 (70) 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/{ai → dist/ai}/skills/elastic-report/SKILLS.md +52 -34
  6. package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
  7. package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
  8. package/dist/client-v2/index.js +1 -1
  9. package/dist/externalVersion.js +2 -1
  10. package/dist/locale/en-US.json +213 -198
  11. package/dist/locale/vi-VN.json +213 -198
  12. package/dist/locale/zh-CN.json +213 -198
  13. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
  14. package/dist/server/mcp/ElasticReportToolCatalog.js +6 -4
  15. package/dist/server/plugin.js +4 -4
  16. package/dist/server/report-block-tools.js +340 -0
  17. package/dist/server/services/ElasticReportService.js +12 -6
  18. package/dist/shared/constants.js +9 -0
  19. package/package.json +2 -3
  20. package/server.d.ts +2 -2
  21. package/server.js +1 -1
  22. package/src/ai/skills/elastic-report/SKILLS.md +52 -0
  23. package/src/client/index.tsx +34 -34
  24. package/src/client/workflow-instructions.tsx +44 -44
  25. package/src/client-v2/__tests__/elastic-report.test.tsx +879 -791
  26. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -178
  27. package/src/client-v2/api.ts +320 -320
  28. package/src/client-v2/bus/DashboardFilterBus.ts +212 -212
  29. package/src/client-v2/components/ElasticBasicCharts.tsx +652 -652
  30. package/src/client-v2/components/ElasticFilterBar.tsx +372 -372
  31. package/src/client-v2/components/ElasticKqlInput.tsx +421 -421
  32. package/src/client-v2/components/ElasticReportBlock.tsx +306 -306
  33. package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -1257
  34. package/src/client-v2/components/HighlightText.tsx +50 -50
  35. package/src/client-v2/components/ReportSelect.tsx +85 -85
  36. package/src/client-v2/index.tsx +14 -14
  37. package/src/client-v2/locale.ts +23 -23
  38. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -115
  39. package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -118
  40. package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1453
  41. package/src/client-v2/plugin.tsx +107 -72
  42. package/src/client-v2/report-destination.tsx +126 -0
  43. package/src/client-v2/utils/kqlAutocomplete.ts +861 -861
  44. package/src/client-v2/workflow/instructions.tsx +149 -149
  45. package/src/index.ts +11 -11
  46. package/src/locale/en-US.json +213 -198
  47. package/src/locale/vi-VN.json +213 -198
  48. package/src/locale/zh-CN.json +213 -198
  49. package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
  50. package/src/server/__tests__/query-compiler.test.ts +620 -620
  51. package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -645
  52. package/src/server/acl-guard.ts +194 -194
  53. package/src/server/collections/es-report-data-views.ts +64 -64
  54. package/src/server/collections/es-reports.ts +80 -80
  55. package/src/server/index.ts +15 -15
  56. package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
  57. package/src/server/mcp/ElasticReportToolCatalog.ts +667 -663
  58. package/src/server/plugin.ts +599 -599
  59. package/src/server/report-block-tools.ts +400 -0
  60. package/src/server/services/ElasticReportService.ts +494 -486
  61. package/src/server/services/ElasticsearchConnectionService.ts +728 -728
  62. package/src/server/services/ReportExportService.ts +282 -282
  63. package/src/server/services/ReportQueryCompiler.ts +1552 -1552
  64. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -124
  65. package/src/shared/constants.ts +39 -36
  66. package/src/shared/types.ts +272 -272
  67. package/dist/client-v2/851.142c93fc6d666b28.js +0 -10
  68. package/dist/client-v2/877.f4095a3dbcadf98f.js +0 -10
  69. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +0 -15
  70. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +0 -7
@@ -1,72 +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
- import { ReportSelect } from './components/ReportSelect';
13
- import type { WorkflowClientRegistry } from './workflow/instructions';
14
-
15
- export class PluginElasticReportClient extends Plugin<Record<string, never>, Application> {
16
- async load() {
17
- this.flowEngine.flowSettings?.registerComponents?.({
18
- ElasticReportSelect: ReportSelect,
19
- });
20
-
21
- this.flowEngine.registerModelLoaders({
22
- ElasticReportBlockModel: {
23
- extends: 'BlockModel',
24
- loader: () => import('./models/ElasticReportBlockModel'),
25
- },
26
- ElasticFilterBarBlockModel: {
27
- extends: 'BlockModel',
28
- loader: () => import('./models/ElasticFilterBarBlockModel'),
29
- },
30
- });
31
-
32
- const title = this.t('Elastic Report');
33
-
34
- this.pluginSettingsManager.addMenuItem({
35
- key: SETTINGS_MENU_KEY,
36
- title,
37
- icon: 'BarChartOutlined',
38
- aclSnippet: ACL_SNIPPET,
39
- });
40
-
41
- this.pluginSettingsManager.addPageTabItem({
42
- menuKey: SETTINGS_MENU_KEY,
43
- key: 'index',
44
- title,
45
- aclSnippet: ACL_SNIPPET,
46
- componentLoader: () => import('./pages/ElasticReportManager'),
47
- });
48
-
49
- if (typeof this.pluginSettingsManager.setPluginSettingsLink === 'function') {
50
- const names = new Set(
51
- [PLUGIN_NAME, SETTINGS_MENU_KEY, this.options?.name, this.options?.packageName].filter(
52
- (item): item is string => typeof item === 'string' && item.trim().length > 0,
53
- ),
54
- );
55
- for (const pluginName of names) {
56
- this.pluginSettingsManager.setPluginSettingsLink(pluginName, SETTINGS_MENU_KEY);
57
- }
58
- }
59
-
60
- const workflow = (
61
- this.app as unknown as {
62
- pm?: { get?: (name: string) => WorkflowClientRegistry | undefined };
63
- }
64
- ).pm?.get?.('workflow');
65
- if (workflow && typeof workflow.registerInstruction === 'function') {
66
- const { registerElasticReportWorkflowInstructions } = await import('./workflow/instructions');
67
- registerElasticReportWorkflowInstructions(workflow);
68
- }
69
- }
70
- }
71
-
72
- 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
+ };