plugin-elastic-report 0.1.1 → 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/dist/ai/skills/elastic-report/SKILLS.md +52 -0
- package/dist/client/357.0dd385384cab5dbf.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
- package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
- package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +5 -3
- package/dist/locale/en-US.json +213 -99
- package/dist/locale/vi-VN.json +213 -99
- package/dist/locale/zh-CN.json +213 -99
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
- package/dist/server/acl-guard.js +97 -25
- package/dist/server/collections/es-report-data-views.js +6 -0
- package/dist/server/collections/es-reports.js +6 -0
- package/dist/server/mcp/ElasticReportToolCatalog.js +238 -14
- package/dist/server/plugin.js +156 -22
- package/dist/server/report-block-tools.js +340 -0
- package/dist/server/services/ElasticReportService.js +137 -17
- package/dist/server/services/ElasticsearchConnectionService.js +274 -34
- package/dist/server/services/ReportExportService.js +243 -0
- package/dist/server/services/ReportQueryCompiler.js +532 -91
- package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
- package/dist/shared/constants.js +26 -2
- package/package.json +3 -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 -19
- package/src/client/workflow-instructions.tsx +44 -0
- package/src/client-v2/__tests__/elastic-report.test.tsx +879 -311
- package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
- package/src/client-v2/api.ts +320 -224
- package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
- package/src/client-v2/components/ElasticBasicCharts.tsx +652 -399
- package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
- package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
- package/src/client-v2/components/ElasticReportBlock.tsx +306 -160
- package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -707
- package/src/client-v2/components/HighlightText.tsx +50 -50
- package/src/client-v2/components/ReportSelect.tsx +85 -72
- package/src/client-v2/index.tsx +14 -14
- package/src/client-v2/locale.ts +23 -23
- package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
- package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -85
- package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1047
- package/src/client-v2/plugin.tsx +107 -52
- package/src/client-v2/report-destination.tsx +126 -0
- package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
- package/src/client-v2/workflow/instructions.tsx +149 -0
- package/src/index.ts +11 -11
- package/src/locale/en-US.json +213 -99
- package/src/locale/vi-VN.json +213 -99
- package/src/locale/zh-CN.json +213 -99
- package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
- package/src/server/__tests__/query-compiler.test.ts +620 -231
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -377
- package/src/server/acl-guard.ts +194 -103
- package/src/server/collections/es-report-data-views.ts +64 -58
- package/src/server/collections/es-reports.ts +80 -74
- package/src/server/index.ts +15 -15
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
- package/src/server/mcp/ElasticReportToolCatalog.ts +667 -417
- package/src/server/plugin.ts +599 -431
- package/src/server/report-block-tools.ts +400 -0
- package/src/server/services/ElasticReportService.ts +494 -326
- package/src/server/services/ElasticsearchConnectionService.ts +728 -401
- package/src/server/services/ReportExportService.ts +282 -0
- package/src/server/services/ReportQueryCompiler.ts +1552 -1017
- package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
- package/src/shared/constants.ts +39 -29
- package/src/shared/types.ts +272 -175
- package/ai/skills/elastic-report/SKILLS.md +0 -32
- package/dist/client-v2/851.488fdbf5bc5b6a36.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,311 +1,879 @@
|
|
|
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 { cleanup, render, screen, waitFor } from '@testing-library/react';
|
|
11
|
-
import userEvent from '@testing-library/user-event';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
static
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
expect(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
expect(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
expect(screen.
|
|
310
|
-
|
|
311
|
-
|
|
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 { act, cleanup, render, screen, waitFor } from '@testing-library/react';
|
|
11
|
+
import userEvent from '@testing-library/user-event';
|
|
12
|
+
import { ConfigProvider } from 'antd';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
15
|
+
import { HIGHLIGHT_POST_TAG, HIGHLIGHT_PRE_TAG } from '../../shared/constants';
|
|
16
|
+
|
|
17
|
+
const mocks = vi.hoisted(() => {
|
|
18
|
+
const request = vi.fn();
|
|
19
|
+
const apiClient = { request };
|
|
20
|
+
const registerModelLoaders = vi.fn();
|
|
21
|
+
const registerComponents = vi.fn();
|
|
22
|
+
const addMenuItem = vi.fn();
|
|
23
|
+
const addPageTabItem = vi.fn();
|
|
24
|
+
const setPluginSettingsLink = vi.fn();
|
|
25
|
+
|
|
26
|
+
class MockBlockModel {
|
|
27
|
+
props: Record<string, unknown> = {};
|
|
28
|
+
static definedMeta: Record<string, unknown> | undefined;
|
|
29
|
+
static definedMetas: Record<string, unknown>[] = [];
|
|
30
|
+
static registeredFlows: Record<string, unknown>[] = [];
|
|
31
|
+
|
|
32
|
+
static define(meta: Record<string, unknown>) {
|
|
33
|
+
this.definedMeta = meta;
|
|
34
|
+
this.definedMetas.push(meta);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static registerFlow(flow: Record<string, unknown>) {
|
|
38
|
+
this.registeredFlows.push(flow);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setProps(next: Record<string, unknown>) {
|
|
42
|
+
this.props = { ...this.props, ...next };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class MockPlugin {
|
|
47
|
+
options: Record<string, unknown>;
|
|
48
|
+
app: Record<string, unknown>;
|
|
49
|
+
flowEngine = { registerModelLoaders, getModel: vi.fn(), flowSettings: { registerComponents } };
|
|
50
|
+
pluginSettingsManager = {
|
|
51
|
+
addMenuItem,
|
|
52
|
+
addPageTabItem,
|
|
53
|
+
setPluginSettingsLink,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
constructor(options: Record<string, unknown> = {}, app: Record<string, unknown> = {}) {
|
|
57
|
+
this.options = options;
|
|
58
|
+
this.app = app;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
t(key: string) {
|
|
62
|
+
return key;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
request,
|
|
68
|
+
apiClient,
|
|
69
|
+
registerModelLoaders,
|
|
70
|
+
registerComponents,
|
|
71
|
+
addMenuItem,
|
|
72
|
+
addPageTabItem,
|
|
73
|
+
setPluginSettingsLink,
|
|
74
|
+
MockBlockModel,
|
|
75
|
+
MockPlugin,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
vi.mock('@nocobase/client-v2', () => ({
|
|
80
|
+
BlockModel: mocks.MockBlockModel,
|
|
81
|
+
Plugin: mocks.MockPlugin,
|
|
82
|
+
Application: class {},
|
|
83
|
+
useApp: () => ({
|
|
84
|
+
apiClient: mocks.apiClient,
|
|
85
|
+
}),
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
vi.mock('@nocobase/flow-engine', () => ({
|
|
89
|
+
tExpr: (key: string) => key,
|
|
90
|
+
useFlowEngine: () => ({
|
|
91
|
+
context: {
|
|
92
|
+
t: (key: string) => key,
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
vi.mock('@nocobase/plugin-workflow/client-v2', () => ({
|
|
98
|
+
Instruction: class {},
|
|
99
|
+
NodeDefaultView: () => null,
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
import { clearDashboardScope } from '../bus/DashboardFilterBus';
|
|
103
|
+
import { ElasticBasicChart } from '../components/ElasticBasicCharts';
|
|
104
|
+
import { ElasticFilterBar } from '../components/ElasticFilterBar';
|
|
105
|
+
import { ElasticReportBlock } from '../components/ElasticReportBlock';
|
|
106
|
+
import { HighlightText } from '../components/HighlightText';
|
|
107
|
+
import { ElasticFilterBarBlockModel } from '../models/ElasticFilterBarBlockModel';
|
|
108
|
+
import { ElasticReportBlockModel } from '../models/ElasticReportBlockModel';
|
|
109
|
+
import { PluginElasticReportClient } from '../plugin';
|
|
110
|
+
import { reportDestinationContext } from '../report-destination';
|
|
111
|
+
|
|
112
|
+
function renderWithoutMotion(ui: React.ReactElement) {
|
|
113
|
+
return render(<ConfigProvider theme={{ token: { motion: false }, hashed: false }}>{ui}</ConfigProvider>);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe('plugin-elastic-report client-v2', () => {
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
mocks.request.mockReset();
|
|
119
|
+
mocks.registerModelLoaders.mockClear();
|
|
120
|
+
mocks.addMenuItem.mockClear();
|
|
121
|
+
mocks.addPageTabItem.mockClear();
|
|
122
|
+
mocks.setPluginSettingsLink.mockClear();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
afterEach(async () => {
|
|
126
|
+
await act(async () => {
|
|
127
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
128
|
+
});
|
|
129
|
+
cleanup();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('registers Report + FilterBar block loaders, settings page, and workflow instruction on load()', async () => {
|
|
133
|
+
const registerInstructionGroup = vi.fn();
|
|
134
|
+
const registerInstruction = vi.fn();
|
|
135
|
+
const mockApp = {
|
|
136
|
+
pm: {
|
|
137
|
+
get: (name: string) => (name === 'workflow' ? { registerInstructionGroup, registerInstruction } : undefined),
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
const plugin = new PluginElasticReportClient({ name: 'plugin-elastic-report' } as never, mockApp as never);
|
|
141
|
+
await plugin.load();
|
|
142
|
+
|
|
143
|
+
expect(mocks.registerComponents).toHaveBeenCalledWith({
|
|
144
|
+
ElasticReportSelect: expect.any(Function),
|
|
145
|
+
});
|
|
146
|
+
expect(mocks.registerModelLoaders).toHaveBeenCalledWith(
|
|
147
|
+
expect.objectContaining({
|
|
148
|
+
ElasticReportBlockModel: expect.objectContaining({
|
|
149
|
+
extends: 'BlockModel',
|
|
150
|
+
}),
|
|
151
|
+
ElasticFilterBarBlockModel: expect.objectContaining({
|
|
152
|
+
extends: 'BlockModel',
|
|
153
|
+
}),
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
expect(mocks.addMenuItem).toHaveBeenCalledWith(
|
|
157
|
+
expect.objectContaining({
|
|
158
|
+
key: 'elastic-report',
|
|
159
|
+
aclSnippet: 'pm.elastic-report',
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
expect(mocks.addPageTabItem).toHaveBeenCalledTimes(1);
|
|
163
|
+
expect(registerInstructionGroup).toHaveBeenCalledWith(
|
|
164
|
+
'elastic-report',
|
|
165
|
+
expect.objectContaining({ key: 'elastic-report' }),
|
|
166
|
+
);
|
|
167
|
+
expect(registerInstruction).toHaveBeenCalledWith('elastic-report-query', expect.any(Function));
|
|
168
|
+
expect(ElasticReportBlockModel).toBeDefined();
|
|
169
|
+
expect(ElasticFilterBarBlockModel).toBeDefined();
|
|
170
|
+
expect(mocks.MockBlockModel.definedMetas).toEqual(
|
|
171
|
+
expect.arrayContaining([
|
|
172
|
+
expect.objectContaining({
|
|
173
|
+
label: 'Elastic Report',
|
|
174
|
+
createModelOptions: { use: 'ElasticReportBlockModel' },
|
|
175
|
+
}),
|
|
176
|
+
expect.objectContaining({
|
|
177
|
+
label: 'Elastic Filter Bar',
|
|
178
|
+
createModelOptions: { use: 'ElasticFilterBarBlockModel' },
|
|
179
|
+
}),
|
|
180
|
+
]),
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('attaches the chosen tab and published report from an empty page to the user message', async () => {
|
|
185
|
+
const onAdd = vi.fn();
|
|
186
|
+
const onRemove = vi.fn();
|
|
187
|
+
const close = vi.fn();
|
|
188
|
+
const routes = [
|
|
189
|
+
{
|
|
190
|
+
type: 'group',
|
|
191
|
+
title: 'QA',
|
|
192
|
+
children: [
|
|
193
|
+
{
|
|
194
|
+
type: 'flowPage',
|
|
195
|
+
title: 'Overview',
|
|
196
|
+
schemaUid: 'single-page',
|
|
197
|
+
enableTabs: false,
|
|
198
|
+
children: [{ type: 'tabs', hidden: true, schemaUid: 'implicit-tab' }],
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
type: 'flowPage',
|
|
202
|
+
title: 'Sales',
|
|
203
|
+
schemaUid: 'page',
|
|
204
|
+
enableTabs: true,
|
|
205
|
+
children: [
|
|
206
|
+
{ type: 'tabs', title: 'First', schemaUid: 'first' },
|
|
207
|
+
{ type: 'tabs', title: 'Second', schemaUid: 'second' },
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
];
|
|
213
|
+
mocks.request.mockResolvedValue({ data: { data: [{ id: 12, title: 'Revenue', visualization: 'metric' }] } });
|
|
214
|
+
const dialog = vi.fn();
|
|
215
|
+
reportDestinationContext.menu.onClick({
|
|
216
|
+
ctx: { t: (key: string) => key, routeRepository: { listAccessible: () => routes }, viewer: { dialog } } as never,
|
|
217
|
+
contextItems: [{ type: 'elastic-report-destination', uid: 'first' }],
|
|
218
|
+
onAdd,
|
|
219
|
+
onRemove,
|
|
220
|
+
});
|
|
221
|
+
await act(async () => {
|
|
222
|
+
renderWithoutMotion(dialog.mock.calls[0][0].content({ close }));
|
|
223
|
+
});
|
|
224
|
+
const user = userEvent.setup();
|
|
225
|
+
const attach = screen.getByRole('button', { name: 'Attach destination' });
|
|
226
|
+
expect(attach).toBeDisabled();
|
|
227
|
+
await act(async () => {
|
|
228
|
+
await user.click(screen.getByRole('combobox', { name: 'Page and tab' }));
|
|
229
|
+
});
|
|
230
|
+
expect(screen.getByText('QA / Overview')).toBeTruthy();
|
|
231
|
+
await act(async () => {
|
|
232
|
+
await user.click(screen.getByText('QA / Sales / Second'));
|
|
233
|
+
});
|
|
234
|
+
await act(async () => {
|
|
235
|
+
await user.click(screen.getByRole('combobox', { name: 'Report' }));
|
|
236
|
+
});
|
|
237
|
+
await act(async () => {
|
|
238
|
+
await user.click(screen.getByText('Revenue'));
|
|
239
|
+
});
|
|
240
|
+
await act(async () => {
|
|
241
|
+
await user.click(attach);
|
|
242
|
+
});
|
|
243
|
+
await waitFor(() =>
|
|
244
|
+
expect(onAdd).toHaveBeenCalledWith(
|
|
245
|
+
expect.objectContaining({
|
|
246
|
+
uid: 'second',
|
|
247
|
+
content: { pageUid: 'page', tabUid: 'second', reportId: 12 },
|
|
248
|
+
}),
|
|
249
|
+
),
|
|
250
|
+
);
|
|
251
|
+
expect(onRemove).toHaveBeenCalledWith('first');
|
|
252
|
+
expect(close).toHaveBeenCalledOnce();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('updates the mounted report block settings on notification', async () => {
|
|
256
|
+
const eventBus = new EventTarget();
|
|
257
|
+
const plugin = new PluginElasticReportClient({} as never, { eventBus } as never);
|
|
258
|
+
const target = { use: 'ElasticReportBlockModel', setStepParams: vi.fn(), setProps: vi.fn() };
|
|
259
|
+
vi.mocked(plugin.flowEngine.getModel).mockReturnValue(target as never);
|
|
260
|
+
await plugin.load();
|
|
261
|
+
eventBus.dispatchEvent(
|
|
262
|
+
new CustomEvent('ws:message:elastic-report:block-settings', {
|
|
263
|
+
detail: { blockUid: 'selected', changes: { compact: true } },
|
|
264
|
+
}),
|
|
265
|
+
);
|
|
266
|
+
expect(plugin.flowEngine.getModel).toHaveBeenCalledWith('selected', true);
|
|
267
|
+
expect(target.setStepParams).toHaveBeenCalledWith('elasticReportBlockSettings', 'editReport', { compact: true });
|
|
268
|
+
expect(target.setProps).toHaveBeenCalledWith({ compact: true });
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('renders Elasticsearch highlights safely with <mark> without injecting raw HTML', () => {
|
|
272
|
+
const text = ` Normal <img src=x onerror=alert(1)> ${HIGHLIGHT_PRE_TAG}matched term${HIGHLIGHT_POST_TAG} tail`;
|
|
273
|
+
const { container } = renderWithoutMotion(<HighlightText text={text} />);
|
|
274
|
+
|
|
275
|
+
const mark = container.querySelector('mark');
|
|
276
|
+
expect(mark?.textContent).toBe('matched term');
|
|
277
|
+
expect(container.querySelector('img')).toBeNull();
|
|
278
|
+
expect(container.textContent).toContain('<img src=x onerror=alert(1)>');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('renders accessible SVG bar chart, switches to data table, and indicates >= on truncated KPI counts', async () => {
|
|
282
|
+
const user = userEvent.setup();
|
|
283
|
+
renderWithoutMotion(
|
|
284
|
+
<div>
|
|
285
|
+
<ElasticBasicChart
|
|
286
|
+
title="Requests by Service"
|
|
287
|
+
visualization="bar"
|
|
288
|
+
metricLabel="Requests"
|
|
289
|
+
metricValue={null}
|
|
290
|
+
totalHits={42}
|
|
291
|
+
series={[
|
|
292
|
+
{ key: 'checkout', label: 'checkout', value: 30, count: 30 },
|
|
293
|
+
{ key: 'catalog', label: 'catalog', value: 12, count: 12 },
|
|
294
|
+
]}
|
|
295
|
+
/>
|
|
296
|
+
<ElasticBasicChart
|
|
297
|
+
title="Total Errors KPI"
|
|
298
|
+
visualization="metric"
|
|
299
|
+
metricType="count"
|
|
300
|
+
metricLabel="Error Count"
|
|
301
|
+
metricValue={10000}
|
|
302
|
+
totalHits={10000}
|
|
303
|
+
totalRelation="gte"
|
|
304
|
+
series={[]}
|
|
305
|
+
/>
|
|
306
|
+
</div>,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
expect(screen.getByRole('img', { name: /Requests by Service/i })).toBeTruthy();
|
|
310
|
+
expect(screen.getByText('≥')).toBeTruthy();
|
|
311
|
+
expect(screen.getByText(/Hits: 10,000\+/)).toBeTruthy();
|
|
312
|
+
|
|
313
|
+
await act(async () => {
|
|
314
|
+
await user.click(screen.getByRole('button', { name: 'Show data table' }));
|
|
315
|
+
});
|
|
316
|
+
expect(await screen.findByText('checkout')).toBeTruthy();
|
|
317
|
+
expect(screen.getByText('catalog')).toBeTruthy();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('preserves KQL, custom timeRange bounds on Refresh, lockedFilters, shard warnings, and edited filter pills', async () => {
|
|
321
|
+
const user = userEvent.setup();
|
|
322
|
+
const savedSpec = {
|
|
323
|
+
visualization: 'table' as const,
|
|
324
|
+
query: 'status >= 400',
|
|
325
|
+
lockedFilters: [
|
|
326
|
+
{ id: 'lock-1', field: 'region', operator: 'eq' as const, value: 'ap-southeast-1', enabled: true },
|
|
327
|
+
],
|
|
328
|
+
filters: [{ id: 'f1', field: 'service', operator: 'eq' as const, value: 'checkout-api', enabled: true }],
|
|
329
|
+
timeRange: {
|
|
330
|
+
preset: 'custom' as const,
|
|
331
|
+
from: '2026-11-29T00:00:00Z',
|
|
332
|
+
to: '2026-11-30T00:00:00Z',
|
|
333
|
+
},
|
|
334
|
+
columns: ['@timestamp', 'service', 'status'],
|
|
335
|
+
pageSize: 20,
|
|
336
|
+
allowInteractiveControls: true,
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
mocks.request.mockImplementation(async (cfg: { url: string; data?: Record<string, unknown> }) => {
|
|
340
|
+
if (cfg.url === 'esReportService:getReportMeta') {
|
|
341
|
+
return {
|
|
342
|
+
data: {
|
|
343
|
+
data: {
|
|
344
|
+
report: {
|
|
345
|
+
id: 10,
|
|
346
|
+
title: 'Gateway Error Logs (Discover Table)',
|
|
347
|
+
dataViewId: 1,
|
|
348
|
+
visualization: 'table',
|
|
349
|
+
published: true,
|
|
350
|
+
spec: { ...savedSpec },
|
|
351
|
+
},
|
|
352
|
+
dataView: {
|
|
353
|
+
id: 1,
|
|
354
|
+
title: 'Logs',
|
|
355
|
+
dataSourceKey: 'es_main',
|
|
356
|
+
indexPattern: 'logs-*',
|
|
357
|
+
timeField: '@timestamp',
|
|
358
|
+
},
|
|
359
|
+
fields: [
|
|
360
|
+
{ name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
|
|
361
|
+
{ name: 'service', type: 'keyword', searchable: true, aggregatable: true },
|
|
362
|
+
{ name: 'status', type: 'integer', searchable: true, aggregatable: true },
|
|
363
|
+
{ name: 'region', type: 'keyword', searchable: true, aggregatable: true },
|
|
364
|
+
],
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (cfg.url === 'esReportService:runReport') {
|
|
371
|
+
return {
|
|
372
|
+
data: {
|
|
373
|
+
data: {
|
|
374
|
+
report: {
|
|
375
|
+
id: 10,
|
|
376
|
+
title: 'Gateway Error Logs (Discover Table)',
|
|
377
|
+
dataViewId: 1,
|
|
378
|
+
visualization: 'table',
|
|
379
|
+
published: true,
|
|
380
|
+
spec: {
|
|
381
|
+
...savedSpec,
|
|
382
|
+
filters: savedSpec.filters.map((f) => ({ ...f })),
|
|
383
|
+
lockedFilters: savedSpec.lockedFilters.map((f) => ({ ...f })),
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
dataView: {
|
|
387
|
+
id: 1,
|
|
388
|
+
title: 'Logs',
|
|
389
|
+
dataSourceKey: 'es_main',
|
|
390
|
+
indexPattern: 'logs-*',
|
|
391
|
+
timeField: '@timestamp',
|
|
392
|
+
},
|
|
393
|
+
result: {
|
|
394
|
+
total: 1,
|
|
395
|
+
totalRelation: 'eq',
|
|
396
|
+
tookMs: 4,
|
|
397
|
+
timedOut: true,
|
|
398
|
+
shards: { total: 5, successful: 4, skipped: 0, failed: 1 },
|
|
399
|
+
visualization: 'table',
|
|
400
|
+
columns: ['@timestamp', 'service', 'status'],
|
|
401
|
+
rows: [
|
|
402
|
+
{
|
|
403
|
+
_id: 'doc-1',
|
|
404
|
+
_index: 'logs-2026',
|
|
405
|
+
source: {
|
|
406
|
+
'@timestamp': '2026-11-30T01:00:00Z',
|
|
407
|
+
service: 'gateway',
|
|
408
|
+
status: 503,
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
series: [],
|
|
413
|
+
histogram: [],
|
|
414
|
+
metricValue: null,
|
|
415
|
+
metricLabel: 'Count',
|
|
416
|
+
compiledDsl: { query: { match_all: {} } },
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
return { data: { data: [] } };
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
await act(async () => {
|
|
426
|
+
renderWithoutMotion(<ElasticReportBlock reportId={10} showToolbar={true} />);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
await waitFor(() => {
|
|
430
|
+
expect(screen.getByText('gateway')).toBeTruthy();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Locked filter badge and partial shard/timeout warning alert are both rendered
|
|
434
|
+
expect(screen.getByText(/region eq ap-southeast-1/)).toBeTruthy();
|
|
435
|
+
expect(screen.getByText('Partial results warning')).toBeTruthy();
|
|
436
|
+
expect(screen.getByText(/Failed shards: 1 \/ 5/)).toBeTruthy();
|
|
437
|
+
|
|
438
|
+
// Clicking Refresh preserves custom timeRange { preset: 'custom', from, to }
|
|
439
|
+
await act(async () => {
|
|
440
|
+
await user.click(screen.getByRole('button', { name: 'Refresh' }));
|
|
441
|
+
});
|
|
442
|
+
await waitFor(() => {
|
|
443
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
444
|
+
expect.objectContaining({
|
|
445
|
+
url: 'esReportService:runReport',
|
|
446
|
+
data: expect.objectContaining({
|
|
447
|
+
reportId: 10,
|
|
448
|
+
overrides: expect.objectContaining({
|
|
449
|
+
timeRange: {
|
|
450
|
+
preset: 'custom',
|
|
451
|
+
from: '2026-11-29T00:00:00Z',
|
|
452
|
+
to: '2026-11-30T00:00:00Z',
|
|
453
|
+
},
|
|
454
|
+
}),
|
|
455
|
+
}),
|
|
456
|
+
}),
|
|
457
|
+
);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
const searchInput = screen.getByRole('combobox', { name: 'KQL / Search Query' }) as HTMLInputElement;
|
|
461
|
+
expect(searchInput.value).toBe('status >= 400');
|
|
462
|
+
|
|
463
|
+
await act(async () => {
|
|
464
|
+
await user.clear(searchInput);
|
|
465
|
+
await user.type(searchInput, 'status >= 500');
|
|
466
|
+
await user.click(screen.getByRole('button', { name: /Search/i }));
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
await waitFor(() => {
|
|
470
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
471
|
+
expect.objectContaining({
|
|
472
|
+
url: 'esReportService:runReport',
|
|
473
|
+
data: expect.objectContaining({
|
|
474
|
+
reportId: 10,
|
|
475
|
+
overrides: expect.objectContaining({
|
|
476
|
+
query: 'status >= 500',
|
|
477
|
+
}),
|
|
478
|
+
}),
|
|
479
|
+
}),
|
|
480
|
+
);
|
|
481
|
+
});
|
|
482
|
+
expect(searchInput.value).toBe('status >= 500');
|
|
483
|
+
|
|
484
|
+
// Click existing filter pill to edit its value in place
|
|
485
|
+
await act(async () => {
|
|
486
|
+
await user.click(screen.getByRole('button', { name: 'Edit Filter: service' }));
|
|
487
|
+
});
|
|
488
|
+
const valueInput = await screen.findByDisplayValue('checkout-api');
|
|
489
|
+
await act(async () => {
|
|
490
|
+
await user.clear(valueInput);
|
|
491
|
+
await user.type(valueInput, 'auth-service');
|
|
492
|
+
await user.click(screen.getByRole('button', { name: 'Apply' }));
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
await waitFor(() => {
|
|
496
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
497
|
+
expect.objectContaining({
|
|
498
|
+
url: 'esReportService:runReport',
|
|
499
|
+
data: expect.objectContaining({
|
|
500
|
+
reportId: 10,
|
|
501
|
+
overrides: expect.objectContaining({
|
|
502
|
+
query: 'status >= 500',
|
|
503
|
+
filters: [expect.objectContaining({ field: 'service', operator: 'eq', value: 'auth-service' })],
|
|
504
|
+
}),
|
|
505
|
+
}),
|
|
506
|
+
}),
|
|
507
|
+
);
|
|
508
|
+
});
|
|
509
|
+
expect(screen.getByText(/service eq auth-service/)).toBeTruthy();
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('supports stacked multi-series charts, KPI delta badges, DashboardFilterBus cross-filtering, cell + filter, and fieldFormats', async () => {
|
|
513
|
+
const user = userEvent.setup();
|
|
514
|
+
const scopeKey = 'page-root-test:ops';
|
|
515
|
+
clearDashboardScope(scopeKey);
|
|
516
|
+
|
|
517
|
+
mocks.request.mockImplementation(async (cfg: { url: string; data?: Record<string, unknown> }) => {
|
|
518
|
+
if (cfg.url === 'esReportService:getReportMeta') {
|
|
519
|
+
return {
|
|
520
|
+
data: {
|
|
521
|
+
data: {
|
|
522
|
+
report: {
|
|
523
|
+
id: 21,
|
|
524
|
+
title: 'Service Latency Table',
|
|
525
|
+
dataViewId: 1,
|
|
526
|
+
visualization: 'table',
|
|
527
|
+
published: true,
|
|
528
|
+
spec: {
|
|
529
|
+
visualization: 'table',
|
|
530
|
+
columns: ['@timestamp', 'service', 'status', 'latency_ms'],
|
|
531
|
+
fieldFormats: {
|
|
532
|
+
status: 'status_badge',
|
|
533
|
+
latency_ms: 'duration_ms',
|
|
534
|
+
},
|
|
535
|
+
contextBindings: [{ esField: 'customer_id', recordFieldPath: 'account.code' }],
|
|
536
|
+
allowInteractiveControls: true,
|
|
537
|
+
allowExport: true,
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
dataView: {
|
|
541
|
+
id: 1,
|
|
542
|
+
title: 'Logs',
|
|
543
|
+
dataSourceKey: 'es_main',
|
|
544
|
+
indexPattern: 'logs-*',
|
|
545
|
+
timeField: '@timestamp',
|
|
546
|
+
},
|
|
547
|
+
fields: [
|
|
548
|
+
{ name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
|
|
549
|
+
{ name: 'service', type: 'keyword', searchable: true, aggregatable: true },
|
|
550
|
+
{ name: 'status', type: 'integer', searchable: true, aggregatable: true },
|
|
551
|
+
{ name: 'latency_ms', type: 'double', searchable: true, aggregatable: true },
|
|
552
|
+
],
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (cfg.url === 'esReportService:runReport') {
|
|
559
|
+
return {
|
|
560
|
+
data: {
|
|
561
|
+
data: {
|
|
562
|
+
report: {
|
|
563
|
+
id: 21,
|
|
564
|
+
title: 'Service Latency Table',
|
|
565
|
+
dataViewId: 1,
|
|
566
|
+
visualization: 'table',
|
|
567
|
+
published: true,
|
|
568
|
+
spec: {
|
|
569
|
+
visualization: 'table',
|
|
570
|
+
columns: ['@timestamp', 'service', 'status', 'latency_ms'],
|
|
571
|
+
fieldFormats: {
|
|
572
|
+
status: 'status_badge',
|
|
573
|
+
latency_ms: 'duration_ms',
|
|
574
|
+
},
|
|
575
|
+
contextBindings: [{ esField: 'customer_id', recordFieldPath: 'account.code' }],
|
|
576
|
+
allowInteractiveControls: true,
|
|
577
|
+
allowExport: true,
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
dataView: {
|
|
581
|
+
id: 1,
|
|
582
|
+
title: 'Logs',
|
|
583
|
+
dataSourceKey: 'es_main',
|
|
584
|
+
indexPattern: 'logs-*',
|
|
585
|
+
timeField: '@timestamp',
|
|
586
|
+
},
|
|
587
|
+
result: {
|
|
588
|
+
total: 1,
|
|
589
|
+
totalRelation: 'eq',
|
|
590
|
+
tookMs: 3,
|
|
591
|
+
visualization: 'table',
|
|
592
|
+
columns: ['@timestamp', 'service', 'status', 'latency_ms'],
|
|
593
|
+
rows: [
|
|
594
|
+
{
|
|
595
|
+
_id: 'doc-21',
|
|
596
|
+
_index: 'logs-2026',
|
|
597
|
+
source: {
|
|
598
|
+
'@timestamp': '2026-11-30T02:00:00Z',
|
|
599
|
+
service: 'payments',
|
|
600
|
+
status: 502,
|
|
601
|
+
latency_ms: 1500,
|
|
602
|
+
},
|
|
603
|
+
},
|
|
604
|
+
],
|
|
605
|
+
series: [],
|
|
606
|
+
histogram: [],
|
|
607
|
+
metricValue: null,
|
|
608
|
+
metricLabel: 'Count',
|
|
609
|
+
compiledDsl: { query: { match_all: {} } },
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
return { data: { data: { buckets: [] } } };
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
await act(async () => {
|
|
619
|
+
renderWithoutMotion(
|
|
620
|
+
<div>
|
|
621
|
+
<ElasticBasicChart
|
|
622
|
+
title="Stacked Latency by Service"
|
|
623
|
+
visualization="bar"
|
|
624
|
+
stackMode="stacked"
|
|
625
|
+
seriesKeys={['checkout', 'payments']}
|
|
626
|
+
metricLabel="P95 Latency"
|
|
627
|
+
metricValue={null}
|
|
628
|
+
totalHits={25}
|
|
629
|
+
series={[
|
|
630
|
+
{
|
|
631
|
+
key: '10:00',
|
|
632
|
+
label: '10:00',
|
|
633
|
+
value: 600,
|
|
634
|
+
count: 25,
|
|
635
|
+
breakdown: [
|
|
636
|
+
{ seriesKey: 'checkout', value: 250, count: 15 },
|
|
637
|
+
{ seriesKey: 'payments', value: 350, count: 10 },
|
|
638
|
+
],
|
|
639
|
+
},
|
|
640
|
+
]}
|
|
641
|
+
/>
|
|
642
|
+
<ElasticBasicChart
|
|
643
|
+
title="P95 Latency KPI"
|
|
644
|
+
visualization="metric"
|
|
645
|
+
metricType="p95"
|
|
646
|
+
metricLabel="P95 Latency"
|
|
647
|
+
metricValue={250}
|
|
648
|
+
previousMetricValue={200}
|
|
649
|
+
deltaPercent={25}
|
|
650
|
+
totalHits={100}
|
|
651
|
+
series={[]}
|
|
652
|
+
/>
|
|
653
|
+
<ElasticFilterBar scopeKey={scopeKey} showGlobalKql={true} showGlobalTimeRange={true} />
|
|
654
|
+
<ElasticReportBlock
|
|
655
|
+
reportId={21}
|
|
656
|
+
scopeKey={scopeKey}
|
|
657
|
+
subscribeDashboardFilters={true}
|
|
658
|
+
contextRecord={{ account: { code: 'ACME-01' } }}
|
|
659
|
+
/>
|
|
660
|
+
</div>,
|
|
661
|
+
);
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
// Formatted duration_ms (1500 -> "1.50 s") and KPI previous-period delta (+25%) are rendered
|
|
665
|
+
await waitFor(() => {
|
|
666
|
+
expect(screen.getByText('1.50 s')).toBeTruthy();
|
|
667
|
+
});
|
|
668
|
+
expect(screen.getByText(/\+25%/)).toBeTruthy();
|
|
669
|
+
|
|
670
|
+
// Context binding filter (customer_id = ACME-01) is sent automatically
|
|
671
|
+
await waitFor(() => {
|
|
672
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
673
|
+
expect.objectContaining({
|
|
674
|
+
url: 'esReportService:runReport',
|
|
675
|
+
data: expect.objectContaining({
|
|
676
|
+
reportId: 21,
|
|
677
|
+
overrides: expect.objectContaining({
|
|
678
|
+
contextFilters: [expect.objectContaining({ field: 'customer_id', operator: 'eq', value: 'ACME-01' })],
|
|
679
|
+
}),
|
|
680
|
+
}),
|
|
681
|
+
}),
|
|
682
|
+
);
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
// Global KQL from ElasticFilterBar propagates via DashboardFilterBus to ElasticReportBlock
|
|
686
|
+
const kqlInputs = screen.getAllByRole('combobox', { name: 'KQL / Search Query' });
|
|
687
|
+
await act(async () => {
|
|
688
|
+
await user.type(kqlInputs[0], 'status >= 500');
|
|
689
|
+
await user.click(screen.getByRole('button', { name: 'Apply' }));
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
await waitFor(() => {
|
|
693
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
694
|
+
expect.objectContaining({
|
|
695
|
+
url: 'esReportService:runReport',
|
|
696
|
+
data: expect.objectContaining({
|
|
697
|
+
reportId: 21,
|
|
698
|
+
overrides: expect.objectContaining({
|
|
699
|
+
query: 'status >= 500',
|
|
700
|
+
}),
|
|
701
|
+
}),
|
|
702
|
+
}),
|
|
703
|
+
);
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
// Clicking Discover cell "+" button pushes shared cross-filter pill to ElasticFilterBar and re-queries
|
|
707
|
+
await act(async () => {
|
|
708
|
+
await user.click(screen.getByRole('button', { name: 'Filter for value: service=payments' }));
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
await waitFor(() => {
|
|
712
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
713
|
+
expect.objectContaining({
|
|
714
|
+
url: 'esReportService:runReport',
|
|
715
|
+
data: expect.objectContaining({
|
|
716
|
+
reportId: 21,
|
|
717
|
+
overrides: expect.objectContaining({
|
|
718
|
+
sharedFilters: [expect.objectContaining({ field: 'service', operator: 'eq', value: 'payments' })],
|
|
719
|
+
}),
|
|
720
|
+
}),
|
|
721
|
+
}),
|
|
722
|
+
);
|
|
723
|
+
});
|
|
724
|
+
expect(screen.getByText(/service eq payments/)).toBeTruthy();
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
it('provides guided KQL autocomplete for fields, operators, live Elasticsearch top values, and Enter-to-submit', async () => {
|
|
728
|
+
const user = userEvent.setup();
|
|
729
|
+
|
|
730
|
+
mocks.request.mockImplementation(async (cfg: { url: string; data?: Record<string, unknown> }) => {
|
|
731
|
+
if (cfg.url === 'esReportService:getReportMeta') {
|
|
732
|
+
return {
|
|
733
|
+
data: {
|
|
734
|
+
data: {
|
|
735
|
+
report: {
|
|
736
|
+
id: 30,
|
|
737
|
+
title: 'Guided Search Report',
|
|
738
|
+
dataViewId: 1,
|
|
739
|
+
visualization: 'table',
|
|
740
|
+
published: true,
|
|
741
|
+
spec: {
|
|
742
|
+
visualization: 'table',
|
|
743
|
+
columns: ['@timestamp', 'service', 'status'],
|
|
744
|
+
allowInteractiveControls: true,
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
dataView: {
|
|
748
|
+
id: 1,
|
|
749
|
+
title: 'Logs',
|
|
750
|
+
dataSourceKey: 'es_main',
|
|
751
|
+
indexPattern: 'logs-*',
|
|
752
|
+
timeField: '@timestamp',
|
|
753
|
+
},
|
|
754
|
+
fields: [
|
|
755
|
+
{ name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
|
|
756
|
+
{ name: 'service', type: 'keyword', searchable: true, aggregatable: true },
|
|
757
|
+
{ name: 'status', type: 'integer', searchable: true, aggregatable: true },
|
|
758
|
+
],
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
if (cfg.url === 'esReportService:inspectTopValues') {
|
|
764
|
+
return {
|
|
765
|
+
data: {
|
|
766
|
+
data: {
|
|
767
|
+
field: cfg.data?.field,
|
|
768
|
+
resolvedField: cfg.data?.field,
|
|
769
|
+
totalDocs: 50,
|
|
770
|
+
buckets:
|
|
771
|
+
cfg.data?.field === 'service'
|
|
772
|
+
? [
|
|
773
|
+
{ value: 'gateway', count: 32, percentage: 64 },
|
|
774
|
+
{ value: 'billing-api', count: 18, percentage: 36 },
|
|
775
|
+
]
|
|
776
|
+
: [{ value: '500', count: 20, percentage: 40 }],
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
if (cfg.url === 'esReportService:runReport') {
|
|
782
|
+
return {
|
|
783
|
+
data: {
|
|
784
|
+
data: {
|
|
785
|
+
report: {
|
|
786
|
+
id: 30,
|
|
787
|
+
title: 'Guided Search Report',
|
|
788
|
+
dataViewId: 1,
|
|
789
|
+
visualization: 'table',
|
|
790
|
+
published: true,
|
|
791
|
+
spec: {
|
|
792
|
+
visualization: 'table',
|
|
793
|
+
columns: ['@timestamp', 'service', 'status'],
|
|
794
|
+
allowInteractiveControls: true,
|
|
795
|
+
},
|
|
796
|
+
},
|
|
797
|
+
dataView: {
|
|
798
|
+
id: 1,
|
|
799
|
+
title: 'Logs',
|
|
800
|
+
dataSourceKey: 'es_main',
|
|
801
|
+
indexPattern: 'logs-*',
|
|
802
|
+
timeField: '@timestamp',
|
|
803
|
+
},
|
|
804
|
+
result: {
|
|
805
|
+
total: 1,
|
|
806
|
+
totalRelation: 'eq',
|
|
807
|
+
tookMs: 2,
|
|
808
|
+
visualization: 'table',
|
|
809
|
+
columns: ['@timestamp', 'service', 'status'],
|
|
810
|
+
rows: [],
|
|
811
|
+
series: [],
|
|
812
|
+
histogram: [],
|
|
813
|
+
metricValue: null,
|
|
814
|
+
metricLabel: 'Count',
|
|
815
|
+
compiledDsl: { query: { match_all: {} } },
|
|
816
|
+
},
|
|
817
|
+
},
|
|
818
|
+
},
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
return { data: { data: [] } };
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
await act(async () => {
|
|
825
|
+
renderWithoutMotion(<ElasticReportBlock reportId={30} showToolbar={true} />);
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
const kqlCombo = await screen.findByRole('combobox', { name: 'KQL / Search Query' });
|
|
829
|
+
|
|
830
|
+
// 1. Focus empty search input -> field suggestions appear
|
|
831
|
+
await act(async () => {
|
|
832
|
+
await user.click(kqlCombo);
|
|
833
|
+
});
|
|
834
|
+
const serviceFieldOpt = await screen.findByRole('option', { name: /service/i });
|
|
835
|
+
|
|
836
|
+
// 2. Click `service` -> inserts `service: ` and automatically loads live top values from Elasticsearch
|
|
837
|
+
await act(async () => {
|
|
838
|
+
await user.click(serviceFieldOpt);
|
|
839
|
+
});
|
|
840
|
+
expect((kqlCombo as HTMLInputElement).value).toBe('service: ');
|
|
841
|
+
|
|
842
|
+
const gatewayValOpt = await screen.findByRole('option', { name: /"gateway"/i });
|
|
843
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
844
|
+
expect.objectContaining({
|
|
845
|
+
url: 'esReportService:inspectTopValues',
|
|
846
|
+
data: expect.objectContaining({
|
|
847
|
+
reportId: 30,
|
|
848
|
+
field: 'service',
|
|
849
|
+
overrides: expect.objectContaining({
|
|
850
|
+
query: '',
|
|
851
|
+
}),
|
|
852
|
+
}),
|
|
853
|
+
}),
|
|
854
|
+
);
|
|
855
|
+
await act(async () => {
|
|
856
|
+
await user.click(gatewayValOpt);
|
|
857
|
+
});
|
|
858
|
+
expect((kqlCombo as HTMLInputElement).value).toBe('service: "gateway" ');
|
|
859
|
+
|
|
860
|
+
// 3. Press Enter directly without highlighting another option -> executes the search immediately
|
|
861
|
+
await act(async () => {
|
|
862
|
+
await user.keyboard('{Enter}');
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
await waitFor(() => {
|
|
866
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
867
|
+
expect.objectContaining({
|
|
868
|
+
url: 'esReportService:runReport',
|
|
869
|
+
data: expect.objectContaining({
|
|
870
|
+
reportId: 30,
|
|
871
|
+
overrides: expect.objectContaining({
|
|
872
|
+
query: 'service: "gateway"',
|
|
873
|
+
}),
|
|
874
|
+
}),
|
|
875
|
+
}),
|
|
876
|
+
);
|
|
877
|
+
});
|
|
878
|
+
});
|
|
879
|
+
});
|