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.
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +2 -2
- package/client.js +1 -1
- package/{ai → dist/ai}/skills/elastic-report/SKILLS.md +52 -34
- package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
- package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +2 -1
- package/dist/locale/en-US.json +213 -198
- package/dist/locale/vi-VN.json +213 -198
- package/dist/locale/zh-CN.json +213 -198
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
- package/dist/server/mcp/ElasticReportToolCatalog.js +6 -4
- package/dist/server/plugin.js +4 -4
- package/dist/server/report-block-tools.js +340 -0
- package/dist/server/services/ElasticReportService.js +12 -6
- package/dist/shared/constants.js +9 -0
- package/package.json +2 -3
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/ai/skills/elastic-report/SKILLS.md +52 -0
- package/src/client/index.tsx +34 -34
- package/src/client/workflow-instructions.tsx +44 -44
- package/src/client-v2/__tests__/elastic-report.test.tsx +879 -791
- package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -178
- package/src/client-v2/api.ts +320 -320
- package/src/client-v2/bus/DashboardFilterBus.ts +212 -212
- package/src/client-v2/components/ElasticBasicCharts.tsx +652 -652
- package/src/client-v2/components/ElasticFilterBar.tsx +372 -372
- package/src/client-v2/components/ElasticKqlInput.tsx +421 -421
- package/src/client-v2/components/ElasticReportBlock.tsx +306 -306
- package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -1257
- package/src/client-v2/components/HighlightText.tsx +50 -50
- package/src/client-v2/components/ReportSelect.tsx +85 -85
- package/src/client-v2/index.tsx +14 -14
- package/src/client-v2/locale.ts +23 -23
- package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -115
- package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -118
- package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1453
- package/src/client-v2/plugin.tsx +107 -72
- package/src/client-v2/report-destination.tsx +126 -0
- package/src/client-v2/utils/kqlAutocomplete.ts +861 -861
- package/src/client-v2/workflow/instructions.tsx +149 -149
- package/src/index.ts +11 -11
- package/src/locale/en-US.json +213 -198
- package/src/locale/vi-VN.json +213 -198
- package/src/locale/zh-CN.json +213 -198
- package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
- package/src/server/__tests__/query-compiler.test.ts +620 -620
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -645
- package/src/server/acl-guard.ts +194 -194
- package/src/server/collections/es-report-data-views.ts +64 -64
- package/src/server/collections/es-reports.ts +80 -80
- package/src/server/index.ts +15 -15
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
- package/src/server/mcp/ElasticReportToolCatalog.ts +667 -663
- package/src/server/plugin.ts +599 -599
- package/src/server/report-block-tools.ts +400 -0
- package/src/server/services/ElasticReportService.ts +494 -486
- package/src/server/services/ElasticsearchConnectionService.ts +728 -728
- package/src/server/services/ReportExportService.ts +282 -282
- package/src/server/services/ReportQueryCompiler.ts +1552 -1552
- package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -124
- package/src/shared/constants.ts +39 -36
- package/src/shared/types.ts +272 -272
- package/dist/client-v2/851.142c93fc6d666b28.js +0 -10
- package/dist/client-v2/877.f4095a3dbcadf98f.js +0 -10
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +0 -15
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +0 -7
package/src/client-v2/plugin.tsx
CHANGED
|
@@ -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
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 { 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
|
+
};
|