mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
## Problem Our `<Button>` component breaks the default `button` contract by redefining the `type` prop to set its variant (`primary`, `default`, etc) instead of the button type (`submit`, `button`, etc). This is confusing and forces to write more code when using it with shadcn components that expect/inject the standard button props. ## Solution - rename the `type` prop to `variant` - rename the `htmlType` prop to `type` - propagate the changes where necessary - format code ## How to test As this is just prop renaming, if it builds it's ok --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
110 lines
3.6 KiB
TypeScript
110 lines
3.6 KiB
TypeScript
import { useParams } from 'common'
|
|
import { ExternalLink, Eye, EyeOff, Loader } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useState } from 'react'
|
|
import { Button, CardContent, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
import { Input } from 'ui-patterns/DataInputs/Input'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
|
|
import { useVaultSecretDecryptedValueQuery } from '@/data/vault/vault-secret-decrypted-value-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
export const DecryptedReadOnlyInput = ({
|
|
value,
|
|
secureEntry,
|
|
descriptionText,
|
|
label,
|
|
}: {
|
|
value?: string
|
|
secureEntry: boolean
|
|
descriptionText: string
|
|
label: string
|
|
}) => {
|
|
const { ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const [showHidden, setShowHidden] = useState(false)
|
|
|
|
const { data: decryptedValue, isPending: isDecryptedValueLoading } =
|
|
useVaultSecretDecryptedValueQuery(
|
|
{
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
id: value ?? '',
|
|
},
|
|
{ enabled: secureEntry && showHidden }
|
|
)
|
|
|
|
const isLoading = isDecryptedValueLoading && showHidden
|
|
const renderedValue = secureEntry
|
|
? isLoading
|
|
? 'Fetching value from Vault...'
|
|
: showHidden
|
|
? decryptedValue
|
|
: value
|
|
: value
|
|
|
|
return (
|
|
<CardContent className="py-6 border-b border-panel-border-interior-light">
|
|
<FormItemLayout
|
|
layout="horizontal"
|
|
label={
|
|
<div className="flex items-center gap-x-2">
|
|
<span>{label}</span>
|
|
{secureEntry && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Link
|
|
target="_blank"
|
|
rel="noreferrer noopener"
|
|
href={`/project/${ref}/integrations/vault/secrets?search=${value}`}
|
|
>
|
|
<ExternalLink
|
|
size={14}
|
|
className="text-foreground-lighter hover:text-foreground transition"
|
|
/>
|
|
</Link>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">Open in Vault</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
}
|
|
description={descriptionText}
|
|
isReactForm={false}
|
|
>
|
|
<Input
|
|
readOnly
|
|
// If the value is secure, allow copying to clipboard if the value is revealed. Otherwise, always allow copying
|
|
copy={!secureEntry || (!isDecryptedValueLoading && showHidden)}
|
|
value={renderedValue}
|
|
type={secureEntry ? (isLoading ? 'text' : showHidden ? 'text' : 'password') : 'text'}
|
|
actions={
|
|
secureEntry ? (
|
|
isLoading ? (
|
|
<div className="flex items-center justify-center">
|
|
<Button
|
|
disabled
|
|
variant="default"
|
|
className="w-7"
|
|
icon={<Loader className="animate-spin" />}
|
|
/>
|
|
</div>
|
|
) : (
|
|
<div className="flex items-center justify-center">
|
|
<Button
|
|
variant="default"
|
|
className="w-7"
|
|
loading={showHidden && isDecryptedValueLoading}
|
|
icon={showHidden ? <Eye /> : <EyeOff />}
|
|
onClick={() => setShowHidden(!showHidden)}
|
|
/>
|
|
</div>
|
|
)
|
|
) : null
|
|
}
|
|
/>
|
|
</FormItemLayout>
|
|
</CardContent>
|
|
)
|
|
}
|