@e-llm-studio/federated-dashboard-components 2.2.4 → 2.2.6-test

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 (131) hide show
  1. package/README.md +297 -0
  2. package/dist/ExecutiveDashboard/ExecutiveDashboardWrapper.js +1 -1
  3. package/dist/ExecutiveDashboard/api/alertsapi.js +1 -1
  4. package/dist/ExecutiveDashboard/api/dashboardApi.js +1 -1
  5. package/dist/ExecutiveDashboard/components/Alerts/AlertsViewTrigger.js +1 -1
  6. package/dist/ExecutiveDashboard/components/Alerts/CreateAlertModal.js +1 -1
  7. package/dist/ExecutiveDashboard/components/BarChart/BarChart.js +1 -1
  8. package/dist/ExecutiveDashboard/components/BarChart/utils.js +1 -1
  9. package/dist/ExecutiveDashboard/components/DashboardDateFilter/DashboardDateFilter.js +1 -1
  10. package/dist/ExecutiveDashboard/components/DashboardGrid/DashboardGrid.js +2 -0
  11. package/dist/ExecutiveDashboard/components/DashboardGrid/DashboardGrid.js.map +1 -0
  12. package/dist/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.js +2 -0
  13. package/dist/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.js.map +1 -0
  14. package/dist/ExecutiveDashboard/components/DashboardGrid/layout.js +2 -0
  15. package/dist/ExecutiveDashboard/components/DashboardGrid/layout.js.map +1 -0
  16. package/dist/ExecutiveDashboard/components/DashboardGrid/useElementSize.js +2 -0
  17. package/dist/ExecutiveDashboard/components/DashboardGrid/useElementSize.js.map +1 -0
  18. package/dist/ExecutiveDashboard/components/DatePickers/CustomRangePicker.js +2 -0
  19. package/dist/ExecutiveDashboard/components/DatePickers/CustomRangePicker.js.map +1 -0
  20. package/dist/ExecutiveDashboard/components/DropDowns/CustomSingleSelect.js +1 -1
  21. package/dist/ExecutiveDashboard/components/ExecutiveDashboard.js +1 -1
  22. package/dist/ExecutiveDashboard/components/Graph/Graph.js +1 -1
  23. package/dist/ExecutiveDashboard/components/Graph/LineChart.js +1 -1
  24. package/dist/ExecutiveDashboard/components/PieChart/utils.js +1 -1
  25. package/dist/ExecutiveDashboard/components/Table/FTable.js +1 -1
  26. package/dist/ExecutiveDashboard/components/Table/TableCard.js +1 -1
  27. package/dist/ExecutiveDashboard/components/common/ChipSelector/ChipSelector.js +2 -0
  28. package/dist/ExecutiveDashboard/components/common/ChipSelector/ChipSelector.js.map +1 -0
  29. package/dist/ExecutiveDashboard/components/common/TooltipWrapper.js +2 -0
  30. package/dist/ExecutiveDashboard/components/common/TooltipWrapper.js.map +1 -0
  31. package/dist/ExecutiveDashboard/components/ui/chart.js +1 -1
  32. package/dist/ExecutiveDashboard/utils/chartCards.js +2 -0
  33. package/dist/ExecutiveDashboard/utils/chartCards.js.map +1 -0
  34. package/dist/ExecutiveDashboard/utils/sectionOrder.js +1 -1
  35. package/dist/assets/icons/thresholdGrey.svg.js +2 -0
  36. package/dist/assets/icons/thresholdGrey.svg.js.map +1 -0
  37. package/dist/assets/icons/thresholdRed.svg.js +2 -0
  38. package/dist/assets/icons/thresholdRed.svg.js.map +1 -0
  39. package/dist/cjs/ExecutiveDashboard/ExecutiveDashboardWrapper.js +1 -1
  40. package/dist/cjs/ExecutiveDashboard/api/alertsapi.js +1 -1
  41. package/dist/cjs/ExecutiveDashboard/api/dashboardApi.js +1 -1
  42. package/dist/cjs/ExecutiveDashboard/components/Alerts/AlertsViewTrigger.js +1 -1
  43. package/dist/cjs/ExecutiveDashboard/components/Alerts/CreateAlertModal.js +1 -1
  44. package/dist/cjs/ExecutiveDashboard/components/BarChart/BarChart.js +1 -1
  45. package/dist/cjs/ExecutiveDashboard/components/BarChart/utils.js +1 -1
  46. package/dist/cjs/ExecutiveDashboard/components/DashboardDateFilter/DashboardDateFilter.js +1 -1
  47. package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/DashboardGrid.js +2 -0
  48. package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/DashboardGrid.js.map +1 -0
  49. package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.js +2 -0
  50. package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.js.map +1 -0
  51. package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/layout.js +2 -0
  52. package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/layout.js.map +1 -0
  53. package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/useElementSize.js +2 -0
  54. package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/useElementSize.js.map +1 -0
  55. package/dist/cjs/ExecutiveDashboard/components/DatePickers/CustomRangePicker.js +2 -0
  56. package/dist/cjs/ExecutiveDashboard/components/DatePickers/CustomRangePicker.js.map +1 -0
  57. package/dist/cjs/ExecutiveDashboard/components/DropDowns/CustomSingleSelect.js +1 -1
  58. package/dist/cjs/ExecutiveDashboard/components/ExecutiveDashboard.js +1 -1
  59. package/dist/cjs/ExecutiveDashboard/components/Graph/Graph.js +1 -1
  60. package/dist/cjs/ExecutiveDashboard/components/Graph/LineChart.js +1 -1
  61. package/dist/cjs/ExecutiveDashboard/components/PieChart/utils.js +1 -1
  62. package/dist/cjs/ExecutiveDashboard/components/Table/FTable.js +1 -1
  63. package/dist/cjs/ExecutiveDashboard/components/Table/TableCard.js +1 -1
  64. package/dist/cjs/ExecutiveDashboard/components/common/ChipSelector/ChipSelector.js +2 -0
  65. package/dist/cjs/ExecutiveDashboard/components/common/ChipSelector/ChipSelector.js.map +1 -0
  66. package/dist/cjs/ExecutiveDashboard/components/common/TooltipWrapper.js +2 -0
  67. package/dist/cjs/ExecutiveDashboard/components/common/TooltipWrapper.js.map +1 -0
  68. package/dist/cjs/ExecutiveDashboard/components/ui/chart.js +1 -1
  69. package/dist/cjs/ExecutiveDashboard/utils/chartCards.js +2 -0
  70. package/dist/cjs/ExecutiveDashboard/utils/chartCards.js.map +1 -0
  71. package/dist/cjs/ExecutiveDashboard/utils/sectionOrder.js +1 -1
  72. package/dist/cjs/assets/icons/thresholdGrey.svg.js +2 -0
  73. package/dist/cjs/assets/icons/thresholdGrey.svg.js.map +1 -0
  74. package/dist/cjs/assets/icons/thresholdRed.svg.js +2 -0
  75. package/dist/cjs/assets/icons/thresholdRed.svg.js.map +1 -0
  76. package/dist/cjs/index.js +1 -1
  77. package/dist/cjs/styles.css +1 -1
  78. package/dist/index.js +1 -1
  79. package/dist/styles.css +1 -1
  80. package/dist/types/ExecutiveDashboard/ExecutiveDashboardWrapper.d.ts +1 -1
  81. package/dist/types/ExecutiveDashboard/ExecutiveDashboardWrapper.d.ts.map +1 -1
  82. package/dist/types/ExecutiveDashboard/TestExecutiveDashboard.d.ts.map +1 -1
  83. package/dist/types/ExecutiveDashboard/api/alertsapi.d.ts +1 -1
  84. package/dist/types/ExecutiveDashboard/api/alertsapi.d.ts.map +1 -1
  85. package/dist/types/ExecutiveDashboard/api/dashboardApi.d.ts +3 -3
  86. package/dist/types/ExecutiveDashboard/api/dashboardApi.d.ts.map +1 -1
  87. package/dist/types/ExecutiveDashboard/components/Alerts/AlertsViewTrigger.d.ts.map +1 -1
  88. package/dist/types/ExecutiveDashboard/components/Alerts/CreateAlertModal.d.ts +4 -0
  89. package/dist/types/ExecutiveDashboard/components/Alerts/CreateAlertModal.d.ts.map +1 -1
  90. package/dist/types/ExecutiveDashboard/components/Alerts/alerts.types.d.ts +19 -0
  91. package/dist/types/ExecutiveDashboard/components/Alerts/alerts.types.d.ts.map +1 -0
  92. package/dist/types/ExecutiveDashboard/components/BarChart/BarChart.d.ts.map +1 -1
  93. package/dist/types/ExecutiveDashboard/components/BarChart/types.d.ts +24 -0
  94. package/dist/types/ExecutiveDashboard/components/BarChart/types.d.ts.map +1 -1
  95. package/dist/types/ExecutiveDashboard/components/BarChart/utils.d.ts +6 -0
  96. package/dist/types/ExecutiveDashboard/components/BarChart/utils.d.ts.map +1 -1
  97. package/dist/types/ExecutiveDashboard/components/DashboardDateFilter/DashboardDateFilter.d.ts.map +1 -1
  98. package/dist/types/ExecutiveDashboard/components/DashboardGrid/DashboardGrid.d.ts +19 -0
  99. package/dist/types/ExecutiveDashboard/components/DashboardGrid/DashboardGrid.d.ts.map +1 -0
  100. package/dist/types/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.d.ts +32 -0
  101. package/dist/types/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.d.ts.map +1 -0
  102. package/dist/types/ExecutiveDashboard/components/DashboardGrid/layout.d.ts +205 -0
  103. package/dist/types/ExecutiveDashboard/components/DashboardGrid/layout.d.ts.map +1 -0
  104. package/dist/types/ExecutiveDashboard/components/DashboardGrid/useElementSize.d.ts +15 -0
  105. package/dist/types/ExecutiveDashboard/components/DashboardGrid/useElementSize.d.ts.map +1 -0
  106. package/dist/types/ExecutiveDashboard/components/DatePickers/CustomRangePicker.d.ts +30 -0
  107. package/dist/types/ExecutiveDashboard/components/DatePickers/CustomRangePicker.d.ts.map +1 -0
  108. package/dist/types/ExecutiveDashboard/components/DropDowns/CustomSingleSelect.d.ts +4 -1
  109. package/dist/types/ExecutiveDashboard/components/DropDowns/CustomSingleSelect.d.ts.map +1 -1
  110. package/dist/types/ExecutiveDashboard/components/ExecutiveDashboard.d.ts +34 -1
  111. package/dist/types/ExecutiveDashboard/components/ExecutiveDashboard.d.ts.map +1 -1
  112. package/dist/types/ExecutiveDashboard/components/Graph/Graph.d.ts.map +1 -1
  113. package/dist/types/ExecutiveDashboard/components/Graph/LineChart.d.ts.map +1 -1
  114. package/dist/types/ExecutiveDashboard/components/Graph/types.d.ts +2 -0
  115. package/dist/types/ExecutiveDashboard/components/Graph/types.d.ts.map +1 -1
  116. package/dist/types/ExecutiveDashboard/components/PieChart/utils.d.ts +9 -0
  117. package/dist/types/ExecutiveDashboard/components/PieChart/utils.d.ts.map +1 -1
  118. package/dist/types/ExecutiveDashboard/components/Table/FTable.d.ts.map +1 -1
  119. package/dist/types/ExecutiveDashboard/components/common/ChipSelector/ChipSelector.d.ts +32 -0
  120. package/dist/types/ExecutiveDashboard/components/common/ChipSelector/ChipSelector.d.ts.map +1 -0
  121. package/dist/types/ExecutiveDashboard/components/common/TooltipWrapper.d.ts +9 -0
  122. package/dist/types/ExecutiveDashboard/components/common/TooltipWrapper.d.ts.map +1 -0
  123. package/dist/types/ExecutiveDashboard/components/ui/chart.d.ts.map +1 -1
  124. package/dist/types/ExecutiveDashboard/types/index.d.ts +71 -19
  125. package/dist/types/ExecutiveDashboard/types/index.d.ts.map +1 -1
  126. package/dist/types/ExecutiveDashboard/utils/chartCards.d.ts +36 -0
  127. package/dist/types/ExecutiveDashboard/utils/chartCards.d.ts.map +1 -0
  128. package/dist/types/ExecutiveDashboard/utils/sectionOrder.d.ts.map +1 -1
  129. package/dist/types/index.d.ts +8 -1
  130. package/dist/types/index.d.ts.map +1 -1
  131. package/package.json +3 -3
