plugin-elastic-report 0.1.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/ai/skills/elastic-report/SKILLS.md +5 -3
  2. package/dist/client/357.0dd385384cab5dbf.js +10 -0
  3. package/dist/client/index.js +1 -1
  4. package/dist/client-v2/851.142c93fc6d666b28.js +10 -0
  5. package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
  6. package/dist/client-v2/877.f4095a3dbcadf98f.js +10 -0
  7. package/dist/client-v2/index.js +1 -1
  8. package/dist/externalVersion.js +3 -2
  9. package/dist/locale/en-US.json +100 -1
  10. package/dist/locale/vi-VN.json +100 -1
  11. package/dist/locale/zh-CN.json +100 -1
  12. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
  13. package/dist/server/acl-guard.js +97 -25
  14. package/dist/server/collections/es-report-data-views.js +6 -0
  15. package/dist/server/collections/es-reports.js +6 -0
  16. package/dist/server/mcp/ElasticReportToolCatalog.js +232 -10
  17. package/dist/server/plugin.js +153 -19
  18. package/dist/server/services/ElasticReportService.js +125 -11
  19. package/dist/server/services/ElasticsearchConnectionService.js +274 -34
  20. package/dist/server/services/ReportExportService.js +243 -0
  21. package/dist/server/services/ReportQueryCompiler.js +532 -91
  22. package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
  23. package/dist/shared/constants.js +17 -2
  24. package/package.json +3 -2
  25. package/src/client/index.tsx +16 -1
  26. package/src/client/workflow-instructions.tsx +44 -0
  27. package/src/client-v2/__tests__/elastic-report.test.tsx +519 -39
  28. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
  29. package/src/client-v2/api.ts +96 -0
  30. package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
  31. package/src/client-v2/components/ElasticBasicCharts.tsx +345 -92
  32. package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
  33. package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
  34. package/src/client-v2/components/ElasticReportBlock.tsx +157 -11
  35. package/src/client-v2/components/ElasticReportRenderer.tsx +621 -71
  36. package/src/client-v2/components/ReportSelect.tsx +39 -26
  37. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
  38. package/src/client-v2/models/ElasticReportBlockModel.tsx +36 -3
  39. package/src/client-v2/pages/ElasticReportManager.tsx +432 -26
  40. package/src/client-v2/plugin.tsx +20 -0
  41. package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
  42. package/src/client-v2/workflow/instructions.tsx +149 -0
  43. package/src/locale/en-US.json +100 -1
  44. package/src/locale/vi-VN.json +100 -1
  45. package/src/locale/zh-CN.json +100 -1
  46. package/src/server/__tests__/query-compiler.test.ts +390 -1
  47. package/src/server/__tests__/report-mcp-acl.integration.test.ts +271 -3
  48. package/src/server/acl-guard.ts +119 -28
  49. package/src/server/collections/es-report-data-views.ts +6 -0
  50. package/src/server/collections/es-reports.ts +6 -0
  51. package/src/server/mcp/ElasticReportToolCatalog.ts +255 -9
  52. package/src/server/plugin.ts +189 -21
  53. package/src/server/services/ElasticReportService.ts +165 -5
  54. package/src/server/services/ElasticsearchConnectionService.ts +375 -48
  55. package/src/server/services/ReportExportService.ts +282 -0
  56. package/src/server/services/ReportQueryCompiler.ts +629 -94
  57. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
  58. package/src/shared/constants.ts +7 -0
  59. package/src/shared/types.ts +98 -1
  60. package/dist/client-v2/851.488fdbf5bc5b6a36.js +0 -10
@@ -45,63 +45,84 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
45
45
  import type {
46
46
  BucketAggType,
47
47
  CalendarIntervalOption,
48
+ ChartStackMode,
49
+ EsConnectionHealthResult,
48
50
  EsConnectionSummary,
49
51
  EsDataViewRecord,
50
52
  EsFieldCapability,
51
53
  EsReportRecord,
54
+ FieldFormatType,
52
55
  FilterOperator,
53
56
  ID,
54
57
  MetricAggType,
58
+ RecordContextBinding,
55
59
  ReportExecutionResult,
56
60
  ReportFilterItem,
57
61
  ReportRuntimeOverrides,
58
62
  ReportSortItem,
59
63
  ReportSpec,
60
64
  ReportVisualizationType,
65
+ RoleSummary,
61
66
  TimeRangePreset,
62
67
  } from '../../shared/types';
