plugin-elastic-report 0.0.0-stage → 0.1.1

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 (257) hide show
  1. package/ai/skills/elastic-report/SKILLS.md +32 -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/index.js +10 -0
  7. package/dist/client-v2/851.488fdbf5bc5b6a36.js +10 -0
  8. package/dist/client-v2/index.js +10 -0
  9. package/dist/externalVersion.js +20 -0
  10. package/dist/index.js +48 -0
  11. package/dist/locale/en-US.json +99 -0
  12. package/dist/locale/vi-VN.json +99 -0
  13. package/dist/locale/zh-CN.json +99 -0
  14. package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
  15. package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
  16. package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
  17. package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
  18. package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
  19. package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
  20. package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
  21. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
  22. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
  23. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
  24. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
  25. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
  26. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
  27. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
  28. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
  29. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
  30. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
  31. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
  32. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
  33. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
  34. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
  35. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
  36. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
  37. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
  38. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
  39. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
  40. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
  41. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
  42. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
  43. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
  44. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
  45. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
  46. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
  47. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
  48. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
  49. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
  50. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
  51. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
  52. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
  53. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
  54. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
  55. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
  56. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
  57. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
  58. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
  59. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
  60. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
  61. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
  62. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
  63. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
  64. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
  65. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
  66. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
  67. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
  68. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
  69. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
  70. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
  71. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
  72. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
  73. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
  74. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
  75. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
  76. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
  77. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
  78. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
  79. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
  80. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
  81. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
  82. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
  83. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
  84. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
  85. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
  86. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
  87. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
  88. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
  89. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
  90. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
  91. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
  92. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
  93. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
  94. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
  95. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
  96. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
  97. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
  98. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
  99. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
  100. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
  101. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
  102. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
  103. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
  104. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
  105. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
  106. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
  107. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
  108. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
  109. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
  110. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
  111. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
  112. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
  113. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
  114. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
  115. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
  116. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
  117. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
  118. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
  119. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
  120. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
  121. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
  122. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
  123. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
  124. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
  125. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
  126. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
  127. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
  128. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
  129. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
  130. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
  131. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
  132. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
  133. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
  134. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
  135. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
  136. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
  137. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
  138. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
  139. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
  140. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
  141. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
  142. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
  143. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
  144. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
  145. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
  146. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
  147. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
  148. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
  149. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
  150. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
  151. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
  152. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
  153. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
  154. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
  155. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
  156. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
  157. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
  158. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
  159. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
  160. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
  161. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
  162. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
  163. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
  164. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
  165. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
  166. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
  167. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
  168. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
  169. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
  170. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
  171. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
  172. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
  173. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
  174. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
  175. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
  176. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
  177. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
  178. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
  179. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
  180. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
  181. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
  182. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
  183. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
  184. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
  185. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
  186. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
  187. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
  188. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
  189. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
  190. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
  191. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
  192. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
  193. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
  194. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
  195. package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
  196. package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
  197. package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
  198. package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
  199. package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
  200. package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
  201. package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
  202. package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
  203. package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
  204. package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
  205. package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
  206. package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
  207. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
  208. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
  209. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
  210. package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
  211. package/dist/server/acl-guard.js +107 -0
  212. package/dist/server/collections/es-report-data-views.js +79 -0
  213. package/dist/server/collections/es-reports.js +95 -0
  214. package/dist/server/index.js +58 -0
  215. package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
  216. package/dist/server/mcp/ElasticReportToolCatalog.js +417 -0
  217. package/dist/server/plugin.js +395 -0
  218. package/dist/server/services/ElasticReportService.js +263 -0
  219. package/dist/server/services/ElasticsearchConnectionService.js +332 -0
  220. package/dist/server/services/ReportQueryCompiler.js +858 -0
  221. package/dist/shared/constants.js +81 -0
  222. package/dist/shared/types.js +24 -0
  223. package/package.json +61 -4
  224. package/server.d.ts +2 -0
  225. package/server.js +1 -0
  226. package/src/client/index.tsx +19 -0
  227. package/src/client-v2/__tests__/elastic-report.test.tsx +311 -0
  228. package/src/client-v2/api.ts +224 -0
  229. package/src/client-v2/components/ElasticBasicCharts.tsx +399 -0
  230. package/src/client-v2/components/ElasticReportBlock.tsx +160 -0
  231. package/src/client-v2/components/ElasticReportRenderer.tsx +707 -0
  232. package/src/client-v2/components/HighlightText.tsx +50 -0
  233. package/src/client-v2/components/ReportSelect.tsx +72 -0
  234. package/src/client-v2/index.tsx +14 -0
  235. package/src/client-v2/locale.ts +23 -0
  236. package/src/client-v2/models/ElasticReportBlockModel.tsx +85 -0
  237. package/src/client-v2/pages/ElasticReportManager.tsx +1047 -0
  238. package/src/client-v2/plugin.tsx +52 -0
  239. package/src/index.ts +11 -0
  240. package/src/locale/en-US.json +99 -0
  241. package/src/locale/vi-VN.json +99 -0
  242. package/src/locale/zh-CN.json +99 -0
  243. package/src/server/__tests__/query-compiler.test.ts +231 -0
  244. package/src/server/__tests__/report-mcp-acl.integration.test.ts +377 -0
  245. package/src/server/acl-guard.ts +103 -0
  246. package/src/server/collections/es-report-data-views.ts +58 -0
  247. package/src/server/collections/es-reports.ts +74 -0
  248. package/src/server/index.ts +15 -0
  249. package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
  250. package/src/server/mcp/ElasticReportToolCatalog.ts +417 -0
  251. package/src/server/plugin.ts +431 -0
  252. package/src/server/services/ElasticReportService.ts +326 -0
  253. package/src/server/services/ElasticsearchConnectionService.ts +401 -0
  254. package/src/server/services/ReportQueryCompiler.ts +1017 -0
  255. package/src/shared/constants.ts +29 -0
  256. package/src/shared/types.ts +175 -0
  257. package/README.md +0 -3
