Files
supabase/apps/studio/components/interfaces/SQLEditor/DiffActionBar.tsx
T
Joshen Lim 17e0c5dbcf Improve snippet organization in SQL Editor (#27881)
* Init changes for sql fodlers

* Added upsert logic in sql-editor-v2 valtio, hooked up with templates and quickstarts

* Do up logic for creating new snippets by typing in /new or by clicking new query button

* Do up logic for updating and deleting snippets

* Do up logic for favourites and shared snippets

* Do up logic for favourites and shared snippets

* Fix

* Fix saving indicator, add empty states for favorites and shared snippets

* Implement sorting

* Some minor QOL improvements

* Minor fix on empty state for private snippets

* Add delete folder mutation

* Implement create and update folder

* Fix reinstate with AI renaming for new snippets under folder

* Support controlled multi select behaviour in private snippets

* Undo changes to tree-view-multi-select

* Support bulk deletes

* Support moving queries + rendering queries in folders

* Support deleting folders and creating a new folder when moving a query

* Fix bug where renaming query removes content

* Add initial loading state in sql editor nav + handle fallback if cannot retrieve content by id

* Fix some spelling

* Fix TS issue in sql folders mutation keys

* Fix toggling favorite

* Lint

* Revert fallback behaviour in ]id] for now

* Fix favorites and shared snippets not showing

* Fix moving currently opened snippet leads to loading

* Support bulk moving

* Improve multi select logic a little

* Nit lint

* Reinstate AI retitling for untitled snippets when running query

* Remove hardcode in useAFlag

* Support creating new snippet in a folder directly

* Fix sharing snippets that are within a folder

* Fix sharing snippets within a folder

* Fix favorite

* Add loading state when fetching folder contents

* Fix favoriting snippets in folders
2024-07-17 12:23:19 +08:00

72 lines
2.1 KiB
TypeScript

import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from 'ui'
import { ChevronDown, CornerDownLeft, Loader2 } from 'lucide-react'
import { DiffType } from './SQLEditor.types'
import { getDiffTypeButtonLabel, getDiffTypeDropdownLabel } from './SQLEditor.utils'
type DiffActionBarProps = {
loading: boolean
selectedDiffType: DiffType
onChangeDiffType: (type: DiffType) => void
onAccept: () => void
onCancel: () => void
}
export const DiffActionBar = ({
loading,
selectedDiffType,
onChangeDiffType,
onAccept,
onCancel,
}: DiffActionBarProps) => {
return (
<>
<div className="flex items-center">
<Button
className="rounded-r-none"
type="primary"
size="tiny"
icon={loading && <Loader2 className="animate-spin" />}
iconRight={<CornerDownLeft size={12} strokeWidth={1.5} />}
onClick={onAccept}
>
{getDiffTypeButtonLabel(selectedDiffType)}
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
type="primary"
className="rounded-l-none border-l-0 px-[4px] py-[5px] flex"
icon={<ChevronDown />}
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" side="bottom">
{Object.values(DiffType)
.filter((diffType) => diffType !== selectedDiffType)
.map((diffType) => (
<DropdownMenuItem key={diffType} onClick={() => onChangeDiffType(diffType)}>
<p>{getDiffTypeDropdownLabel(diffType)}</p>
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
</div>
<Button
type="alternative"
size="tiny"
className="bg-brand-300 hover:bg-brand-400 dark:bg-brand-400 dark:hover:bg-brand-500 text-brand-600 group"
iconRight={<span className="dark:text-brand-500 group-hover:text-brand-600">ESC</span>}
onClick={onCancel}
>
Discard
</Button>
</>
)
}