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,306 +1,306 @@
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 { useApp } from '@nocobase/client-v2';
11
- import { Card, Empty, Tag } from 'antd';
12
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
13
- import type {
14
- EsDataViewRecord,
15
- EsFieldCapability,
16
- EsReportRecord,
17
- ExportFormat,
18
- FieldTopValuesResult,
19
- ID,
20
- ReportExecutionResult,
21
- ReportFilterItem,
22
- ReportRuntimeOverrides,
23
- } from '../../shared/types';
24
- import {
25
- downloadReportExport,
26
- executeSavedReport,
27
- fetchFieldTopValues,
28
- fetchReportMeta,
29
- type ApiClientLike,
30
- } from '../api';
31
- import {
32
- buildRecordContextFilters,
33
- detectBrowserTimeZone,
34
- upsertDashboardFilter,
35
- useDashboardScope,
36
- } from '../bus/DashboardFilterBus';
37
- import { useT } from '../locale';
38
- import { ElasticReportRenderer } from './ElasticReportRenderer';
39
-
40
- export interface ElasticReportBlockProps {
41
- reportId?: ID;
42
- showToolbar?: boolean;
43
- compact?: boolean;
44
- scopeKey?: string;
45
- subscribeDashboardFilters?: boolean;
46
- contextRecord?: unknown;
47
- }
48
-
49
- export const ElasticReportBlock: React.FC<ElasticReportBlockProps> = ({
50
- reportId,
51
- showToolbar = true,
52
- compact = false,
53
- scopeKey,
54
- subscribeDashboardFilters = true,
55
- contextRecord,
56
- }) => {
57
- const t = useT();
58
- const app = useApp();
59
- const api = app.apiClient as unknown as ApiClientLike;
60
- const apiRef = useRef<ApiClientLike>(api);
61
- apiRef.current = api;
62
-
63
- const activeScopeKey = subscribeDashboardFilters && scopeKey ? scopeKey : null;
64
- const sharedState = useDashboardScope(activeScopeKey);
65
-
66
- const [report, setReport] = useState<EsReportRecord | null>(null);
67
- const [dataView, setDataView] = useState<EsDataViewRecord | null>(null);
68
- const [fields, setFields] = useState<EsFieldCapability[]>([]);
69
- const [result, setResult] = useState<ReportExecutionResult | null>(null);
70
- const [loading, setLoading] = useState(false);
71
- const [error, setError] = useState<string | null>(null);
72
- const reqCounter = useRef(0);
73
- const latestLocalOverridesRef = useRef<ReportRuntimeOverrides | undefined>(undefined);
74
- const browserTimeZone = useMemo(() => detectBrowserTimeZone(), []);
75
-
76
- const contextFilters = useMemo(
77
- () => buildRecordContextFilters(report?.spec.contextBindings, contextRecord),
78
- [contextRecord, report?.spec.contextBindings],
79
- );
80
-
81
- const composeRuntimeOverrides = useCallback(
82
- (localOverrides?: ReportRuntimeOverrides): ReportRuntimeOverrides => {
83
- const localQuery =
84
- localOverrides?.query !== undefined ? localOverrides.query.trim() : (report?.spec.query ?? '').trim();
85
- const globalQuery = (sharedState.query ?? '').trim();
86
- let combinedQuery = localQuery;
87
- if (globalQuery && localQuery) {
88
- combinedQuery = `(${localQuery}) AND (${globalQuery})`;
89
- } else if (globalQuery) {
90
- combinedQuery = globalQuery;
91
- }
92
-
93
- return {
94
- ...localOverrides,
95
- ...(localOverrides?.query !== undefined || globalQuery ? { query: combinedQuery } : {}),
96
- ...(sharedState.timeRange
97
- ? { timeRange: sharedState.timeRange }
98
- : localOverrides?.timeRange
99
- ? { timeRange: localOverrides.timeRange }
100
- : {}),
101
- ...(sharedState.filters.length > 0 ? { sharedFilters: sharedState.filters } : {}),
102
- ...(contextFilters.length > 0 ? { contextFilters } : {}),
103
- ...(browserTimeZone ? { timeZone: browserTimeZone } : {}),
104
- };
105
- },
106
- [
107
- browserTimeZone,
108
- contextFilters,
109
- report?.spec.query,
110
- sharedState.filters,
111
- sharedState.query,
112
- sharedState.timeRange,
113
- ],
114
- );
115
-
116
- const runWithOverrides = useCallback(
117
- async (localOverrides?: ReportRuntimeOverrides) => {
118
- if (reportId === undefined || reportId === null || String(reportId).trim() === '') {
119
- return;
120
- }
121
- latestLocalOverridesRef.current = localOverrides;
122
- const merged = composeRuntimeOverrides(localOverrides);
123
- const seq = ++reqCounter.current;
124
- setLoading(true);
125
- setError(null);
126
- try {
127
- const res = await executeSavedReport(apiRef.current, reportId, merged);
128
- if (seq !== reqCounter.current) return;
129
- setResult(res.result);
130
- } catch (err) {
131
- if (seq !== reqCounter.current) return;
132
- setError(err instanceof Error ? err.message : String(err));
133
- } finally {
134
- if (seq === reqCounter.current) {
135
- setLoading(false);
136
- }
137
- }
138
- },
139
- [composeRuntimeOverrides, reportId],
140
- );
141
-
142
- useEffect(() => {
143
- if (reportId === undefined || reportId === null || String(reportId).trim() === '') {
144
- setReport(null);
145
- setDataView(null);
146
- setFields([]);
147
- setResult(null);
148
- setError(null);
149
- return;
150
- }
151
-
152
- let cancelled = false;
153
- const loadInitial = async () => {
154
- setLoading(true);
155
- setError(null);
156
- try {
157
- const initialOverrides: ReportRuntimeOverrides = {
158
- ...(browserTimeZone ? { timeZone: browserTimeZone } : {}),
159
- };
160
- const [meta, execution] = await Promise.all([
161
- fetchReportMeta(apiRef.current, reportId),
162
- executeSavedReport(apiRef.current, reportId, initialOverrides),
163
- ]);
164
- if (cancelled) return;
165
- const resolvedReport = execution.report ?? meta.report;
166
- setReport(resolvedReport);
167
- setDataView(execution.dataView ?? meta.dataView);
168
- setFields(meta.fields ?? []);
169
- setResult(execution.result);
170
- } catch (err) {
171
- if (!cancelled) {
172
- setError(err instanceof Error ? err.message : String(err));
173
- }
174
- } finally {
175
- if (!cancelled) {
176
- setLoading(false);
177
- }
178
- }
179
- };
180
-
181
- loadInitial();
182
- return () => {
183
- cancelled = true;
184
- };
185
- }, [browserTimeZone, reportId]);
186
-
187
- // Re-run whenever shared dashboard filter bar / cross-filter / record context updates after initial mount
188
- const appliedSharedStampRef = useRef<string>('');
189
- useEffect(() => {
190
- if (!report) return;
191
- const stamp = JSON.stringify({
192
- updatedAt: sharedState.updatedAt,
193
- refreshTick: sharedState.refreshTick,
194
- ctxFilters: contextFilters,
195
- });
196
- if (appliedSharedStampRef.current === '') {
197
- appliedSharedStampRef.current = stamp;
198
- if (sharedState.updatedAt === 0 && contextFilters.length === 0) {
199
- return;
200
- }
201
- } else if (appliedSharedStampRef.current === stamp) {
202
- return;
203
- }
204
- appliedSharedStampRef.current = stamp;
205
- runWithOverrides(latestLocalOverridesRef.current);
206
- }, [contextFilters, report, runWithOverrides, sharedState.refreshTick, sharedState.updatedAt]);
207
-
208
- const handleCrossFilter = useCallback(
209
- (item: ReportFilterItem) => {
210
- if (activeScopeKey) {
211
- upsertDashboardFilter(activeScopeKey, item);
212
- }
213
- },
214
- [activeScopeKey],
215
- );
216
-
217
- const handleInspectTopValues = useCallback(
218
- async (field: string, localOverrides?: ReportRuntimeOverrides): Promise<FieldTopValuesResult> => {
219
- if (reportId === undefined || reportId === null) {
220
- return { field, resolvedField: field, totalDocs: 0, buckets: [] };
221
- }
222
- return fetchFieldTopValues(apiRef.current, {
223
- reportId,
224
- field,
225
- size: 8,
226
- overrides: composeRuntimeOverrides(localOverrides),
227
- });
228
- },
229
- [composeRuntimeOverrides, reportId],
230
- );
231
-
232
- const handleExport = useCallback(
233
- async (format: ExportFormat, columns?: string[], localOverrides?: ReportRuntimeOverrides) => {
234
- if (reportId === undefined || reportId === null) return;
235
- await downloadReportExport(apiRef.current, {
236
- reportId,
237
- reportTitle: report?.title,
238
- format,
239
- columns,
240
- overrides: composeRuntimeOverrides(localOverrides),
241
- });
242
- },
243
- [composeRuntimeOverrides, report?.title, reportId],
244
- );
245
-
246
- if (reportId === undefined || reportId === null || String(reportId).trim() === '') {
247
- return (
248
- <Card
249
- size={compact ? 'small' : 'default'}
250
- style={{ width: '100%', maxWidth: '100%', minWidth: 0, boxSizing: 'border-box', overflow: 'hidden' }}
251
- >
252
- <Empty description={t('Select a saved Elastic Report in block settings to display data')} />
253
- </Card>
254
- );
255
- }
256
-
257
- return (
258
- <Card
259
- size={compact ? 'small' : 'default'}
260
- title={report?.title}
261
- style={{ width: '100%', maxWidth: '100%', minWidth: 0, boxSizing: 'border-box', overflow: 'hidden' }}
262
- styles={{ body: { maxWidth: '100%', minWidth: 0, overflowX: 'hidden' } }}
263
- extra={
264
- <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, paddingInlineEnd: 2 }}>
265
- {sharedState.filters.length > 0 && (
266
- <Tag color="cyan">
267
- {t('Dashboard filter')}: {sharedState.filters.length}
268
- </Tag>
269
- )}
270
- {dataView?.indexPattern && <span style={{ fontSize: 12, opacity: 0.7 }}>{dataView.indexPattern}</span>}
271
- </span>
272
- }
273
- >
274
- {report ? (
275
- <ElasticReportRenderer
276
- title={report.title}
277
- spec={report.spec}
278
- dataView={dataView}
279
- fields={fields}
280
- result={result}
281
- loading={loading}
282
- error={error}
283
- showToolbar={showToolbar}
284
- compact={compact}
285
- onExecute={(overrides) => {
286
- runWithOverrides(overrides);
287
- }}
288
- onCrossFilter={activeScopeKey ? handleCrossFilter : undefined}
289
- onInspectTopValues={handleInspectTopValues}
290
- onExport={report.spec.allowExport !== false ? handleExport : undefined}
291
- />
292
- ) : (
293
- <ElasticReportRenderer
294
- title={t('Elastic Report')}
295
- spec={{ visualization: 'table' }}
296
- result={null}
297
- loading={loading}
298
- error={error}
299
- showToolbar={false}
300
- compact={compact}
301
- onExecute={() => undefined}
302
- />
303
- )}
304
- </Card>
305
- );
306
- };
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 { useApp } from '@nocobase/client-v2';
11
+ import { Card, Empty, Tag } from 'antd';
12
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
13
+ import type {
14
+ EsDataViewRecord,
15
+ EsFieldCapability,
16
+ EsReportRecord,
17
+ ExportFormat,
18
+ FieldTopValuesResult,
19
+ ID,
20
+ ReportExecutionResult,
21
+ ReportFilterItem,
22
+ ReportRuntimeOverrides,
23
+ } from '../../shared/types';
24
+ import {
25
+ downloadReportExport,
26
+ executeSavedReport,
27
+ fetchFieldTopValues,
28
+ fetchReportMeta,
29
+ type ApiClientLike,
30
+ } from '../api';
31
+ import {
32
+ buildRecordContextFilters,
33
+ detectBrowserTimeZone,
34
+ upsertDashboardFilter,
35
+ useDashboardScope,
36
+ } from '../bus/DashboardFilterBus';
37
+ import { useT } from '../locale';
38
+ import { ElasticReportRenderer } from './ElasticReportRenderer';
39
+
40
+ export interface ElasticReportBlockProps {
41
+ reportId?: ID;
42
+ showToolbar?: boolean;
43
+ compact?: boolean;
44
+ scopeKey?: string;
45
+ subscribeDashboardFilters?: boolean;
46
+ contextRecord?: unknown;
47
+ }
48
+
49
+ export const ElasticReportBlock: React.FC<ElasticReportBlockProps> = ({
50
+ reportId,
51
+ showToolbar = true,
52
+ compact = false,
53
+ scopeKey,
54
+ subscribeDashboardFilters = true,
55
+ contextRecord,
56
+ }) => {
57
+ const t = useT();
58
+ const app = useApp();
59
+ const api = app.apiClient as unknown as ApiClientLike;
60
+ const apiRef = useRef<ApiClientLike>(api);
61
+ apiRef.current = api;
62
+
63
+ const activeScopeKey = subscribeDashboardFilters && scopeKey ? scopeKey : null;
64
+ const sharedState = useDashboardScope(activeScopeKey);
65
+
66
+ const [report, setReport] = useState<EsReportRecord | null>(null);
67
+ const [dataView, setDataView] = useState<EsDataViewRecord | null>(null);
68
+ const [fields, setFields] = useState<EsFieldCapability[]>([]);
69
+ const [result, setResult] = useState<ReportExecutionResult | null>(null);
70
+ const [loading, setLoading] = useState(false);
71
+ const [error, setError] = useState<string | null>(null);
72
+ const reqCounter = useRef(0);
73
+ const latestLocalOverridesRef = useRef<ReportRuntimeOverrides | undefined>(undefined);
74
+ const browserTimeZone = useMemo(() => detectBrowserTimeZone(), []);
75
+
76
+ const contextFilters = useMemo(
77
+ () => buildRecordContextFilters(report?.spec.contextBindings, contextRecord),
78
+ [contextRecord, report?.spec.contextBindings],
79
+ );
80
+
81
+ const composeRuntimeOverrides = useCallback(
82
+ (localOverrides?: ReportRuntimeOverrides): ReportRuntimeOverrides => {
83
+ const localQuery =
84
+ localOverrides?.query !== undefined ? localOverrides.query.trim() : (report?.spec.query ?? '').trim();
85
+ const globalQuery = (sharedState.query ?? '').trim();
86
+ let combinedQuery = localQuery;
87
+ if (globalQuery && localQuery) {
88
+ combinedQuery = `(${localQuery}) AND (${globalQuery})`;
89
+ } else if (globalQuery) {
90
+ combinedQuery = globalQuery;
91
+ }
92
+
93
+ return {
94
+ ...localOverrides,
95
+ ...(localOverrides?.query !== undefined || globalQuery ? { query: combinedQuery } : {}),
96
+ ...(sharedState.timeRange
97
+ ? { timeRange: sharedState.timeRange }
98
+ : localOverrides?.timeRange
99
+ ? { timeRange: localOverrides.timeRange }
100
+ : {}),
101
+ ...(sharedState.filters.length > 0 ? { sharedFilters: sharedState.filters } : {}),
102
+ ...(contextFilters.length > 0 ? { contextFilters } : {}),
103
+ ...(browserTimeZone ? { timeZone: browserTimeZone } : {}),
104
+ };
105
+ },
106
+ [
107
+ browserTimeZone,
108
+ contextFilters,
109
+ report?.spec.query,
110
+ sharedState.filters,
111
+ sharedState.query,
112
+ sharedState.timeRange,
113
+ ],
114
+ );
115
+
116
+ const runWithOverrides = useCallback(
117
+ async (localOverrides?: ReportRuntimeOverrides) => {
118
+ if (reportId === undefined || reportId === null || String(reportId).trim() === '') {
119
+ return;
120
+ }
121
+ latestLocalOverridesRef.current = localOverrides;
122
+ const merged = composeRuntimeOverrides(localOverrides);
123
+ const seq = ++reqCounter.current;
124
+ setLoading(true);
125
+ setError(null);
126
+ try {
127
+ const res = await executeSavedReport(apiRef.current, reportId, merged);
128
+ if (seq !== reqCounter.current) return;
129
+ setResult(res.result);
130
+ } catch (err) {
131
+ if (seq !== reqCounter.current) return;
132
+ setError(err instanceof Error ? err.message : String(err));
133
+ } finally {
134
+ if (seq === reqCounter.current) {
135
+ setLoading(false);
136
+ }
137
+ }
138
+ },
139
+ [composeRuntimeOverrides, reportId],
140
+ );
141
+
142
+ useEffect(() => {
143
+ if (reportId === undefined || reportId === null || String(reportId).trim() === '') {
144
+ setReport(null);
145
+ setDataView(null);
146
+ setFields([]);
147
+ setResult(null);
148
+ setError(null);
149
+ return;
150
+ }
151
+
152
+ let cancelled = false;
153
+ const loadInitial = async () => {
154
+ setLoading(true);
155
+ setError(null);
156
+ try {
157
+ const initialOverrides: ReportRuntimeOverrides = {
158
+ ...(browserTimeZone ? { timeZone: browserTimeZone } : {}),
159
+ };
160
+ const [meta, execution] = await Promise.all([
161
+ fetchReportMeta(apiRef.current, reportId),
162
+ executeSavedReport(apiRef.current, reportId, initialOverrides),
163
+ ]);
164
+ if (cancelled) return;
165
+ const resolvedReport = execution.report ?? meta.report;
166
+ setReport(resolvedReport);
167
+ setDataView(execution.dataView ?? meta.dataView);
168
+ setFields(meta.fields ?? []);
169
+ setResult(execution.result);
170
+ } catch (err) {
171
+ if (!cancelled) {
172
+ setError(err instanceof Error ? err.message : String(err));
173
+ }
174
+ } finally {
175
+ if (!cancelled) {
176
+ setLoading(false);
177
+ }
178
+ }
179
+ };
180
+
181
+ loadInitial();
182
+ return () => {
183
+ cancelled = true;
184
+ };
185
+ }, [browserTimeZone, reportId]);
186
+
187
+ // Re-run whenever shared dashboard filter bar / cross-filter / record context updates after initial mount
188
+ const appliedSharedStampRef = useRef<string>('');
189
+ useEffect(() => {
190
+ if (!report) return;
191
+ const stamp = JSON.stringify({
192
+ updatedAt: sharedState.updatedAt,
193
+ refreshTick: sharedState.refreshTick,
194
+ ctxFilters: contextFilters,
195
+ });
196
+ if (appliedSharedStampRef.current === '') {
197
+ appliedSharedStampRef.current = stamp;
198
+ if (sharedState.updatedAt === 0 && contextFilters.length === 0) {
199
+ return;
200
+ }
201
+ } else if (appliedSharedStampRef.current === stamp) {
202
+ return;
203
+ }
204
+ appliedSharedStampRef.current = stamp;
205
+ runWithOverrides(latestLocalOverridesRef.current);
206
+ }, [contextFilters, report, runWithOverrides, sharedState.refreshTick, sharedState.updatedAt]);
207
+
208
+ const handleCrossFilter = useCallback(
209
+ (item: ReportFilterItem) => {
210
+ if (activeScopeKey) {
211
+ upsertDashboardFilter(activeScopeKey, item);
212
+ }
213
+ },
214
+ [activeScopeKey],
215
+ );
216
+
217
+ const handleInspectTopValues = useCallback(
218
+ async (field: string, localOverrides?: ReportRuntimeOverrides): Promise<FieldTopValuesResult> => {
219
+ if (reportId === undefined || reportId === null) {
220
+ return { field, resolvedField: field, totalDocs: 0, buckets: [] };
221
+ }
222
+ return fetchFieldTopValues(apiRef.current, {
223
+ reportId,
224
+ field,
225
+ size: 8,
226
+ overrides: composeRuntimeOverrides(localOverrides),
227
+ });
228
+ },
229
+ [composeRuntimeOverrides, reportId],
230
+ );
231
+
232
+ const handleExport = useCallback(
233
+ async (format: ExportFormat, columns?: string[], localOverrides?: ReportRuntimeOverrides) => {
234
+ if (reportId === undefined || reportId === null) return;
235
+ await downloadReportExport(apiRef.current, {
236
+ reportId,
237
+ reportTitle: report?.title,
238
+ format,
239
+ columns,
240
+ overrides: composeRuntimeOverrides(localOverrides),
241
+ });
242
+ },
243
+ [composeRuntimeOverrides, report?.title, reportId],
244
+ );
245
+
246
+ if (reportId === undefined || reportId === null || String(reportId).trim() === '') {
247
+ return (
248
+ <Card
249
+ size={compact ? 'small' : 'default'}
250
+ style={{ width: '100%', maxWidth: '100%', minWidth: 0, boxSizing: 'border-box', overflow: 'hidden' }}
251
+ >
252
+ <Empty description={t('Select a saved Elastic Report in block settings to display data')} />
253
+ </Card>
254
+ );
255
+ }
256
+
257
+ return (
258
+ <Card
259
+ size={compact ? 'small' : 'default'}
260
+ title={report?.title}
261
+ style={{ width: '100%', maxWidth: '100%', minWidth: 0, boxSizing: 'border-box', overflow: 'hidden' }}
262
+ styles={{ body: { maxWidth: '100%', minWidth: 0, overflowX: 'hidden' } }}
263
+ extra={
264
+ <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, paddingInlineEnd: 2 }}>
265
+ {sharedState.filters.length > 0 && (
266
+ <Tag color="cyan">
267
+ {t('Dashboard filter')}: {sharedState.filters.length}
268
+ </Tag>
269
+ )}
270
+ {dataView?.indexPattern && <span style={{ fontSize: 12, opacity: 0.7 }}>{dataView.indexPattern}</span>}
271
+ </span>
272
+ }
273
+ >
274
+ {report ? (
275
+ <ElasticReportRenderer
276
+ title={report.title}
277
+ spec={report.spec}
278
+ dataView={dataView}
279
+ fields={fields}
280
+ result={result}
281
+ loading={loading}
282
+ error={error}
283
+ showToolbar={showToolbar}
284
+ compact={compact}
285
+ onExecute={(overrides) => {
286
+ runWithOverrides(overrides);
287
+ }}
288
+ onCrossFilter={activeScopeKey ? handleCrossFilter : undefined}
289
+ onInspectTopValues={handleInspectTopValues}
290
+ onExport={report.spec.allowExport !== false ? handleExport : undefined}
291
+ />
292
+ ) : (
293
+ <ElasticReportRenderer
294
+ title={t('Elastic Report')}
295
+ spec={{ visualization: 'table' }}
296
+ result={null}
297
+ loading={loading}
298
+ error={error}
299
+ showToolbar={false}
300
+ compact={compact}
301
+ onExecute={() => undefined}
302
+ />
303
+ )}
304
+ </Card>
305
+ );
306
+ };