Files
supabase/apps/studio/components/interfaces/Advisors/DisableRuleModal.tsx
Gildas Garcia 96d43099bb chore: refactor Button API so that it can be used a standard button (#46880)
## 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>
2026-06-16 23:59:58 +02:00

91 lines
2.6 KiB
TypeScript

import { useParams } from 'common'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { toast } from 'sonner'
import {
Button,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
DialogTrigger,
} from 'ui'
import { LintInfo } from '../Linter/Linter.constants'
import { lintInfoMap } from '../Linter/Linter.utils'
import { useLintRuleCreateMutation } from '@/data/lint/create-lint-rule-mutation'
interface DisableRuleModalProps {
lint: LintInfo
}
export const DisableRuleModal = ({ lint }: DisableRuleModalProps) => {
const { ref } = useParams()
const router = useRouter()
const routeCategory = router.pathname.split('/').pop()
const [open, setOpen] = useState(false)
const { mutate: createRule, isPending: isCreating } = useLintRuleCreateMutation({
onSuccess: (_, vars) => {
const ruleLint = vars.exception.lint_name
const ruleLintMeta = lintInfoMap.find((x) => x.name === ruleLint)
toast.success(`Successfully disabled the "${ruleLintMeta?.title}" rule`)
if (ruleLintMeta) {
if (!!routeCategory && routeCategory !== ruleLintMeta.category) {
router.push(
`/project/${ref}/advisors/rules/${ruleLintMeta.category}?lint=${ruleLintMeta.name}`
)
}
}
setOpen(false)
},
})
const onCreateRule = () => {
if (!ref) return console.error('Project ref is required')
createRule({
projectRef: ref,
exception: {
is_disabled: true,
lint_category: undefined,
lint_name: lint.name,
assigned_to: undefined,
},
})
}
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button variant="default">Disable rule</Button>
</DialogTrigger>
<DialogContent size="small">
<DialogHeader>
<DialogTitle>Confirm to disable rule</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection>
<p className="text-sm">
This will silence the "{lint.title}" by hiding this rule in the Advisor reports, as well
omitting this rule from email notifications for this project.
</p>
</DialogSection>
<DialogFooter>
<Button disabled={isCreating} variant="default" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button loading={isCreating} variant="primary" onClick={onCreateRule}>
Disable
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}