From e0febdadcb5bdcbf35d80346497bb60de9f5786e Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Wed, 10 Dec 2025 17:20:49 +0800 Subject: [PATCH] Change flag for API keys last used (#41221) --- .../components/interfaces/APIKeys/APIKeyRow.tsx | 7 +++---- .../interfaces/APIKeys/SecretAPIKeys.tsx | 17 +++++++---------- .../ui/ProjectSettings/DisplayApiSettings.tsx | 16 ++++++++-------- .../ProjectSettings/DisplayApiSettings.utils.ts | 8 +++++++- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/apps/studio/components/interfaces/APIKeys/APIKeyRow.tsx b/apps/studio/components/interfaces/APIKeys/APIKeyRow.tsx index c9474f31b42..fc5a0e3847c 100644 --- a/apps/studio/components/interfaces/APIKeys/APIKeyRow.tsx +++ b/apps/studio/components/interfaces/APIKeys/APIKeyRow.tsx @@ -1,6 +1,7 @@ import { motion } from 'framer-motion' import { MoreVertical } from 'lucide-react' +import { useFlag } from 'common' import { TextConfirmModal } from 'components/ui/TextConfirmModalWrapper' import type { APIKeysData } from 'data/api-keys/api-keys-query' import { @@ -14,7 +15,6 @@ import { import { ShimmeringLoader, TimestampInfo } from 'ui-patterns' import { APIKeyDeleteDialog } from './APIKeyDeleteDialog' import { ApiKeyPill } from './ApiKeyPill' -import { useFlag } from 'common' export const APIKeyRow = ({ apiKey, @@ -34,8 +34,7 @@ export const APIKeyRow = ({ setKeyToDelete: (id: string | null) => void }) => { const MotionTableRow = motion.create(TableRow) - - const hideApiKeyLastUsed = useFlag('HideApiKeyLastUsed') + const showApiKeysLastUsed = useFlag('showApiKeysLastUsed') return ( <> @@ -65,7 +64,7 @@ export const APIKeyRow = ({ - {!hideApiKeyLastUsed && ( + {showApiKeysLastUsed && (
{isLoadingLastSeen ? ( diff --git a/apps/studio/components/interfaces/APIKeys/SecretAPIKeys.tsx b/apps/studio/components/interfaces/APIKeys/SecretAPIKeys.tsx index 5027f6c31bd..d4912561a0c 100644 --- a/apps/studio/components/interfaces/APIKeys/SecretAPIKeys.tsx +++ b/apps/studio/components/interfaces/APIKeys/SecretAPIKeys.tsx @@ -27,10 +27,7 @@ interface LastSeenData { [hash: string]: { timestamp: number; relative: string } } -function useLastSeen( - projectRef: string, - enabled?: boolean -): { +function useLastSeen({ projectRef, enabled }: { projectRef: string; enabled?: boolean }): { data?: LastSeenData isLoading: boolean } { @@ -79,11 +76,11 @@ export const SecretAPIKeys = () => { isError: isErrorApiKeys, } = useAPIKeysQuery({ projectRef, reveal: false }, { enabled: canReadAPIKeys }) - const hideApiKeyLastUsed = useFlag('HideApiKeyLastUsed') ?? true - const { data: lastSeen, isLoading: isLoadingLastSeen } = useLastSeen( - projectRef ?? '', - !hideApiKeyLastUsed - ) + const showApiKeysLastUsed = useFlag('showApiKeysLastUsed') + const { data: lastSeen, isLoading: isLoadingLastSeen } = useLastSeen({ + projectRef: projectRef ?? '', + enabled: showApiKeysLastUsed, + }) const secretApiKeys = useMemo( () => @@ -164,7 +161,7 @@ export const SecretAPIKeys = () => { Name API Key - {!hideApiKeyLastUsed && ( + {showApiKeysLastUsed && ( Last Used )} diff --git a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx index 4c90a5b8342..01fa1bb35c2 100644 --- a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx +++ b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx @@ -51,18 +51,18 @@ export const DisplayApiSettings = ({ // api keys should not be empty. However it can be populated with a delay on project creation const isApiKeysEmpty = apiKeys.length === 0 - const hideApiKeyLastUsed = useFlag('HideApiKeyLastUsed') ?? true - const { isLoading: isLoadingLastUsed, logData: lastUsedLogData } = useLastUsedAPIKeysLogQuery( - projectRef!, - !hideApiKeyLastUsed - ) + const showApiKeyLastUsed = useFlag('showApiKeysLastUsed') + const { isLoading: isLoadingLastUsed, logData: lastUsedLogData } = useLastUsedAPIKeysLogQuery({ + projectRef: projectRef ?? '', + enabled: showApiKeyLastUsed, + }) const lastUsedAPIKeys = useMemo(() => { if ( apiKeys.length < 1 || !lastUsedLogData || lastUsedLogData.length < 1 || - hideApiKeyLastUsed + !showApiKeyLastUsed ) { return {} } @@ -74,7 +74,7 @@ export const DisplayApiSettings = ({ console.error(e) return {} } - }, [lastUsedLogData, apiKeys, hideApiKeyLastUsed]) + }, [lastUsedLogData, apiKeys, showApiKeyLastUsed]) return ( - {!hideApiKeyLastUsed && ( + {showApiKeyLastUsed && (