Files
supabase/apps/database-new/components/Header/SaveSchemaDropdown.tsx
T
Terry SuttonandIvan Vasilov b4fa734c85 Chore/use completions api (#20246)
* Start

* Refactor code and remove unused imports

* Refactor SchemaFlowHandler and UserChat components

* Refactor code and remove unused files

* Refactor Thread component and remove CurrentThreadName import

* Remove oldest_messages view from supabase.ts

* Refactor supabase.ts file

* Hook up loading state ChatInput component and remove old route handlers

* Add updated prompt

* Refactor chat form component and remove unused code

* Make the suspense work when fetching messages.

* Small refactor in the chat assistant form component.

* Experimenting with streaming responses. WIP.

* Move all components to thread_id/message_id folder.

* Massive refactor but uses Nextjs app router properly.

* Add a conditional submit which is used if the user haven't been logged in.

* Add a typecheck command to db-new app.

* Minor fixes.

* Bunch of minor fixes.

* Clean up more code.

* Refactor the AssistantChatForm to use the new React forms features.

* Run fitView after 50 milliseconds because it didn't run in some cases.

* Style and flow nudges

* Prettier

* Delete old file

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2024-02-19 15:52:58 -03:30

73 lines
2.1 KiB
TypeScript

'use client'
import { getAppStateSnapshot } from '@/lib/state'
import Image from 'next/image'
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
IconChevronDown,
IconClipboard,
IconDownload,
} from 'ui'
const SaveSchemaDropdown = () => {
const copyToClipboard = () => {
const snap = getAppStateSnapshot()
const focused = window.document.hasFocus()
if (focused) {
window.navigator?.clipboard?.writeText(snap.selectedCode)
} else {
console.warn('Unable to copy to clipboard')
}
}
const downloadSQL = () => {
const snap = getAppStateSnapshot()
const blob = new Blob([snap.selectedCode], { type: 'text/plain' })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.download = 'migration.sql'
link.href = url
link.click()
}
const loadSQLInSupabase = () => {
const snap = getAppStateSnapshot()
window.open(
`https://supabase.com/dashboard/project/_/sql?content=${encodeURIComponent(
snap.selectedCode
)}`,
'_blank'
)
}
return (
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button type="default" iconRight={<IconChevronDown />}>
Save schema
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-44" align="end">
<DropdownMenuItem className="space-x-2" onClick={() => copyToClipboard()}>
<IconClipboard size={14} strokeWidth={1.5} className="text-lighter" />
<p>Copy SQL</p>
</DropdownMenuItem>
<DropdownMenuItem className="space-x-2" onClick={() => downloadSQL()}>
<IconDownload size={14} strokeWidth={1.5} className="text-lighter" />
<p>Download SQL</p>
</DropdownMenuItem>
<DropdownMenuItem className="space-x-2" onClick={() => loadSQLInSupabase()}>
<Image alt="supabase" src="/supabase.png" width={14} height={14} />
<p>Load SQL in Supabase</p>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
export default SaveSchemaDropdown