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
|
@@ -1,1453 +1,1453 @@
|
|
|
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 {
|
|
11
|
-
CopyOutlined,
|
|
12
|
-
DeleteOutlined,
|
|
13
|
-
EditOutlined,
|
|
14
|
-
EyeOutlined,
|
|
15
|
-
PlayCircleOutlined,
|
|
16
|
-
PlusOutlined,
|
|
17
|
-
ReloadOutlined,
|
|
18
|
-
} from '@ant-design/icons';
|
|
19
|
-
import { useApp } from '@nocobase/client-v2';
|
|
20
|
-
import {
|
|
21
|
-
Alert,
|
|
22
|
-
App,
|
|
23
|
-
Button,
|
|
24
|
-
Card,
|
|
25
|
-
Col,
|
|
26
|
-
Descriptions,
|
|
27
|
-
Divider,
|
|
28
|
-
Drawer,
|
|
29
|
-
Form,
|
|
30
|
-
Input,
|
|
31
|
-
InputNumber,
|
|
32
|
-
Modal,
|
|
33
|
-
Popconfirm,
|
|
34
|
-
Row,
|
|
35
|
-
Select,
|
|
36
|
-
Space,
|
|
37
|
-
Switch,
|
|
38
|
-
Table,
|
|
39
|
-
Tabs,
|
|
40
|
-
Tag,
|
|
41
|
-
Typography,
|
|
42
|
-
} from 'antd';
|
|
43
|
-
import type { TableColumnsType } from 'antd';
|
|
44
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
45
|
-
import type {
|
|
46
|
-
BucketAggType,
|
|
47
|
-
CalendarIntervalOption,
|
|
48
|
-
ChartStackMode,
|
|
49
|
-
EsConnectionHealthResult,
|
|
50
|
-
EsConnectionSummary,
|
|
51
|
-
EsDataViewRecord,
|
|
52
|
-
EsFieldCapability,
|
|
53
|
-
EsReportRecord,
|
|
54
|
-
FieldFormatType,
|
|
55
|
-
FilterOperator,
|
|
56
|
-
ID,
|
|
57
|
-
MetricAggType,
|
|
58
|
-
RecordContextBinding,
|
|
59
|
-
ReportExecutionResult,
|
|
60
|
-
ReportFilterItem,
|
|
61
|
-
ReportRuntimeOverrides,
|
|
62
|
-
ReportSortItem,
|
|
63
|
-
ReportSpec,
|
|
64
|
-
ReportVisualizationType,
|
|
65
|
-
RoleSummary,
|
|
66
|
-
TimeRangePreset,
|
|
67
|
-
} from '../../shared/types';
|
|
68
|
-
import {
|
|
69
|
-
executeReportPreview,
|
|
70
|
-
fetchAllReports,
|
|
71
|
-
fetchAvailableRoles,
|
|
72
|
-
fetchDataViewFields,
|
|
73
|
-
fetchDataViews,
|
|
74
|
-
fetchEsConnections,
|
|
75
|
-
fetchEsIndices,
|
|
76
|
-
fetchFieldTopValues,
|
|
77
|
-
fetchMcpInfo,
|
|
78
|
-
persistReport,
|
|
79
|
-
removeDataView,
|
|
80
|
-
removeReport,
|
|
81
|
-
saveDataView,
|
|
82
|
-
testEsConnection,
|
|
83
|
-
type ApiClientLike,
|
|
84
|
-
type McpInfoPayload,
|
|
85
|
-
} from '../api';
|
|
86
|
-
import { ElasticKqlInput } from '../components/ElasticKqlInput';
|
|
87
|
-
import { ElasticReportRenderer } from '../components/ElasticReportRenderer';
|
|
88
|
-
import { useT } from '../locale';
|
|
89
|
-
|
|
90
|
-
const { Paragraph, Text } = Typography;
|
|
91
|
-
|
|
92
|
-
interface FilterFormRow {
|
|
93
|
-
field: string;
|
|
94
|
-
operator: FilterOperator;
|
|
95
|
-
value?: string;
|
|
96
|
-
valueTo?: string;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
interface ReportEditorFormValues {
|
|
100
|
-
title: string;
|
|
101
|
-
description?: string;
|
|
102
|
-
dataViewId: ID;
|
|
103
|
-
published: boolean;
|
|
104
|
-
allowedRoles?: string[];
|
|
105
|
-
visualization: ReportVisualizationType;
|
|
106
|
-
query?: string;
|
|
107
|
-
timePreset: TimeRangePreset;
|
|
108
|
-
timeFrom?: string;
|
|
109
|
-
timeTo?: string;
|
|
110
|
-
filters?: FilterFormRow[];
|
|
111
|
-
lockedFilters?: FilterFormRow[];
|
|
112
|
-
sort?: Array<{
|
|
113
|
-
field: string;
|
|
114
|
-
order: 'asc' | 'desc';
|
|
115
|
-
}>;
|
|
116
|
-
columns?: string[];
|
|
117
|
-
fieldFormats?: Array<{
|
|
118
|
-
field: string;
|
|
119
|
-
format: FieldFormatType;
|
|
120
|
-
}>;
|
|
121
|
-
contextBindings?: RecordContextBinding[];
|
|
122
|
-
pageSize: number;
|
|
123
|
-
showHistogram: boolean;
|
|
124
|
-
allowInteractiveControls: boolean;
|
|
125
|
-
allowExport: boolean;
|
|
126
|
-
bucketType: BucketAggType;
|
|
127
|
-
bucketField?: string;
|
|
128
|
-
calendarInterval: CalendarIntervalOption;
|
|
129
|
-
topN: number;
|
|
130
|
-
metricType: MetricAggType;
|
|
131
|
-
metricField?: string;
|
|
132
|
-
metricLabel?: string;
|
|
133
|
-
splitSeriesField?: string;
|
|
134
|
-
stackMode?: ChartStackMode;
|
|
135
|
-
comparePreviousPeriod?: boolean;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
interface DataViewFormValues {
|
|
139
|
-
title: string;
|
|
140
|
-
dataSourceKey: string;
|
|
141
|
-
indexPattern: string;
|
|
142
|
-
timeField?: string;
|
|
143
|
-
description?: string;
|
|
144
|
-
allowedRoles?: string[];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const FILTER_OPERATOR_ITEMS: Array<{ label: string; value: FilterOperator }> = [
|
|
148
|
-
{ label: 'is (=)', value: 'eq' },
|
|
149
|
-
{ label: 'is not (!=)', value: 'ne' },
|
|
150
|
-
{ label: 'contains', value: 'contains' },
|
|
151
|
-
{ label: 'in (comma-separated)', value: 'in' },
|
|
152
|
-
{ label: 'not in', value: 'not_in' },
|
|
153
|
-
{ label: '>', value: 'gt' },
|
|
154
|
-
{ label: '>=', value: 'gte' },
|
|
155
|
-
{ label: '<', value: 'lt' },
|
|
156
|
-
{ label: '<=', value: 'lte' },
|
|
157
|
-
{ label: 'between', value: 'between' },
|
|
158
|
-
{ label: 'exists', value: 'exists' },
|
|
159
|
-
{ label: 'does not exist', value: 'not_exists' },
|
|
160
|
-
];
|
|
161
|
-
|
|
162
|
-
function mapFilterRows(rows: FilterFormRow[] | undefined, prefix: string): ReportFilterItem[] {
|
|
163
|
-
return (rows ?? [])
|
|
164
|
-
.filter((f) => Boolean(f?.field))
|
|
165
|
-
.map((f, idx) => ({
|
|
166
|
-
id: `${prefix}-${idx}`,
|
|
167
|
-
field: f.field,
|
|
168
|
-
operator: f.operator || 'eq',
|
|
169
|
-
...(f.value !== undefined && f.value !== '' ? { value: f.value } : {}),
|
|
170
|
-
...(f.valueTo !== undefined && f.valueTo !== '' ? { valueTo: f.valueTo } : {}),
|
|
171
|
-
enabled: true,
|
|
172
|
-
}));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function formValuesToSpec(values: ReportEditorFormValues): ReportSpec {
|
|
176
|
-
const filters = mapFilterRows(values.filters, 'flt');
|
|
177
|
-
const lockedFilters = mapFilterRows(values.lockedFilters, 'locked');
|
|
178
|
-
|
|
179
|
-
const sort: ReportSortItem[] = (values.sort ?? [])
|
|
180
|
-
.filter((s) => Boolean(s?.field))
|
|
181
|
-
.map((s) => ({
|
|
182
|
-
field: s.field,
|
|
183
|
-
order: s.order === 'asc' ? 'asc' : 'desc',
|
|
184
|
-
}));
|
|
185
|
-
|
|
186
|
-
const preset = values.timePreset || 'last_24h';
|
|
187
|
-
const timeRange =
|
|
188
|
-
preset === 'custom'
|
|
189
|
-
? {
|
|
190
|
-
preset: 'custom' as const,
|
|
191
|
-
...(values.timeFrom?.trim() ? { from: values.timeFrom.trim() } : {}),
|
|
192
|
-
...(values.timeTo?.trim() ? { to: values.timeTo.trim() } : {}),
|
|
193
|
-
}
|
|
194
|
-
: { preset };
|
|
195
|
-
|
|
196
|
-
const fieldFormatsMap: Record<string, FieldFormatType> = {};
|
|
197
|
-
for (const row of values.fieldFormats ?? []) {
|
|
198
|
-
if (row?.field && row.format && row.format !== 'auto') {
|
|
199
|
-
fieldFormatsMap[row.field] = row.format;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const contextBindings = (values.contextBindings ?? []).filter(
|
|
203
|
-
(b) => Boolean(b?.esField?.trim()) && Boolean(b?.recordFieldPath?.trim()),
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
return {
|
|
207
|
-
visualization: values.visualization || 'table',
|
|
208
|
-
query: values.query?.trim() ?? '',
|
|
209
|
-
queryMode: 'kql',
|
|
210
|
-
filters,
|
|
211
|
-
lockedFilters,
|
|
212
|
-
sort,
|
|
213
|
-
timeRange,
|
|
214
|
-
columns: values.columns ?? [],
|
|
215
|
-
...(Object.keys(fieldFormatsMap).length > 0 ? { fieldFormats: fieldFormatsMap } : {}),
|
|
216
|
-
...(contextBindings.length > 0 ? { contextBindings } : {}),
|
|
217
|
-
pageSize: values.pageSize || 20,
|
|
218
|
-
allowInteractiveControls: values.allowInteractiveControls !== false,
|
|
219
|
-
allowExport: values.allowExport !== false,
|
|
220
|
-
chart: {
|
|
221
|
-
bucketType: values.bucketType || 'date_histogram',
|
|
222
|
-
...(values.bucketField ? { bucketField: values.bucketField } : {}),
|
|
223
|
-
calendarInterval: values.calendarInterval || 'auto',
|
|
224
|
-
topN: values.topN || 10,
|
|
225
|
-
metricType: values.metricType || 'count',
|
|
226
|
-
...(values.metricField ? { metricField: values.metricField } : {}),
|
|
227
|
-
...(values.metricLabel ? { metricLabel: values.metricLabel } : {}),
|
|
228
|
-
showHistogram: values.showHistogram !== false,
|
|
229
|
-
...(values.splitSeriesField ? { splitSeriesField: values.splitSeriesField } : {}),
|
|
230
|
-
...(values.stackMode && values.stackMode !== 'none' ? { stackMode: values.stackMode } : {}),
|
|
231
|
-
...(values.comparePreviousPeriod === true ? { comparePreviousPeriod: true } : {}),
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export const ElasticReportManager: React.FC = () => {
|
|
237
|
-
const t = useT();
|
|
238
|
-
const app = useApp();
|
|
239
|
-
const api = app.apiClient as unknown as ApiClientLike;
|
|
240
|
-
const { message } = App.useApp();
|
|
241
|
-
|
|
242
|
-
const [connections, setConnections] = useState<EsConnectionSummary[]>([]);
|
|
243
|
-
const [roles, setRoles] = useState<RoleSummary[]>([]);
|
|
244
|
-
const [dataViews, setDataViews] = useState<EsDataViewRecord[]>([]);
|
|
245
|
-
const [reports, setReports] = useState<EsReportRecord[]>([]);
|
|
246
|
-
const [mcpInfo, setMcpInfo] = useState<McpInfoPayload | null>(null);
|
|
247
|
-
const [loadingList, setLoadingList] = useState(false);
|
|
248
|
-
|
|
249
|
-
// Data View modal state
|
|
250
|
-
const [dvModalOpen, setDvModalOpen] = useState(false);
|
|
251
|
-
const [editingDataView, setEditingDataView] = useState<EsDataViewRecord | null>(null);
|
|
252
|
-
const [dvSaving, setDvSaving] = useState(false);
|
|
253
|
-
const [matchedIndices, setMatchedIndices] = useState<string[]>([]);
|
|
254
|
-
const [loadingIndices, setLoadingIndices] = useState(false);
|
|
255
|
-
const [testingConn, setTestingConn] = useState(false);
|
|
256
|
-
const [connHealth, setConnHealth] = useState<EsConnectionHealthResult | null>(null);
|
|
257
|
-
const [dvForm] = Form.useForm<DataViewFormValues>();
|
|
258
|
-
|
|
259
|
-
// Report Studio drawer state
|
|
260
|
-
const [studioOpen, setStudioOpen] = useState(false);
|
|
261
|
-
const [editingReport, setEditingReport] = useState<EsReportRecord | null>(null);
|
|
262
|
-
const [studioFields, setStudioFields] = useState<EsFieldCapability[]>([]);
|
|
263
|
-
const [studioPreviewSpec, setStudioPreviewSpec] = useState<ReportSpec>({ visualization: 'table' });
|
|
264
|
-
const [previewResult, setPreviewResult] = useState<ReportExecutionResult | null>(null);
|
|
265
|
-
const [previewLoading, setPreviewLoading] = useState(false);
|
|
266
|
-
const [previewError, setPreviewError] = useState<string | null>(null);
|
|
267
|
-
const [savingReport, setSavingReport] = useState(false);
|
|
268
|
-
const [reportForm] = Form.useForm<ReportEditorFormValues>();
|
|
269
|
-
|
|
270
|
-
const watchedVisualization = Form.useWatch('visualization', reportForm) ?? 'table';
|
|
271
|
-
const watchedDataViewId = Form.useWatch('dataViewId', reportForm);
|
|
272
|
-
const watchedTimePreset = Form.useWatch('timePreset', reportForm) ?? 'last_24h';
|
|
273
|
-
const watchedBucketType = Form.useWatch('bucketType', reportForm) ?? 'date_histogram';
|
|
274
|
-
const watchedMetricType = Form.useWatch('metricType', reportForm) ?? 'count';
|
|
275
|
-
|
|
276
|
-
const roleOptions = useMemo(
|
|
277
|
-
() =>
|
|
278
|
-
roles.map((r) => ({
|
|
279
|
-
label: r.title && r.title !== r.name ? `${r.title} (${r.name})` : r.name,
|
|
280
|
-
value: r.name,
|
|
281
|
-
})),
|
|
282
|
-
[roles],
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
const loadAll = useCallback(async () => {
|
|
286
|
-
setLoadingList(true);
|
|
287
|
-
try {
|
|
288
|
-
const [connList, roleList, dvList, reportList, mcpData] = await Promise.all([
|
|
289
|
-
fetchEsConnections(api).catch(() => []),
|
|
290
|
-
fetchAvailableRoles(api).catch(() => []),
|
|
291
|
-
fetchDataViews(api).catch(() => []),
|
|
292
|
-
fetchAllReports(api).catch(() => []),
|
|
293
|
-
fetchMcpInfo(api).catch(() => null),
|
|
294
|
-
]);
|
|
295
|
-
setConnections(connList);
|
|
296
|
-
setRoles(roleList);
|
|
297
|
-
setDataViews(dvList);
|
|
298
|
-
setReports(reportList);
|
|
299
|
-
setMcpInfo(mcpData);
|
|
300
|
-
} finally {
|
|
301
|
-
setLoadingList(false);
|
|
302
|
-
}
|
|
303
|
-
}, [api]);
|
|
304
|
-
|
|
305
|
-
useEffect(() => {
|
|
306
|
-
loadAll();
|
|
307
|
-
}, [loadAll]);
|
|
308
|
-
|
|
309
|
-
useEffect(() => {
|
|
310
|
-
if (!studioOpen || watchedDataViewId === undefined || watchedDataViewId === null) {
|
|
311
|
-
setStudioFields([]);
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
let cancelled = false;
|
|
315
|
-
fetchDataViewFields(api, watchedDataViewId, false)
|
|
316
|
-
.then((res) => {
|
|
317
|
-
if (!cancelled) setStudioFields(res.fields ?? []);
|
|
318
|
-
})
|
|
319
|
-
.catch(() => {
|
|
320
|
-
if (!cancelled) setStudioFields([]);
|
|
321
|
-
});
|
|
322
|
-
return () => {
|
|
323
|
-
cancelled = true;
|
|
324
|
-
};
|
|
325
|
-
}, [api, studioOpen, watchedDataViewId]);
|
|
326
|
-
|
|
327
|
-
const selectedDataView = useMemo(
|
|
328
|
-
() => dataViews.find((dv) => String(dv.id) === String(watchedDataViewId)) ?? null,
|
|
329
|
-
[dataViews, watchedDataViewId],
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
const aggregatableStudioFields = useMemo(
|
|
333
|
-
() => studioFields.filter((f) => f.aggregatable || Boolean(f.keywordSubfield)),
|
|
334
|
-
[studioFields],
|
|
335
|
-
);
|
|
336
|
-
|
|
337
|
-
const numericStudioFields = useMemo(
|
|
338
|
-
() =>
|
|
339
|
-
studioFields.filter((f) =>
|
|
340
|
-
['long', 'integer', 'short', 'byte', 'double', 'float', 'half_float', 'scaled_float'].includes(f.type),
|
|
341
|
-
),
|
|
342
|
-
[studioFields],
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
const openNewDataViewModal = () => {
|
|
346
|
-
setEditingDataView(null);
|
|
347
|
-
setMatchedIndices([]);
|
|
348
|
-
setConnHealth(null);
|
|
349
|
-
dvForm.resetFields();
|
|
350
|
-
dvForm.setFieldsValue({
|
|
351
|
-
dataSourceKey: connections[0]?.key,
|
|
352
|
-
indexPattern: '*',
|
|
353
|
-
timeField: '@timestamp',
|
|
354
|
-
allowedRoles: [],
|
|
355
|
-
});
|
|
356
|
-
setDvModalOpen(true);
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
const openEditDataViewModal = (record: EsDataViewRecord) => {
|
|
360
|
-
setEditingDataView(record);
|
|
361
|
-
setMatchedIndices([]);
|
|
362
|
-
setConnHealth(null);
|
|
363
|
-
dvForm.setFieldsValue({
|
|
364
|
-
title: record.title,
|
|
365
|
-
dataSourceKey: record.dataSourceKey,
|
|
366
|
-
indexPattern: record.indexPattern,
|
|
367
|
-
timeField: record.timeField ?? '',
|
|
368
|
-
description: record.description ?? '',
|
|
369
|
-
allowedRoles: record.allowedRoles ?? [],
|
|
370
|
-
});
|
|
371
|
-
setDvModalOpen(true);
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
const handleBrowseIndices = async () => {
|
|
375
|
-
const dsKey = dvForm.getFieldValue('dataSourceKey');
|
|
376
|
-
const pattern = dvForm.getFieldValue('indexPattern') || '*';
|
|
377
|
-
if (!dsKey) return;
|
|
378
|
-
setLoadingIndices(true);
|
|
379
|
-
try {
|
|
380
|
-
const list = await fetchEsIndices(api, dsKey, pattern);
|
|
381
|
-
setMatchedIndices(list);
|
|
382
|
-
} catch (err) {
|
|
383
|
-
message.error(err instanceof Error ? err.message : String(err));
|
|
384
|
-
} finally {
|
|
385
|
-
setLoadingIndices(false);
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
const handleTestDvConnection = async () => {
|
|
390
|
-
const dsKey = dvForm.getFieldValue('dataSourceKey');
|
|
391
|
-
const pattern = dvForm.getFieldValue('indexPattern') || '*';
|
|
392
|
-
if (!dsKey) return;
|
|
393
|
-
setTestingConn(true);
|
|
394
|
-
setConnHealth(null);
|
|
395
|
-
try {
|
|
396
|
-
const res = await testEsConnection(api, dsKey, pattern);
|
|
397
|
-
setConnHealth(res);
|
|
398
|
-
message.success(t('Connection verified'));
|
|
399
|
-
} catch (err) {
|
|
400
|
-
message.error(err instanceof Error ? err.message : String(err));
|
|
401
|
-
} finally {
|
|
402
|
-
setTestingConn(false);
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
const handleSaveDataView = async () => {
|
|
407
|
-
try {
|
|
408
|
-
const values = await dvForm.validateFields();
|
|
409
|
-
setDvSaving(true);
|
|
410
|
-
await saveDataView(api, {
|
|
411
|
-
...(editingDataView ? { id: editingDataView.id } : {}),
|
|
412
|
-
title: values.title,
|
|
413
|
-
dataSourceKey: values.dataSourceKey,
|
|
414
|
-
indexPattern: values.indexPattern,
|
|
415
|
-
timeField: values.timeField || null,
|
|
416
|
-
description: values.description || null,
|
|
417
|
-
allowedRoles: values.allowedRoles ?? [],
|
|
418
|
-
});
|
|
419
|
-
message.success(t('Saved successfully'));
|
|
420
|
-
setDvModalOpen(false);
|
|
421
|
-
await loadAll();
|
|
422
|
-
} catch (err) {
|
|
423
|
-
if (err instanceof Error && 'message' in err) {
|
|
424
|
-
message.error(err.message);
|
|
425
|
-
}
|
|
426
|
-
} finally {
|
|
427
|
-
setDvSaving(false);
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
const openNewReportStudio = () => {
|
|
432
|
-
setEditingReport(null);
|
|
433
|
-
setPreviewResult(null);
|
|
434
|
-
setPreviewError(null);
|
|
435
|
-
reportForm.resetFields();
|
|
436
|
-
reportForm.setFieldsValue({
|
|
437
|
-
title: '',
|
|
438
|
-
dataViewId: dataViews[0]?.id,
|
|
439
|
-
published: true,
|
|
440
|
-
allowedRoles: [],
|
|
441
|
-
visualization: 'table',
|
|
442
|
-
query: '',
|
|
443
|
-
timePreset: 'last_24h',
|
|
444
|
-
timeFrom: '',
|
|
445
|
-
timeTo: '',
|
|
446
|
-
filters: [],
|
|
447
|
-
lockedFilters: [],
|
|
448
|
-
sort: [],
|
|
449
|
-
columns: [],
|
|
450
|
-
fieldFormats: [],
|
|
451
|
-
contextBindings: [],
|
|
452
|
-
pageSize: 20,
|
|
453
|
-
showHistogram: true,
|
|
454
|
-
allowInteractiveControls: true,
|
|
455
|
-
allowExport: true,
|
|
456
|
-
bucketType: 'date_histogram',
|
|
457
|
-
calendarInterval: 'auto',
|
|
458
|
-
topN: 10,
|
|
459
|
-
metricType: 'count',
|
|
460
|
-
stackMode: 'none',
|
|
461
|
-
comparePreviousPeriod: false,
|
|
462
|
-
});
|
|
463
|
-
setStudioPreviewSpec({
|
|
464
|
-
visualization: 'table',
|
|
465
|
-
query: '',
|
|
466
|
-
queryMode: 'kql',
|
|
467
|
-
filters: [],
|
|
468
|
-
lockedFilters: [],
|
|
469
|
-
sort: [],
|
|
470
|
-
timeRange: { preset: 'last_24h' },
|
|
471
|
-
columns: [],
|
|
472
|
-
pageSize: 20,
|
|
473
|
-
allowInteractiveControls: true,
|
|
474
|
-
allowExport: true,
|
|
475
|
-
chart: {
|
|
476
|
-
bucketType: 'date_histogram',
|
|
477
|
-
calendarInterval: 'auto',
|
|
478
|
-
topN: 10,
|
|
479
|
-
metricType: 'count',
|
|
480
|
-
showHistogram: true,
|
|
481
|
-
},
|
|
482
|
-
});
|
|
483
|
-
setStudioOpen(true);
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
const openEditReportStudio = (record: EsReportRecord) => {
|
|
487
|
-
setEditingReport(record);
|
|
488
|
-
setPreviewResult(null);
|
|
489
|
-
setPreviewError(null);
|
|
490
|
-
const spec = record.spec;
|
|
491
|
-
setStudioPreviewSpec(spec);
|
|
492
|
-
reportForm.setFieldsValue({
|
|
493
|
-
title: record.title,
|
|
494
|
-
description: record.description ?? '',
|
|
495
|
-
dataViewId: record.dataViewId,
|
|
496
|
-
published: record.published !== false,
|
|
497
|
-
allowedRoles: record.allowedRoles ?? [],
|
|
498
|
-
visualization: spec.visualization ?? 'table',
|
|
499
|
-
query: spec.query ?? '',
|
|
500
|
-
timePreset: spec.timeRange?.preset ?? 'last_24h',
|
|
501
|
-
timeFrom: spec.timeRange?.from ?? '',
|
|
502
|
-
timeTo: spec.timeRange?.to ?? '',
|
|
503
|
-
filters: (spec.filters ?? []).map((f) => ({
|
|
504
|
-
field: f.field,
|
|
505
|
-
operator: f.operator,
|
|
506
|
-
value: Array.isArray(f.value) ? f.value.join(', ') : f.value !== undefined ? String(f.value) : '',
|
|
507
|
-
valueTo: f.valueTo !== undefined ? String(f.valueTo) : '',
|
|
508
|
-
})),
|
|
509
|
-
lockedFilters: (spec.lockedFilters ?? []).map((f) => ({
|
|
510
|
-
field: f.field,
|
|
511
|
-
operator: f.operator,
|
|
512
|
-
value: Array.isArray(f.value) ? f.value.join(', ') : f.value !== undefined ? String(f.value) : '',
|
|
513
|
-
valueTo: f.valueTo !== undefined ? String(f.valueTo) : '',
|
|
514
|
-
})),
|
|
515
|
-
sort: spec.sort ?? [],
|
|
516
|
-
columns: spec.columns ?? [],
|
|
517
|
-
fieldFormats: Object.entries(spec.fieldFormats ?? {}).map(([field, format]) => ({ field, format })),
|
|
518
|
-
contextBindings: spec.contextBindings ?? [],
|
|
519
|
-
pageSize: spec.pageSize ?? 20,
|
|
520
|
-
showHistogram: spec.chart?.showHistogram !== false,
|
|
521
|
-
allowInteractiveControls: spec.allowInteractiveControls !== false,
|
|
522
|
-
allowExport: spec.allowExport !== false,
|
|
523
|
-
bucketType: spec.chart?.bucketType ?? 'date_histogram',
|
|
524
|
-
bucketField: spec.chart?.bucketField,
|
|
525
|
-
calendarInterval: spec.chart?.calendarInterval ?? 'auto',
|
|
526
|
-
topN: spec.chart?.topN ?? 10,
|
|
527
|
-
metricType: spec.chart?.metricType ?? 'count',
|
|
528
|
-
metricField: spec.chart?.metricField,
|
|
529
|
-
metricLabel: spec.chart?.metricLabel,
|
|
530
|
-
splitSeriesField: spec.chart?.splitSeriesField,
|
|
531
|
-
stackMode: spec.chart?.stackMode ?? 'none',
|
|
532
|
-
comparePreviousPeriod: spec.chart?.comparePreviousPeriod === true,
|
|
533
|
-
});
|
|
534
|
-
setStudioOpen(true);
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
const handleRunStudioPreview = async (overrides?: ReportRuntimeOverrides) => {
|
|
538
|
-
const values = reportForm.getFieldsValue(true) as ReportEditorFormValues;
|
|
539
|
-
if (values.dataViewId === undefined || values.dataViewId === null) {
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
setPreviewLoading(true);
|
|
543
|
-
setPreviewError(null);
|
|
544
|
-
try {
|
|
545
|
-
const spec = formValuesToSpec(values);
|
|
546
|
-
if (!overrides) {
|
|
547
|
-
setStudioPreviewSpec(spec);
|
|
548
|
-
}
|
|
549
|
-
const res = await executeReportPreview(api, values.dataViewId, spec, overrides);
|
|
550
|
-
setPreviewResult(res.result);
|
|
551
|
-
} catch (err) {
|
|
552
|
-
setPreviewError(err instanceof Error ? err.message : String(err));
|
|
553
|
-
} finally {
|
|
554
|
-
setPreviewLoading(false);
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
const handleSaveReport = async () => {
|
|
559
|
-
try {
|
|
560
|
-
const values = await reportForm.validateFields();
|
|
561
|
-
setSavingReport(true);
|
|
562
|
-
const spec = formValuesToSpec(values);
|
|
563
|
-
await persistReport(api, {
|
|
564
|
-
...(editingReport ? { id: editingReport.id } : {}),
|
|
565
|
-
title: values.title,
|
|
566
|
-
description: values.description || null,
|
|
567
|
-
dataViewId: values.dataViewId,
|
|
568
|
-
published: values.published !== false,
|
|
569
|
-
allowedRoles: values.allowedRoles ?? [],
|
|
570
|
-
spec,
|
|
571
|
-
});
|
|
572
|
-
message.success(t('Saved successfully'));
|
|
573
|
-
setStudioOpen(false);
|
|
574
|
-
await loadAll();
|
|
575
|
-
} catch (err) {
|
|
576
|
-
if (err instanceof Error && 'message' in err) {
|
|
577
|
-
message.error(err.message);
|
|
578
|
-
}
|
|
579
|
-
} finally {
|
|
580
|
-
setSavingReport(false);
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
|
|
584
|
-
const reportColumns: TableColumnsType<EsReportRecord> = [
|
|
585
|
-
{
|
|
586
|
-
title: t('Title'),
|
|
587
|
-
dataIndex: 'title',
|
|
588
|
-
key: 'title',
|
|
589
|
-
render: (val: string, row) => (
|
|
590
|
-
<Space direction="vertical" size={0}>
|
|
591
|
-
<Text strong>{val}</Text>
|
|
592
|
-
{row.description && (
|
|
593
|
-
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
594
|
-
{row.description}
|
|
595
|
-
</Text>
|
|
596
|
-
)}
|
|
597
|
-
</Space>
|
|
598
|
-
),
|
|
599
|
-
},
|
|
600
|
-
{
|
|
601
|
-
title: t('Visualization'),
|
|
602
|
-
dataIndex: 'visualization',
|
|
603
|
-
key: 'visualization',
|
|
604
|
-
width: 140,
|
|
605
|
-
render: (val: string) => <Tag color="blue">{String(val).toUpperCase()}</Tag>,
|
|
606
|
-
},
|
|
607
|
-
{
|
|
608
|
-
title: t('Data View'),
|
|
609
|
-
key: 'dataView',
|
|
610
|
-
render: (_: unknown, row) =>
|
|
611
|
-
row.dataView ? `${row.dataView.title} (${row.dataView.indexPattern})` : String(row.dataViewId),
|
|
612
|
-
},
|
|
613
|
-
{
|
|
614
|
-
title: t('Allowed Roles'),
|
|
615
|
-
key: 'allowedRoles',
|
|
616
|
-
width: 180,
|
|
617
|
-
render: (_: unknown, row) =>
|
|
618
|
-
row.allowedRoles && row.allowedRoles.length > 0 ? (
|
|
619
|
-
<Space wrap size={[4, 4]}>
|
|
620
|
-
{row.allowedRoles.map((r) => (
|
|
621
|
-
<Tag key={r}>{r}</Tag>
|
|
622
|
-
))}
|
|
623
|
-
</Space>
|
|
624
|
-
) : (
|
|
625
|
-
<Text type="secondary">{t('All roles')}</Text>
|
|
626
|
-
),
|
|
627
|
-
},
|
|
628
|
-
{
|
|
629
|
-
title: t('Published'),
|
|
630
|
-
dataIndex: 'published',
|
|
631
|
-
key: 'published',
|
|
632
|
-
width: 120,
|
|
633
|
-
render: (pub: boolean) => <Tag color={pub ? 'success' : 'default'}>{pub ? t('Published') : t('Draft')}</Tag>,
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
title: '',
|
|
637
|
-
key: 'actions',
|
|
638
|
-
width: 180,
|
|
639
|
-
render: (_: unknown, row) => (
|
|
640
|
-
<Space>
|
|
641
|
-
<Button size="small" icon={<EditOutlined />} onClick={() => openEditReportStudio(row)}>
|
|
642
|
-
{t('Edit')}
|
|
643
|
-
</Button>
|
|
644
|
-
<Popconfirm
|
|
645
|
-
title={t('Confirm delete?')}
|
|
646
|
-
onConfirm={async () => {
|
|
647
|
-
await removeReport(api, row.id);
|
|
648
|
-
message.success(t('Deleted successfully'));
|
|
649
|
-
await loadAll();
|
|
650
|
-
}}
|
|
651
|
-
>
|
|
652
|
-
<Button size="small" danger icon={<DeleteOutlined />}>
|
|
653
|
-
{t('Delete')}
|
|
654
|
-
</Button>
|
|
655
|
-
</Popconfirm>
|
|
656
|
-
</Space>
|
|
657
|
-
),
|
|
658
|
-
},
|
|
659
|
-
];
|
|
660
|
-
|
|
661
|
-
const dataViewColumns: TableColumnsType<EsDataViewRecord> = [
|
|
662
|
-
{ title: t('Title'), dataIndex: 'title', key: 'title' },
|
|
663
|
-
{ title: t('Data Source (Elasticsearch)'), dataIndex: 'dataSourceKey', key: 'dataSourceKey' },
|
|
664
|
-
{
|
|
665
|
-
title: t('Index Pattern'),
|
|
666
|
-
dataIndex: 'indexPattern',
|
|
667
|
-
key: 'indexPattern',
|
|
668
|
-
render: (val: string) => <Tag>{val}</Tag>,
|
|
669
|
-
},
|
|
670
|
-
{ title: t('Time Field'), dataIndex: 'timeField', key: 'timeField', render: (v?: string | null) => v || '—' },
|
|
671
|
-
{
|
|
672
|
-
title: t('Allowed Roles'),
|
|
673
|
-
key: 'allowedRoles',
|
|
674
|
-
width: 180,
|
|
675
|
-
render: (_: unknown, row) =>
|
|
676
|
-
row.allowedRoles && row.allowedRoles.length > 0 ? (
|
|
677
|
-
<Space wrap size={[4, 4]}>
|
|
678
|
-
{row.allowedRoles.map((r) => (
|
|
679
|
-
<Tag key={r}>{r}</Tag>
|
|
680
|
-
))}
|
|
681
|
-
</Space>
|
|
682
|
-
) : (
|
|
683
|
-
<Text type="secondary">{t('All roles')}</Text>
|
|
684
|
-
),
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
title: t('Fields'),
|
|
688
|
-
key: 'fieldCount',
|
|
689
|
-
width: 110,
|
|
690
|
-
render: (_: unknown, row) => row.cachedFields?.length ?? 0,
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
title: '',
|
|
694
|
-
key: 'actions',
|
|
695
|
-
width: 260,
|
|
696
|
-
render: (_: unknown, row) => (
|
|
697
|
-
<Space>
|
|
698
|
-
<Button
|
|
699
|
-
size="small"
|
|
700
|
-
icon={<ReloadOutlined />}
|
|
701
|
-
onClick={async () => {
|
|
702
|
-
await fetchDataViewFields(api, row.id, true);
|
|
703
|
-
message.success(t('Saved successfully'));
|
|
704
|
-
await loadAll();
|
|
705
|
-
}}
|
|
706
|
-
>
|
|
707
|
-
{t('Refresh Fields')}
|
|
708
|
-
</Button>
|
|
709
|
-
<Button size="small" icon={<EditOutlined />} onClick={() => openEditDataViewModal(row)}>
|
|
710
|
-
{t('Edit')}
|
|
711
|
-
</Button>
|
|
712
|
-
<Popconfirm
|
|
713
|
-
title={t('Confirm delete?')}
|
|
714
|
-
onConfirm={async () => {
|
|
715
|
-
await removeDataView(api, row.id);
|
|
716
|
-
message.success(t('Deleted successfully'));
|
|
717
|
-
await loadAll();
|
|
718
|
-
}}
|
|
719
|
-
>
|
|
720
|
-
<Button size="small" danger icon={<DeleteOutlined />} aria-label={t('Delete')} />
|
|
721
|
-
</Popconfirm>
|
|
722
|
-
</Space>
|
|
723
|
-
),
|
|
724
|
-
},
|
|
725
|
-
];
|
|
726
|
-
|
|
727
|
-
return (
|
|
728
|
-
<Card variant="borderless">
|
|
729
|
-
<Tabs
|
|
730
|
-
items={[
|
|
731
|
-
{
|
|
732
|
-
key: 'reports',
|
|
733
|
-
label: t('Reports'),
|
|
734
|
-
children: (
|
|
735
|
-
<div>
|
|
736
|
-
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
|
|
737
|
-
<Space>
|
|
738
|
-
<Button type="primary" icon={<PlusOutlined />} onClick={openNewReportStudio}>
|
|
739
|
-
{t('New Report')}
|
|
740
|
-
</Button>
|
|
741
|
-
<Button icon={<ReloadOutlined />} onClick={loadAll}>
|
|
742
|
-
{t('Refresh')}
|
|
743
|
-
</Button>
|
|
744
|
-
</Space>
|
|
745
|
-
</div>
|
|
746
|
-
<Table<EsReportRecord>
|
|
747
|
-
rowKey="id"
|
|
748
|
-
scroll={{ x: 'max-content' }}
|
|
749
|
-
loading={loadingList}
|
|
750
|
-
columns={reportColumns}
|
|
751
|
-
dataSource={reports}
|
|
752
|
-
/>
|
|
753
|
-
</div>
|
|
754
|
-
),
|
|
755
|
-
},
|
|
756
|
-
{
|
|
757
|
-
key: 'dataViews',
|
|
758
|
-
label: t('Data Views'),
|
|
759
|
-
children: (
|
|
760
|
-
<div>
|
|
761
|
-
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
|
|
762
|
-
<Space>
|
|
763
|
-
<Button type="primary" icon={<PlusOutlined />} onClick={openNewDataViewModal}>
|
|
764
|
-
{t('New Data View')}
|
|
765
|
-
</Button>
|
|
766
|
-
<Button icon={<ReloadOutlined />} onClick={loadAll}>
|
|
767
|
-
{t('Refresh')}
|
|
768
|
-
</Button>
|
|
769
|
-
</Space>
|
|
770
|
-
</div>
|
|
771
|
-
<Table<EsDataViewRecord>
|
|
772
|
-
rowKey="id"
|
|
773
|
-
scroll={{ x: 'max-content' }}
|
|
774
|
-
loading={loadingList}
|
|
775
|
-
columns={dataViewColumns}
|
|
776
|
-
dataSource={dataViews}
|
|
777
|
-
/>
|
|
778
|
-
</div>
|
|
779
|
-
),
|
|
780
|
-
},
|
|
781
|
-
{
|
|
782
|
-
key: 'mcp',
|
|
783
|
-
label: t('MCP & AI Employee'),
|
|
784
|
-
children: (
|
|
785
|
-
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
786
|
-
<Alert
|
|
787
|
-
type="info"
|
|
788
|
-
showIcon
|
|
789
|
-
message={t('AI Employee Usage')}
|
|
790
|
-
description={t(
|
|
791
|
-
'This plugin automatically registers the elastic-report MCP server (with user context) and AI Employee tools so AI agents can inspect fields, preview Elasticsearch queries, and publish Saved Reports ready to select in blocks.',
|
|
792
|
-
)}
|
|
793
|
-
/>
|
|
794
|
-
{mcpInfo && (
|
|
795
|
-
<Descriptions bordered column={1} size="small">
|
|
796
|
-
<Descriptions.Item label={t('MCP Server Name')}>
|
|
797
|
-
<Tag color="purple">{mcpInfo.serverName}</Tag>
|
|
798
|
-
</Descriptions.Item>
|
|
799
|
-
<Descriptions.Item label={t('Dedicated MCP Endpoint')}>
|
|
800
|
-
<Space>
|
|
801
|
-
<code>{mcpInfo.endpointPath}</code>
|
|
802
|
-
<Button
|
|
803
|
-
size="small"
|
|
804
|
-
icon={<CopyOutlined />}
|
|
805
|
-
onClick={() => {
|
|
806
|
-
navigator.clipboard?.writeText(window.location.origin + mcpInfo.endpointPath);
|
|
807
|
-
message.success(t('Copied to clipboard'));
|
|
808
|
-
}}
|
|
809
|
-
>
|
|
810
|
-
{t('Copy')}
|
|
811
|
-
</Button>
|
|
812
|
-
</Space>
|
|
813
|
-
</Descriptions.Item>
|
|
814
|
-
</Descriptions>
|
|
815
|
-
)}
|
|
816
|
-
<Card size="small" title={t('Exposed MCP Tools')}>
|
|
817
|
-
<Table
|
|
818
|
-
size="small"
|
|
819
|
-
rowKey="name"
|
|
820
|
-
pagination={false}
|
|
821
|
-
dataSource={mcpInfo?.tools ?? []}
|
|
822
|
-
columns={[
|
|
823
|
-
{
|
|
824
|
-
title: 'Tool',
|
|
825
|
-
dataIndex: 'name',
|
|
826
|
-
key: 'name',
|
|
827
|
-
width: 220,
|
|
828
|
-
render: (v: string) => <code>{v}</code>,
|
|
829
|
-
},
|
|
830
|
-
{ title: t('Description'), dataIndex: 'description', key: 'description' },
|
|
831
|
-
]}
|
|
832
|
-
/>
|
|
833
|
-
</Card>
|
|
834
|
-
</Space>
|
|
835
|
-
),
|
|
836
|
-
},
|
|
837
|
-
]}
|
|
838
|
-
/>
|
|
839
|
-
|
|
840
|
-
{/* Data View Modal */}
|
|
841
|
-
<Modal
|
|
842
|
-
title={editingDataView ? t('Edit Data View') : t('New Data View')}
|
|
843
|
-
open={dvModalOpen}
|
|
844
|
-
confirmLoading={dvSaving}
|
|
845
|
-
onCancel={() => setDvModalOpen(false)}
|
|
846
|
-
onOk={handleSaveDataView}
|
|
847
|
-
width={600}
|
|
848
|
-
style={{ maxWidth: 'calc(100vw - 32px)' }}
|
|
849
|
-
centered
|
|
850
|
-
>
|
|
851
|
-
<Form form={dvForm} layout="vertical">
|
|
852
|
-
<Form.Item name="title" label={t('Title')} rules={[{ required: true }]}>
|
|
853
|
-
<Input placeholder="Application Logs" />
|
|
854
|
-
</Form.Item>
|
|
855
|
-
<Form.Item
|
|
856
|
-
name="dataSourceKey"
|
|
857
|
-
label={t('Data Source (Elasticsearch)')}
|
|
858
|
-
rules={[{ required: true }]}
|
|
859
|
-
extra={t(
|
|
860
|
-
'Configure Elasticsearch 8.x TLS, CA Fingerprint, API Key, or Bearer Token in Data Source Manager',
|
|
861
|
-
)}
|
|
862
|
-
>
|
|
863
|
-
<Select
|
|
864
|
-
onChange={() => setConnHealth(null)}
|
|
865
|
-
options={connections.map((c) => {
|
|
866
|
-
const badgeParts = [
|
|
867
|
-
c.endpointMode === 'cloud' ? 'Cloud' : 'Nodes',
|
|
868
|
-
c.authMode && c.authMode !== 'none' ? c.authMode : undefined,
|
|
869
|
-
c.tlsMode === 'caFingerprint'
|
|
870
|
-
? 'CA-FP'
|
|
871
|
-
: c.tlsMode === 'caCert'
|
|
872
|
-
? 'CA-PEM'
|
|
873
|
-
: c.tlsMode === 'skip'
|
|
874
|
-
? 'No-TLS-Verify'
|
|
875
|
-
: undefined,
|
|
876
|
-
].filter(Boolean);
|
|
877
|
-
return {
|
|
878
|
-
label: `${c.displayName} (${c.key})${badgeParts.length ? ` · [${badgeParts.join(' / ')}]` : ''}`,
|
|
879
|
-
value: c.key,
|
|
880
|
-
};
|
|
881
|
-
})}
|
|
882
|
-
/>
|
|
883
|
-
</Form.Item>
|
|
884
|
-
<div style={{ marginBottom: 12, display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
|
|
885
|
-
<Button size="small" loading={testingConn} onClick={handleTestDvConnection}>
|
|
886
|
-
{t('Test Connection')}
|
|
887
|
-
</Button>
|
|
888
|
-
{connHealth?.ok && (
|
|
889
|
-
<Tag color="success">
|
|
890
|
-
{t('Connection verified')}
|
|
891
|
-
{connHealth.clusterName ? `: ${connHealth.clusterName}` : ''}
|
|
892
|
-
{connHealth.version ? ` (v${connHealth.version})` : ''}
|
|
893
|
-
{connHealth.limitedPrivileges ? ` · ${t('Index-scoped role')}` : ''}
|
|
894
|
-
</Tag>
|
|
895
|
-
)}
|
|
896
|
-
</div>
|
|
897
|
-
<Form.Item name="indexPattern" label={t('Index Pattern')} rules={[{ required: true }]}>
|
|
898
|
-
<Space.Compact style={{ width: '100%' }}>
|
|
899
|
-
<Input placeholder="logs-*" />
|
|
900
|
-
<Button loading={loadingIndices} icon={<EyeOutlined />} onClick={handleBrowseIndices}>
|
|
901
|
-
{t('Browse Indices')}
|
|
902
|
-
</Button>
|
|
903
|
-
</Space.Compact>
|
|
904
|
-
</Form.Item>
|
|
905
|
-
{matchedIndices.length > 0 && (
|
|
906
|
-
<Paragraph style={{ fontSize: 12 }}>
|
|
907
|
-
<Text strong>{t('Matching Indices')}: </Text>
|
|
908
|
-
{matchedIndices.slice(0, 20).map((idx) => (
|
|
909
|
-
<Tag key={idx} style={{ marginBottom: 4 }}>
|
|
910
|
-
{idx}
|
|
911
|
-
</Tag>
|
|
912
|
-
))}
|
|
913
|
-
</Paragraph>
|
|
914
|
-
)}
|
|
915
|
-
<Form.Item name="timeField" label={t('Time Field')}>
|
|
916
|
-
<Input placeholder="@timestamp" />
|
|
917
|
-
</Form.Item>
|
|
918
|
-
<Form.Item name="allowedRoles" label={t('Allowed Roles')}>
|
|
919
|
-
<Select
|
|
920
|
-
mode="tags"
|
|
921
|
-
allowClear
|
|
922
|
-
placeholder={t('Leave empty to allow all authenticated users')}
|
|
923
|
-
options={roleOptions}
|
|
924
|
-
/>
|
|
925
|
-
</Form.Item>
|
|
926
|
-
<Form.Item name="description" label={t('Description')}>
|
|
927
|
-
<Input.TextArea rows={2} />
|
|
928
|
-
</Form.Item>
|
|
929
|
-
</Form>
|
|
930
|
-
</Modal>
|
|
931
|
-
|
|
932
|
-
{/* Report Studio Drawer */}
|
|
933
|
-
<Drawer
|
|
934
|
-
title={editingReport ? t('Edit Report') : t('New Report')}
|
|
935
|
-
open={studioOpen}
|
|
936
|
-
onClose={() => setStudioOpen(false)}
|
|
937
|
-
width="min(1080px, 96vw)"
|
|
938
|
-
extra={
|
|
939
|
-
<Space>
|
|
940
|
-
<Button icon={<PlayCircleOutlined />} loading={previewLoading} onClick={() => handleRunStudioPreview()}>
|
|
941
|
-
{t('Run Preview')}
|
|
942
|
-
</Button>
|
|
943
|
-
<Button type="primary" loading={savingReport} onClick={handleSaveReport}>
|
|
944
|
-
{t('Save')}
|
|
945
|
-
</Button>
|
|
946
|
-
</Space>
|
|
947
|
-
}
|
|
948
|
-
>
|
|
949
|
-
<Form form={reportForm} layout="vertical">
|
|
950
|
-
<Row gutter={16}>
|
|
951
|
-
<Col xs={24} md={10}>
|
|
952
|
-
<Form.Item name="title" label={t('Title')} rules={[{ required: true }]}>
|
|
953
|
-
<Input placeholder="HTTP 5xx Error Logs" />
|
|
954
|
-
</Form.Item>
|
|
955
|
-
</Col>
|
|
956
|
-
<Col xs={24} md={7}>
|
|
957
|
-
<Form.Item name="dataViewId" label={t('Data View')} rules={[{ required: true }]}>
|
|
958
|
-
<Select
|
|
959
|
-
options={dataViews.map((dv) => ({
|
|
960
|
-
label: `${dv.title} (${dv.indexPattern})`,
|
|
961
|
-
value: dv.id,
|
|
962
|
-
}))}
|
|
963
|
-
/>
|
|
964
|
-
</Form.Item>
|
|
965
|
-
</Col>
|
|
966
|
-
<Col xs={24} md={7}>
|
|
967
|
-
<Form.Item name="visualization" label={t('Visualization')} rules={[{ required: true }]}>
|
|
968
|
-
<Select
|
|
969
|
-
options={[
|
|
970
|
-
{ label: t('Table (Discover)'), value: 'table' },
|
|
971
|
-
{ label: t('Bar Chart'), value: 'bar' },
|
|
972
|
-
{ label: t('Line Chart'), value: 'line' },
|
|
973
|
-
{ label: t('Area Chart'), value: 'area' },
|
|
974
|
-
{ label: t('Pie Chart'), value: 'pie' },
|
|
975
|
-
{ label: t('Metric KPI'), value: 'metric' },
|
|
976
|
-
]}
|
|
977
|
-
/>
|
|
978
|
-
</Form.Item>
|
|
979
|
-
</Col>
|
|
980
|
-
</Row>
|
|
981
|
-
|
|
982
|
-
<Row gutter={16}>
|
|
983
|
-
<Col xs={24} md={10}>
|
|
984
|
-
<Form.Item name="query" label={t('KQL / Search Query')}>
|
|
985
|
-
<ElasticKqlInput
|
|
986
|
-
placeholder={t('Search KQL, e.g. status >= 500 AND service: "api"')}
|
|
987
|
-
fields={studioFields}
|
|
988
|
-
sampleRows={previewResult?.rows}
|
|
989
|
-
style={{ width: '100%' }}
|
|
990
|
-
onInspectTopValues={
|
|
991
|
-
watchedDataViewId !== undefined && watchedDataViewId !== null
|
|
992
|
-
? (field) =>
|
|
993
|
-
fetchFieldTopValues(api, {
|
|
994
|
-
dataViewId: watchedDataViewId,
|
|
995
|
-
field,
|
|
996
|
-
size: 12,
|
|
997
|
-
})
|
|
998
|
-
: undefined
|
|
999
|
-
}
|
|
1000
|
-
onSubmit={() => {
|
|
1001
|
-
handleRunStudioPreview();
|
|
1002
|
-
}}
|
|
1003
|
-
/>
|
|
1004
|
-
</Form.Item>
|
|
1005
|
-
</Col>
|
|
1006
|
-
<Col xs={12} md={5}>
|
|
1007
|
-
<Form.Item name="timePreset" label={t('Time Field')}>
|
|
1008
|
-
<Select
|
|
1009
|
-
options={[
|
|
1010
|
-
{ label: t('Last 15 minutes'), value: 'last_15m' },
|
|
1011
|
-
{ label: t('Last 1 hour'), value: 'last_1h' },
|
|
1012
|
-
{ label: t('Last 24 hours'), value: 'last_24h' },
|
|
1013
|
-
{ label: t('Last 7 days'), value: 'last_7d' },
|
|
1014
|
-
{ label: t('Last 30 days'), value: 'last_30d' },
|
|
1015
|
-
{ label: t('Last 90 days'), value: 'last_90d' },
|
|
1016
|
-
{ label: t('All time'), value: 'all' },
|
|
1017
|
-
{ label: t('Custom range'), value: 'custom' },
|
|
1018
|
-
]}
|
|
1019
|
-
/>
|
|
1020
|
-
</Form.Item>
|
|
1021
|
-
</Col>
|
|
1022
|
-
<Col xs={12} md={6}>
|
|
1023
|
-
<Form.Item name="allowedRoles" label={t('Allowed Roles')}>
|
|
1024
|
-
<Select
|
|
1025
|
-
mode="tags"
|
|
1026
|
-
allowClear
|
|
1027
|
-
placeholder={t('Leave empty to allow all authenticated users')}
|
|
1028
|
-
options={roleOptions}
|
|
1029
|
-
/>
|
|
1030
|
-
</Form.Item>
|
|
1031
|
-
</Col>
|
|
1032
|
-
<Col xs={12} md={3}>
|
|
1033
|
-
<Form.Item name="published" label={t('Published')} valuePropName="checked">
|
|
1034
|
-
<Switch />
|
|
1035
|
-
</Form.Item>
|
|
1036
|
-
</Col>
|
|
1037
|
-
</Row>
|
|
1038
|
-
|
|
1039
|
-
{watchedTimePreset === 'custom' && (
|
|
1040
|
-
<Row gutter={16}>
|
|
1041
|
-
<Col xs={12} md={6}>
|
|
1042
|
-
<Form.Item name="timeFrom" label={t('From')}>
|
|
1043
|
-
<Input placeholder="2026-11-29T00:00:00Z / now-24h" />
|
|
1044
|
-
</Form.Item>
|
|
1045
|
-
</Col>
|
|
1046
|
-
<Col xs={12} md={6}>
|
|
1047
|
-
<Form.Item name="timeTo" label={t('To')}>
|
|
1048
|
-
<Input placeholder="2026-11-30T00:00:00Z / now" />
|
|
1049
|
-
</Form.Item>
|
|
1050
|
-
</Col>
|
|
1051
|
-
</Row>
|
|
1052
|
-
)}
|
|
1053
|
-
|
|
1054
|
-
{/* Mandatory Server-Enforced Locked Filters Builder */}
|
|
1055
|
-
<Card size="small" title={t('Locked Security Filters (Server-enforced)')} style={{ marginBottom: 12 }}>
|
|
1056
|
-
<Form.List name="lockedFilters">
|
|
1057
|
-
{(lockedList, { add, remove }) => (
|
|
1058
|
-
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1059
|
-
{lockedList.map(({ key, name }) => (
|
|
1060
|
-
<Space key={key} wrap align="baseline">
|
|
1061
|
-
<Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 190 }}>
|
|
1062
|
-
<Select
|
|
1063
|
-
showSearch
|
|
1064
|
-
placeholder={t('Field')}
|
|
1065
|
-
options={studioFields.map((f) => ({ label: `${f.name} (${f.type})`, value: f.name }))}
|
|
1066
|
-
/>
|
|
1067
|
-
</Form.Item>
|
|
1068
|
-
<Form.Item name={[name, 'operator']} style={{ marginBottom: 0, minWidth: 160 }}>
|
|
1069
|
-
<Select options={FILTER_OPERATOR_ITEMS} />
|
|
1070
|
-
</Form.Item>
|
|
1071
|
-
<Form.Item name={[name, 'value']} style={{ marginBottom: 0 }}>
|
|
1072
|
-
<Input placeholder={t('Value')} />
|
|
1073
|
-
</Form.Item>
|
|
1074
|
-
<Form.Item name={[name, 'valueTo']} style={{ marginBottom: 0 }}>
|
|
1075
|
-
<Input placeholder={t('To Value')} style={{ width: 120 }} />
|
|
1076
|
-
</Form.Item>
|
|
1077
|
-
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1078
|
-
</Space>
|
|
1079
|
-
))}
|
|
1080
|
-
<Button size="small" type="dashed" icon={<PlusOutlined />} onClick={() => add({ operator: 'eq' })}>
|
|
1081
|
-
{t('Add Locked Filter')}
|
|
1082
|
-
</Button>
|
|
1083
|
-
</Space>
|
|
1084
|
-
)}
|
|
1085
|
-
</Form.List>
|
|
1086
|
-
</Card>
|
|
1087
|
-
|
|
1088
|
-
{/* Structured Filters Builder */}
|
|
1089
|
-
<Card size="small" title={t('Add Filter')} style={{ marginBottom: 12 }}>
|
|
1090
|
-
<Form.List name="filters">
|
|
1091
|
-
{(fieldsList, { add, remove }) => (
|
|
1092
|
-
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1093
|
-
{fieldsList.map(({ key, name }) => (
|
|
1094
|
-
<Space key={key} wrap align="baseline">
|
|
1095
|
-
<Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 190 }}>
|
|
1096
|
-
<Select
|
|
1097
|
-
showSearch
|
|
1098
|
-
placeholder={t('Field')}
|
|
1099
|
-
options={studioFields.map((f) => ({ label: `${f.name} (${f.type})`, value: f.name }))}
|
|
1100
|
-
/>
|
|
1101
|
-
</Form.Item>
|
|
1102
|
-
<Form.Item name={[name, 'operator']} style={{ marginBottom: 0, minWidth: 160 }}>
|
|
1103
|
-
<Select options={FILTER_OPERATOR_ITEMS} />
|
|
1104
|
-
</Form.Item>
|
|
1105
|
-
<Form.Item name={[name, 'value']} style={{ marginBottom: 0 }}>
|
|
1106
|
-
<Input placeholder={t('Value')} />
|
|
1107
|
-
</Form.Item>
|
|
1108
|
-
<Form.Item name={[name, 'valueTo']} style={{ marginBottom: 0 }}>
|
|
1109
|
-
<Input placeholder={t('To Value')} style={{ width: 120 }} />
|
|
1110
|
-
</Form.Item>
|
|
1111
|
-
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1112
|
-
</Space>
|
|
1113
|
-
))}
|
|
1114
|
-
<Button size="small" type="dashed" icon={<PlusOutlined />} onClick={() => add({ operator: 'eq' })}>
|
|
1115
|
-
{t('Add Filter')}
|
|
1116
|
-
</Button>
|
|
1117
|
-
</Space>
|
|
1118
|
-
)}
|
|
1119
|
-
</Form.List>
|
|
1120
|
-
</Card>
|
|
1121
|
-
|
|
1122
|
-
{watchedVisualization === 'table' ? (
|
|
1123
|
-
<Row gutter={16}>
|
|
1124
|
-
<Col xs={24} md={12}>
|
|
1125
|
-
<Form.Item name="columns" label={t('Columns')}>
|
|
1126
|
-
<Select
|
|
1127
|
-
mode="multiple"
|
|
1128
|
-
allowClear
|
|
1129
|
-
placeholder={t('Auto-detect columns from documents')}
|
|
1130
|
-
options={studioFields.filter((f) => !f.isSubfield).map((f) => ({ label: f.name, value: f.name }))}
|
|
1131
|
-
/>
|
|
1132
|
-
</Form.Item>
|
|
1133
|
-
<Card size="small" title={t('Sort')} style={{ marginBottom: 12 }}>
|
|
1134
|
-
<Form.List name="sort">
|
|
1135
|
-
{(sortList, { add, remove }) => (
|
|
1136
|
-
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1137
|
-
{sortList.map(({ key, name }) => (
|
|
1138
|
-
<Space key={key} align="baseline">
|
|
1139
|
-
<Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 200 }}>
|
|
1140
|
-
<Select
|
|
1141
|
-
showSearch
|
|
1142
|
-
placeholder={t('Field')}
|
|
1143
|
-
options={aggregatableStudioFields.map((f) => ({
|
|
1144
|
-
label: f.keywordSubfield ? `${f.name} (${f.keywordSubfield})` : f.name,
|
|
1145
|
-
value: f.keywordSubfield || f.name,
|
|
1146
|
-
}))}
|
|
1147
|
-
/>
|
|
1148
|
-
</Form.Item>
|
|
1149
|
-
<Form.Item name={[name, 'order']} style={{ marginBottom: 0, minWidth: 130 }}>
|
|
1150
|
-
<Select
|
|
1151
|
-
options={[
|
|
1152
|
-
{ label: t('Descending'), value: 'desc' },
|
|
1153
|
-
{ label: t('Ascending'), value: 'asc' },
|
|
1154
|
-
]}
|
|
1155
|
-
/>
|
|
1156
|
-
</Form.Item>
|
|
1157
|
-
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1158
|
-
</Space>
|
|
1159
|
-
))}
|
|
1160
|
-
<Button
|
|
1161
|
-
size="small"
|
|
1162
|
-
type="dashed"
|
|
1163
|
-
icon={<PlusOutlined />}
|
|
1164
|
-
onClick={() => add({ order: 'desc' })}
|
|
1165
|
-
>
|
|
1166
|
-
{t('Add Sort')}
|
|
1167
|
-
</Button>
|
|
1168
|
-
</Space>
|
|
1169
|
-
)}
|
|
1170
|
-
</Form.List>
|
|
1171
|
-
</Card>
|
|
1172
|
-
</Col>
|
|
1173
|
-
<Col xs={24} md={12}>
|
|
1174
|
-
<Row gutter={12}>
|
|
1175
|
-
<Col span={6}>
|
|
1176
|
-
<Form.Item name="pageSize" label={t('Page Size')}>
|
|
1177
|
-
<InputNumber min={5} max={200} style={{ width: '100%' }} />
|
|
1178
|
-
</Form.Item>
|
|
1179
|
-
</Col>
|
|
1180
|
-
<Col span={6}>
|
|
1181
|
-
<Form.Item
|
|
1182
|
-
name="showHistogram"
|
|
1183
|
-
label={t('Show time histogram above table')}
|
|
1184
|
-
valuePropName="checked"
|
|
1185
|
-
>
|
|
1186
|
-
<Switch />
|
|
1187
|
-
</Form.Item>
|
|
1188
|
-
</Col>
|
|
1189
|
-
<Col span={6}>
|
|
1190
|
-
<Form.Item
|
|
1191
|
-
name="allowInteractiveControls"
|
|
1192
|
-
label={t('Allow interactive search/filter on block')}
|
|
1193
|
-
valuePropName="checked"
|
|
1194
|
-
>
|
|
1195
|
-
<Switch />
|
|
1196
|
-
</Form.Item>
|
|
1197
|
-
</Col>
|
|
1198
|
-
<Col span={6}>
|
|
1199
|
-
<Form.Item name="allowExport" label={t('Allow data export on block')} valuePropName="checked">
|
|
1200
|
-
<Switch />
|
|
1201
|
-
</Form.Item>
|
|
1202
|
-
</Col>
|
|
1203
|
-
</Row>
|
|
1204
|
-
<Card size="small" title={t('Field Formats')} style={{ marginBottom: 12 }}>
|
|
1205
|
-
<Form.List name="fieldFormats">
|
|
1206
|
-
{(fmtList, { add, remove }) => (
|
|
1207
|
-
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1208
|
-
{fmtList.map(({ key, name }) => (
|
|
1209
|
-
<Space key={key} align="baseline">
|
|
1210
|
-
<Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 170 }}>
|
|
1211
|
-
<Select
|
|
1212
|
-
showSearch
|
|
1213
|
-
placeholder={t('Field')}
|
|
1214
|
-
options={studioFields
|
|
1215
|
-
.filter((f) => !f.isSubfield)
|
|
1216
|
-
.map((f) => ({ label: f.name, value: f.name }))}
|
|
1217
|
-
/>
|
|
1218
|
-
</Form.Item>
|
|
1219
|
-
<Form.Item name={[name, 'format']} style={{ marginBottom: 0, minWidth: 160 }}>
|
|
1220
|
-
<Select
|
|
1221
|
-
options={[
|
|
1222
|
-
{ label: t('Duration (ms)'), value: 'duration_ms' },
|
|
1223
|
-
{ label: t('Bytes'), value: 'bytes' },
|
|
1224
|
-
{ label: t('Percent (%)'), value: 'percent' },
|
|
1225
|
-
{ label: t('Number'), value: 'number' },
|
|
1226
|
-
{ label: t('Status Badge'), value: 'status_badge' },
|
|
1227
|
-
{ label: t('URL Link'), value: 'url' },
|
|
1228
|
-
]}
|
|
1229
|
-
/>
|
|
1230
|
-
</Form.Item>
|
|
1231
|
-
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1232
|
-
</Space>
|
|
1233
|
-
))}
|
|
1234
|
-
<Button
|
|
1235
|
-
size="small"
|
|
1236
|
-
type="dashed"
|
|
1237
|
-
icon={<PlusOutlined />}
|
|
1238
|
-
onClick={() => add({ format: 'status_badge' })}
|
|
1239
|
-
>
|
|
1240
|
-
{t('Add Field Format')}
|
|
1241
|
-
</Button>
|
|
1242
|
-
</Space>
|
|
1243
|
-
)}
|
|
1244
|
-
</Form.List>
|
|
1245
|
-
</Card>
|
|
1246
|
-
<Form.Item name="description" label={t('Description')}>
|
|
1247
|
-
<Input.TextArea rows={2} />
|
|
1248
|
-
</Form.Item>
|
|
1249
|
-
</Col>
|
|
1250
|
-
</Row>
|
|
1251
|
-
) : (
|
|
1252
|
-
<Card size="small" style={{ marginBottom: 12 }}>
|
|
1253
|
-
<Row gutter={16}>
|
|
1254
|
-
{watchedVisualization !== 'metric' && (
|
|
1255
|
-
<>
|
|
1256
|
-
<Col xs={12} md={6}>
|
|
1257
|
-
<Form.Item name="bucketType" label={t('Bucket Type')}>
|
|
1258
|
-
<Select
|
|
1259
|
-
options={[
|
|
1260
|
-
{ label: t('Date Histogram'), value: 'date_histogram' },
|
|
1261
|
-
{ label: t('Top Terms'), value: 'terms' },
|
|
1262
|
-
]}
|
|
1263
|
-
/>
|
|
1264
|
-
</Form.Item>
|
|
1265
|
-
</Col>
|
|
1266
|
-
<Col xs={12} md={6}>
|
|
1267
|
-
<Form.Item name="bucketField" label={t('Bucket Field')}>
|
|
1268
|
-
<Select
|
|
1269
|
-
showSearch
|
|
1270
|
-
allowClear
|
|
1271
|
-
options={aggregatableStudioFields.map((f) => ({
|
|
1272
|
-
label: f.keywordSubfield ? `${f.name} → ${f.keywordSubfield}` : f.name,
|
|
1273
|
-
value: f.keywordSubfield || f.name,
|
|
1274
|
-
}))}
|
|
1275
|
-
/>
|
|
1276
|
-
</Form.Item>
|
|
1277
|
-
</Col>
|
|
1278
|
-
{watchedBucketType === 'date_histogram' ? (
|
|
1279
|
-
<Col xs={12} md={4}>
|
|
1280
|
-
<Form.Item name="calendarInterval" label={t('Interval')}>
|
|
1281
|
-
<Select
|
|
1282
|
-
options={[
|
|
1283
|
-
{ label: 'Auto', value: 'auto' },
|
|
1284
|
-
{ label: '1m', value: '1m' },
|
|
1285
|
-
{ label: '5m', value: '5m' },
|
|
1286
|
-
{ label: '15m', value: '15m' },
|
|
1287
|
-
{ label: '1h', value: '1h' },
|
|
1288
|
-
{ label: '1d', value: '1d' },
|
|
1289
|
-
{ label: '1w', value: '1w' },
|
|
1290
|
-
{ label: '1M', value: '1M' },
|
|
1291
|
-
]}
|
|
1292
|
-
/>
|
|
1293
|
-
</Form.Item>
|
|
1294
|
-
</Col>
|
|
1295
|
-
) : (
|
|
1296
|
-
<Col xs={12} md={4}>
|
|
1297
|
-
<Form.Item name="topN" label={t('Top N')}>
|
|
1298
|
-
<InputNumber min={1} max={50} style={{ width: '100%' }} />
|
|
1299
|
-
</Form.Item>
|
|
1300
|
-
</Col>
|
|
1301
|
-
)}
|
|
1302
|
-
{watchedVisualization !== 'pie' && (
|
|
1303
|
-
<>
|
|
1304
|
-
<Col xs={12} md={4}>
|
|
1305
|
-
<Form.Item name="splitSeriesField" label={t('Split Series Field')}>
|
|
1306
|
-
<Select
|
|
1307
|
-
showSearch
|
|
1308
|
-
allowClear
|
|
1309
|
-
options={aggregatableStudioFields.map((f) => ({
|
|
1310
|
-
label: f.keywordSubfield ? `${f.name} → ${f.keywordSubfield}` : f.name,
|
|
1311
|
-
value: f.keywordSubfield || f.name,
|
|
1312
|
-
}))}
|
|
1313
|
-
/>
|
|
1314
|
-
</Form.Item>
|
|
1315
|
-
</Col>
|
|
1316
|
-
<Col xs={12} md={4}>
|
|
1317
|
-
<Form.Item name="stackMode" label={t('Stack Mode')}>
|
|
1318
|
-
<Select
|
|
1319
|
-
options={[
|
|
1320
|
-
{ label: t('Grouped'), value: 'none' },
|
|
1321
|
-
{ label: t('Stacked'), value: 'stacked' },
|
|
1322
|
-
{ label: t('100% Stacked'), value: 'percent' },
|
|
1323
|
-
]}
|
|
1324
|
-
/>
|
|
1325
|
-
</Form.Item>
|
|
1326
|
-
</Col>
|
|
1327
|
-
</>
|
|
1328
|
-
)}
|
|
1329
|
-
</>
|
|
1330
|
-
)}
|
|
1331
|
-
<Col xs={12} md={4}>
|
|
1332
|
-
<Form.Item name="metricType" label={t('Metric')}>
|
|
1333
|
-
<Select
|
|
1334
|
-
options={[
|
|
1335
|
-
{ label: 'Count', value: 'count' },
|
|
1336
|
-
{ label: 'Sum', value: 'sum' },
|
|
1337
|
-
{ label: 'Average', value: 'avg' },
|
|
1338
|
-
{ label: 'Min', value: 'min' },
|
|
1339
|
-
{ label: 'Max', value: 'max' },
|
|
1340
|
-
{ label: 'P50 (Median)', value: 'p50' },
|
|
1341
|
-
{ label: 'P95', value: 'p95' },
|
|
1342
|
-
{ label: 'P99', value: 'p99' },
|
|
1343
|
-
{ label: 'Unique (Cardinality)', value: 'cardinality' },
|
|
1344
|
-
]}
|
|
1345
|
-
/>
|
|
1346
|
-
</Form.Item>
|
|
1347
|
-
</Col>
|
|
1348
|
-
{watchedMetricType !== 'count' && (
|
|
1349
|
-
<Col xs={12} md={4}>
|
|
1350
|
-
<Form.Item name="metricField" label={t('Metric Field')}>
|
|
1351
|
-
<Select
|
|
1352
|
-
showSearch
|
|
1353
|
-
options={(watchedMetricType === 'cardinality'
|
|
1354
|
-
? aggregatableStudioFields
|
|
1355
|
-
: numericStudioFields.length > 0
|
|
1356
|
-
? numericStudioFields
|
|
1357
|
-
: aggregatableStudioFields
|
|
1358
|
-
).map((f) => ({
|
|
1359
|
-
label: f.name,
|
|
1360
|
-
value: f.keywordSubfield || f.name,
|
|
1361
|
-
}))}
|
|
1362
|
-
/>
|
|
1363
|
-
</Form.Item>
|
|
1364
|
-
</Col>
|
|
1365
|
-
)}
|
|
1366
|
-
<Col xs={12} md={6}>
|
|
1367
|
-
<Form.Item name="metricLabel" label={t('Metric Label')}>
|
|
1368
|
-
<Input placeholder="Requests / Latency (ms)" />
|
|
1369
|
-
</Form.Item>
|
|
1370
|
-
</Col>
|
|
1371
|
-
{watchedVisualization === 'metric' && (
|
|
1372
|
-
<Col xs={12} md={5}>
|
|
1373
|
-
<Form.Item
|
|
1374
|
-
name="comparePreviousPeriod"
|
|
1375
|
-
label={t('Compare previous period')}
|
|
1376
|
-
valuePropName="checked"
|
|
1377
|
-
>
|
|
1378
|
-
<Switch />
|
|
1379
|
-
</Form.Item>
|
|
1380
|
-
</Col>
|
|
1381
|
-
)}
|
|
1382
|
-
<Col xs={12} md={5}>
|
|
1383
|
-
<Form.Item
|
|
1384
|
-
name="allowInteractiveControls"
|
|
1385
|
-
label={t('Allow interactive search/filter on block')}
|
|
1386
|
-
valuePropName="checked"
|
|
1387
|
-
>
|
|
1388
|
-
<Switch />
|
|
1389
|
-
</Form.Item>
|
|
1390
|
-
</Col>
|
|
1391
|
-
</Row>
|
|
1392
|
-
</Card>
|
|
1393
|
-
)}
|
|
1394
|
-
|
|
1395
|
-
<Card size="small" title={t('Record Context Bindings')} style={{ marginBottom: 12 }}>
|
|
1396
|
-
<Form.List name="contextBindings">
|
|
1397
|
-
{(ctxList, { add, remove }) => (
|
|
1398
|
-
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1399
|
-
{ctxList.map(({ key, name }) => (
|
|
1400
|
-
<Space key={key} wrap align="baseline">
|
|
1401
|
-
<Form.Item name={[name, 'esField']} style={{ marginBottom: 0, minWidth: 200 }}>
|
|
1402
|
-
<Select
|
|
1403
|
-
showSearch
|
|
1404
|
-
placeholder={t('Field')}
|
|
1405
|
-
options={studioFields.map((f) => ({ label: `${f.name} (${f.type})`, value: f.name }))}
|
|
1406
|
-
/>
|
|
1407
|
-
</Form.Item>
|
|
1408
|
-
<Form.Item name={[name, 'recordFieldPath']} style={{ marginBottom: 0, minWidth: 220 }}>
|
|
1409
|
-
<Input placeholder={t('Record Field Path')} />
|
|
1410
|
-
</Form.Item>
|
|
1411
|
-
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1412
|
-
</Space>
|
|
1413
|
-
))}
|
|
1414
|
-
<Button size="small" type="dashed" icon={<PlusOutlined />} onClick={() => add()}>
|
|
1415
|
-
{t('Add Context Binding')}
|
|
1416
|
-
</Button>
|
|
1417
|
-
</Space>
|
|
1418
|
-
)}
|
|
1419
|
-
</Form.List>
|
|
1420
|
-
</Card>
|
|
1421
|
-
</Form>
|
|
1422
|
-
|
|
1423
|
-
<Divider orientation="left">{t('Preview')}</Divider>
|
|
1424
|
-
<ElasticReportRenderer
|
|
1425
|
-
title={reportForm.getFieldValue('title') || t('Preview')}
|
|
1426
|
-
spec={studioPreviewSpec}
|
|
1427
|
-
dataView={selectedDataView}
|
|
1428
|
-
fields={studioFields}
|
|
1429
|
-
result={previewResult}
|
|
1430
|
-
loading={previewLoading}
|
|
1431
|
-
error={previewError}
|
|
1432
|
-
showToolbar={true}
|
|
1433
|
-
onExecute={(overrides) => {
|
|
1434
|
-
handleRunStudioPreview(overrides);
|
|
1435
|
-
}}
|
|
1436
|
-
onInspectTopValues={
|
|
1437
|
-
watchedDataViewId !== undefined && watchedDataViewId !== null
|
|
1438
|
-
? (field, overrides) =>
|
|
1439
|
-
fetchFieldTopValues(api, {
|
|
1440
|
-
dataViewId: watchedDataViewId,
|
|
1441
|
-
field,
|
|
1442
|
-
size: 8,
|
|
1443
|
-
overrides,
|
|
1444
|
-
})
|
|
1445
|
-
: undefined
|
|
1446
|
-
}
|
|
1447
|
-
/>
|
|
1448
|
-
</Drawer>
|
|
1449
|
-
</Card>
|
|
1450
|
-
);
|
|
1451
|
-
};
|
|
1452
|
-
|
|
1453
|
-
export default ElasticReportManager;
|
|
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 {
|
|
11
|
+
CopyOutlined,
|
|
12
|
+
DeleteOutlined,
|
|
13
|
+
EditOutlined,
|
|
14
|
+
EyeOutlined,
|
|
15
|
+
PlayCircleOutlined,
|
|
16
|
+
PlusOutlined,
|
|
17
|
+
ReloadOutlined,
|
|
18
|
+
} from '@ant-design/icons';
|
|
19
|
+
import { useApp } from '@nocobase/client-v2';
|
|
20
|
+
import {
|
|
21
|
+
Alert,
|
|
22
|
+
App,
|
|
23
|
+
Button,
|
|
24
|
+
Card,
|
|
25
|
+
Col,
|
|
26
|
+
Descriptions,
|
|
27
|
+
Divider,
|
|
28
|
+
Drawer,
|
|
29
|
+
Form,
|
|
30
|
+
Input,
|
|
31
|
+
InputNumber,
|
|
32
|
+
Modal,
|
|
33
|
+
Popconfirm,
|
|
34
|
+
Row,
|
|
35
|
+
Select,
|
|
36
|
+
Space,
|
|
37
|
+
Switch,
|
|
38
|
+
Table,
|
|
39
|
+
Tabs,
|
|
40
|
+
Tag,
|
|
41
|
+
Typography,
|
|
42
|
+
} from 'antd';
|
|
43
|
+
import type { TableColumnsType } from 'antd';
|
|
44
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
45
|
+
import type {
|
|
46
|
+
BucketAggType,
|
|
47
|
+
CalendarIntervalOption,
|
|
48
|
+
ChartStackMode,
|
|
49
|
+
EsConnectionHealthResult,
|
|
50
|
+
EsConnectionSummary,
|
|
51
|
+
EsDataViewRecord,
|
|
52
|
+
EsFieldCapability,
|
|
53
|
+
EsReportRecord,
|
|
54
|
+
FieldFormatType,
|
|
55
|
+
FilterOperator,
|
|
56
|
+
ID,
|
|
57
|
+
MetricAggType,
|
|
58
|
+
RecordContextBinding,
|
|
59
|
+
ReportExecutionResult,
|
|
60
|
+
ReportFilterItem,
|
|
61
|
+
ReportRuntimeOverrides,
|
|
62
|
+
ReportSortItem,
|
|
63
|
+
ReportSpec,
|
|
64
|
+
ReportVisualizationType,
|
|
65
|
+
RoleSummary,
|
|
66
|
+
TimeRangePreset,
|
|
67
|
+
} from '../../shared/types';
|
|
68
|
+
import {
|
|
69
|
+
executeReportPreview,
|
|
70
|
+
fetchAllReports,
|
|
71
|
+
fetchAvailableRoles,
|
|
72
|
+
fetchDataViewFields,
|
|
73
|
+
fetchDataViews,
|
|
74
|
+
fetchEsConnections,
|
|
75
|
+
fetchEsIndices,
|
|
76
|
+
fetchFieldTopValues,
|
|
77
|
+
fetchMcpInfo,
|
|
78
|
+
persistReport,
|
|
79
|
+
removeDataView,
|
|
80
|
+
removeReport,
|
|
81
|
+
saveDataView,
|
|
82
|
+
testEsConnection,
|
|
83
|
+
type ApiClientLike,
|
|
84
|
+
type McpInfoPayload,
|
|
85
|
+
} from '../api';
|
|
86
|
+
import { ElasticKqlInput } from '../components/ElasticKqlInput';
|
|
87
|
+
import { ElasticReportRenderer } from '../components/ElasticReportRenderer';
|
|
88
|
+
import { useT } from '../locale';
|
|
89
|
+
|
|
90
|
+
const { Paragraph, Text } = Typography;
|
|
91
|
+
|
|
92
|
+
interface FilterFormRow {
|
|
93
|
+
field: string;
|
|
94
|
+
operator: FilterOperator;
|
|
95
|
+
value?: string;
|
|
96
|
+
valueTo?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface ReportEditorFormValues {
|
|
100
|
+
title: string;
|
|
101
|
+
description?: string;
|
|
102
|
+
dataViewId: ID;
|
|
103
|
+
published: boolean;
|
|
104
|
+
allowedRoles?: string[];
|
|
105
|
+
visualization: ReportVisualizationType;
|
|
106
|
+
query?: string;
|
|
107
|
+
timePreset: TimeRangePreset;
|
|
108
|
+
timeFrom?: string;
|
|
109
|
+
timeTo?: string;
|
|
110
|
+
filters?: FilterFormRow[];
|
|
111
|
+
lockedFilters?: FilterFormRow[];
|
|
112
|
+
sort?: Array<{
|
|
113
|
+
field: string;
|
|
114
|
+
order: 'asc' | 'desc';
|
|
115
|
+
}>;
|
|
116
|
+
columns?: string[];
|
|
117
|
+
fieldFormats?: Array<{
|
|
118
|
+
field: string;
|
|
119
|
+
format: FieldFormatType;
|
|
120
|
+
}>;
|
|
121
|
+
contextBindings?: RecordContextBinding[];
|
|
122
|
+
pageSize: number;
|
|
123
|
+
showHistogram: boolean;
|
|
124
|
+
allowInteractiveControls: boolean;
|
|
125
|
+
allowExport: boolean;
|
|
126
|
+
bucketType: BucketAggType;
|
|
127
|
+
bucketField?: string;
|
|
128
|
+
calendarInterval: CalendarIntervalOption;
|
|
129
|
+
topN: number;
|
|
130
|
+
metricType: MetricAggType;
|
|
131
|
+
metricField?: string;
|
|
132
|
+
metricLabel?: string;
|
|
133
|
+
splitSeriesField?: string;
|
|
134
|
+
stackMode?: ChartStackMode;
|
|
135
|
+
comparePreviousPeriod?: boolean;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface DataViewFormValues {
|
|
139
|
+
title: string;
|
|
140
|
+
dataSourceKey: string;
|
|
141
|
+
indexPattern: string;
|
|
142
|
+
timeField?: string;
|
|
143
|
+
description?: string;
|
|
144
|
+
allowedRoles?: string[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const FILTER_OPERATOR_ITEMS: Array<{ label: string; value: FilterOperator }> = [
|
|
148
|
+
{ label: 'is (=)', value: 'eq' },
|
|
149
|
+
{ label: 'is not (!=)', value: 'ne' },
|
|
150
|
+
{ label: 'contains', value: 'contains' },
|
|
151
|
+
{ label: 'in (comma-separated)', value: 'in' },
|
|
152
|
+
{ label: 'not in', value: 'not_in' },
|
|
153
|
+
{ label: '>', value: 'gt' },
|
|
154
|
+
{ label: '>=', value: 'gte' },
|
|
155
|
+
{ label: '<', value: 'lt' },
|
|
156
|
+
{ label: '<=', value: 'lte' },
|
|
157
|
+
{ label: 'between', value: 'between' },
|
|
158
|
+
{ label: 'exists', value: 'exists' },
|
|
159
|
+
{ label: 'does not exist', value: 'not_exists' },
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
function mapFilterRows(rows: FilterFormRow[] | undefined, prefix: string): ReportFilterItem[] {
|
|
163
|
+
return (rows ?? [])
|
|
164
|
+
.filter((f) => Boolean(f?.field))
|
|
165
|
+
.map((f, idx) => ({
|
|
166
|
+
id: `${prefix}-${idx}`,
|
|
167
|
+
field: f.field,
|
|
168
|
+
operator: f.operator || 'eq',
|
|
169
|
+
...(f.value !== undefined && f.value !== '' ? { value: f.value } : {}),
|
|
170
|
+
...(f.valueTo !== undefined && f.valueTo !== '' ? { valueTo: f.valueTo } : {}),
|
|
171
|
+
enabled: true,
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function formValuesToSpec(values: ReportEditorFormValues): ReportSpec {
|
|
176
|
+
const filters = mapFilterRows(values.filters, 'flt');
|
|
177
|
+
const lockedFilters = mapFilterRows(values.lockedFilters, 'locked');
|
|
178
|
+
|
|
179
|
+
const sort: ReportSortItem[] = (values.sort ?? [])
|
|
180
|
+
.filter((s) => Boolean(s?.field))
|
|
181
|
+
.map((s) => ({
|
|
182
|
+
field: s.field,
|
|
183
|
+
order: s.order === 'asc' ? 'asc' : 'desc',
|
|
184
|
+
}));
|
|
185
|
+
|
|
186
|
+
const preset = values.timePreset || 'last_24h';
|
|
187
|
+
const timeRange =
|
|
188
|
+
preset === 'custom'
|
|
189
|
+
? {
|
|
190
|
+
preset: 'custom' as const,
|
|
191
|
+
...(values.timeFrom?.trim() ? { from: values.timeFrom.trim() } : {}),
|
|
192
|
+
...(values.timeTo?.trim() ? { to: values.timeTo.trim() } : {}),
|
|
193
|
+
}
|
|
194
|
+
: { preset };
|
|
195
|
+
|
|
196
|
+
const fieldFormatsMap: Record<string, FieldFormatType> = {};
|
|
197
|
+
for (const row of values.fieldFormats ?? []) {
|
|
198
|
+
if (row?.field && row.format && row.format !== 'auto') {
|
|
199
|
+
fieldFormatsMap[row.field] = row.format;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const contextBindings = (values.contextBindings ?? []).filter(
|
|
203
|
+
(b) => Boolean(b?.esField?.trim()) && Boolean(b?.recordFieldPath?.trim()),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
visualization: values.visualization || 'table',
|
|
208
|
+
query: values.query?.trim() ?? '',
|
|
209
|
+
queryMode: 'kql',
|
|
210
|
+
filters,
|
|
211
|
+
lockedFilters,
|
|
212
|
+
sort,
|
|
213
|
+
timeRange,
|
|
214
|
+
columns: values.columns ?? [],
|
|
215
|
+
...(Object.keys(fieldFormatsMap).length > 0 ? { fieldFormats: fieldFormatsMap } : {}),
|
|
216
|
+
...(contextBindings.length > 0 ? { contextBindings } : {}),
|
|
217
|
+
pageSize: values.pageSize || 20,
|
|
218
|
+
allowInteractiveControls: values.allowInteractiveControls !== false,
|
|
219
|
+
allowExport: values.allowExport !== false,
|
|
220
|
+
chart: {
|
|
221
|
+
bucketType: values.bucketType || 'date_histogram',
|
|
222
|
+
...(values.bucketField ? { bucketField: values.bucketField } : {}),
|
|
223
|
+
calendarInterval: values.calendarInterval || 'auto',
|
|
224
|
+
topN: values.topN || 10,
|
|
225
|
+
metricType: values.metricType || 'count',
|
|
226
|
+
...(values.metricField ? { metricField: values.metricField } : {}),
|
|
227
|
+
...(values.metricLabel ? { metricLabel: values.metricLabel } : {}),
|
|
228
|
+
showHistogram: values.showHistogram !== false,
|
|
229
|
+
...(values.splitSeriesField ? { splitSeriesField: values.splitSeriesField } : {}),
|
|
230
|
+
...(values.stackMode && values.stackMode !== 'none' ? { stackMode: values.stackMode } : {}),
|
|
231
|
+
...(values.comparePreviousPeriod === true ? { comparePreviousPeriod: true } : {}),
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export const ElasticReportManager: React.FC = () => {
|
|
237
|
+
const t = useT();
|
|
238
|
+
const app = useApp();
|
|
239
|
+
const api = app.apiClient as unknown as ApiClientLike;
|
|
240
|
+
const { message } = App.useApp();
|
|
241
|
+
|
|
242
|
+
const [connections, setConnections] = useState<EsConnectionSummary[]>([]);
|
|
243
|
+
const [roles, setRoles] = useState<RoleSummary[]>([]);
|
|
244
|
+
const [dataViews, setDataViews] = useState<EsDataViewRecord[]>([]);
|
|
245
|
+
const [reports, setReports] = useState<EsReportRecord[]>([]);
|
|
246
|
+
const [mcpInfo, setMcpInfo] = useState<McpInfoPayload | null>(null);
|
|
247
|
+
const [loadingList, setLoadingList] = useState(false);
|
|
248
|
+
|
|
249
|
+
// Data View modal state
|
|
250
|
+
const [dvModalOpen, setDvModalOpen] = useState(false);
|
|
251
|
+
const [editingDataView, setEditingDataView] = useState<EsDataViewRecord | null>(null);
|
|
252
|
+
const [dvSaving, setDvSaving] = useState(false);
|
|
253
|
+
const [matchedIndices, setMatchedIndices] = useState<string[]>([]);
|
|
254
|
+
const [loadingIndices, setLoadingIndices] = useState(false);
|
|
255
|
+
const [testingConn, setTestingConn] = useState(false);
|
|
256
|
+
const [connHealth, setConnHealth] = useState<EsConnectionHealthResult | null>(null);
|
|
257
|
+
const [dvForm] = Form.useForm<DataViewFormValues>();
|
|
258
|
+
|
|
259
|
+
// Report Studio drawer state
|
|
260
|
+
const [studioOpen, setStudioOpen] = useState(false);
|
|
261
|
+
const [editingReport, setEditingReport] = useState<EsReportRecord | null>(null);
|
|
262
|
+
const [studioFields, setStudioFields] = useState<EsFieldCapability[]>([]);
|
|
263
|
+
const [studioPreviewSpec, setStudioPreviewSpec] = useState<ReportSpec>({ visualization: 'table' });
|
|
264
|
+
const [previewResult, setPreviewResult] = useState<ReportExecutionResult | null>(null);
|
|
265
|
+
const [previewLoading, setPreviewLoading] = useState(false);
|
|
266
|
+
const [previewError, setPreviewError] = useState<string | null>(null);
|
|
267
|
+
const [savingReport, setSavingReport] = useState(false);
|
|
268
|
+
const [reportForm] = Form.useForm<ReportEditorFormValues>();
|
|
269
|
+
|
|
270
|
+
const watchedVisualization = Form.useWatch('visualization', reportForm) ?? 'table';
|
|
271
|
+
const watchedDataViewId = Form.useWatch('dataViewId', reportForm);
|
|
272
|
+
const watchedTimePreset = Form.useWatch('timePreset', reportForm) ?? 'last_24h';
|
|
273
|
+
const watchedBucketType = Form.useWatch('bucketType', reportForm) ?? 'date_histogram';
|
|
274
|
+
const watchedMetricType = Form.useWatch('metricType', reportForm) ?? 'count';
|
|
275
|
+
|
|
276
|
+
const roleOptions = useMemo(
|
|
277
|
+
() =>
|
|
278
|
+
roles.map((r) => ({
|
|
279
|
+
label: r.title && r.title !== r.name ? `${r.title} (${r.name})` : r.name,
|
|
280
|
+
value: r.name,
|
|
281
|
+
})),
|
|
282
|
+
[roles],
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const loadAll = useCallback(async () => {
|
|
286
|
+
setLoadingList(true);
|
|
287
|
+
try {
|
|
288
|
+
const [connList, roleList, dvList, reportList, mcpData] = await Promise.all([
|
|
289
|
+
fetchEsConnections(api).catch(() => []),
|
|
290
|
+
fetchAvailableRoles(api).catch(() => []),
|
|
291
|
+
fetchDataViews(api).catch(() => []),
|
|
292
|
+
fetchAllReports(api).catch(() => []),
|
|
293
|
+
fetchMcpInfo(api).catch(() => null),
|
|
294
|
+
]);
|
|
295
|
+
setConnections(connList);
|
|
296
|
+
setRoles(roleList);
|
|
297
|
+
setDataViews(dvList);
|
|
298
|
+
setReports(reportList);
|
|
299
|
+
setMcpInfo(mcpData);
|
|
300
|
+
} finally {
|
|
301
|
+
setLoadingList(false);
|
|
302
|
+
}
|
|
303
|
+
}, [api]);
|
|
304
|
+
|
|
305
|
+
useEffect(() => {
|
|
306
|
+
loadAll();
|
|
307
|
+
}, [loadAll]);
|
|
308
|
+
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
if (!studioOpen || watchedDataViewId === undefined || watchedDataViewId === null) {
|
|
311
|
+
setStudioFields([]);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
let cancelled = false;
|
|
315
|
+
fetchDataViewFields(api, watchedDataViewId, false)
|
|
316
|
+
.then((res) => {
|
|
317
|
+
if (!cancelled) setStudioFields(res.fields ?? []);
|
|
318
|
+
})
|
|
319
|
+
.catch(() => {
|
|
320
|
+
if (!cancelled) setStudioFields([]);
|
|
321
|
+
});
|
|
322
|
+
return () => {
|
|
323
|
+
cancelled = true;
|
|
324
|
+
};
|
|
325
|
+
}, [api, studioOpen, watchedDataViewId]);
|
|
326
|
+
|
|
327
|
+
const selectedDataView = useMemo(
|
|
328
|
+
() => dataViews.find((dv) => String(dv.id) === String(watchedDataViewId)) ?? null,
|
|
329
|
+
[dataViews, watchedDataViewId],
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
const aggregatableStudioFields = useMemo(
|
|
333
|
+
() => studioFields.filter((f) => f.aggregatable || Boolean(f.keywordSubfield)),
|
|
334
|
+
[studioFields],
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
const numericStudioFields = useMemo(
|
|
338
|
+
() =>
|
|
339
|
+
studioFields.filter((f) =>
|
|
340
|
+
['long', 'integer', 'short', 'byte', 'double', 'float', 'half_float', 'scaled_float'].includes(f.type),
|
|
341
|
+
),
|
|
342
|
+
[studioFields],
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
const openNewDataViewModal = () => {
|
|
346
|
+
setEditingDataView(null);
|
|
347
|
+
setMatchedIndices([]);
|
|
348
|
+
setConnHealth(null);
|
|
349
|
+
dvForm.resetFields();
|
|
350
|
+
dvForm.setFieldsValue({
|
|
351
|
+
dataSourceKey: connections[0]?.key,
|
|
352
|
+
indexPattern: '*',
|
|
353
|
+
timeField: '@timestamp',
|
|
354
|
+
allowedRoles: [],
|
|
355
|
+
});
|
|
356
|
+
setDvModalOpen(true);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const openEditDataViewModal = (record: EsDataViewRecord) => {
|
|
360
|
+
setEditingDataView(record);
|
|
361
|
+
setMatchedIndices([]);
|
|
362
|
+
setConnHealth(null);
|
|
363
|
+
dvForm.setFieldsValue({
|
|
364
|
+
title: record.title,
|
|
365
|
+
dataSourceKey: record.dataSourceKey,
|
|
366
|
+
indexPattern: record.indexPattern,
|
|
367
|
+
timeField: record.timeField ?? '',
|
|
368
|
+
description: record.description ?? '',
|
|
369
|
+
allowedRoles: record.allowedRoles ?? [],
|
|
370
|
+
});
|
|
371
|
+
setDvModalOpen(true);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const handleBrowseIndices = async () => {
|
|
375
|
+
const dsKey = dvForm.getFieldValue('dataSourceKey');
|
|
376
|
+
const pattern = dvForm.getFieldValue('indexPattern') || '*';
|
|
377
|
+
if (!dsKey) return;
|
|
378
|
+
setLoadingIndices(true);
|
|
379
|
+
try {
|
|
380
|
+
const list = await fetchEsIndices(api, dsKey, pattern);
|
|
381
|
+
setMatchedIndices(list);
|
|
382
|
+
} catch (err) {
|
|
383
|
+
message.error(err instanceof Error ? err.message : String(err));
|
|
384
|
+
} finally {
|
|
385
|
+
setLoadingIndices(false);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const handleTestDvConnection = async () => {
|
|
390
|
+
const dsKey = dvForm.getFieldValue('dataSourceKey');
|
|
391
|
+
const pattern = dvForm.getFieldValue('indexPattern') || '*';
|
|
392
|
+
if (!dsKey) return;
|
|
393
|
+
setTestingConn(true);
|
|
394
|
+
setConnHealth(null);
|
|
395
|
+
try {
|
|
396
|
+
const res = await testEsConnection(api, dsKey, pattern);
|
|
397
|
+
setConnHealth(res);
|
|
398
|
+
message.success(t('Connection verified'));
|
|
399
|
+
} catch (err) {
|
|
400
|
+
message.error(err instanceof Error ? err.message : String(err));
|
|
401
|
+
} finally {
|
|
402
|
+
setTestingConn(false);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const handleSaveDataView = async () => {
|
|
407
|
+
try {
|
|
408
|
+
const values = await dvForm.validateFields();
|
|
409
|
+
setDvSaving(true);
|
|
410
|
+
await saveDataView(api, {
|
|
411
|
+
...(editingDataView ? { id: editingDataView.id } : {}),
|
|
412
|
+
title: values.title,
|
|
413
|
+
dataSourceKey: values.dataSourceKey,
|
|
414
|
+
indexPattern: values.indexPattern,
|
|
415
|
+
timeField: values.timeField || null,
|
|
416
|
+
description: values.description || null,
|
|
417
|
+
allowedRoles: values.allowedRoles ?? [],
|
|
418
|
+
});
|
|
419
|
+
message.success(t('Saved successfully'));
|
|
420
|
+
setDvModalOpen(false);
|
|
421
|
+
await loadAll();
|
|
422
|
+
} catch (err) {
|
|
423
|
+
if (err instanceof Error && 'message' in err) {
|
|
424
|
+
message.error(err.message);
|
|
425
|
+
}
|
|
426
|
+
} finally {
|
|
427
|
+
setDvSaving(false);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const openNewReportStudio = () => {
|
|
432
|
+
setEditingReport(null);
|
|
433
|
+
setPreviewResult(null);
|
|
434
|
+
setPreviewError(null);
|
|
435
|
+
reportForm.resetFields();
|
|
436
|
+
reportForm.setFieldsValue({
|
|
437
|
+
title: '',
|
|
438
|
+
dataViewId: dataViews[0]?.id,
|
|
439
|
+
published: true,
|
|
440
|
+
allowedRoles: [],
|
|
441
|
+
visualization: 'table',
|
|
442
|
+
query: '',
|
|
443
|
+
timePreset: 'last_24h',
|
|
444
|
+
timeFrom: '',
|
|
445
|
+
timeTo: '',
|
|
446
|
+
filters: [],
|
|
447
|
+
lockedFilters: [],
|
|
448
|
+
sort: [],
|
|
449
|
+
columns: [],
|
|
450
|
+
fieldFormats: [],
|
|
451
|
+
contextBindings: [],
|
|
452
|
+
pageSize: 20,
|
|
453
|
+
showHistogram: true,
|
|
454
|
+
allowInteractiveControls: true,
|
|
455
|
+
allowExport: true,
|
|
456
|
+
bucketType: 'date_histogram',
|
|
457
|
+
calendarInterval: 'auto',
|
|
458
|
+
topN: 10,
|
|
459
|
+
metricType: 'count',
|
|
460
|
+
stackMode: 'none',
|
|
461
|
+
comparePreviousPeriod: false,
|
|
462
|
+
});
|
|
463
|
+
setStudioPreviewSpec({
|
|
464
|
+
visualization: 'table',
|
|
465
|
+
query: '',
|
|
466
|
+
queryMode: 'kql',
|
|
467
|
+
filters: [],
|
|
468
|
+
lockedFilters: [],
|
|
469
|
+
sort: [],
|
|
470
|
+
timeRange: { preset: 'last_24h' },
|
|
471
|
+
columns: [],
|
|
472
|
+
pageSize: 20,
|
|
473
|
+
allowInteractiveControls: true,
|
|
474
|
+
allowExport: true,
|
|
475
|
+
chart: {
|
|
476
|
+
bucketType: 'date_histogram',
|
|
477
|
+
calendarInterval: 'auto',
|
|
478
|
+
topN: 10,
|
|
479
|
+
metricType: 'count',
|
|
480
|
+
showHistogram: true,
|
|
481
|
+
},
|
|
482
|
+
});
|
|
483
|
+
setStudioOpen(true);
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
const openEditReportStudio = (record: EsReportRecord) => {
|
|
487
|
+
setEditingReport(record);
|
|
488
|
+
setPreviewResult(null);
|
|
489
|
+
setPreviewError(null);
|
|
490
|
+
const spec = record.spec;
|
|
491
|
+
setStudioPreviewSpec(spec);
|
|
492
|
+
reportForm.setFieldsValue({
|
|
493
|
+
title: record.title,
|
|
494
|
+
description: record.description ?? '',
|
|
495
|
+
dataViewId: record.dataViewId,
|
|
496
|
+
published: record.published !== false,
|
|
497
|
+
allowedRoles: record.allowedRoles ?? [],
|
|
498
|
+
visualization: spec.visualization ?? 'table',
|
|
499
|
+
query: spec.query ?? '',
|
|
500
|
+
timePreset: spec.timeRange?.preset ?? 'last_24h',
|
|
501
|
+
timeFrom: spec.timeRange?.from ?? '',
|
|
502
|
+
timeTo: spec.timeRange?.to ?? '',
|
|
503
|
+
filters: (spec.filters ?? []).map((f) => ({
|
|
504
|
+
field: f.field,
|
|
505
|
+
operator: f.operator,
|
|
506
|
+
value: Array.isArray(f.value) ? f.value.join(', ') : f.value !== undefined ? String(f.value) : '',
|
|
507
|
+
valueTo: f.valueTo !== undefined ? String(f.valueTo) : '',
|
|
508
|
+
})),
|
|
509
|
+
lockedFilters: (spec.lockedFilters ?? []).map((f) => ({
|
|
510
|
+
field: f.field,
|
|
511
|
+
operator: f.operator,
|
|
512
|
+
value: Array.isArray(f.value) ? f.value.join(', ') : f.value !== undefined ? String(f.value) : '',
|
|
513
|
+
valueTo: f.valueTo !== undefined ? String(f.valueTo) : '',
|
|
514
|
+
})),
|
|
515
|
+
sort: spec.sort ?? [],
|
|
516
|
+
columns: spec.columns ?? [],
|
|
517
|
+
fieldFormats: Object.entries(spec.fieldFormats ?? {}).map(([field, format]) => ({ field, format })),
|
|
518
|
+
contextBindings: spec.contextBindings ?? [],
|
|
519
|
+
pageSize: spec.pageSize ?? 20,
|
|
520
|
+
showHistogram: spec.chart?.showHistogram !== false,
|
|
521
|
+
allowInteractiveControls: spec.allowInteractiveControls !== false,
|
|
522
|
+
allowExport: spec.allowExport !== false,
|
|
523
|
+
bucketType: spec.chart?.bucketType ?? 'date_histogram',
|
|
524
|
+
bucketField: spec.chart?.bucketField,
|
|
525
|
+
calendarInterval: spec.chart?.calendarInterval ?? 'auto',
|
|
526
|
+
topN: spec.chart?.topN ?? 10,
|
|
527
|
+
metricType: spec.chart?.metricType ?? 'count',
|
|
528
|
+
metricField: spec.chart?.metricField,
|
|
529
|
+
metricLabel: spec.chart?.metricLabel,
|
|
530
|
+
splitSeriesField: spec.chart?.splitSeriesField,
|
|
531
|
+
stackMode: spec.chart?.stackMode ?? 'none',
|
|
532
|
+
comparePreviousPeriod: spec.chart?.comparePreviousPeriod === true,
|
|
533
|
+
});
|
|
534
|
+
setStudioOpen(true);
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
const handleRunStudioPreview = async (overrides?: ReportRuntimeOverrides) => {
|
|
538
|
+
const values = reportForm.getFieldsValue(true) as ReportEditorFormValues;
|
|
539
|
+
if (values.dataViewId === undefined || values.dataViewId === null) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
setPreviewLoading(true);
|
|
543
|
+
setPreviewError(null);
|
|
544
|
+
try {
|
|
545
|
+
const spec = formValuesToSpec(values);
|
|
546
|
+
if (!overrides) {
|
|
547
|
+
setStudioPreviewSpec(spec);
|
|
548
|
+
}
|
|
549
|
+
const res = await executeReportPreview(api, values.dataViewId, spec, overrides);
|
|
550
|
+
setPreviewResult(res.result);
|
|
551
|
+
} catch (err) {
|
|
552
|
+
setPreviewError(err instanceof Error ? err.message : String(err));
|
|
553
|
+
} finally {
|
|
554
|
+
setPreviewLoading(false);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
const handleSaveReport = async () => {
|
|
559
|
+
try {
|
|
560
|
+
const values = await reportForm.validateFields();
|
|
561
|
+
setSavingReport(true);
|
|
562
|
+
const spec = formValuesToSpec(values);
|
|
563
|
+
await persistReport(api, {
|
|
564
|
+
...(editingReport ? { id: editingReport.id } : {}),
|
|
565
|
+
title: values.title,
|
|
566
|
+
description: values.description || null,
|
|
567
|
+
dataViewId: values.dataViewId,
|
|
568
|
+
published: values.published !== false,
|
|
569
|
+
allowedRoles: values.allowedRoles ?? [],
|
|
570
|
+
spec,
|
|
571
|
+
});
|
|
572
|
+
message.success(t('Saved successfully'));
|
|
573
|
+
setStudioOpen(false);
|
|
574
|
+
await loadAll();
|
|
575
|
+
} catch (err) {
|
|
576
|
+
if (err instanceof Error && 'message' in err) {
|
|
577
|
+
message.error(err.message);
|
|
578
|
+
}
|
|
579
|
+
} finally {
|
|
580
|
+
setSavingReport(false);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const reportColumns: TableColumnsType<EsReportRecord> = [
|
|
585
|
+
{
|
|
586
|
+
title: t('Title'),
|
|
587
|
+
dataIndex: 'title',
|
|
588
|
+
key: 'title',
|
|
589
|
+
render: (val: string, row) => (
|
|
590
|
+
<Space direction="vertical" size={0}>
|
|
591
|
+
<Text strong>{val}</Text>
|
|
592
|
+
{row.description && (
|
|
593
|
+
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
594
|
+
{row.description}
|
|
595
|
+
</Text>
|
|
596
|
+
)}
|
|
597
|
+
</Space>
|
|
598
|
+
),
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
title: t('Visualization'),
|
|
602
|
+
dataIndex: 'visualization',
|
|
603
|
+
key: 'visualization',
|
|
604
|
+
width: 140,
|
|
605
|
+
render: (val: string) => <Tag color="blue">{String(val).toUpperCase()}</Tag>,
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
title: t('Data View'),
|
|
609
|
+
key: 'dataView',
|
|
610
|
+
render: (_: unknown, row) =>
|
|
611
|
+
row.dataView ? `${row.dataView.title} (${row.dataView.indexPattern})` : String(row.dataViewId),
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
title: t('Allowed Roles'),
|
|
615
|
+
key: 'allowedRoles',
|
|
616
|
+
width: 180,
|
|
617
|
+
render: (_: unknown, row) =>
|
|
618
|
+
row.allowedRoles && row.allowedRoles.length > 0 ? (
|
|
619
|
+
<Space wrap size={[4, 4]}>
|
|
620
|
+
{row.allowedRoles.map((r) => (
|
|
621
|
+
<Tag key={r}>{r}</Tag>
|
|
622
|
+
))}
|
|
623
|
+
</Space>
|
|
624
|
+
) : (
|
|
625
|
+
<Text type="secondary">{t('All roles')}</Text>
|
|
626
|
+
),
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
title: t('Published'),
|
|
630
|
+
dataIndex: 'published',
|
|
631
|
+
key: 'published',
|
|
632
|
+
width: 120,
|
|
633
|
+
render: (pub: boolean) => <Tag color={pub ? 'success' : 'default'}>{pub ? t('Published') : t('Draft')}</Tag>,
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
title: '',
|
|
637
|
+
key: 'actions',
|
|
638
|
+
width: 180,
|
|
639
|
+
render: (_: unknown, row) => (
|
|
640
|
+
<Space>
|
|
641
|
+
<Button size="small" icon={<EditOutlined />} onClick={() => openEditReportStudio(row)}>
|
|
642
|
+
{t('Edit')}
|
|
643
|
+
</Button>
|
|
644
|
+
<Popconfirm
|
|
645
|
+
title={t('Confirm delete?')}
|
|
646
|
+
onConfirm={async () => {
|
|
647
|
+
await removeReport(api, row.id);
|
|
648
|
+
message.success(t('Deleted successfully'));
|
|
649
|
+
await loadAll();
|
|
650
|
+
}}
|
|
651
|
+
>
|
|
652
|
+
<Button size="small" danger icon={<DeleteOutlined />}>
|
|
653
|
+
{t('Delete')}
|
|
654
|
+
</Button>
|
|
655
|
+
</Popconfirm>
|
|
656
|
+
</Space>
|
|
657
|
+
),
|
|
658
|
+
},
|
|
659
|
+
];
|
|
660
|
+
|
|
661
|
+
const dataViewColumns: TableColumnsType<EsDataViewRecord> = [
|
|
662
|
+
{ title: t('Title'), dataIndex: 'title', key: 'title' },
|
|
663
|
+
{ title: t('Data Source (Elasticsearch)'), dataIndex: 'dataSourceKey', key: 'dataSourceKey' },
|
|
664
|
+
{
|
|
665
|
+
title: t('Index Pattern'),
|
|
666
|
+
dataIndex: 'indexPattern',
|
|
667
|
+
key: 'indexPattern',
|
|
668
|
+
render: (val: string) => <Tag>{val}</Tag>,
|
|
669
|
+
},
|
|
670
|
+
{ title: t('Time Field'), dataIndex: 'timeField', key: 'timeField', render: (v?: string | null) => v || '—' },
|
|
671
|
+
{
|
|
672
|
+
title: t('Allowed Roles'),
|
|
673
|
+
key: 'allowedRoles',
|
|
674
|
+
width: 180,
|
|
675
|
+
render: (_: unknown, row) =>
|
|
676
|
+
row.allowedRoles && row.allowedRoles.length > 0 ? (
|
|
677
|
+
<Space wrap size={[4, 4]}>
|
|
678
|
+
{row.allowedRoles.map((r) => (
|
|
679
|
+
<Tag key={r}>{r}</Tag>
|
|
680
|
+
))}
|
|
681
|
+
</Space>
|
|
682
|
+
) : (
|
|
683
|
+
<Text type="secondary">{t('All roles')}</Text>
|
|
684
|
+
),
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
title: t('Fields'),
|
|
688
|
+
key: 'fieldCount',
|
|
689
|
+
width: 110,
|
|
690
|
+
render: (_: unknown, row) => row.cachedFields?.length ?? 0,
|
|
691
|
+
},
|
|
692
|
+
{
|
|
693
|
+
title: '',
|
|
694
|
+
key: 'actions',
|
|
695
|
+
width: 260,
|
|
696
|
+
render: (_: unknown, row) => (
|
|
697
|
+
<Space>
|
|
698
|
+
<Button
|
|
699
|
+
size="small"
|
|
700
|
+
icon={<ReloadOutlined />}
|
|
701
|
+
onClick={async () => {
|
|
702
|
+
await fetchDataViewFields(api, row.id, true);
|
|
703
|
+
message.success(t('Saved successfully'));
|
|
704
|
+
await loadAll();
|
|
705
|
+
}}
|
|
706
|
+
>
|
|
707
|
+
{t('Refresh Fields')}
|
|
708
|
+
</Button>
|
|
709
|
+
<Button size="small" icon={<EditOutlined />} onClick={() => openEditDataViewModal(row)}>
|
|
710
|
+
{t('Edit')}
|
|
711
|
+
</Button>
|
|
712
|
+
<Popconfirm
|
|
713
|
+
title={t('Confirm delete?')}
|
|
714
|
+
onConfirm={async () => {
|
|
715
|
+
await removeDataView(api, row.id);
|
|
716
|
+
message.success(t('Deleted successfully'));
|
|
717
|
+
await loadAll();
|
|
718
|
+
}}
|
|
719
|
+
>
|
|
720
|
+
<Button size="small" danger icon={<DeleteOutlined />} aria-label={t('Delete')} />
|
|
721
|
+
</Popconfirm>
|
|
722
|
+
</Space>
|
|
723
|
+
),
|
|
724
|
+
},
|
|
725
|
+
];
|
|
726
|
+
|
|
727
|
+
return (
|
|
728
|
+
<Card variant="borderless">
|
|
729
|
+
<Tabs
|
|
730
|
+
items={[
|
|
731
|
+
{
|
|
732
|
+
key: 'reports',
|
|
733
|
+
label: t('Reports'),
|
|
734
|
+
children: (
|
|
735
|
+
<div>
|
|
736
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
|
|
737
|
+
<Space>
|
|
738
|
+
<Button type="primary" icon={<PlusOutlined />} onClick={openNewReportStudio}>
|
|
739
|
+
{t('New Report')}
|
|
740
|
+
</Button>
|
|
741
|
+
<Button icon={<ReloadOutlined />} onClick={loadAll}>
|
|
742
|
+
{t('Refresh')}
|
|
743
|
+
</Button>
|
|
744
|
+
</Space>
|
|
745
|
+
</div>
|
|
746
|
+
<Table<EsReportRecord>
|
|
747
|
+
rowKey="id"
|
|
748
|
+
scroll={{ x: 'max-content' }}
|
|
749
|
+
loading={loadingList}
|
|
750
|
+
columns={reportColumns}
|
|
751
|
+
dataSource={reports}
|
|
752
|
+
/>
|
|
753
|
+
</div>
|
|
754
|
+
),
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
key: 'dataViews',
|
|
758
|
+
label: t('Data Views'),
|
|
759
|
+
children: (
|
|
760
|
+
<div>
|
|
761
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
|
|
762
|
+
<Space>
|
|
763
|
+
<Button type="primary" icon={<PlusOutlined />} onClick={openNewDataViewModal}>
|
|
764
|
+
{t('New Data View')}
|
|
765
|
+
</Button>
|
|
766
|
+
<Button icon={<ReloadOutlined />} onClick={loadAll}>
|
|
767
|
+
{t('Refresh')}
|
|
768
|
+
</Button>
|
|
769
|
+
</Space>
|
|
770
|
+
</div>
|
|
771
|
+
<Table<EsDataViewRecord>
|
|
772
|
+
rowKey="id"
|
|
773
|
+
scroll={{ x: 'max-content' }}
|
|
774
|
+
loading={loadingList}
|
|
775
|
+
columns={dataViewColumns}
|
|
776
|
+
dataSource={dataViews}
|
|
777
|
+
/>
|
|
778
|
+
</div>
|
|
779
|
+
),
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
key: 'mcp',
|
|
783
|
+
label: t('MCP & AI Employee'),
|
|
784
|
+
children: (
|
|
785
|
+
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
786
|
+
<Alert
|
|
787
|
+
type="info"
|
|
788
|
+
showIcon
|
|
789
|
+
message={t('AI Employee Usage')}
|
|
790
|
+
description={t(
|
|
791
|
+
'This plugin automatically registers the elastic-report MCP server (with user context) and AI Employee tools so AI agents can inspect fields, preview Elasticsearch queries, and publish Saved Reports ready to select in blocks.',
|
|
792
|
+
)}
|
|
793
|
+
/>
|
|
794
|
+
{mcpInfo && (
|
|
795
|
+
<Descriptions bordered column={1} size="small">
|
|
796
|
+
<Descriptions.Item label={t('MCP Server Name')}>
|
|
797
|
+
<Tag color="purple">{mcpInfo.serverName}</Tag>
|
|
798
|
+
</Descriptions.Item>
|
|
799
|
+
<Descriptions.Item label={t('Dedicated MCP Endpoint')}>
|
|
800
|
+
<Space>
|
|
801
|
+
<code>{mcpInfo.endpointPath}</code>
|
|
802
|
+
<Button
|
|
803
|
+
size="small"
|
|
804
|
+
icon={<CopyOutlined />}
|
|
805
|
+
onClick={() => {
|
|
806
|
+
navigator.clipboard?.writeText(window.location.origin + mcpInfo.endpointPath);
|
|
807
|
+
message.success(t('Copied to clipboard'));
|
|
808
|
+
}}
|
|
809
|
+
>
|
|
810
|
+
{t('Copy')}
|
|
811
|
+
</Button>
|
|
812
|
+
</Space>
|
|
813
|
+
</Descriptions.Item>
|
|
814
|
+
</Descriptions>
|
|
815
|
+
)}
|
|
816
|
+
<Card size="small" title={t('Exposed MCP Tools')}>
|
|
817
|
+
<Table
|
|
818
|
+
size="small"
|
|
819
|
+
rowKey="name"
|
|
820
|
+
pagination={false}
|
|
821
|
+
dataSource={mcpInfo?.tools ?? []}
|
|
822
|
+
columns={[
|
|
823
|
+
{
|
|
824
|
+
title: 'Tool',
|
|
825
|
+
dataIndex: 'name',
|
|
826
|
+
key: 'name',
|
|
827
|
+
width: 220,
|
|
828
|
+
render: (v: string) => <code>{v}</code>,
|
|
829
|
+
},
|
|
830
|
+
{ title: t('Description'), dataIndex: 'description', key: 'description' },
|
|
831
|
+
]}
|
|
832
|
+
/>
|
|
833
|
+
</Card>
|
|
834
|
+
</Space>
|
|
835
|
+
),
|
|
836
|
+
},
|
|
837
|
+
]}
|
|
838
|
+
/>
|
|
839
|
+
|
|
840
|
+
{/* Data View Modal */}
|
|
841
|
+
<Modal
|
|
842
|
+
title={editingDataView ? t('Edit Data View') : t('New Data View')}
|
|
843
|
+
open={dvModalOpen}
|
|
844
|
+
confirmLoading={dvSaving}
|
|
845
|
+
onCancel={() => setDvModalOpen(false)}
|
|
846
|
+
onOk={handleSaveDataView}
|
|
847
|
+
width={600}
|
|
848
|
+
style={{ maxWidth: 'calc(100vw - 32px)' }}
|
|
849
|
+
centered
|
|
850
|
+
>
|
|
851
|
+
<Form form={dvForm} layout="vertical">
|
|
852
|
+
<Form.Item name="title" label={t('Title')} rules={[{ required: true }]}>
|
|
853
|
+
<Input placeholder="Application Logs" />
|
|
854
|
+
</Form.Item>
|
|
855
|
+
<Form.Item
|
|
856
|
+
name="dataSourceKey"
|
|
857
|
+
label={t('Data Source (Elasticsearch)')}
|
|
858
|
+
rules={[{ required: true }]}
|
|
859
|
+
extra={t(
|
|
860
|
+
'Configure Elasticsearch 8.x TLS, CA Fingerprint, API Key, or Bearer Token in Data Source Manager',
|
|
861
|
+
)}
|
|
862
|
+
>
|
|
863
|
+
<Select
|
|
864
|
+
onChange={() => setConnHealth(null)}
|
|
865
|
+
options={connections.map((c) => {
|
|
866
|
+
const badgeParts = [
|
|
867
|
+
c.endpointMode === 'cloud' ? 'Cloud' : 'Nodes',
|
|
868
|
+
c.authMode && c.authMode !== 'none' ? c.authMode : undefined,
|
|
869
|
+
c.tlsMode === 'caFingerprint'
|
|
870
|
+
? 'CA-FP'
|
|
871
|
+
: c.tlsMode === 'caCert'
|
|
872
|
+
? 'CA-PEM'
|
|
873
|
+
: c.tlsMode === 'skip'
|
|
874
|
+
? 'No-TLS-Verify'
|
|
875
|
+
: undefined,
|
|
876
|
+
].filter(Boolean);
|
|
877
|
+
return {
|
|
878
|
+
label: `${c.displayName} (${c.key})${badgeParts.length ? ` · [${badgeParts.join(' / ')}]` : ''}`,
|
|
879
|
+
value: c.key,
|
|
880
|
+
};
|
|
881
|
+
})}
|
|
882
|
+
/>
|
|
883
|
+
</Form.Item>
|
|
884
|
+
<div style={{ marginBottom: 12, display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
|
|
885
|
+
<Button size="small" loading={testingConn} onClick={handleTestDvConnection}>
|
|
886
|
+
{t('Test Connection')}
|
|
887
|
+
</Button>
|
|
888
|
+
{connHealth?.ok && (
|
|
889
|
+
<Tag color="success">
|
|
890
|
+
{t('Connection verified')}
|
|
891
|
+
{connHealth.clusterName ? `: ${connHealth.clusterName}` : ''}
|
|
892
|
+
{connHealth.version ? ` (v${connHealth.version})` : ''}
|
|
893
|
+
{connHealth.limitedPrivileges ? ` · ${t('Index-scoped role')}` : ''}
|
|
894
|
+
</Tag>
|
|
895
|
+
)}
|
|
896
|
+
</div>
|
|
897
|
+
<Form.Item name="indexPattern" label={t('Index Pattern')} rules={[{ required: true }]}>
|
|
898
|
+
<Space.Compact style={{ width: '100%' }}>
|
|
899
|
+
<Input placeholder="logs-*" />
|
|
900
|
+
<Button loading={loadingIndices} icon={<EyeOutlined />} onClick={handleBrowseIndices}>
|
|
901
|
+
{t('Browse Indices')}
|
|
902
|
+
</Button>
|
|
903
|
+
</Space.Compact>
|
|
904
|
+
</Form.Item>
|
|
905
|
+
{matchedIndices.length > 0 && (
|
|
906
|
+
<Paragraph style={{ fontSize: 12 }}>
|
|
907
|
+
<Text strong>{t('Matching Indices')}: </Text>
|
|
908
|
+
{matchedIndices.slice(0, 20).map((idx) => (
|
|
909
|
+
<Tag key={idx} style={{ marginBottom: 4 }}>
|
|
910
|
+
{idx}
|
|
911
|
+
</Tag>
|
|
912
|
+
))}
|
|
913
|
+
</Paragraph>
|
|
914
|
+
)}
|
|
915
|
+
<Form.Item name="timeField" label={t('Time Field')}>
|
|
916
|
+
<Input placeholder="@timestamp" />
|
|
917
|
+
</Form.Item>
|
|
918
|
+
<Form.Item name="allowedRoles" label={t('Allowed Roles')}>
|
|
919
|
+
<Select
|
|
920
|
+
mode="tags"
|
|
921
|
+
allowClear
|
|
922
|
+
placeholder={t('Leave empty to allow all authenticated users')}
|
|
923
|
+
options={roleOptions}
|
|
924
|
+
/>
|
|
925
|
+
</Form.Item>
|
|
926
|
+
<Form.Item name="description" label={t('Description')}>
|
|
927
|
+
<Input.TextArea rows={2} />
|
|
928
|
+
</Form.Item>
|
|
929
|
+
</Form>
|
|
930
|
+
</Modal>
|
|
931
|
+
|
|
932
|
+
{/* Report Studio Drawer */}
|
|
933
|
+
<Drawer
|
|
934
|
+
title={editingReport ? t('Edit Report') : t('New Report')}
|
|
935
|
+
open={studioOpen}
|
|
936
|
+
onClose={() => setStudioOpen(false)}
|
|
937
|
+
width="min(1080px, 96vw)"
|
|
938
|
+
extra={
|
|
939
|
+
<Space>
|
|
940
|
+
<Button icon={<PlayCircleOutlined />} loading={previewLoading} onClick={() => handleRunStudioPreview()}>
|
|
941
|
+
{t('Run Preview')}
|
|
942
|
+
</Button>
|
|
943
|
+
<Button type="primary" loading={savingReport} onClick={handleSaveReport}>
|
|
944
|
+
{t('Save')}
|
|
945
|
+
</Button>
|
|
946
|
+
</Space>
|
|
947
|
+
}
|
|
948
|
+
>
|
|
949
|
+
<Form form={reportForm} layout="vertical">
|
|
950
|
+
<Row gutter={16}>
|
|
951
|
+
<Col xs={24} md={10}>
|
|
952
|
+
<Form.Item name="title" label={t('Title')} rules={[{ required: true }]}>
|
|
953
|
+
<Input placeholder="HTTP 5xx Error Logs" />
|
|
954
|
+
</Form.Item>
|
|
955
|
+
</Col>
|
|
956
|
+
<Col xs={24} md={7}>
|
|
957
|
+
<Form.Item name="dataViewId" label={t('Data View')} rules={[{ required: true }]}>
|
|
958
|
+
<Select
|
|
959
|
+
options={dataViews.map((dv) => ({
|
|
960
|
+
label: `${dv.title} (${dv.indexPattern})`,
|
|
961
|
+
value: dv.id,
|
|
962
|
+
}))}
|
|
963
|
+
/>
|
|
964
|
+
</Form.Item>
|
|
965
|
+
</Col>
|
|
966
|
+
<Col xs={24} md={7}>
|
|
967
|
+
<Form.Item name="visualization" label={t('Visualization')} rules={[{ required: true }]}>
|
|
968
|
+
<Select
|
|
969
|
+
options={[
|
|
970
|
+
{ label: t('Table (Discover)'), value: 'table' },
|
|
971
|
+
{ label: t('Bar Chart'), value: 'bar' },
|
|
972
|
+
{ label: t('Line Chart'), value: 'line' },
|
|
973
|
+
{ label: t('Area Chart'), value: 'area' },
|
|
974
|
+
{ label: t('Pie Chart'), value: 'pie' },
|
|
975
|
+
{ label: t('Metric KPI'), value: 'metric' },
|
|
976
|
+
]}
|
|
977
|
+
/>
|
|
978
|
+
</Form.Item>
|
|
979
|
+
</Col>
|
|
980
|
+
</Row>
|
|
981
|
+
|
|
982
|
+
<Row gutter={16}>
|
|
983
|
+
<Col xs={24} md={10}>
|
|
984
|
+
<Form.Item name="query" label={t('KQL / Search Query')}>
|
|
985
|
+
<ElasticKqlInput
|
|
986
|
+
placeholder={t('Search KQL, e.g. status >= 500 AND service: "api"')}
|
|
987
|
+
fields={studioFields}
|
|
988
|
+
sampleRows={previewResult?.rows}
|
|
989
|
+
style={{ width: '100%' }}
|
|
990
|
+
onInspectTopValues={
|
|
991
|
+
watchedDataViewId !== undefined && watchedDataViewId !== null
|
|
992
|
+
? (field) =>
|
|
993
|
+
fetchFieldTopValues(api, {
|
|
994
|
+
dataViewId: watchedDataViewId,
|
|
995
|
+
field,
|
|
996
|
+
size: 12,
|
|
997
|
+
})
|
|
998
|
+
: undefined
|
|
999
|
+
}
|
|
1000
|
+
onSubmit={() => {
|
|
1001
|
+
handleRunStudioPreview();
|
|
1002
|
+
}}
|
|
1003
|
+
/>
|
|
1004
|
+
</Form.Item>
|
|
1005
|
+
</Col>
|
|
1006
|
+
<Col xs={12} md={5}>
|
|
1007
|
+
<Form.Item name="timePreset" label={t('Time Field')}>
|
|
1008
|
+
<Select
|
|
1009
|
+
options={[
|
|
1010
|
+
{ label: t('Last 15 minutes'), value: 'last_15m' },
|
|
1011
|
+
{ label: t('Last 1 hour'), value: 'last_1h' },
|
|
1012
|
+
{ label: t('Last 24 hours'), value: 'last_24h' },
|
|
1013
|
+
{ label: t('Last 7 days'), value: 'last_7d' },
|
|
1014
|
+
{ label: t('Last 30 days'), value: 'last_30d' },
|
|
1015
|
+
{ label: t('Last 90 days'), value: 'last_90d' },
|
|
1016
|
+
{ label: t('All time'), value: 'all' },
|
|
1017
|
+
{ label: t('Custom range'), value: 'custom' },
|
|
1018
|
+
]}
|
|
1019
|
+
/>
|
|
1020
|
+
</Form.Item>
|
|
1021
|
+
</Col>
|
|
1022
|
+
<Col xs={12} md={6}>
|
|
1023
|
+
<Form.Item name="allowedRoles" label={t('Allowed Roles')}>
|
|
1024
|
+
<Select
|
|
1025
|
+
mode="tags"
|
|
1026
|
+
allowClear
|
|
1027
|
+
placeholder={t('Leave empty to allow all authenticated users')}
|
|
1028
|
+
options={roleOptions}
|
|
1029
|
+
/>
|
|
1030
|
+
</Form.Item>
|
|
1031
|
+
</Col>
|
|
1032
|
+
<Col xs={12} md={3}>
|
|
1033
|
+
<Form.Item name="published" label={t('Published')} valuePropName="checked">
|
|
1034
|
+
<Switch />
|
|
1035
|
+
</Form.Item>
|
|
1036
|
+
</Col>
|
|
1037
|
+
</Row>
|
|
1038
|
+
|
|
1039
|
+
{watchedTimePreset === 'custom' && (
|
|
1040
|
+
<Row gutter={16}>
|
|
1041
|
+
<Col xs={12} md={6}>
|
|
1042
|
+
<Form.Item name="timeFrom" label={t('From')}>
|
|
1043
|
+
<Input placeholder="2026-11-29T00:00:00Z / now-24h" />
|
|
1044
|
+
</Form.Item>
|
|
1045
|
+
</Col>
|
|
1046
|
+
<Col xs={12} md={6}>
|
|
1047
|
+
<Form.Item name="timeTo" label={t('To')}>
|
|
1048
|
+
<Input placeholder="2026-11-30T00:00:00Z / now" />
|
|
1049
|
+
</Form.Item>
|
|
1050
|
+
</Col>
|
|
1051
|
+
</Row>
|
|
1052
|
+
)}
|
|
1053
|
+
|
|
1054
|
+
{/* Mandatory Server-Enforced Locked Filters Builder */}
|
|
1055
|
+
<Card size="small" title={t('Locked Security Filters (Server-enforced)')} style={{ marginBottom: 12 }}>
|
|
1056
|
+
<Form.List name="lockedFilters">
|
|
1057
|
+
{(lockedList, { add, remove }) => (
|
|
1058
|
+
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1059
|
+
{lockedList.map(({ key, name }) => (
|
|
1060
|
+
<Space key={key} wrap align="baseline">
|
|
1061
|
+
<Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 190 }}>
|
|
1062
|
+
<Select
|
|
1063
|
+
showSearch
|
|
1064
|
+
placeholder={t('Field')}
|
|
1065
|
+
options={studioFields.map((f) => ({ label: `${f.name} (${f.type})`, value: f.name }))}
|
|
1066
|
+
/>
|
|
1067
|
+
</Form.Item>
|
|
1068
|
+
<Form.Item name={[name, 'operator']} style={{ marginBottom: 0, minWidth: 160 }}>
|
|
1069
|
+
<Select options={FILTER_OPERATOR_ITEMS} />
|
|
1070
|
+
</Form.Item>
|
|
1071
|
+
<Form.Item name={[name, 'value']} style={{ marginBottom: 0 }}>
|
|
1072
|
+
<Input placeholder={t('Value')} />
|
|
1073
|
+
</Form.Item>
|
|
1074
|
+
<Form.Item name={[name, 'valueTo']} style={{ marginBottom: 0 }}>
|
|
1075
|
+
<Input placeholder={t('To Value')} style={{ width: 120 }} />
|
|
1076
|
+
</Form.Item>
|
|
1077
|
+
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1078
|
+
</Space>
|
|
1079
|
+
))}
|
|
1080
|
+
<Button size="small" type="dashed" icon={<PlusOutlined />} onClick={() => add({ operator: 'eq' })}>
|
|
1081
|
+
{t('Add Locked Filter')}
|
|
1082
|
+
</Button>
|
|
1083
|
+
</Space>
|
|
1084
|
+
)}
|
|
1085
|
+
</Form.List>
|
|
1086
|
+
</Card>
|
|
1087
|
+
|
|
1088
|
+
{/* Structured Filters Builder */}
|
|
1089
|
+
<Card size="small" title={t('Add Filter')} style={{ marginBottom: 12 }}>
|
|
1090
|
+
<Form.List name="filters">
|
|
1091
|
+
{(fieldsList, { add, remove }) => (
|
|
1092
|
+
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1093
|
+
{fieldsList.map(({ key, name }) => (
|
|
1094
|
+
<Space key={key} wrap align="baseline">
|
|
1095
|
+
<Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 190 }}>
|
|
1096
|
+
<Select
|
|
1097
|
+
showSearch
|
|
1098
|
+
placeholder={t('Field')}
|
|
1099
|
+
options={studioFields.map((f) => ({ label: `${f.name} (${f.type})`, value: f.name }))}
|
|
1100
|
+
/>
|
|
1101
|
+
</Form.Item>
|
|
1102
|
+
<Form.Item name={[name, 'operator']} style={{ marginBottom: 0, minWidth: 160 }}>
|
|
1103
|
+
<Select options={FILTER_OPERATOR_ITEMS} />
|
|
1104
|
+
</Form.Item>
|
|
1105
|
+
<Form.Item name={[name, 'value']} style={{ marginBottom: 0 }}>
|
|
1106
|
+
<Input placeholder={t('Value')} />
|
|
1107
|
+
</Form.Item>
|
|
1108
|
+
<Form.Item name={[name, 'valueTo']} style={{ marginBottom: 0 }}>
|
|
1109
|
+
<Input placeholder={t('To Value')} style={{ width: 120 }} />
|
|
1110
|
+
</Form.Item>
|
|
1111
|
+
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1112
|
+
</Space>
|
|
1113
|
+
))}
|
|
1114
|
+
<Button size="small" type="dashed" icon={<PlusOutlined />} onClick={() => add({ operator: 'eq' })}>
|
|
1115
|
+
{t('Add Filter')}
|
|
1116
|
+
</Button>
|
|
1117
|
+
</Space>
|
|
1118
|
+
)}
|
|
1119
|
+
</Form.List>
|
|
1120
|
+
</Card>
|
|
1121
|
+
|
|
1122
|
+
{watchedVisualization === 'table' ? (
|
|
1123
|
+
<Row gutter={16}>
|
|
1124
|
+
<Col xs={24} md={12}>
|
|
1125
|
+
<Form.Item name="columns" label={t('Columns')}>
|
|
1126
|
+
<Select
|
|
1127
|
+
mode="multiple"
|
|
1128
|
+
allowClear
|
|
1129
|
+
placeholder={t('Auto-detect columns from documents')}
|
|
1130
|
+
options={studioFields.filter((f) => !f.isSubfield).map((f) => ({ label: f.name, value: f.name }))}
|
|
1131
|
+
/>
|
|
1132
|
+
</Form.Item>
|
|
1133
|
+
<Card size="small" title={t('Sort')} style={{ marginBottom: 12 }}>
|
|
1134
|
+
<Form.List name="sort">
|
|
1135
|
+
{(sortList, { add, remove }) => (
|
|
1136
|
+
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1137
|
+
{sortList.map(({ key, name }) => (
|
|
1138
|
+
<Space key={key} align="baseline">
|
|
1139
|
+
<Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 200 }}>
|
|
1140
|
+
<Select
|
|
1141
|
+
showSearch
|
|
1142
|
+
placeholder={t('Field')}
|
|
1143
|
+
options={aggregatableStudioFields.map((f) => ({
|
|
1144
|
+
label: f.keywordSubfield ? `${f.name} (${f.keywordSubfield})` : f.name,
|
|
1145
|
+
value: f.keywordSubfield || f.name,
|
|
1146
|
+
}))}
|
|
1147
|
+
/>
|
|
1148
|
+
</Form.Item>
|
|
1149
|
+
<Form.Item name={[name, 'order']} style={{ marginBottom: 0, minWidth: 130 }}>
|
|
1150
|
+
<Select
|
|
1151
|
+
options={[
|
|
1152
|
+
{ label: t('Descending'), value: 'desc' },
|
|
1153
|
+
{ label: t('Ascending'), value: 'asc' },
|
|
1154
|
+
]}
|
|
1155
|
+
/>
|
|
1156
|
+
</Form.Item>
|
|
1157
|
+
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1158
|
+
</Space>
|
|
1159
|
+
))}
|
|
1160
|
+
<Button
|
|
1161
|
+
size="small"
|
|
1162
|
+
type="dashed"
|
|
1163
|
+
icon={<PlusOutlined />}
|
|
1164
|
+
onClick={() => add({ order: 'desc' })}
|
|
1165
|
+
>
|
|
1166
|
+
{t('Add Sort')}
|
|
1167
|
+
</Button>
|
|
1168
|
+
</Space>
|
|
1169
|
+
)}
|
|
1170
|
+
</Form.List>
|
|
1171
|
+
</Card>
|
|
1172
|
+
</Col>
|
|
1173
|
+
<Col xs={24} md={12}>
|
|
1174
|
+
<Row gutter={12}>
|
|
1175
|
+
<Col span={6}>
|
|
1176
|
+
<Form.Item name="pageSize" label={t('Page Size')}>
|
|
1177
|
+
<InputNumber min={5} max={200} style={{ width: '100%' }} />
|
|
1178
|
+
</Form.Item>
|
|
1179
|
+
</Col>
|
|
1180
|
+
<Col span={6}>
|
|
1181
|
+
<Form.Item
|
|
1182
|
+
name="showHistogram"
|
|
1183
|
+
label={t('Show time histogram above table')}
|
|
1184
|
+
valuePropName="checked"
|
|
1185
|
+
>
|
|
1186
|
+
<Switch />
|
|
1187
|
+
</Form.Item>
|
|
1188
|
+
</Col>
|
|
1189
|
+
<Col span={6}>
|
|
1190
|
+
<Form.Item
|
|
1191
|
+
name="allowInteractiveControls"
|
|
1192
|
+
label={t('Allow interactive search/filter on block')}
|
|
1193
|
+
valuePropName="checked"
|
|
1194
|
+
>
|
|
1195
|
+
<Switch />
|
|
1196
|
+
</Form.Item>
|
|
1197
|
+
</Col>
|
|
1198
|
+
<Col span={6}>
|
|
1199
|
+
<Form.Item name="allowExport" label={t('Allow data export on block')} valuePropName="checked">
|
|
1200
|
+
<Switch />
|
|
1201
|
+
</Form.Item>
|
|
1202
|
+
</Col>
|
|
1203
|
+
</Row>
|
|
1204
|
+
<Card size="small" title={t('Field Formats')} style={{ marginBottom: 12 }}>
|
|
1205
|
+
<Form.List name="fieldFormats">
|
|
1206
|
+
{(fmtList, { add, remove }) => (
|
|
1207
|
+
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1208
|
+
{fmtList.map(({ key, name }) => (
|
|
1209
|
+
<Space key={key} align="baseline">
|
|
1210
|
+
<Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 170 }}>
|
|
1211
|
+
<Select
|
|
1212
|
+
showSearch
|
|
1213
|
+
placeholder={t('Field')}
|
|
1214
|
+
options={studioFields
|
|
1215
|
+
.filter((f) => !f.isSubfield)
|
|
1216
|
+
.map((f) => ({ label: f.name, value: f.name }))}
|
|
1217
|
+
/>
|
|
1218
|
+
</Form.Item>
|
|
1219
|
+
<Form.Item name={[name, 'format']} style={{ marginBottom: 0, minWidth: 160 }}>
|
|
1220
|
+
<Select
|
|
1221
|
+
options={[
|
|
1222
|
+
{ label: t('Duration (ms)'), value: 'duration_ms' },
|
|
1223
|
+
{ label: t('Bytes'), value: 'bytes' },
|
|
1224
|
+
{ label: t('Percent (%)'), value: 'percent' },
|
|
1225
|
+
{ label: t('Number'), value: 'number' },
|
|
1226
|
+
{ label: t('Status Badge'), value: 'status_badge' },
|
|
1227
|
+
{ label: t('URL Link'), value: 'url' },
|
|
1228
|
+
]}
|
|
1229
|
+
/>
|
|
1230
|
+
</Form.Item>
|
|
1231
|
+
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1232
|
+
</Space>
|
|
1233
|
+
))}
|
|
1234
|
+
<Button
|
|
1235
|
+
size="small"
|
|
1236
|
+
type="dashed"
|
|
1237
|
+
icon={<PlusOutlined />}
|
|
1238
|
+
onClick={() => add({ format: 'status_badge' })}
|
|
1239
|
+
>
|
|
1240
|
+
{t('Add Field Format')}
|
|
1241
|
+
</Button>
|
|
1242
|
+
</Space>
|
|
1243
|
+
)}
|
|
1244
|
+
</Form.List>
|
|
1245
|
+
</Card>
|
|
1246
|
+
<Form.Item name="description" label={t('Description')}>
|
|
1247
|
+
<Input.TextArea rows={2} />
|
|
1248
|
+
</Form.Item>
|
|
1249
|
+
</Col>
|
|
1250
|
+
</Row>
|
|
1251
|
+
) : (
|
|
1252
|
+
<Card size="small" style={{ marginBottom: 12 }}>
|
|
1253
|
+
<Row gutter={16}>
|
|
1254
|
+
{watchedVisualization !== 'metric' && (
|
|
1255
|
+
<>
|
|
1256
|
+
<Col xs={12} md={6}>
|
|
1257
|
+
<Form.Item name="bucketType" label={t('Bucket Type')}>
|
|
1258
|
+
<Select
|
|
1259
|
+
options={[
|
|
1260
|
+
{ label: t('Date Histogram'), value: 'date_histogram' },
|
|
1261
|
+
{ label: t('Top Terms'), value: 'terms' },
|
|
1262
|
+
]}
|
|
1263
|
+
/>
|
|
1264
|
+
</Form.Item>
|
|
1265
|
+
</Col>
|
|
1266
|
+
<Col xs={12} md={6}>
|
|
1267
|
+
<Form.Item name="bucketField" label={t('Bucket Field')}>
|
|
1268
|
+
<Select
|
|
1269
|
+
showSearch
|
|
1270
|
+
allowClear
|
|
1271
|
+
options={aggregatableStudioFields.map((f) => ({
|
|
1272
|
+
label: f.keywordSubfield ? `${f.name} → ${f.keywordSubfield}` : f.name,
|
|
1273
|
+
value: f.keywordSubfield || f.name,
|
|
1274
|
+
}))}
|
|
1275
|
+
/>
|
|
1276
|
+
</Form.Item>
|
|
1277
|
+
</Col>
|
|
1278
|
+
{watchedBucketType === 'date_histogram' ? (
|
|
1279
|
+
<Col xs={12} md={4}>
|
|
1280
|
+
<Form.Item name="calendarInterval" label={t('Interval')}>
|
|
1281
|
+
<Select
|
|
1282
|
+
options={[
|
|
1283
|
+
{ label: 'Auto', value: 'auto' },
|
|
1284
|
+
{ label: '1m', value: '1m' },
|
|
1285
|
+
{ label: '5m', value: '5m' },
|
|
1286
|
+
{ label: '15m', value: '15m' },
|
|
1287
|
+
{ label: '1h', value: '1h' },
|
|
1288
|
+
{ label: '1d', value: '1d' },
|
|
1289
|
+
{ label: '1w', value: '1w' },
|
|
1290
|
+
{ label: '1M', value: '1M' },
|
|
1291
|
+
]}
|
|
1292
|
+
/>
|
|
1293
|
+
</Form.Item>
|
|
1294
|
+
</Col>
|
|
1295
|
+
) : (
|
|
1296
|
+
<Col xs={12} md={4}>
|
|
1297
|
+
<Form.Item name="topN" label={t('Top N')}>
|
|
1298
|
+
<InputNumber min={1} max={50} style={{ width: '100%' }} />
|
|
1299
|
+
</Form.Item>
|
|
1300
|
+
</Col>
|
|
1301
|
+
)}
|
|
1302
|
+
{watchedVisualization !== 'pie' && (
|
|
1303
|
+
<>
|
|
1304
|
+
<Col xs={12} md={4}>
|
|
1305
|
+
<Form.Item name="splitSeriesField" label={t('Split Series Field')}>
|
|
1306
|
+
<Select
|
|
1307
|
+
showSearch
|
|
1308
|
+
allowClear
|
|
1309
|
+
options={aggregatableStudioFields.map((f) => ({
|
|
1310
|
+
label: f.keywordSubfield ? `${f.name} → ${f.keywordSubfield}` : f.name,
|
|
1311
|
+
value: f.keywordSubfield || f.name,
|
|
1312
|
+
}))}
|
|
1313
|
+
/>
|
|
1314
|
+
</Form.Item>
|
|
1315
|
+
</Col>
|
|
1316
|
+
<Col xs={12} md={4}>
|
|
1317
|
+
<Form.Item name="stackMode" label={t('Stack Mode')}>
|
|
1318
|
+
<Select
|
|
1319
|
+
options={[
|
|
1320
|
+
{ label: t('Grouped'), value: 'none' },
|
|
1321
|
+
{ label: t('Stacked'), value: 'stacked' },
|
|
1322
|
+
{ label: t('100% Stacked'), value: 'percent' },
|
|
1323
|
+
]}
|
|
1324
|
+
/>
|
|
1325
|
+
</Form.Item>
|
|
1326
|
+
</Col>
|
|
1327
|
+
</>
|
|
1328
|
+
)}
|
|
1329
|
+
</>
|
|
1330
|
+
)}
|
|
1331
|
+
<Col xs={12} md={4}>
|
|
1332
|
+
<Form.Item name="metricType" label={t('Metric')}>
|
|
1333
|
+
<Select
|
|
1334
|
+
options={[
|
|
1335
|
+
{ label: 'Count', value: 'count' },
|
|
1336
|
+
{ label: 'Sum', value: 'sum' },
|
|
1337
|
+
{ label: 'Average', value: 'avg' },
|
|
1338
|
+
{ label: 'Min', value: 'min' },
|
|
1339
|
+
{ label: 'Max', value: 'max' },
|
|
1340
|
+
{ label: 'P50 (Median)', value: 'p50' },
|
|
1341
|
+
{ label: 'P95', value: 'p95' },
|
|
1342
|
+
{ label: 'P99', value: 'p99' },
|
|
1343
|
+
{ label: 'Unique (Cardinality)', value: 'cardinality' },
|
|
1344
|
+
]}
|
|
1345
|
+
/>
|
|
1346
|
+
</Form.Item>
|
|
1347
|
+
</Col>
|
|
1348
|
+
{watchedMetricType !== 'count' && (
|
|
1349
|
+
<Col xs={12} md={4}>
|
|
1350
|
+
<Form.Item name="metricField" label={t('Metric Field')}>
|
|
1351
|
+
<Select
|
|
1352
|
+
showSearch
|
|
1353
|
+
options={(watchedMetricType === 'cardinality'
|
|
1354
|
+
? aggregatableStudioFields
|
|
1355
|
+
: numericStudioFields.length > 0
|
|
1356
|
+
? numericStudioFields
|
|
1357
|
+
: aggregatableStudioFields
|
|
1358
|
+
).map((f) => ({
|
|
1359
|
+
label: f.name,
|
|
1360
|
+
value: f.keywordSubfield || f.name,
|
|
1361
|
+
}))}
|
|
1362
|
+
/>
|
|
1363
|
+
</Form.Item>
|
|
1364
|
+
</Col>
|
|
1365
|
+
)}
|
|
1366
|
+
<Col xs={12} md={6}>
|
|
1367
|
+
<Form.Item name="metricLabel" label={t('Metric Label')}>
|
|
1368
|
+
<Input placeholder="Requests / Latency (ms)" />
|
|
1369
|
+
</Form.Item>
|
|
1370
|
+
</Col>
|
|
1371
|
+
{watchedVisualization === 'metric' && (
|
|
1372
|
+
<Col xs={12} md={5}>
|
|
1373
|
+
<Form.Item
|
|
1374
|
+
name="comparePreviousPeriod"
|
|
1375
|
+
label={t('Compare previous period')}
|
|
1376
|
+
valuePropName="checked"
|
|
1377
|
+
>
|
|
1378
|
+
<Switch />
|
|
1379
|
+
</Form.Item>
|
|
1380
|
+
</Col>
|
|
1381
|
+
)}
|
|
1382
|
+
<Col xs={12} md={5}>
|
|
1383
|
+
<Form.Item
|
|
1384
|
+
name="allowInteractiveControls"
|
|
1385
|
+
label={t('Allow interactive search/filter on block')}
|
|
1386
|
+
valuePropName="checked"
|
|
1387
|
+
>
|
|
1388
|
+
<Switch />
|
|
1389
|
+
</Form.Item>
|
|
1390
|
+
</Col>
|
|
1391
|
+
</Row>
|
|
1392
|
+
</Card>
|
|
1393
|
+
)}
|
|
1394
|
+
|
|
1395
|
+
<Card size="small" title={t('Record Context Bindings')} style={{ marginBottom: 12 }}>
|
|
1396
|
+
<Form.List name="contextBindings">
|
|
1397
|
+
{(ctxList, { add, remove }) => (
|
|
1398
|
+
<Space direction="vertical" style={{ width: '100%' }}>
|
|
1399
|
+
{ctxList.map(({ key, name }) => (
|
|
1400
|
+
<Space key={key} wrap align="baseline">
|
|
1401
|
+
<Form.Item name={[name, 'esField']} style={{ marginBottom: 0, minWidth: 200 }}>
|
|
1402
|
+
<Select
|
|
1403
|
+
showSearch
|
|
1404
|
+
placeholder={t('Field')}
|
|
1405
|
+
options={studioFields.map((f) => ({ label: `${f.name} (${f.type})`, value: f.name }))}
|
|
1406
|
+
/>
|
|
1407
|
+
</Form.Item>
|
|
1408
|
+
<Form.Item name={[name, 'recordFieldPath']} style={{ marginBottom: 0, minWidth: 220 }}>
|
|
1409
|
+
<Input placeholder={t('Record Field Path')} />
|
|
1410
|
+
</Form.Item>
|
|
1411
|
+
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
|
|
1412
|
+
</Space>
|
|
1413
|
+
))}
|
|
1414
|
+
<Button size="small" type="dashed" icon={<PlusOutlined />} onClick={() => add()}>
|
|
1415
|
+
{t('Add Context Binding')}
|
|
1416
|
+
</Button>
|
|
1417
|
+
</Space>
|
|
1418
|
+
)}
|
|
1419
|
+
</Form.List>
|
|
1420
|
+
</Card>
|
|
1421
|
+
</Form>
|
|
1422
|
+
|
|
1423
|
+
<Divider orientation="left">{t('Preview')}</Divider>
|
|
1424
|
+
<ElasticReportRenderer
|
|
1425
|
+
title={reportForm.getFieldValue('title') || t('Preview')}
|
|
1426
|
+
spec={studioPreviewSpec}
|
|
1427
|
+
dataView={selectedDataView}
|
|
1428
|
+
fields={studioFields}
|
|
1429
|
+
result={previewResult}
|
|
1430
|
+
loading={previewLoading}
|
|
1431
|
+
error={previewError}
|
|
1432
|
+
showToolbar={true}
|
|
1433
|
+
onExecute={(overrides) => {
|
|
1434
|
+
handleRunStudioPreview(overrides);
|
|
1435
|
+
}}
|
|
1436
|
+
onInspectTopValues={
|
|
1437
|
+
watchedDataViewId !== undefined && watchedDataViewId !== null
|
|
1438
|
+
? (field, overrides) =>
|
|
1439
|
+
fetchFieldTopValues(api, {
|
|
1440
|
+
dataViewId: watchedDataViewId,
|
|
1441
|
+
field,
|
|
1442
|
+
size: 8,
|
|
1443
|
+
overrides,
|
|
1444
|
+
})
|
|
1445
|
+
: undefined
|
|
1446
|
+
}
|
|
1447
|
+
/>
|
|
1448
|
+
</Drawer>
|
|
1449
|
+
</Card>
|
|
1450
|
+
);
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
export default ElasticReportManager;
|