63
68
  import {
64
69
  executeReportPreview,
65
70
  fetchAllReports,
71
+ fetchAvailableRoles,
66
72
  fetchDataViewFields,
67
73
  fetchDataViews,
68
74
  fetchEsConnections,
69
75
  fetchEsIndices,
76
+ fetchFieldTopValues,
70
77
  fetchMcpInfo,
71
78
  persistReport,
72
79
  removeDataView,
73
80
  removeReport,
74
81
  saveDataView,
82
+ testEsConnection,
75
83
  type ApiClientLike,
76
84
  type McpInfoPayload,
77
85
  } from '../api';
86
+ import { ElasticKqlInput } from '../components/ElasticKqlInput';
78
87
  import { ElasticReportRenderer } from '../components/ElasticReportRenderer';
79
88
  import { useT } from '../locale';
80
89
 
81
90
  const { Paragraph, Text } = Typography;
82
91
 
92
+ interface FilterFormRow {
93
+ field: string;
94
+ operator: FilterOperator;
95
+ value?: string;
96
+ valueTo?: string;
97
+ }
98
+
83
99
  interface ReportEditorFormValues {
84
100
  title: string;
85
101
  description?: string;
86
102
  dataViewId: ID;
87
103
  published: boolean;
104
+ allowedRoles?: string[];
88
105
  visualization: ReportVisualizationType;
89
106
  query?: string;
90
107
  timePreset: TimeRangePreset;
91
- filters?: Array<{
92
- field: string;
93
- operator: FilterOperator;
94
- value?: string;
95
- valueTo?: string;
96
- }>;
108
+ timeFrom?: string;
109
+ timeTo?: string;
110
+ filters?: FilterFormRow[];
111
+ lockedFilters?: FilterFormRow[];
97
112
  sort?: Array<{
98
113
  field: string;
99
114
  order: 'asc' | 'desc';
100
115
  }>;
101
116
  columns?: string[];
117
+ fieldFormats?: Array<{
118
+ field: string;
119
+ format: FieldFormatType;
120
+ }>;
121
+ contextBindings?: RecordContextBinding[];
102
122
  pageSize: number;
103
123
  showHistogram: boolean;
104
124
  allowInteractiveControls: boolean;
125
+ allowExport: boolean;
105
126
  bucketType: BucketAggType;
106
127
  bucketField?: string;
107
128
  calendarInterval: CalendarIntervalOption;
@@ -109,6 +130,9 @@ interface ReportEditorFormValues {
109
130
  metricType: MetricAggType;
110
131
  metricField?: string;
111
132
  metricLabel?: string;
133
+ splitSeriesField?: string;
134
+ stackMode?: ChartStackMode;
135
+ comparePreviousPeriod?: boolean;
112
136
  }
113
137
 
114
138
  interface DataViewFormValues {
@@ -117,6 +141,7 @@ interface DataViewFormValues {
117
141
  indexPattern: string;
118
142
  timeField?: string;
119
143
  description?: string;
144
+ allowedRoles?: string[];
120
145
  }
121
146
 
122
147
  const FILTER_OPERATOR_ITEMS: Array<{ label: string; value: FilterOperator }> = [
@@ -134,17 +159,22 @@ const FILTER_OPERATOR_ITEMS: Array<{ label: string; value: FilterOperator }> = [
134
159
  { label: 'does not exist', value: 'not_exists' },
135
160
  ];
136
161
 
137
- function formValuesToSpec(values: ReportEditorFormValues): ReportSpec {
138
- const filters: ReportFilterItem[] = (values.filters ?? [])
162
+ function mapFilterRows(rows: FilterFormRow[] | undefined, prefix: string): ReportFilterItem[] {
163
+ return (rows ?? [])
139
164
  .filter((f) => Boolean(f?.field))
140
165
  .map((f, idx) => ({
141
- id: `flt-${idx}`,
166
+ id: `${prefix}-${idx}`,
142
167
  field: f.field,
143
168
  operator: f.operator || 'eq',
144
169
  ...(f.value !== undefined && f.value !== '' ? { value: f.value } : {}),
145
170
  ...(f.valueTo !== undefined && f.valueTo !== '' ? { valueTo: f.valueTo } : {}),
146
171
  enabled: true,
147
172
  }));
173
+ }
174
+
175
+ function formValuesToSpec(values: ReportEditorFormValues): ReportSpec {
176
+ const filters = mapFilterRows(values.filters, 'flt');
177
+ const lockedFilters = mapFilterRows(values.lockedFilters, 'locked');
148
178
 
149
179
  const sort: ReportSortItem[] = (values.sort ?? [])
150
180
  .filter((s) => Boolean(s?.field))
@@ -153,16 +183,40 @@ function formValuesToSpec(values: ReportEditorFormValues): ReportSpec {
153
183
  order: s.order === 'asc' ? 'asc' : 'desc',
154
184
  }));
155
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
+
156
206
  return {
157
207
  visualization: values.visualization || 'table',
158
208
  query: values.query?.trim() ?? '',
159
209
  queryMode: 'kql',
160
210
  filters,
211
+ lockedFilters,
161
212
  sort,
162
- timeRange: { preset: values.timePreset || 'last_24h' },
213
+ timeRange,
163
214
  columns: values.columns ?? [],
215
+ ...(Object.keys(fieldFormatsMap).length > 0 ? { fieldFormats: fieldFormatsMap } : {}),
216
+ ...(contextBindings.length > 0 ? { contextBindings } : {}),
164
217
  pageSize: values.pageSize || 20,
165
218
  allowInteractiveControls: values.allowInteractiveControls !== false,
219
+ allowExport: values.allowExport !== false,
166
220
  chart: {
167
221
  bucketType: values.bucketType || 'date_histogram',
168
222
  ...(values.bucketField ? { bucketField: values.bucketField } : {}),
@@ -172,6 +226,9 @@ function formValuesToSpec(values: ReportEditorFormValues): ReportSpec {
172
226
  ...(values.metricField ? { metricField: values.metricField } : {}),
173
227
  ...(values.metricLabel ? { metricLabel: values.metricLabel } : {}),
174
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 } : {}),
175
232
  },
176
233
  };
177
234
  }
@@ -183,6 +240,7 @@ export const ElasticReportManager: React.FC = () => {
183
240
  const { message } = App.useApp();
184
241
 
185
242
  const [connections, setConnections] = useState<EsConnectionSummary[]>([]);
243
+ const [roles, setRoles] = useState<RoleSummary[]>([]);
186
244
  const [dataViews, setDataViews] = useState<EsDataViewRecord[]>([]);
187
245
  const [reports, setReports] = useState<EsReportRecord[]>([]);
188
246
  const [mcpInfo, setMcpInfo] = useState<McpInfoPayload | null>(null);
@@ -194,6 +252,8 @@ export const ElasticReportManager: React.FC = () => {
194
252
  const [dvSaving, setDvSaving] = useState(false);
195
253
  const [matchedIndices, setMatchedIndices] = useState<string[]>([]);
196
254
  const [loadingIndices, setLoadingIndices] = useState(false);
255
+ const [testingConn, setTestingConn] = useState(false);
256
+ const [connHealth, setConnHealth] = useState<EsConnectionHealthResult | null>(null);
197
257
  const [dvForm] = Form.useForm<DataViewFormValues>();
198
258
 
199
259
  // Report Studio drawer state
@@ -209,19 +269,31 @@ export const ElasticReportManager: React.FC = () => {
209
269
 
210
270
  const watchedVisualization = Form.useWatch('visualization', reportForm) ?? 'table';
211
271
  const watchedDataViewId = Form.useWatch('dataViewId', reportForm);
272
+ const watchedTimePreset = Form.useWatch('timePreset', reportForm) ?? 'last_24h';
212
273
  const watchedBucketType = Form.useWatch('bucketType', reportForm) ?? 'date_histogram';
213
274
  const watchedMetricType = Form.useWatch('metricType', reportForm) ?? 'count';
214
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
+
215
285
  const loadAll = useCallback(async () => {
216
286
  setLoadingList(true);
217
287
  try {
218
- const [connList, dvList, reportList, mcpData] = await Promise.all([
288
+ const [connList, roleList, dvList, reportList, mcpData] = await Promise.all([
219
289
  fetchEsConnections(api).catch(() => []),
290
+ fetchAvailableRoles(api).catch(() => []),
220
291
  fetchDataViews(api).catch(() => []),
221
292
  fetchAllReports(api).catch(() => []),
222
293
  fetchMcpInfo(api).catch(() => null),
223
294
  ]);
224
295
  setConnections(connList);
296
+ setRoles(roleList);
225
297
  setDataViews(dvList);
226
298
  setReports(reportList);
227
299
  setMcpInfo(mcpData);
@@ -273,11 +345,13 @@ export const ElasticReportManager: React.FC = () => {
273
345
  const openNewDataViewModal = () => {
274
346
  setEditingDataView(null);
275
347
  setMatchedIndices([]);
348
+ setConnHealth(null);
276
349
  dvForm.resetFields();
277
350
  dvForm.setFieldsValue({
278
351
  dataSourceKey: connections[0]?.key,
279
352
  indexPattern: '*',
280
353
  timeField: '@timestamp',
354
+ allowedRoles: [],
281
355
  });
282
356
  setDvModalOpen(true);
283
357
  };
@@ -285,12 +359,14 @@ export const ElasticReportManager: React.FC = () => {
285
359
  const openEditDataViewModal = (record: EsDataViewRecord) => {
286
360
  setEditingDataView(record);
287
361
  setMatchedIndices([]);
362
+ setConnHealth(null);
288
363
  dvForm.setFieldsValue({
289
364
  title: record.title,
290
365
  dataSourceKey: record.dataSourceKey,
291
366
  indexPattern: record.indexPattern,
292
367
  timeField: record.timeField ?? '',
293
368
  description: record.description ?? '',
369
+ allowedRoles: record.allowedRoles ?? [],
294
370
  });
295
371
  setDvModalOpen(true);
296
372
  };
@@ -310,6 +386,23 @@ export const ElasticReportManager: React.FC = () => {
310
386
  }
311
387
  };
312
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
+
313
406
  const handleSaveDataView = async () => {
314
407
  try {
315
408
  const values = await dvForm.validateFields();
@@ -321,6 +414,7 @@ export const ElasticReportManager: React.FC = () => {
321
414
  indexPattern: values.indexPattern,
322
415
  timeField: values.timeField || null,
323
416
  description: values.description || null,
417
+ allowedRoles: values.allowedRoles ?? [],
324
418
  });
325
419
  message.success(t('Saved successfully'));
326
420
  setDvModalOpen(false);
@@ -343,30 +437,41 @@ export const ElasticReportManager: React.FC = () => {
343
437
  title: '',
344
438
  dataViewId: dataViews[0]?.id,
345
439
  published: true,
440
+ allowedRoles: [],
346
441
  visualization: 'table',
347
442
  query: '',
348
443
  timePreset: 'last_24h',
444
+ timeFrom: '',
445
+ timeTo: '',
349
446
  filters: [],
447
+ lockedFilters: [],
350
448
  sort: [],
351
449
  columns: [],
450
+ fieldFormats: [],
451
+ contextBindings: [],
352
452
  pageSize: 20,
353
453
  showHistogram: true,
354
454
  allowInteractiveControls: true,
455
+ allowExport: true,
355
456
  bucketType: 'date_histogram',
356
457
  calendarInterval: 'auto',
357
458
  topN: 10,
358
459
  metricType: 'count',
460
+ stackMode: 'none',
461
+ comparePreviousPeriod: false,
359
462
  });
360
463
  setStudioPreviewSpec({
361
464
  visualization: 'table',
362
465
  query: '',
363
466
  queryMode: 'kql',
364
467
  filters: [],
468
+ lockedFilters: [],
365
469
  sort: [],
366
470
  timeRange: { preset: 'last_24h' },
367
471
  columns: [],
368
472
  pageSize: 20,
369
473
  allowInteractiveControls: true,
474
+ allowExport: true,
370
475
  chart: {
371
476
  bucketType: 'date_histogram',
372
477
  calendarInterval: 'auto',
@@ -389,20 +494,32 @@ export const ElasticReportManager: React.FC = () => {
389
494
  description: record.description ?? '',
390
495
  dataViewId: record.dataViewId,
391
496
  published: record.published !== false,
497
+ allowedRoles: record.allowedRoles ?? [],
392
498
  visualization: spec.visualization ?? 'table',
393
499
  query: spec.query ?? '',
394
500
  timePreset: spec.timeRange?.preset ?? 'last_24h',
501
+ timeFrom: spec.timeRange?.from ?? '',
502
+ timeTo: spec.timeRange?.to ?? '',
395
503
  filters: (spec.filters ?? []).map((f) => ({
396
504
  field: f.field,
397
505
  operator: f.operator,
398
506
  value: Array.isArray(f.value) ? f.value.join(', ') : f.value !== undefined ? String(f.value) : '',
399
507
  valueTo: f.valueTo !== undefined ? String(f.valueTo) : '',
400
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
+ })),
401
515
  sort: spec.sort ?? [],
402
516
  columns: spec.columns ?? [],
517
+ fieldFormats: Object.entries(spec.fieldFormats ?? {}).map(([field, format]) => ({ field, format })),
518
+ contextBindings: spec.contextBindings ?? [],
403
519
  pageSize: spec.pageSize ?? 20,
404
520
  showHistogram: spec.chart?.showHistogram !== false,
405
521
  allowInteractiveControls: spec.allowInteractiveControls !== false,
522
+ allowExport: spec.allowExport !== false,
406
523
  bucketType: spec.chart?.bucketType ?? 'date_histogram',
407
524
  bucketField: spec.chart?.bucketField,
408
525
  calendarInterval: spec.chart?.calendarInterval ?? 'auto',
@@ -410,6 +527,9 @@ export const ElasticReportManager: React.FC = () => {
410
527
  metricType: spec.chart?.metricType ?? 'count',
411
528
  metricField: spec.chart?.metricField,
412
529
  metricLabel: spec.chart?.metricLabel,
530
+ splitSeriesField: spec.chart?.splitSeriesField,
531
+ stackMode: spec.chart?.stackMode ?? 'none',
532
+ comparePreviousPeriod: spec.chart?.comparePreviousPeriod === true,
413
533
  });
414
534
  setStudioOpen(true);
415
535
  };
@@ -446,6 +566,7 @@ export const ElasticReportManager: React.FC = () => {
446
566
  description: values.description || null,
447
567
  dataViewId: values.dataViewId,
448
568
  published: values.published !== false,
569
+ allowedRoles: values.allowedRoles ?? [],
449
570
  spec,
450
571
  });
451
572
  message.success(t('Saved successfully'));
@@ -489,6 +610,21 @@ export const ElasticReportManager: React.FC = () => {
489
610
  render: (_: unknown, row) =>
490
611
  row.dataView ? `${row.dataView.title} (${row.dataView.indexPattern})` : String(row.dataViewId),
491
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
+ },
492
628
  {
493
629
  title: t('Published'),
494
630
  dataIndex: 'published',
@@ -532,6 +668,21 @@ export const ElasticReportManager: React.FC = () => {
532
668
  render: (val: string) => <Tag>{val}</Tag>,
533
669
  },
534
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
+ },
535
686
  {
536
687
  title: t('Fields'),
537
688
  key: 'fieldCount',
@@ -574,7 +725,7 @@ export const ElasticReportManager: React.FC = () => {
574
725
  ];
575
726
 
576
727
  return (
577
- <Card bordered={false}>
728
+ <Card variant="borderless">
578
729
  <Tabs
579
730
  items={[
580
731
  {
@@ -592,7 +743,13 @@ export const ElasticReportManager: React.FC = () => {
592
743
  </Button>
593
744
  </Space>
594
745
  </div>
595
- <Table<EsReportRecord> rowKey="id" loading={loadingList} columns={reportColumns} dataSource={reports} />
746
+ <Table<EsReportRecord>
747
+ rowKey="id"
748
+ scroll={{ x: 'max-content' }}
749
+ loading={loadingList}
750
+ columns={reportColumns}
751
+ dataSource={reports}
752
+ />
596
753
  </div>
597
754
  ),
598
755
  },
@@ -613,6 +770,7 @@ export const ElasticReportManager: React.FC = () => {
613
770
  </div>
614
771
  <Table<EsDataViewRecord>
615
772
  rowKey="id"
773
+ scroll={{ x: 'max-content' }}
616
774
  loading={loadingList}
617
775
  columns={dataViewColumns}
618
776
  dataSource={dataViews}
@@ -687,19 +845,55 @@ export const ElasticReportManager: React.FC = () => {
687
845
  onCancel={() => setDvModalOpen(false)}
688
846
  onOk={handleSaveDataView}
689
847
  width={600}
848
+ style={{ maxWidth: 'calc(100vw - 32px)' }}
849
+ centered
690
850
  >
691
851
  <Form form={dvForm} layout="vertical">
692
852
  <Form.Item name="title" label={t('Title')} rules={[{ required: true }]}>
693
853
  <Input placeholder="Application Logs" />
694
854
  </Form.Item>
695
- <Form.Item name="dataSourceKey" label={t('Data Source (Elasticsearch)')} rules={[{ required: true }]}>
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
+ >
696
863
  <Select
697
- options={connections.map((c) => ({
698
- label: `${c.displayName} (${c.key})`,
699
- value: c.key,
700
- }))}
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
+ })}
701
882
  />
702
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>
703
897
  <Form.Item name="indexPattern" label={t('Index Pattern')} rules={[{ required: true }]}>
704
898
  <Space.Compact style={{ width: '100%' }}>
705
899
  <Input placeholder="logs-*" />
@@ -721,6 +915,14 @@ export const ElasticReportManager: React.FC = () => {
721
915
  <Form.Item name="timeField" label={t('Time Field')}>
722
916
  <Input placeholder="@timestamp" />
723
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>
724
926
  <Form.Item name="description" label={t('Description')}>
725
927
  <Input.TextArea rows={2} />
726
928
  </Form.Item>
@@ -732,7 +934,7 @@ export const ElasticReportManager: React.FC = () => {
732
934
  title={editingReport ? t('Edit Report') : t('New Report')}
733
935
  open={studioOpen}
734
936
  onClose={() => setStudioOpen(false)}
735
- width={1080}
937
+ width="min(1080px, 96vw)"
736
938
  extra={
737
939
  <Space>
738
940
  <Button icon={<PlayCircleOutlined />} loading={previewLoading} onClick={() => handleRunStudioPreview()}>
@@ -778,9 +980,27 @@ export const ElasticReportManager: React.FC = () => {
778
980
  </Row>
779
981
 
780
982
  <Row gutter={16}>
781
- <Col xs={24} md={14}>
983
+ <Col xs={24} md={10}>
782
984
  <Form.Item name="query" label={t('KQL / Search Query')}>
783
- <Input placeholder={t('Search KQL, e.g. status >= 500 AND service: "api"')} />
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
+ />
784
1004
  </Form.Item>
785
1005
  </Col>
786
1006
  <Col xs={12} md={5}>
@@ -794,17 +1014,77 @@ export const ElasticReportManager: React.FC = () => {
794
1014
  { label: t('Last 30 days'), value: 'last_30d' },
795
1015
  { label: t('Last 90 days'), value: 'last_90d' },
796
1016
  { label: t('All time'), value: 'all' },
1017
+ { label: t('Custom range'), value: 'custom' },
797
1018
  ]}
798
1019
  />
799
1020
  </Form.Item>
800
1021
  </Col>
801
- <Col xs={12} md={5}>
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}>
802
1033
  <Form.Item name="published" label={t('Published')} valuePropName="checked">
803
1034
  <Switch />
804
1035
  </Form.Item>
805
1036
  </Col>
806
1037
  </Row>
807
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
+
808
1088
  {/* Structured Filters Builder */}
809
1089
  <Card size="small" title={t('Add Filter')} style={{ marginBottom: 12 }}>
810
1090
  <Form.List name="filters">
@@ -892,12 +1172,12 @@ export const ElasticReportManager: React.FC = () => {
892
1172
  </Col>
893
1173
  <Col xs={24} md={12}>
894
1174
  <Row gutter={12}>
895
- <Col span={8}>
1175
+ <Col span={6}>
896
1176
  <Form.Item name="pageSize" label={t('Page Size')}>
897
1177
  <InputNumber min={5} max={200} style={{ width: '100%' }} />
898
1178
  </Form.Item>
899
1179
  </Col>
900
- <Col span={8}>
1180
+ <Col span={6}>
901
1181
  <Form.Item
902
1182
  name="showHistogram"
903
1183
  label={t('Show time histogram above table')}
@@ -906,7 +1186,7 @@ export const ElasticReportManager: React.FC = () => {
906
1186
  <Switch />
907
1187
  </Form.Item>
908
1188
  </Col>
909
- <Col span={8}>
1189
+ <Col span={6}>
910
1190
  <Form.Item
911
1191
  name="allowInteractiveControls"
912
1192
  label={t('Allow interactive search/filter on block')}
@@ -915,7 +1195,54 @@ export const ElasticReportManager: React.FC = () => {
915
1195
  <Switch />
916
1196
  </Form.Item>
917
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>
918
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>
919
1246
  <Form.Item name="description" label={t('Description')}>
920
1247
  <Input.TextArea rows={2} />
921
1248
  </Form.Item>
@@ -972,6 +1299,33 @@ export const ElasticReportManager: React.FC = () => {
972
1299
  </Form.Item>
973
1300
  </Col>
974
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
+ )}
975
1329
  </>
976
1330
  )}
977
1331
  <Col xs={12} md={4}>
@@ -983,6 +1337,9 @@ export const ElasticReportManager: React.FC = () => {
983
1337
  { label: 'Average', value: 'avg' },
984
1338
  { label: 'Min', value: 'min' },
985
1339
  { label: 'Max', value: 'max' },
1340
+ { label: 'P50 (Median)', value: 'p50' },
1341
+ { label: 'P95', value: 'p95' },
1342
+ { label: 'P99', value: 'p99' },
986
1343
  { label: 'Unique (Cardinality)', value: 'cardinality' },
987
1344
  ]}
988
1345
  />
@@ -1011,7 +1368,18 @@ export const ElasticReportManager: React.FC = () => {
1011
1368
  <Input placeholder="Requests / Latency (ms)" />
1012
1369
  </Form.Item>
1013
1370
  </Col>
1014
- <Col xs={12} md={6}>
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}>
1015
1383
  <Form.Item
1016
1384
  name="allowInteractiveControls"
1017
1385
  label={t('Allow interactive search/filter on block')}
@@ -1023,6 +1391,33 @@ export const ElasticReportManager: React.FC = () => {
1023
1391
  </Row>
1024
1392
  </Card>
1025
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>
1026
1421
  </Form>
1027
1422
 
1028
1423
  <Divider orientation="left">{t('Preview')}</Divider>
@@ -1038,6 +1433,17 @@ export const ElasticReportManager: React.FC = () => {
1038
1433
  onExecute={(overrides) => {
1039
1434
  handleRunStudioPreview(overrides);
1040
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
+ }
1041
1447
  />
1042
1448
  </Drawer>
1043
1449
  </Card>