Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/improve search input sql editor (#21546)

Jonathan Summers-Muir8c68a09fc4db
diff --git a/apps/studio/components/layouts/SQLEditorLayout/QueryItem.tsx b/apps/studio/components/layouts/SQLEditorLayout/QueryItem.tsx
index d4e8fac4baa..b9edf78bddb 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/QueryItem.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/QueryItem.tsx
@@ -1,30 +1,28 @@
-import clsx from 'clsx'
import { useParams } from 'common'
import { noop } from 'lodash'
-import Link from 'next/link'
-import { useRouter } from 'next/router'
import { useEffect, useRef, useState } from 'react'
import toast from 'react-hot-toast'
import {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
Alert_Shadcn_,
- Checkbox,
Checkbox_Shadcn_,
+ HoverCardContent_Shadcn_,
+ HoverCardTrigger_Shadcn_,
+ HoverCard_Shadcn_,
IconAlertCircle,
IconAlertTriangle,
IconEye,
IconUnlock,
Modal,
- TooltipContent_Shadcn_,
- TooltipTrigger_Shadcn_,
- Tooltip_Shadcn_,
+ cn,
} from 'ui'
+import { InnerSideMenuItem } from 'ui-patterns'
+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import DownloadSnippetModal from 'components/interfaces/SQLEditor/DownloadSnippetModal'
import RenameQueryModal from 'components/interfaces/SQLEditor/RenameQueryModal'
import SimpleCodeBlock from 'components/to-be-cleaned/SimpleCodeBlock'
-import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import CopyButton from 'components/ui/CopyButton'
import { useContentDeleteMutation } from 'data/content/content-delete-mutation'
import type { SqlSnippet } from 'data/content/sql-snippets-query'
@@ -106,71 +104,57 @@ const QueryItem = ({
return (
<>
- <Tooltip_Shadcn_ delayDuration={100}>
- <TooltipTrigger_Shadcn_ asChild>
- <div
+ <HoverCard_Shadcn_ openDelay={200}>
+ <HoverCardTrigger_Shadcn_ asChild>
+ <InnerSideMenuItem
+ title={description || name}
+ ref={isActive ? (activeItemRef as React.RefObject<HTMLAnchorElement>) : null}
+ href={`/project/${ref}/sql/${id}`}
key={id}
- className={clsx(
- 'h-7 pl-3 pr-2',
- 'flex items-center justify-between rounded-md group relative',
- isActive ? 'bg-surface-300' : 'hover:bg-surface-200'
- )}
- ref={isActive ? (activeItemRef as React.RefObject<HTMLDivElement>) : null}
+ className={'flex gap-3 items-center'}
+ forceHoverState={open}
+ isActive={isActive}
>
{visibility === 'user' && (
- <Checkbox
- className={clsx(
- 'transition absolute left-2.5 top-1 [&>input]:border-foreground-lighter',
+ <Checkbox_Shadcn_
+ className={cn(
+ 'transition absolute left-2.5 border-strong',
hasQueriesSelected ? '' : 'opacity-0 group-hover:opacity-100'
)}
checked={isSelected}
- onChange={(event) => {
- onSelectQuery((event.nativeEvent as KeyboardEvent).shiftKey)
- }}
+ onCheckedChange={onSelectQuery}
/>
)}
- <div className="flex items-center justify-between w-full gap-x-2">
- <Link
- title={description || name}
- href={`/project/${ref}/sql/${id}`}
- className={clsx(
- 'w-full overflow-hidden truncate',
- isActive
- ? 'text-foreground'
- : 'text-foreground-light group-hover:text-foreground/80',
- 'text-sm transition-all overflow-hidden text-ellipsis',
- hasQueriesSelected && visibility === 'user'
- ? 'ml-5'
- : visibility === 'user'
- ? 'group-hover:ml-5'
- : ''
- )}
- >
- {name}
- </Link>
- {!hasQueriesSelected && (
- <QueryItemActions
- tabInfo={tabInfo}
- activeId={activeId}
- open={open}
- setOpen={setOpen}
- onSelectDeleteQuery={() => setDeleteModalOpen(true)}
- onSelectRenameQuery={() => setRenameModalOpen(true)}
- onSelectShareQuery={() => setShareModalOpen(true)}
- onSelectDownloadQuery={() => setIsDownloadSnippetModalOpen(true)}
- />
+ <span
+ className={cn(
+ 'transition-all',
+ 'w-full overflow-hidden truncate',
+ hasQueriesSelected && visibility === 'user'
+ ? 'ml-5'
+ : visibility === 'user'
+ ? 'group-hover:ml-5'
+ : '',
+ 'text-ellipsis'
)}
- </div>
- </div>
- </TooltipTrigger_Shadcn_>
+ >
+ {name}
+ </span>
+ {!hasQueriesSelected && (
+ <QueryItemActions
+ tabInfo={tabInfo}
+ open={open}
+ setOpen={setOpen}
+ onSelectDeleteQuery={() => setDeleteModalOpen(true)}
+ onSelectRenameQuery={() => setRenameModalOpen(true)}
+ onSelectShareQuery={() => setShareModalOpen(true)}
+ onSelectDownloadQuery={() => setIsDownloadSnippetModalOpen(true)}
+ />
+ )}
+ </InnerSideMenuItem>
+ </HoverCardTrigger_Shadcn_>
{!hideTooltip && (
- <TooltipContent_Shadcn_
- side="right"
- align="start"
- className="w-96 flex flex-col gap-y-2 py-3 -translate-y-[4px]"
- >
- <p className="text-xs">Query preview:</p>
- <div className="bg-surface-300 py-2 px-3 rounded relative">
+ <HoverCardContent_Shadcn_ side="right" align="center" className="w-96" animate="slide-in">
+ <>
{content.sql.trim() ? (
<SimpleCodeBlock
showCopy={false}
@@ -191,10 +175,10 @@ const QueryItem = ({
text={content.sql}
/>
)}
- </div>
- </TooltipContent_Shadcn_>
+ </>
+ </HoverCardContent_Shadcn_>
)}
- </Tooltip_Shadcn_>
+ </HoverCard_Shadcn_>
<RenameQueryModal
snippet={tabInfo}
visible={renameModalOpen}
@@ -211,23 +195,17 @@ const QueryItem = ({
onSelectConfirm={onConfirmDelete}
onSelectCancel={() => setDeleteModalOpen(false)}
>
- <Modal.Content>
- <div className="my-6">
- <div className="text-sm text-foreground-light grid gap-4">
- <div className="grid gap-1">
- {visibility === 'project' && (
- <Alert_Shadcn_ variant="destructive">
- <IconAlertCircle strokeWidth={2} />
- <AlertTitle_Shadcn_>This SQL snippet will be lost forever</AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- Deleting this query will remove it for all members of the project team.
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- )}
- <p>Are you sure you want to delete '{name}'?</p>
- </div>
- </div>
- </div>
+ <Modal.Content className="my-6 grid gap-1 text-sm text-foreground-light grid gap-4">
+ {visibility === 'project' && (
+ <Alert_Shadcn_ variant="destructive">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>This SQL snippet will be lost forever</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Deleting this query will remove it for all members of the project team.
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+ <p>Are you sure you want to delete '{name}'?</p>
</Modal.Content>
</ConfirmationModal>
<ConfirmationModal
@@ -239,32 +217,26 @@ const QueryItem = ({
onSelectConfirm={onConfirmShare}
onSelectCancel={() => setShareModalOpen(false)}
>
- <Modal.Content>
- <div className="my-6">
- <div className="text-sm text-foreground-light grid gap-4">
- <div className="grid gap-1">
- <Alert_Shadcn_ variant="warning">
- <IconAlertTriangle strokeWidth={2} />
- <AlertTitle_Shadcn_>
- This SQL query will become public to all team members
- </AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- Anyone with access to the project can view it
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- <ul className="mt-4 space-y-5">
- <li className="flex gap-3">
- <IconEye />
- <span>Project members will have read-only access to this query.</span>
- </li>
- <li className="flex gap-3">
- <IconUnlock />
- <span>Anyone will be able to duplicate it to their personal snippets.</span>
- </li>
- </ul>
- </div>
- </div>
- </div>
+ <Modal.Content className="my-6 text-sm text-foreground-light grid gap-4 grid gap-1">
+ <Alert_Shadcn_ variant="warning">
+ <IconAlertTriangle strokeWidth={2} />
+ <AlertTitle_Shadcn_>
+ This SQL query will become public to all team members
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Anyone with access to the project can view it
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ <ul className="mt-4 space-y-5">
+ <li className="flex gap-3">
+ <IconEye />
+ <span>Project members will have read-only access to this query.</span>
+ </li>
+ <li className="flex gap-3">
+ <IconUnlock />
+ <span>Anyone will be able to duplicate it to their personal snippets.</span>
+ </li>
+ </ul>
</Modal.Content>
</ConfirmationModal>
<DownloadSnippetModal
diff --git a/apps/studio/components/layouts/SQLEditorLayout/QueryItemActions.tsx b/apps/studio/components/layouts/SQLEditorLayout/QueryItemActions.tsx
index 2eedc7458d9..7e8359d8e1c 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/QueryItemActions.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/QueryItemActions.tsx
@@ -1,6 +1,6 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import clsx from 'clsx'
import { IS_PLATFORM, useParams } from 'common'
+import { Copy, Download, Edit, MoreHorizontal, Share, Trash } from 'lucide-react'
import { useRouter } from 'next/router'
import {
Button,
@@ -9,12 +9,6 @@ import {
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
- IconChevronDown,
- IconCopy,
- IconDownload,
- IconEdit2,
- IconShare,
- IconTrash,
} from 'ui'
import { createSqlSnippetSkeleton } from 'components/interfaces/SQLEditor/SQLEditor.utils'
@@ -26,7 +20,6 @@ import { useSqlEditorStateSnapshot } from 'state/sql-editor'
interface QueryItemActionsProps {
tabInfo: SqlSnippet
- activeId: string | undefined
open: boolean
setOpen: (value: boolean) => void
onSelectRenameQuery: () => void
@@ -37,7 +30,6 @@ interface QueryItemActionsProps {
export const QueryItemActions = ({
tabInfo,
- activeId,
open,
setOpen,
onSelectRenameQuery,
@@ -106,49 +98,54 @@ export const QueryItemActions = ({
}
return (
- <div className="group [div&>button[data-state='open']>span]:text-foreground-lighter flex items-center">
+ <>
{IS_PLATFORM ? (
<DropdownMenu open={open} onOpenChange={setOpen}>
- <DropdownMenuTrigger asChild>
+ <DropdownMenuTrigger
+ className="opacity-0 group-hover:opacity-100 group-focus:opacity-100 focus:opacity-100 data-[state=open]:opacity-100"
+ asChild
+ name="Query actions"
+ >
<Button
type="text"
- className="px-1 opacity-50 hover:opacity-100"
- icon={<IconChevronDown size="tiny" strokeWidth={2} />}
+ className="px-1 text-lighter data-[state=open]:text-foreground"
+ icon={<MoreHorizontal size={14} strokeWidth={2} />}
+ onClick={(e) => e.preventDefault()}
/>
</DropdownMenuTrigger>
- <DropdownMenuContent side="bottom" align="end" className=" w-52 translate-x-2">
+ <DropdownMenuContent side="bottom" align="start" className="w-52">
{isSnippetOwner && (
- <DropdownMenuItem onClick={onClickRename} className="space-x-2">
- <IconEdit2 size="tiny" />
- <p>Rename query</p>
+ <DropdownMenuItem onClick={onClickRename} className="flex gap-2">
+ <Edit size={14} />
+ Rename query
</DropdownMenuItem>
)}
{visibility === 'user' && canCreateSQLSnippet && (
- <DropdownMenuItem onClick={onClickShare} className="space-x-2">
- <IconShare size="tiny" />
- <p>Share query</p>
+ <DropdownMenuItem onClick={onClickShare} className="flex gap-2">
+ <Share size={14} />
+ Share query
</DropdownMenuItem>
)}
{visibility === 'project' && canCreateSQLSnippet && (
- <DropdownMenuItem onClick={createPersonalCopy} className="space-x-2">
- <IconCopy size="tiny" />
- <p>Duplicate personal copy</p>
+ <DropdownMenuItem onClick={createPersonalCopy} className="flex gap-2">
+ <Copy size={14} />
+ Duplicate personal copy
</DropdownMenuItem>
)}
{IS_PLATFORM && (
- <DropdownMenuItem onClick={() => onSelectDownloadQuery()} className="space-x-2">
- <IconDownload size="tiny" />
- <p>Download as migration file</p>
+ <DropdownMenuItem onClick={() => onSelectDownloadQuery()} className="flex gap-2">
+ <Download size={14} />
+ Download as migration file
</DropdownMenuItem>
)}
{isSnippetOwner && (
<>
<DropdownMenuSeparator />
- <DropdownMenuItem onClick={onClickDelete} className="space-x-2">
- <IconTrash size="tiny" />
- <p>Delete query</p>
+ <DropdownMenuItem onClick={onClickDelete} className="flex gap-2">
+ <Trash size={14} />
+ Delete query
</DropdownMenuItem>
</>
)}
@@ -159,6 +156,6 @@ export const QueryItemActions = ({
<span />
</Button>
)}
- </div>
+ </>
)
}
diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
index e3822aaa822..5b7c4e60c91 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
@@ -1,6 +1,7 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
import { partition } from 'lodash'
+import { Plus } from 'lucide-react'
import { observer } from 'mobx-react-lite'
import { useRouter } from 'next/router'
import { useMemo, useState } from 'react'
@@ -10,24 +11,27 @@ import {
AlertTitle_Shadcn_,
Alert_Shadcn_,
Button,
- IconPlus,
- IconSearch,
- IconX,
- Input,
- Menu,
Modal,
- Separator,
TooltipContent_Shadcn_,
TooltipTrigger_Shadcn_,
Tooltip_Shadcn_,
} from 'ui'
+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
+import {
+ InnerSideBarEmptyPanel,
+ InnerSideBarFilterSearchInput,
+ InnerSideBarFilters,
+ InnerSideBarShimmeringLoaders,
+ InnerSideMenuCollapsible,
+ InnerSideMenuCollapsibleContent,
+ InnerSideMenuCollapsibleTrigger,
+ InnerSideMenuItem,
+ InnerSideMenuSeparator,
+} from 'ui-patterns/InnerSideMenu'
import { untitledSnippetTitle } from 'components/interfaces/SQLEditor/SQLEditor.constants'
import { createSqlSnippetSkeleton } from 'components/interfaces/SQLEditor/SQLEditor.utils'
-import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import { WarningIcon } from 'components/ui/Icons'
-import ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem'
-import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { useContentDeleteMutation } from 'data/content/content-delete-mutation'
import { SqlSnippet, useSqlSnippetsQuery } from 'data/content/sql-snippets-query'
import { useCheckPermissions, useSelectedProject, useStore } from 'hooks'
@@ -209,176 +213,158 @@ const SideBarContent = observer(() => {
return (
<>
<div className="mt-6">
- <Menu type="pills">
- {isLoading ? (
- <div className="px-5 my-4 space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : isSuccess ? (
- <div className="space-y-6">
- <div className="px-4 flex flex-col gap-2">
- <Button
- type="default"
- className="justify-start"
- onClick={() => handleNewQuery()}
- icon={<IconPlus size="tiny" />}
+ {isLoading ? (
+ <InnerSideBarShimmeringLoaders />
+ ) : isSuccess ? (
+ <div>
+ <div className="flex flex-col gap-4">
+ <Button
+ type="default"
+ className="justify-start mx-4"
+ onClick={() => handleNewQuery()}
+ icon={<Plus className="text-foreground-muted" strokeWidth={1} size={14} />}
+ >
+ New query
+ </Button>
+
+ <div className="px-2">
+ <InnerSideMenuItem
+ title="Templates"
+ isActive={router.asPath === `/project/${ref}/sql/templates`}
+ href={`/project/${ref}/sql/templates`}
>
- New query
- </Button>
- <Input
- className="table-editor-search border-none"
- icon={
- <IconSearch className="text-foreground-lighter" size={12} strokeWidth={1.5} />
- }
- placeholder="Search queries"
- onChange={(e) => setSearchText(e.target.value.trim())}
- value={searchText}
- size="tiny"
- actions={
- searchText && (
- <Button type="text" className="px-1" onClick={() => setSearchText('')}>
- <IconX size={12} strokeWidth={2} />
- </Button>
- )
- }
- />
+ Templates
+ </InnerSideMenuItem>
+ <InnerSideMenuItem
+ title="Quickstarts"
+ isActive={router.asPath === `/project/${ref}/sql/quickstarts`}
+ href={`/project/${ref}/sql/quickstarts`}
+ >
+ Quickstarts
+ </InnerSideMenuItem>
</div>
- <div className="flex flex-col gap-y-6 px-2">
- {searchText.length === 0 && (
- <div>
- <ProductMenuItem
- name="Templates"
- isActive={router.asPath === `/project/${ref}/sql/templates`}
- url={`/project/${ref}/sql/templates`}
- />
- <ProductMenuItem
- name="Quickstarts"
- isActive={router.asPath === `/project/${ref}/sql/quickstarts`}
- url={`/project/${ref}/sql/quickstarts`}
- />
- </div>
- )}
- {searchText.length > 0 &&
- filteredFavoriteSnippets.length === 0 &&
- filteredProjectSnippets.length === 0 &&
- personalSnippets.length === 0 && (
- <div className="h-32 border border-dashed flex flex-col gap-y-3 items-center justify-center rounded px-3">
- <div className="flex flex-col gap-y-1 items-center justify-center">
- <p className="text-xs text-foreground">No queries found</p>
- <p className="text-xs text-foreground-light text-center">
- Your search for "{searchText}" did not return any results
- </p>
- </div>
+ {snippets.length > 0 && (
+ <InnerSideBarFilters className="mx-2">
+ <InnerSideBarFilterSearchInput
+ name="search-queries"
+ placeholder="Search queries..."
+ onChange={(e) => setSearchText(e.target.value.trim())}
+ value={searchText}
+ aria-labelledby="Search queries"
+ />
+ </InnerSideBarFilters>
+ )}
+
+ {searchText.length > 0 &&
+ filteredProjectSnippets.length === 0 &&
+ filteredFavoriteSnippets.length === 0 &&
+ filteredProjectSnippets.length === 0 && (
+ <InnerSideBarEmptyPanel
+ className="mx-4"
+ title="No project queries found"
+ description="Click the New query button to create a new query"
+ actions={
<Button type="default" onClick={() => handleNewQuery()}>
New query
</Button>
- </div>
- )}
+ }
+ />
+ )}
- {filteredProjectSnippets.length > 0 ? (
- <div className="editor-product-menu">
- <Menu.Group title="Project queries" />
+ {filteredProjectSnippets.length > 0 && (
+ <InnerSideMenuCollapsible className="editor-product-menu" defaultOpen>
+ <InnerSideMenuCollapsibleTrigger title="Project queries" />
+ <InnerSideMenuCollapsibleContent>
+ <>
+ {filteredProjectSnippets.map((tabInfo) => (
+ <QueryItem
+ key={tabInfo.id}
+ tabInfo={tabInfo}
+ hasQueriesSelected={selectedQueries.length > 0}
+ />
+ ))}
+ </>
+ </InnerSideMenuCollapsibleContent>
+ </InnerSideMenuCollapsible>
+ )}
- <div className="space-y-1">
- {filteredProjectSnippets.map((tabInfo) => {
- const { id } = tabInfo || {}
- return (
- <QueryItem
- key={id}
- tabInfo={tabInfo}
- hasQueriesSelected={selectedQueries.length > 0}
- />
- )
- })}
- </div>
+ {selectedQueries.length > 0 && (
+ <>
+ <InnerSideMenuSeparator />
+ <div className="px-4 flex items-center gap-x-2 py-2">
+ <Button block type="danger" onClick={() => setShowDeleteModal(true)}>
+ Delete {selectedQueries.length.toLocaleString()} quer
+ {selectedQueries.length > 1 ? 'ies' : 'y'}
+ </Button>
+ <Tooltip_Shadcn_ delayDuration={100}>
+ <TooltipTrigger_Shadcn_ asChild>
+ <Button type="default" onClick={() => setSelectedQueries([])}>
+ Cancel
+ </Button>
+ </TooltipTrigger_Shadcn_>
+ <TooltipContent_Shadcn_ side="bottom">Clear selection</TooltipContent_Shadcn_>
+ </Tooltip_Shadcn_>
</div>
- ) : null}
-
- {selectedQueries.length > 0 && (
- <>
- <Separator />
- <div className="px-2 flex items-center gap-x-2">
- <Button block type="default" onClick={() => setShowDeleteModal(true)}>
- Delete {selectedQueries.length.toLocaleString()} quer
- {selectedQueries.length > 1 ? 'ies' : 'y'}
- </Button>
- <Tooltip_Shadcn_ delayDuration={100}>
- <TooltipTrigger_Shadcn_ asChild>
- <Button
- type="default"
- className="px-1"
- icon={<IconX />}
- onClick={() => setSelectedQueries([])}
- />
- </TooltipTrigger_Shadcn_>
- <TooltipContent_Shadcn_ side="bottom" className="text-xs">
- Clear selection
- </TooltipContent_Shadcn_>
- </Tooltip_Shadcn_>
- </div>
- </>
- )}
+ </>
+ )}
- {filteredFavoriteSnippets.length > 0 ? (
- <div className="editor-product-menu">
- <Menu.Group title="Favorites" />
- <div className="space-y-1">
- {filteredFavoriteSnippets.map((tabInfo) => {
- const { id } = tabInfo || {}
- return (
- <QueryItem
- key={id}
- tabInfo={tabInfo}
- isSelected={selectedQueries.includes(id as string)}
- hasQueriesSelected={selectedQueries.length > 0}
- onSelectQuery={(isShiftHeld) => onSelectQuery(id, isShiftHeld)}
- onDeleteQuery={postDeleteCleanup}
- />
- )
- })}
- </div>
- </div>
- ) : null}
-
- {personalSnippets.length > 0 ? (
- <div className="editor-product-menu">
- <Menu.Group title="Your queries" />
- <div className="space-y-1 pb-8">
- {personalSnippets.map((tabInfo) => {
- const { id } = tabInfo || {}
- return (
+ {filteredFavoriteSnippets.length > 0 && (
+ <InnerSideMenuCollapsible className="editor-product-menu" defaultOpen>
+ <InnerSideMenuCollapsibleTrigger title="Favorites" />
+ <InnerSideMenuCollapsibleContent>
+ <>
+ {filteredFavoriteSnippets.map((tabInfo) => (
+ <QueryItem
+ key={tabInfo.id}
+ tabInfo={tabInfo}
+ isSelected={selectedQueries.includes(tabInfo.id as string)}
+ hasQueriesSelected={selectedQueries.length > 0}
+ onSelectQuery={(isShiftHeld) => onSelectQuery(tabInfo.id, isShiftHeld)}
+ onDeleteQuery={postDeleteCleanup}
+ />
+ ))}
+ </>
+ </InnerSideMenuCollapsibleContent>
+ </InnerSideMenuCollapsible>
+ )}
+
+ {personalSnippets.length > 0 && (
+ <InnerSideMenuCollapsible className="editor-product-menu" defaultOpen>
+ <InnerSideMenuCollapsibleTrigger title="Your queries" />
+ <InnerSideMenuCollapsibleContent className="editor-product-menu">
+ <>
+ <div className="space-y-0.5">
+ {personalSnippets.map((tabInfo) => (
<QueryItem
- key={id}
+ key={tabInfo.id}
tabInfo={tabInfo}
- isSelected={selectedQueries.includes(id as string)}
+ isSelected={selectedQueries.includes(tabInfo.id as string)}
hasQueriesSelected={selectedQueries.length > 0}
- onSelectQuery={(isShiftHeld) => onSelectQuery(id, isShiftHeld)}
+ onSelectQuery={(isShiftHeld) => onSelectQuery(tabInfo.id, isShiftHeld)}
onDeleteQuery={postDeleteCleanup}
/>
- )
- })}
- </div>
- </div>
- ) : null}
- </div>
+ ))}
+ </div>
+ </>
+ </InnerSideMenuCollapsibleContent>
+ </InnerSideMenuCollapsible>
+ )}
</div>
- ) : (
- <div></div>
- )}
- </Menu>
+ </div>
+ ) : null}
</div>
+
<ConfirmationModal
header="Confirm to delete query"
- buttonLabel="Delete query"
+ buttonLabel={`Delete ${selectedQueries.length.toLocaleString()} quer${selectedQueries.length > 1 ? 'ies' : 'y'}`}
buttonLoadingLabel="Deleting query"
size="medium"
loading={isDeleting}
visible={showDeleteModal}
onSelectConfirm={onConfirmDelete}
onSelectCancel={() => setShowDeleteModal(false)}
+ danger
>
<Modal.Content>
<div className="my-6">
diff --git a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
index 96d2134c589..93837e4b59a 100644
--- a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
@@ -1,36 +1,28 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
-import { partition } from 'lodash'
-import { Plus, Search } from 'lucide-react'
-import { useRouter } from 'next/router'
-import { useEffect, useMemo, useRef, useState } from 'react'
-
-import {
- AlertDescription_Shadcn_,
- AlertTitle_Shadcn_,
- Alert_Shadcn_,
- Button,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuRadioGroup,
- DropdownMenuRadioItem,
- DropdownMenuTrigger,
- IconChevronsDown,
- Input_Shadcn_,
- cn,
-} from 'ui'
-
import { ProtectedSchemaModal } from 'components/interfaces/Database/ProtectedSchemaWarning'
import AlertError from 'components/ui/AlertError'
import InfiniteList from 'components/ui/InfiniteList'
import SchemaSelector from 'components/ui/SchemaSelector'
-import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { useSchemasQuery } from 'data/database/schemas-query'
import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-query'
import { useCheckPermissions, useLocalStorage } from 'hooks'
import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas'
+import { partition } from 'lodash'
+import { Plus } from 'lucide-react'
+import { useRouter } from 'next/router'
+import { useMemo, useState } from 'react'
import { useTableEditorStateSnapshot } from 'state/table-editor'
+import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui'
+import {
+ InnerSideBarEmptyPanel,
+ InnerSideBarFilterSearchInput,
+ InnerSideBarFilterSortDropdown,
+ InnerSideBarFilterSortDropdownItem,
+ InnerSideBarFilters,
+ InnerSideBarShimmeringLoaders,
+} from 'ui-patterns/InnerSideMenu'
import { useProjectContext } from '../ProjectLayout/ProjectContext'
import EntityListItem from './EntityListItem'
@@ -45,9 +37,6 @@ const TableEditorMenu = () => {
'table-editor-sort',
'alphabetical'
)
- const [isSearchOpen, setIsSearchOpen] = useState(false)
- const inputRef = useRef<HTMLInputElement | null>(null)
- const [isSearchInputFocused, setIsSearchInputFocused] = useState(false)
const { project } = useProjectContext()
const {
@@ -97,20 +86,6 @@ const TableEditorMenu = () => {
)
const isLocked = protectedSchemas.some((s) => s.id === schema?.id)
- const expandSearch = () => {
- setIsSearchOpen(!isSearchOpen)
- }
-
- useEffect(() => {
- if (isSearchOpen && inputRef.current) {
- inputRef.current.focus()
- }
- }, [isSearchOpen])
-
- const handleSearchInputFocusChange = () => {
- setIsSearchInputFocused(inputRef.current === document.activeElement)
- }
-
return (
<>
<div
@@ -183,79 +158,38 @@ const TableEditorMenu = () => {
</div>
</div>
<div className="flex flex-auto flex-col gap-2 pb-4 px-2">
- <div className="flex items-center px-2 w-full gap-2">
- <label htmlFor={'search-tables'} className="relative w-full">
- <span className="sr-only">Search tables</span>
- <Input_Shadcn_
- id="search-tables"
- name="search-tables"
- type="text"
- placeholder="Search tables..."
- className={cn('h-[28px] w-full', 'text-xs', 'pl-7', 'w-full')}
- onChange={(e) => {
- setSearchText(e.target.value.trim())
- }}
- value={searchText}
- ref={(el) => {
- inputRef.current = el
- if (el) {
- el.addEventListener('focus', handleSearchInputFocusChange)
- el.addEventListener('blur', handleSearchInputFocusChange)
- }
- }}
- onKeyDown={(e) => {
- if (e.key === 'Escape') {
- setIsSearchOpen(false)
- setSearchText('')
- }
- }}
- />
- <Search
- className="absolute left-2 top-2 text-foreground-muted"
- size={14}
- strokeWidth={1.5}
- />
- </label>
- <DropdownMenu>
- <Tooltip.Root delayDuration={0}>
- <DropdownMenuTrigger asChild>
- <Tooltip.Trigger className="text-foreground-lighter transition-colors hover:text-foreground data-[state=open]:text-foreground">
- <IconChevronsDown size={18} strokeWidth={1} />
- </Tooltip.Trigger>
- </DropdownMenuTrigger>
- <Tooltip.Portal>
- <Tooltip.Content
- side="bottom"
- className={[
- 'rounded bg-alternative py-1 px-2 leading-none shadow',
- 'border border-background text-xs',
- ].join(' ')}
- >
- <Tooltip.Arrow className="radix-tooltip-arrow" />
- Sort By
- </Tooltip.Content>
- </Tooltip.Portal>
- </Tooltip.Root>
- <DropdownMenuContent side="bottom" align="end" className="w-48">
- <DropdownMenuRadioGroup value={sort} onValueChange={(value: any) => setSort(value)}>
- <DropdownMenuRadioItem key="alphabetical" value="alphabetical">
- Alphabetical
- </DropdownMenuRadioItem>
- <DropdownMenuRadioItem key="grouped-alphabetical" value="grouped-alphabetical">
- Entity Type
- </DropdownMenuRadioItem>
- </DropdownMenuRadioGroup>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
-
- {isLoading && (
- <div className="flex flex-col px-2 gap-1 pb-4">
- <ShimmeringLoader className="w-full h-7 rounded-md" delayIndex={0} />
- <ShimmeringLoader className="w-full h-7 rounded-md" delayIndex={1} />
- <ShimmeringLoader className="w-full h-7 rounded-md" delayIndex={2} />
- </div>
- )}
+ <InnerSideBarFilters>
+ <InnerSideBarFilterSearchInput
+ name="search-tables"
+ aria-labelledby="Search tables"
+ onChange={(e) => {
+ setSearchText(e.target.value.trim())
+ }}
+ value={searchText}
+ placeholder="Search tables..."
+ >
+ <InnerSideBarFilterSortDropdown
+ value={sort}
+ onValueChange={(value: any) => setSort(value)}
+ >
+ <InnerSideBarFilterSortDropdownItem
+ key="alphabetical"
+ value="alphabetical"
+ className="flex gap-2"
+ >
+ Alphabetical
+ </InnerSideBarFilterSortDropdownItem>
+ <InnerSideBarFilterSortDropdownItem
+ key="grouped-alphabetical"
+ value="grouped-alphabetical"
+ >
+ Entity Type
+ </InnerSideBarFilterSortDropdownItem>
+ </InnerSideBarFilterSortDropdown>
+ </InnerSideBarFilterSearchInput>
+ </InnerSideBarFilters>
+
+ {isLoading && <InnerSideBarShimmeringLoaders />}
{isError && (
<AlertError error={(error ?? null) as any} subject="Failed to retrieve tables" />
@@ -264,20 +198,18 @@ const TableEditorMenu = () => {
{isSuccess && (
<>
{searchText.length === 0 && (entityTypes?.length ?? 0) <= 0 && (
- <div className="mx-2 my-2 space-y-1 rounded-md border border-muted bg-surface-100 py-3 px-4">
- <p className="text-xs">No entities available</p>
- <p className="text-xs text-foreground-light">
- This schema has no entities available yet
- </p>
- </div>
+ <InnerSideBarEmptyPanel
+ className="mx-2"
+ title="No entities available"
+ description="This schema has no entities available yet"
+ />
)}
{searchText.length > 0 && (entityTypes?.length ?? 0) <= 0 && (
- <div className="mx-2 my-2 space-y-1 rounded-md border border-muted bg-surface-100 py-3 px-4">
- <p className="text-xs">No results found</p>
- <p className="text-xs text-foreground-light">
- Your search for "{searchText}" did not return any results
- </p>
- </div>
+ <InnerSideBarEmptyPanel
+ className="mx-2"
+ title="No results found"
+ description={`Your search for "${searchText}" did not return any results`}
+ />
)}
{(entityTypes?.length ?? 0) > 0 && (
<div className="flex flex-1">
diff --git a/packages/ui-patterns/InnerSideMenu/index.tsx b/packages/ui-patterns/InnerSideMenu/index.tsx
new file mode 100644
index 00000000000..1fbbe7f89a8
--- /dev/null
+++ b/packages/ui-patterns/InnerSideMenu/index.tsx
@@ -0,0 +1,234 @@
+import {
+ // ChevronRight,
+ Search,
+} from 'lucide-react'
+import Link from 'next/link'
+import { ElementRef, forwardRef } from 'react'
+import {
+ CollapsibleContent_Shadcn_,
+ CollapsibleTrigger_Shadcn_,
+ Collapsible_Shadcn_,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuRadioGroup,
+ DropdownMenuRadioItem,
+ DropdownMenuTrigger,
+ IconChevronsDown,
+ Input_Shadcn_,
+ TooltipContent_Shadcn_,
+ TooltipTrigger_Shadcn_,
+ Tooltip_Shadcn_,
+ cn,
+} from 'ui'
+import ShimmeringLoader from '../ShimmeringLoader'
+
+const InnerSideMenuCollapsible = forwardRef<
+ ElementRef<typeof Collapsible_Shadcn_>,
+ React.ComponentPropsWithoutRef<typeof Collapsible_Shadcn_>
+>(({ ...props }, ref) => {
+ return <Collapsible_Shadcn_ {...props} className={cn('w-full px-2', props.className)} />
+})
+
+const InnerSideMenuCollapsibleTrigger = forwardRef<
+ ElementRef<typeof CollapsibleTrigger_Shadcn_>,
+ React.ComponentPropsWithoutRef<typeof CollapsibleTrigger_Shadcn_>
+>(({ ...props }, ref) => {
+ return (
+ <CollapsibleTrigger_Shadcn_
+ disabled
+ ref={ref}
+ {...props}
+ className={cn(
+ 'w-full flex gap-1 items-center group px-3 text-xs font-normal font-mono uppercase text-lighter tracking-wide',
+ props.className
+ )}
+ >
+ {/* <ChevronRight
+ className="transition-all text-foreground-muted group-data-[state=open]:rotate-90"
+ size={16}
+ strokeWidth={1.5}
+ /> */}
+ <span className="group-hover:not-disabled:text-foreground">{props.title}</span>
+ </CollapsibleTrigger_Shadcn_>
+ )
+})
+
+const InnerSideMenuCollapsibleContent = forwardRef<
+ ElementRef<typeof CollapsibleContent_Shadcn_>,
+ React.ComponentPropsWithoutRef<typeof CollapsibleContent_Shadcn_>
+>(({ ...props }, ref) => {
+ return (
+ <CollapsibleContent_Shadcn_
+ {...props}
+ className={cn('w-full data-[state=open]:pt-1 flex flex-col gap-2', props.className)}
+ />
+ )
+})
+
+const InnerSideMenuSeparator = forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>(
+ (props, ref) => {
+ return <div ref={ref} {...props} className={cn('h-px bg-border-muted', props.className)} />
+ }
+)
+
+const InnerSideMenuItem = forwardRef<
+ ElementRef<typeof Link>,
+ React.ComponentPropsWithoutRef<typeof Link> & {
+ isActive?: boolean
+ forceHoverState?: boolean | null
+ }
+>(({ className, isActive, forceHoverState, ...props }, ref) => {
+ return (
+ <Link
+ ref={ref}
+ {...props}
+ aria-current={isActive}
+ className={cn(
+ 'text-sm',
+ 'h-7 pl-3 pr-2',
+ 'flex items-center justify-between rounded-md group relative',
+ isActive ? 'bg-selection' : 'hover:bg-surface-200',
+ forceHoverState && 'bg-surface-200',
+ isActive ? 'text-foreground' : 'text-foreground-light hover:text-foreground',
+ className
+ )}
+ />
+ )
+})
+
+const InnerSideBarFilters = forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>(
+ (props, ref) => {
+ return (
+ <div ref={ref} {...props} className={cn('flex px-2 gap-2 items-center', props.className)} />
+ )
+ }
+)
+
+const InnerSideBarFilterSearchInput = forwardRef<
+ HTMLInputElement,
+ React.ComponentPropsWithoutRef<'input'> & { 'aria-labelledby': string; name: string }
+>(({ children, ...props }, ref) => {
+ return (
+ <label htmlFor={props.name} className="relative w-full">
+ <span className="sr-only">{props['aria-labelledby']}</span>
+ <Input_Shadcn_
+ ref={ref}
+ type="text"
+ className={cn(
+ 'h-[28px] w-full',
+ 'text-xs',
+ 'pl-7',
+ 'pr-7',
+ 'w-full',
+ 'rounded',
+ // 'bg-transparent',
+ // 'border',
+ // 'border-control',
+ props.className
+ )}
+ {...props}
+ />
+ {children}
+ <Search className="absolute left-2 top-2 text-foreground-muted" size={14} strokeWidth={1.5} />
+ </label>
+ )
+})
+
+const InnerSideBarFilterSortDropdown = forwardRef<
+ ElementRef<typeof DropdownMenu>,
+ React.ComponentPropsWithoutRef<typeof DropdownMenu> & {
+ value: string
+ onValueChange: (value: string) => void
+ contentClassName?: string
+ triggerClassName?: string
+ }
+>(({ value, onValueChange, contentClassName, triggerClassName, ...props }, ref) => {
+ return (
+ <DropdownMenu modal={false}>
+ <Tooltip_Shadcn_ delayDuration={0}>
+ <DropdownMenuTrigger
+ asChild
+ className={cn(
+ 'absolute right-1 top-[.3rem]',
+ 'text-foreground-muted transition-colors hover:text-foreground data-[state=open]:text-foreground',
+ triggerClassName
+ )}
+ >
+ <TooltipTrigger_Shadcn_>
+ <IconChevronsDown size={18} strokeWidth={1} />
+ </TooltipTrigger_Shadcn_>
+ </DropdownMenuTrigger>
+ <TooltipContent_Shadcn_ side="bottom">Sort By</TooltipContent_Shadcn_>
+ </Tooltip_Shadcn_>
+ <DropdownMenuContent side="bottom" align="end" className={cn('w-48', contentClassName)}>
+ <DropdownMenuRadioGroup value={value} onValueChange={onValueChange}>
+ {props.children}
+ </DropdownMenuRadioGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )
+})
+
+const InnerSideBarFilterSortDropdownItem = forwardRef<
+ ElementRef<typeof DropdownMenuRadioItem>,
+ React.ComponentPropsWithoutRef<typeof DropdownMenuRadioItem>
+>((props, ref) => {
+ return <DropdownMenuRadioItem ref={ref} {...props} />
+})
+
+const InnerSideBarShimmeringLoaders = forwardRef<
+ HTMLDivElement,
+ React.ComponentPropsWithoutRef<'div'>
+>((props, ref) => {
+ return (
+ <div ref={ref} {...props} className={cn('flex flex-col px-2 gap-1 pb-4', props.className)}>
+ <ShimmeringLoader className="w-full h-7 rounded-md" delayIndex={0} />
+ <ShimmeringLoader className="w-full h-7 rounded-md" delayIndex={1} />
+ <ShimmeringLoader className="w-full h-7 rounded-md" delayIndex={2} />
+ </div>
+ )
+})
+
+const InnerSideBarEmptyPanel = forwardRef<
+ HTMLDivElement,
+ React.ComponentPropsWithoutRef<'div'> & {
+ title: string
+ description?: string
+ illustration?: React.ReactNode
+ actions?: React.ReactNode
+ }
+>(({ illustration, title, description, actions, ...props }, ref) => {
+ return (
+ <div
+ ref={ref}
+ {...props}
+ className={cn(
+ 'border bg-surface-100/50 flex flex-col gap-y-3 items-center justify-center rounded-md px-3 py-4',
+ props.className
+ )}
+ >
+ <div className="flex flex-col gap-y-1 items-center justify-center">
+ {illustration}
+ {title && <p className="text-xs text-foreground-light">{title}</p>}
+ {description && (
+ <p className="text-xs text-foreground-lighter text-center">{description}</p>
+ )}
+ {actions && <div className="mt-2">{actions}</div>}
+ </div>
+ </div>
+ )
+})
+
+export {
+ InnerSideBarFilterSearchInput,
+ InnerSideBarFilters,
+ InnerSideBarShimmeringLoaders,
+ InnerSideMenuCollapsible,
+ InnerSideMenuCollapsibleContent,
+ InnerSideMenuCollapsibleTrigger,
+ InnerSideMenuItem,
+ InnerSideMenuSeparator,
+ InnerSideBarFilterSortDropdown,
+ InnerSideBarFilterSortDropdownItem,
+ InnerSideBarEmptyPanel,
+}
diff --git a/packages/ui-patterns/ShimmeringLoader/index.tsx b/packages/ui-patterns/ShimmeringLoader/index.tsx
new file mode 100644
index 00000000000..e7ec3e32a71
--- /dev/null
+++ b/packages/ui-patterns/ShimmeringLoader/index.tsx
@@ -0,0 +1,34 @@
+import { cn } from 'ui'
+
+export interface ShimmeringLoader {
+ className?: string
+ delayIndex?: number
+ animationDelay?: number
+}
+
+const ShimmeringLoader = ({
+ className,
+ delayIndex = 0,
+ animationDelay = 150,
+}: ShimmeringLoader) => {
+ return (
+ <div
+ className={cn('shimmering-loader rounded py-3', className)}
+ style={{
+ animationFillMode: 'backwards',
+ animationDelay: `${delayIndex * animationDelay}ms`,
+ }}
+ />
+ )
+}
+
+const GenericSkeletonLoader = () => (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+)
+
+export { GenericSkeletonLoader }
+export default ShimmeringLoader
diff --git a/packages/ui-patterns/index.tsx b/packages/ui-patterns/index.tsx
index ebe615b423f..47ecd7580bb 100644
--- a/packages/ui-patterns/index.tsx
+++ b/packages/ui-patterns/index.tsx
@@ -12,5 +12,7 @@ export * from './SchemaTableNode'
export * from './ThemeImage'
export * from './ThemeToggle'
export * from './TweetCard'
+export * from './InnerSideMenu'
+export * from './ShimmeringLoader'
export * from './Dialogs/ConfirmDialog'
export * from './Dialogs/ConfirmationModal'
diff --git a/packages/ui/index.tsx b/packages/ui/index.tsx
index 770a53b4e08..253134b4330 100644
--- a/packages/ui/index.tsx
+++ b/packages/ui/index.tsx
@@ -207,6 +207,12 @@ export {
TooltipContent as TooltipContent_Shadcn_,
} from './src/components/shadcn/ui/tooltip'
+export {
+ HoverCard as HoverCard_Shadcn_,
+ HoverCardTrigger as HoverCardTrigger_Shadcn_,
+ HoverCardContent as HoverCardContent_Shadcn_,
+} from './src/components/shadcn/ui/hover-card'
+
export { Toggle as Toggle_Shadcn } from './src/components/shadcn/ui/toggle'
export { ScrollArea, ScrollBar } from './src/components/shadcn/ui/scroll-area'
diff --git a/packages/ui/src/components/shadcn/ui/dropdown-menu.tsx b/packages/ui/src/components/shadcn/ui/dropdown-menu.tsx
index d507665cd94..83e6ab6ef00 100644
--- a/packages/ui/src/components/shadcn/ui/dropdown-menu.tsx
+++ b/packages/ui/src/components/shadcn/ui/dropdown-menu.tsx
@@ -79,7 +79,7 @@ const DropdownMenuItem = React.forwardRef<
<DropdownMenuPrimitive.Item
ref={ref}
className={cn(
- 'relative flex select-none items-center rounded-sm px-2 py-1.5 text-xs outline-none transition-colors focus:bg-overlay-hover focus:text-strong data-[disabled]:pointer-events-none data-[disabled]:opacity-50 cursor-pointer',
+ 'relative flex select-none items-center rounded-sm px-2 py-1.5 text-xs outline-none transition-colors focus:bg-overlay-hover focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 cursor-pointer',
inset && 'pl-8',
className
)}