@solidxai/core-ui 0.1.9-beta.14 → 0.1.9-beta.17

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 (108) hide show
  1. package/dist/components/core/chatter/SolidChatterMessageBox.js +1 -1
  2. package/dist/components/core/chatter/SolidChatterMessageBox.js.map +1 -1
  3. package/dist/components/core/chatter/SolidChatterMessageBox.tsx +1 -1
  4. package/dist/components/core/common/SolidGlobalSearchElement.d.ts.map +1 -1
  5. package/dist/components/core/common/SolidGlobalSearchElement.js +77 -42
  6. package/dist/components/core/common/SolidGlobalSearchElement.js.map +1 -1
  7. package/dist/components/core/common/SolidGlobalSearchElement.tsx +43 -5
  8. package/dist/components/core/dashboard/mappers/echartsOptionMapper.d.ts +4 -0
  9. package/dist/components/core/dashboard/mappers/echartsOptionMapper.d.ts.map +1 -0
  10. package/dist/components/core/dashboard/mappers/echartsOptionMapper.js +76 -0
  11. package/dist/components/core/dashboard/mappers/echartsOptionMapper.js.map +1 -0
  12. package/dist/components/core/dashboard/mappers/echartsOptionMapper.ts +78 -0
  13. package/dist/components/core/dashboard/widgets/DefaultDashboardBarChartWidget.d.ts +3 -0
  14. package/dist/components/core/dashboard/widgets/DefaultDashboardBarChartWidget.d.ts.map +1 -0
  15. package/dist/components/core/dashboard/widgets/DefaultDashboardBarChartWidget.js +17 -0
  16. package/dist/components/core/dashboard/widgets/DefaultDashboardBarChartWidget.js.map +1 -0
  17. package/dist/components/core/dashboard/widgets/DefaultDashboardBarChartWidget.tsx +6 -0
  18. package/dist/components/core/dashboard/widgets/DefaultDashboardChartWidget.d.ts +3 -0
  19. package/dist/components/core/dashboard/widgets/DefaultDashboardChartWidget.d.ts.map +1 -0
  20. package/dist/components/core/dashboard/widgets/DefaultDashboardChartWidget.js +41 -0
  21. package/dist/components/core/dashboard/widgets/DefaultDashboardChartWidget.js.map +1 -0
  22. package/dist/components/core/dashboard/widgets/DefaultDashboardChartWidget.tsx +56 -0
  23. package/dist/components/core/dashboard/widgets/DefaultDashboardKpiWidget.d.ts +3 -0
  24. package/dist/components/core/dashboard/widgets/DefaultDashboardKpiWidget.d.ts.map +1 -0
  25. package/dist/components/core/dashboard/widgets/DefaultDashboardKpiWidget.js +9 -0
  26. package/dist/components/core/dashboard/widgets/DefaultDashboardKpiWidget.js.map +1 -0
  27. package/dist/components/core/dashboard/widgets/DefaultDashboardKpiWidget.tsx +7 -0
  28. package/dist/components/core/dashboard/widgets/DefaultDashboardLineChartWidget.d.ts +3 -0
  29. package/dist/components/core/dashboard/widgets/DefaultDashboardLineChartWidget.d.ts.map +1 -0
  30. package/dist/components/core/dashboard/widgets/DefaultDashboardLineChartWidget.js +17 -0
  31. package/dist/components/core/dashboard/widgets/DefaultDashboardLineChartWidget.js.map +1 -0
  32. package/dist/components/core/dashboard/widgets/DefaultDashboardLineChartWidget.tsx +6 -0
  33. package/dist/components/core/dashboard/widgets/DefaultDashboardPieChartWidget.d.ts +3 -0
  34. package/dist/components/core/dashboard/widgets/DefaultDashboardPieChartWidget.d.ts.map +1 -0
  35. package/dist/components/core/dashboard/widgets/DefaultDashboardPieChartWidget.js +17 -0
  36. package/dist/components/core/dashboard/widgets/DefaultDashboardPieChartWidget.js.map +1 -0
  37. package/dist/components/core/dashboard/widgets/DefaultDashboardPieChartWidget.tsx +6 -0
  38. package/dist/components/core/dashboard/widgets/DefaultDashboardTableWidget.d.ts +3 -0
  39. package/dist/components/core/dashboard/widgets/DefaultDashboardTableWidget.d.ts.map +1 -0
  40. package/dist/components/core/dashboard/widgets/DefaultDashboardTableWidget.js +12 -0
  41. package/dist/components/core/dashboard/widgets/DefaultDashboardTableWidget.js.map +1 -0
  42. package/dist/components/core/dashboard/widgets/DefaultDashboardTableWidget.tsx +39 -0
  43. package/dist/components/core/dashboard/widgets/DefaultDashboardUnknownWidget.d.ts +3 -0
  44. package/dist/components/core/dashboard/widgets/DefaultDashboardUnknownWidget.d.ts.map +1 -0
  45. package/dist/components/core/dashboard/widgets/DefaultDashboardUnknownWidget.js +7 -0
  46. package/dist/components/core/dashboard/widgets/DefaultDashboardUnknownWidget.js.map +1 -0
  47. package/dist/components/core/dashboard/widgets/DefaultDashboardUnknownWidget.tsx +9 -0
  48. package/dist/components/core/dashboard/widgets/QueueSlaHeatmapWidget.d.ts +3 -0
  49. package/dist/components/core/dashboard/widgets/QueueSlaHeatmapWidget.d.ts.map +1 -0
  50. package/dist/components/core/dashboard/widgets/QueueSlaHeatmapWidget.js +159 -0
  51. package/dist/components/core/dashboard/widgets/QueueSlaHeatmapWidget.js.map +1 -0
  52. package/dist/components/core/dashboard/widgets/QueueSlaHeatmapWidget.tsx +205 -0
  53. package/dist/components/core/model/CreateModel.d.ts.map +1 -1
  54. package/dist/components/core/model/CreateModel.js +11 -24
  55. package/dist/components/core/model/CreateModel.js.map +1 -1
  56. package/dist/components/core/model/CreateModel.tsx +10 -22
  57. package/dist/components/core/model/FieldMetaDataForm.js +1 -1
  58. package/dist/components/core/model/FieldMetaDataForm.js.map +1 -1
  59. package/dist/components/core/model/FieldMetaDataForm.tsx +1 -1
  60. package/dist/components/core/model/ModelMetaData.d.ts.map +1 -1
  61. package/dist/components/core/model/ModelMetaData.js +6 -18
  62. package/dist/components/core/model/ModelMetaData.js.map +1 -1
  63. package/dist/components/core/model/ModelMetaData.tsx +8 -21
  64. package/dist/helpers/registry.d.ts.map +1 -1
  65. package/dist/helpers/registry.js +15 -10
  66. package/dist/helpers/registry.js.map +1 -1
  67. package/dist/helpers/registry.ts +16 -12
  68. package/dist/index.d.ts +4 -7
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +3 -7
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.ts +12 -13
  73. package/dist/redux/api/dashboardRuntimeApi.d.ts +34 -0
  74. package/dist/redux/api/dashboardRuntimeApi.d.ts.map +1 -0
  75. package/dist/redux/api/dashboardRuntimeApi.js +79 -0
  76. package/dist/redux/api/dashboardRuntimeApi.js.map +1 -0
  77. package/dist/redux/api/dashboardRuntimeApi.ts +75 -0
  78. package/dist/redux/store/defaultStoreConfig.d.ts +34 -9
  79. package/dist/redux/store/defaultStoreConfig.d.ts.map +1 -1
  80. package/dist/redux/store/defaultStoreConfig.js +2 -6
  81. package/dist/redux/store/defaultStoreConfig.js.map +1 -1
  82. package/dist/redux/store/defaultStoreConfig.ts +2 -6
  83. package/dist/resources/globals.css +9 -7
  84. package/dist/routes/pages/admin/core/DashboardPage.d.ts +1 -0
  85. package/dist/routes/pages/admin/core/DashboardPage.d.ts.map +1 -1
  86. package/dist/routes/pages/admin/core/DashboardPage.js +780 -5
  87. package/dist/routes/pages/admin/core/DashboardPage.js.map +1 -1
  88. package/dist/routes/pages/admin/core/DashboardPage.module.css +186 -0
  89. package/dist/routes/pages/admin/core/DashboardPage.tsx +898 -7
  90. package/dist/routes/solidRoutes.d.ts.map +1 -1
  91. package/dist/routes/solidRoutes.js +2 -2
  92. package/dist/routes/solidRoutes.js.map +1 -1
  93. package/dist/routes/solidRoutes.tsx +2 -2
  94. package/dist/routes/types.d.ts +1 -1
  95. package/dist/routes/types.d.ts.map +1 -1
  96. package/dist/routes/types.js.map +1 -1
  97. package/dist/routes/types.ts +1 -1
  98. package/dist/types/dashboard.d.ts +16 -0
  99. package/dist/types/dashboard.d.ts.map +1 -0
  100. package/dist/types/dashboard.js +2 -0
  101. package/dist/types/dashboard.js.map +1 -0
  102. package/dist/types/dashboard.ts +23 -0
  103. package/dist/types/extension-registry.d.ts +1 -0
  104. package/dist/types/extension-registry.d.ts.map +1 -1
  105. package/dist/types/extension-registry.js +1 -0
  106. package/dist/types/extension-registry.js.map +1 -1
  107. package/dist/types/extension-registry.ts +1 -0
  108. package/package.json +3 -1
