Skip to content

Commit

Permalink
fix: change remediation links for database linter (#22520)
Browse files Browse the repository at this point in the history
* fix: change remediation links for database linter

* fix: tab update behavior
  • Loading branch information
charislam committed Apr 5, 2024
1 parent c7e80e3 commit fef87b7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
39 changes: 26 additions & 13 deletions apps/docs/components/GuidesTableOfContents.tsx
Expand Up @@ -55,19 +55,32 @@ const GuidesTableOfContents = ({
useEffect(() => {
if (overrideToc) return

const headings = Array.from(
document.querySelector('#sb-docs-guide-main-article')?.querySelectorAll('h2, h3') ?? []
)
const newHeadings = headings
.filter((heading) => heading.id)
.map((heading) => {
const text = heading.textContent.replace('#', '')
const link = heading.querySelector('a').getAttribute('href')
const level = heading.tagName === 'H2' ? 2 : 3
return { text, link, level }
})
setTocList(newHeadings)
}, [pathname]) // needed to recalculate the toc when path changes
/**
* Because we're directly querying the DOM, needs the setTimeout so the DOM
* update will happen first.
*/
const timeoutHandle = setTimeout(() => {
const headings = Array.from(
document.querySelector('#sb-docs-guide-main-article')?.querySelectorAll('h2, h3') ?? []
)
const newHeadings = headings
.filter((heading) => heading.id)
.map((heading) => {
const text = heading.textContent.replace('#', '')
const link = heading.querySelector('a').getAttribute('href')
const level = heading.tagName === 'H2' ? 2 : 3
return { text, link, level }
})
setTocList(newHeadings)
})

return () => clearTimeout(timeoutHandle)
/**
* window.location.href needed to recalculate toc when page changes,
* useRerenderOnEvt below will guarantee rerender on change
*/
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [overrideToc, window.location.href])

useEffect(() => {
if (hash && displayedList.length > 0) {
Expand Down
8 changes: 5 additions & 3 deletions apps/docs/hooks/useManualRerender.ts
Expand Up @@ -7,10 +7,12 @@ import { useEffect, useReducer } from 'react'
const useRerenderOnEvt = (event: string, listeningElem?: Document | Window | HTMLElement) => {
const [, rerender] = useReducer((state) => !state, true)

const elem = listeningElem ?? window

useEffect(() => {
;(listeningElem ?? window).addEventListener(event, rerender)
return () => (listeningElem ?? window).removeEventListener(event, rerender)
}, [event, listeningElem, rerender])
elem.addEventListener(event, rerender)
return () => elem.removeEventListener(event, rerender)
}, [elem, event, rerender])
}

export { useRerenderOnEvt }
4 changes: 2 additions & 2 deletions apps/docs/pages/guides/database/database-linter.tsx
Expand Up @@ -33,11 +33,11 @@ const meta = {
const editLink = 'https://github.com/supabase/splinter/tree/main/docs'

const markdownIntro = `
You can use the Project Linter to check your database for issues such as missing indexes and improperly set-up RLS policies.
You can use the Database Linter to check your database for issues such as missing indexes and improperly set-up RLS policies.
## Using the linter
In the dashboard, navigate to [Database Linter](/dashboard/project/_/database/linter) under Database. The linter runs automatically. You can also manually rerun it after you're resolved issues, or ignore individual lints.
In the dashboard, navigate to [Database Linter](/dashboard/project/_/database/linter) under Database. The linter runs automatically. You can also manually rerun it after you've resolved issues.
`.trim()

const getBasename = (path: string) => path.split('/').at(-1).replace(/\.md$/, '')
Expand Down
12 changes: 6 additions & 6 deletions apps/studio/data/lint/lint-query.ts
Expand Up @@ -45,7 +45,7 @@ select
fk.table_,
fk.fkey_name
) as detail,
'https://supabase.github.io/splinter/0001_unindexed_foreign_keys' as remediation,
'https://supabase.com/docs/guides/database/database-linter?lint=0001_unindexed_foreign_keys' as remediation,
jsonb_build_object(
'schema', fk.schema_,
'name', fk.table_,
Expand Down Expand Up @@ -75,7 +75,7 @@ select
'View/Materialized View "%s" in the public schema may expose \`auth.users\` data to anon or authenticated roles.',
c.relname
) as detail,
'https://supabase.github.io/splinter/0002_auth_users_exposed' as remediation,
'https://supabase.com/docs/guides/database/database-linter?lint=0002_auth_users_exposed' as remediation,
jsonb_build_object(
'schema', 'public',
'name', c.relname,
Expand Down Expand Up @@ -171,7 +171,7 @@ select
table_,
policy_name
) as detail,
'https://supabase.github.io/splinter/0003_auth_rls_initplan' as remediation,
'https://supabase.com/docs/guides/database/database-linter?lint=0003_auth_rls_initplan' as remediation,
jsonb_build_object(
'schema', schema_,
'name', table_,
Expand Down Expand Up @@ -209,7 +209,7 @@ select
pgns.nspname,
pgc.relname
) as detail,
'https://supabase.github.io/splinter/0004_no_primary_key' as remediation,
'https://supabase.com/docs/guides/database/database-linter?lint=0004_no_primary_key' as remediation,
jsonb_build_object(
'schema', pgns.nspname,
'name', pgc.relname,
Expand Down Expand Up @@ -250,7 +250,7 @@ select
psui.schemaname,
psui.relname
) as detail,
'https://supabase.github.io/splinter/0005_unused_index' as remediation,
'https://supabase.com/docs/guides/database/database-linter?lint=0005_unused_index' as remediation,
jsonb_build_object(
'schema', psui.schemaname,
'name', psui.relname,
Expand Down Expand Up @@ -289,7 +289,7 @@ select
act.cmd,
array_agg(p.polname order by p.polname)
) as detail,
'https://supabase.github.io/splinter/0006_multiple_permissive_policies' as remediation,
'https://supabase.com/docs/guides/database/database-linter?lint=0006_multiple_permissive_policies' as remediation,
jsonb_build_object(
'schema', n.nspname,
'name', c.relname,
Expand Down

0 comments on commit fef87b7

Please sign in to comment.