plugin-elastic-report 0.0.0-stage → 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 (272) hide show
  1. package/ai/skills/elastic-report/SKILLS.md +34 -0
  2. package/client-v2.d.ts +2 -0
  3. package/client-v2.js +1 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/357.0dd385384cab5dbf.js +10 -0
  7. package/dist/client/index.js +10 -0
  8. package/dist/client-v2/851.142c93fc6d666b28.js +10 -0
  9. package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
  10. package/dist/client-v2/877.f4095a3dbcadf98f.js +10 -0
  11. package/dist/client-v2/index.js +10 -0
  12. package/dist/externalVersion.js +21 -0
  13. package/dist/index.js +48 -0
  14. package/dist/locale/en-US.json +198 -0
  15. package/dist/locale/vi-VN.json +198 -0
  16. package/dist/locale/zh-CN.json +198 -0
  17. package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
  18. package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
  19. package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
  20. package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
  21. package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
  22. package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
  23. package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
  24. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
  25. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
  26. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
  27. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
  28. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
  29. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
  30. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
  31. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
  32. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
  33. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
  34. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
  35. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
  36. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
  37. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
  38. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
  39. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
  40. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
  41. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
  42. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
  43. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
  44. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
  45. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
  46. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
  47. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
  48. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
  49. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
  50. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
  51. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
  52. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
  53. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
  54. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
  55. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
  56. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
  57. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
  58. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
  59. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
  60. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
  61. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
  62. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
  63. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
  64. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
  65. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
  66. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
  67. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
  68. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
  69. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
  70. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
  71. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
  72. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
  73. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
  74. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
  75. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
  76. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
  77. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
  78. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
  79. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
  80. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
  81. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
  82. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
  83. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
  84. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
  85. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
  86. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
  87. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
  88. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
  89. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
  90. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
  91. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
  92. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
  93. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
  94. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
  95. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
  96. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
  97. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
  98. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
  99. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
  100. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
  101. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
  102. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
  103. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
  104. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
  105. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
  106. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
  107. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
  108. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
  109. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
  110. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
  111. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
  112. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
  113. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
  114. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
  115. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
  116. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
  117. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
  118. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
  119. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
  120. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
  121. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
  122. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
  123. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
  124. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
  125. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
  126. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
  127. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
  128. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
  129. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
  130. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
  131. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
  132. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
  133. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
  134. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
  135. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
  136. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
  137. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
  138. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
  139. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
  140. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
  141. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
  142. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
  143. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
  144. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
  145. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
  146. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
  147. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
  148. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
  149. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
  150. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
  151. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
  152. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
  153. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
  154. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
  155. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
  156. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
  157. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
  158. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
  159. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
  160. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
  161. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
  162. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
  163. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
  164. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
  165. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
  166. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
  167. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
  168. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
  169. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
  170. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
  171. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
  172. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
  173. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
  174. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
  175. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
  176. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
  177. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
  178. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
  179. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
  180. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
  181. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
  182. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
  183. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
  184. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
  185. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
  186. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
  187. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
  188. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
  189. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
  190. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
  191. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
  192. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
  193. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
  194. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
  195. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
  196. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
  197. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
  198. package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
  199. package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
  200. package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
  201. package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
  202. package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
  203. package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
  204. package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
  205. package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
  206. package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
  207. package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
  208. package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
  209. package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
  210. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
  211. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
  212. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
  213. package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
  214. package/dist/server/acl-guard.js +179 -0
  215. package/dist/server/collections/es-report-data-views.js +85 -0
  216. package/dist/server/collections/es-reports.js +101 -0
  217. package/dist/server/index.js +58 -0
  218. package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
  219. package/dist/server/mcp/ElasticReportToolCatalog.js +639 -0
  220. package/dist/server/plugin.js +529 -0
  221. package/dist/server/services/ElasticReportService.js +377 -0
  222. package/dist/server/services/ElasticsearchConnectionService.js +572 -0
  223. package/dist/server/services/ReportExportService.js +243 -0
  224. package/dist/server/services/ReportQueryCompiler.js +1299 -0
  225. package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
  226. package/dist/shared/constants.js +96 -0
  227. package/dist/shared/types.js +24 -0
  228. package/package.json +62 -4
  229. package/server.d.ts +2 -0
  230. package/server.js +1 -0
  231. package/src/client/index.tsx +34 -0
  232. package/src/client/workflow-instructions.tsx +44 -0
  233. package/src/client-v2/__tests__/elastic-report.test.tsx +791 -0
  234. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
  235. package/src/client-v2/api.ts +320 -0
  236. package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
  237. package/src/client-v2/components/ElasticBasicCharts.tsx +652 -0
  238. package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
  239. package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
  240. package/src/client-v2/components/ElasticReportBlock.tsx +306 -0
  241. package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -0
  242. package/src/client-v2/components/HighlightText.tsx +50 -0
  243. package/src/client-v2/components/ReportSelect.tsx +85 -0
  244. package/src/client-v2/index.tsx +14 -0
  245. package/src/client-v2/locale.ts +23 -0
  246. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
  247. package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -0
  248. package/src/client-v2/pages/ElasticReportManager.tsx +1453 -0
  249. package/src/client-v2/plugin.tsx +72 -0
  250. package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
  251. package/src/client-v2/workflow/instructions.tsx +149 -0
  252. package/src/index.ts +11 -0
  253. package/src/locale/en-US.json +198 -0
  254. package/src/locale/vi-VN.json +198 -0
  255. package/src/locale/zh-CN.json +198 -0
  256. package/src/server/__tests__/query-compiler.test.ts +620 -0
  257. package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -0
  258. package/src/server/acl-guard.ts +194 -0
  259. package/src/server/collections/es-report-data-views.ts +64 -0
  260. package/src/server/collections/es-reports.ts +80 -0
  261. package/src/server/index.ts +15 -0
  262. package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
  263. package/src/server/mcp/ElasticReportToolCatalog.ts +663 -0
  264. package/src/server/plugin.ts +599 -0
  265. package/src/server/services/ElasticReportService.ts +486 -0
  266. package/src/server/services/ElasticsearchConnectionService.ts +728 -0
  267. package/src/server/services/ReportExportService.ts +282 -0
  268. package/src/server/services/ReportQueryCompiler.ts +1552 -0
  269. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
  270. package/src/shared/constants.ts +36 -0
  271. package/src/shared/types.ts +272 -0
  272. package/README.md +0 -3
