77 SelectItem ,
88 Subtitle ,
99 TextInput ,
10+ Switch ,
1011} from "@tremor/react" ;
1112import { useEffect , useMemo , useState } from "react" ;
1213import {
@@ -16,13 +17,16 @@ import {
1617 useWatch ,
1718 useFieldArray ,
1819} from "react-hook-form" ;
19- import { LayoutItem , Threshold } from "../../types" ;
20+ import { LayoutItem , Threshold , PresetPanelType } from "../../types" ;
2021import ColumnsSelection from "./columns-selection" ;
2122
2223interface PresetForm {
2324 selectedPreset : string ;
2425 countOfLastAlerts : string ;
2526 thresholds : Threshold [ ] ;
27+ presetPanelType : PresetPanelType ;
28+ showFiringOnly : boolean ;
29+ customLink ?: string ;
2630}
2731
2832export interface PresetWidgetFormProps {
@@ -47,9 +51,12 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
4751 ? editingItem . preset . countOfLastAlerts || 0
4852 : 5 ,
4953 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
5256 ] ,
57+ presetPanelType : editingItem ?. presetPanelType || PresetPanelType . ALERT_TABLE ,
58+ showFiringOnly : editingItem ?. showFiringOnly ?? false ,
59+ customLink : editingItem ?. customLink || "" ,
5360 } ,
5461 } ) ;
5562 const [ presetColumns , setPresetColumns ] = useState < string [ ] | undefined > (
@@ -72,6 +79,9 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
7279 ...t ,
7380 value : parseInt ( t . value ?. toString ( ) as string , 10 ) || 0 ,
7481 } ) ) ,
82+ presetPanelType : formValues . presetPanelType || PresetPanelType . ALERT_TABLE ,
83+ showFiringOnly : formValues . showFiringOnly ?? false ,
84+ customLink : formValues . customLink || "" ,
7585 } ;
7686 } , [ formValues , presetColumns ] ) ;
7787
@@ -80,8 +90,23 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
8090 return { } as LayoutItem ;
8191 }
8292
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 ;
85110
86111 return {
87112 w : itemWidth ,
@@ -102,6 +127,9 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
102127 } ,
103128 presetColumns : normalizedFormValues . presetColumns ,
104129 thresholds : normalizedFormValues . thresholds ,
130+ presetPanelType : normalizedFormValues . presetPanelType ,
131+ showFiringOnly : normalizedFormValues . showFiringOnly ,
132+ customLink : normalizedFormValues . customLink ,
105133 } ,
106134 isValid
107135 ) ;
@@ -158,18 +186,81 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
158186 />
159187 </ div >
160188 < div className = "mb-4 mt-2" >
161- < Subtitle > Last alerts count to display </ Subtitle >
189+ < Subtitle > Panel Type </ Subtitle >
162190 < Controller
163- name = "countOfLastAlerts "
191+ name = "presetPanelType "
164192 control = { control }
165193 rules = { {
166194 required : {
167195 value : true ,
168- message : "Preset selection is required" ,
196+ message : "Panel type selection is required" ,
169197 } ,
170198 } }
171199 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
173264 { ...field }
174265 error = { ! ! get ( errors , "countOfLastAlerts.message" ) }
175266 errorMessage = { get ( errors , "countOfLastAlerts.message" ) }
@@ -185,6 +276,8 @@ export const PresetWidgetForm: React.FC<PresetWidgetFormProps> = ({
185276 selectedColumns = { presetColumns }
186277 onChange = { ( selectedColumns ) => setPresetColumns ( selectedColumns ) }
187278 > </ ColumnsSelection >
279+ </ >
280+ ) }
188281 < div className = "mb-4" >
189282 < div className = "flex items-center justify-between" >
190283 < Subtitle > Thresholds</ Subtitle >
0 commit comments