Skip to content

Commit 87667de

Browse files
authored
Small UI tweak to security issues dropdown (supabase#29605)
1 parent a40ccd1 commit 87667de

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed

apps/studio/components/interfaces/Home/SecurityStatus.tsx

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CheckCircle2, Loader2 } from 'lucide-react'
1+
import { CheckCircle2, ChevronRight, Loader2 } from 'lucide-react'
22
import { useState } from 'react'
33
import {
44
Button,
@@ -13,18 +13,20 @@ import { useSelectedProject } from 'hooks/misc/useSelectedProject'
1313
import Link from 'next/link'
1414

1515
import { LINTER_LEVELS, LINT_TABS } from '../Linter/Linter.constants'
16+
import { useParams } from 'common'
1617

1718
export const SecurityStatus = () => {
18-
const project = useSelectedProject()
19+
const { ref } = useParams()
1920
const [open, setOpen] = useState(false)
20-
const { data, isLoading } = useProjectLintsQuery({ projectRef: project?.ref })
21+
const { data, isLoading } = useProjectLintsQuery({ projectRef: ref })
2122

2223
const securityLints = (data ?? []).filter((lint) => lint.categories.includes('SECURITY'))
2324
const errorLints = securityLints.filter((lint) => lint.level === 'ERROR')
2425
const warnLints = securityLints.filter((lint) => lint.level === 'WARN')
2526
const infoLints = securityLints.filter((lint) => lint.level === 'INFO')
2627

27-
const noIssuesFound = errorLints.length === 0 && warnLints.length === 0 && infoLints.length === 0
28+
const totalLints = errorLints.length + warnLints.length + infoLints.length
29+
const noIssuesFound = totalLints === 0
2830

2931
return (
3032
<Popover_Shadcn_ modal={false} open={open} onOpenChange={setOpen}>
@@ -51,12 +53,8 @@ export const SecurityStatus = () => {
5153
Security Issues
5254
</Button>
5355
</PopoverTrigger_Shadcn_>
54-
<PopoverContent_Shadcn_
55-
className={`py-1.5 px-0 ${noIssuesFound ? 'w-72' : 'w-84'}`}
56-
side="bottom"
57-
align="center"
58-
>
59-
<div className="py-2 text-sm flex gap-3">
56+
<PopoverContent_Shadcn_ side="bottom" align="center" className={cn('py-1.5 px-0 w-64')}>
57+
<div className="text-sm">
6058
{noIssuesFound ? (
6159
<div className="flex gap-3 px-4">
6260
<CheckCircle2 className="text-brand shrink-0" size={18} strokeWidth={1.5} />
@@ -66,42 +64,61 @@ export const SecurityStatus = () => {
6664
Keep monitoring Security Advisor for updates as your project grows.
6765
</p>
6866
<Button asChild type="default" className="w-min mt-2">
69-
<Link href={`/project/${project?.ref}/database/security-advisor`}>
70-
Security Advisor
71-
</Link>
67+
<Link href={`/project/${ref}/database/security-advisor`}>Security Advisor</Link>
7268
</Button>
7369
</div>
7470
</div>
7571
) : (
76-
<div className="grid gap-y-3.5">
72+
<div className="grid">
73+
<p className="text-xs text-foreground-lighter px-3 pb-1.5">
74+
{totalLints} issue{totalLints > 1 ? 's' : ''} have been identified
75+
</p>
76+
<PopoverSeparator_Shadcn_ />
7777
{[
7878
{ lints: errorLints, level: LINTER_LEVELS.ERROR },
7979
{ lints: warnLints, level: LINTER_LEVELS.WARN },
8080
{ lints: infoLints, level: LINTER_LEVELS.INFO },
81-
].map(
82-
({ lints, level }) =>
81+
].map(({ lints, level }) => {
82+
const { label, descriptionShort } = LINT_TABS.find((tab) => tab.id === level) ?? {}
83+
return (
8384
lints.length > 0 && (
8485
<>
85-
<div key={level} className="flex gap-3 pb-0 px-4">
86-
<StatusDot level={level} />
87-
<div>
88-
{lints.length} {level.toLowerCase()} issue{lints.length > 1 ? 's' : ''}
89-
<p className="text-xs text-foreground-lighter">
90-
{LINT_TABS.find((tab) => tab.id === level)?.descriptionShort}
91-
</p>
86+
<Link href={`/project/${ref}/database/security-advisor?preset=${level}`}>
87+
<div
88+
key={level}
89+
className="group flex items-center justify-between w-full px-3 py-3 transition hover:bg-surface-300"
90+
>
91+
<div className="flex gap-x-3">
92+
<div>
93+
<StatusDot level={level} />
94+
</div>
95+
<div>
96+
<p className="text-xs">
97+
{lints.length}{' '}
98+
{label === 'Info'
99+
? 'suggestion'
100+
: label?.slice(0, label.length - 1).toLowerCase()}
101+
{lints.length > 1 ? 's' : ''}
102+
</p>
103+
<p className="text-xs text-foreground-light">{descriptionShort}</p>
104+
</div>
105+
</div>
106+
<ChevronRight
107+
size={14}
108+
className="transition opacity-0 group-hover:opacity-100"
109+
/>
92110
</div>
93-
</div>
94-
<PopoverSeparator_Shadcn_ className="" />
111+
</Link>
112+
<PopoverSeparator_Shadcn_ />
95113
</>
96114
)
97-
)}
98-
<Button asChild type="default" className="w-min ml-4">
99-
<Link
100-
href={`/project/${project?.ref}/database/security-advisor${errorLints.length === 0 ? '?preset=WARN' : ''}`}
101-
>
102-
Security Advisor
103-
</Link>
104-
</Button>
115+
)
116+
})}
117+
<div className="flex items-center justify-end pt-2 pb-0.5 px-3">
118+
<Button asChild type="default" className="w-min">
119+
<Link href={`/project/${ref}/database/security-advisor`}>Security Advisor</Link>
120+
</Button>
121+
</div>
105122
</div>
106123
)}
107124
</div>

apps/studio/components/interfaces/Linter/Linter.constants.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ export const LINT_TABS = [
1919
id: LINTER_LEVELS.ERROR,
2020
label: 'Errors',
2121
description: 'You should consider these issues urgent and fix them as soon as you can.',
22-
descriptionShort: 'Consider these issues urgent and fix them as soon as you can.',
22+
descriptionShort: 'Require immediate attention',
2323
},
2424
{
2525
id: LINTER_LEVELS.WARN,
26-
label: 'Warnings ',
26+
label: 'Warnings',
2727
description: 'You should try and read through these issues and fix them if necessary.',
28-
descriptionShort: 'Read through these issues and fix them if necessary.',
28+
descriptionShort: 'To resolve only if necessary',
2929
},
3030
{
3131
id: LINTER_LEVELS.INFO,
32-
label: 'Info ',
32+
label: 'Info',
3333
description: 'You should read through these suggestions and consider implementing them.',
34-
descriptionShort: 'Read through these suggestions and consider implementing them.',
34+
descriptionShort: 'For consideration to implement',
3535
},
3636
]

0 commit comments

Comments
 (0)