@@ -0,0 +1,707 @@
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 { CodeOutlined, FilterOutlined, ReloadOutlined, RollbackOutlined, SearchOutlined } from '@ant-design/icons';
11
+ import {
12
+ Alert,
13
+ Button,
14
+ Descriptions,
15
+ Drawer,
16
+ Empty,
17
+ Form,
18
+ Input,
19
+ Modal,
20
+ Popover,
21
+ Select,
22
+ Space,
23
+ Spin,
24
+ Table,
25
+ Tabs,
26
+ Tag,
27
+ Typography,
28
+ } from 'antd';
29
+ import type { TableColumnsType } from 'antd';
30
+ import React, { useEffect, useId, useMemo, useRef, useState } from 'react';
31
+ import type {
32
+ EsDataViewRecord,
33
+ EsFieldCapability,
34
+ FilterOperator,
35
+ ReportExecutionResult,
36
+ ReportFilterItem,
37
+ ReportRowHit,
38
+ ReportRuntimeOverrides,
39
+ ReportSortItem,
40
+ ReportSpec,
41
+ TimeRangePreset,
42
+ } from '../../shared/types';
43
+ import { useT } from '../locale';
44
+ import { ElasticBasicChart, ReportHistogramStrip } from './ElasticBasicCharts';
45
+ import { HighlightText } from './HighlightText';
46
+
47
+ const { Text } = Typography;
48
+
49
+ const VISUALLY_HIDDEN_STYLE: React.CSSProperties = {
50
+ position: 'absolute',
51
+ clipPath: 'inset(50%)',
52
+ overflow: 'hidden',
53
+ width: 1,
54
+ height: 1,
55
+ margin: -1,
56
+ padding: 0,
57
+ border: 0,
58
+ whiteSpace: 'nowrap',
59
+ };
60
+
61
+ const OPERATOR_OPTIONS: Array<{ label: string; value: FilterOperator; needsValue: boolean; needsRange?: boolean }> = [
62
+ { label: 'is (=)', value: 'eq', needsValue: true },
63
+ { label: 'is not (!=)', value: 'ne', needsValue: true },
64
+ { label: 'contains', value: 'contains', needsValue: true },
65
+ { label: 'is one of (in)', value: 'in', needsValue: true },
66
+ { label: 'is not one of', value: 'not_in', needsValue: true },
67
+ { label: '>', value: 'gt', needsValue: true },
68
+ { label: '>=', value: 'gte', needsValue: true },
69
+ { label: '<', value: 'lt', needsValue: true },
70
+ { label: '<=', value: 'lte', needsValue: true },
71
+ { label: 'between', value: 'between', needsValue: true, needsRange: true },
72
+ { label: 'exists', value: 'exists', needsValue: false },
73
+ { label: 'does not exist', value: 'not_exists', needsValue: false },
74
+ ];
75
+
76
+ function getNestedValue(source: Record<string, unknown>, path: string): unknown {
77
+ if (path in source) return source[path];
78
+ const parts = path.split('.');
79
+ let current: unknown = source;
80
+ for (const part of parts) {
81
+ if (
82
+ current &&
83
+ typeof current === 'object' &&
84
+ !Array.isArray(current) &&
85
+ part in (current as Record<string, unknown>)
86
+ ) {
87
+ current = (current as Record<string, unknown>)[part];
88
+ } else {
89
+ return undefined;
90
+ }
91
+ }
92
+ return current;
93
+ }
94
+
95
+ function formatCellValue(value: unknown): string {
96
+ if (value === null || value === undefined) return '—';
97
+ if (typeof value === 'string') return value;
98
+ if (typeof value === 'number' || typeof value === 'boolean') return String(value);
99
+ try {
100
+ return JSON.stringify(value);
101
+ } catch {
102
+ return String(value);
103
+ }
104
+ }
105
+
106
+ export interface ElasticReportRendererProps {
107
+ title: string;
108
+ spec: ReportSpec;
109
+ dataView?: EsDataViewRecord | null;
110
+ fields?: EsFieldCapability[];
111
+ result?: ReportExecutionResult | null;
112
+ loading?: boolean;
113
+ error?: string | null;
114
+ showToolbar?: boolean;
115
+ compact?: boolean;
116
+ onExecute: (overrides: ReportRuntimeOverrides) => void;
117
+ }
118
+
119
+ export const ElasticReportRenderer: React.FC<ElasticReportRendererProps> = ({
120
+ title,
121
+ spec,
122
+ dataView,
123
+ fields = [],
124
+ result,
125
+ loading = false,
126
+ error = null,
127
+ showToolbar = true,
128
+ compact = false,
129
+ onExecute,
130
+ }) => {
131
+ const t = useT();
132
+ const regionLabelId = useId();
133
+
134
+ const [queryText, setQueryText] = useState<string>(spec.query ?? '');
135
+ const [filters, setFilters] = useState<ReportFilterItem[]>(spec.filters ?? []);
136
+ const [sort, setSort] = useState<ReportSortItem[]>(spec.sort ?? []);
137
+ const [timePreset, setTimePreset] = useState<TimeRangePreset>(spec.timeRange?.preset ?? 'last_24h');
138
+ const [page, setPage] = useState<number>(1);
139
+ const [cursorHistory, setCursorHistory] = useState<Array<Array<string | number | boolean | null>>>([]);
140
+
141
+ const [filterPopoverOpen, setFilterPopoverOpen] = useState(false);
142
+ const [editingFilterIdx, setEditingFilterIdx] = useState<number | null>(null);
143
+ const [draftFilterField, setDraftFilterField] = useState<string>('');
144
+ const [draftFilterOp, setDraftFilterOp] = useState<FilterOperator>('eq');
145
+ const [draftFilterValue, setDraftFilterValue] = useState<string>('');
146
+ const [draftFilterValueTo, setDraftFilterValueTo] = useState<string>('');
147
+
148
+ const [inspectDslOpen, setInspectDslOpen] = useState(false);
149
+ const [selectedDoc, setSelectedDoc] = useState<ReportRowHit | null>(null);
150
+
151
+ const serializedSpec = useMemo(() => JSON.stringify(spec), [spec]);
152
+ const appliedSpecRef = useRef<string>(serializedSpec);
153
+
154
+ useEffect(() => {
155
+ if (appliedSpecRef.current === serializedSpec) {
156
+ return;
157
+ }
158
+ appliedSpecRef.current = serializedSpec;
159
+ setQueryText(spec.query ?? '');
160
+ setFilters(spec.filters ?? []);
161
+ setSort(spec.sort ?? []);
162
+ setTimePreset(spec.timeRange?.preset ?? 'last_24h');
163
+ setPage(1);
164
+ setCursorHistory([]);
165
+ }, [serializedSpec, spec]);
166
+
167
+ const aggregatableFields = useMemo(
168
+ () => fields.filter((f) => f.aggregatable || Boolean(f.keywordSubfield)),
169
+ [fields],
170
+ );
171
+
172
+ const timeRangeOptions: Array<{ label: string; value: TimeRangePreset }> = useMemo(
173
+ () => [
174
+ { label: t('Last 15 minutes'), value: 'last_15m' },
175
+ { label: t('Last 1 hour'), value: 'last_1h' },
176
+ { label: t('Last 24 hours'), value: 'last_24h' },
177
+ { label: t('Last 7 days'), value: 'last_7d' },
178
+ { label: t('Last 30 days'), value: 'last_30d' },
179
+ { label: t('Last 90 days'), value: 'last_90d' },
180
+ { label: t('All time'), value: 'all' },
181
+ ],
182
+ [t],
183
+ );
184
+
185
+ const triggerQuery = (nextOverrides?: Partial<ReportRuntimeOverrides>) => {
186
+ const merged: ReportRuntimeOverrides = {
187
+ query: nextOverrides?.query !== undefined ? nextOverrides.query : queryText,
188
+ filters: nextOverrides?.filters !== undefined ? nextOverrides.filters : filters,
189
+ sort: nextOverrides?.sort !== undefined ? nextOverrides.sort : sort,
190
+ timeRange: nextOverrides?.timeRange !== undefined ? nextOverrides.timeRange : { preset: timePreset },
191
+ page: nextOverrides?.page ?? 1,
192
+ pageSize: spec.pageSize ?? 20,
193
+ ...(nextOverrides?.searchAfter ? { searchAfter: nextOverrides.searchAfter } : {}),
194
+ };
195
+ onExecute(merged);
196
+ };
197
+
198
+ const openAddFilterPopover = () => {
199
+ setEditingFilterIdx(null);
200
+ setDraftFilterOp('eq');
201
+ setDraftFilterValue('');
202
+ setDraftFilterValueTo('');
203
+ setFilterPopoverOpen(true);
204
+ };
205
+
206
+ const openEditFilterPopover = (idx: number) => {
207
+ const item = filters[idx];
208
+ if (!item) return;
209
+ setEditingFilterIdx(idx);
210
+ setDraftFilterField(item.field);
211
+ setDraftFilterOp(item.operator);
212
+ setDraftFilterValue(
213
+ Array.isArray(item.value) ? item.value.join(', ') : item.value !== undefined ? String(item.value) : '',
214
+ );
215
+ setDraftFilterValueTo(item.valueTo !== undefined ? String(item.valueTo) : '');
216
+ setFilterPopoverOpen(true);
217
+ };
218
+
219
+ const handleSaveFilterPill = () => {
220
+ if (!draftFilterField) return;
221
+ const opMeta = OPERATOR_OPTIONS.find((o) => o.value === draftFilterOp);
222
+ const parsedValue =
223
+ draftFilterOp === 'in' || draftFilterOp === 'not_in'
224
+ ? draftFilterValue
225
+ .split(',')
226
+ .map((part) => part.trim())
227
+ .filter(Boolean)
228
+ : draftFilterValue;
229
+ const nextItem: ReportFilterItem = {
230
+ id: editingFilterIdx !== null ? filters[editingFilterIdx]?.id ?? `${Date.now()}` : `${Date.now()}`,
231
+ field: draftFilterField,
232
+ operator: draftFilterOp,
233
+ ...(opMeta?.needsValue ? { value: parsedValue } : {}),
234
+ ...(opMeta?.needsRange && draftFilterValueTo ? { valueTo: draftFilterValueTo } : {}),
235
+ enabled: true,
236
+ };
237
+ const updated =
238
+ editingFilterIdx !== null
239
+ ? filters.map((item, i) => (i === editingFilterIdx ? nextItem : item))
240
+ : [...filters, nextItem];
241
+ setFilters(updated);
242
+ setPage(1);
243
+ setCursorHistory([]);
244
+ setFilterPopoverOpen(false);
245
+ setEditingFilterIdx(null);
246
+ setDraftFilterValue('');
247
+ setDraftFilterValueTo('');
248
+ triggerQuery({ filters: updated, page: 1 });
249
+ };
250
+
251
+ const handleRemoveFilter = (idx: number) => {
252
+ const updated = filters.filter((_, i) => i !== idx);
253
+ setFilters(updated);
254
+ setPage(1);
255
+ setCursorHistory([]);
256
+ triggerQuery({ filters: updated, page: 1 });
257
+ };
258
+
259
+ const handleReset = () => {
260
+ const baseQuery = spec.query ?? '';
261
+ const baseFilters = spec.filters ?? [];
262
+ const baseSort = spec.sort ?? [];
263
+ const basePreset = spec.timeRange?.preset ?? 'last_24h';
264
+ setQueryText(baseQuery);
265
+ setFilters(baseFilters);
266
+ setSort(baseSort);
267
+ setTimePreset(basePreset);
268
+ setPage(1);
269
+ setCursorHistory([]);
270
+ onExecute({
271
+ query: baseQuery,
272
+ filters: baseFilters,
273
+ sort: baseSort,
274
+ timeRange: spec.timeRange ?? { preset: basePreset },
275
+ page: 1,
276
+ pageSize: spec.pageSize ?? 20,
277
+ });
278
+ };
279
+
280
+ const handleBucketDrilldown = (bucketKey: string) => {
281
+ if (!showToolbar || spec.allowInteractiveControls === false) return;
282
+ const bucketField = spec.chart?.bucketField || dataView?.timeField;
283
+ if (!bucketField || spec.chart?.bucketType === 'date_histogram') return;
284
+ const updated: ReportFilterItem[] = [
285
+ ...filters,
286
+ { id: `${Date.now()}`, field: bucketField, operator: 'eq', value: bucketKey, enabled: true },
287
+ ];
288
+ setFilters(updated);
289
+ triggerQuery({ filters: updated, page: 1 });
290
+ };
291
+
292
+ const activeColumns = useMemo(() => result?.columns ?? spec.columns ?? [], [result?.columns, spec.columns]);
293
+
294
+ const tableColumns: TableColumnsType<ReportRowHit> = useMemo(
295
+ () =>
296
+ activeColumns.map((colName) => {
297
+ const activeSort = sort.find((s) => s.field === colName || s.field === `${colName}.keyword`);
298
+ const canSortCol = aggregatableFields.some((f) => f.name === colName || f.name === `${colName}.keyword`);
299
+ return {
300
+ title: colName,
301
+ key: colName,
302
+ ellipsis: true,
303
+ ...(canSortCol
304
+ ? {
305
+ sorter: true,
306
+ sortOrder: activeSort ? (activeSort.order === 'asc' ? 'ascend' : 'descend') : null,
307
+ }
308
+ : {}),
309
+ render: (_: unknown, record: ReportRowHit) => {
310
+ const hl = record.highlights?.[colName]?.[0];
311
+ if (hl) {
312
+ return <HighlightText text={hl} />;
313
+ }
314
+ const rawVal =
315
+ colName === '_id'
316
+ ? record._id
317
+ : colName === '_index'
318
+ ? record._index
319
+ : getNestedValue(record.source, colName);
320
+ return <span>{formatCellValue(rawVal)}</span>;
321
+ },
322
+ };
323
+ }),
324
+ [activeColumns, aggregatableFields, sort],
325
+ );
326
+
327
+ const canInteract = showToolbar && spec.allowInteractiveControls !== false;
328
+ const currentOpMeta = OPERATOR_OPTIONS.find((o) => o.value === draftFilterOp);
329
+
330
+ return (
331
+ <div>
332
+ {/* Polite status region announces updated hit counts for screen readers without putting aria-live on <table> */}
333
+ <div role="status" aria-live="polite" style={VISUALLY_HIDDEN_STYLE}>
334
+ {!loading && result ? `${title}: ${result.total} ${t('Hits')}` : ''}
335
+ </div>
336
+
337
+ {canInteract && (
338
+ <div style={{ marginBottom: 12 }}>
339
+ <Space wrap style={{ width: '100%', justifyContent: 'space-between' }}>
340
+ <Space wrap>
341
+ <Input
342
+ allowClear
343
+ aria-label={t('KQL / Search Query')}
344
+ placeholder={t('Search KQL, e.g. status >= 500 AND service: "api"')}
345
+ prefix={<SearchOutlined aria-hidden="true" />}
346
+ value={queryText}
347
+ style={{ minWidth: compact ? 220 : 320 }}
348
+ onChange={(e) => {
349
+ const nextVal = e.target.value;
350
+ setQueryText(nextVal);
351
+ if (nextVal === '' && e.type === 'click') {
352
+ setPage(1);
353
+ setCursorHistory([]);
354
+ triggerQuery({ query: '', page: 1 });
355
+ }
356
+ }}
357
+ onPressEnter={() => {
358
+ setPage(1);
359
+ setCursorHistory([]);
360
+ triggerQuery({ query: queryText, page: 1 });
361
+ }}
362
+ />
363
+ {dataView?.timeField && (
364
+ <Select
365
+ aria-label={t('Time Field')}
366
+ value={timePreset}
367
+ options={timeRangeOptions}
368
+ style={{ minWidth: 150 }}
369
+ onChange={(nextPreset) => {
370
+ setTimePreset(nextPreset);
371
+ setPage(1);
372
+ setCursorHistory([]);
373
+ triggerQuery({ timeRange: { preset: nextPreset }, page: 1 });
374
+ }}
375
+ />
376
+ )}
377
+ <Popover
378
+ trigger="click"
379
+ title={editingFilterIdx !== null ? t('Edit Filter') : t('Add Filter')}
380
+ open={filterPopoverOpen}
381
+ onOpenChange={(open) => {
382
+ setFilterPopoverOpen(open);
383
+ if (!open) {
384
+ setEditingFilterIdx(null);
385
+ }
386
+ }}
387
+ content={
388
+ <div style={{ width: 280 }}>
389
+ <Form layout="vertical" size="small">
390
+ <Form.Item label={t('Field')} style={{ marginBottom: 8 }}>
391
+ <Select
392
+ showSearch
393
+ value={draftFilterField || undefined}
394
+ placeholder={t('Field')}
395
+ options={fields.map((f) => ({ label: `${f.name} (${f.type})`, value: f.name }))}
396
+ onChange={(val) => setDraftFilterField(val)}
397
+ />
398
+ </Form.Item>
399
+ <Form.Item label={t('Operator')} style={{ marginBottom: 8 }}>
400
+ <Select
401
+ value={draftFilterOp}
402
+ options={OPERATOR_OPTIONS.map((o) => ({ label: o.label, value: o.value }))}
403
+ onChange={(val) => setDraftFilterOp(val)}
404
+ />
405
+ </Form.Item>
406
+ {currentOpMeta?.needsValue && (
407
+ <Form.Item label={t('Value')} style={{ marginBottom: 8 }}>
408
+ <Input value={draftFilterValue} onChange={(e) => setDraftFilterValue(e.target.value)} />
409
+ </Form.Item>
410
+ )}
411
+ {currentOpMeta?.needsRange && (
412
+ <Form.Item label={t('To Value')} style={{ marginBottom: 8 }}>
413
+ <Input value={draftFilterValueTo} onChange={(e) => setDraftFilterValueTo(e.target.value)} />
414
+ </Form.Item>
415
+ )}
416
+ <Space style={{ justifyContent: 'flex-end', width: '100%' }}>
417
+ <Button
418
+ size="small"
419
+ onClick={() => {
420
+ setFilterPopoverOpen(false);
421
+ setEditingFilterIdx(null);
422
+ }}
423
+ >
424
+ {t('Cancel')}
425
+ </Button>
426
+ <Button size="small" type="primary" onClick={handleSaveFilterPill}>
427
+ {t('Apply')}
428
+ </Button>
429
+ </Space>
430
+ </Form>
431
+ </div>
432
+ }
433
+ >
434
+ <Button icon={<FilterOutlined />} onClick={openAddFilterPopover}>
435
+ {t('Add Filter')}
436
+ </Button>
437
+ </Popover>
438
+
439
+ {spec.visualization === 'table' && aggregatableFields.length > 0 && (
440
+ <Select
441
+ allowClear
442
+ aria-label={t('Sort')}
443
+ placeholder={t('Sort')}
444
+ style={{ minWidth: 170 }}
445
+ value={sort[0] ? `${sort[0].field}:${sort[0].order}` : undefined}
446
+ options={aggregatableFields.slice(0, 40).flatMap((f) => [
447
+ { label: `${f.name} ↓`, value: `${f.name}:desc` },
448
+ { label: `${f.name} ↑`, value: `${f.name}:asc` },
449
+ ])}
450
+ onChange={(encoded) => {
451
+ if (!encoded) {
452
+ setSort([]);
453
+ setPage(1);
454
+ setCursorHistory([]);
455
+ triggerQuery({ sort: [], page: 1 });
456
+ return;
457
+ }
458
+ const lastColon = encoded.lastIndexOf(':');
459
+ const nextSort: ReportSortItem[] = [
460
+ {
461
+ field: encoded.slice(0, lastColon),
462
+ order: encoded.slice(lastColon + 1) === 'asc' ? 'asc' : 'desc',
463
+ },
464
+ ];
465
+ setSort(nextSort);
466
+ setPage(1);
467
+ setCursorHistory([]);
468
+ triggerQuery({ sort: nextSort, page: 1 });
469
+ }}
470
+ />
471
+ )}
472
+ </Space>
473
+
474
+ <Space>
475
+ <Button
476
+ type="primary"
477
+ icon={<SearchOutlined />}
478
+ onClick={() => {
479
+ setPage(1);
480
+ setCursorHistory([]);
481
+ triggerQuery({ page: 1 });
482
+ }}
483
+ >
484
+ {t('Search')}
485
+ </Button>
486
+ <Button icon={<ReloadOutlined />} aria-label={t('Refresh')} onClick={() => triggerQuery({ page })} />
487
+ <Button icon={<RollbackOutlined />} onClick={handleReset}>
488
+ {t('Reset')}
489
+ </Button>
490
+ {result?.compiledDsl && (
491
+ <Button icon={<CodeOutlined />} onClick={() => setInspectDslOpen(true)}>
492
+ {t('Inspect DSL')}
493
+ </Button>
494
+ )}
495
+ </Space>
496
+ </Space>
497
+
498
+ {filters.length > 0 && (
499
+ <div style={{ marginTop: 8, display: 'flex', flexWrap: 'wrap', gap: 6 }}>
500
+ {filters.map((flt, idx) => (
501
+ <Tag
502
+ key={flt.id || `${flt.field}-${idx}`}
503
+ closable
504
+ color="processing"
505
+ onClose={(e) => {
506
+ e.preventDefault();
507
+ e.stopPropagation();
508
+ handleRemoveFilter(idx);
509
+ }}
510
+ >
511
+ <span
512
+ role="button"
513
+ tabIndex={0}
514
+ aria-label={`${t('Edit Filter')}: ${flt.field}`}
515
+ style={{ cursor: 'pointer' }}
516
+ onClick={() => openEditFilterPopover(idx)}
517
+ onKeyDown={(e) => {
518
+ if (e.key === 'Enter' || e.key === ' ') {
519
+ e.preventDefault();
520
+ openEditFilterPopover(idx);
521
+ }
522
+ }}
523
+ >
524
+ {flt.field} {flt.operator}
525
+ {flt.value !== undefined
526
+ ? ` ${Array.isArray(flt.value) ? flt.value.join(', ') : String(flt.value)}`
527
+ : ''}
528
+ {flt.valueTo !== undefined ? ` .. ${String(flt.valueTo)}` : ''}
529
+ </span>
530
+ </Tag>
531
+ ))}
532
+ </div>
533
+ )}
534
+ </div>
535
+ )}
536
+
537
+ {error && <Alert type="error" showIcon message={error} style={{ marginBottom: 12 }} />}
538
+
539
+ <Spin spinning={loading}>
540
+ {!result ? (
541
+ <Empty description={t('No matching documents')} />
542
+ ) : spec.visualization === 'table' ? (
543
+ <div>
544
+ {result.histogram.length > 0 && spec.chart?.showHistogram !== false && (
545
+ <ReportHistogramStrip buckets={result.histogram} />
546
+ )}
547
+ <div
548
+ style={{
549
+ display: 'flex',
550
+ justifyContent: 'space-between',
551
+ alignItems: 'center',
552
+ marginBottom: 8,
553
+ fontSize: 12,
554
+ }}
555
+ >
556
+ <Text id={regionLabelId} strong>
557
+ {title} · {t('Hits')}: {result.total.toLocaleString()}
558
+ {result.totalRelation === 'gte' ? '+' : ''} ({result.tookMs} ms)
559
+ </Text>
560
+ {result.nextSearchAfter && cursorHistory.length > 0 && (
561
+ <Button
562
+ size="small"
563
+ onClick={() => {
564
+ setPage(1);
565
+ setCursorHistory([]);
566
+ triggerQuery({ page: 1 });
567
+ }}
568
+ >
569
+ {t('First page')}
570
+ </Button>
571
+ )}
572
+ </div>
573
+
574
+ <div
575
+ role="region"
576
+ aria-labelledby={regionLabelId}
577
+ tabIndex={0}
578
+ style={{ overflowX: 'auto', maxInlineSize: '100%', containerType: 'inline-size' }}
579
+ >
580
+ <Table<ReportRowHit>
581
+ size={compact ? 'small' : 'middle'}
582
+ rowKey={(record) => `${record._index}:${record._id}`}
583
+ columns={tableColumns}
584
+ dataSource={result.rows}
585
+ onRow={(record) => ({
586
+ onClick: () => setSelectedDoc(record),
587
+ style: { cursor: 'pointer' },
588
+ })}
589
+ onChange={(pagination, _tableFilters, sorter) => {
590
+ const singleSorter = Array.isArray(sorter) ? sorter[0] : sorter;
591
+ if (singleSorter && singleSorter.columnKey && singleSorter.order) {
592
+ const nextSort: ReportSortItem[] = [
593
+ {
594
+ field: String(singleSorter.columnKey),
595
+ order: singleSorter.order === 'ascend' ? 'asc' : 'desc',
596
+ },
597
+ ];
598
+ setSort(nextSort);
599
+ setPage(1);
600
+ setCursorHistory([]);
601
+ triggerQuery({ sort: nextSort, page: 1 });
602
+ return;
603
+ }
604
+
605
+ const nextPage = pagination.current ?? 1;
606
+ const pageSize = spec.pageSize ?? 20;
607
+ if (nextPage * pageSize > 10000 && result.nextSearchAfter) {
608
+ const updatedHistory = [...cursorHistory, result.nextSearchAfter];
609
+ setCursorHistory(updatedHistory);
610
+ setPage(nextPage);
611
+ triggerQuery({ page: nextPage, searchAfter: result.nextSearchAfter });
612
+ return;
613
+ }
614
+ setPage(nextPage);
615
+ triggerQuery({ page: nextPage });
616
+ }}
617
+ pagination={{
618
+ current: page,
619
+ pageSize: spec.pageSize ?? 20,
620
+ total: Math.min(result.total, 10000),
621
+ showSizeChanger: false,
622
+ }}
623
+ />
624
+ </div>
625
+
626
+ {result.total >= 10000 && result.nextSearchAfter && (
627
+ <div style={{ marginTop: 8, textAlign: 'right' }}>
628
+ <Button
629
+ size="small"
630
+ onClick={() => {
631
+ if (!result.nextSearchAfter) return;
632
+ const updatedHistory = [...cursorHistory, result.nextSearchAfter];
633
+ setCursorHistory(updatedHistory);
634
+ setPage((p) => p + 1);
635
+ triggerQuery({ searchAfter: result.nextSearchAfter });
636
+ }}
637
+ >
638
+ {t('Next cursor page')}
639
+ </Button>
640
+ </div>
641
+ )}
642
+ </div>
643
+ ) : (
644
+ <ElasticBasicChart
645
+ title={title}
646
+ visualization={spec.visualization}
647
+ series={result.series}
648
+ metricValue={result.metricValue}
649
+ metricLabel={result.metricLabel}
650
+ totalHits={result.total}
651
+ onSelectBucket={handleBucketDrilldown}
652
+ />
653
+ )}
654
+ </Spin>
655
+
656
+ <Modal
657
+ title={t('Elasticsearch Query DSL')}
658
+ open={inspectDslOpen}
659
+ footer={null}
660
+ onCancel={() => setInspectDslOpen(false)}
661
+ width={680}
662
+ >
663
+ <pre style={{ maxHeight: 420, overflow: 'auto', fontSize: 12 }}>
664
+ {JSON.stringify(result?.compiledDsl ?? {}, null, 2)}
665
+ </pre>
666
+ </Modal>
667
+
668
+ <Drawer
669
+ title={t('Document Details')}
670
+ open={Boolean(selectedDoc)}
671
+ onClose={() => setSelectedDoc(null)}
672
+ width={640}
673
+ >
674
+ {selectedDoc && (
675
+ <Tabs
676
+ items={[
677
+ {
678
+ key: 'table',
679
+ label: t('Table View'),
680
+ children: (
681
+ <Descriptions bordered column={1} size="small">
682
+ <Descriptions.Item label="_index">{selectedDoc._index}</Descriptions.Item>
683
+ <Descriptions.Item label="_id">{selectedDoc._id}</Descriptions.Item>
684
+ {Object.entries(selectedDoc.source).map(([k, v]) => (
685
+ <Descriptions.Item key={k} label={k}>
686
+ {formatCellValue(v)}
687
+ </Descriptions.Item>
688
+ ))}
689
+ </Descriptions>
690
+ ),
691
+ },
692
+ {
693
+ key: 'json',
694
+ label: t('JSON View'),
695
+ children: (
696
+ <pre style={{ maxHeight: 520, overflow: 'auto', fontSize: 12 }}>
697
+ {JSON.stringify(selectedDoc, null, 2)}
698
+ </pre>
699
+ ),
700
+ },
701
+ ]}
702
+ />
703
+ )}
704
+ </Drawer>
705
+ </div>
706
+ );
707
+ };