package/README.md CHANGED
@@ -21,6 +21,7 @@ dashboard by hand.
21
21
  3. [How it works (architecture)](#3-how-it-works-architecture)
22
22
  4. [`ExecutiveDashboardWrapper` props](#4-executivedashboardwrapper-props)
23
23
  - [4.1 Section order (`sectionOrder` / `hiddenSections`)](#41-section-order-sectionorder--hiddensections)
24
+ - [4.2 Grid layout (`layout`)](#42-grid-layout-layout)
24
25
  5. [The `tables` prop in depth](#5-the-tables-prop-in-depth)
25
26
  - [5.1 Table grid layout (`tableLayout`)](#51-table-grid-layout-tablelayout)
26
27
  6. [Backend API contract](#6-backend-api-contract)
@@ -209,6 +210,7 @@ consumed by the wrapper.
209
210
  | `tableLayout` | `DashboardTableLayoutConfig` | No | Grid layout for the tables section — how many tables sit per row, which options the toolbar offers, and how narrow a card may get before the grid reflows. See [§5.1](#51-table-grid-layout-tablelayout). |
210
211
  | `sectionOrder` | `DashboardSectionKey[]` | No | Vertical order of the dashboard sections, by UI config key — e.g. `["tableBuilder", "kpiCards", "graphBuilder"]`. Partial lists are allowed. See [§4.1](#41-section-order-sectionorder--hiddensections). |
211
212
  | `hiddenSections` | `DashboardSectionKey[]` | No | Parts to leave out entirely, e.g. `["graphBuilder", "sidebarFilters"]`. Applied after `sectionOrder`, and unlike it, also accepts the pinned `dateFilters` / `sidebarFilters`. See [§4.1](#41-section-order-sectionorder--hiddensections). |
213
+ | `layout` | `DashboardLayoutConfig` | No | Parent-controlled grid: column count plus per-component `colSpan` / `rowSpan` / `order` / `hidden`, keyed by the get-data response keys. Off unless `enabled: true`. See [§4.2](#42-grid-layout-layout). |
212
214
  | `fetchUIConfig` | `FetchUIConfig` | No | Override the built-in UI-config fetcher — `(config, signal?) => Promise<DashboardUIConfig>`. Useful for mocks/tests or a custom transport. Defaults to the built-in `/federated/filters/ui` fetcher. |
213
215
  | `fetchDashboardData` | `FetchDashboardData` | No | Override the built-in data fetcher — `(config, params, signal?) => Promise<DashboardDataResponse>`. Defaults to the built-in `/federated/filters/get-data` fetcher. |
214
216
  | `initialStartDate` | `Date` | No | Force the initial range start instead of deriving it from the config's default preset. Must be paired with `initialEndDate`. |
@@ -333,6 +335,298 @@ import {
333
335
  > `displayOrder`, graph tiers/series honour theirs, and table placement inside
334
336
  > the grid is controlled by [`tableLayout.spans`](#per-table-widths-spans).
335
337
 
338
+ ### 4.2 Grid layout (`layout`)
339
+
340
+ The grid layout puts every dashboard component into a single CSS grid. It sends
341
+ the number of columns plus, for any component to size, a grid config keyed by
342
+ **that component's key in the get-data response**.
343
+
344
+ **It comes from the backend.** The UI config API (`POST /federated/filters/ui`)
345
+ returns it as `data.dashboardLayout`, so hosts don't need to pass anything:
346
+
347
+ ```json
348
+ {
349
+ "data": {
350
+ "dashboardLayout": {
351
+ "enabled": true,
352
+ "columns": 4,
353
+ "items": {
354
+ "primary": { "colSpan": 4, "rowSpan": 3, "order": 1 },
355
+ "Total Incurred Cost": { "colSpan": 1, "order": 2 },
356
+ "test kpi card": { "colSpan": 4, "order": 6, "endRow": true }
357
+ }
358
+ }
359
+ }
360
+ }
361
+ ```
362
+
363
+ When the backend config version changes while live polling is running, the
364
+ dashboard refetches the UI config quietly and the new layout applies without a
365
+ reload. The user's filters and plot selections are kept.
366
+
367
+ The UI config's `components` flags are respected too. `gridDesign: false`
368
+ turns the backend grid off (the regular layout renders), and a component type
369
+ set to `false` (`kpiCards`, `graphBuilder`, `tableBuilder`) is left off the
370
+ grid. A missing flag counts as on.
371
+
372
+ A host can still **override** the backend layout by passing the `layout` prop,
373
+ which takes the same shape:
374
+
375
+ ```tsx
376
+ <ExecutiveDashboardWrapper
377
+ configId="..."
378
+ layout={{
379
+ enabled: true,
380
+ columns: 4,
381
+ items: {
382
+ "Total Incurred Cost": { colSpan: 1, order: 1 },
383
+ "Total litigated claim": { colSpan: 1, order: 2 },
384
+ "test kpi card": { hidden: true },
385
+ graph: { colSpan: 3, rowSpan: 3, order: 3 },
386
+ claim_cost_by_incident_type: { colSpan: 2, rowSpan: 3 },
387
+ highest_value_litigation_claims: { colSpan: 4, rowSpan: 3 },
388
+ },
389
+ }}
390
+ />
391
+ ```
392
+
393
+ The grid is **read-only**: there is no editing UI and nothing is saved. To
394
+ change the layout, pass a different `layout` object and the grid re-renders
395
+ immediately. When `layout` is missing or `enabled` isn't `true`, the dashboard
396
+ renders exactly as before (`sectionOrder`, `tableLayout` and so on). While the
397
+ grid is on, `items[].order` replaces `sectionOrder`. The **date filter bar and
398
+ the filters sidebar stay outside the grid**, where they always are, and
399
+ `hiddenSections` still hides them.
400
+
401
+ #### Keys: taken from the get-data response
402
+
403
+ Given a response like:
404
+
405
+ ```json
406
+ {
407
+ "graph": { "tier": [ { "key": "primary" }, { "key": "tier2" } ] },
408
+ "kpiCards": { "Total Incurred Cost": { "currentValue": 0, "baselineValue": 50537473 }, "Total Claims Count": {} },
409
+ "barChart": { "cost_by_region": [] },
410
+ "pieChart": { "claims_by_status": [] },
411
+ "table": { "claim_cost_by_incident_type": [], "highest_value_litigation_claims": [] }
412
+ }
413
+ ```
414
+
415
+ | Component | Key accepted in `items` | Widget id |
416
+ | ---------------- | -------------------------------------------------------------------- | ------------------------------ |
417
+ | KPI card | its key in `data.kpiCards` (= UI config `title`) **or** UI config `key` | `kpi:<card.key ?? card.title>` |
418
+ | Graph card | `"graph"`, `"graphBuilder"` **or** any `data.graph.tier[].key` | `chart:graphBuilder` |
419
+ | Bar chart | its key in `data.barChart` **or** its UI config `title` | `bar:<key>` |
420
+ | Pie chart | its key in `data.pieChart` **or** its UI config `title` | `pie:<key>` |
421
+ | Table | its key in `data.table` | `table:<key>` |
422
+ | Host widget | `extraWidgets[].key` | as given |
423
+
424
+ Matching rules:
425
+
426
+ - Keys are compared **canonically**: trimmed, lower-cased, with spaces, `_` and
427
+ `-` removed. `"Total Incurred Cost"` and `"total_incurred_cost"` are the same key.
428
+ - A widget answers to its full id, the part after the colon, and its aliases.
429
+ **Full ids always win.**
430
+ - A short name claimed by **two different** widgets matches neither (e.g. a
431
+ table and a KPI card both keyed `costs`). Use the full id (`"table:costs"`).
432
+ - **Unknown keys are ignored.** Outside production they log one console warning
433
+ per key, listing every available widget id.
434
+ - Two keys that resolve to the same widget merge, with later fields winning.
435
+ - **Components not listed in `items` still render**, at their default size and
436
+ position. Use `hidden: true` to remove one.
437
+
438
+ #### Bar and pie charts: one card each
439
+
440
+ Unlike the graph, every bar and pie chart is **its own card**, the way tables
441
+ are — they already sit side by side outside the grid. So one `items` entry sizes
442
+ one chart: `cost_by_region: { colSpan: 2, rowSpan: 3 }`. They default to
443
+ `colSpan: 1, rowSpan: 3` with a 380 px minimum width, and re-flow onto their own
444
+ row when the grid is too narrow to hold them at that width. A chart in a
445
+ fixed-height cell sizes its plot to the cell; `rowSpan: "fit"` keeps the chart's
446
+ own default height instead. Charts are ordered by their config `displayOrder`,
447
+ bar charts before pie charts, unless `order` says otherwise.
448
+
449
+ #### The graph: one card for all tiers
450
+
451
+ The graph is always **one card with every tier** stacked inside it, exactly as
452
+ when the grid is off. Tiers are never split into separate grid cells. One
453
+ `items` entry sizes the whole card, e.g. `graph: { colSpan: 3, rowSpan: 3, order: 5 }`,
454
+ and its height is shared across the tiers (the first a little taller). A tier key
455
+ works as that entry's key too, so `primary: {...}` sizes the same card.
456
+
457
+ #### Per-component settings (`items[key]`)
458
+
459
+ | Setting | Type | Meaning |
460
+ | ---------- | -------------------- | ---------------------------------------------------------------------------------------- |
461
+ | `colSpan` | `number` | Width in columns. Rounded and clamped to `1..columns`. An invalid value uses the default. |
462
+ | `rowSpan` | `number \| "auto" \| "fit"` | Height in row units (max 12). A number spans that many grid rows and is `n × rowHeight + (n − 1) × gap` tall; its content never makes it taller (it scrolls inside), and it only grows when a card beside it makes its rows taller, so bottom edges line up. `"auto"` sizes to the content (at least one row unit), stretched to the tallest card in its row. `"fit"` is the same as `defaultHeight: true`. |
463
+ | `defaultHeight` | `boolean` | The component is as tall as its content (`height: fit-content`): no fixed height and no inner scroll. With `matchRowHeights` (the default) it then stretches to the tallest card in its row; with `matchRowHeights: false` it is not stretched. Takes priority over `rowSpan`. Charts use their regular-layout heights. |
464
+ | `order` | `number` | Components with an `order` come first, ascending. The rest keep the default order. |
465
+ | `hidden` | `boolean` | Leave the component off the grid. |
466
+ | `minWidth` | `number` (px) | The narrowest this component may get. On a screen where the configured layout would squeeze it below this, its row re-flows instead (see Responsiveness). Defaults below. |
467
+ | `newRow` | `boolean` | Start a new section: column 1, below everything placed so far (including tall cards). Later components never move up past it. |
468
+ | `endRow` | `boolean` | Nothing else goes on this component's row. The rest of the row stays empty and the next component starts a new section. |
469
+ | `colStart` | `number` | 1-based column to start at. The component moves down until that spot is free. Clamped so the whole `colSpan` fits. |
470
+
471
+ Numeric strings (`"3"`) are accepted. Booleans and empty strings count as missing.
472
+
473
+ Defaults per component:
474
+
475
+ | Component | `colSpan` × `rowSpan` | `minWidth` |
476
+ | ---------- | --------------------- | ---------- |
477
+ | KPI card | 1 × auto | 266 |
478
+ | Graph card | 2 × 3 | 360 |
479
+ | Table | 1 × 3 | 340 |
480
+ | Host widget| its own defaults | its own, else 200 |
481
+
482
+ The default order is KPI cards (by `displayOrder`), then the graph card, tables, and finally host widgets.
483
+
484
+ #### Row placement
485
+
486
+ The grid computes an explicit position for every component (it does not rely
487
+ on the browser's auto-placement). Components fill rows left to right, and cards
488
+ spanning several rows are respected: smaller cards flow into the columns beside
489
+ them.
490
+
491
+ **No holes.** With the default `packing: "dense"`, a card that doesn't fit the
492
+ space left in a row doesn't leave that space empty: the next card that fits
493
+ moves up into it. For example, with a 6-row graph in columns 1–4 and KPI cards
494
+ beside it, a `colSpan: 2` card that meets a single free column drops a row, and
495
+ the following 1-column card fills the gap. Set `packing: "ordered"` to keep
496
+ strict reading order instead (holes are then left as they are).
497
+
498
+ `newRow`, `endRow` and `colStart` control placement, and they work the same for
499
+ every component type:
500
+
501
+ ```tsx
502
+ layout={{
503
+ enabled: true,
504
+ columns: 4,
505
+ items: {
506
+ // Cards 1–4 fill the first row. Card 5 sits alone in column 1 of the
507
+ // second row, and columns 2–4 of that row stay empty.
508
+ "Average Cost per Claim": { colSpan: 1, order: 5, endRow: true },
509
+
510
+ // The graph starts a fresh row regardless of what came before it.
511
+ graph: { colSpan: 3, rowSpan: 3, newRow: true },
512
+
513
+ // A table placed in column 2 of its row, with column 1 left empty.
514
+ claim_cost_by_incident_type: { colSpan: 2, rowSpan: 3, colStart: 2 },
515
+ },
516
+ }}
517
+ ```
518
+
519
+ - `endRow` on one component has the same effect as `newRow` on the next visible one.
520
+ - A section started by `newRow` / `endRow` is a hard boundary: dense packing
521
+ never backfills a hole above it, so a section keeps its own cards.
522
+ - `colStart` with `newRow` puts the component at that column in the new section.
523
+
524
+ #### Grid settings
525
+
526
+ | Setting | Default | Meaning |
527
+ | ---------------- | ------- | ------------------------------------------------------------------- |
528
+ | `enabled` | `false` | Turns the grid on. Off means the regular layout. |
529
+ | `columns` | `3` | Column count, max `12`. |
530
+ | `rowHeight` | `132` | px per row unit. A cell spanning `n` rows is `n*rowHeight + (n-1)*gap` tall. |
531
+ | `gap` | `12` | px between cells. |
532
+ | `packing` | `"dense"` | `"dense"` fills holes with later cards that fit; `"ordered"` keeps strict reading order. |
533
+ | `fillRows` | `false` | Cards that end a row grow into the empty columns after them (sharing them in proportion to their spans), never wider than same-size cards on fuller lines. Always on while cards are widened for a narrow screen. |
534
+ | `equalHeights` | `true` | Every row holding an `"auto"` card (KPI cards by default) is the same height, the tallest such card's, so KPI cards match across the whole grid. `false` sizes each row on its own. |
535
+ | `matchRowHeights` | `true` | A `defaultHeight` / `"fit"` card stretches to the tallest card in its row, so side-by-side cards (a bar chart beside a pie) share one height; the shorter card's chart centres in the extra space. The row keeps its height. `false` keeps each fit card at its own content height. |
536
+ | `items` | `{}` | Per-component settings, see above. |
537
+ | `extraWidgets` | `[]` | Host-owned components, see below. |
538
+
539
+ #### Responsiveness
540
+
541
+ **The config is shown as-is whenever it fits.** The column count always stays at
542
+ `columns`, and while every card is at least its `minWidth`, every component keeps
543
+ its configured `colSpan`, `rowSpan`, order and row breaks. A 6-column layout is
544
+ 6 columns.
545
+
546
+ **On a smaller screen, cards are protected instead of squeezed.** The grid
547
+ measures its container (not the window). A card that would get narrower than
548
+ its `minWidth` is widened to the fewest columns that keep it at that width, and
549
+ the layout is packed again, so cards wrap onto the next free line (e.g. 5 KPI
550
+ cards → 3 + 2 → 2 + 2 + 1 → stacked). While any card is widened, the cards that
551
+ end each row grow into the columns left after them, so lines stay full, and a
552
+ tall graph whose neighbors no longer fit beside it takes the full width.
553
+ Same-size cards stay the same width, though: a leftover line (fewer cards than
554
+ the fullest line of that size) grows no wider than the cards above it. Five KPI
555
+ cards at two per line give `2 + 2 + 1` with the last one half-width, and only go
556
+ full width once all of them do.
557
+
558
+ **Heights never leak between cards.** Every grid row is at least `rowHeight`,
559
+ so a card with a numeric `rowSpan` is exactly its row units tall and never
560
+ stretches the rows it crosses: a KPI card sharing a row with a 4-row table is
561
+ the same height as every other KPI card. With `equalHeights` (the default),
562
+ every row holding an `"auto"` card shares one height, the tallest such card's,
563
+ so a KPI card with a CTA button, a subtitle or a wrapping delta makes all KPI
564
+ cards that tall, not just the ones in its row. Tall cards crossing those rows
565
+ stretch with them, so edges stay aligned. Charts are
566
+ given the cell's measured height, so they fill it. A card with
567
+ `defaultHeight: true` opts out: it is as tall as its content and its row can be
568
+ shorter than `rowHeight`, e.g. `{ colSpan: 4, order: 8, endRow: true,
569
+ defaultHeight: true }` for a full-width table that shows every row without
570
+ scrolling.
571
+
572
+ **Cards keep their own styling.** The grid only sizes cells; each card renders
573
+ with its normal styles. Charts size from the cell's pixel height, and content
574
+ taller than a fixed-height cell scrolls inside the cell.
575
+
576
+ #### Adding components
577
+
578
+ **Host widgets.** Pass `extraWidgets` to place your own components. A widget
579
+ whose `key` matches a built-in replaces it, and the rest are appended after
580
+ the built-ins:
581
+
582
+ ```tsx
583
+ layout={{
584
+ enabled: true,
585
+ columns: 3,
586
+ extraWidgets: [
587
+ {
588
+ key: "custom:alerts",
589
+ aliases: ["alerts"],
590
+ title: "Alerts",
591
+ type: "alerts",
592
+ defaultColSpan: 1,
593
+ defaultRowSpan: 3,
594
+ // Either a static `node`, or `render` to size from the cell.
595
+ render: ({ height, width }) => <AlertsPanel height={height ?? 300} />,
596
+ },
597
+ ],
598
+ items: { alerts: { order: 1 } },
599
+ }}
600
+ ```
601
+
602
+ `render` receives `{ colSpan, rowSpan, height, width }`: `colSpan` is the
603
+ rendered span after responsive scaling, `height` is the cell's measured px
604
+ height (at least its `rowSpan` height; null for `"auto"` and `"fit"` rows), and
605
+ `width` is its measured px width (null before the first measurement).
606
+
607
+ **New builder types.** When the UI config grows a new component type, add it in
608
+ two places: a branch in `buildDashboardWidgets`
609
+ ([DashboardGrid/buildDashboardWidgets.ts](src/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.ts))
610
+ that pushes one widget per config entry with a `<type>:<key>` id and defaults,
611
+ and a matching renderer in `ExecutiveDashboard`. Key matching, ordering and
612
+ sizing then work for it with no further changes.
613
+
614
+ The pieces are exported for hosts that lay out their own dashboards:
615
+
616
+ ```tsx
617
+ import {
618
+ DashboardGrid, // <DashboardGrid widgets={…} config={…} />
619
+ resolveLayout, // (config, widgets) → { columns, rowHeight, gap, items }
620
+ buildDashboardWidgets, // ({ uiData, renderers, extraWidgets }) → DashboardWidget[]
621
+ buildWidgetIndex, // key lookup used by resolveLayout
622
+ packLayout, // (items, columns, gap, width, { packing, fillRows }) → { items: positions, rows: row sizing }
623
+ placeItems, // same arguments → just the positions (colStart/colSpan/rowStart/rowSpan)
624
+ cellHeight, // (rowSpan, rowHeight, gap) → px | null
625
+ DEFAULT_COLUMNS, MAX_COLUMNS, DEFAULT_ROW_HEIGHT, DEFAULT_GAP,
626
+ DEFAULT_MIN_WIDTH, MAX_ROW_SPAN,
627
+ } from "@e-llm-studio/federated-dashboard-components";
628
+ ```
629
+
336
630
  ---
337
631
 
338
632
  ## 5. The `tables` prop in depth
@@ -611,6 +905,7 @@ following are exported from the package root (see [src/index.ts](src/index.ts)):
611
905
  | `TableLayoutToggle` | The 1/2/3-per-row icon group on its own. Props: `TableLayoutToggleProps`. |
612
906
  | `useResponsiveColumns`| Hook behind the grid — caps a desired column count to what the container fits. |
613
907
  | `DashboardCard` | Rich content card (sections, tags, events, news, grid). |
908
+ | `DashboardGrid` | Read-only responsive grid behind the `layout` prop. Props: `DashboardGridProps`. See [§4.2](#42-grid-layout-layout). |
614
909
 
615
910
  ### Chart primitives (shadcn/Recharts port)
616
911
 
@@ -674,6 +969,7 @@ noted.
674
969
  - **Query:** `DashboardQueryParams` — `{ startDate?, endDate?, filters? }`.
675
970
  - **Tables:** `DashboardTablesConfig`, `DashboardTableRenderConfig`, `DashboardTableCardStyles`, `DashboardTableLayoutConfig`, `TableBuilderConfig`, `TableColumnConfig`, `FTableColumn`, `TableRow`.
676
971
  - **Layout:** `DashboardSectionKey` — a section named by its UI config key (`"graphBuilder" | "kpiCards" | "tableBuilder"`, plus any future one, since any string is accepted). Used by `sectionOrder` / `hiddenSections` ([§4.1](#41-section-order-sectionorder--hiddensections)).
972
+ - **Grid layout:** `DashboardLayoutConfig`, `DashboardItemConfig`, `DashboardRowSpan`, `DashboardWidget`, `DashboardWidgetRenderContext`, `ResolvedLayout`, `ResolvedLayoutItem` ([§4.2](#42-grid-layout-layout)).
677
973
  - **KPI:** `KpiValueObject`, `KpiDelta`, `KpiSentiment`, `IndicatorLogic`.
678
974
  - **Fetchers:** `FetchUIConfig`, `FetchDashboardData` (function types for the pluggable fetchers).
679
975
 
@@ -688,6 +984,7 @@ noted.
688
984
  | Requests hit the wrong host / 404 | `baseUrl` defaults to `https://dev.appmod.ai`. For another environment pass an explicit absolute `baseUrl`. |
689
985
  | "Failed to load dashboard" with a Retry button | An API returned non-2xx or `success: false`. Check the three endpoints in [§6](#6-backend-api-contract) and the `config_id`. |
690
986
  | Tables render as plain text | No matching entry in `tables` for that `tableBuilder[].key`. Keys must match exactly. See [§5](#5-the-tables-prop-in-depth). |
987
+ | `layout.items` entry has no effect | The key didn't match a widget, or matched two. Check the dev console warning for the available widget ids and use the full id (e.g. `"table:costs"`). See [§4.2](#42-grid-layout-layout). |
691
988
  | Peer dependency warnings on install | Install the peers listed in [§1](#peer-dependencies) at compatible versions. |
692
989
 
693
990
  ---
@@ -1,2 +1,2 @@
1
- import{__assign as e,__awaiter as n,__generator as r,__rest as t,__spreadArray as l}from"../_virtual/_tslib.js";import{jsx as o,Fragment as i,jsxs as a}from"react/jsx-runtime";import u,{useState as d,useRef as s,useMemo as c,useCallback as v,useEffect as f}from"react";import{ExecutiveDashboard as g}from"./components/ExecutiveDashboard.js";import{DATE_PRESETS as b}from"./components/DashboardDateFilter/datePreset.js";import{DashboardSkeleton as h}from"./components/DashboardSkeleton/DashboardSkeleton.js";import{fetchUIConfig as p,fetchCurrentConfigUIVersionFromRedis as m,fetchDashboardData as D,fetchTableData as y}from"./api/dashboardApi.js";import{useVisibilityPolling as E}from"./hooks/useVisibilityPolling.js";var C=1e4;function F(F){var w,I,A,k=this,S=F.baseUrl,P=void 0===S?"https://dev.appmod.ai":S,j=F.configId,M=F.accessToken,O=F.authBaseUrl,R=F.graphEmptyState,T=F.tables,N=F.tableLayout,U=F.sectionOrder,x=F.hiddenSections,L=F.fetchUIConfig,V=F.fetchUIVersionFromRedis,B=F.fetchDashboardData,K=F.fetchTableData,J=F.initialStartDate,Y=F.initialEndDate,_=F.initialPreset,z=F.initialFilters,G=F.hiddenFilters,H=F.onDateChange,q=F.onFiltersApplied,Q=F.onFilterStateChange,W=F.renderLoading,X=F.renderError,Z=F.pollingConfigProp,$=F.metricCardConfig,ee=F.kpiCtaConfig,ne=F.tableCtaConfig,re=null!=L?L:p,te=null!=V?V:m,le=null!=B?B:D,oe=null!=K?K:y,ie=d(null),ae=ie[0],ue=ie[1],de=d(null),se=de[0],ce=de[1],ve=d({}),fe=ve[0],ge=ve[1],be=d(!0),he=be[0],pe=be[1],me=d(!0),De=me[0],ye=me[1],Ee=d(null),Ce=Ee[0],Fe=Ee[1],we=d(!1),Ie=we[0],Ae=we[1],ke=d(!1),Se=ke[0],Pe=ke[1],je=d({}),Me=je[0],Oe=je[1],Re=d({}),Te=Re[0],Ne=Re[1],Ue=d({}),xe=Ue[0],Le=Ue[1],Ve=d(null),Be=Ve[0],Ke=Ve[1],Je=u.useRef(null),Ye=u.useRef(!1),_e=s(null),ze=s(null),Ge=s({}),He=s(null),qe=s(new Set),Qe=s(!1),We=s(C),Xe=s(-1),Ze=s(!0),$e=s(z);$e.current=z;var en=s(_);en.current=_;var nn=JSON.stringify(null!=G?G:{}),rn=c(function(){return JSON.parse(nn)},[nn]),tn=s(rn);tn.current=rn;var ln=c(function(){return e(e({},xe),rn)},[xe,rn]),on=c(function(){var n;return(null===(n=null==ae?void 0:ae.data)||void 0===n?void 0:n.sidebarFilters)?e(e({},ae),{data:e(e({},ae.data),{sidebarFilters:ae.data.sidebarFilters.filter(function(e){return!(e.schemaFilterName in rn)})})}):ae},[ae,rn]),an=d(null!==(I=null===(w=null==ae?void 0:ae.data)||void 0===w?void 0:w.dateFilters.defaultPreset)&&void 0!==I?I:"today"),un=an[0],dn=an[1],sn=d(!1),cn=sn[0],vn=sn[1],fn=d({}),gn=fn[0],bn=fn[1],hn=c(function(){var e,n;if(ae){var r=ae.data.dateFilters;return(null==r?void 0:r.pollingEnabled)&&(We.current=null!==(e=r.pollingInterval)&&void 0!==e?e:C),{pollingEnabled:null!==(n=Boolean("yes"===(null==r?void 0:r.pollingEnabled)))&&void 0!==n&&n,pollingInterval:C,maxErrorInterval:5e4,backoffMultiplier:1.5}}},[ae]),pn=c(function(){return null!=Z?Z:hn},[Z,hn]),mn=function(e){var n=Object.values(b).find(function(n){return n.value===e});return n&&"getRange"in n?n.getRange():null},Dn=v(function(){return n(k,void 0,void 0,function(){var e,n,t,l,o,i,a,u,d,s,c,v,f,g,b,h,p;return r(this,function(r){switch(r.label){case 0:pe(!0),Fe(null),null===(u=_e.current)||void 0===u||u.abort(),e=new AbortController,_e.current=e,r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,re({configId:j,baseUrl:P},e.signal)];case 2:return n=r.sent(),ue(n),t={},null===(c=null===(s=null===(d=null==n?void 0:n.data)||void 0===d?void 0:d.graphBuilder)||void 0===s?void 0:s.tiers)||void 0===c||c.forEach(function(e){e.plotOptions.length>0&&(t[e.key]=e.plotOptions[0].value)}),Oe(t),l={},o=null!==(v=$e.current)&&void 0!==v?v:{},null===(g=null===(f=null==n?void 0:n.data)||void 0===f?void 0:f.sidebarFilters)||void 0===g||g.forEach(function(e){var n;if(!(e.schemaFilterName in tn.current)){var r="Multi select"===e.type,t=o[e.schemaFilterName];l[e.schemaFilterName]=null==t?r?[]:"":r?Array.isArray(t)?t:""===t?[]:[t]:Array.isArray(t)?null!==(n=t[0])&&void 0!==n?n:"":t}}),Ne(l),Le(l),Ye.current||(i=J&&Y?{startDate:J,endDate:Y}:mn(null!==(b=en.current)&&void 0!==b?b:null===(p=null===(h=null==n?void 0:n.data)||void 0===h?void 0:h.dateFilters)||void 0===p?void 0:p.defaultPreset))&&(Ye.current=!0,Je.current={start:i.startDate.getTime(),end:i.endDate.getTime()},Ke({start:i.startDate,end:i.endDate})),[3,5];case 3:return"AbortError"===(null==(a=r.sent())?void 0:a.name)?[2]:(Fe(a),[3,5]);case 4:return _e.current===e&&pe(!1),[7];case 5:return[2]}})})},[j,P,re,J,Y]),yn=v(function(){return n(k,void 0,void 0,function(){var e,n,t,l,o;return r(this,function(r){switch(r.label){case 0:if(Qe.current)return[3,7];Qe.current=!0,console.log("----- POLLING API ----"),null===(o=He.current)||void 0===o||o.abort(),e=new AbortController,He.current=e,r.label=1;case 1:return r.trys.push([1,5,6,7]),[4,te({configId:j,baseUrl:P},e.signal)];case 2:return(null==(n=r.sent())?void 0:n.timestamp)&&parseInt(null==n?void 0:n.timestamp)>Xe.current?(t=mn(un),"custom"===un&&Be&&(t={startDate:null==Be?void 0:Be.start,endDate:null==Be?void 0:Be.end}),console.log("loadData ranges: ",{selectedPreset:un,currentRange:t}),[4,En(t).then(function(){return Xe.current=parseInt(n.timestamp)})]):[3,4];case 3:r.sent(),r.label=4;case 4:return Ze.current=!1,[3,7];case 5:return"AbortError"===(null==(l=r.sent())?void 0:l.name)?[2]:(console.error("Something went wrong while fetching version from Redis"),[3,7]);case 6:return Qe.current=!1,[7];case 7:return[2]}})})},[un,Be,te]);E((null==hn?void 0:hn.pollingEnabled)&&cn,We.current,yn,[pn,cn,yn]),f(function(){return Dn(),function(){var e;return null===(e=_e.current)||void 0===e?void 0:e.abort()}},[Dn]),f(function(){if(hn&&hn.pollingEnabled){var e=hn.pollingInterval;"number"==typeof e&&!isNaN(e)&&e>0&&(We.current=e)}},[hn]);var En=v(function(e){return n(k,void 0,void 0,function(){var n,t,l,o,i,a,u,d;return r(this,function(r){switch(r.label){case 0:if(!Be)return[2];null===(i=ze.current)||void 0===i||i.abort(),n=new AbortController,ze.current=n,Ze.current&&ye(!0),Fe(null),console.log("loadData ranges: ",{selectedPreset:un,currentRange:e,dateRange:Be}),r.label=1;case 1:return r.trys.push([1,3,4,5]),t={startDate:(null==hn?void 0:hn.pollingEnabled)&&e&&"custom"!==un?e.startDate:Be.start,endDate:(null==hn?void 0:hn.pollingEnabled)&&e&&"custom"!==un?e.endDate:Be.end,filters:ln},[4,le({configId:j,baseUrl:P},t,n.signal)];case 2:return l=r.sent(),ce(l),(null==hn?void 0:hn.pollingEnabled)||bn({}),We.current&&(null==pn?void 0:pn.pollingEnabled)&&(null==hn?void 0:hn.pollingInterval)&&(We.current=null!==(a=null==pn?void 0:pn.pollingInterval)&&void 0!==a?a:C,Ze.current=!1),[3,5];case 3:return"AbortError"===(null==(o=r.sent())?void 0:o.name)?[2]:(Fe(o),We.current&&(null==pn?void 0:pn.maxErrorInterval)&&(We.current=Math.min(We.current*(null!==(u=null==hn?void 0:hn.backoffMultiplier)&&void 0!==u?u:1.5),null!==(d=null==hn?void 0:hn.maxErrorInterval)&&void 0!==d?d:5e4)),[3,5]);case 4:return ze.current===n&&ye(!1),[7];case 5:return[2]}})})},[j,P,Be,ln,le]),Cn=v(function(t,o){return n(k,void 0,void 0,function(){var n,i,a,u,d,s,c;return r(this,function(r){switch(r.label){case 0:if(!Be||!qe.current.has(t)||Ge.current[t])return[2];n=new AbortController,Ge.current[t]=n,i=function(){return!qe.current.has(t)||n.signal.aborted||Ge.current[t]!==n},bn(function(n){var r,l,o,i,a,u,d,s;return e(e({},n),((r={})[t]={rows:null!==(o=null===(l=n[t])||void 0===l?void 0:l.rows)&&void 0!==o?o:[],cursor:null===(i=n[t])||void 0===i?void 0:i.cursor,hasMore:null!==(u=null===(a=n[t])||void 0===a?void 0:a.hasMore)&&void 0!==u&&u,loading:!0,loaded:null!==(s=null===(d=n[t])||void 0===d?void 0:d.loaded)&&void 0!==s&&s},r))}),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,oe({configId:j,baseUrl:P},e({startDate:Be.start,endDate:Be.end,filters:ln,tableKey:t,pageSize:20},o?{cursor:o}:{}),n.signal)];case 2:return a=r.sent(),u=null!==(c=null===(s=a.table)||void 0===s?void 0:s[t])&&void 0!==c?c:[],i()?[2]:(bn(function(n){var r,o,i=n[t];return i?e(e({},n),((r={})[t]={rows:l(l([],i.rows,!0),u,!0),cursor:null!==(o=a.nextCursor)&&void 0!==o?o:void 0,hasMore:a.hasNext,loading:!1,loaded:!0},r)):n}),[3,5]);case 3:return"AbortError"===(null==(d=r.sent())?void 0:d.name)||i()?[2]:(bn(function(n){var r;return n[t]?e(e({},n),((r={})[t]=e(e({},n[t]),{loading:!1,hasMore:!1}),r)):n}),[3,5]);case 4:return Ge.current[t]===n&&delete Ge.current[t],[7];case 5:return[2]}})})},[j,P,Be,ln,oe]),Fn=v(function(e,n){var r;if(!n)return qe.current.delete(e),null===(r=Ge.current[e])||void 0===r||r.abort(),delete Ge.current[e],void bn(function(n){var r=n,l=e;return r[l],t(r,["symbol"==typeof l?l:l+""])});qe.current.add(e),Cn(e)},[Cn]),wn=v(function(e){var n=gn[e];(null==n?void 0:n.hasMore)&&!n.loading&&n.cursor&&Cn(e,n.cursor)},[Cn,gn]);f(function(){return function(){qe.current.clear(),Object.values(Ge.current).forEach(function(e){return e.abort()})}},[]),f(function(){return En(),function(){var e;return null===(e=ze.current)||void 0===e?void 0:e.abort()}},[En]),f(function(){return function(){var e;return null===(e=He.current)||void 0===e?void 0:e.abort()}},[]),f(function(){!function(e){var n=Object.values(b).find(function(n){return n.value===e});if("custom"!==e){var r=!(!n||!("pollingEnabled"in n)||!1===n.pollingEnabled);vn(r)}else{var t=new Date,l=(null==Be?void 0:Be.end)&&Be.end.getFullYear()===t.getFullYear()&&Be.end.getMonth()===t.getMonth()&&Be.end.getDate()===t.getDate();vn(!!l)}}(un)},[un,Be]),f(function(){var e,n,r=null!==(e=en.current)&&void 0!==e?e:null===(n=null==ae?void 0:ae.data)||void 0===n?void 0:n.dateFilters.defaultPreset;r&&dn(r)},[null===(A=null==ae?void 0:ae.data)||void 0===A?void 0:A.dateFilters.defaultPreset]);var In=s(Q);In.current=Q;var An=s(un);An.current=un,f(function(){var e;ae&&Be&&(null===(e=In.current)||void 0===e||e.call(In,{filters:ln,startDate:Be.start,endDate:Be.end,selectedPreset:An.current}))},[ae,ln,Be]);var kn=v(function(e){if((null==e?void 0:e.startDate)&&(null==e?void 0:e.endDate)){var n=e.startDate.getTime(),r=e.endDate.getTime();Je.current&&Je.current.start===n&&Je.current.end===r||(Je.current={start:n,end:r},Ke({start:e.startDate,end:e.endDate}))}null==H||H(e),ye(!0)},[H]);f(function(){if(ae&&se){var n={};se.graph.tier.forEach(function(e){if(e.key&&e.thresholds){var r=Object.keys(e.thresholds);if(r.length>0){var t=e.thresholds[r[0]];if(t){var l=Object.keys(t);if(l.length>0){var o=l.find(function(e){var n;return!0===(null===(n=t[e])||void 0===n?void 0:n.primary)});n[e.key]=o||l[0]}}}}}),ge(function(r){return e(e({},n),r)})}},[ae,se]);var Sn=he||De&&!se;return Ce?X?o(i,{children:X(Ce,Dn)}):a("div",e({style:{padding:24,color:"#b91c1c"}},{children:["Failed to load dashboard: ",Ce.message,o("button",e({onClick:Dn,style:{marginLeft:12}},{children:"Retry"}))]})):!Sn&&ae&&se&&Be?(console.log("pollingEnabled: ",null==hn?void 0:hn.pollingEnabled,cn),o(g,{baseUrl:P&&"string"==typeof P&&P.trim()?P:void 0,configId:j&&"string"==typeof j&&j.trim()?j:void 0,accessToken:M&&"string"==typeof M&&M.trim()?M:void 0,authBaseUrl:O&&"string"==typeof O&&O.trim()?O:void 0,uiConfig:null!=on?on:ae,data:se,dataLoading:De,startDate:Be.start,endDate:Be.end,onDateChange:kn,onRefresh:function(){En(),ye(!0)},selectedKpis:Me,onKpiChange:function(n,r){Oe(function(t){var l;return e(e({},t),((l={})[n]=r,l))})},sidebarVisible:Ie,onSidebarShow:function(){return Ae(!0)},onSidebarHide:function(){return Ae(!1)},filterValues:Te,onFilterChange:function(n,r){Ne(function(t){var l;return e(e({},t),((l={})[n]=r,l))})},onFilterReset:function(){if(ae){var e={};ae.data.sidebarFilters.forEach(function(n){e[n.id]="multiSelect"===n.type?[]:""}),Ne(e)}},onFilterApply:function(){Le(Te),Ae(!1),null==q||q(Te)},appliedFilters:xe,graphEmptyState:R,tables:T,tableLayout:N,sectionOrder:U,hiddenSections:x,tablePages:gn,onTableExpand:Fn,onTableLoadMore:wn,pollingEnabled:(null==hn?void 0:hn.pollingEnabled)&&cn,selectedPreset:un,handlePresetChange:function(e){dn(e)},metricCardConfig:$,kpiCtaConfig:ee,tableCtaConfig:ne,activeThreshold:fe,onThresholdViewChange:function(n,r){ge(function(t){var l,o=e({},t);return o[null!==(l=r.key)&&void 0!==l?l:"primary"]=n,o})},onAlertsClick:function(){return Pe(!0)},showAlerts:Se,onAlertClose:function(){return Pe(!1)}})):W?o(i,{children:W()}):o(h,{})}export{F as ExecutiveDashboardWrapper,F as default};
1
+ import{__assign as e,__awaiter as n,__generator as r,__rest as t,__spreadArray as l}from"../_virtual/_tslib.js";import{jsx as o,Fragment as i,jsxs as a}from"react/jsx-runtime";import u,{useState as d,useRef as s,useMemo as c,useCallback as v,useEffect as f}from"react";import{ExecutiveDashboard as g}from"./components/ExecutiveDashboard.js";import{DATE_PRESETS as b}from"./components/DashboardDateFilter/datePreset.js";import{DashboardSkeleton as h}from"./components/DashboardSkeleton/DashboardSkeleton.js";import{fetchUIConfig as p,fetchCurrentConfigUIVersionFromRedis as m,fetchDashboardData as y,fetchTableData as D}from"./api/dashboardApi.js";import{useVisibilityPolling as E}from"./hooks/useVisibilityPolling.js";var C=1e4;function F(F){var k,I,w,A=this,S=F.baseUrl,P=void 0===S?"https://dev.appmod.ai":S,T=F.configId,R=F.accessToken,j=F.authBaseUrl,M=F.graphEmptyState,O=F.tables,U=F.tableLayout,N=F.sectionOrder,x=F.hiddenSections,L=F.fetchUIConfig,B=F.fetchUIVersionFromRedis,V=F.fetchDashboardData,K=F.fetchTableData,J=F.initialStartDate,Y=F.initialEndDate,_=F.initialPreset,z=F.initialFilters,G=F.hiddenFilters,H=F.onDateChange,q=F.onFiltersApplied,Q=F.onFilterStateChange,W=F.renderLoading,X=F.renderError,Z=F.pollingConfigProp,$=F.metricCardConfig,ee=F.kpiCtaConfig,ne=F.tableCtaConfig,re=F.layout,te=null!=L?L:p,le=null!=B?B:m,oe=null!=V?V:y,ie=null!=K?K:D,ae=d(null),ue=ae[0],de=ae[1],se=d(null),ce=se[0],ve=se[1],fe=d({}),ge=fe[0],be=fe[1],he=d(!0),pe=he[0],me=he[1],ye=d(!0),De=ye[0],Ee=ye[1],Ce=d(null),Fe=Ce[0],ke=Ce[1],Ie=d(!1),we=Ie[0],Ae=Ie[1],Se=d(!1),Pe=Se[0],Te=Se[1],Re=d({}),je=Re[0],Me=Re[1],Oe=d({}),Ue=Oe[0],Ne=Oe[1],xe=d({}),Le=xe[0],Be=xe[1],Ve=d(null),Ke=Ve[0],Je=Ve[1],Ye=u.useRef(null),_e=u.useRef(!1),ze=s(null),Ge=s(null),He=s({}),qe=s(null),Qe=s(new Set),We=s(!1),Xe=s(C),Ze=s(-1),$e=s(!0),en=s(z);en.current=z;var nn=s(_);nn.current=_;var rn=JSON.stringify(null!=G?G:{}),tn=c(function(){return JSON.parse(rn)},[rn]),ln=s(tn);ln.current=tn;var on=c(function(){return e(e({},Le),tn)},[Le,tn]),an=c(function(){var n;return(null===(n=null==ue?void 0:ue.data)||void 0===n?void 0:n.sidebarFilters)?e(e({},ue),{data:e(e({},ue.data),{sidebarFilters:ue.data.sidebarFilters.filter(function(e){return!(e.schemaFilterName in tn)})})}):ue},[ue,tn]),un=d(null!==(I=null===(k=null==ue?void 0:ue.data)||void 0===k?void 0:k.dateFilters.defaultPreset)&&void 0!==I?I:"today"),dn=un[0],sn=un[1],cn=d(!1),vn=cn[0],fn=cn[1],gn=d({}),bn=gn[0],hn=gn[1],pn=c(function(){var e,n;if(ue){var r=ue.data.dateFilters;return(null==r?void 0:r.pollingEnabled)&&(Xe.current=null!==(e=r.pollingInterval)&&void 0!==e?e:C),{pollingEnabled:null!==(n=Boolean("yes"===(null==r?void 0:r.pollingEnabled)))&&void 0!==n&&n,pollingInterval:C,maxErrorInterval:5e4,backoffMultiplier:1.5}}},[ue]),mn=c(function(){return null!=Z?Z:pn},[Z,pn]),yn=function(e){var n=Object.values(b).find(function(n){return n.value===e});return n&&"getRange"in n?n.getRange():null},Dn=v(function(){return n(A,void 0,void 0,function(){var e,n,t,l,o,i,a,u,d,s,c,v,f,g,b,h,p;return r(this,function(r){switch(r.label){case 0:me(!0),ke(null),null===(u=ze.current)||void 0===u||u.abort(),e=new AbortController,ze.current=e,r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,te({configId:T,baseUrl:P,accessToken:R},e.signal)];case 2:return n=r.sent(),de(n),t={},null===(c=null===(s=null===(d=null==n?void 0:n.data)||void 0===d?void 0:d.graphBuilder)||void 0===s?void 0:s.tiers)||void 0===c||c.forEach(function(e){e.plotOptions.length>0&&(t[e.key]=e.plotOptions[0].value)}),Me(t),l={},o=null!==(v=en.current)&&void 0!==v?v:{},null===(g=null===(f=null==n?void 0:n.data)||void 0===f?void 0:f.sidebarFilters)||void 0===g||g.forEach(function(e){var n;if(!(e.schemaFilterName in ln.current)){var r="Multi select"===e.type,t=o[e.schemaFilterName];l[e.schemaFilterName]=null==t?r?[]:"":r?Array.isArray(t)?t:""===t?[]:[t]:Array.isArray(t)?null!==(n=t[0])&&void 0!==n?n:"":t}}),Ne(l),Be(l),_e.current||(i=J&&Y?{startDate:J,endDate:Y}:yn(null!==(b=nn.current)&&void 0!==b?b:null===(p=null===(h=null==n?void 0:n.data)||void 0===h?void 0:h.dateFilters)||void 0===p?void 0:p.defaultPreset))&&(_e.current=!0,Ye.current={start:i.startDate.getTime(),end:i.endDate.getTime()},Je({start:i.startDate,end:i.endDate})),[3,5];case 3:return"AbortError"===(null==(a=r.sent())?void 0:a.name)?[2]:(ke(a),[3,5]);case 4:return ze.current===e&&me(!1),[7];case 5:return[2]}})})},[T,P,R,te,J,Y]),En=v(function(){return n(A,void 0,void 0,function(){var e,n,t,l,o,i;return r(this,function(r){switch(r.label){case 0:if(We.current)return[3,8];We.current=!0,console.log("----- POLLING API ----"),null===(i=qe.current)||void 0===i||i.abort(),e=new AbortController,qe.current=e,r.label=1;case 1:return r.trys.push([1,6,7,8]),[4,le({configId:T,baseUrl:P,accessToken:R},e.signal)];case 2:return(null==(n=r.sent())?void 0:n.timestamp)&&parseInt(null==n?void 0:n.timestamp)>Ze.current?(t=yn(dn),"custom"===dn&&Ke&&(t={startDate:null==Ke?void 0:Ke.start,endDate:null==Ke?void 0:Ke.end}),[4,te({configId:T,baseUrl:P,accessToken:R},e.signal)]):[3,5];case 3:return l=r.sent(),de(l),console.log("loadData ranges: ",{selectedPreset:dn,currentRange:t}),[4,Cn(t).then(function(){return Ze.current=parseInt(n.timestamp)})];case 4:r.sent(),r.label=5;case 5:return $e.current=!1,[3,8];case 6:return"AbortError"===(null==(o=r.sent())?void 0:o.name)?[2]:(console.error("Something went wrong while fetching version from Redis"),[3,8]);case 7:return We.current=!1,[7];case 8:return[2]}})})},[dn,Ke,le,te,T,P,R]);E((null==pn?void 0:pn.pollingEnabled)&&vn,Xe.current,En,[mn,vn,En]),f(function(){return Dn(),function(){var e;return null===(e=ze.current)||void 0===e?void 0:e.abort()}},[Dn]),f(function(){if(pn&&pn.pollingEnabled){var e=pn.pollingInterval;"number"==typeof e&&!isNaN(e)&&e>0&&(Xe.current=e)}},[pn]);var Cn=v(function(e){return n(A,void 0,void 0,function(){var n,t,l,o,i,a,u,d;return r(this,function(r){switch(r.label){case 0:if(!Ke)return[2];null===(i=Ge.current)||void 0===i||i.abort(),n=new AbortController,Ge.current=n,$e.current&&Ee(!0),ke(null),console.log("loadData ranges: ",{selectedPreset:dn,currentRange:e,dateRange:Ke}),r.label=1;case 1:return r.trys.push([1,3,4,5]),t={startDate:(null==pn?void 0:pn.pollingEnabled)&&e&&"custom"!==dn?e.startDate:Ke.start,endDate:(null==pn?void 0:pn.pollingEnabled)&&e&&"custom"!==dn?e.endDate:Ke.end,filters:on},[4,oe({configId:T,baseUrl:P,accessToken:R},t,n.signal)];case 2:return l=r.sent(),ve(l),(null==pn?void 0:pn.pollingEnabled)||hn({}),Xe.current&&(null==mn?void 0:mn.pollingEnabled)&&(null==pn?void 0:pn.pollingInterval)&&(Xe.current=null!==(a=null==mn?void 0:mn.pollingInterval)&&void 0!==a?a:C,$e.current=!1),[3,5];case 3:return"AbortError"===(null==(o=r.sent())?void 0:o.name)?[2]:(ke(o),Xe.current&&(null==mn?void 0:mn.maxErrorInterval)&&(Xe.current=Math.min(Xe.current*(null!==(u=null==pn?void 0:pn.backoffMultiplier)&&void 0!==u?u:1.5),null!==(d=null==pn?void 0:pn.maxErrorInterval)&&void 0!==d?d:5e4)),[3,5]);case 4:return Ge.current===n&&Ee(!1),[7];case 5:return[2]}})})},[T,P,R,Ke,on,oe]),Fn=v(function(t,o){return n(A,void 0,void 0,function(){var n,i,a,u,d,s,c;return r(this,function(r){switch(r.label){case 0:if(!Ke||!Qe.current.has(t)||He.current[t])return[2];n=new AbortController,He.current[t]=n,i=function(){return!Qe.current.has(t)||n.signal.aborted||He.current[t]!==n},hn(function(n){var r,l,o,i,a,u,d,s;return e(e({},n),((r={})[t]={rows:null!==(o=null===(l=n[t])||void 0===l?void 0:l.rows)&&void 0!==o?o:[],cursor:null===(i=n[t])||void 0===i?void 0:i.cursor,hasMore:null!==(u=null===(a=n[t])||void 0===a?void 0:a.hasMore)&&void 0!==u&&u,loading:!0,loaded:null!==(s=null===(d=n[t])||void 0===d?void 0:d.loaded)&&void 0!==s&&s},r))}),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,ie({configId:T,baseUrl:P,accessToken:R},e({startDate:Ke.start,endDate:Ke.end,filters:on,tableKey:t,pageSize:20},o?{cursor:o}:{}),n.signal)];case 2:return a=r.sent(),u=null!==(c=null===(s=a.table)||void 0===s?void 0:s[t])&&void 0!==c?c:[],i()?[2]:(hn(function(n){var r,o,i=n[t];return i?e(e({},n),((r={})[t]={rows:l(l([],i.rows,!0),u,!0),cursor:null!==(o=a.nextCursor)&&void 0!==o?o:void 0,hasMore:a.hasNext,loading:!1,loaded:!0},r)):n}),[3,5]);case 3:return"AbortError"===(null==(d=r.sent())?void 0:d.name)||i()?[2]:(hn(function(n){var r;return n[t]?e(e({},n),((r={})[t]=e(e({},n[t]),{loading:!1,hasMore:!1}),r)):n}),[3,5]);case 4:return He.current[t]===n&&delete He.current[t],[7];case 5:return[2]}})})},[T,P,R,Ke,on,ie]),kn=v(function(e,n){var r;if(!n)return Qe.current.delete(e),null===(r=He.current[e])||void 0===r||r.abort(),delete He.current[e],void hn(function(n){var r=n,l=e;return r[l],t(r,["symbol"==typeof l?l:l+""])});Qe.current.add(e),Fn(e)},[Fn]),In=v(function(e){var n=bn[e];(null==n?void 0:n.hasMore)&&!n.loading&&n.cursor&&Fn(e,n.cursor)},[Fn,bn]);f(function(){return function(){Qe.current.clear(),Object.values(He.current).forEach(function(e){return e.abort()})}},[]),f(function(){return Cn(),function(){var e;return null===(e=Ge.current)||void 0===e?void 0:e.abort()}},[Cn]),f(function(){return function(){var e;return null===(e=qe.current)||void 0===e?void 0:e.abort()}},[]),f(function(){!function(e){var n=Object.values(b).find(function(n){return n.value===e});if("custom"!==e){var r=!(!n||!("pollingEnabled"in n)||!1===n.pollingEnabled);fn(r)}else{var t=new Date,l=(null==Ke?void 0:Ke.end)&&Ke.end.getFullYear()===t.getFullYear()&&Ke.end.getMonth()===t.getMonth()&&Ke.end.getDate()===t.getDate();fn(!!l)}}(dn)},[dn,Ke]),f(function(){var e,n,r=null!==(e=nn.current)&&void 0!==e?e:null===(n=null==ue?void 0:ue.data)||void 0===n?void 0:n.dateFilters.defaultPreset;r&&sn(r)},[null===(w=null==ue?void 0:ue.data)||void 0===w?void 0:w.dateFilters.defaultPreset]);var wn=s(Q);wn.current=Q;var An=s(dn);An.current=dn,f(function(){var e;ue&&Ke&&(null===(e=wn.current)||void 0===e||e.call(wn,{filters:on,startDate:Ke.start,endDate:Ke.end,selectedPreset:An.current}))},[ue,on,Ke]);var Sn=v(function(e){if((null==e?void 0:e.startDate)&&(null==e?void 0:e.endDate)){var n=e.startDate.getTime(),r=e.endDate.getTime();Ye.current&&Ye.current.start===n&&Ye.current.end===r||(Ye.current={start:n,end:r},Je({start:e.startDate,end:e.endDate}))}null==H||H(e),Ee(!0)},[H]);f(function(){if(ue&&ce){var n={};ce.graph.tier.forEach(function(e){var r,t;if(e.key&&e.thresholds){var l=Object.keys(e.thresholds);if(l.length>0){var o=e.thresholds[l[0]];if(o){var i=Object.keys(o);if(i.length>0){var a=null===(t=null===(r=ue.data.graphBuilder)||void 0===r?void 0:r.tiers)||void 0===t?void 0:t.find(function(n){return n.key===e.key}),u=(null==a?void 0:a.series)||[],d=function(e){var n;return null===(n=u.find(function(n){return n.key===e}))||void 0===n?void 0:n.kpiRole},s=i.find(function(e){return"primary"===d(e)}),c=i.find(function(e){return"secondary"===d(e)});n[e.key]=s||c||i[0]}}}}}),be(function(r){return e(e({},n),r)})}},[ue,ce]);var Pn=pe||De&&!ce;return Fe?X?o(i,{children:X(Fe,Dn)}):a("div",e({style:{padding:24,color:"#b91c1c"}},{children:["Failed to load dashboard: ",Fe.message,o("button",e({onClick:Dn,style:{marginLeft:12}},{children:"Retry"}))]})):!Pn&&ue&&ce&&Ke?(console.log("pollingEnabled: ",null==pn?void 0:pn.pollingEnabled,vn),o(g,{baseUrl:P&&"string"==typeof P&&P.trim()?P:void 0,configId:T&&"string"==typeof T&&T.trim()?T:void 0,accessToken:R&&"string"==typeof R&&R.trim()?R:void 0,authBaseUrl:j&&"string"==typeof j&&j.trim()?j:void 0,uiConfig:null!=an?an:ue,data:ce,dataLoading:De,startDate:Ke.start,endDate:Ke.end,onDateChange:Sn,onRefresh:function(){Cn(),Ee(!0)},selectedKpis:je,onKpiChange:function(n,r){Me(function(t){var l;return e(e({},t),((l={})[n]=r,l))})},sidebarVisible:we,onSidebarShow:function(){return Ae(!0)},onSidebarHide:function(){return Ae(!1)},filterValues:Ue,onFilterChange:function(n,r){Ne(function(t){var l;return e(e({},t),((l={})[n]=r,l))})},onFilterReset:function(){if(ue){var e={};ue.data.sidebarFilters.forEach(function(n){e[n.id]="multiSelect"===n.type?[]:""}),Ne(e),Be(e),Ae(!1),null==q||q(e)}},onFilterApply:function(){Be(Ue),Ae(!1),null==q||q(Ue)},appliedFilters:Le,graphEmptyState:M,tables:O,tableLayout:U,sectionOrder:N,hiddenSections:x,tablePages:bn,onTableExpand:kn,onTableLoadMore:In,pollingEnabled:(null==pn?void 0:pn.pollingEnabled)&&vn,selectedPreset:dn,handlePresetChange:function(e){sn(e)},metricCardConfig:$,kpiCtaConfig:ee,tableCtaConfig:ne,layout:re,activeThreshold:ge,onThresholdViewChange:function(n,r){be(function(t){var l,o=e({},t);return o[null!==(l=r.key)&&void 0!==l?l:"primary"]=n,o})},onAlertsClick:function(){return Te(!0)},showAlerts:Pe,onAlertClose:function(){return Te(!1)}})):W?o(i,{children:W()}):o(h,{})}export{F as ExecutiveDashboardWrapper,F as default};
2
2
  //# sourceMappingURL=ExecutiveDashboardWrapper.js.map
@@ -1,2 +1,2 @@
1
- import{__awaiter as e,__generator as t,__assign as n}from"../../_virtual/_tslib.js";import{DashboardApiError as r}from"./dashboardApi.js";var s=function(e){try{return e.replace(/\/+$/,"")}catch(t){return e}};function i(n,s,i,o){var a,c;return e(this,void 0,void 0,function(){var e,u;return t(this,function(t){switch(t.label){case 0:if(!i)throw new r("Access token is required.");return[4,fetch(n,{method:"POST",headers:{accept:"application/json","Content-Type":"application/json",Authorization:"Bearer ".concat(i)},body:JSON.stringify(s),signal:o})];case 1:if(!(e=t.sent()).ok)throw new r("Request failed with status ".concat(e.status),e.status);return[4,e.json()];case 2:if(!1===(u=t.sent()).success)throw new r((null===(a=u.error)||void 0===a?void 0:a.errorMessage)||"Request failed");return[2,null!==(c=u.data)&&void 0!==c?c:u]}})})}function o(n,s,i,o){var a,c;return e(this,void 0,void 0,function(){var e,u;return t(this,function(t){switch(t.label){case 0:if(!s)throw new r("Access token is required.");return[4,fetch(n,{method:"GET",headers:{accept:"application/json",Authorization:"Bearer ".concat(s)},credentials:o?"include":void 0,signal:i})];case 1:if(!(e=t.sent()).ok)throw new r("Request failed with status ".concat(e.status),e.status);return[4,e.json()];case 2:if(!1===(u=t.sent()).success)throw new r((null===(a=u.error)||void 0===a?void 0:a.errorMessage)||"Request failed");return[2,null!==(c=u.data)&&void 0!==c?c:u]}})})}function a(n,s,i,o){var a,c;return e(this,void 0,void 0,function(){var e,u;return t(this,function(t){switch(t.label){case 0:if(!i)throw new r("Access token is required.");return[4,fetch(n,{method:"PUT",headers:{accept:"application/json","Content-Type":"application/json",Authorization:"Bearer ".concat(i)},body:JSON.stringify(s),signal:o})];case 1:if(!(e=t.sent()).ok)throw new r("Request failed with status ".concat(e.status),e.status);return[4,e.json()];case 2:if(!1===(u=t.sent()).success)throw new r((null===(a=u.error)||void 0===a?void 0:a.errorMessage)||"Request failed");return[2,null!==(c=u.data)&&void 0!==c?c:u]}})})}function c(n,s,i){var o,a;return e(this,void 0,void 0,function(){var e,c;return t(this,function(t){switch(t.label){case 0:if(!s)throw new r("Access token is required.");return[4,fetch(n,{method:"DELETE",headers:{accept:"application/json",Authorization:"Bearer ".concat(s)},signal:i})];case 1:if(!(e=t.sent()).ok)throw new r("Request failed with status ".concat(e.status),e.status);return[4,e.json()];case 2:if(!1===(c=t.sent()).success)throw new r((null===(o=c.error)||void 0===o?void 0:o.errorMessage)||"Request failed");return[2,null!==(a=c.data)&&void 0!==a?a:c]}})})}function u(n,r){var i=n.baseUrl,a=void 0===i?"":i,c=n.configId,u=n.accessToken;return e(this,void 0,void 0,function(){return t(this,function(e){switch(e.label){case 0:return[4,o("".concat(s(a),"/federated/alerts/").concat(c,"/rules"),u,r)];case 1:return[2,e.sent()]}})})}function d(r,o,a){var c=r.baseUrl,u=void 0===c?"":c,d=r.configId,l=r.accessToken;return e(this,void 0,void 0,function(){var e;return t(this,function(t){switch(t.label){case 0:return e=n(n({},o),{config_id:d}),[4,i("".concat(s(u),"/federated/alerts/rules"),e,l,a)];case 1:return[2,t.sent()]}})})}function l(r,i,o,c){var u=r.baseUrl,d=void 0===u?"":u,l=r.configId,f=r.accessToken;return e(this,void 0,void 0,function(){var e;return t(this,function(t){switch(t.label){case 0:return e=n(n({},o),{config_id:l}),[4,a("".concat(s(d),"/federated/alerts/rules/").concat(i),e,f,c)];case 1:return[2,t.sent()]}})})}function f(n,r,i){var o=n.baseUrl,a=void 0===o?"":o;n.configId;var u=n.accessToken;return e(this,void 0,void 0,function(){return t(this,function(e){switch(e.label){case 0:return[4,c("".concat(s(a),"/federated/alerts/rules/").concat(r),u,i)];case 1:return[2,e.sent()]}})})}function h(n,r,o){var a=n.baseUrl,c=void 0===a?"":a,u=n.configId,d=n.accessToken;return e(this,void 0,void 0,function(){return t(this,function(e){switch(e.label){case 0:return[4,i("".concat(s(c),"/federated/alerts/rules/").concat(r,"/status"),{config_id:u},d,o)];case 1:return[2,e.sent()]}})})}function v(n,r){var i=n.baseUrl,a=void 0===i?"":i,c=n.configId,u=n.accessToken;return e(this,void 0,void 0,function(){return t(this,function(e){switch(e.label){case 0:return[4,o("".concat(s(a),"/federated/alerts/").concat(c,"/history/sources"),u,r)];case 1:return[2,e.sent()]}})})}function w(n,r){var i=n.baseUrl,a=void 0===i?"":i,c=n.configId,u=n.accessToken;return e(this,void 0,void 0,function(){return t(this,function(e){switch(e.label){case 0:return[4,o("".concat(s(a),"/federated/alerts/").concat(c,"/history"),u,r)];case 1:return[2,e.sent()]}})})}function p(n,i,a){var c=n.authBaseUrl,u=void 0===c?"":c,d=n.accessToken,l=void 0===d?"":d;return e(this,void 0,void 0,function(){var e,n;return t(this,function(t){switch(t.label){case 0:if(!u)throw new r("authBaseUrl is required.");return e=new URLSearchParams,i&&Object.entries(i).forEach(function(t){var n=t[0],r=t[1];null!=r&&""!==r&&e.append(n,String(r))}),n=e.toString(),[4,o("".concat(s(u),"/api/user/get-by-query-v2").concat(n?"?"+n:""),l,a,!0)];case 1:return[2,t.sent()]}})})}export{d as createAlert,f as deleteAlert,w as fetchAlertHistory,u as fetchAlerts,v as fetchDistinctSources,p as getAllUsers,l as updateAlert,h as updateAlertStatus};
1
+ import{__awaiter as t,__generator as e,__assign as n}from"../../_virtual/_tslib.js";import{DashboardApiError as r}from"./dashboardApi.js";var s=function(t){try{return t.replace(/\/+$/,"")}catch(e){return t}};function i(n,s,i,o){var a,c;return t(this,void 0,void 0,function(){var t,u;return e(this,function(e){switch(e.label){case 0:if(!i)throw new r("Access token is required.");return[4,fetch(n,{method:"POST",headers:{accept:"application/json","Content-Type":"application/json",Authorization:"Bearer ".concat(i)},body:JSON.stringify(s),signal:o})];case 1:if(!(t=e.sent()).ok)throw new r("Request failed with status ".concat(t.status),t.status);return[4,t.json()];case 2:if(!1===(u=e.sent()).success)throw new r((null===(a=u.error)||void 0===a?void 0:a.errorMessage)||"Request failed");return[2,null!==(c=u.data)&&void 0!==c?c:u]}})})}function o(n,s,i,o){var a,c;return t(this,void 0,void 0,function(){var t,u;return e(this,function(e){switch(e.label){case 0:if(!s)throw new r("Access token is required.");return[4,fetch(n,{method:"GET",headers:{accept:"application/json",Authorization:"Bearer ".concat(s)},credentials:o?"include":void 0,signal:i})];case 1:if(!(t=e.sent()).ok)throw new r("Request failed with status ".concat(t.status),t.status);return[4,t.json()];case 2:if(!1===(u=e.sent()).success)throw new r((null===(a=u.error)||void 0===a?void 0:a.errorMessage)||"Request failed");return[2,null!==(c=u.data)&&void 0!==c?c:u]}})})}function a(n,s,i,o){var a,c;return t(this,void 0,void 0,function(){var t,u;return e(this,function(e){switch(e.label){case 0:if(!i)throw new r("Access token is required.");return[4,fetch(n,{method:"PUT",headers:{accept:"application/json","Content-Type":"application/json",Authorization:"Bearer ".concat(i)},body:JSON.stringify(s),signal:o})];case 1:if(!(t=e.sent()).ok)throw new r("Request failed with status ".concat(t.status),t.status);return[4,t.json()];case 2:if(!1===(u=e.sent()).success)throw new r((null===(a=u.error)||void 0===a?void 0:a.errorMessage)||"Request failed");return[2,null!==(c=u.data)&&void 0!==c?c:u]}})})}function c(n,s,i){var o,a;return t(this,void 0,void 0,function(){var t,c;return e(this,function(e){switch(e.label){case 0:if(!s)throw new r("Access token is required.");return[4,fetch(n,{method:"DELETE",headers:{accept:"application/json",Authorization:"Bearer ".concat(s)},signal:i})];case 1:if(!(t=e.sent()).ok)throw new r("Request failed with status ".concat(t.status),t.status);return[4,t.json()];case 2:if(!1===(c=e.sent()).success)throw new r((null===(o=c.error)||void 0===o?void 0:o.errorMessage)||"Request failed");return[2,null!==(a=c.data)&&void 0!==a?a:c]}})})}function u(n,r){var i=n.baseUrl,a=void 0===i?"":i,c=n.configId,u=n.accessToken;return t(this,void 0,void 0,function(){return e(this,function(t){switch(t.label){case 0:return[4,o("".concat(s(a),"/federated/alerts/").concat(c,"/plots"),u,r)];case 1:return[2,t.sent()]}})})}function d(n,r){var i=n.baseUrl,a=void 0===i?"":i,c=n.configId,u=n.accessToken;return t(this,void 0,void 0,function(){return e(this,function(t){switch(t.label){case 0:return[4,o("".concat(s(a),"/federated/alerts/").concat(c,"/rules"),u,r)];case 1:return[2,t.sent()]}})})}function l(r,o,a){var c=r.baseUrl,u=void 0===c?"":c,d=r.configId,l=r.accessToken;return t(this,void 0,void 0,function(){var t;return e(this,function(e){switch(e.label){case 0:return t=n(n({},o),{config_id:d}),[4,i("".concat(s(u),"/federated/alerts/").concat(d,"/rules"),t,l,a)];case 1:return[2,e.sent()]}})})}function f(n,r,i,o){var c=n.baseUrl,u=void 0===c?"":c,d=n.configId,l=n.accessToken;return t(this,void 0,void 0,function(){return e(this,function(t){switch(t.label){case 0:return[4,a("".concat(s(u),"/federated/alerts/").concat(d,"/rules/").concat(r),{payload:i},l,o)];case 1:return[2,t.sent()]}})})}function h(n,r,i){var o=n.baseUrl,a=void 0===o?"":o,u=n.configId,d=n.accessToken;return t(this,void 0,void 0,function(){return e(this,function(t){switch(t.label){case 0:return[4,c("".concat(s(a),"/federated/alerts/").concat(u,"/rules/").concat(r),d,i)];case 1:return[2,t.sent()]}})})}function v(n,r){var i=n.baseUrl,a=void 0===i?"":i,c=n.configId,u=n.accessToken;return t(this,void 0,void 0,function(){return e(this,function(t){switch(t.label){case 0:return[4,o("".concat(s(a),"/federated/alerts/").concat(c,"/history/sources"),u,r)];case 1:return[2,t.sent()]}})})}function w(n,r){var i=n.baseUrl,a=void 0===i?"":i,c=n.configId,u=n.accessToken;return t(this,void 0,void 0,function(){return e(this,function(t){switch(t.label){case 0:return[4,o("".concat(s(a),"/federated/alerts/").concat(c,"/history"),u,r)];case 1:return[2,t.sent()]}})})}function p(n,i,a){var c=n.authBaseUrl,u=void 0===c?"":c,d=n.accessToken,l=void 0===d?"":d;return t(this,void 0,void 0,function(){var t,n;return e(this,function(e){switch(e.label){case 0:if(!u)throw new r("authBaseUrl is required.");return t=new URLSearchParams,i&&Object.entries(i).forEach(function(e){var n=e[0],r=e[1];null!=r&&""!==r&&t.append(n,String(r))}),n=t.toString(),[4,o("".concat(s(u),"/api/user/get-by-query-v2").concat(n?"?"+n:""),l,a,!0)];case 1:return[2,e.sent()]}})})}export{l as createAlert,h as deleteAlert,w as fetchAlertHistory,d as fetchAlerts,v as fetchDistinctSources,u as fetchPlotAndKPIs,p as getAllUsers,f as updateAlert};
2
2
  //# sourceMappingURL=alertsapi.js.map
@@ -1,2 +1,2 @@
1
- import{__extends as t,__awaiter as e,__generator as r,__assign as n}from"../../_virtual/_tslib.js";var i=function(e){function r(t,r){var n=e.call(this,t)||this;return n.name="DashboardApiError",n.status=r,n}return t(r,e),r}(Error),a=function(t){return t.replace(/\/+$/,"")};function s(t,n,a){var s;return e(this,void 0,void 0,function(){var e,o;return r(this,function(r){switch(r.label){case 0:return[4,fetch(t,{method:"POST",headers:{accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(n),signal:a})];case 1:if(!(e=r.sent()).ok)throw new i("Request failed with status ".concat(e.status),e.status);return[4,e.json()];case 2:if(!(o=r.sent()).success)throw new i((null===(s=o.error)||void 0===s?void 0:s.errorMessage)||"Request failed");return[2,o.data]}})})}function o(t,n){var a;return e(this,void 0,void 0,function(){var e,s;return r(this,function(r){switch(r.label){case 0:return[4,fetch(t,{method:"GET",headers:{accept:"application/json"},signal:n})];case 1:if(!(e=r.sent()).ok)throw new i("Request failed with status ".concat(e.status),e.status);return[4,e.json()];case 2:if(!(s=r.sent()).success)throw new i((null===(a=s.error)||void 0===a?void 0:a.errorMessage)||"Request failed");return[2,s.data]}})})}function c(t,n){var i=t.configId,o=t.baseUrl,c=void 0===o?"":o;return e(this,void 0,void 0,function(){return r(this,function(t){return[2,s("".concat(a(c),"/federated/filters/ui"),{config_id:i},n)]})})}function u(t,n){var i=t.configId,o=t.baseUrl,c=void 0===o?"":o;return e(this,void 0,void 0,function(){var t;return r(this,function(e){switch(e.label){case 0:return[4,s("".concat(a(c),"/federated/filters/distinct-value"),{config_id:i},n)];case 1:return[2,(null==(t=e.sent())?void 0:t.sidebarFilters)||{}]}})})}function d(t,i){return e(this,void 0,void 0,function(){var e,a,s;return r(this,function(r){switch(r.label){case 0:return[4,Promise.all([c(t,i),u(t,i)])];case 1:return e=r.sent(),a=e[0],s=e[1],[2,{data:n(n({},a),{sidebarFilters:(a.sidebarFilters||[]).map(function(t){return n(n({},t),{options:s[t.schemaFilterName]||[]})})})}]}})})}function f(t,n){var i=t.configId,s=void 0===i?"":i,c=t.baseUrl,u=void 0===c?"":c;return e(this,void 0,void 0,function(){return r(this,function(t){switch(t.label){case 0:return[4,o("".concat(a(null!=u?u:""),"/federated/filters/dashboard/").concat(s,"/last-updated/"),n)];case 1:return[2,t.sent()]}})})}function l(t){void 0===t&&(t={});var e={};return Object.entries(t).forEach(function(t){var r=t[0],n=t[1];Array.isArray(n)?n.length>0&&(e[r]=n):""!==n&&null!=n&&(e[r]=[n])}),e}function v(t,n,i){var o=t.configId,c=t.baseUrl,u=void 0===c?"":c;return e(this,void 0,void 0,function(){var t;return r(this,function(e){return t={config_id:o,dateFilters:{startDate:n.startDate?n.startDate.toISOString():"",endDate:n.endDate?n.endDate.toISOString():""},sidebarFilters:l(n.filters)},[2,s("".concat(a(u),"/federated/filters/get-data"),t,i)]})})}function h(t,i,o){var c,u=t.configId,d=t.baseUrl,f=void 0===d?"":d;return e(this,void 0,void 0,function(){return r(this,function(t){return[2,s("".concat(a(f),"/federated/filters/table-data"),n({config_id:u,dateFilters:{startDate:i.startDate?i.startDate.toISOString():"",endDate:i.endDate?i.endDate.toISOString():""},sidebarFilters:l(i.filters),tableKey:i.tableKey,pageSize:null!==(c=i.pageSize)&&void 0!==c?c:20},i.cursor?{cursor:i.cursor}:{}),o)]})})}export{i as DashboardApiError,f as fetchCurrentConfigUIVersionFromRedis,v as fetchDashboardData,h as fetchTableData,d as fetchUIConfig};
1
+ import{__extends as t,__awaiter as e,__generator as r,__assign as n}from"../../_virtual/_tslib.js";var i=function(e){function r(t,r){var n=e.call(this,t)||this;return n.name="DashboardApiError",n.status=r,n}return t(r,e),r}(Error),a=function(t){return t.replace(/\/+$/,"")},s=function(t){return t?{Authorization:"Bearer ".concat(t)}:{}};function o(t,a,o,c){var u;return e(this,void 0,void 0,function(){var e,d;return r(this,function(r){switch(r.label){case 0:return[4,fetch(t,{method:"POST",headers:n({accept:"application/json","Content-Type":"application/json"},s(o)),body:JSON.stringify(a),signal:c})];case 1:if(!(e=r.sent()).ok)throw new i("Request failed with status ".concat(e.status),e.status);return[4,e.json()];case 2:if(!(d=r.sent()).success)throw new i((null===(u=d.error)||void 0===u?void 0:u.errorMessage)||"Request failed");return[2,d.data]}})})}function c(t,a,o){var c;return e(this,void 0,void 0,function(){var e,u;return r(this,function(r){switch(r.label){case 0:return[4,fetch(t,{method:"GET",headers:n({accept:"application/json"},s(a)),signal:o})];case 1:if(!(e=r.sent()).ok)throw new i("Request failed with status ".concat(e.status),e.status);return[4,e.json()];case 2:if(!(u=r.sent()).success)throw new i((null===(c=u.error)||void 0===c?void 0:c.errorMessage)||"Request failed");return[2,u.data]}})})}function u(t,n){var i=t.configId,s=t.baseUrl,c=void 0===s?"":s,u=t.accessToken;return e(this,void 0,void 0,function(){return r(this,function(t){return[2,o("".concat(a(c),"/federated/filters/ui"),{config_id:i},u,n)]})})}function d(t,n){var i=t.configId,s=t.baseUrl,c=void 0===s?"":s,u=t.accessToken;return e(this,void 0,void 0,function(){var t;return r(this,function(e){switch(e.label){case 0:return[4,o("".concat(a(c),"/federated/filters/distinct-value"),{config_id:i},u,n)];case 1:return[2,(null==(t=e.sent())?void 0:t.sidebarFilters)||{}]}})})}function f(t,i){return e(this,void 0,void 0,function(){var e,a,s;return r(this,function(r){switch(r.label){case 0:return[4,Promise.all([u(t,i),d(t,i)])];case 1:return e=r.sent(),a=e[0],s=e[1],[2,{data:n(n({},a),{sidebarFilters:(a.sidebarFilters||[]).map(function(t){return n(n({},t),{options:s[t.schemaFilterName]||[]})})})}]}})})}function l(t,n){var i=t.configId,s=void 0===i?"":i,o=t.baseUrl,u=void 0===o?"":o,d=t.accessToken;return e(this,void 0,void 0,function(){return r(this,function(t){switch(t.label){case 0:return[4,c("".concat(a(null!=u?u:""),"/federated/filters/dashboard/").concat(s,"/last-updated/"),d,n)];case 1:return[2,t.sent()]}})})}function v(t){void 0===t&&(t={});var e={};return Object.entries(t).forEach(function(t){var r=t[0],n=t[1];Array.isArray(n)?n.length>0&&(e[r]=n):""!==n&&null!=n&&(e[r]=[n])}),e}function h(t,n,i){var s=t.configId,c=t.baseUrl,u=void 0===c?"":c,d=t.accessToken;return e(this,void 0,void 0,function(){var t;return r(this,function(e){return t={config_id:s,dateFilters:{startDate:n.startDate?n.startDate.toISOString():"",endDate:n.endDate?n.endDate.toISOString():""},sidebarFilters:v(n.filters)},[2,o("".concat(a(u),"/federated/filters/get-data"),t,d,i)]})})}function b(t,i,s){var c,u=t.configId,d=t.baseUrl,f=void 0===d?"":d,l=t.accessToken;return e(this,void 0,void 0,function(){return r(this,function(t){return[2,o("".concat(a(f),"/federated/filters/table-data"),n({config_id:u,dateFilters:{startDate:i.startDate?i.startDate.toISOString():"",endDate:i.endDate?i.endDate.toISOString():""},sidebarFilters:v(i.filters),tableKey:i.tableKey,pageSize:null!==(c=i.pageSize)&&void 0!==c?c:20},i.cursor?{cursor:i.cursor}:{}),l,s)]})})}export{i as DashboardApiError,l as fetchCurrentConfigUIVersionFromRedis,h as fetchDashboardData,b as fetchTableData,f as fetchUIConfig};
2
2
  //# sourceMappingURL=dashboardApi.js.map
@@ -1,2 +1,2 @@
1
- import{__assign as e,__spreadArray as r,__awaiter as t,__generator as n}from"../../../_virtual/_tslib.js";import{jsx as i,jsxs as o,Fragment as l}from"react/jsx-runtime";import{Toast as a}from"primereact/toast";import s from"../common/ConfirmationModal.js";import{ChevronRight as c,Pencil as u,MoreVertical as d,Loader2 as p,Play as f,Pause as y,Trash2 as h}from"lucide-react";import v from"../TablePage/TablePage.js";import g from"../FiltersSidebar/FiltersSidebar.js";import{useState as b,useRef as m,useEffect as x,useMemo as S,useCallback as w}from"react";import{createPortal as C}from"react-dom";import A from"./CreateAlertModal.js";import{fetchAlertHistory as k,deleteAlert as F,updateAlertStatus as E,fetchAlerts as z,fetchDistinctSources as T,getAllUsers as D,createAlert as P,updateAlert as L}from"../../api/alertsapi.js";var N=function(N){var I=N.baseUrl,U=N.authBaseUrl,R=N.configId,_=N.onClose,j=N.uiConfig,B=N.accessToken,W=b(""),O=W[0],q=W[1],V=b([]),H=V[0],K=V[1],M=b(!1),G=M[0],X=M[1],Y=b([]),J=Y[0],Q=Y[1],Z=b(!1),$=Z[0],ee=Z[1],re=b({}),te=re[0],ne=re[1],ie=b({}),oe=ie[0],le=ie[1],ae=b(null),se=ae[0],ce=ae[1],ue=b(!1),de=ue[0],pe=ue[1],fe=b(null),ye=fe[0],he=fe[1],ve=b(null),ge=ve[0],be=ve[1],me=m({}),xe=b({}),Se=xe[0],we=xe[1],Ce=b(null),Ae=Ce[0],ke=Ce[1],Fe=b(!1),Ee=Fe[0],ze=Fe[1],Te=b(""),De=Te[0],Pe=Te[1],Le=b([]),Ne=Le[0],Ie=Le[1],Ue=b(!1),Re=Ue[0],_e=Ue[1],je=b(!1),Be=je[0],We=je[1],Oe=b({}),qe=Oe[0],Ve=Oe[1],He=b({}),Ke=He[0],Me=He[1],Ge=b("history"),Xe=Ge[0],Ye=Ge[1],Je=m(null),Qe=m(null),Ze=m(null),$e=m(null);function er(e){var r=new Date(e);return isNaN(r.getTime())?e:r.toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}x(function(){$&&le(te)},[$,te]),x(function(){Be&&Me(qe)},[Be,qe]);var rr=function(){return t(void 0,void 0,void 0,function(){var e,r,t,i;return n(this,function(n){switch(n.label){case 0:X(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,z({baseUrl:I,configId:R||"",accessToken:B})];case 2:return e=n.sent(),r=e,K(Array.isArray(r)?r:[]),[3,5];case 3:return t=n.sent(),console.error("Failed to fetch alerts:",t),null===(i=Je.current)||void 0===i||i.show({severity:"error",summary:"Error",detail:"Failed to load alerts. Please refresh.",life:3e3}),K([]),[3,5];case 4:return X(!1),[7];case 5:return[2]}})})};x(function(){rr()},[]),x(function(){t(void 0,void 0,void 0,function(){var e,r,t,i;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,T({baseUrl:I,configId:R||"",accessToken:B})];case 1:return e=n.sent(),r=e,Q(Array.isArray(r)?r:[]),[3,3];case 2:return t=n.sent(),console.error("Failed to fetch distinct sources:",t),null===(i=Je.current)||void 0===i||i.show({severity:"error",summary:"Error",detail:"Failed to load data sources.",life:3e3}),[3,3];case 3:return[2]}})})},[]),x(function(){var e=!0;return"history"===Xe?(_e(!0),k({baseUrl:I,configId:R||"",accessToken:B}).then(function(r){e&&Ie(r||[])}).catch(function(r){var t;console.error("Error fetching history:",r),null===(t=Je.current)||void 0===t||t.show({severity:"error",summary:"Error",detail:"Failed to load alert history.",life:3e3}),e&&Ie([])}).finally(function(){e&&_e(!1)})):Ie([]),function(){e=!1}},[Xe]);var tr=(Array.isArray(H)?H:[]).map(function(e){var r,t,n,i=e.kpiType?e.kpiType.charAt(0).toUpperCase()+e.kpiType.slice(1):"—",o=e.status?e.status.charAt(0).toUpperCase()+e.status.slice(1):"—",l=(null===(t=null===(r=e.recipients)||void 0===r?void 0:r.userEmails)||void 0===t?void 0:t.map(function(e){return{name:e,email:e,value:e,label:e}}))||[],a={">":"Greater than","<":"Less than",">=":"Greater than or equal to","<=":"Less than or equal to"}[e.conditionType]||e.conditionType||"",s=a?"".concat(a," ").concat(e.thresholdValue):"".concat(e.thresholdValue);return{id:e.id,alertName:e.name,type:i,status:o,subscribers:l,raw:e,kpi:(n=e.kpiKey,n?n.split("_").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join(" "):"—"),threshold:s,severity:e.severity,createdOn:e.createdAt?er(e.createdAt):"—",rawScope:e.entityType,triggerConfig:{"Evaluation Type":e.evaluationType,"Evaluation period":e.evaluationPeriod,"Trigger After":e.triggerAfter?"".concat(e.triggerAfter," data points"):void 0}}}),nr=S(function(){return tr.filter(function(e){var r,t,n=!te.severity||(null===(r=e.severity)||void 0===r?void 0:r.toLowerCase())===te.severity.toLowerCase(),i=!te.status||(null===(t=e.status)||void 0===t?void 0:t.toLowerCase())===te.status.toLowerCase();return n&&i})},[te,tr]),ir=S(function(){var e=0,r=!1;return Object.entries(qe).forEach(function(t){var n=t[0],i=t[1];null===i||""===i||Array.isArray(i)&&0===i.length||("dateFrom"===n||"dateTo"===n?r=!0:e+=Array.isArray(i)?i.length:1)}),r&&(e+=1),e},[qe]),or=Object.values(te).reduce(function(e,r){return e+(Array.isArray(r)?r.length:r&&""!==r?1:0)},0),lr=[{key:"alertName",header:i("span",e({style:{fontSize:"13px"}},{children:"Alert Name"})),body:function(r){return o("div",e({style:{fontWeight:500,display:"flex",alignItems:"center",gap:"8px",color:"#475569",fontSize:"13px"}},{children:[i("span",e({className:"q-alert-chevron",style:{cursor:"pointer",display:"flex",padding:"4px"}},{children:i(c,{size:16})})),r.alertName||"—"]}))}},{key:"kpi",header:i("span",e({style:{fontSize:"13px"}},{children:"KPI"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.kpi||"—"}))}},{key:"threshold",header:i("span",e({style:{fontSize:"13px"}},{children:"Threshold"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px",whiteSpace:"nowrap"}},{children:r.threshold||"—"}))}},{key:"severity",header:i("span",e({style:{fontSize:"13px"}},{children:"Severity"})),body:function(r){var t=r.severity||"",n=t.charAt(0).toUpperCase()+t.slice(1),o="#F1F5F9",l="#475569";return"critical"===t.toLowerCase()?(o="#FEE2E2",l="#DC2626"):"warning"===t.toLowerCase()&&(o="#FEF3C7",l="#D97706"),i("span",e({style:{background:o,color:l,padding:"2px 8px",borderRadius:"12px",fontSize:"12px",fontWeight:600,display:"inline-block"}},{children:n||"—"}))}},{key:"createdOn",header:i("span",e({style:{fontSize:"13px"}},{children:"Created on"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.createdOn}))}},{key:"status",header:i("span",e({style:{fontSize:"13px"}},{children:"Status"})),body:function(r){var t="#F1F5F9",n="#475569",o=r.status||"Active";return"active"===o.toLowerCase()?(t="#DCFCE7",n="#16A34A"):"failed"===o.toLowerCase()?(t="#FEE2E2",n="#DC2626"):"paused"===o.toLowerCase()&&(t="#F1F5F9",n="#64748B"),i("span",e({style:{background:t,color:n,padding:"2px 8px",borderRadius:"12px",fontSize:"12px",fontWeight:600,whiteSpace:"nowrap",display:"inline-block"}},{children:o.charAt(0).toUpperCase()+o.slice(1)}))}},{key:"customActions",header:i("span",e({style:{fontSize:"13px"}},{children:"Actions"})),body:function(r){var t="Failed"===r.status||"Paused"===r.status;return o("div",e({style:{display:"flex",alignItems:"center",gap:"12px",flexWrap:"nowrap",position:"relative"}},{children:[o("button",e({onClick:function(e){e.stopPropagation(),ce(r),pe(!0)},style:{background:"white",color:t?"#94A3B8":"#475569",border:"1px solid #cbd5e1",padding:"6px 12px",borderRadius:"6px",fontSize:"13px",display:"flex",alignItems:"center",gap:"6px",cursor:t?"not-allowed":"pointer",fontWeight:500,opacity:t?.6:1,whiteSpace:"nowrap",flexShrink:0},disabled:t},{children:[i(u,{size:12})," Edit Alert"]})),i("button",e({ref:function(e){me.current[r.id]=e},className:"q-alert-kebab-trigger",onClick:function(e){return pr(e,r)}},{children:i(d,{size:16})}))]}))}}],ar=[{id:"severity",label:"Severity",type:"singleSelect",options:[{label:"All",value:""},{label:"Critical",value:"critical"},{label:"Warning",value:"warning"},{label:"Info",value:"info"}],value:oe.severity||"",onChange:function(r){return le(function(t){return e(e({},t),{severity:r})})}},{id:"status",label:"Status",type:"singleSelect",options:[{label:"All",value:""},{label:"Active",value:"active"},{label:"Paused",value:"paused"}],value:oe.status||"",onChange:function(r){return le(function(t){return e(e({},t),{status:r})})}}],sr=[{key:"no",header:i("span",e({style:{fontSize:"13px"}},{children:"No"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.no}))}},{key:"alert_name",header:i("span",e({style:{fontSize:"13px"}},{children:"Alert Name"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.alert_name}))}},{key:"source",header:i("span",e({style:{fontSize:"13px"}},{children:"Source"})),body:function(r){return i("div",e({style:{color:"#475569",fontSize:"13px",display:"flex",flexDirection:"column"}},{children:r.source.length>0?o(l,{children:[o("span",{children:[r.source[0]," ",r.source.length>1?"|":""]}),r.source.slice(1).map(function(r,t){return i("span",e({style:{fontWeight:600,color:"#0F172A"}},{children:r}),t)})]}):"—"}))}},{key:"severity",header:i("span",e({style:{fontSize:"13px"}},{children:"Severity"})),body:function(r){var t=r.severity||"",n=t.charAt(0).toUpperCase()+t.slice(1),o="#F1F5F9",l="#475569";return"critical"===t.toLowerCase()?(o="#FEE2E2",l="#DC2626"):"warning"===t.toLowerCase()&&(o="#FEF3C7",l="#D97706"),i("span",e({style:{background:o,color:l,padding:"2px 8px",borderRadius:"12px",fontSize:"12px",fontWeight:600,display:"inline-block"}},{children:n||"—"}))}},{key:"triggered_at",header:i("span",e({style:{fontSize:"13px"}},{children:"Triggered at"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.triggered_at}))}},{key:"current_value",header:i("span",e({style:{fontSize:"13px"}},{children:"Current value"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.current_value}))}},{key:"threshold",header:i("span",e({style:{fontSize:"13px"}},{children:"Threshold"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.threshold}))}},{key:"actions",header:i("span",e({style:{fontSize:"13px"}},{children:"Actions"})),body:function(r){return i("button",e({style:{background:"white",color:"#475569",border:"1px solid #cbd5e1",padding:"6px 12px",borderRadius:"6px",fontSize:"13px",cursor:"pointer",fontWeight:500}},{children:"View alert"}))}}],cr=S(function(){return Ne.map(function(e,r){return{id:e.historyId||"hist_".concat(r),no:r+1,alert_name:e.title||"—",rawSource:e.source,source:e.source?String(e.source).split("|").map(function(e){return e.trim()}):[],severity:e.severity||"—",triggered_at:e.triggeredAt?er(e.triggeredAt):"—",current_value:void 0!==e.currentValue?String(e.currentValue):"—",threshold:void 0!==e.thresholdValue?String(e.thresholdValue):"—"}})},[Ne]),ur=S(function(){return cr.filter(function(e,r){var t,n=!qe.severity||(null===(t=e.severity)||void 0===t?void 0:t.toLowerCase())===qe.severity.toLowerCase(),i=qe.source,o=!i||e.rawSource.includes(i),l=new Date(e.triggered_at),a=!qe.dateFrom||l>=qe.dateFrom,s=!qe.dateTo||l<=qe.dateTo;return n&&o&&a&&s})},[qe,cr,Ne]),dr=[{id:"source",label:"Source",type:"singleSelect",options:r([{label:"All",value:""}],(null==J?void 0:J.map(function(e){return{label:e,value:e}}))||[],!0),value:Ke.source||"",onChange:function(r){return Me(function(t){return e(e({},t),{source:r})})}},{id:"severity",label:"Severity",type:"singleSelect",options:[{label:"All",value:""},{label:"Critical",value:"critical"},{label:"Warning",value:"warning"},{label:"Info",value:"info"}],value:Ke.severity||"",onChange:function(r){return Me(function(t){return e(e({},t),{severity:r})})}},{id:"dateRange",label:"Date range",type:"dateRange",value:{start:Ke.dateFrom||null,end:Ke.dateTo||null},onChange:function(r){return Me(function(t){var n,i;return e(e({},t),{dateFrom:null!==(n=null==r?void 0:r.start)&&void 0!==n?n:null,dateTo:null!==(i=null==r?void 0:r.end)&&void 0!==i?i:null})})}}],pr=w(function(e,r){e.stopPropagation(),he(function(e){if((null==e?void 0:e.id)===r.id)return be(null),null;var t=me.current[r.id];if(t){var n=t.getBoundingClientRect();be({top:n.bottom+4,left:n.right})}return r})},[]);x(function(){if(ye){var e=function(){he(null),be(null)};return window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),function(){window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}}},[ye]);return"history"===Xe?i(l,{children:o("div",e({style:{display:"flex",flexDirection:"column",height:"100%"}},{children:[i("div",{children:i(v,{title:"Alerts",onClose:_,headerCtaLabel:"Manage alerts",onClickHeaderCta:function(){return Ye("manage")},styles:{tableWrapper:{border:"1px solid #E2E8F0",borderRadius:"12px",boxShadow:"0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)"}},subtitle:"View and track recent alerts generated across your services",search:{value:De,placeholder:"Search..",searchKey:"alert_name",onChange:Pe},filter:{count:ir,onClick:function(){return We(!0)}},table:{rows:ur,loading:Re,extraColumns:sr,emptyState:{title:"No alerts found",description:"No alerts have been generated yet."},tableProps:{className:"q-alert-hist-log-table"}}})}),i(g,{visible:Be,onHide:function(){return We(!1)},title:"Filter History",onReset:function(){Ve({}),Me({}),We(!1)},onApply:function(){Ve(Ke),We(!1)},fields:dr})]}))}):o(l,{children:[i(a,{ref:Je,position:"top-right"}),o("div",{children:[i(v,{title:"Manage Alerts",onClose:function(){return Ye("history")},styles:{tableWrapper:{border:"1px solid #E2E8F0",borderRadius:"12px",boxShadow:"0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)"}},subtitle:"Set up and manage custom alert triggers to stay updated about your services.",search:{value:O,placeholder:"Search...",searchKey:"alertName",onChange:q},filter:{count:or,onClick:function(){return ee(!0)}},addAction:{label:"Create Alert",onClick:function(){ce(null),pe(!0)}},table:{rows:nr,loading:G,extraColumns:lr,hiddenColumns:["logId","modifiedBy","changeSummary","changeDateTime","actions"],emptyState:{title:"No Alerts found",description:"Try creating one."},tableProps:{className:"q-alert-log-table"},onRowClick:function(e,r){r.toggle()},rowDetail:{expandOnRowClick:!1,style:{padding:0,backgroundColor:"transparent"},render:function(r){return o("div",e({style:{padding:"16px 40px",display:"flex",gap:"48px",borderBottom:"1px solid #E2E8F0",background:"#F8FAFC",fontSize:"13px"}},{children:[o("div",e({style:{flex:1,display:"flex",flexDirection:"column",gap:"8px"}},{children:[i("strong",e({style:{fontSize:"11px",color:"#64748B",textTransform:"uppercase",letterSpacing:"0.5px"}},{children:"Scope"})),i("div",e({style:{display:"flex",flexDirection:"column",gap:"4px"}},{children:r.rawScope&&Object.entries(r.rawScope).filter(function(e){return e[0],null!=e[1]}).length>0?Object.entries(r.rawScope).filter(function(e){return e[0],null!=e[1]}).map(function(r){var t=r[0],n=r[1];return o("div",e({style:{display:"flex",gap:"16px",marginBottom:"4px"}},{children:[i("span",e({style:{color:"#64748B",width:"120px",whiteSpace:"nowrap"}},{children:t})),i("span",e({style:{color:"#0F172A",fontWeight:500}},{children:String(n)}))]}),t)}):i("div",e({style:{color:"#94a3b8"}},{children:"No scope defined"}))}))]})),i("div",{style:{width:"1px",backgroundColor:"#E2E8F0"}}),o("div",e({style:{flex:1,display:"flex",flexDirection:"column",gap:"8px"}},{children:[i("strong",e({style:{fontSize:"11px",color:"#64748B",textTransform:"uppercase",letterSpacing:"0.5px"}},{children:"Trigger Configuration"})),i("div",e({style:{display:"flex",flexDirection:"column",gap:"4px"}},{children:r.triggerConfig&&Object.entries(r.triggerConfig).filter(function(e){return e[0],null!=e[1]}).length>0?Object.entries(r.triggerConfig).filter(function(e){return e[0],null!=e[1]}).map(function(r){var t=r[0],n=r[1];return o("div",e({style:{display:"flex",gap:"16px",marginBottom:"4px"}},{children:[i("span",e({style:{color:"#64748B",width:"120px"}},{children:t})),i("span",e({style:{color:"#0F172A",fontWeight:500}},{children:String(n)}))]}),t)}):i("div",e({style:{color:"#94a3b8"}},{children:"No trigger configuration"}))}))]})),i("div",{style:{width:"1px",backgroundColor:"#E2E8F0"}}),o("div",e({style:{flex:1,display:"flex",flexDirection:"column",gap:"8px"}},{children:[i("strong",e({style:{fontSize:"11px",color:"#64748B",textTransform:"uppercase",letterSpacing:"0.5px"}},{children:"Alert Recipients"})),i("div",e({style:{display:"flex",flexDirection:"column",gap:"4px"}},{children:r.subscribers&&r.subscribers.length>0?i("span",e({style:{color:"#0F172A",fontWeight:500}},{children:(Array.isArray(r.subscribers)?r.subscribers:[r.subscribers]).map(function(e){return"string"==typeof e?e:e.name||e.email||e.label||""}).join(", ")})):i("div",e({style:{color:"#94a3b8"}},{children:"No recipients"}))}))]}))]}))}}}}),i(g,{visible:$,onHide:function(){return ee(!1)},onReset:function(){le({}),ne({}),ee(!1)},onApply:function(){ne(oe),ee(!1)},fields:ar}),i(s,{isOpen:!!Ae,isLoading:Ee,onClose:function(){Ee||ke(null)},onConfirm:function(){return t(void 0,void 0,void 0,function(){var e,r,t;return n(this,function(n){switch(n.label){case 0:if(!Ae)return[2];ze(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,F({baseUrl:I,configId:R||"",accessToken:B},Ae.id)];case 2:return n.sent(),null===(r=Je.current)||void 0===r||r.show({severity:"success",summary:"Success",detail:"Alert deleted successfully!",life:3e3}),rr(),ke(null),[3,5];case 3:return e=n.sent(),console.error(e),null===(t=Je.current)||void 0===t||t.show({severity:"error",summary:"Error",detail:"Failed to delete alert. Please try again.",life:3e3}),[3,5];case 4:return ze(!1),[7];case 5:return[2]}})})},title:"Delete Alert?",message:Ae?"You'll stop receiving reports for \"".concat(Ae.alertName,'."'):"",warningText:"This action cannot be undone.",confirmText:"Delete",cancelText:"Cancel",confirmButtonColor:"#EF4444"}),i(A,{isOpen:de,onClose:function(){pe(!1),ce(null)},uiConfig:j,onSearchSubscribers:function(e){return new Promise(function(r){Qe.current&&(clearTimeout(Qe.current),Ze.current&&Ze.current([])),$e.current&&$e.current.abort(),Ze.current=r,Qe.current=setTimeout(function(){return t(void 0,void 0,void 0,function(){var t,i,o;return n(this,function(n){switch(n.label){case 0:t=new AbortController,$e.current=t,n.label=1;case 1:return n.trys.push([1,3,4,5]),i=[],[4,D({authBaseUrl:U,accessToken:B},{page:1,limit:50,pagination:!0,search:e.trim()||void 0,isPopulateRoles:!1,isPopulatePermissions:!1,isPopulateApps:!1,isPopulateEnvironments:!1,isPopulateOperations:!1,isPopulateGroups:!1,isPopulateOrganization:!1},t.signal)];case 2:return(o=n.sent())&&o.forEach(function(e){i.push({label:e.email,value:e.email,userId:e._id})}),r(i),[3,5];case 3:return"AbortError"===n.sent().name||console.error("User search failed: An error occurred while querying the user directory."),r([]),[3,5];case 4:return $e.current===t&&($e.current=null),Qe.current=null,Ze.current=null,[7];case 5:return[2]}})})},400)})},onSave:function(e,r){return t(void 0,void 0,void 0,function(){var t,i,o,l,a;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,5,,6]),r?(t=null==se?void 0:se.id,[4,L({baseUrl:I,configId:R||"",accessToken:B},t,e)]):[3,2];case 1:return n.sent(),null===(o=Je.current)||void 0===o||o.show({severity:"success",summary:"Success",detail:"Updates saved successfully!",life:3e3}),[3,4];case 2:return[4,P({baseUrl:I,configId:R||"",accessToken:B},e)];case 3:n.sent(),null===(l=Je.current)||void 0===l||l.show({severity:"success",summary:"Success",detail:"Alert created successfully!",life:3e3}),n.label=4;case 4:return rr(),[2,!0];case 5:return i=n.sent(),console.error("Error in handleCreateAlert:",i),null===(a=Je.current)||void 0===a||a.show({severity:"error",summary:"Error",detail:r?"Failed to update alert. Please try again.":"Failed to create alert. Please try again.",life:3e3}),[2,!1];case 6:return[2]}})})},editData:se})]}),ye&&ge&&C(o(l,{children:[i("div",{style:{position:"fixed",inset:0,zIndex:9998},onClick:function(){he(null),be(null)}}),o("div",e({className:"q-alert-kebab-menu",style:{position:"fixed",top:ge.top,left:ge.left,transform:"translateX(-100%)"}},{children:[o("button",e({className:"q-alert-kebab-item",disabled:"FAILED"===ye.status||Se[ye.id],style:{color:"FAILED"===ye.status||Se[ye.id]?"#94a3b8":void 0,cursor:"FAILED"===ye.status||Se[ye.id]?"not-allowed":"pointer"},onClick:function(r){return t(void 0,void 0,void 0,function(){var t,i,o,l,a;return n(this,function(n){switch(n.label){case 0:if(r.stopPropagation(),"FAILED"===ye.status||Se[ye.id])return[2];t=ye,we(function(r){var n;return e(e({},r),((n={})[t.id]=!0,n))}),n.label=1;case 1:return n.trys.push([1,4,5,6]),[4,E({baseUrl:I,configId:R||"",accessToken:B},t.id)];case 2:return n.sent(),"PAUSED"===t.status?null===(o=Je.current)||void 0===o||o.show({severity:"success",summary:"Success",detail:"Alert resumed successfully!",life:3e3}):null===(l=Je.current)||void 0===l||l.show({severity:"success",summary:"Success",detail:"Alert paused successfully!",life:3e3}),[4,rr()];case 3:return n.sent(),he(null),be(null),[3,6];case 4:return i=n.sent(),console.error(i),null===(a=Je.current)||void 0===a||a.show({severity:"error",summary:"Error",detail:"Failed to update Alert status. Please try again.",life:3e3}),[3,6];case 5:return we(function(r){var n;return e(e({},r),((n={})[t.id]=!1,n))}),[7];case 6:return[2]}})})}},{children:[Se[ye.id]?i(p,{size:14,className:"animate-spin"}):"PAUSED"===ye.status?i(f,{size:14}):i(y,{size:14}),"PAUSED"===ye.status?"Resume Alert":"ACTIVE"===ye.status?"Pause Alert":""]})),o("button",e({className:"q-alert-kebab-item danger",onClick:function(e){e.stopPropagation(),ke(ye),he(null),be(null)}},{children:[i(h,{size:14})," Delete"]}))]}))]}),document.body)]})};export{N as AlertsViewTrigger};
1
+ import{__assign as e,__spreadArray as r,__awaiter as t,__generator as n}from"../../../_virtual/_tslib.js";import{jsx as i,jsxs as l,Fragment as o}from"react/jsx-runtime";import{Toast as a}from"primereact/toast";import s from"../common/ConfirmationModal.js";import{ChevronRight as c,Pencil as u,MoreVertical as d,Loader2 as p,Play as f,Pause as y,Trash2 as h}from"lucide-react";import v from"../TablePage/TablePage.js";import g from"../FiltersSidebar/FiltersSidebar.js";import{useState as m,useRef as b,useEffect as x,useMemo as S,useCallback as A}from"react";import{createPortal as w}from"react-dom";import C from"./CreateAlertModal.js";import{fetchAlertHistory as k,deleteAlert as F,updateAlert as E,fetchDistinctSources as T,getAllUsers as z,createAlert as P,fetchAlerts as D,fetchPlotAndKPIs as I}from"../../api/alertsapi.js";var L=function(L){var N=L.baseUrl,U=L.authBaseUrl,R=L.configId,B=L.onClose,_=L.uiConfig,j=L.accessToken,O=m(""),W=O[0],V=O[1],q=m([]),K=q[0],H=q[1],M=m(!1),G=M[0],X=M[1],Y=m([]),J=Y[0],Q=Y[1],Z=m(!1),$=Z[0],ee=Z[1],re=m({}),te=re[0],ne=re[1],ie=m({}),le=ie[0],oe=ie[1],ae=m(null),se=ae[0],ce=ae[1],ue=m(!1),de=ue[0],pe=ue[1],fe=m(null),ye=fe[0],he=fe[1],ve=m(null),ge=ve[0],me=ve[1],be=b({}),xe=m({}),Se=xe[0],Ae=xe[1],we=m(null),Ce=we[0],ke=we[1],Fe=m(!1),Ee=Fe[0],Te=Fe[1],ze=m(""),Pe=ze[0],De=ze[1],Ie=m([]),Le=Ie[0],Ne=Ie[1],Ue=m(!1),Re=Ue[0],Be=Ue[1],_e=m(!1),je=_e[0],Oe=_e[1],We=m({}),Ve=We[0],qe=We[1],Ke=m({}),He=Ke[0],Me=Ke[1],Ge=m("history"),Xe=Ge[0],Ye=Ge[1],Je=m([]),Qe=Je[0],Ze=Je[1],$e=m([]),er=$e[0],rr=$e[1],tr=b(null),nr=b(null),ir=b(null),lr=b(null);function or(e){var r=new Date(e);return isNaN(r.getTime())?e:r.toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}x(function(){$&&oe(te)},[$,te]),x(function(){je&&Me(Ve)},[je,Ve]);var ar=function(){return t(void 0,void 0,void 0,function(){var e,r,t,i;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,T({baseUrl:N,configId:R||"",accessToken:j})];case 1:return e=n.sent(),r=e,Q(Array.isArray(r)?r:[]),[3,3];case 2:return t=n.sent(),console.error("Failed to fetch distinct sources:",t),null===(i=tr.current)||void 0===i||i.show({severity:"error",summary:"Error",detail:"Failed to load data sources.",life:3e3}),[3,3];case 3:return[2]}})})};function sr(){t(void 0,void 0,void 0,function(){var e,r,t,i;return n(this,function(n){switch(n.label){case 0:X(!0),he(null),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,D({baseUrl:N,configId:R||"",accessToken:j})];case 2:return e=n.sent(),r=e,H(Array.isArray(r)?r:[]),[3,5];case 3:return t=n.sent(),console.error("Failed to fetch alerts:",t),null===(i=tr.current)||void 0===i||i.show({severity:"error",summary:"Error",detail:"Failed to load alerts. Please refresh.",life:3e3}),H([]),[3,5];case 4:return X(!1),[7];case 5:return[2]}})}),t(void 0,void 0,void 0,function(){var e,r,t,i;return n(this,function(n){switch(n.label){case 0:X(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,I({baseUrl:N,configId:R||"",accessToken:j})];case 2:return e=n.sent(),r=e,Ze(Array.isArray(r)?r:[]),[3,5];case 3:return t=n.sent(),console.error("Failed to fetch plots & KPI's:",t),null===(i=tr.current)||void 0===i||i.show({severity:"error",summary:"Error",detail:"Failed to load plots & KPIs. Please refresh.",life:3e3}),Ze([]),[3,5];case 4:return X(!1),[7];case 5:return[2]}})}),ar()}x(function(){sr()},[]),x(function(){var e=!0;return"history"===Xe?(Be(!0),k({baseUrl:N,configId:R||"",accessToken:j}).then(function(r){e&&Ne(r||[])}).catch(function(r){var t;console.error("Error fetching history:",r),null===(t=tr.current)||void 0===t||t.show({severity:"error",summary:"Error",detail:"Failed to load alert history.",life:3e3}),e&&Ne([])}).finally(function(){e&&Be(!1)}),ar()):Ne([]),function(){e=!1}},[Xe]);var cr=(Array.isArray(K)?K:[]).map(function(e){var r,t,n=e.kpiType?e.kpiType.charAt(0).toUpperCase()+e.kpiType.slice(1):"—",i=e.status?e.status.charAt(0).toUpperCase()+e.status.slice(1):"—",l=(null===(t=null===(r=e.recipients)||void 0===r?void 0:r.userEmails)||void 0===t?void 0:t.map(function(r,t){var n;return{name:r,email:r,value:r,label:r,userId:(null===(n=e.recipients.userIds)||void 0===n?void 0:n[t])||void 0}}))||[],o={">":"Greater than","<":"Less than",">=":"Greater than or equal to","<=":"Less than or equal to"}[e.conditionType]||e.conditionType||"",a=o?"".concat(o," ").concat(e.thresholdValue):"".concat(e.thresholdValue);return{id:e.id,alertName:e.name,type:n,status:i,subscribers:l,raw:e,kpi:e.kpiLabel,threshold:a,severity:e.severity,createdOn:e.createdAt?or(e.createdAt):"—",alertScope:e.alertScope,triggerConfig:{"Evaluation Type":e.evaluationType,"Evaluation period":e.evaluationPeriod,"Trigger After":e.triggerAfter?"".concat(e.triggerAfter," data points"):void 0}}}),ur=S(function(){return cr.filter(function(e){var r,t,n=!te.severity||(null===(r=e.severity)||void 0===r?void 0:r.toLowerCase())===te.severity.toLowerCase(),i=!te.status||(null===(t=e.status)||void 0===t?void 0:t.toLowerCase())===te.status.toLowerCase();return n&&i})},[te,cr]),dr=S(function(){var e=0,r=!1;return Object.entries(Ve).forEach(function(t){var n=t[0],i=t[1];null===i||""===i||Array.isArray(i)&&0===i.length||("dateFrom"===n||"dateTo"===n?r=!0:e+=Array.isArray(i)?i.length:1)}),r&&(e+=1),e},[Ve]),pr=Object.values(te).reduce(function(e,r){return e+(Array.isArray(r)?r.length:r&&""!==r?1:0)},0),fr=[{key:"alertName",header:i("span",e({style:{fontSize:"13px"}},{children:"Alert Name"})),body:function(r){return l("div",e({style:{fontWeight:500,display:"flex",alignItems:"center",gap:"8px",color:"#475569",fontSize:"13px"}},{children:[i("span",e({className:"q-alert-chevron",style:{cursor:"pointer",display:"flex",padding:"4px"}},{children:i(c,{size:16})})),r.alertName||"—"]}))}},{key:"kpi",header:i("span",e({style:{fontSize:"13px"}},{children:"KPI"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.kpi||"—"}))}},{key:"threshold",header:i("span",e({style:{fontSize:"13px"}},{children:"Threshold"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px",whiteSpace:"nowrap"}},{children:r.threshold||"—"}))}},{key:"severity",header:i("span",e({style:{fontSize:"13px"}},{children:"Severity"})),body:function(r){var t=r.severity||"",n=t.charAt(0).toUpperCase()+t.slice(1),l="#F1F5F9",o="#475569";return"critical"===t.toLowerCase()?(l="#FEE2E2",o="#DC2626"):"warning"===t.toLowerCase()&&(l="#FEF3C7",o="#D97706"),i("span",e({style:{background:l,color:o,padding:"2px 8px",borderRadius:"12px",fontSize:"12px",fontWeight:600,display:"inline-block"}},{children:n||"—"}))}},{key:"createdOn",header:i("span",e({style:{fontSize:"13px"}},{children:"Created on"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.createdOn}))}},{key:"status",header:i("span",e({style:{fontSize:"13px"}},{children:"Status"})),body:function(r){var t="#F1F5F9",n="#475569",l=r.status||"Active";return"active"===l.toLowerCase()?(t="#DCFCE7",n="#16A34A"):"failed"===l.toLowerCase()?(t="#FEE2E2",n="#DC2626"):"paused"===l.toLowerCase()&&(t="#F1F5F9",n="#64748B"),i("span",e({style:{background:t,color:n,padding:"2px 8px",borderRadius:"12px",fontSize:"12px",fontWeight:600,whiteSpace:"nowrap",display:"inline-block"}},{children:l.charAt(0).toUpperCase()+l.slice(1)}))}},{key:"customActions",header:i("span",e({style:{fontSize:"13px"}},{children:"Actions"})),body:function(r){var t="Failed"===r.status||"Paused"===r.status;return l("div",e({style:{display:"flex",alignItems:"center",gap:"12px",flexWrap:"nowrap",position:"relative"}},{children:[l("button",e({onClick:function(e){e.stopPropagation(),ce(r),pe(!0)},style:{background:"white",color:t?"#94A3B8":"#475569",border:"1px solid #cbd5e1",padding:"6px 12px",borderRadius:"6px",fontSize:"13px",display:"flex",alignItems:"center",gap:"6px",cursor:t?"not-allowed":"pointer",fontWeight:500,opacity:t?.6:1,whiteSpace:"nowrap",flexShrink:0},disabled:t},{children:[i(u,{size:12})," Edit Alert"]})),i("button",e({ref:function(e){be.current[r.id]=e},className:"q-alert-kebab-trigger",onClick:function(e){return br(e,r)}},{children:i(d,{size:16})}))]}))}}],yr=[{id:"severity",label:"Severity",type:"singleSelect",options:[{label:"All",value:""},{label:"Critical",value:"critical"},{label:"Warning",value:"warning"},{label:"Info",value:"info"}],value:le.severity||"",onChange:function(r){return oe(function(t){return e(e({},t),{severity:r})})}},{id:"status",label:"Status",type:"singleSelect",options:[{label:"All",value:""},{label:"Active",value:"active"},{label:"Paused",value:"paused"}],value:le.status||"",onChange:function(r){return oe(function(t){return e(e({},t),{status:r})})}}],hr=[{key:"no",header:i("span",e({style:{fontSize:"13px"}},{children:"No"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.no}))}},{key:"alert_name",header:i("span",e({style:{fontSize:"13px"}},{children:"Alert Name"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.alert_name}))}},{key:"source",header:i("span",e({style:{fontSize:"13px"}},{children:"Source"})),body:function(r){return i("div",e({style:{color:"#475569",fontSize:"13px",display:"flex",flexDirection:"column"}},{children:r.source.length>0?l(o,{children:[l("span",{children:[r.source[0]," ",r.source.length>1?"|":""]}),r.source.slice(1).map(function(r,t){return i("span",e({style:{fontWeight:600,color:"#0F172A"}},{children:r}),t)})]}):"—"}))}},{key:"severity",header:i("span",e({style:{fontSize:"13px"}},{children:"Severity"})),body:function(r){var t=r.severity||"",n=t.charAt(0).toUpperCase()+t.slice(1),l="#F1F5F9",o="#475569";return"critical"===t.toLowerCase()?(l="#FEE2E2",o="#DC2626"):"warning"===t.toLowerCase()&&(l="#FEF3C7",o="#D97706"),i("span",e({style:{background:l,color:o,padding:"2px 8px",borderRadius:"12px",fontSize:"12px",fontWeight:600,display:"inline-block"}},{children:n||"—"}))}},{key:"triggered_at",header:i("span",e({style:{fontSize:"13px"}},{children:"Triggered at"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.triggered_at}))}},{key:"current_value",header:i("span",e({style:{fontSize:"13px"}},{children:"Triggered value"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.current_value}))}},{key:"threshold",header:i("span",e({style:{fontSize:"13px"}},{children:"Threshold"})),body:function(r){return i("span",e({style:{color:"#475569",fontSize:"13px"}},{children:r.threshold}))}}],vr=S(function(){return Le.map(function(e,r){return{id:e.historyId||"hist_".concat(r),no:r+1,alert_name:e.title||"—",rawSource:e.source,source:e.source?String(e.source).split("|").map(function(e){return e.trim()}):[],severity:e.severity||"—",triggered_at:e.triggeredAt?or(e.triggeredAt):"—",current_value:void 0!==e.currentValue?String(e.currentValue):"—",threshold:void 0!==e.thresholdValue?String(e.thresholdValue):"—"}})},[Le]),gr=S(function(){return vr.filter(function(e,r){var t,n=!Ve.severity||(null===(t=e.severity)||void 0===t?void 0:t.toLowerCase())===Ve.severity.toLowerCase(),i=Ve.source,l=!i||e.rawSource.includes(i),o=new Date(e.triggered_at),a=!Ve.dateFrom||o>=Ve.dateFrom,s=!Ve.dateTo||o<=Ve.dateTo;return n&&l&&a&&s})},[Ve,vr,Le]),mr=[{id:"source",label:"Source",type:"singleSelect",options:r([{label:"All",value:""}],(null==J?void 0:J.map(function(e){return{label:e,value:e}}))||[],!0),value:He.source||"",onChange:function(r){return Me(function(t){return e(e({},t),{source:r})})}},{id:"severity",label:"Severity",type:"singleSelect",options:[{label:"All",value:""},{label:"Critical",value:"critical"},{label:"Warning",value:"warning"},{label:"Info",value:"info"}],value:He.severity||"",onChange:function(r){return Me(function(t){return e(e({},t),{severity:r})})}},{id:"dateRange",label:"Date range",type:"dateRange",value:{start:He.dateFrom||null,end:He.dateTo||null},onChange:function(r){return Me(function(t){var n,i;return e(e({},t),{dateFrom:null!==(n=null==r?void 0:r.start)&&void 0!==n?n:null,dateTo:null!==(i=null==r?void 0:r.end)&&void 0!==i?i:null})})}}],br=A(function(e,r){e.stopPropagation(),he(function(e){if((null==e?void 0:e.id)===r.id)return me(null),null;var t=be.current[r.id];if(t){var n=t.getBoundingClientRect();me({top:n.bottom+4,left:n.right})}return r})},[]);x(function(){if(ye){var e=function(){he(null),me(null)};return window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),function(){window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}}},[ye]);return"history"===Xe?i(o,{children:l("div",e({style:{display:"flex",flexDirection:"column",height:"100%",width:"100%"}},{children:[i("div",{children:i(v,{title:"Alerts",onClose:B,headerCtaLabel:"Manage alerts",onClickHeaderCta:function(){return Ye("manage")},styles:{tableWrapper:{border:"1px solid #E2E8F0",borderRadius:"12px",boxShadow:"0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)",padding:"16px"}},subtitle:"View and track recent alerts generated across your services",search:{value:Pe,placeholder:"Search..",searchKey:"alert_name",onChange:De},filter:{count:dr,onClick:function(){return Oe(!0)}},table:{rows:gr,loading:Re,extraColumns:hr,emptyState:{title:"No alerts found",description:"No alerts have been generated yet."},tableProps:{className:"q-alert-hist-log-table"}}})}),i(g,{visible:je,onHide:function(){return Oe(!1)},title:"Filter History",onReset:function(){qe({}),Me({}),Oe(!1)},onApply:function(){qe(He),Oe(!1)},fields:mr})]}))}):l(o,{children:[i(a,{ref:tr,position:"top-right"}),l("div",e({style:{width:"100%"}},{children:[i(v,{title:"Manage Alerts",onClose:function(){return Ye("history")},styles:{tableWrapper:{border:"1px solid #E2E8F0",borderRadius:"12px",boxShadow:"0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)",padding:"16px"}},subtitle:"Set up and manage custom alert triggers to stay updated about your services.",search:{value:W,placeholder:"Search...",searchKey:"alertName",onChange:V},filter:{count:pr,onClick:function(){return ee(!0)}},addAction:{label:"Create Alert",onClick:function(){ce(null),pe(!0)}},table:{rows:ur,loading:G,extraColumns:fr,hiddenColumns:["logId","modifiedBy","changeSummary","changeDateTime","actions"],emptyState:{title:"No Alerts found",description:"Try creating one."},tableProps:{className:"q-alert-log-table"},onRowClick:function(e,r){r.toggle()},rowDetail:{expandOnRowClick:!1,style:{padding:0,backgroundColor:"transparent"},render:function(r){return l("div",e({style:{padding:"16px 40px",display:"flex",gap:"48px",borderBottom:"1px solid #E2E8F0",background:"#F8FAFC",fontSize:"13px"}},{children:[l("div",e({style:{flex:1,display:"flex",flexDirection:"column",gap:"8px"}},{children:[i("strong",e({style:{fontSize:"11px",color:"#64748B",textTransform:"uppercase",letterSpacing:"0.5px"}},{children:"Scope"})),i("div",e({style:{display:"flex",flexDirection:"column",gap:"4px"}},{children:r.alertScope&&Object.entries(r.alertScope).filter(function(e){return e[0],null!=e[1]}).length>0?Object.entries(r.alertScope).filter(function(e){return e[0],null!=e[1].data}).map(function(r){var t=r[0],n=r[1];return l("div",e({style:{display:"flex",gap:"16px",marginBottom:"4px"}},{children:[i("span",e({style:{color:"#64748B",width:"120px",whiteSpace:"nowrap"}},{children:n.label})),i("span",e({style:{color:"#0F172A",fontWeight:500}},{children:n.data.map(function(e,r){var t;return"".concat(e).concat(r!==(null===(t=n.data)||void 0===t?void 0:t.length)-1?", ":"")})}))]}),t)}):i("div",e({style:{color:"#94a3b8"}},{children:"No scope defined"}))}))]})),i("div",{style:{width:"1px",backgroundColor:"#E2E8F0"}}),l("div",e({style:{flex:1,display:"flex",flexDirection:"column",gap:"8px"}},{children:[i("strong",e({style:{fontSize:"11px",color:"#64748B",textTransform:"uppercase",letterSpacing:"0.5px"}},{children:"Trigger Configuration"})),i("div",e({style:{display:"flex",flexDirection:"column",gap:"4px"}},{children:r.triggerConfig&&Object.entries(r.triggerConfig).filter(function(e){return e[0],null!=e[1]}).length>0?Object.entries(r.triggerConfig).filter(function(e){return e[0],null!=e[1]}).map(function(r){var t=r[0],n=r[1];return l("div",e({style:{display:"flex",gap:"16px",marginBottom:"4px"}},{children:[i("span",e({style:{color:"#64748B",width:"120px"}},{children:t})),i("span",e({style:{color:"#0F172A",fontWeight:500}},{children:String(n)}))]}),t)}):i("div",e({style:{color:"#94a3b8"}},{children:"No trigger configuration"}))}))]})),i("div",{style:{width:"1px",backgroundColor:"#E2E8F0"}}),l("div",e({style:{flex:1,display:"flex",flexDirection:"column",gap:"8px"}},{children:[i("strong",e({style:{fontSize:"11px",color:"#64748B",textTransform:"uppercase",letterSpacing:"0.5px"}},{children:"Alert Recipients"})),i("div",e({style:{display:"flex",flexDirection:"column",gap:"4px"}},{children:r.subscribers&&r.subscribers.length>0?i("span",e({style:{color:"#0F172A",fontWeight:500}},{children:(Array.isArray(r.subscribers)?r.subscribers:[r.subscribers]).map(function(e){return"string"==typeof e?e:e.name||e.email||e.label||""}).join(", ")})):i("div",e({style:{color:"#94a3b8"}},{children:"No recipients"}))}))]}))]}))}}}}),i(g,{visible:$,onHide:function(){return ee(!1)},onReset:function(){oe({}),ne({}),ee(!1)},onApply:function(){ne(le),ee(!1)},fields:yr}),i(s,{isOpen:!!Ce,isLoading:Ee,onClose:function(){Ee||ke(null)},onConfirm:function(){return t(void 0,void 0,void 0,function(){var e,r,t;return n(this,function(n){switch(n.label){case 0:if(!Ce)return[2];Te(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,F({baseUrl:N,configId:R||"",accessToken:j},Ce.id)];case 2:return n.sent(),null===(r=tr.current)||void 0===r||r.show({severity:"success",summary:"Success",detail:"Alert deleted successfully!",life:3e3}),sr(),ke(null),[3,5];case 3:return e=n.sent(),console.error(e),null===(t=tr.current)||void 0===t||t.show({severity:"error",summary:"Error",detail:"Failed to delete alert. Please try again.",life:3e3}),[3,5];case 4:return Te(!1),[7];case 5:return[2]}})})},title:"Delete Alert?",message:Ce?'Are you sure you want to delete the alert "'.concat(Ce.alertName,'."? You’ll no longer receive alerts from it.'):"",warningText:"This action cannot be undone.",confirmText:"Delete",cancelText:"Cancel",confirmButtonColor:"#EF4444"}),i(C,{isOpen:de,onClose:function(){pe(!1),ce(null)},uiConfig:_,onSearchSubscribers:function(e){return new Promise(function(r){nr.current&&(clearTimeout(nr.current),ir.current&&ir.current([])),lr.current&&lr.current.abort(),ir.current=r,nr.current=setTimeout(function(){return t(void 0,void 0,void 0,function(){var t,i,l;return n(this,function(n){switch(n.label){case 0:t=new AbortController,lr.current=t,n.label=1;case 1:return n.trys.push([1,3,4,5]),i=[],[4,z({authBaseUrl:U,accessToken:j},{page:1,limit:50,pagination:!0,search:e.trim()||void 0,isPopulateRoles:!1,isPopulatePermissions:!1,isPopulateApps:!1,isPopulateEnvironments:!1,isPopulateOperations:!1,isPopulateGroups:!1,isPopulateOrganization:!1},t.signal)];case 2:return(l=n.sent())&&l.forEach(function(e){i.push({label:e.email,value:e.email,userId:e._id})}),r(i),[3,5];case 3:return"AbortError"===n.sent().name||console.error("User search failed: An error occurred while querying the user directory."),r([]),[3,5];case 4:return lr.current===t&&(lr.current=null),nr.current=null,ir.current=null,[7];case 5:return[2]}})})},400)})},onSave:function(e,r){return t(void 0,void 0,void 0,function(){var t,i,l,o,a;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,5,,6]),r?(t=null==se?void 0:se.id,[4,E({baseUrl:N,configId:R||"",accessToken:j},t,e)]):[3,2];case 1:return n.sent(),null===(l=tr.current)||void 0===l||l.show({severity:"success",summary:"Success",detail:"Updates saved successfully!",life:3e3}),[3,4];case 2:return[4,P({baseUrl:N,configId:R||"",accessToken:j},e)];case 3:n.sent(),null===(o=tr.current)||void 0===o||o.show({severity:"success",summary:"Success",detail:"Alert created successfully!",life:3e3}),n.label=4;case 4:return sr(),[2,!0];case 5:return i=n.sent(),console.error("Error in handleCreateAlert:",i),null===(a=tr.current)||void 0===a||a.show({severity:"error",summary:"Error",detail:r?"Failed to update alert. Please try again.":"Failed to create alert. Please try again.",life:3e3}),[2,!1];case 6:return[2]}})})},editData:se,plotAndKPIs:Qe,selectedPlot:er,handlePlotSelectionChange:function(e){rr(e)}})]})),ye&&ge&&w(l(o,{children:[i("div",{style:{position:"fixed",inset:0,zIndex:9998},onClick:function(){he(null),me(null)}}),l("div",e({className:"q-alert-kebab-menu",style:{position:"fixed",top:ge.top,left:ge.left,transform:"translateX(-100%)"}},{children:[l("button",e({className:"q-alert-kebab-item",disabled:"FAILED"===ye.status||Se[ye.id],style:{color:"FAILED"===ye.status||Se[ye.id]?"#94a3b8":void 0,cursor:"FAILED"===ye.status||Se[ye.id]?"not-allowed":"pointer"},onClick:function(r){return t(void 0,void 0,void 0,function(){var t,i,l,o,a,s,c,u,d,p,f,y,h;return n(this,function(n){switch(n.label){case 0:if(r.stopPropagation(),"FAILED"===ye.status||Se[ye.id])return[2];t=ye,Ae(function(r){var n;return e(e({},r),((n={})[t.id]=!0,n))}),n.label=1;case 1:return n.trys.push([1,4,5,6]),i=(null===(u=t.status)||void 0===u?void 0:u.toUpperCase())||"",o=(l="PAUSED"===i)?"ACTIVE":"PAUSED",a=t.raw||{},s={name:(null==a?void 0:a.name)||"",kpiKey:(null==a?void 0:a.kpiKey)||"",kpiType:(null==a?void 0:a.kpiType)||"",entityType:(null==a?void 0:a.entityType)||{},conditionType:(null==a?void 0:a.conditionType)||"",thresholdValue:null!==(d=null==a?void 0:a.thresholdValue)&&void 0!==d?d:null,severity:(null==a?void 0:a.severity)||"",evaluationType:(null==a?void 0:a.evaluationType)||"",evaluationPeriod:(null==a?void 0:a.evaluationPeriod)||null,triggerAfter:null!==(p=null==a?void 0:a.triggerAfter)&&void 0!==p?p:0,recipients:(null==a?void 0:a.recipients)||{userIds:[],userEmails:[]},status:o},[4,E({baseUrl:N,configId:R||"",accessToken:j},t.id,s)];case 2:return n.sent(),l?null===(f=tr.current)||void 0===f||f.show({severity:"success",summary:"Success",detail:"Alert resumed successfully!",life:3e3}):null===(y=tr.current)||void 0===y||y.show({severity:"success",summary:"Success",detail:"Alert paused successfully!",life:3e3}),[4,sr()];case 3:return n.sent(),he(null),me(null),[3,6];case 4:return c=n.sent(),console.error(c),null===(h=tr.current)||void 0===h||h.show({severity:"error",summary:"Error",detail:"Failed to update Alert status. Please try again.",life:3e3}),[3,6];case 5:return Ae(function(r){var n;return e(e({},r),((n={})[t.id]=!1,n))}),[7];case 6:return[2]}})})}},{children:[Se[ye.id]?i(p,{size:14,className:"animate-spin"}):"PAUSED"===ye.status?i(f,{size:14}):i(y,{size:14}),"PAUSED"===ye.status?"Resume Alert":"ACTIVE"===ye.status?"Pause Alert":""]})),l("button",e({className:"q-alert-kebab-item danger",onClick:function(e){e.stopPropagation(),ke(ye),he(null),me(null)}},{children:[i(h,{size:14})," Delete"]}))]}))]}),document.body)]})};export{L as AlertsViewTrigger};
2
2
  //# sourceMappingURL=AlertsViewTrigger.js.map