@@ -23,6 +23,9 @@ import { AuditFilters } from "./audit-filters.tsx";
2323import { AuditTable } from "./audit-table.tsx" ;
2424
2525const CURSOR_PAGINATION_SEARCH_PARAM = "after" ;
26+ const AGENT_FILTER_SEARCH_PARAM = "agent" ;
27+ const USER_FILTER_SEARCH_PARAM = "user" ;
28+ const SORT_SEARCH_PARAM = "sort" ;
2629
2730type AuditOrderBy =
2831 | "createdAt_desc"
@@ -61,13 +64,19 @@ export function AuditListContent({
6164 columnsDenyList,
6265 filters,
6366} : AuditListContentProps ) {
67+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
6468 const [ selectedAgent , setSelectedAgent ] = useState < string | undefined > (
65- undefined ,
69+ filters ?. agentId ?? searchParams . get ( AGENT_FILTER_SEARCH_PARAM ) ??
70+ undefined ,
6671 ) ;
6772 const [ selectedUser , setSelectedUser ] = useState < string | undefined > (
68- undefined ,
73+ filters ?. resourceId ?? searchParams . get ( USER_FILTER_SEARCH_PARAM ) ??
74+ undefined ,
75+ ) ;
76+ const [ sort , setSort ] = useState < AuditOrderBy > (
77+ ( filters ?. orderBy ?? searchParams . get ( SORT_SEARCH_PARAM ) ??
78+ SORT_OPTIONS [ 0 ] . value ) as AuditOrderBy ,
6979 ) ;
70- const [ sort , setSort ] = useState < AuditOrderBy > ( SORT_OPTIONS [ 0 ] . value ) ;
7180 // Cursor-based pagination state
7281 const navigate = useNavigateWorkspace ( ) ;
7382
@@ -76,7 +85,6 @@ export function AuditListContent({
7685
7786 // Get teamId from teams and params
7887 const params = useParams ( ) ;
79- const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
8088 const getSafeCursor = ( cursor : string | null ) => {
8189 if ( ! cursor ) return ;
8290 try {
@@ -108,30 +116,62 @@ export function AuditListContent({
108116
109117 // Handlers
110118 function handleAgentChange ( value : string ) {
111- setSelectedAgent ( value === "all" ? undefined : value ) ;
112- setSearchParams ( { [ CURSOR_PAGINATION_SEARCH_PARAM ] : "" } ) ;
119+ const newAgentValue = value === "all" ? undefined : value ;
120+ setSelectedAgent ( newAgentValue ) ;
121+
122+ // Update URL params
123+ const newSearchParams = new URLSearchParams ( searchParams ) ;
124+ if ( newAgentValue ) {
125+ newSearchParams . set ( AGENT_FILTER_SEARCH_PARAM , newAgentValue ) ;
126+ } else {
127+ newSearchParams . delete ( AGENT_FILTER_SEARCH_PARAM ) ;
128+ }
129+ newSearchParams . delete ( CURSOR_PAGINATION_SEARCH_PARAM ) ; // Reset pagination
130+ setSearchParams ( newSearchParams ) ;
113131 }
132+
114133 function handleUserChange ( value : string ) {
115- setSelectedUser ( value === "all" ? undefined : value ) ;
134+ const newUserValue = value === "all" ? undefined : value ;
135+ setSelectedUser ( newUserValue ) ;
116136
117- setSearchParams ( { [ CURSOR_PAGINATION_SEARCH_PARAM ] : "" } ) ;
137+ // Update URL params
138+ const newSearchParams = new URLSearchParams ( searchParams ) ;
139+ if ( newUserValue ) {
140+ newSearchParams . set ( USER_FILTER_SEARCH_PARAM , newUserValue ) ;
141+ } else {
142+ newSearchParams . delete ( USER_FILTER_SEARCH_PARAM ) ;
143+ }
144+ newSearchParams . delete ( CURSOR_PAGINATION_SEARCH_PARAM ) ; // Reset pagination
145+ setSearchParams ( newSearchParams ) ;
118146 }
147+
119148 function handleSortChange ( newSort : string ) {
120149 setSort ( newSort as AuditOrderBy ) ;
121- setSearchParams ( { [ CURSOR_PAGINATION_SEARCH_PARAM ] : "" } ) ;
150+ const newSearchParams = new URLSearchParams ( searchParams ) ;
151+ newSearchParams . set ( SORT_SEARCH_PARAM , newSort ) ;
152+ newSearchParams . delete ( CURSOR_PAGINATION_SEARCH_PARAM ) ; // Reset pagination
153+ setSearchParams ( newSearchParams ) ;
122154 }
155+
123156 function handleNextPage ( ) {
124157 if ( pagination ?. hasMore && pagination ?. nextCursor ) {
125- setSearchParams ( {
126- [ CURSOR_PAGINATION_SEARCH_PARAM ] : pagination . nextCursor ,
127- } ) ;
158+ const newSearchParams = new URLSearchParams ( searchParams ) ;
159+ newSearchParams . set (
160+ CURSOR_PAGINATION_SEARCH_PARAM ,
161+ pagination . nextCursor ,
162+ ) ;
163+ setSearchParams ( newSearchParams ) ;
128164 }
129165 }
166+
130167 function handlePrevPage ( ) {
131168 if ( pagination ?. prevCursor ) {
132- setSearchParams ( {
133- [ CURSOR_PAGINATION_SEARCH_PARAM ] : pagination ?. prevCursor ,
134- } ) ;
169+ const newSearchParams = new URLSearchParams ( searchParams ) ;
170+ newSearchParams . set (
171+ CURSOR_PAGINATION_SEARCH_PARAM ,
172+ pagination ?. prevCursor ,
173+ ) ;
174+ setSearchParams ( newSearchParams ) ;
135175 }
136176 }
137177
0 commit comments