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,212 +1,212 @@
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 { useCallback, useSyncExternalStore } from 'react';
11
- import type {
12
- AutoRefreshInterval,
13
- RecordContextBinding,
14
- ReportFilterItem,
15
- ReportTimeRange,
16
- ScalarFilterValue,
17
- SharedDashboardState,
18
- } from '../../shared/types';
19
-
20
- interface FlowModelNodeLike {
21
- uid?: string;
22
- parent?: unknown;
23
- }
24
-
25
- const EMPTY_DASHBOARD_STATE: SharedDashboardState = Object.freeze({
26
- filters: [],
27
- refreshTick: 0,
28
- updatedAt: 0,
29
- });
30
-
31
- const scopes = new Map<string, SharedDashboardState>();
32
- const listenersByScope = new Map<string, Set<() => void>>();
33
-
34
- function notifyScope(scopeKey: string): void {
35
- const listeners = listenersByScope.get(scopeKey);
36
- if (!listeners) return;
37
- for (const listener of listeners) {
38
- listener();
39
- }
40
- }
41
-
42
- export function resolveFlowRootScopeId(model?: FlowModelNodeLike, syncGroup?: string): string {
43
- let rootUid = '';
44
- let current: unknown = model;
45
- let guard = 0;
46
- while (current && typeof current === 'object' && guard < 32) {
47
- const node = current as FlowModelNodeLike;
48
- if (typeof node.uid === 'string' && node.uid) {
49
- rootUid = node.uid;
50
- }
51
- if (!node.parent) {
52
- break;
53
- }
54
- current = node.parent;
55
- guard++;
56
- }
57
- const baseScope = rootUid || (typeof window !== 'undefined' ? window.location.pathname : 'default-page');
58
- const cleanGroup = syncGroup?.trim();
59
- return cleanGroup ? `${baseScope}:${cleanGroup}` : baseScope;
60
- }
61
-
62
- export function getDashboardScopeState(scopeKey: string): SharedDashboardState {
63
- return scopes.get(scopeKey) ?? EMPTY_DASHBOARD_STATE;
64
- }
65
-
66
- export function patchDashboardScope(
67
- scopeKey: string,
68
- patch: {
69
- query?: string;
70
- timeRange?: ReportTimeRange;
71
- filters?: ReportFilterItem[];
72
- autoRefreshSec?: AutoRefreshInterval;
73
- },
74
- ): void {
75
- if (!scopeKey) return;
76
- const prev = getDashboardScopeState(scopeKey);
77
- const next: SharedDashboardState = {
78
- ...prev,
79
- ...(patch.query !== undefined ? { query: patch.query } : {}),
80
- ...(patch.timeRange !== undefined ? { timeRange: patch.timeRange } : {}),
81
- ...(patch.filters !== undefined ? { filters: patch.filters } : {}),
82
- ...(patch.autoRefreshSec !== undefined ? { autoRefreshSec: patch.autoRefreshSec } : {}),
83
- updatedAt: Date.now(),
84
- };
85
- scopes.set(scopeKey, next);
86
- notifyScope(scopeKey);
87
- }
88
-
89
- export function upsertDashboardFilter(scopeKey: string, item: ReportFilterItem): void {
90
- if (!scopeKey) return;
91
- const prev = getDashboardScopeState(scopeKey);
92
- const existingIdx = prev.filters.findIndex((f) => f.field === item.field && f.operator === item.operator);
93
- const withId: ReportFilterItem = {
94
- ...item,
95
- id: item.id ?? `shared-${Date.now()}`,
96
- enabled: true,
97
- };
98
- const nextFilters =
99
- existingIdx >= 0 ? prev.filters.map((f, idx) => (idx === existingIdx ? withId : f)) : [...prev.filters, withId];
100
- patchDashboardScope(scopeKey, { filters: nextFilters });
101
- }
102
-
103
- export function removeDashboardFilterByField(scopeKey: string, field: string): void {
104
- if (!scopeKey) return;
105
- const prev = getDashboardScopeState(scopeKey);
106
- patchDashboardScope(scopeKey, {
107
- filters: prev.filters.filter((f) => f.field !== field),
108
- });
109
- }
110
-
111
- export function removeDashboardFilterAt(scopeKey: string, index: number): void {
112
- if (!scopeKey) return;
113
- const prev = getDashboardScopeState(scopeKey);
114
- patchDashboardScope(scopeKey, {
115
- filters: prev.filters.filter((_, idx) => idx !== index),
116
- });
117
- }
118
-
119
- export function triggerDashboardRefresh(scopeKey: string): void {
120
- if (!scopeKey) return;
121
- const prev = getDashboardScopeState(scopeKey);
122
- scopes.set(scopeKey, {
123
- ...prev,
124
- refreshTick: prev.refreshTick + 1,
125
- updatedAt: Date.now(),
126
- });
127
- notifyScope(scopeKey);
128
- }
129
-
130
- export function clearDashboardScope(scopeKey: string): void {
131
- if (!scopeKey) return;
132
- const prev = getDashboardScopeState(scopeKey);
133
- scopes.set(scopeKey, {
134
- filters: [],
135
- refreshTick: prev.refreshTick + 1,
136
- updatedAt: Date.now(),
137
- });
138
- notifyScope(scopeKey);
139
- }
140
-
141
- export function useDashboardScope(scopeKey?: string | null): SharedDashboardState {
142
- const subscribe = useCallback(
143
- (onStoreChange: () => void) => {
144
- if (!scopeKey) {
145
- return () => undefined;
146
- }
147
- let set = listenersByScope.get(scopeKey);
148
- if (!set) {
149
- set = new Set();
150
- listenersByScope.set(scopeKey, set);
151
- }
152
- set.add(onStoreChange);
153
- return () => {
154
- set?.delete(onStoreChange);
155
- };
156
- },
157
- [scopeKey],
158
- );
159
-
160
- const getSnapshot = useCallback(
161
- () => (scopeKey ? getDashboardScopeState(scopeKey) : EMPTY_DASHBOARD_STATE),
162
- [scopeKey],
163
- );
164
-
165
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
166
- }
167
-
168
- function readNestedScalar(record: unknown, path: string): ScalarFilterValue | undefined {
169
- if (!record || typeof record !== 'object') return undefined;
170
- const parts = path.split('.').filter(Boolean);
171
- let cur: unknown = record;
172
- for (const part of parts) {
173
- if (cur && typeof cur === 'object' && !Array.isArray(cur) && part in (cur as Record<string, unknown>)) {
174
- cur = (cur as Record<string, unknown>)[part];
175
- } else {
176
- return undefined;
177
- }
178
- }
179
- if (typeof cur === 'string' && cur.trim()) return cur.trim();
180
- if (typeof cur === 'number' && Number.isFinite(cur)) return cur;
181
- if (typeof cur === 'boolean') return cur;
182
- return undefined;
183
- }
184
-
185
- export function buildRecordContextFilters(
186
- bindings: RecordContextBinding[] | undefined,
187
- record: unknown,
188
- ): ReportFilterItem[] {
189
- if (!bindings || bindings.length === 0 || !record) return [];
190
- const items: ReportFilterItem[] = [];
191
- for (const binding of bindings) {
192
- const val = readNestedScalar(record, binding.recordFieldPath);
193
- if (val !== undefined) {
194
- items.push({
195
- id: `ctx-${binding.esField}`,
196
- field: binding.esField,
197
- operator: 'eq',
198
- value: val,
199
- enabled: true,
200
- });
201
- }
202
- }
203
- return items;
204
- }
205
-
206
- export function detectBrowserTimeZone(): string | undefined {
207
- try {
208
- return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined;
209
- } catch {
210
- return undefined;
211
- }
212
- }
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 { useCallback, useSyncExternalStore } from 'react';
11
+ import type {
12
+ AutoRefreshInterval,
13
+ RecordContextBinding,
14
+ ReportFilterItem,
15
+ ReportTimeRange,
16
+ ScalarFilterValue,
17
+ SharedDashboardState,
18
+ } from '../../shared/types';
19
+
20
+ interface FlowModelNodeLike {
21
+ uid?: string;
22
+ parent?: unknown;
23
+ }
24
+
25
+ const EMPTY_DASHBOARD_STATE: SharedDashboardState = Object.freeze({
26
+ filters: [],
27
+ refreshTick: 0,
28
+ updatedAt: 0,
29
+ });
30
+
31
+ const scopes = new Map<string, SharedDashboardState>();
32
+ const listenersByScope = new Map<string, Set<() => void>>();
33
+
34
+ function notifyScope(scopeKey: string): void {
35
+ const listeners = listenersByScope.get(scopeKey);
36
+ if (!listeners) return;
37
+ for (const listener of listeners) {
38
+ listener();
39
+ }
40
+ }
41
+
42
+ export function resolveFlowRootScopeId(model?: FlowModelNodeLike, syncGroup?: string): string {
43
+ let rootUid = '';
44
+ let current: unknown = model;
45
+ let guard = 0;
46
+ while (current && typeof current === 'object' && guard < 32) {
47
+ const node = current as FlowModelNodeLike;
48
+ if (typeof node.uid === 'string' && node.uid) {
49
+ rootUid = node.uid;
50
+ }
51
+ if (!node.parent) {
52
+ break;
53
+ }
54
+ current = node.parent;
55
+ guard++;
56
+ }
57
+ const baseScope = rootUid || (typeof window !== 'undefined' ? window.location.pathname : 'default-page');
58
+ const cleanGroup = syncGroup?.trim();
59
+ return cleanGroup ? `${baseScope}:${cleanGroup}` : baseScope;
60
+ }
61
+
62
+ export function getDashboardScopeState(scopeKey: string): SharedDashboardState {
63
+ return scopes.get(scopeKey) ?? EMPTY_DASHBOARD_STATE;
64
+ }
65
+
66
+ export function patchDashboardScope(
67
+ scopeKey: string,
68
+ patch: {
69
+ query?: string;
70
+ timeRange?: ReportTimeRange;
71
+ filters?: ReportFilterItem[];
72
+ autoRefreshSec?: AutoRefreshInterval;
73
+ },
74
+ ): void {
75
+ if (!scopeKey) return;
76
+ const prev = getDashboardScopeState(scopeKey);
77
+ const next: SharedDashboardState = {
78
+ ...prev,
79
+ ...(patch.query !== undefined ? { query: patch.query } : {}),
80
+ ...(patch.timeRange !== undefined ? { timeRange: patch.timeRange } : {}),
81
+ ...(patch.filters !== undefined ? { filters: patch.filters } : {}),
82
+ ...(patch.autoRefreshSec !== undefined ? { autoRefreshSec: patch.autoRefreshSec } : {}),
83
+ updatedAt: Date.now(),
84
+ };
85
+ scopes.set(scopeKey, next);
86
+ notifyScope(scopeKey);
87
+ }
88
+
89
+ export function upsertDashboardFilter(scopeKey: string, item: ReportFilterItem): void {
90
+ if (!scopeKey) return;
91
+ const prev = getDashboardScopeState(scopeKey);
92
+ const existingIdx = prev.filters.findIndex((f) => f.field === item.field && f.operator === item.operator);
93
+ const withId: ReportFilterItem = {
94
+ ...item,
95
+ id: item.id ?? `shared-${Date.now()}`,
96
+ enabled: true,
97
+ };
98
+ const nextFilters =
99
+ existingIdx >= 0 ? prev.filters.map((f, idx) => (idx === existingIdx ? withId : f)) : [...prev.filters, withId];
100
+ patchDashboardScope(scopeKey, { filters: nextFilters });
101
+ }
102
+
103
+ export function removeDashboardFilterByField(scopeKey: string, field: string): void {
104
+ if (!scopeKey) return;
105
+ const prev = getDashboardScopeState(scopeKey);
106
+ patchDashboardScope(scopeKey, {
107
+ filters: prev.filters.filter((f) => f.field !== field),
108
+ });
109
+ }
110
+
111
+ export function removeDashboardFilterAt(scopeKey: string, index: number): void {
112
+ if (!scopeKey) return;
113
+ const prev = getDashboardScopeState(scopeKey);
114
+ patchDashboardScope(scopeKey, {
115
+ filters: prev.filters.filter((_, idx) => idx !== index),
116
+ });
117
+ }
118
+
119
+ export function triggerDashboardRefresh(scopeKey: string): void {
120
+ if (!scopeKey) return;
121
+ const prev = getDashboardScopeState(scopeKey);
122
+ scopes.set(scopeKey, {
123
+ ...prev,
124
+ refreshTick: prev.refreshTick + 1,
125
+ updatedAt: Date.now(),
126
+ });
127
+ notifyScope(scopeKey);
128
+ }
129
+
130
+ export function clearDashboardScope(scopeKey: string): void {
131
+ if (!scopeKey) return;
132
+ const prev = getDashboardScopeState(scopeKey);
133
+ scopes.set(scopeKey, {
134
+ filters: [],
135
+ refreshTick: prev.refreshTick + 1,
136
+ updatedAt: Date.now(),
137
+ });
138
+ notifyScope(scopeKey);
139
+ }
140
+
141
+ export function useDashboardScope(scopeKey?: string | null): SharedDashboardState {
142
+ const subscribe = useCallback(
143
+ (onStoreChange: () => void) => {
144
+ if (!scopeKey) {
145
+ return () => undefined;
146
+ }
147
+ let set = listenersByScope.get(scopeKey);
148
+ if (!set) {
149
+ set = new Set();
150
+ listenersByScope.set(scopeKey, set);
151
+ }
152
+ set.add(onStoreChange);
153
+ return () => {
154
+ set?.delete(onStoreChange);
155
+ };
156
+ },
157
+ [scopeKey],
158
+ );
159
+
160
+ const getSnapshot = useCallback(
161
+ () => (scopeKey ? getDashboardScopeState(scopeKey) : EMPTY_DASHBOARD_STATE),
162
+ [scopeKey],
163
+ );
164
+
165
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
166
+ }
167
+
168
+ function readNestedScalar(record: unknown, path: string): ScalarFilterValue | undefined {
169
+ if (!record || typeof record !== 'object') return undefined;
170
+ const parts = path.split('.').filter(Boolean);
171
+ let cur: unknown = record;
172
+ for (const part of parts) {
173
+ if (cur && typeof cur === 'object' && !Array.isArray(cur) && part in (cur as Record<string, unknown>)) {
174
+ cur = (cur as Record<string, unknown>)[part];
175
+ } else {
176
+ return undefined;
177
+ }
178
+ }
179
+ if (typeof cur === 'string' && cur.trim()) return cur.trim();
180
+ if (typeof cur === 'number' && Number.isFinite(cur)) return cur;
181
+ if (typeof cur === 'boolean') return cur;
182
+ return undefined;
183
+ }
184
+
185
+ export function buildRecordContextFilters(
186
+ bindings: RecordContextBinding[] | undefined,
187
+ record: unknown,
188
+ ): ReportFilterItem[] {
189
+ if (!bindings || bindings.length === 0 || !record) return [];
190
+ const items: ReportFilterItem[] = [];
191
+ for (const binding of bindings) {
192
+ const val = readNestedScalar(record, binding.recordFieldPath);
193
+ if (val !== undefined) {
194
+ items.push({
195
+ id: `ctx-${binding.esField}`,
196
+ field: binding.esField,
197
+ operator: 'eq',
198
+ value: val,
199
+ enabled: true,
200
+ });
201
+ }
202
+ }
203
+ return items;
204
+ }
205
+
206
+ export function detectBrowserTimeZone(): string | undefined {
207
+ try {
208
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined;
209
+ } catch {
210
+ return undefined;
211
+ }
212
+ }