mirror of
https://github.com/supabase/supabase.git
synced 2026-06-20 22:06:04 +08:00
* Improve layout and truncation in SigningKeyRow Added flex and truncation classes to ensure status labels and key IDs are properly truncated and aligned. This enhances the table's appearance and prevents overflow issues for long text. * Improve icon layout and badge styling in UI components Added flex-shrink-0 to icons in AlgorithmHoverCard for better alignment. Updated InfoPill to use min-w-0, overflow-hidden, and improved badge and label layout for consistent appearance and handling of long content. * Remove unused cn import from InfoPill component The cn utility import was removed from InfoPill.tsx as it is no longer used. The Badge component now uses a direct className string instead. * Update JWT key table columns and add rotation info Removed the 'Key ID' column and added a 'Last rotated at' column to the JWT secret keys table. The signing key row now displays the relative time since the key was last updated for previously used keys. * Add Key ID column to JWT secret keys table Introduces a new 'Key ID' column to the JWTSecretKeysTable component for improved visibility and management of JWT secret keys. * Improve JWT key table UI and add tooltip to key ID Updated the JWT secret keys table to enhance the empty state with an icon and explanatory text, and adjusted column alignment and visibility for 'Last rotated at'. Added a tooltip to the key ID for better accessibility and ensured the 'Last rotated at' column displays for both previously used and revoked keys. * Improve API key table layout and responsiveness API key name and description are now grouped together, with description shown under the name. The last seen column is hidden on smaller screens and displays 'Never used' when appropriate. ApiKeyPill max width is now responsive to screen size. The description column was removed from SecretAPIKeys to streamline the table. * Adjust API key pill and input sizing for responsiveness Reduced max-widths for ApiKeyPill and updated PublishableAPIKeys layout to improve responsiveness. ApiKeyInput now uses dynamic min/max widths for better display across breakpoints. * Adjust lg breakpoint min-width for API key input Changed the lg:min-w value from 40rem to 24rem for the API key input field to improve layout responsiveness at large screen sizes. * Update PublishableAPIKeys.tsx * Remove unused file * Minor refactors --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
135 lines
4.6 KiB
TypeScript
135 lines
4.6 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useMemo } from 'react'
|
|
|
|
import { InputVariants } from '@ui/components/shadcn/ui/input'
|
|
import { useParams } from 'common'
|
|
import CopyButton from 'components/ui/CopyButton'
|
|
import { FormHeader } from 'components/ui/Forms/FormHeader'
|
|
import { useAPIKeysQuery } from 'data/api-keys/api-keys-query'
|
|
import { useCheckPermissions, usePermissionsLoaded } from 'hooks/misc/useCheckPermissions'
|
|
import { cn, EyeOffIcon, Input_Shadcn_, Skeleton, WarningIcon } from 'ui'
|
|
|
|
// to add in later with follow up PR
|
|
// import CreatePublishableAPIKeyDialog from './CreatePublishableAPIKeyDialog'
|
|
// to add in later with follow up PR
|
|
// import ShowPublicJWTsDialogComposer from '../JwtSecrets/ShowPublicJWTsDialogComposer'
|
|
|
|
export const PublishableAPIKeys = () => {
|
|
const { ref: projectRef } = useParams()
|
|
const {
|
|
data: apiKeysData,
|
|
isLoading: isLoadingApiKeys,
|
|
error,
|
|
} = useAPIKeysQuery({ projectRef, reveal: false })
|
|
|
|
const publishableApiKeys = useMemo(
|
|
() => apiKeysData?.filter(({ type }) => type === 'publishable') ?? [],
|
|
[apiKeysData]
|
|
)
|
|
|
|
const isPermissionsLoading = !usePermissionsLoaded()
|
|
const canReadAPIKeys = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, '*')
|
|
|
|
// The default publisahble key will always be the first one
|
|
const apiKey = publishableApiKeys[0]
|
|
|
|
return (
|
|
<div>
|
|
<FormHeader
|
|
title="Publishable key"
|
|
description="This key is safe to use in a browser if you have enabled Row Level Security (RLS) for your tables and configured policies."
|
|
/>
|
|
<div className="flex flex-col gap-8">
|
|
<div className="-space-y-px w-full lg:w-content lg:w-fit">
|
|
<div className="bg-surface-100 px-5 py-2 flex items-center gap-5 first:rounded-t-md border">
|
|
<span className="text-sm">Publishable key</span>
|
|
<div className="flex items-center gap-2">
|
|
<ApiKeyInput />
|
|
<CopyButton
|
|
disabled={isPermissionsLoading || isLoadingApiKeys || !canReadAPIKeys}
|
|
type="default"
|
|
text={apiKey?.api_key}
|
|
iconOnly
|
|
size={'tiny'}
|
|
className="px-2 rounded-full"
|
|
/>
|
|
</div>
|
|
</div>
|
|
{error && canReadAPIKeys ? (
|
|
<div className="text-xs bg-warning-200 last:rounded-b-md border border-warning-400 px-5 text-foreground-lighter py-1">
|
|
<div className="text-warning">Failed to load publishable key: {error?.message}</div>
|
|
</div>
|
|
) : (
|
|
<div className="text-xs bg-200 last:rounded-b-md border px-5 text-foreground-lighter py-1">
|
|
The publishable key can be safely shared publicly
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="flex flex-col gap-2 max-w-64">
|
|
{/* <Separator /> */}
|
|
{/* @mildtomato - To add in later with follow up PR */}
|
|
{/* <ShowPublicJWTsDialogComposer /> */}
|
|
</div>
|
|
|
|
{/* <CreatePublishableAPIKeyModal /> */}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function ApiKeyInput() {
|
|
const { ref: projectRef } = useParams()
|
|
const {
|
|
data: apiKeysData,
|
|
isLoading: isApiKeysLoading,
|
|
error,
|
|
} = useAPIKeysQuery({ projectRef, reveal: false })
|
|
const publishableApiKeys = useMemo(
|
|
() => apiKeysData?.filter(({ type }) => type === 'publishable') ?? [],
|
|
[apiKeysData]
|
|
)
|
|
const isPermissionsLoading = !usePermissionsLoaded()
|
|
const canReadAPIKeys = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, '*')
|
|
// The default publisahble key will always be the first one
|
|
const apiKey = publishableApiKeys[0]
|
|
|
|
const baseClasses =
|
|
'flex-1 grow gap-1 rounded-full min-w-0 max-w-[200px] sm:max-w-[300px] md:max-w-[400px] lg:min-w-[24rem]'
|
|
const size = 'tiny'
|
|
|
|
if (isApiKeysLoading || isPermissionsLoading) {
|
|
return (
|
|
<div className={cn(InputVariants({ size }), baseClasses, 'items-center')}>
|
|
<Skeleton className="h-2 w-48 rounded-full bg-foreground-muted" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!canReadAPIKeys) {
|
|
return (
|
|
<div className={cn(InputVariants({ size }), baseClasses, 'items-center gap-2 font-normal')}>
|
|
<EyeOffIcon />
|
|
You do not have permission to read API Key
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (error) {
|
|
return (
|
|
<div className={cn(InputVariants({ size }), baseClasses, 'items-center gap-2 font-normal')}>
|
|
<WarningIcon />
|
|
Failed to load publishable key
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Input_Shadcn_
|
|
key={apiKey?.id}
|
|
size={size}
|
|
className={cn(baseClasses, 'font-mono')}
|
|
value={apiKey?.api_key}
|
|
/>
|
|
)
|
|
}
|