@@ -4,16 +4,13 @@ import { usePresetAlertsCount } from "@/features/presets/custom-preset-links";
4
4
import { useDashboardPreset } from "@/utils/hooks/useDashboardPresets" ;
5
5
import { Button , Icon } from "@tremor/react" ;
6
6
import { FireIcon } from "@heroicons/react/24/outline" ;
7
- import { DynamicImageProviderIcon } from "@/components/ui" ;
8
- import { getStatusColor , getStatusIcon } from "@/shared/lib/status-utils" ;
9
- import { SeverityBorderIcon , UISeverity } from "@/shared/ui" ;
10
- import { severityMapping } from "@/entities/alerts/model" ;
11
7
import * as Tooltip from "@radix-ui/react-tooltip" ;
12
8
import Skeleton from "react-loading-skeleton" ;
13
9
import "react-loading-skeleton/dist/skeleton.css" ;
14
10
import { useRouter } from "next/navigation" ;
15
11
import TimeAgo from "react-timeago" ;
16
12
import { useSearchParams } from "next/navigation" ;
13
+ import WidgetAlertsTable from "./widget-alerts-table" ;
17
14
18
15
interface GridItemProps {
19
16
item : WidgetData ;
@@ -43,6 +40,7 @@ const PresetGridItem: React.FC<GridItemProps> = ({ item }) => {
43
40
( ) => [ timeRangeCel , presetCel ] . filter ( Boolean ) . join ( " && " ) ,
44
41
[ presetCel , timeRangeCel ]
45
42
) ;
43
+
46
44
const {
47
45
alerts,
48
46
totalCount : presetAlertsCount ,
@@ -98,82 +96,6 @@ const PresetGridItem: React.FC<GridItemProps> = ({ item }) => {
98
96
return `rgb(${ r } , ${ g } , ${ b } , ${ alpha } )` ;
99
97
}
100
98
101
- function renderLastAlertsGrid ( ) {
102
- if ( isLoading ) {
103
- return (
104
- < >
105
- { Array . from ( { length : countOfLastAlerts } ) . map ( ( _ , index ) => (
106
- < div
107
- key = { index }
108
- className = "flex flex-row min-h-7 h-7 items-center gap-2"
109
- >
110
- < Skeleton containerClassName = "h-4 w-1" />
111
- < Skeleton containerClassName = "h-4 w-4" />
112
- < Skeleton containerClassName = "h-4 w-4" />
113
- < Skeleton containerClassName = "h-4 flex-1" />
114
- < Skeleton containerClassName = "h-4 flex-1" />
115
- </ div >
116
- ) ) }
117
- </ >
118
- ) ;
119
- }
120
-
121
- if ( presetAlertsCount === 0 ) {
122
- let emptyStateText = "No alerts matching this preset" ;
123
-
124
- if ( timeRangeCel ) {
125
- emptyStateText = "No alerts matching this preset and time range" ;
126
- }
127
-
128
- return (
129
- < div className = "flex items-center justify-center h-10" >
130
- { emptyStateText }
131
- </ div >
132
- ) ;
133
- }
134
-
135
- return (
136
- < >
137
- { alerts ?. map ( ( alert ) => (
138
- < div
139
- key = { alert . fingerprint }
140
- className = "flex flex-row min-h-7 h-7 items-center gap-2"
141
- >
142
- < SeverityBorderIcon
143
- severity = {
144
- ( severityMapping [ Number ( alert . severity ) ] ||
145
- alert . severity ) as UISeverity
146
- }
147
- />
148
- < Icon
149
- icon = { getStatusIcon ( alert . status ) }
150
- size = "sm"
151
- color = { getStatusColor ( alert . status ) }
152
- className = "!p-0"
153
- />
154
- < div >
155
- < DynamicImageProviderIcon
156
- className = "inline-block"
157
- alt = { ( alert as any ) . providerType }
158
- height = { 16 }
159
- width = { 16 }
160
- title = { ( alert as any ) . providerType }
161
- providerType = { ( alert as any ) . providerType }
162
- src = { `/icons/${ ( alert as any ) . providerType } -icon.png` }
163
- />
164
- </ div >
165
- < div className = "flex-1 truncate text-xs" title = { alert . name } >
166
- { alert . name } (< TimeAgo date = { alert . lastReceived } /> )
167
- </ div >
168
- < div className = "flex-1 truncate text-xs" title = { alert . description } >
169
- { alert . description }
170
- </ div >
171
- </ div >
172
- ) ) }
173
- </ >
174
- ) ;
175
- }
176
-
177
99
function renderCEL ( ) {
178
100
if ( ! presetCel ) {
179
101
return ;
@@ -279,14 +201,12 @@ const PresetGridItem: React.FC<GridItemProps> = ({ item }) => {
279
201
</ div >
280
202
</ div >
281
203
{ countOfLastAlerts > 0 && (
282
- < div
283
- style = { {
284
- background : isLoading ? undefined : hexToRgb ( getColor ( ) , 0.1 ) ,
285
- } }
286
- className = "bg-opacity-25 flex flex-col overflow-y-auto overflow-x-hidden auto-rows-auto border rounded-md p-2"
287
- >
288
- { renderLastAlertsGrid ( ) }
289
- </ div >
204
+ < WidgetAlertsTable
205
+ presetName = { preset ?. name as string }
206
+ alerts = { isLoading ? undefined : alerts }
207
+ columns = { ( item as any ) ?. presetColumns }
208
+ background = { isLoading ? undefined : hexToRgb ( getColor ( ) , 0.1 ) }
209
+ />
290
210
) }
291
211
</ div >
292
212
) ;
0 commit comments