mirror of
https://github.com/supabase/supabase.git
synced 2026-10-19 08:09:11 +03:00
* chore: cleanup packages - Avoid circular imports - Export API-types as types - pg-format without depending on Node internal Buffer (not browser-compatible) - Avoid importing from barrel files in ui dir * chore: avoid barrel file imports in studio (#27771) * chore: avoid barrel file imports - Removes some unused imports - Avoids barrel file import for faster builds + less memory * add eslint rule * type fixes * delete layouts barrel * delete components/grid barrel file * delete components/grid/utils barrel file * delete components/grid/components/common barrel file * delete components/grid/components/editor barrel file * delete components/grid/components/formatter barrel file * delete components/grid/components/grid barrel file * delete components/grid/components/header/filter barrel file * remote components/grid/store barrel file * remove components/interfaces/Auth/Policies barrel file * delete components/interfaces/Settings/Logs barrel file * delete components/ui/CodeEditor barrel file * delete components/ui/Forms barrel file * delete components/ui/Shimmers barrel file * delete data/analytics barrel file * delete hooks barrel file * cleanup lib/common/fetch barrel file * final * barral files cleanup * global react-data-grid styles * remove console.log --------- Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com> * fix build --------- Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
119 lines
3.8 KiB
TypeScript
119 lines
3.8 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { ChevronDown } from 'lucide-react'
|
|
|
|
import { useParams } from 'common'
|
|
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
|
|
import { useAuthConfigQuery } from 'data/auth/auth-config-query'
|
|
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
|
|
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from 'ui'
|
|
import { HOOKS_DEFINITIONS, HOOK_DEFINITION_TITLE, Hook } from './hooks.constants'
|
|
import { extractMethod, isValidHook } from './hooks.utils'
|
|
|
|
interface AddHookDropdownProps {
|
|
buttonText?: string
|
|
onSelectHook: (hook: HOOK_DEFINITION_TITLE) => void
|
|
}
|
|
|
|
export const AddHookDropdown = ({
|
|
buttonText = 'Add hook',
|
|
onSelectHook,
|
|
}: AddHookDropdownProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const organization = useSelectedOrganization()
|
|
|
|
const { data: subscription } = useOrgSubscriptionQuery(
|
|
{ orgSlug: organization?.slug },
|
|
{ enabled: IS_PLATFORM }
|
|
)
|
|
const { data: authConfig } = useAuthConfigQuery({ projectRef })
|
|
const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')
|
|
|
|
const hooks: Hook[] = HOOKS_DEFINITIONS.map((definition) => {
|
|
return {
|
|
...definition,
|
|
enabled: authConfig?.[definition.enabledKey] || false,
|
|
method: extractMethod(
|
|
authConfig?.[definition.uriKey] || '',
|
|
authConfig?.[definition.secretsKey] || ''
|
|
),
|
|
}
|
|
})
|
|
|
|
const nonEnterpriseHookOptions = hooks.filter((h) => !isValidHook(h) && !h.enterprise)
|
|
const enterpriseHookOptions = hooks.filter((h) => !isValidHook(h) && h.enterprise)
|
|
|
|
if (!canUpdateConfig) {
|
|
return (
|
|
<ButtonTooltip
|
|
disabled
|
|
type="primary"
|
|
tooltip={{
|
|
content: { side: 'bottom', text: 'You need additional permissions to add auth hooks' },
|
|
}}
|
|
>
|
|
{buttonText}
|
|
</ButtonTooltip>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<DropdownMenu modal={false}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button type="primary" iconRight={<ChevronDown className="w-4 h-4" strokeWidth={1} />}>
|
|
{buttonText}
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent className="w-76 p-0" align="end">
|
|
<div className="p-1">
|
|
{nonEnterpriseHookOptions.map((h) => (
|
|
<DropdownMenuItem key={h.title} onClick={() => onSelectHook(h.title)}>
|
|
{h.title}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</div>
|
|
{nonEnterpriseHookOptions.length > 0 && <DropdownMenuSeparator />}
|
|
|
|
<div className="bg-surface-200 p-1 -mt-2">
|
|
{subscription?.plan.id !== 'enterprise' && (
|
|
<DropdownMenuLabel className="grid gap-1 bg-surface-200">
|
|
<p className="text-foreground-light">Enterprise plan required</p>
|
|
<p className="text-foreground-lighter text-xs">
|
|
The following hooks are not available on{' '}
|
|
<a
|
|
target="_href"
|
|
href="https://forms.supabase.com/enterprise"
|
|
className="underline"
|
|
>
|
|
your plan
|
|
</a>
|
|
.
|
|
</p>
|
|
</DropdownMenuLabel>
|
|
)}
|
|
{enterpriseHookOptions.map((h) => (
|
|
<DropdownMenuItem
|
|
key={h.title}
|
|
disabled={true}
|
|
className="cursor-not-allowed"
|
|
onClick={() => onSelectHook(h.title)}
|
|
>
|
|
{h.title}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</div>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|