mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 03:45: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>
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { Copy } from 'lucide-react'
|
|
import { useCallback, useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { Button, copyToClipboard } from 'ui'
|
|
|
|
import { getDecryptedValue } from '@/data/vault/vault-secret-decrypted-value-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
export const CopyEnvButton = ({
|
|
serverOptions,
|
|
values,
|
|
}: {
|
|
serverOptions: { name: string; secureEntry: boolean }[]
|
|
values: Record<string, string>
|
|
}) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
|
|
const onCopy = useCallback(async () => {
|
|
setIsLoading(true)
|
|
const envFile = Promise.all(
|
|
serverOptions.map(async (option) => {
|
|
if (option.secureEntry) {
|
|
const decryptedValue = await getDecryptedValue({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
id: values[option.name],
|
|
})
|
|
return `${option.name.toUpperCase().replace('VAULT_', '')}=${decryptedValue[0].decrypted_secret}`
|
|
}
|
|
return `${option.name.toUpperCase().replace('.', '_')}=${values[option.name]}`
|
|
})
|
|
).then((values) => values.join('\n'))
|
|
|
|
copyToClipboard(envFile, () => {
|
|
toast.success('Copied to clipboard as environment variables')
|
|
setIsLoading(false)
|
|
})
|
|
}, [serverOptions, values])
|
|
|
|
return (
|
|
<Button variant="default" loading={isLoading} icon={<Copy />} onClick={onCopy}>
|
|
Copy all
|
|
</Button>
|
|
)
|
|
}
|