mirror of
https://github.com/supabase/supabase.git
synced 2026-07-02 18:34:44 +08:00
* SheetProvider in studio * mobile global nav * view sub navigation * fix ProjectLayout conditional * Account mobile layout * width * hide * layout * overflow * responsive button * overflow * fix mobile nav if IS_PLATFORM * refactor * hide if no content * show command menu item on mobile * ui-patterns sheet provider * use client * show if productMenu * show if productMenu * drag to close * drag to close * 16px input fontsize on inputs to avoid zoom on mobile * offscreen test element * offscreen test element * offscreen test element * update test * update test * update test * pb * test? * test * test * test * spec-click-target * remove console * remove unused import * add dependency to sheet content * close sheet on router.asPath change * remove provider and use simple Sheet * update sidebar mobile * align labels * avoid input zoom on mobile * remove yo
93 lines
3.2 KiB
TypeScript
93 lines
3.2 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { partition } from 'lodash'
|
|
import { useRouter } from 'next/router'
|
|
import { toast } from 'sonner'
|
|
|
|
import { useParams } from 'common'
|
|
import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.queries'
|
|
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
|
|
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
|
|
import { TelemetryActions } from 'lib/constants/telemetry'
|
|
import { uuidv4 } from 'lib/helpers'
|
|
import { useProfile } from 'lib/profile'
|
|
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
|
|
import { createSqlSnippetSkeletonV2 } from '../SQLEditor.utils'
|
|
import SQLCard from './SQLCard'
|
|
|
|
const SQLQuickstarts = () => {
|
|
const router = useRouter()
|
|
const { ref } = useParams()
|
|
const { profile } = useProfile()
|
|
const project = useSelectedProject()
|
|
const [, quickStart] = partition(SQL_TEMPLATES, { type: 'template' })
|
|
|
|
const snapV2 = useSqlEditorV2StateSnapshot()
|
|
|
|
const canCreateSQLSnippet = useCheckPermissions(PermissionAction.CREATE, 'user_content', {
|
|
resource: { type: 'sql', owner_id: profile?.id },
|
|
subject: { id: profile?.id },
|
|
})
|
|
|
|
const { mutate: sendEvent } = useSendEventMutation()
|
|
|
|
const handleNewQuery = async (sql: string, name: string) => {
|
|
if (!ref) return console.error('Project ref is required')
|
|
if (!project) return console.error('Project is required')
|
|
if (!profile) return console.error('Profile is required')
|
|
|
|
if (!canCreateSQLSnippet) {
|
|
return toast('Your queries will not be saved as you do not have sufficient permissions')
|
|
}
|
|
|
|
try {
|
|
const snippet = createSqlSnippetSkeletonV2({
|
|
id: uuidv4(),
|
|
name,
|
|
sql,
|
|
owner_id: profile?.id,
|
|
project_id: project?.id,
|
|
})
|
|
snapV2.addSnippet({ projectRef: ref, snippet })
|
|
snapV2.addNeedsSaving(snippet.id)
|
|
router.push(`/project/${ref}/sql/${snippet.id}`)
|
|
} catch (error: any) {
|
|
toast.error(`Failed to create new query: ${error.message}`)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="block h-full space-y-8 overflow-y-auto p-4 md:p-6">
|
|
<div className="mb-8">
|
|
<div className="mb-4">
|
|
<h1 className="text-foreground mb-3 text-xl">Quickstarts</h1>
|
|
|
|
<p className="text-foreground-light text-sm">
|
|
Click on any script to fill the query box, modify the script, then click
|
|
<span className="text-code">Run</span>.
|
|
</p>
|
|
</div>
|
|
<div className="grid gap-4 sm:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3">
|
|
{quickStart.map((x) => (
|
|
<SQLCard
|
|
key={x.title}
|
|
title={x.title}
|
|
description={x.description}
|
|
sql={x.sql}
|
|
onClick={(sql, title) => {
|
|
handleNewQuery(sql, title)
|
|
sendEvent({
|
|
action: TelemetryActions.SQL_EDITOR_QUICKSTART_CLICKED,
|
|
properties: { title },
|
|
})
|
|
}}
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default SQLQuickstarts
|