@@ -47,7 +47,7 @@ import { formatDate, formatDateTime, useObjectTranslation } from '@object-ui/i18
4747import { useAdapter , useDataInvalidation } from '@object-ui/react' ;
4848
4949/** The `sys_api_key` columns the list reads; the key's secret is never among them. */
50- export const API_KEY_LIST_FIELDS = [
50+ const API_KEY_LIST_FIELDS = [
5151 'id' ,
5252 'name' ,
5353 'prefix' ,
@@ -90,7 +90,7 @@ const SCOPE_KEYS: Record<string, string> = {
9090 'metadata:write' : 'oauth.consent.scope.metadataWrite' ,
9191} ;
9292
93- export function describeGrantedScope ( scope : string , t : Translate ) : string {
93+ function describeGrantedScope ( scope : string , t : Translate ) : string {
9494 const key = SCOPE_KEYS [ scope ] ;
9595 return key ? t ( key ) : t ( 'oauth.consent.scope.unrecognised' , { scope } ) ;
9696}
@@ -178,20 +178,22 @@ function AssistantRows({
178178
179179function KeyRows ( {
180180 keys,
181+ readAt,
181182 onRevoke,
182183} : {
183184 keys : ApiKeyRow [ ] ;
185+ /** When the rows were read: expiry is judged against the read, not against each render. */
186+ readAt : number ;
184187 onRevoke : ( row : ApiKeyRow ) => void ;
185188} ) {
186189 const { t, language } = useObjectTranslation ( ) ;
187190 if ( keys . length === 0 ) {
188191 return < p className = "text-sm text-muted-foreground" > { t ( 'connectAgent.access.keysEmpty' ) } </ p > ;
189192 }
190- const now = Date . now ( ) ;
191193 return (
192194 < ul className = "divide-y rounded-md border" >
193195 { keys . map ( ( k ) => {
194- const expired = isExpired ( k , now ) ;
196+ const expired = isExpired ( k , readAt ) ;
195197 return (
196198 < li key = { k . id } className = "flex items-start gap-3 px-3 py-2 text-sm" data-testid = "api-key-row" >
197199 < div className = "min-w-0 flex-1 space-y-1" >
@@ -246,7 +248,7 @@ export function AuthorizedAccessList() {
246248 const [ assistants , setAssistants ] = useState < Load < AuthorizedClientsList > > ( {
247249 state : 'loading' ,
248250 } ) ;
249- const [ keys , setKeys ] = useState < Load < ApiKeyRow [ ] > > ( { state : 'loading' } ) ;
251+ const [ keys , setKeys ] = useState < Load < { rows : ApiKeyRow [ ] ; readAt : number } > > ( { state : 'loading' } ) ;
250252 const [ confirmKey , setConfirmKey ] = useState < ApiKeyRow | null > ( null ) ;
251253 const [ revokingId , setRevokingId ] = useState < string | null > ( null ) ;
252254 const [ revokeError , setRevokeError ] = useState < string | null > ( null ) ;
@@ -260,7 +262,6 @@ export function AuthorizedAccessList() {
260262 useEffect ( ( ) => {
261263 if ( ! adapter || ! userId ) return ;
262264 let live = true ;
263- setAssistants ( { state : 'loading' } ) ;
264265 adapter
265266 . getClient ( )
266267 . oauth . authorizedClients . list ( )
@@ -283,7 +284,8 @@ export function AuthorizedAccessList() {
283284 $orderby : [ { field : 'created_at' , order : 'desc' } ] ,
284285 } )
285286 . then (
286- ( res ) => live && setKeys ( { state : 'ready' , value : ( res ?. data ?? [ ] ) as ApiKeyRow [ ] } ) ,
287+ ( res ) =>
288+ live && setKeys ( { state : 'ready' , value : { rows : ( res ?. data ?? [ ] ) as ApiKeyRow [ ] , readAt : Date . now ( ) } } ) ,
287289 ( e : unknown ) => live && setKeys ( { state : 'error' , message : errorText ( e ) } ) ,
288290 ) ;
289291 return ( ) => {
@@ -352,7 +354,7 @@ export function AuthorizedAccessList() {
352354 { t ( 'connectAgent.access.loadFailed' , { message : keys . message } ) }
353355 </ p >
354356 ) : (
355- < KeyRows keys = { keys . value } onRevoke = { setConfirmKey } />
357+ < KeyRows keys = { keys . value . rows } readAt = { keys . value . readAt } onRevoke = { setConfirmKey } />
356358 ) }
357359 { revokingId ? (
358360 < p className = "text-xs text-muted-foreground" > { t ( 'connectAgent.access.revoking' ) } </ p >
0 commit comments