@@ -0,0 +1,791 @@
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, 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
+
111
+ function renderWithoutMotion(ui: React.ReactElement) {
112
+ return render(<ConfigProvider theme={{ token: { motion: false }, hashed: false }}>{ui}</ConfigProvider>);
113
+ }
114
+
115
+ describe('plugin-elastic-report client-v2', () => {
116
+ beforeEach(() => {
117
+ mocks.request.mockReset();
118
+ mocks.registerModelLoaders.mockClear();
119
+ mocks.addMenuItem.mockClear();
120
+ mocks.addPageTabItem.mockClear();
121
+ mocks.setPluginSettingsLink.mockClear();
122
+ });
123
+
124
+ afterEach(async () => {
125
+ await act(async () => {
126
+ await new Promise((resolve) => setTimeout(resolve, 0));
127
+ });
128
+ cleanup();
129
+ });
130
+
131
+ it('registers Report + FilterBar block loaders, settings page, and workflow instruction on load()', async () => {
132
+ const registerInstructionGroup = vi.fn();
133
+ const registerInstruction = vi.fn();
134
+ const mockApp = {
135
+ pm: {
136
+ get: (name: string) => (name === 'workflow' ? { registerInstructionGroup, registerInstruction } : undefined),
137
+ },
138
+ };
139
+ const plugin = new PluginElasticReportClient({ name: 'plugin-elastic-report' } as never, mockApp as never);
140
+ await plugin.load();
141
+
142
+ expect(mocks.registerComponents).toHaveBeenCalledWith({
143
+ ElasticReportSelect: expect.any(Function),
144
+ });
145
+ expect(mocks.registerModelLoaders).toHaveBeenCalledWith(
146
+ expect.objectContaining({
147
+ ElasticReportBlockModel: expect.objectContaining({
148
+ extends: 'BlockModel',
149
+ }),
150
+ ElasticFilterBarBlockModel: expect.objectContaining({
151
+ extends: 'BlockModel',
152
+ }),
153
+ }),
154
+ );
155
+ expect(mocks.addMenuItem).toHaveBeenCalledWith(
156
+ expect.objectContaining({
157
+ key: 'elastic-report',
158
+ aclSnippet: 'pm.elastic-report',
159
+ }),
160
+ );
161
+ expect(mocks.addPageTabItem).toHaveBeenCalledTimes(1);
162
+ expect(registerInstructionGroup).toHaveBeenCalledWith(
163
+ 'elastic-report',
164
+ expect.objectContaining({ key: 'elastic-report' }),
165
+ );
166
+ expect(registerInstruction).toHaveBeenCalledWith('elastic-report-query', expect.any(Function));
167
+ expect(ElasticReportBlockModel).toBeDefined();
168
+ expect(ElasticFilterBarBlockModel).toBeDefined();
169
+ expect(mocks.MockBlockModel.definedMetas).toEqual(
170
+ expect.arrayContaining([
171
+ expect.objectContaining({
172
+ label: 'Elastic Report',
173
+ createModelOptions: { use: 'ElasticReportBlockModel' },
174
+ }),
175
+ expect.objectContaining({
176
+ label: 'Elastic Filter Bar',
177
+ createModelOptions: { use: 'ElasticFilterBarBlockModel' },
178
+ }),
179
+ ]),
180
+ );
181
+ });
182
+
183
+ it('renders Elasticsearch highlights safely with <mark> without injecting raw HTML', () => {
184
+ const text = ` Normal <img src=x onerror=alert(1)> ${HIGHLIGHT_PRE_TAG}matched term${HIGHLIGHT_POST_TAG} tail`;
185
+ const { container } = renderWithoutMotion(<HighlightText text={text} />);
186
+
187
+ const mark = container.querySelector('mark');
188
+ expect(mark?.textContent).toBe('matched term');
189
+ expect(container.querySelector('img')).toBeNull();
190
+ expect(container.textContent).toContain('<img src=x onerror=alert(1)>');
191
+ });
192
+
193
+ it('renders accessible SVG bar chart, switches to data table, and indicates >= on truncated KPI counts', async () => {
194
+ const user = userEvent.setup();
195
+ renderWithoutMotion(
196
+ <div>
197
+ <ElasticBasicChart
198
+ title="Requests by Service"
199
+ visualization="bar"
200
+ metricLabel="Requests"
201
+ metricValue={null}
202
+ totalHits={42}
203
+ series={[
204
+ { key: 'checkout', label: 'checkout', value: 30, count: 30 },
205
+ { key: 'catalog', label: 'catalog', value: 12, count: 12 },
206
+ ]}
207
+ />
208
+ <ElasticBasicChart
209
+ title="Total Errors KPI"
210
+ visualization="metric"
211
+ metricType="count"
212
+ metricLabel="Error Count"
213
+ metricValue={10000}
214
+ totalHits={10000}
215
+ totalRelation="gte"
216
+ series={[]}
217
+ />
218
+ </div>,
219
+ );
220
+
221
+ expect(screen.getByRole('img', { name: /Requests by Service/i })).toBeTruthy();
222
+ expect(screen.getByText('≥')).toBeTruthy();
223
+ expect(screen.getByText(/Hits: 10,000\+/)).toBeTruthy();
224
+
225
+ await act(async () => {
226
+ await user.click(screen.getByRole('button', { name: 'Show data table' }));
227
+ });
228
+ expect(await screen.findByText('checkout')).toBeTruthy();
229
+ expect(screen.getByText('catalog')).toBeTruthy();
230
+ });
231
+
232
+ it('preserves KQL, custom timeRange bounds on Refresh, lockedFilters, shard warnings, and edited filter pills', async () => {
233
+ const user = userEvent.setup();
234
+ const savedSpec = {
235
+ visualization: 'table' as const,
236
+ query: 'status >= 400',
237
+ lockedFilters: [
238
+ { id: 'lock-1', field: 'region', operator: 'eq' as const, value: 'ap-southeast-1', enabled: true },
239
+ ],
240
+ filters: [{ id: 'f1', field: 'service', operator: 'eq' as const, value: 'checkout-api', enabled: true }],
241
+ timeRange: {
242
+ preset: 'custom' as const,
243
+ from: '2026-11-29T00:00:00Z',
244
+ to: '2026-11-30T00:00:00Z',
245
+ },
246
+ columns: ['@timestamp', 'service', 'status'],
247
+ pageSize: 20,
248
+ allowInteractiveControls: true,
249
+ };
250
+
251
+ mocks.request.mockImplementation(async (cfg: { url: string; data?: Record<string, unknown> }) => {
252
+ if (cfg.url === 'esReportService:getReportMeta') {
253
+ return {
254
+ data: {
255
+ data: {
256
+ report: {
257
+ id: 10,
258
+ title: 'Gateway Error Logs (Discover Table)',
259
+ dataViewId: 1,
260
+ visualization: 'table',
261
+ published: true,
262
+ spec: { ...savedSpec },
263
+ },
264
+ dataView: {
265
+ id: 1,
266
+ title: 'Logs',
267
+ dataSourceKey: 'es_main',
268
+ indexPattern: 'logs-*',
269
+ timeField: '@timestamp',
270
+ },
271
+ fields: [
272
+ { name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
273
+ { name: 'service', type: 'keyword', searchable: true, aggregatable: true },
274
+ { name: 'status', type: 'integer', searchable: true, aggregatable: true },
275
+ { name: 'region', type: 'keyword', searchable: true, aggregatable: true },
276
+ ],
277
+ },
278
+ },
279
+ };
280
+ }
281
+
282
+ if (cfg.url === 'esReportService:runReport') {
283
+ return {
284
+ data: {
285
+ data: {
286
+ report: {
287
+ id: 10,
288
+ title: 'Gateway Error Logs (Discover Table)',
289
+ dataViewId: 1,
290
+ visualization: 'table',
291
+ published: true,
292
+ spec: {
293
+ ...savedSpec,
294
+ filters: savedSpec.filters.map((f) => ({ ...f })),
295
+ lockedFilters: savedSpec.lockedFilters.map((f) => ({ ...f })),
296
+ },
297
+ },
298
+ dataView: {
299
+ id: 1,
300
+ title: 'Logs',
301
+ dataSourceKey: 'es_main',
302
+ indexPattern: 'logs-*',
303
+ timeField: '@timestamp',
304
+ },
305
+ result: {
306
+ total: 1,
307
+ totalRelation: 'eq',
308
+ tookMs: 4,
309
+ timedOut: true,
310
+ shards: { total: 5, successful: 4, skipped: 0, failed: 1 },
311
+ visualization: 'table',
312
+ columns: ['@timestamp', 'service', 'status'],
313
+ rows: [
314
+ {
315
+ _id: 'doc-1',
316
+ _index: 'logs-2026',
317
+ source: {
318
+ '@timestamp': '2026-11-30T01:00:00Z',
319
+ service: 'gateway',
320
+ status: 503,
321
+ },
322
+ },
323
+ ],
324
+ series: [],
325
+ histogram: [],
326
+ metricValue: null,
327
+ metricLabel: 'Count',
328
+ compiledDsl: { query: { match_all: {} } },
329
+ },
330
+ },
331
+ },
332
+ };
333
+ }
334
+ return { data: { data: [] } };
335
+ });
336
+
337
+ await act(async () => {
338
+ renderWithoutMotion(<ElasticReportBlock reportId={10} showToolbar={true} />);
339
+ });
340
+
341
+ await waitFor(() => {
342
+ expect(screen.getByText('gateway')).toBeTruthy();
343
+ });
344
+
345
+ // Locked filter badge and partial shard/timeout warning alert are both rendered
346
+ expect(screen.getByText(/region eq ap-southeast-1/)).toBeTruthy();
347
+ expect(screen.getByText('Partial results warning')).toBeTruthy();
348
+ expect(screen.getByText(/Failed shards: 1 \/ 5/)).toBeTruthy();
349
+
350
+ // Clicking Refresh preserves custom timeRange { preset: 'custom', from, to }
351
+ await act(async () => {
352
+ await user.click(screen.getByRole('button', { name: 'Refresh' }));
353
+ });
354
+ await waitFor(() => {
355
+ expect(mocks.request).toHaveBeenCalledWith(
356
+ expect.objectContaining({
357
+ url: 'esReportService:runReport',
358
+ data: expect.objectContaining({
359
+ reportId: 10,
360
+ overrides: expect.objectContaining({
361
+ timeRange: {
362
+ preset: 'custom',
363
+ from: '2026-11-29T00:00:00Z',
364
+ to: '2026-11-30T00:00:00Z',
365
+ },
366
+ }),
367
+ }),
368
+ }),
369
+ );
370
+ });
371
+
372
+ const searchInput = screen.getByRole('combobox', { name: 'KQL / Search Query' }) as HTMLInputElement;
373
+ expect(searchInput.value).toBe('status >= 400');
374
+
375
+ await act(async () => {
376
+ await user.clear(searchInput);
377
+ await user.type(searchInput, 'status >= 500');
378
+ await user.click(screen.getByRole('button', { name: /Search/i }));
379
+ });
380
+
381
+ await waitFor(() => {
382
+ expect(mocks.request).toHaveBeenCalledWith(
383
+ expect.objectContaining({
384
+ url: 'esReportService:runReport',
385
+ data: expect.objectContaining({
386
+ reportId: 10,
387
+ overrides: expect.objectContaining({
388
+ query: 'status >= 500',
389
+ }),
390
+ }),
391
+ }),
392
+ );
393
+ });
394
+ expect(searchInput.value).toBe('status >= 500');
395
+
396
+ // Click existing filter pill to edit its value in place
397
+ await act(async () => {
398
+ await user.click(screen.getByRole('button', { name: 'Edit Filter: service' }));
399
+ });
400
+ const valueInput = await screen.findByDisplayValue('checkout-api');
401
+ await act(async () => {
402
+ await user.clear(valueInput);
403
+ await user.type(valueInput, 'auth-service');
404
+ await user.click(screen.getByRole('button', { name: 'Apply' }));
405
+ });
406
+
407
+ await waitFor(() => {
408
+ expect(mocks.request).toHaveBeenCalledWith(
409
+ expect.objectContaining({
410
+ url: 'esReportService:runReport',
411
+ data: expect.objectContaining({
412
+ reportId: 10,
413
+ overrides: expect.objectContaining({
414
+ query: 'status >= 500',
415
+ filters: [expect.objectContaining({ field: 'service', operator: 'eq', value: 'auth-service' })],
416
+ }),
417
+ }),
418
+ }),
419
+ );
420
+ });
421
+ expect(screen.getByText(/service eq auth-service/)).toBeTruthy();
422
+ });
423
+
424
+ it('supports stacked multi-series charts, KPI delta badges, DashboardFilterBus cross-filtering, cell + filter, and fieldFormats', async () => {
425
+ const user = userEvent.setup();
426
+ const scopeKey = 'page-root-test:ops';
427
+ clearDashboardScope(scopeKey);
428
+
429
+ mocks.request.mockImplementation(async (cfg: { url: string; data?: Record<string, unknown> }) => {
430
+ if (cfg.url === 'esReportService:getReportMeta') {
431
+ return {
432
+ data: {
433
+ data: {
434
+ report: {
435
+ id: 21,
436
+ title: 'Service Latency Table',
437
+ dataViewId: 1,
438
+ visualization: 'table',
439
+ published: true,
440
+ spec: {
441
+ visualization: 'table',
442
+ columns: ['@timestamp', 'service', 'status', 'latency_ms'],
443
+ fieldFormats: {
444
+ status: 'status_badge',
445
+ latency_ms: 'duration_ms',
446
+ },
447
+ contextBindings: [{ esField: 'customer_id', recordFieldPath: 'account.code' }],
448
+ allowInteractiveControls: true,
449
+ allowExport: true,
450
+ },
451
+ },
452
+ dataView: {
453
+ id: 1,
454
+ title: 'Logs',
455
+ dataSourceKey: 'es_main',
456
+ indexPattern: 'logs-*',
457
+ timeField: '@timestamp',
458
+ },
459
+ fields: [
460
+ { name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
461
+ { name: 'service', type: 'keyword', searchable: true, aggregatable: true },
462
+ { name: 'status', type: 'integer', searchable: true, aggregatable: true },
463
+ { name: 'latency_ms', type: 'double', searchable: true, aggregatable: true },
464
+ ],
465
+ },
466
+ },
467
+ };
468
+ }
469
+
470
+ if (cfg.url === 'esReportService:runReport') {
471
+ return {
472
+ data: {
473
+ data: {
474
+ report: {
475
+ id: 21,
476
+ title: 'Service Latency Table',
477
+ dataViewId: 1,
478
+ visualization: 'table',
479
+ published: true,
480
+ spec: {
481
+ visualization: 'table',
482
+ columns: ['@timestamp', 'service', 'status', 'latency_ms'],
483
+ fieldFormats: {
484
+ status: 'status_badge',
485
+ latency_ms: 'duration_ms',
486
+ },
487
+ contextBindings: [{ esField: 'customer_id', recordFieldPath: 'account.code' }],
488
+ allowInteractiveControls: true,
489
+ allowExport: true,
490
+ },
491
+ },
492
+ dataView: {
493
+ id: 1,
494
+ title: 'Logs',
495
+ dataSourceKey: 'es_main',
496
+ indexPattern: 'logs-*',
497
+ timeField: '@timestamp',
498
+ },
499
+ result: {
500
+ total: 1,
501
+ totalRelation: 'eq',
502
+ tookMs: 3,
503
+ visualization: 'table',
504
+ columns: ['@timestamp', 'service', 'status', 'latency_ms'],
505
+ rows: [
506
+ {
507
+ _id: 'doc-21',
508
+ _index: 'logs-2026',
509
+ source: {
510
+ '@timestamp': '2026-11-30T02:00:00Z',
511
+ service: 'payments',
512
+ status: 502,
513
+ latency_ms: 1500,
514
+ },
515
+ },
516
+ ],
517
+ series: [],
518
+ histogram: [],
519
+ metricValue: null,
520
+ metricLabel: 'Count',
521
+ compiledDsl: { query: { match_all: {} } },
522
+ },
523
+ },
524
+ },
525
+ };
526
+ }
527
+ return { data: { data: { buckets: [] } } };
528
+ });
529
+
530
+ await act(async () => {
531
+ renderWithoutMotion(
532
+ <div>
533
+ <ElasticBasicChart
534
+ title="Stacked Latency by Service"
535
+ visualization="bar"
536
+ stackMode="stacked"
537
+ seriesKeys={['checkout', 'payments']}
538
+ metricLabel="P95 Latency"
539
+ metricValue={null}
540
+ totalHits={25}
541
+ series={[
542
+ {
543
+ key: '10:00',
544
+ label: '10:00',
545
+ value: 600,
546
+ count: 25,
547
+ breakdown: [
548
+ { seriesKey: 'checkout', value: 250, count: 15 },
549
+ { seriesKey: 'payments', value: 350, count: 10 },
550
+ ],
551
+ },
552
+ ]}
553
+ />
554
+ <ElasticBasicChart
555
+ title="P95 Latency KPI"
556
+ visualization="metric"
557
+ metricType="p95"
558
+ metricLabel="P95 Latency"
559
+ metricValue={250}
560
+ previousMetricValue={200}
561
+ deltaPercent={25}
562
+ totalHits={100}
563
+ series={[]}
564
+ />
565
+ <ElasticFilterBar scopeKey={scopeKey} showGlobalKql={true} showGlobalTimeRange={true} />
566
+ <ElasticReportBlock
567
+ reportId={21}
568
+ scopeKey={scopeKey}
569
+ subscribeDashboardFilters={true}
570
+ contextRecord={{ account: { code: 'ACME-01' } }}
571
+ />
572
+ </div>,
573
+ );
574
+ });
575
+
576
+ // Formatted duration_ms (1500 -> "1.50 s") and KPI previous-period delta (+25%) are rendered
577
+ await waitFor(() => {
578
+ expect(screen.getByText('1.50 s')).toBeTruthy();
579
+ });
580
+ expect(screen.getByText(/\+25%/)).toBeTruthy();
581
+
582
+ // Context binding filter (customer_id = ACME-01) is sent automatically
583
+ await waitFor(() => {
584
+ expect(mocks.request).toHaveBeenCalledWith(
585
+ expect.objectContaining({
586
+ url: 'esReportService:runReport',
587
+ data: expect.objectContaining({
588
+ reportId: 21,
589
+ overrides: expect.objectContaining({
590
+ contextFilters: [expect.objectContaining({ field: 'customer_id', operator: 'eq', value: 'ACME-01' })],
591
+ }),
592
+ }),
593
+ }),
594
+ );
595
+ });
596
+
597
+ // Global KQL from ElasticFilterBar propagates via DashboardFilterBus to ElasticReportBlock
598
+ const kqlInputs = screen.getAllByRole('combobox', { name: 'KQL / Search Query' });
599
+ await act(async () => {
600
+ await user.type(kqlInputs[0], 'status >= 500');
601
+ await user.click(screen.getByRole('button', { name: 'Apply' }));
602
+ });
603
+
604
+ await waitFor(() => {
605
+ expect(mocks.request).toHaveBeenCalledWith(
606
+ expect.objectContaining({
607
+ url: 'esReportService:runReport',
608
+ data: expect.objectContaining({
609
+ reportId: 21,
610
+ overrides: expect.objectContaining({
611
+ query: 'status >= 500',
612
+ }),
613
+ }),
614
+ }),
615
+ );
616
+ });
617
+
618
+ // Clicking Discover cell "+" button pushes shared cross-filter pill to ElasticFilterBar and re-queries
619
+ await act(async () => {
620
+ await user.click(screen.getByRole('button', { name: 'Filter for value: service=payments' }));
621
+ });
622
+
623
+ await waitFor(() => {
624
+ expect(mocks.request).toHaveBeenCalledWith(
625
+ expect.objectContaining({
626
+ url: 'esReportService:runReport',
627
+ data: expect.objectContaining({
628
+ reportId: 21,
629
+ overrides: expect.objectContaining({
630
+ sharedFilters: [expect.objectContaining({ field: 'service', operator: 'eq', value: 'payments' })],
631
+ }),
632
+ }),
633
+ }),
634
+ );
635
+ });
636
+ expect(screen.getByText(/service eq payments/)).toBeTruthy();
637
+ });
638
+
639
+ it('provides guided KQL autocomplete for fields, operators, live Elasticsearch top values, and Enter-to-submit', async () => {
640
+ const user = userEvent.setup();
641
+
642
+ mocks.request.mockImplementation(async (cfg: { url: string; data?: Record<string, unknown> }) => {
643
+ if (cfg.url === 'esReportService:getReportMeta') {
644
+ return {
645
+ data: {
646
+ data: {
647
+ report: {
648
+ id: 30,
649
+ title: 'Guided Search Report',
650
+ dataViewId: 1,
651
+ visualization: 'table',
652
+ published: true,
653
+ spec: {
654
+ visualization: 'table',
655
+ columns: ['@timestamp', 'service', 'status'],
656
+ allowInteractiveControls: true,
657
+ },
658
+ },
659
+ dataView: {
660
+ id: 1,
661
+ title: 'Logs',
662
+ dataSourceKey: 'es_main',
663
+ indexPattern: 'logs-*',
664
+ timeField: '@timestamp',
665
+ },
666
+ fields: [
667
+ { name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
668
+ { name: 'service', type: 'keyword', searchable: true, aggregatable: true },
669
+ { name: 'status', type: 'integer', searchable: true, aggregatable: true },
670
+ ],
671
+ },
672
+ },
673
+ };
674
+ }
675
+ if (cfg.url === 'esReportService:inspectTopValues') {
676
+ return {
677
+ data: {
678
+ data: {
679
+ field: cfg.data?.field,
680
+ resolvedField: cfg.data?.field,
681
+ totalDocs: 50,
682
+ buckets:
683
+ cfg.data?.field === 'service'
684
+ ? [
685
+ { value: 'gateway', count: 32, percentage: 64 },
686
+ { value: 'billing-api', count: 18, percentage: 36 },
687
+ ]
688
+ : [{ value: '500', count: 20, percentage: 40 }],
689
+ },
690
+ },
691
+ };
692
+ }
693
+ if (cfg.url === 'esReportService:runReport') {
694
+ return {
695
+ data: {
696
+ data: {
697
+ report: {
698
+ id: 30,
699
+ title: 'Guided Search Report',
700
+ dataViewId: 1,
701
+ visualization: 'table',
702
+ published: true,
703
+ spec: {
704
+ visualization: 'table',
705
+ columns: ['@timestamp', 'service', 'status'],
706
+ allowInteractiveControls: true,
707
+ },
708
+ },
709
+ dataView: {
710
+ id: 1,
711
+ title: 'Logs',
712
+ dataSourceKey: 'es_main',
713
+ indexPattern: 'logs-*',
714
+ timeField: '@timestamp',
715
+ },
716
+ result: {
717
+ total: 1,
718
+ totalRelation: 'eq',
719
+ tookMs: 2,
720
+ visualization: 'table',
721
+ columns: ['@timestamp', 'service', 'status'],
722
+ rows: [],
723
+ series: [],
724
+ histogram: [],
725
+ metricValue: null,
726
+ metricLabel: 'Count',
727
+ compiledDsl: { query: { match_all: {} } },
728
+ },
729
+ },
730
+ },
731
+ };
732
+ }
733
+ return { data: { data: [] } };
734
+ });
735
+
736
+ await act(async () => {
737
+ renderWithoutMotion(<ElasticReportBlock reportId={30} showToolbar={true} />);
738
+ });
739
+
740
+ const kqlCombo = await screen.findByRole('combobox', { name: 'KQL / Search Query' });
741
+
742
+ // 1. Focus empty search input -> field suggestions appear
743
+ await act(async () => {
744
+ await user.click(kqlCombo);
745
+ });
746
+ const serviceFieldOpt = await screen.findByRole('option', { name: /service/i });
747
+
748
+ // 2. Click `service` -> inserts `service: ` and automatically loads live top values from Elasticsearch
749
+ await act(async () => {
750
+ await user.click(serviceFieldOpt);
751
+ });
752
+ expect((kqlCombo as HTMLInputElement).value).toBe('service: ');
753
+
754
+ const gatewayValOpt = await screen.findByRole('option', { name: /"gateway"/i });
755
+ expect(mocks.request).toHaveBeenCalledWith(
756
+ expect.objectContaining({
757
+ url: 'esReportService:inspectTopValues',
758
+ data: expect.objectContaining({
759
+ reportId: 30,
760
+ field: 'service',
761
+ overrides: expect.objectContaining({
762
+ query: '',
763
+ }),
764
+ }),
765
+ }),
766
+ );
767
+ await act(async () => {
768
+ await user.click(gatewayValOpt);
769
+ });
770
+ expect((kqlCombo as HTMLInputElement).value).toBe('service: "gateway" ');
771
+
772
+ // 3. Press Enter directly without highlighting another option -> executes the search immediately
773
+ await act(async () => {
774
+ await user.keyboard('{Enter}');
775
+ });
776
+
777
+ await waitFor(() => {
778
+ expect(mocks.request).toHaveBeenCalledWith(
779
+ expect.objectContaining({
780
+ url: 'esReportService:runReport',
781
+ data: expect.objectContaining({
782
+ reportId: 30,
783
+ overrides: expect.objectContaining({
784
+ query: 'service: "gateway"',
785
+ }),
786
+ }),
787
+ }),
788
+ );
789
+ });
790
+ });
791
+ });