Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/show lints on project homepage (#23424)

Terry Suttonfee07c5d3669
diff --git a/apps/studio/components/interfaces/Home/SecurityStatus.tsx b/apps/studio/components/interfaces/Home/SecurityStatus.tsx
new file mode 100644
index 00000000000..e855d6a6581
--- /dev/null
+++ b/apps/studio/components/interfaces/Home/SecurityStatus.tsx
@@ -0,0 +1,87 @@
+import { CheckCircle2, Loader2 } from 'lucide-react'
+import { useState } from 'react'
+import { Button, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, Popover_Shadcn_, cn } from 'ui'
+
+import { useProjectLintsQuery } from 'data/lint/lint-query'
+import { useSelectedProject } from 'hooks/misc/useSelectedProject'
+
+import Link from 'next/link'
+import { WarningIcon } from 'ui/src/components/StatusIcon'
+
+export const SecurityStatus = () => {
+ const project = useSelectedProject()
+ const [open, setOpen] = useState(false)
+ const { data, isLoading } = useProjectLintsQuery({
+ projectRef: project?.ref,
+ })
+
+ const securityLints = (data ?? []).filter(
+ (lint) =>
+ lint.categories.includes('SECURITY') && (lint.level === 'ERROR' || lint.level === 'WARN')
+ )
+
+ const noIssuesFound = securityLints.length === 0
+
+ return (
+ <Popover_Shadcn_ modal={false} open={open} onOpenChange={setOpen}>
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button
+ type="default"
+ icon={
+ isLoading ? (
+ <Loader2 className="animate-spin" />
+ ) : (
+ <div
+ className={cn(
+ `w-2 h-2 rounded-full`,
+ noIssuesFound ? 'bg-brand' : 'bg-destructive-600'
+ )}
+ />
+ )
+ }
+ >
+ Security Issues
+ </Button>
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_
+ className={`py-1.5 px-0 ${noIssuesFound ? 'w-64' : 'w-84'}`}
+ side="bottom"
+ align="center"
+ >
+ <div className="px-4 py-2 text-sm flex gap-3">
+ {noIssuesFound ? (
+ <CheckCircle2 className="text-brand shrink-0" size={18} strokeWidth={1.5} />
+ ) : (
+ <WarningIcon className="shrink-0" />
+ )}
+
+ <div className="flex flex-col gap-y-3 -mt-1">
+ {noIssuesFound ? (
+ <div className="flex flex-col gap-y-1">
+ <p className="text-xs">No security issues found</p>
+ <p className="text-xs text-foreground-light">
+ Keep monitoring Security Advisor for updates as your project grows.
+ </p>
+ </div>
+ ) : (
+ <div className="flex flex-col gap-y-1">
+ <p className="text-xs">
+ {securityLints.length} security issues requiring urgent attention
+ </p>
+ <p className="text-xs text-foreground-light">
+ Check the Security Advisor to address them
+ </p>
+ </div>
+ )}
+
+ <Button asChild type="default" className="w-min">
+ <Link href={`/project/${project?.ref}/database/security-advisor`}>
+ Head to Security Advisor
+ </Link>
+ </Button>
+ </div>
+ </div>
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ )
+}
diff --git a/apps/studio/components/interfaces/Home/ServiceStatus.tsx b/apps/studio/components/interfaces/Home/ServiceStatus.tsx
index 892d5112329..6e5ed6fa0e1 100644
--- a/apps/studio/components/interfaces/Home/ServiceStatus.tsx
+++ b/apps/studio/components/interfaces/Home/ServiceStatus.tsx
@@ -133,7 +133,7 @@ const ServiceStatus = () => {
{isBranch ? 'Preview Branch' : 'Project'} Status
</Button>
</PopoverTrigger_Shadcn_>
- <PopoverContent_Shadcn_ className="p-0 w-56" side="bottom" align="end">
+ <PopoverContent_Shadcn_ className="p-0 w-56" side="bottom" align="center">
{services.map((service) => (
<div
key={service.name}
diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
index 1b7c029ce7c..d43c6b510a6 100644
--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
@@ -61,6 +61,8 @@ import {
suffixWithLimit,
} from './SQLEditor.utils'
import UtilityPanel from './UtilityPanel/UtilityPanel'
+import { lintKeys } from 'data/lint/keys'
+import { useQueryClient } from '@tanstack/react-query'
import { Loader2 } from 'lucide-react'
// Load the monaco editor client-side only (does not behave well server-side)
@@ -89,6 +91,7 @@ const SQLEditor = () => {
const snapV2 = useSqlEditorV2StateSnapshot()
const getImpersonatedRole = useGetImpersonatedRole()
const databaseSelectorState = useDatabaseSelectorStateSnapshot()
+ const queryClient = useQueryClient()
const enableFolders = useFlag('sqlFolderOrganization')
const { mutate: formatQuery } = useFormatQueryMutation()
@@ -178,6 +181,9 @@ const SQLEditor = () => {
// Refetching instead of invalidating since invalidate doesn't work with `enabled` flag
refetchEntityDefinitions()
+
+ // revalidate lint query
+ queryClient.invalidateQueries(lintKeys.lint(ref))
},
onError(error: any, vars) {
if (id) {
diff --git a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
index e887acce6ec..b85393dc886 100644
--- a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
@@ -41,6 +41,7 @@ import {
} from './NavigationBar.utils'
import { NavigationIconButton } from './NavigationIconButton'
import NavigationIconLink from './NavigationIconLink'
+import { useProjectLintsQuery } from 'data/lint/lint-query'
export const ICON_SIZE = 20
export const ICON_STROKE_WIDTH = 1.5
@@ -73,6 +74,15 @@ const NavigationBar = () => {
'realtime:all',
])
+ const { data } = useProjectLintsQuery({
+ projectRef: project?.ref,
+ })
+
+ const securityLints = (data ?? []).filter(
+ (lint) =>
+ lint.categories.includes('SECURITY') && (lint.level === 'ERROR' || lint.level === 'WARN')
+ )
+
const activeRoute = router.pathname.split('/')[3]
const toolRoutes = generateToolRoutes(projectRef, project)
const productRoutes = generateProductRoutes(projectRef, project, {
@@ -150,6 +160,7 @@ const NavigationBar = () => {
onClick={onCloseNavigationIconLink}
/>
))}
+
<Separator className="my-1 bg-border-muted" />
{otherRoutes.map((route) => {
if (route.key === 'api' && isNewAPIDocsEnabled) {
@@ -165,6 +176,21 @@ const NavigationBar = () => {
Project API
</NavigationIconButton>
)
+ } else if (route.key === 'advisors') {
+ return (
+ <div className="relative">
+ {securityLints.length > 0 && (
+ <div className="absolute flex h-2 w-2 left-6 top-2 z-10 bg-destructive-600 rounded-full" />
+ )}
+
+ <NavigationIconLink
+ key={route.key}
+ route={route}
+ isActive={activeRoute === route.key}
+ onClick={onCloseNavigationIconLink}
+ />
+ </div>
+ )
} else if (route.key === 'logs') {
// TODO: Undo this when warehouse flag is removed
const label = showWarehouse ? 'Logs & Analytics' : route.label
diff --git a/apps/studio/pages/project/[ref]/advisors/security.tsx b/apps/studio/pages/project/[ref]/advisors/security.tsx
index 1e4a4e88ec0..edeb7c593bb 100644
--- a/apps/studio/pages/project/[ref]/advisors/security.tsx
+++ b/apps/studio/pages/project/[ref]/advisors/security.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useState } from 'react'
+import { useEffect, useState } from 'react'
import { useParams } from 'common'
import LintPageTabs from 'components/interfaces/Linter/LintPageTabs'
@@ -46,12 +46,7 @@ const ProjectLints: NextPageWithLayout = () => {
refetchLintsQuery()
}
- let clientLints: Lint[] = []
-
- const activeLints = useMemo(() => {
- return [...(data ?? []), ...clientLints]?.filter((x) => x.categories.includes('SECURITY'))
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [data])
+ const activeLints = (data ?? []).filter((lint) => lint.categories.includes('SECURITY'))
useEffect(() => {
// check the URL for an ID and set the selected lint
diff --git a/apps/studio/pages/project/[ref]/index.tsx b/apps/studio/pages/project/[ref]/index.tsx
index 1f3dbd4f80f..12daccea6fe 100644
--- a/apps/studio/pages/project/[ref]/index.tsx
+++ b/apps/studio/pages/project/[ref]/index.tsx
@@ -5,6 +5,7 @@ import { ClientLibrary, ExampleProject } from 'components/interfaces/Home'
import Connect from 'components/interfaces/Home/Connect/Connect'
import { CLIENT_LIBRARIES, EXAMPLE_PROJECTS } from 'components/interfaces/Home/Home.constants'
import ProjectUsageSection from 'components/interfaces/Home/ProjectUsageSection'
+import { SecurityStatus } from 'components/interfaces/Home/SecurityStatus'
import ServiceStatus from 'components/interfaces/Home/ServiceStatus'
import { ProjectLayoutWithAuth } from 'components/layouts/ProjectLayout/ProjectLayout'
import ProjectPausedState from 'components/layouts/ProjectLayout/ProjectPausedState'
@@ -40,17 +41,15 @@ const Home: NextPageWithLayout = () => {
<div className="flex items-center justify-between mx-6 space-x-6">
<h1 className="text-3xl">{projectName}</h1>
<div className="flex items-center gap-x-3">
+ <SecurityStatus />
{IS_PLATFORM && project?.status === PROJECT_STATUS.ACTIVE_HEALTHY && <ServiceStatus />}
{IS_PLATFORM && project?.status === PROJECT_STATUS.ACTIVE_HEALTHY && <Connect />}
</div>
</div>
-
<div className="mx-6">
<ProjectUpgradeFailedBanner />
</div>
-
{project?.status === PROJECT_STATUS.INACTIVE && <ProjectPausedState />}
-
<div className="mx-6">
{IS_PLATFORM && project?.status !== PROJECT_STATUS.INACTIVE && <ProjectUsageSection />}
</div>