6
6
Table ,
7
7
TableBody ,
8
8
TableHeader ,
9
- Badge ,
10
9
Button ,
11
10
ResizableTableContainer ,
12
11
Link ,
@@ -20,15 +19,14 @@ import {
20
19
parsingPromptText ,
21
20
getIssueDetectedType ,
22
21
} from "@/lib/utils" ;
23
- import { useAlertSearch } from "@/hooks/useAlertSearch" ;
24
22
import { useNavigate } from "react-router-dom" ;
25
23
import { useClientSidePagination } from "@/hooks/useClientSidePagination" ;
26
24
import { TableAlertTokenUsage } from "./table-alert-token-usage" ;
27
- import { Key01 , LinkExternal02 , PackageX } from "@untitled-ui/icons-react" ;
28
- import { useListWorkspaces } from "@/features/workspace/hooks/use-list-workspaces" ;
29
- import { SearchFieldAlerts } from "./search-field-alerts" ;
30
- import { SwitchMaliciousAlertsFilter } from "./switch-malicious-alerts-filter" ;
25
+
31
26
import { useQueryGetWorkspaceAlertTable } from "../hooks/use-query-get-workspace-alerts-table" ;
27
+ import { useAlertsFilterSearchParams } from "../hooks/use-alerts-filter-search-params" ;
28
+ import { useListWorkspaces } from "@/features/workspace/hooks/use-list-workspaces" ;
29
+ import { Key01 , LinkExternal02 , PackageX } from "@untitled-ui/icons-react" ;
32
30
33
31
const getTitle = ( alert : AlertConversation ) => {
34
32
const prompt = alert . conversation ;
@@ -150,10 +148,12 @@ function EmptyState({
150
148
}
151
149
152
150
export function TableAlerts ( ) {
153
- const { page, nextPage, prevPage } = useAlertSearch ( ) ;
154
151
const navigate = useNavigate ( ) ;
152
+ const { state, prevPage, nextPage } = useAlertsFilterSearchParams ( ) ;
153
+
155
154
const { data : filteredAlerts = [ ] , isLoading : isLoadingAlerts } =
156
155
useQueryGetWorkspaceAlertTable ( ) ;
156
+
157
157
const {
158
158
data : { workspaces } = { workspaces : [ ] } ,
159
159
isLoading : isLoadingWorkspaces ,
@@ -163,86 +163,71 @@ export function TableAlerts() {
163
163
164
164
const { dataView, hasNextPage, hasPreviousPage } = useClientSidePagination (
165
165
filteredAlerts ,
166
- page ,
166
+ state . page ,
167
167
15 ,
168
168
) ;
169
169
170
170
return (
171
171
< >
172
- < div className = "flex mb-2 mx-2 justify-between w-[calc(100vw-20rem)]" >
173
- < div className = "flex gap-2 items-center" >
174
- < h2 className = "font-bold text-lg" > All Alerts</ h2 >
175
- < Badge size = "sm" variant = "inverted" data-testid = "alerts-count" >
176
- { filteredAlerts . length }
177
- </ Badge >
178
- </ div >
179
-
180
- < div className = "flex items-center gap-8" >
181
- < SwitchMaliciousAlertsFilter />
182
- < SearchFieldAlerts />
183
- </ div >
184
- </ div >
185
- < div className = "overflow-x-auto" >
186
- < ResizableTableContainer >
187
- < Table data-testid = "alerts-table" aria-label = "Alerts table" >
188
- < TableHeader >
189
- < Row >
190
- < Column isRowHeader width = { 150 } >
191
- Time
192
- </ Column >
193
- < Column width = { 150 } > Type</ Column >
194
- < Column > Event</ Column >
195
- < Column width = { 325 } > Issue Detected</ Column >
196
- < Column width = { 200 } > Token usage</ Column >
197
- </ Row >
198
- </ TableHeader >
199
- < TableBody
200
- renderEmptyState = { ( ) =>
201
- isLoading ? (
202
- < div > Loading alerts</ div >
203
- ) : (
204
- < EmptyState hasMultipleWorkspaces = { workspaces . length > 1 } />
205
- )
206
- }
207
- >
208
- { dataView . map ( ( alert ) => {
209
- return (
210
- < Row
211
- key = { alert . alert_id }
212
- className = "h-20"
213
- onAction = { ( ) =>
214
- navigate ( `/prompt/${ alert . conversation . chat_id } ` )
215
- }
216
- >
217
- < Cell className = "truncate" >
218
- { formatDistanceToNow ( new Date ( alert . timestamp ) , {
219
- addSuffix : true ,
220
- } ) }
221
- </ Cell >
222
- < Cell className = "truncate" >
223
- < TypeCellContent alert = { alert } />
224
- </ Cell >
225
- < Cell className = "truncate" > { getTitle ( alert ) } </ Cell >
226
- < Cell >
227
- < div className = "truncate flex gap-2 items-center" >
228
- < IssueDetectedCellContent alert = { alert } />
229
- </ div >
230
- </ Cell >
231
- < Cell >
232
- < TableAlertTokenUsage
233
- usage = { alert . conversation . token_usage_agg }
234
- />
235
- </ Cell >
236
- </ Row >
237
- ) ;
238
- } ) }
239
- </ TableBody >
240
- </ Table >
241
- </ ResizableTableContainer >
242
- </ div >
172
+ < ResizableTableContainer >
173
+ < Table data-testid = "alerts-table" aria-label = "Alerts table" >
174
+ < TableHeader >
175
+ < Row >
176
+ < Column isRowHeader width = { 150 } >
177
+ Time
178
+ </ Column >
179
+ < Column width = { 150 } > Type</ Column >
180
+ < Column > Event</ Column >
181
+ < Column width = { 325 } > Issue Detected</ Column >
182
+ < Column width = { 200 } > Token usage</ Column >
183
+ </ Row >
184
+ </ TableHeader >
185
+ < TableBody
186
+ renderEmptyState = { ( ) =>
187
+ isLoading ? (
188
+ < div > Loading alerts</ div >
189
+ ) : (
190
+ < EmptyState hasMultipleWorkspaces = { workspaces . length > 1 } />
191
+ )
192
+ }
193
+ >
194
+ { dataView . map ( ( alert ) => {
195
+ return (
196
+ < Row
197
+ key = { alert . alert_id }
198
+ className = "h-20"
199
+ onAction = { ( ) =>
200
+ navigate ( `/prompt/${ alert . conversation . chat_id } ` )
201
+ }
202
+ >
203
+ < Cell className = "truncate" >
204
+ { formatDistanceToNow ( new Date ( alert . timestamp ) , {
205
+ addSuffix : true ,
206
+ } ) }
207
+ </ Cell >
208
+ < Cell className = "truncate" >
209
+ < TypeCellContent alert = { alert } />
210
+ </ Cell >
211
+ < Cell className = "truncate" > { getTitle ( alert ) } </ Cell >
212
+ < Cell >
213
+ < div className = "truncate flex gap-2 items-center" >
214
+ < IssueDetectedCellContent alert = { alert } />
215
+ </ div >
216
+ </ Cell >
217
+ < Cell >
218
+ < TableAlertTokenUsage
219
+ usage = { alert . conversation . token_usage_agg }
220
+ />
221
+ </ Cell >
222
+ </ Row >
223
+ ) ;
224
+ } ) }
225
+ </ TableBody >
226
+ </ Table >
227
+ </ ResizableTableContainer >
243
228
244
229
< div className = "flex justify-center w-full p-4" >
245
- < div className = "flex gap-2" >
230
+ < div className = "grid grid-cols-2 gap-2" >
246
231
< Button isDisabled = { ! hasPreviousPage } onPress = { prevPage } >
247
232
Previous
248
233
</ Button >
0 commit comments