7
7
SelectItem ,
8
8
Subtitle ,
9
9
TextInput ,
10
+ Switch ,
10
11
} from "@tremor/react" ;
11
12
import { useEffect , useMemo , useState } from "react" ;
12
13
import {
@@ -16,13 +17,16 @@ import {
16
17
useWatch ,
17
18
useFieldArray ,
18
19
} from "react-hook-form" ;
19
- import { LayoutItem , Threshold } from "../../types" ;
20
+ import { LayoutItem , Threshold , PresetPanelType } from "../../types" ;
20
21
import ColumnsSelection from "./columns-selection" ;
21
22
22
23
interface PresetForm {
23
24
selectedPreset : string ;
24
25
countOfLastAlerts : string ;
25
26
thresholds : Threshold [ ] ;
27
+ presetPanelType : PresetPanelType ;
28
+ showFiringOnly : boolean ;
29
+ customLink ?: string ;
26
30
}
27
31
28
32
export interface PresetWidgetFormProps {
@@ -47,9 +51,12 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
47
51
? editingItem . preset . countOfLastAlerts || 0
48
52
: 5 ,
49
53
thresholds : editingItem ?. thresholds || [
50
- { value : 0 , color : "#22c55e " } , // Green
51
- { value : 20 , color : "#ef4444 " } , // Red
54
+ { value : 0 , color : "#10b981 " } , // Bold emerald green
55
+ { value : 20 , color : "#dc2626 " } , // Bold red
52
56
] ,
57
+ presetPanelType : editingItem ?. presetPanelType || PresetPanelType . ALERT_TABLE ,
58
+ showFiringOnly : editingItem ?. showFiringOnly ?? false ,
59
+ customLink : editingItem ?. customLink || "" ,
53
60
} ,
54
61
} ) ;
55
62
const [ presetColumns , setPresetColumns ] = useState < string [ ] | undefined > (
@@ -72,6 +79,9 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
72
79
...t ,
73
80
value : parseInt ( t . value ?. toString ( ) as string , 10 ) || 0 ,
74
81
} ) ) ,
82
+ presetPanelType : formValues . presetPanelType || PresetPanelType . ALERT_TABLE ,
83
+ showFiringOnly : formValues . showFiringOnly ?? false ,
84
+ customLink : formValues . customLink || "" ,
75
85
} ;
76
86
} , [ formValues , presetColumns ] ) ;
77
87
@@ -80,8 +90,23 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
80
90
return { } as LayoutItem ;
81
91
}
82
92
83
- const itemHeight = normalizedFormValues . countOfLastAlerts > 0 ? 6 : 4 ;
84
- const itemWidth = normalizedFormValues . countOfLastAlerts > 0 ? 4 : 3 ;
93
+ const isAlertTable = normalizedFormValues . presetPanelType === PresetPanelType . ALERT_TABLE ;
94
+ const isAlertCountPanel = normalizedFormValues . presetPanelType === PresetPanelType . ALERT_COUNT_PANEL ;
95
+
96
+ if ( isAlertCountPanel ) {
97
+ // Narrower, more compact layout for count panels with no minimum width
98
+ return {
99
+ w : 4 ,
100
+ h : 3 ,
101
+ minW : 0 ,
102
+ minH : 2 ,
103
+ static : false ,
104
+ } as LayoutItem ;
105
+ }
106
+
107
+ // Original layout for alert tables
108
+ const itemHeight = isAlertTable && normalizedFormValues . countOfLastAlerts > 0 ? 6 : 4 ;
109
+ const itemWidth = isAlertTable && normalizedFormValues . countOfLastAlerts > 0 ? 8 : 6 ;
85
110
86
111
return {
87
112
w : itemWidth ,
@@ -102,6 +127,9 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
102
127
} ,
103
128
presetColumns : normalizedFormValues . presetColumns ,
104
129
thresholds : normalizedFormValues . thresholds ,
130
+ presetPanelType : normalizedFormValues . presetPanelType ,
131
+ showFiringOnly : normalizedFormValues . showFiringOnly ,
132
+ customLink : normalizedFormValues . customLink ,
105
133
} ,
106
134
isValid
107
135
) ;
@@ -158,18 +186,81 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
158
186
/>
159
187
</ div >
160
188
< div className = "mb-4 mt-2" >
161
- < Subtitle > Last alerts count to display </ Subtitle >
189
+ < Subtitle > Panel Type </ Subtitle >
162
190
< Controller
163
- name = "countOfLastAlerts "
191
+ name = "presetPanelType "
164
192
control = { control }
165
193
rules = { {
166
194
required : {
167
195
value : true ,
168
- message : "Preset selection is required" ,
196
+ message : "Panel type selection is required" ,
169
197
} ,
170
198
} }
171
199
render = { ( { field } ) => (
172
- < TextInput
200
+ < Select
201
+ { ...field }
202
+ placeholder = "Select a panel type"
203
+ error = { ! ! get ( errors , "presetPanelType.message" ) }
204
+ errorMessage = { get ( errors , "presetPanelType.message" ) }
205
+ >
206
+ < SelectItem value = { PresetPanelType . ALERT_TABLE } >
207
+ Alert Table
208
+ </ SelectItem >
209
+ < SelectItem value = { PresetPanelType . ALERT_COUNT_PANEL } >
210
+ Alert Count Panel
211
+ </ SelectItem >
212
+ </ Select >
213
+ ) }
214
+ />
215
+ </ div >
216
+ { formValues . presetPanelType === PresetPanelType . ALERT_COUNT_PANEL && (
217
+ < >
218
+ < div className = "mb-4 mt-2" >
219
+ < div className = "flex items-center justify-between" >
220
+ < Subtitle > Show Firing Alerts Only</ Subtitle >
221
+ < Controller
222
+ name = "showFiringOnly"
223
+ control = { control }
224
+ render = { ( { field } ) => (
225
+ < Switch
226
+ checked = { field . value }
227
+ onChange = { field . onChange }
228
+ />
229
+ ) }
230
+ />
231
+ </ div >
232
+ </ div >
233
+ < div className = "mb-4 mt-2" >
234
+ < Subtitle > Custom Link (optional)</ Subtitle >
235
+ < Controller
236
+ name = "customLink"
237
+ control = { control }
238
+ render = { ( { field } ) => (
239
+ < TextInput
240
+ { ...field }
241
+ placeholder = "https://example.com or leave empty for preset link"
242
+ type = "url"
243
+ />
244
+ ) }
245
+ />
246
+ </ div >
247
+ </ >
248
+ ) }
249
+ { formValues . presetPanelType === PresetPanelType . ALERT_TABLE && (
250
+ < >
251
+ < div className = "mb-4 mt-2" >
252
+ < Subtitle > Last alerts count to display</ Subtitle >
253
+ < Controller
254
+ name = "countOfLastAlerts"
255
+ control = { control }
256
+ rules = { {
257
+ required : {
258
+ value : true ,
259
+ message : "Preset selection is required" ,
260
+ } ,
261
+ } }
262
+ render = { ( { field } ) => (
263
+ < TextInput
173
264
{ ...field }
174
265
error = { ! ! get ( errors , "countOfLastAlerts.message" ) }
175
266
errorMessage = { get ( errors , "countOfLastAlerts.message" ) }
@@ -185,6 +276,8 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
185
276
selectedColumns = { presetColumns }
186
277
onChange = { ( selectedColumns ) => setPresetColumns ( selectedColumns ) }
187
278
> </ ColumnsSelection >
279
+ </ >
280
+ ) }
188
281
< div className = "mb-4" >
189
282
< div className = "flex items-center justify-between" >
190
283
< Subtitle > Thresholds</ Subtitle >
0 commit comments