Files
supabase/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/SqlCodeBlock.tsx
Ivan Vasilov fd3309c886 feat: UI for pg-cron (#29291)
* Add crons option in the database menu.

* Add react-hook-form to the studio package.json.

* Refactor the functionSelector to be used by other features.

* Add the bulk of the functionality for the cron UI. Some of the code is copy-pasted from functions feature, needs to be cleaned before merging.

* Tons of changes, the Create Cron sheet works now.

* Added some more functionality for the cronjob feature.

* Convert the Cron table to a listing with cards.

* Add click-to-copy in the Auth Hooks feature.

* Remove extra prop.

* Fix type errors.

* Fix some random issues. Fix the tests.

* Fix the tests.

* Add a style for disabled radio button item.

* Make the default SQL snippet. Handle the case pg_net is not installed.

* Fix the heading and save button when creating a new cron job.

* Change the name of the custom label in the schedule dropdown.

* Minor fixes.

* Rename all mentions of cronjobs to cron jobs.

* Always show the cron jobs link.

* Rename the link from crons to cron-jobs.

* Fix the disabled state for the stacked radio group.

* More minor fixes.

* More small fixes.

* Fix the tests.

* Minor UI tweaks

* More minor tweaks

* Add padding bottom

* Add feature flag for the cron ui.

* Fix the SQL function option.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-10-03 15:11:17 -02:30

40 lines
971 B
TypeScript

import { format } from 'sql-formatter'
import { CodeBlock, cn } from 'ui'
interface SQLCodeBlockProps {
children: string[]
className?: string
}
export const SQLCodeBlock = ({ children, className }: SQLCodeBlockProps) => {
let formatted = (children || [''])[0]
try {
formatted = format(formatted, {
language: 'postgresql',
keywordCase: 'upper',
})
} catch {}
if (formatted.length === 0) {
return null
}
return (
<pre className="rounded-md relative group">
<CodeBlock
value={formatted}
language="sql"
className={cn(
'py-3 px-3.5 prose dark:prose-dark transition max-w-full',
// change the look of the code block. The flex hack is so that the code is wrapping since
// every word is a separate span
'[&>code]:m-0 [&>code>span]:flex [&>code>span]:flex-wrap',
className
)}
hideCopy
hideLineNumbers
/>
</pre>
)
}