@@ -1,10 +1,785 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import SolidDashboard from '../../../../components/core/dashboard/SolidDashboard';
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
57
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
58
+ import { useEffect, useMemo, useRef, useState } from "react";
3
59
  import { useParams } from "react-router-dom";
60
+ import { AlertTriangle, Filter, RefreshCw, Save } from "lucide-react";
61
+ import { GridStack } from "gridstack";
62
+ import "gridstack/dist/gridstack.min.css";
63
+ import { getExtensionComponent } from "../../../../helpers/registry";
64
+ import { SolidAutocomplete, SolidButton, SolidDatePicker, SolidDialog, SolidDialogBody, SolidDialogFooter, SolidSelect, SolidSpinner, } from "../../../../components/shad-cn-ui";
65
+ import { resolveChartType } from "../../../../components/core/dashboard/mappers/echartsOptionMapper";
66
+ import { useGetDashboardDataMutation, useGetDashboardDefinitionQuery, useGetDashboardLayoutQuery, useLazyGetDashboardVariableOptionsQuery, useSaveDashboardLayoutMutation, } from "../../../../redux/api/dashboardRuntimeApi";
67
+ import styles from "./DashboardPage.module.css";
68
+ var normalizeType = function (value) { return "".concat(value !== null && value !== void 0 ? value : "").toLowerCase(); };
69
+ var isDateRangeVariable = function (variable) {
70
+ var type = normalizeType(variable === null || variable === void 0 ? void 0 : variable.type);
71
+ return type === "date" || type === "daterange" || type === "date_range";
72
+ };
73
+ var isDynamicVariable = function (variable) {
74
+ var type = normalizeType(variable === null || variable === void 0 ? void 0 : variable.type);
75
+ return type === "selectiondynamic" || type === "dynamicselect" || type === "selectdynamic";
76
+ };
77
+ var isStaticVariable = function (variable) {
78
+ var type = normalizeType(variable === null || variable === void 0 ? void 0 : variable.type);
79
+ return type === "selectionstatic" || type === "select" || type === "multiselect";
80
+ };
81
+ var isMultiValueVariable = function (variable) {
82
+ var type = normalizeType(variable === null || variable === void 0 ? void 0 : variable.type);
83
+ return type === "multiselect" || !!(variable === null || variable === void 0 ? void 0 : variable.multiple) || !!(variable === null || variable === void 0 ? void 0 : variable.allowMultiple) || !!(variable === null || variable === void 0 ? void 0 : variable.isMultiSelect);
84
+ };
85
+ var toOptions = function (options) {
86
+ return (options !== null && options !== void 0 ? options : [])
87
+ .map(function (entry) {
88
+ var _a, _b, _c, _d, _e, _f, _g;
89
+ if (typeof entry === "string") {
90
+ var _h = entry.split(":"), value = _h[0], label = _h[1];
91
+ return { value: value, label: label !== null && label !== void 0 ? label : value };
92
+ }
93
+ return {
94
+ value: "".concat((_b = (_a = entry === null || entry === void 0 ? void 0 : entry.value) !== null && _a !== void 0 ? _a : entry === null || entry === void 0 ? void 0 : entry.id) !== null && _b !== void 0 ? _b : ""),
95
+ label: "".concat((_g = (_f = (_e = (_d = (_c = entry === null || entry === void 0 ? void 0 : entry.label) !== null && _c !== void 0 ? _c : entry === null || entry === void 0 ? void 0 : entry.name) !== null && _d !== void 0 ? _d : entry === null || entry === void 0 ? void 0 : entry.displayName) !== null && _e !== void 0 ? _e : entry === null || entry === void 0 ? void 0 : entry.value) !== null && _f !== void 0 ? _f : entry === null || entry === void 0 ? void 0 : entry.id) !== null && _g !== void 0 ? _g : ""),
96
+ };
97
+ })
98
+ .filter(function (entry) { return !!entry.value; });
99
+ };
100
+ var toIso = function (value) {
101
+ if (!value || Number.isNaN(value.getTime()))
102
+ return null;
103
+ return value.toISOString();
104
+ };
105
+ var extractWidgetName = function (widgetData) { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = widgetData === null || widgetData === void 0 ? void 0 : widgetData.meta) === null || _a === void 0 ? void 0 : _a.widgetName) !== null && _b !== void 0 ? _b : widgetData === null || widgetData === void 0 ? void 0 : widgetData.widgetName) !== null && _c !== void 0 ? _c : widgetData === null || widgetData === void 0 ? void 0 : widgetData.id) !== null && _d !== void 0 ? _d : ""; };
106
+ var sortLayoutItems = function (items) {
107
+ return __spreadArray([], (items !== null && items !== void 0 ? items : []), true).sort(function (a, b) {
108
+ var _a, _b, _c, _d;
109
+ var byY = ((_a = a === null || a === void 0 ? void 0 : a.y) !== null && _a !== void 0 ? _a : 0) - ((_b = b === null || b === void 0 ? void 0 : b.y) !== null && _b !== void 0 ? _b : 0);
110
+ if (byY !== 0)
111
+ return byY;
112
+ return ((_c = a === null || a === void 0 ? void 0 : a.x) !== null && _c !== void 0 ? _c : 0) - ((_d = b === null || b === void 0 ? void 0 : b.x) !== null && _d !== void 0 ? _d : 0);
113
+ });
114
+ };
115
+ var toLayoutItems = function (items) {
116
+ return (items !== null && items !== void 0 ? items : [])
117
+ .filter(function (item) { var _a; return !!((_a = item === null || item === void 0 ? void 0 : item.widgetId) !== null && _a !== void 0 ? _a : item === null || item === void 0 ? void 0 : item.id); })
118
+ .map(function (item) {
119
+ var _a, _b, _c, _d, _e;
120
+ return ({
121
+ widgetId: (_a = item === null || item === void 0 ? void 0 : item.widgetId) !== null && _a !== void 0 ? _a : item === null || item === void 0 ? void 0 : item.id,
122
+ x: Number((_b = item === null || item === void 0 ? void 0 : item.x) !== null && _b !== void 0 ? _b : 0),
123
+ y: Number((_c = item === null || item === void 0 ? void 0 : item.y) !== null && _c !== void 0 ? _c : 0),
124
+ w: Number((_d = item === null || item === void 0 ? void 0 : item.w) !== null && _d !== void 0 ? _d : 4),
125
+ h: Number((_e = item === null || item === void 0 ? void 0 : item.h) !== null && _e !== void 0 ? _e : 3),
126
+ minW: (item === null || item === void 0 ? void 0 : item.minW) !== undefined ? Number(item === null || item === void 0 ? void 0 : item.minW) : undefined,
127
+ minH: (item === null || item === void 0 ? void 0 : item.minH) !== undefined ? Number(item === null || item === void 0 ? void 0 : item.minH) : undefined,
128
+ });
129
+ });
130
+ };
131
+ var getAllLayoutItemsFromGrid = function (grid) {
132
+ var _a;
133
+ if (!grid)
134
+ return [];
135
+ var snapshot = grid.save(false, false, function (node, widget) {
136
+ var _a, _b, _c, _d, _e, _f, _g;
137
+ if (!widget.id) {
138
+ widget.id =
139
+ (_g = (_d = (_a = node === null || node === void 0 ? void 0 : node.id) !== null && _a !== void 0 ? _a : (_c = (_b = node === null || node === void 0 ? void 0 : node.el) === null || _b === void 0 ? void 0 : _b.getAttribute) === null || _c === void 0 ? void 0 : _c.call(_b, "gs-id")) !== null && _d !== void 0 ? _d : (_f = (_e = node === null || node === void 0 ? void 0 : node.el) === null || _e === void 0 ? void 0 : _e.getAttribute) === null || _f === void 0 ? void 0 : _f.call(_e, "id")) !== null && _g !== void 0 ? _g : "";
140
+ }
141
+ });
142
+ var widgets = Array.isArray(snapshot) ? snapshot : [];
143
+ var fromSave = toLayoutItems(widgets.map(function (item) {
144
+ var _a, _b, _c;
145
+ return ({
146
+ widgetId: (_a = item === null || item === void 0 ? void 0 : item.id) !== null && _a !== void 0 ? _a : item === null || item === void 0 ? void 0 : item.widgetId,
147
+ x: item === null || item === void 0 ? void 0 : item.x,
148
+ y: item === null || item === void 0 ? void 0 : item.y,
149
+ w: (_b = item === null || item === void 0 ? void 0 : item.w) !== null && _b !== void 0 ? _b : item === null || item === void 0 ? void 0 : item.width,
150
+ h: (_c = item === null || item === void 0 ? void 0 : item.h) !== null && _c !== void 0 ? _c : item === null || item === void 0 ? void 0 : item.height,
151
+ minW: item === null || item === void 0 ? void 0 : item.minW,
152
+ minH: item === null || item === void 0 ? void 0 : item.minH,
153
+ });
154
+ }));
155
+ if (fromSave.length > 0)
156
+ return fromSave;
157
+ var nodes = Array.isArray((_a = grid === null || grid === void 0 ? void 0 : grid.engine) === null || _a === void 0 ? void 0 : _a.nodes) ? grid.engine.nodes : [];
158
+ return toLayoutItems(nodes.map(function (node) {
159
+ var _a, _b, _c, _d, _e, _f, _g, _h;
160
+ return ({
161
+ widgetId: (_d = (_a = node === null || node === void 0 ? void 0 : node.id) !== null && _a !== void 0 ? _a : (_c = (_b = node === null || node === void 0 ? void 0 : node.el) === null || _b === void 0 ? void 0 : _b.getAttribute) === null || _c === void 0 ? void 0 : _c.call(_b, "gs-id")) !== null && _d !== void 0 ? _d : (_f = (_e = node === null || node === void 0 ? void 0 : node.el) === null || _e === void 0 ? void 0 : _e.getAttribute) === null || _f === void 0 ? void 0 : _f.call(_e, "id"),
162
+ x: node === null || node === void 0 ? void 0 : node.x,
163
+ y: node === null || node === void 0 ? void 0 : node.y,
164
+ w: (_g = node === null || node === void 0 ? void 0 : node.w) !== null && _g !== void 0 ? _g : node === null || node === void 0 ? void 0 : node.width,
165
+ h: (_h = node === null || node === void 0 ? void 0 : node.h) !== null && _h !== void 0 ? _h : node === null || node === void 0 ? void 0 : node.height,
166
+ minW: node === null || node === void 0 ? void 0 : node.minW,
167
+ minH: node === null || node === void 0 ? void 0 : node.minH,
168
+ });
169
+ }));
170
+ };
171
+ var resolveDefaultDashboardWidgetComponentName = function (definition, runtime) {
172
+ var _a, _b;
173
+ var runtimeData = (_b = (_a = runtime === null || runtime === void 0 ? void 0 : runtime.data) !== null && _a !== void 0 ? _a : runtime) !== null && _b !== void 0 ? _b : {};
174
+ if ((runtimeData === null || runtimeData === void 0 ? void 0 : runtimeData.value) !== undefined)
175
+ return "DefaultDashboardKpiWidget";
176
+ if (Array.isArray(runtimeData === null || runtimeData === void 0 ? void 0 : runtimeData.columns) && Array.isArray(runtimeData === null || runtimeData === void 0 ? void 0 : runtimeData.records))
177
+ return "DefaultDashboardTableWidget";
178
+ var chartType = resolveChartType(definition);
179
+ if (chartType === "line")
180
+ return "DefaultDashboardLineChartWidget";
181
+ if (chartType === "bar")
182
+ return "DefaultDashboardBarChartWidget";
183
+ if (chartType === "pie")
184
+ return "DefaultDashboardPieChartWidget";
185
+ return "DefaultDashboardUnknownWidget";
186
+ };
187
+ var getPreferredWidgetComponentName = function (definition, runtime) {
188
+ var _a, _b, _c, _d, _e;
189
+ var explicit = (_d = (_b = (_a = definition === null || definition === void 0 ? void 0 : definition.componentName) !== null && _a !== void 0 ? _a : definition === null || definition === void 0 ? void 0 : definition.widgetComponentName) !== null && _b !== void 0 ? _b : (_c = definition === null || definition === void 0 ? void 0 : definition.renderer) === null || _c === void 0 ? void 0 : _c.componentName) !== null && _d !== void 0 ? _d : (_e = definition === null || definition === void 0 ? void 0 : definition.ui) === null || _e === void 0 ? void 0 : _e.componentName;
190
+ return explicit || resolveDefaultDashboardWidgetComponentName(definition, runtime);
191
+ };
192
+ var notifyDashboardChartsToResize = function () {
193
+ if (typeof window === "undefined")
194
+ return;
195
+ window.requestAnimationFrame(function () {
196
+ window.dispatchEvent(new Event("resize"));
197
+ });
198
+ };
199
+ var resolvePresetRange = function (preset) {
200
+ if (!preset)
201
+ return { start: null, end: null };
202
+ var now = new Date();
203
+ var end = new Date(now);
204
+ if (preset === "today") {
205
+ var start = new Date(now);
206
+ start.setHours(0, 0, 0, 0);
207
+ return { start: start, end: end };
208
+ }
209
+ if (preset === "last_24_hours") {
210
+ var start = new Date(now);
211
+ start.setHours(start.getHours() - 24);
212
+ return { start: start, end: end };
213
+ }
214
+ if (preset === "last_7_days") {
215
+ var start = new Date(now);
216
+ start.setDate(start.getDate() - 7);
217
+ return { start: start, end: end };
218
+ }
219
+ if (preset === "last_30_days") {
220
+ var start = new Date(now);
221
+ start.setDate(start.getDate() - 30);
222
+ return { start: start, end: end };
223
+ }
224
+ return { start: null, end: null };
225
+ };
226
+ var parseDateValue = function (value) {
227
+ if (!value)
228
+ return null;
229
+ var date = new Date(value);
230
+ return Number.isNaN(date.getTime()) ? null : date;
231
+ };
232
+ var getDatePresetOptions = function (variable) {
233
+ var _a, _b;
234
+ var metadataPresets = (_b = (_a = variable === null || variable === void 0 ? void 0 : variable.presetValues) !== null && _a !== void 0 ? _a : variable === null || variable === void 0 ? void 0 : variable.presets) !== null && _b !== void 0 ? _b : variable === null || variable === void 0 ? void 0 : variable.datePresets;
235
+ var builtIns = [
236
+ { value: "today", label: "Today" },
237
+ { value: "last_24_hours", label: "Last 24 Hours" },
238
+ { value: "last_7_days", label: "Last 7 Days" },
239
+ { value: "last_30_days", label: "Last 30 Days" },
240
+ ];
241
+ var source = Array.isArray(metadataPresets) && metadataPresets.length ? metadataPresets : builtIns;
242
+ var normalized = source
243
+ .map(function (entry) {
244
+ var _a, _b, _c, _d;
245
+ if (typeof entry === "string") {
246
+ var _e = entry.split(":"), value_1 = _e[0], label_1 = _e[1];
247
+ var cleaned = "".concat(value_1 !== null && value_1 !== void 0 ? value_1 : "").trim();
248
+ if (!cleaned)
249
+ return null;
250
+ return { value: cleaned, label: "".concat(label_1 !== null && label_1 !== void 0 ? label_1 : cleaned) };
251
+ }
252
+ var value = "".concat((_b = (_a = entry === null || entry === void 0 ? void 0 : entry.value) !== null && _a !== void 0 ? _a : entry === null || entry === void 0 ? void 0 : entry.id) !== null && _b !== void 0 ? _b : "").trim();
253
+ if (!value)
254
+ return null;
255
+ var label = "".concat((_d = (_c = entry === null || entry === void 0 ? void 0 : entry.label) !== null && _c !== void 0 ? _c : entry === null || entry === void 0 ? void 0 : entry.displayName) !== null && _d !== void 0 ? _d : value);
256
+ return { value: value, label: label };
257
+ })
258
+ .filter(Boolean);
259
+ if (!normalized.find(function (entry) { return entry.value === "custom"; })) {
260
+ normalized.push({ value: "custom", label: "Custom" });
261
+ }
262
+ return normalized;
263
+ };
264
+ var buildDefaultFilterValues = function (variables) {
265
+ var defaults = {};
266
+ variables.forEach(function (variable) {
267
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
268
+ var name = variable === null || variable === void 0 ? void 0 : variable.name;
269
+ if (!name)
270
+ return;
271
+ if (isDateRangeVariable(variable)) {
272
+ var presetRange = resolvePresetRange((_b = (_a = variable === null || variable === void 0 ? void 0 : variable.defaultValue) === null || _a === void 0 ? void 0 : _a.preset) !== null && _b !== void 0 ? _b : variable === null || variable === void 0 ? void 0 : variable.defaultValuePreset);
273
+ var start = (_f = parseDateValue((_d = (_c = variable === null || variable === void 0 ? void 0 : variable.defaultValue) === null || _c === void 0 ? void 0 : _c.start) !== null && _d !== void 0 ? _d : (_e = variable === null || variable === void 0 ? void 0 : variable.defaultValue) === null || _e === void 0 ? void 0 : _e.from)) !== null && _f !== void 0 ? _f : presetRange.start;
274
+ var end = (_k = parseDateValue((_h = (_g = variable === null || variable === void 0 ? void 0 : variable.defaultValue) === null || _g === void 0 ? void 0 : _g.end) !== null && _h !== void 0 ? _h : (_j = variable === null || variable === void 0 ? void 0 : variable.defaultValue) === null || _j === void 0 ? void 0 : _j.to)) !== null && _k !== void 0 ? _k : presetRange.end;
275
+ var preset = "".concat((_o = (_m = (_l = variable === null || variable === void 0 ? void 0 : variable.defaultValue) === null || _l === void 0 ? void 0 : _l.preset) !== null && _m !== void 0 ? _m : variable === null || variable === void 0 ? void 0 : variable.defaultValuePreset) !== null && _o !== void 0 ? _o : "").trim() ||
276
+ (start || end ? "custom" : "custom");
277
+ defaults[name] = { start: start, end: end, preset: preset };
278
+ return;
279
+ }
280
+ if (isMultiValueVariable(variable)) {
281
+ var base = variable === null || variable === void 0 ? void 0 : variable.defaultValue;
282
+ defaults[name] = Array.isArray(base) ? base.map(function (entry) { return "".concat(entry); }) : [];
283
+ return;
284
+ }
285
+ if ((variable === null || variable === void 0 ? void 0 : variable.defaultValue) !== undefined && (variable === null || variable === void 0 ? void 0 : variable.defaultValue) !== null) {
286
+ defaults[name] = "".concat(variable.defaultValue);
287
+ return;
288
+ }
289
+ defaults[name] = "";
290
+ });
291
+ return defaults;
292
+ };
293
+ var buildClearedFilterValues = function (variables) {
294
+ var cleared = {};
295
+ variables.forEach(function (variable) {
296
+ var name = variable === null || variable === void 0 ? void 0 : variable.name;
297
+ if (!name)
298
+ return;
299
+ if (isDateRangeVariable(variable)) {
300
+ cleared[name] = { start: null, end: null, preset: "custom" };
301
+ return;
302
+ }
303
+ if (isMultiValueVariable(variable)) {
304
+ cleared[name] = [];
305
+ return;
306
+ }
307
+ cleared[name] = "";
308
+ });
309
+ return cleared;
310
+ };
311
+ var isFilterValueApplied = function (variable, value) {
312
+ if (isDateRangeVariable(variable)) {
313
+ var range = value;
314
+ return !!(range === null || range === void 0 ? void 0 : range.start) || !!(range === null || range === void 0 ? void 0 : range.end);
315
+ }
316
+ if (isMultiValueVariable(variable)) {
317
+ return Array.isArray(value) && value.length > 0;
318
+ }
319
+ return value !== undefined && value !== null && "".concat(value).trim() !== "";
320
+ };
321
+ var isSameFilterValue = function (variable, left, right) {
322
+ var _a, _b;
323
+ if (isDateRangeVariable(variable)) {
324
+ var leftRange = (_a = left) !== null && _a !== void 0 ? _a : { start: null, end: null };
325
+ var rightRange = (_b = right) !== null && _b !== void 0 ? _b : { start: null, end: null };
326
+ return toIso(leftRange.start) === toIso(rightRange.start) && toIso(leftRange.end) === toIso(rightRange.end);
327
+ }
328
+ if (isMultiValueVariable(variable)) {
329
+ var leftArr = Array.isArray(left) ? left.map(function (v) { return "".concat(v); }).sort() : [];
330
+ var rightArr_1 = Array.isArray(right) ? right.map(function (v) { return "".concat(v); }).sort() : [];
331
+ if (leftArr.length !== rightArr_1.length)
332
+ return false;
333
+ return leftArr.every(function (value, index) { return value === rightArr_1[index]; });
334
+ }
335
+ return "".concat(left !== null && left !== void 0 ? left : "") === "".concat(right !== null && right !== void 0 ? right : "");
336
+ };
337
+ var getDashboardTitle = function (definition, fallback) { var _a, _b, _c; return (_c = (_b = (_a = definition === null || definition === void 0 ? void 0 : definition.displayName) !== null && _a !== void 0 ? _a : definition === null || definition === void 0 ? void 0 : definition.title) !== null && _b !== void 0 ? _b : definition === null || definition === void 0 ? void 0 : definition.name) !== null && _c !== void 0 ? _c : fallback; };
338
+ var getWidgetTitle = function (widget, fallback) { var _a, _b, _c; return (_c = (_b = (_a = widget === null || widget === void 0 ? void 0 : widget.displayName) !== null && _a !== void 0 ? _a : widget === null || widget === void 0 ? void 0 : widget.title) !== null && _b !== void 0 ? _b : widget === null || widget === void 0 ? void 0 : widget.name) !== null && _c !== void 0 ? _c : fallback; };
339
+ var isUnauthorizedWidgetRuntime = function (runtime) { var _a, _b; return !!(((_a = runtime === null || runtime === void 0 ? void 0 : runtime.meta) === null || _a === void 0 ? void 0 : _a.unauthorized) || ((_b = runtime === null || runtime === void 0 ? void 0 : runtime.uiHints) === null || _b === void 0 ? void 0 : _b.state) === "unauthorized"); };
4
340
  export function DashboardPage() {
341
+ var _this = this;
342
+ var _a, _b, _c, _d, _e;
5
343
  var params = useParams();
6
- var dashboardName = params.dashboardName;
7
- var moduleName = params.moduleName;
8
- return (_jsx("div", { children: _jsx(SolidDashboard, { moduleName: moduleName, dashboardName: dashboardName }) }));
344
+ var moduleName = (_a = params.moduleName) !== null && _a !== void 0 ? _a : "";
345
+ var dashboardName = (_b = params.dashboardName) !== null && _b !== void 0 ? _b : "";
346
+ var gridRef = useRef(null);
347
+ var gridInstanceRef = useRef(null);
348
+ var _f = useGetDashboardDefinitionQuery({ moduleName: moduleName, dashboardName: dashboardName }, { skip: !moduleName || !dashboardName }), definition = _f.data, definitionLoading = _f.isLoading;
349
+ var layoutData = useGetDashboardLayoutQuery({ moduleName: moduleName, dashboardName: dashboardName }, { skip: !moduleName || !dashboardName }).data;
350
+ var _g = useGetDashboardDataMutation(), getDashboardData = _g[0], _h = _g[1], dashboardData = _h.data, dataLoading = _h.isLoading, dataError = _h.error;
351
+ var _j = useSaveDashboardLayoutMutation(), saveDashboardLayout = _j[0], saveLayoutLoading = _j[1].isLoading;
352
+ var getVariableOptions = useLazyGetDashboardVariableOptionsQuery()[0];
353
+ var _k = useState({}), appliedVariableValues = _k[0], setAppliedVariableValues = _k[1];
354
+ var _l = useState({}), filterDraftValues = _l[0], setFilterDraftValues = _l[1];
355
+ var _m = useState({}), dynamicOptions = _m[0], setDynamicOptions = _m[1];
356
+ var _o = useState(null), draftLayoutItems = _o[0], setDraftLayoutItems = _o[1];
357
+ var _p = useState(false), isFilterDialogOpen = _p[0], setIsFilterDialogOpen = _p[1];
358
+ var bootstrappedRef = useRef(false);
359
+ var variables = useMemo(function () { return (Array.isArray(definition === null || definition === void 0 ? void 0 : definition.variables) ? definition.variables : []); }, [definition]);
360
+ var definitionWidgets = useMemo(function () { return (Array.isArray(definition === null || definition === void 0 ? void 0 : definition.widgets) ? definition.widgets : []); }, [definition]);
361
+ var effectiveLayoutItems = useMemo(function () { var _a, _b; return toLayoutItems((_b = (_a = layoutData === null || layoutData === void 0 ? void 0 : layoutData.effectiveLayout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : []); }, [layoutData]);
362
+ var gridColumns = Number((_d = (_c = layoutData === null || layoutData === void 0 ? void 0 : layoutData.effectiveLayout) === null || _c === void 0 ? void 0 : _c.columns) !== null && _d !== void 0 ? _d : 12) || 12;
363
+ var defaultFilterValues = useMemo(function () { return buildDefaultFilterValues(variables); }, [variables]);
364
+ useEffect(function () {
365
+ if (!definition || bootstrappedRef.current)
366
+ return;
367
+ setAppliedVariableValues(defaultFilterValues);
368
+ setFilterDraftValues(defaultFilterValues);
369
+ bootstrappedRef.current = true;
370
+ }, [definition, defaultFilterValues]);
371
+ useEffect(function () {
372
+ if (!isFilterDialogOpen)
373
+ return;
374
+ setFilterDraftValues(appliedVariableValues);
375
+ }, [appliedVariableValues, isFilterDialogOpen]);
376
+ useEffect(function () {
377
+ if (!moduleName || !dashboardName || variables.length === 0)
378
+ return;
379
+ var dynamicVariables = variables.filter(function (variable) { return isDynamicVariable(variable); });
380
+ dynamicVariables.forEach(function (variable) {
381
+ var variableName = variable === null || variable === void 0 ? void 0 : variable.name;
382
+ if (!variableName)
383
+ return;
384
+ void getVariableOptions({ moduleName: moduleName, dashboardName: dashboardName, variableName: variableName, limit: 100 })
385
+ .unwrap()
386
+ .then(function (response) {
387
+ setDynamicOptions(function (prev) {
388
+ var _a;
389
+ return (__assign(__assign({}, prev), (_a = {}, _a[variableName] = toOptions(Array.isArray(response) ? response : []), _a)));
390
+ });
391
+ })
392
+ .catch(function () {
393
+ setDynamicOptions(function (prev) {
394
+ var _a;
395
+ return (__assign(__assign({}, prev), (_a = {}, _a[variableName] = [], _a)));
396
+ });
397
+ });
398
+ });
399
+ }, [dashboardName, getVariableOptions, moduleName, variables]);
400
+ var handleDynamicOptionsSearch = function (variableName, query) { return __awaiter(_this, void 0, void 0, function () {
401
+ var response_1, _a;
402
+ return __generator(this, function (_b) {
403
+ switch (_b.label) {
404
+ case 0:
405
+ if (!moduleName || !dashboardName || !variableName)
406
+ return [2 /*return*/];
407
+ _b.label = 1;
408
+ case 1:
409
+ _b.trys.push([1, 3, , 4]);
410
+ return [4 /*yield*/, getVariableOptions({ moduleName: moduleName, dashboardName: dashboardName, variableName: variableName, query: query, limit: 100 }).unwrap()];
411
+ case 2:
412
+ response_1 = _b.sent();
413
+ setDynamicOptions(function (prev) {
414
+ var _a;
415
+ return (__assign(__assign({}, prev), (_a = {}, _a[variableName] = toOptions(Array.isArray(response_1) ? response_1 : []), _a)));
416
+ });
417
+ return [3 /*break*/, 4];
418
+ case 3:
419
+ _a = _b.sent();
420
+ setDynamicOptions(function (prev) {
421
+ var _a;
422
+ return (__assign(__assign({}, prev), (_a = {}, _a[variableName] = [], _a)));
423
+ });
424
+ return [3 /*break*/, 4];
425
+ case 4: return [2 /*return*/];
426
+ }
427
+ });
428
+ }); };
429
+ useEffect(function () {
430
+ if (!bootstrappedRef.current || !moduleName || !dashboardName)
431
+ return;
432
+ void handleRefresh(appliedVariableValues);
433
+ // eslint-disable-next-line react-hooks/exhaustive-deps
434
+ }, [moduleName, dashboardName, bootstrappedRef.current]);
435
+ var widgetDefinitionMap = useMemo(function () {
436
+ var map = new Map();
437
+ definitionWidgets.forEach(function (widget) {
438
+ if (widget === null || widget === void 0 ? void 0 : widget.id)
439
+ map.set(widget.id, widget);
440
+ if (widget === null || widget === void 0 ? void 0 : widget.name)
441
+ map.set(widget.name, widget);
442
+ });
443
+ return map;
444
+ }, [definitionWidgets]);
445
+ var widgetDataMap = useMemo(function () {
446
+ var map = new Map();
447
+ var rows = Array.isArray(dashboardData === null || dashboardData === void 0 ? void 0 : dashboardData.widgets) ? dashboardData.widgets : [];
448
+ rows.forEach(function (row) {
449
+ var name = extractWidgetName(row);
450
+ if (name)
451
+ map.set(name, row);
452
+ });
453
+ return map;
454
+ }, [dashboardData]);
455
+ var orderedWidgets = useMemo(function () {
456
+ var layoutItems = sortLayoutItems(effectiveLayoutItems);
457
+ if (!layoutItems.length)
458
+ return definitionWidgets;
459
+ var seen = new Set();
460
+ var arranged = [];
461
+ layoutItems.forEach(function (item) {
462
+ var key = item === null || item === void 0 ? void 0 : item.widgetId;
463
+ var definitionWidget = widgetDefinitionMap.get(key);
464
+ if (!definitionWidget || seen.has(key))
465
+ return;
466
+ arranged.push(definitionWidget);
467
+ seen.add(key);
468
+ });
469
+ definitionWidgets.forEach(function (widget) {
470
+ var _a;
471
+ var key = (_a = widget === null || widget === void 0 ? void 0 : widget.id) !== null && _a !== void 0 ? _a : widget === null || widget === void 0 ? void 0 : widget.name;
472
+ if (!key || seen.has(key))
473
+ return;
474
+ arranged.push(widget);
475
+ });
476
+ return arranged;
477
+ }, [definitionWidgets, effectiveLayoutItems, widgetDefinitionMap]);
478
+ var widgetLayoutMap = useMemo(function () {
479
+ var map = new Map();
480
+ effectiveLayoutItems.forEach(function (item) { return map.set(item.widgetId, item); });
481
+ return map;
482
+ }, [effectiveLayoutItems]);
483
+ var appliedFilterCount = useMemo(function () {
484
+ return variables.reduce(function (count, variable) {
485
+ var name = variable === null || variable === void 0 ? void 0 : variable.name;
486
+ if (!name)
487
+ return count;
488
+ var value = appliedVariableValues[name];
489
+ var defaultValue = defaultFilterValues[name];
490
+ if (!isFilterValueApplied(variable, value))
491
+ return count;
492
+ return isSameFilterValue(variable, value, defaultValue) ? count : count + 1;
493
+ }, 0);
494
+ }, [appliedVariableValues, defaultFilterValues, variables]);
495
+ useEffect(function () {
496
+ if (!gridRef.current || orderedWidgets.length === 0)
497
+ return;
498
+ if (gridInstanceRef.current) {
499
+ gridInstanceRef.current.destroy(false);
500
+ gridInstanceRef.current = null;
501
+ }
502
+ var initialLayout = effectiveLayoutItems.length
503
+ ? effectiveLayoutItems
504
+ : orderedWidgets.map(function (widget, index) {
505
+ var _a, _b;
506
+ return ({
507
+ widgetId: (_b = (_a = widget === null || widget === void 0 ? void 0 : widget.id) !== null && _a !== void 0 ? _a : widget === null || widget === void 0 ? void 0 : widget.name) !== null && _b !== void 0 ? _b : "widget-".concat(index),
508
+ x: 0,
509
+ y: index * 3,
510
+ w: 4,
511
+ h: 3,
512
+ });
513
+ });
514
+ var gridWidgets = initialLayout.map(function (item) { return ({
515
+ id: item.widgetId,
516
+ x: item.x,
517
+ y: item.y,
518
+ w: item.w,
519
+ h: item.h,
520
+ minW: item.minW,
521
+ minH: item.minH,
522
+ }); });
523
+ var instance = GridStack.init({
524
+ column: gridColumns,
525
+ cellHeight: 92,
526
+ margin: 8,
527
+ float: true,
528
+ }, gridRef.current);
529
+ // React renders the DOM; make sure Gridstack converts every item node to a widget,
530
+ // then explicitly apply layout from API to avoid attribute-parsing or timing issues.
531
+ instance.batchUpdate();
532
+ var domItems = Array.from(gridRef.current.querySelectorAll(".grid-stack-item"));
533
+ domItems.forEach(function (itemEl) {
534
+ if (!itemEl.gridstackNode) {
535
+ instance.makeWidget(itemEl);
536
+ }
537
+ });
538
+ instance.column(gridColumns, "none");
539
+ instance.load(gridWidgets, false);
540
+ instance.batchUpdate(false);
541
+ notifyDashboardChartsToResize();
542
+ window.setTimeout(notifyDashboardChartsToResize, 60);
543
+ instance.on("change", function (_event, _items) {
544
+ var normalized = getAllLayoutItemsFromGrid(instance);
545
+ setDraftLayoutItems(normalized);
546
+ notifyDashboardChartsToResize();
547
+ });
548
+ instance.on("resizestop", function () { return notifyDashboardChartsToResize(); });
549
+ instance.on("dragstop", function () { return notifyDashboardChartsToResize(); });
550
+ gridInstanceRef.current = instance;
551
+ return function () {
552
+ instance.destroy(false);
553
+ if (gridInstanceRef.current === instance)
554
+ gridInstanceRef.current = null;
555
+ };
556
+ }, [orderedWidgets, gridColumns, effectiveLayoutItems]);
557
+ var handleDraftVariableChange = function (variableName, value) {
558
+ setFilterDraftValues(function (prev) {
559
+ var _a;
560
+ return (__assign(__assign({}, prev), (_a = {}, _a[variableName] = value, _a)));
561
+ });
562
+ };
563
+ var buildPayloadVariables = function (values) {
564
+ var payload = {};
565
+ variables.forEach(function (variable) {
566
+ var _a, _b;
567
+ var name = variable === null || variable === void 0 ? void 0 : variable.name;
568
+ if (!name)
569
+ return;
570
+ var value = values[name];
571
+ if (isDateRangeVariable(variable)) {
572
+ var range = value;
573
+ var from = toIso((_a = range === null || range === void 0 ? void 0 : range.start) !== null && _a !== void 0 ? _a : null);
574
+ var to = toIso((_b = range === null || range === void 0 ? void 0 : range.end) !== null && _b !== void 0 ? _b : null);
575
+ if (!from && !to)
576
+ return;
577
+ payload[name] = { from: from, to: to };
578
+ return;
579
+ }
580
+ if (isMultiValueVariable(variable)) {
581
+ var list = Array.isArray(value) ? value.filter(Boolean) : [];
582
+ if (!list.length)
583
+ return;
584
+ payload[name] = list;
585
+ return;
586
+ }
587
+ if (value === undefined || value === null || value === "")
588
+ return;
589
+ payload[name] = value;
590
+ });
591
+ return payload;
592
+ };
593
+ function handleRefresh(values) {
594
+ if (values === void 0) { values = appliedVariableValues; }
595
+ return __awaiter(this, void 0, void 0, function () {
596
+ return __generator(this, function (_a) {
597
+ switch (_a.label) {
598
+ case 0:
599
+ if (!moduleName || !dashboardName)
600
+ return [2 /*return*/];
601
+ return [4 /*yield*/, getDashboardData({
602
+ moduleName: moduleName,
603
+ dashboardName: dashboardName,
604
+ variables: buildPayloadVariables(values),
605
+ }).unwrap()];
606
+ case 1:
607
+ _a.sent();
608
+ return [2 /*return*/];
609
+ }
610
+ });
611
+ });
612
+ }
613
+ function handleApplyFilters() {
614
+ return __awaiter(this, void 0, void 0, function () {
615
+ var nextValues;
616
+ return __generator(this, function (_a) {
617
+ switch (_a.label) {
618
+ case 0:
619
+ nextValues = __assign({}, filterDraftValues);
620
+ setAppliedVariableValues(nextValues);
621
+ setIsFilterDialogOpen(false);
622
+ return [4 /*yield*/, handleRefresh(nextValues)];
623
+ case 1:
624
+ _a.sent();
625
+ return [2 /*return*/];
626
+ }
627
+ });
628
+ });
629
+ }
630
+ function handleClearFilters() {
631
+ return __awaiter(this, void 0, void 0, function () {
632
+ var clearedValues;
633
+ return __generator(this, function (_a) {
634
+ switch (_a.label) {
635
+ case 0:
636
+ clearedValues = buildClearedFilterValues(variables);
637
+ setFilterDraftValues(clearedValues);
638
+ setAppliedVariableValues(clearedValues);
639
+ setIsFilterDialogOpen(false);
640
+ return [4 /*yield*/, handleRefresh(clearedValues)];
641
+ case 1:
642
+ _a.sent();
643
+ return [2 /*return*/];
644
+ }
645
+ });
646
+ });
647
+ }
648
+ function handleSaveLayout() {
649
+ return __awaiter(this, void 0, void 0, function () {
650
+ var liveGridLayout, baseLayout, items;
651
+ return __generator(this, function (_a) {
652
+ switch (_a.label) {
653
+ case 0:
654
+ if (!moduleName || !dashboardName)
655
+ return [2 /*return*/];
656
+ liveGridLayout = getAllLayoutItemsFromGrid(gridInstanceRef.current);
657
+ baseLayout = effectiveLayoutItems.length ? effectiveLayoutItems : [];
658
+ items = liveGridLayout.length
659
+ ? liveGridLayout
660
+ : draftLayoutItems && draftLayoutItems.length
661
+ ? draftLayoutItems
662
+ : baseLayout;
663
+ return [4 /*yield*/, saveDashboardLayout({
664
+ moduleName: moduleName,
665
+ dashboardName: dashboardName,
666
+ layout: {
667
+ engine: "gridstack",
668
+ columns: gridColumns,
669
+ items: items,
670
+ },
671
+ }).unwrap()];
672
+ case 1:
673
+ _a.sent();
674
+ setDraftLayoutItems(null);
675
+ return [2 /*return*/];
676
+ }
677
+ });
678
+ });
679
+ }
680
+ var renderVariable = function (variable) {
681
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
682
+ var variableName = variable === null || variable === void 0 ? void 0 : variable.name;
683
+ if (!variableName)
684
+ return null;
685
+ var value = filterDraftValues[variableName];
686
+ var label = (_b = (_a = variable === null || variable === void 0 ? void 0 : variable.displayName) !== null && _a !== void 0 ? _a : variable === null || variable === void 0 ? void 0 : variable.label) !== null && _b !== void 0 ? _b : variableName;
687
+ if (isDateRangeVariable(variable)) {
688
+ var range_1 = (_c = value) !== null && _c !== void 0 ? _c : { start: null, end: null };
689
+ var presetOptions = getDatePresetOptions(variable);
690
+ var preset = (range_1 === null || range_1 === void 0 ? void 0 : range_1.preset) && presetOptions.some(function (entry) { return entry.value === range_1.preset; }) ? range_1.preset : "custom";
691
+ return (_jsxs("div", { className: styles.filterField, children: [_jsx("label", { className: styles.filterLabel, children: label }), _jsx(SolidSelect, { value: preset, options: presetOptions, optionLabel: "label", optionValue: "value", placeholder: "Select ".concat(label, " preset"), onChange: function (event) {
692
+ var _a, _b, _c, _d, _e;
693
+ var selectedPreset = "".concat((_a = event === null || event === void 0 ? void 0 : event.value) !== null && _a !== void 0 ? _a : "custom");
694
+ if (selectedPreset === "custom") {
695
+ handleDraftVariableChange(variableName, {
696
+ start: (_b = range_1.start) !== null && _b !== void 0 ? _b : null,
697
+ end: (_c = range_1.end) !== null && _c !== void 0 ? _c : null,
698
+ preset: "custom",
699
+ });
700
+ return;
701
+ }
702
+ var nextRange = resolvePresetRange(selectedPreset);
703
+ handleDraftVariableChange(variableName, {
704
+ start: (_d = nextRange.start) !== null && _d !== void 0 ? _d : null,
705
+ end: (_e = nextRange.end) !== null && _e !== void 0 ? _e : null,
706
+ preset: selectedPreset,
707
+ });
708
+ } }), preset === "custom" ? (_jsxs("div", { className: styles.dateRange, children: [_jsx(SolidDatePicker, { selected: (_d = range_1.start) !== null && _d !== void 0 ? _d : null, inputClassName: "w-full", onChange: function (next) {
709
+ var _a;
710
+ return handleDraftVariableChange(variableName, {
711
+ start: next !== null && next !== void 0 ? next : null,
712
+ end: (_a = range_1.end) !== null && _a !== void 0 ? _a : null,
713
+ preset: "custom",
714
+ });
715
+ }, placeholderText: "Start date", dateFormat: "yyyy-MM-dd" }), _jsx(SolidDatePicker, { selected: (_e = range_1.end) !== null && _e !== void 0 ? _e : null, inputClassName: "w-full", onChange: function (next) {
716
+ var _a;
717
+ return handleDraftVariableChange(variableName, {
718
+ start: (_a = range_1.start) !== null && _a !== void 0 ? _a : null,
719
+ end: next !== null && next !== void 0 ? next : null,
720
+ preset: "custom",
721
+ });
722
+ }, placeholderText: "End date", dateFormat: "yyyy-MM-dd" })] })) : null] }, variableName));
723
+ }
724
+ if (isMultiValueVariable(variable)) {
725
+ var baseOptions = isDynamicVariable(variable)
726
+ ? ((_f = dynamicOptions[variableName]) !== null && _f !== void 0 ? _f : [])
727
+ : toOptions((_h = (_g = variable === null || variable === void 0 ? void 0 : variable.selectionStaticValues) !== null && _g !== void 0 ? _g : variable === null || variable === void 0 ? void 0 : variable.options) !== null && _h !== void 0 ? _h : []);
728
+ var selectedValues_1 = Array.isArray(value) ? value : [];
729
+ return (_jsxs("div", { className: styles.filterField, children: [_jsx("label", { className: styles.filterLabel, children: label }), _jsx(SolidAutocomplete, { multiple: true, dropdown: true, field: "label", className: "w-full", inputClassName: "w-full", value: baseOptions.filter(function (option) { return selectedValues_1.includes(option.value); }), suggestions: baseOptions, completeMethod: function () { return Promise.resolve(); }, placeholder: "Select ".concat(label), onChange: function (event) {
730
+ var selected = Array.isArray(event === null || event === void 0 ? void 0 : event.value)
731
+ ? event.value
732
+ .map(function (entry) { var _a, _b, _c; return "".concat((_c = (_b = (_a = entry === null || entry === void 0 ? void 0 : entry.value) !== null && _a !== void 0 ? _a : entry === null || entry === void 0 ? void 0 : entry.id) !== null && _b !== void 0 ? _b : entry) !== null && _c !== void 0 ? _c : ""); })
733
+ .filter(function (entry) { return !!entry; })
734
+ : [];
735
+ handleDraftVariableChange(variableName, selected);
736
+ } })] }, variableName));
737
+ }
738
+ if (isDynamicVariable(variable)) {
739
+ var options_1 = (_j = dynamicOptions[variableName]) !== null && _j !== void 0 ? _j : [];
740
+ var selectedValue_1 = typeof value === "string" ? value : "";
741
+ var selectedOption = (_k = options_1.find(function (entry) { return "".concat(entry.value) === selectedValue_1; })) !== null && _k !== void 0 ? _k : null;
742
+ return (_jsxs("div", { className: styles.filterField, children: [_jsx("label", { className: styles.filterLabel, children: label }), _jsx(SolidAutocomplete, { dropdown: true, field: "label", className: "w-full", inputClassName: "w-full", value: selectedOption, suggestions: options_1, completeMethod: function (_a) {
743
+ var query = _a.query;
744
+ return handleDynamicOptionsSearch(variableName, query);
745
+ }, placeholder: "Select ".concat(label), onChange: function (event) {
746
+ var _a, _b;
747
+ var selected = event === null || event === void 0 ? void 0 : event.value;
748
+ var nextValue = (_b = (_a = selected === null || selected === void 0 ? void 0 : selected.value) !== null && _a !== void 0 ? _a : selected === null || selected === void 0 ? void 0 : selected.id) !== null && _b !== void 0 ? _b : "";
749
+ handleDraftVariableChange(variableName, nextValue ? "".concat(nextValue) : "");
750
+ } })] }, variableName));
751
+ }
752
+ var options = isDynamicVariable(variable)
753
+ ? ((_l = dynamicOptions[variableName]) !== null && _l !== void 0 ? _l : [])
754
+ : isStaticVariable(variable)
755
+ ? toOptions((_o = (_m = variable === null || variable === void 0 ? void 0 : variable.selectionStaticValues) !== null && _m !== void 0 ? _m : variable === null || variable === void 0 ? void 0 : variable.options) !== null && _o !== void 0 ? _o : [])
756
+ : [];
757
+ return (_jsxs("div", { className: styles.filterField, children: [_jsx("label", { className: styles.filterLabel, children: label }), _jsx(SolidSelect, { value: typeof value === "string" ? value : "", options: options, optionLabel: "label", optionValue: "value", placeholder: "Select ".concat(label), onChange: function (event) { return handleDraftVariableChange(variableName, event.value ? "".concat(event.value) : ""); } })] }, variableName));
758
+ };
759
+ var renderWidgetBody = function (widgetDefinition, runtime) {
760
+ var _a, _b, _c, _d;
761
+ if (isUnauthorizedWidgetRuntime(runtime)) {
762
+ return (_jsxs("div", { className: styles.widgetUnauthorizedState, children: [_jsx(AlertTriangle, { size: 18, className: styles.widgetUnauthorizedIcon }), _jsx("span", { className: styles.widgetUnauthorizedText, children: (_b = (_a = runtime === null || runtime === void 0 ? void 0 : runtime.uiHints) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Unauthorized" })] }));
763
+ }
764
+ var componentName = getPreferredWidgetComponentName(widgetDefinition, runtime);
765
+ var ExtensionWidget = getExtensionComponent(componentName);
766
+ if (!ExtensionWidget) {
767
+ var UnknownWidget = getExtensionComponent("DefaultDashboardUnknownWidget");
768
+ if (!UnknownWidget)
769
+ return _jsx("pre", { children: JSON.stringify((_d = (_c = runtime === null || runtime === void 0 ? void 0 : runtime.data) !== null && _c !== void 0 ? _c : runtime) !== null && _d !== void 0 ? _d : {}, null, 2) });
770
+ return _jsx(UnknownWidget, { definition: widgetDefinition, runtime: runtime, variables: appliedVariableValues });
771
+ }
772
+ return (_jsx(ExtensionWidget, __assign({}, ({ definition: widgetDefinition, runtime: runtime, variables: appliedVariableValues }))));
773
+ };
774
+ if (definitionLoading) {
775
+ return (_jsx("div", { className: styles.page, children: _jsx(SolidSpinner, {}) }));
776
+ }
777
+ return (_jsxs("div", { className: styles.page, children: [_jsxs("div", { className: styles.header, children: [_jsxs("div", { className: styles.titleBlock, children: [_jsx("h1", { className: styles.title, children: getDashboardTitle(definition, dashboardName) }), _jsx("p", { className: styles.subtitle, children: (_e = definition === null || definition === void 0 ? void 0 : definition.description) !== null && _e !== void 0 ? _e : "".concat(moduleName, " / ").concat(dashboardName) })] }), _jsxs("div", { className: styles.headerActions, children: [_jsxs("div", { className: styles.filterButtonWrap, children: [_jsx(SolidButton, { className: styles.iconButton, leftIcon: _jsx(Filter, { size: 16 }), onClick: function () { return setIsFilterDialogOpen(true); }, tooltip: "Filters", "aria-label": "Filters" }), appliedFilterCount > 0 ? _jsx("span", { className: styles.filterCountBadge, children: appliedFilterCount }) : null] }), _jsx(SolidButton, { className: styles.iconButton, leftIcon: _jsx(RefreshCw, { size: 16 }), onClick: function () { return void handleRefresh(); }, disabled: dataLoading, tooltip: "Refresh", "aria-label": "Refresh" }), _jsx(SolidButton, { className: styles.iconButton, leftIcon: _jsx(Save, { size: 16 }), onClick: function () { return void handleSaveLayout(); }, disabled: saveLayoutLoading, tooltip: "Save Layout", "aria-label": "Save Layout" })] })] }), _jsxs(SolidDialog, { open: isFilterDialogOpen, onOpenChange: setIsFilterDialogOpen, header: "Dashboard Filters", contentClassName: styles.filterDialogContent, children: [_jsx(SolidDialogBody, { children: _jsx("div", { className: styles.filterModalColumn, children: variables.map(renderVariable) }) }), _jsxs(SolidDialogFooter, { className: styles.filterModalActions, children: [_jsx(SolidButton, { variant: "outline", onClick: function () { return void handleClearFilters(); }, children: "Clear" }), _jsx(SolidButton, { onClick: function () { return void handleApplyFilters(); }, children: "Apply" })] })] }), dataError ? _jsx("p", { className: styles.error, children: "Failed to load dashboard data." }) : null, _jsx("div", { ref: gridRef, className: "grid-stack ".concat(styles.gridStack), children: orderedWidgets.map(function (widget) {
778
+ var _a, _b, _c, _d, _e, _f, _g;
779
+ var widgetName = (_a = widget === null || widget === void 0 ? void 0 : widget.id) !== null && _a !== void 0 ? _a : widget === null || widget === void 0 ? void 0 : widget.name;
780
+ var runtime = widgetDataMap.get(widgetName);
781
+ var slot = widgetLayoutMap.get(widgetName);
782
+ return (_jsx("div", { className: "grid-stack-item", "gs-id": widgetName, "gs-x": (_b = slot === null || slot === void 0 ? void 0 : slot.x) !== null && _b !== void 0 ? _b : 0, "gs-y": (_c = slot === null || slot === void 0 ? void 0 : slot.y) !== null && _c !== void 0 ? _c : 0, "gs-w": (_d = slot === null || slot === void 0 ? void 0 : slot.w) !== null && _d !== void 0 ? _d : 4, "gs-h": (_e = slot === null || slot === void 0 ? void 0 : slot.h) !== null && _e !== void 0 ? _e : 3, "gs-min-w": (_f = slot === null || slot === void 0 ? void 0 : slot.minW) !== null && _f !== void 0 ? _f : 2, "gs-min-h": (_g = slot === null || slot === void 0 ? void 0 : slot.minH) !== null && _g !== void 0 ? _g : 2, children: _jsxs("div", { className: "grid-stack-item-content ".concat(styles.widgetCard), children: [_jsx("h3", { className: styles.widgetTitle, children: getWidgetTitle(widget, widgetName) }), _jsx("div", { className: styles.widgetBody, children: runtime ? renderWidgetBody(widget, runtime) : _jsx("p", { className: styles.muted, children: "No data" }) })] }) }, widgetName));
783
+ }) })] }));
9
784
  }
10
785
  //# sourceMappingURL=DashboardPage.js.map