Skip to content

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

Chore/table editor sidepanel revamp (#19977)

Terry Sutton646657937df2
diff --git a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
index f63df7608b1..60eef71bc66 100644
--- a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
@@ -1,24 +1,24 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import clsx from 'clsx'
+import { IS_PLATFORM } from 'common'
import saveAs from 'file-saver'
+import { Eye, MoreHorizontal, Table2, Unlock } from 'lucide-react'
import Link from 'next/link'
import Papa from 'papaparse'
-import SVG from 'react-inlinesvg'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
- IconChevronDown,
IconCopy,
IconDownload,
IconEdit,
IconLock,
IconTrash,
+ cn,
} from 'ui'
-import { IS_PLATFORM } from 'common'
import { parseSupaTable } from 'components/grid'
import { ItemRenderer } from 'components/ui/InfiniteList'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
@@ -26,7 +26,6 @@ import { Entity } from 'data/entity-types/entity-type-query'
import { fetchAllTableRows } from 'data/table-rows/table-rows-query'
import { getTable } from 'data/tables/table-query'
import { useStore } from 'hooks'
-import { BASE_PATH } from 'lib/constants'
import { useTableEditorStateSnapshot } from 'state/table-editor'
import { useProjectContext } from '../ProjectLayout/ProjectContext'
@@ -36,8 +35,6 @@ export interface EntityListItemProps {
isLocked: boolean
}
-const svgLoader = <span className="block w-4 h-4 bg-[#133929] rounded-sm" />
-
const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
id,
projectRef,
@@ -49,6 +46,7 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
const snap = useTableEditorStateSnapshot()
const isActive = Number(id) === entity.id
+
const formatTooltipText = (entityType: string) => {
return Object.entries(ENTITY_TYPE)
.find(([, value]) => value === entityType)?.[0]
@@ -128,68 +126,50 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
>
<Link
href={`/project/${projectRef}/editor/${entity.id}`}
- className="flex items-center py-1 px-3 w-full space-x-3 max-w-[90%]"
+ className="flex items-center gap-2 py-1 pl-2 w-full max-w-[90%]"
>
<Tooltip.Root delayDuration={0} disableHoverableContent={true}>
<Tooltip.Trigger className="flex items-center" asChild>
- <span>
- {entity.type === ENTITY_TYPE.TABLE ? (
- <SVG
- className="table-icon"
- src={`${BASE_PATH}/img/icons/table-icon.svg`}
- style={{ width: `16px`, height: `16px`, strokeWidth: '1px' }}
- preProcessor={(code: any) =>
- code.replace(/svg/, 'svg class="m-auto text-color-inherit"')
- }
- loader={svgLoader}
- cacheRequests={true}
- />
- ) : entity.type === ENTITY_TYPE.VIEW ? (
- <SVG
- className="view-icon"
- src={`${BASE_PATH}/img/icons/view-icon.svg`}
- style={{ width: `16px`, height: `16px`, strokeWidth: '1px' }}
- preProcessor={(code: any) =>
- code.replace(/svg/, 'svg class="m-auto text-color-inherit"')
- }
- loader={svgLoader}
- cacheRequests={true}
- />
- ) : (
- <div
- className={clsx(
- 'flex items-center justify-center text-xs h-4 w-4 rounded-[2px] font-bold',
- entity.type === ENTITY_TYPE.FOREIGN_TABLE && 'text-yellow-900 bg-yellow-500',
- entity.type === ENTITY_TYPE.MATERIALIZED_VIEW &&
- 'text-purple-1000 bg-purple-500',
- entity.type === ENTITY_TYPE.PARTITIONED_TABLE &&
- 'text-foreground-light bg-border-stronger'
- )}
- >
- {Object.entries(ENTITY_TYPE)
- .find(([, value]) => value === entity.type)?.[0]?.[0]
- ?.toUpperCase()}
- </div>
- )}
- </span>
- </Tooltip.Trigger>
- <Tooltip.Portal>
- <Tooltip.Content side="bottom">
- <Tooltip.Arrow className="radix-tooltip-arrow" />
+ {entity.type === ENTITY_TYPE.TABLE ? (
+ <Table2 size={15} strokeWidth={1.5} className="text-foreground-light" />
+ ) : entity.type === ENTITY_TYPE.VIEW ? (
+ <Eye size={15} strokeWidth={1.5} className="text-foreground-light" />
+ ) : (
<div
- className={[
- 'rounded bg-alternative py-1 px-2 leading-none shadow',
- 'border border-background',
- ].join(' ')}
+ className={clsx(
+ 'flex items-center justify-center text-xs h-4 w-4 rounded-[2px] font-bold',
+ entity.type === ENTITY_TYPE.FOREIGN_TABLE && 'text-yellow-900 bg-yellow-500',
+ entity.type === ENTITY_TYPE.MATERIALIZED_VIEW && 'text-purple-1000 bg-purple-500',
+ entity.type === ENTITY_TYPE.PARTITIONED_TABLE &&
+ 'text-foreground-light bg-border-stronger'
+ )}
>
- <span className="text-xs text-foreground capitalize">
- {formatTooltipText(entity.type)}
- </span>
+ {Object.entries(ENTITY_TYPE)
+ .find(([, value]) => value === entity.type)?.[0]?.[0]
+ ?.toUpperCase()}
</div>
+ )}
+ </Tooltip.Trigger>
+ <Tooltip.Portal>
+ <Tooltip.Content
+ side="bottom"
+ className={[
+ 'rounded bg-alternative py-1 px-2 leading-none shadow',
+ 'border border-background',
+ 'text-xs text-foreground capitalize',
+ ].join(' ')}
+ >
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ {formatTooltipText(entity.type)}
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
- <p className="text-sm text-foreground-light group-hover:text-foreground transition max-w-[85%] overflow-hidden text-ellipsis whitespace-nowrap">
+ <div
+ className={cn(
+ 'text-sm text-foreground-light group-hover:text-foreground transition max-w-[175px] overflow-hidden text-ellipsis whitespace-nowrap flex items-center gap-2 relative w-full',
+ isActive && 'text-foreground'
+ )}
+ >
{/* only show tooltips if required, to reduce noise */}
{entity.name.length > 20 ? (
<Tooltip.Root delayDuration={0} disableHoverableContent={true}>
@@ -197,30 +177,40 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
{entity.name}
</Tooltip.Trigger>
<Tooltip.Portal>
- <Tooltip.Content side="bottom">
+ <Tooltip.Content
+ side="right"
+ className={[
+ 'rounded bg-alternative py-1 px-2 leading-none shadow',
+ 'border border-background',
+ 'text-xs text-foreground',
+ ].join(' ')}
+ >
<Tooltip.Arrow className="radix-tooltip-arrow" />
- <div
- className={[
- 'rounded bg-alternative py-1 px-2 leading-none shadow',
- 'border border-background',
- ].join(' ')}
- >
- <span className="text-xs text-foreground">{entity.name}</span>
- </div>
+ {entity.name}
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
) : (
entity.name
)}
- </p>
+
+ {entity.type === ENTITY_TYPE.TABLE && !entity.rls_enabled && (
+ <div className="w-4 px-0.5">
+ <Unlock
+ size={14}
+ strokeWidth={1.5}
+ className={cn(isActive ? 'text-warning' : 'text-warning-500')}
+ />
+ </div>
+ )}
+ </div>
</Link>
- <div className="pr-3">
+ <div className="pr-2 flex items-center">
{entity.type === ENTITY_TYPE.TABLE && isActive && !isLocked && (
<DropdownMenu>
<DropdownMenuTrigger>
- <div className="text-foreground-lighter transition-colors hover:text-foreground">
- <IconChevronDown size={14} strokeWidth={2} />
+ <div className="text-foreground-lighter transition-all hover:text-foreground">
+ <MoreHorizontal size={14} strokeWidth={2} />
</div>
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="start">
@@ -233,7 +223,7 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
}}
>
<IconEdit size="tiny" />
- <p>Edit Table</p>
+ <span>Edit Table</span>
</DropdownMenuItem>
<DropdownMenuItem
key="duplicate-table"
@@ -244,7 +234,7 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
}}
>
<IconCopy size="tiny" />
- <p>Duplicate Table</p>
+ <span>Duplicate Table</span>
</DropdownMenuItem>
<DropdownMenuItem key="view-policies" className="space-x-2" asChild>
<Link
@@ -252,7 +242,7 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
href={`/project/${projectRef}/auth/policies?schema=${snap.selectedSchemaName}&search=${entity.id}`}
>
<IconLock size="tiny" />
- <p>View Policies</p>
+ <span>View Policies</span>
</Link>
</DropdownMenuItem>
<DropdownMenuItem
@@ -264,7 +254,7 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
}}
>
<IconDownload size="tiny" />
- <p>Export as CSV</p>
+ <span>Export as CSV</span>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
@@ -276,7 +266,7 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
}}
>
<IconTrash size="tiny" />
- <p>Delete Table</p>
+ <span>Delete Table</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
diff --git a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
index 5f15b1e393a..1f04cfc7fbb 100644
--- a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
@@ -1,9 +1,12 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
+import { AnimatePresence, motion } from 'framer-motion'
import { partition } from 'lodash'
+import { Loader2 } from 'lucide-react'
import { useRouter } from 'next/router'
-import { useMemo, useState } from 'react'
+import { useEffect, useMemo, useRef, useState } from 'react'
+
import {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
@@ -15,12 +18,10 @@ import {
DropdownMenuRadioItem,
DropdownMenuTrigger,
IconChevronsDown,
- IconEdit,
- IconLoader,
- IconRefreshCw,
+ IconPlusCircle,
IconSearch,
IconX,
- Input,
+ cn,
} from 'ui'
import { ProtectedSchemaModal } from 'components/interfaces/Database/ProtectedSchemaWarning'
@@ -47,6 +48,9 @@ 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 {
@@ -74,7 +78,6 @@ const TableEditorMenu = () => {
}
)
- const totalCount = data?.pages?.[0].data.count
const entityTypes = useMemo(
() => data?.pages.flatMap((page) => page.data.entities),
[data?.pages]
@@ -92,20 +95,35 @@ const TableEditorMenu = () => {
await refetch()
}
+ refreshTables
const [protectedSchemas] = partition(
(schemas ?? []).sort((a, b) => a.name.localeCompare(b.name)),
(schema) => EXCLUDED_SCHEMAS.includes(schema?.name ?? '')
)
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
- className="pt-5 flex flex-col flex-grow space-y-4 h-full"
+ className="pt-5 flex flex-col flex-grow space-y-3 h-full"
style={{ maxHeight: 'calc(100vh - 48px)' }}
>
<SchemaSelector
- className="mx-4"
+ className="mx-4 h-7"
selectedSchemaName={snap.selectedSchemaName}
onSelectSchema={(name: string) => {
setSearchText('')
@@ -115,7 +133,7 @@ const TableEditorMenu = () => {
onSelectCreateSchema={() => snap.onAddSchema()}
/>
- <div className="space-y-1 mx-4">
+ <div className="grid gap-3 mx-4 zans">
{!isLocked ? (
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger className="w-full">
@@ -126,11 +144,11 @@ const TableEditorMenu = () => {
size="tiny"
icon={
<div className="text-foreground-lighter">
- <IconEdit size={14} strokeWidth={1.5} />
+ <IconPlusCircle size={14} strokeWidth={1.5} />
</div>
}
type="default"
- style={{ justifyContent: 'start' }}
+ className="justify-start h-7"
onClick={snap.onAddTable}
>
<span>New table</span>
@@ -156,9 +174,7 @@ const TableEditorMenu = () => {
</Tooltip.Root>
) : (
<Alert_Shadcn_>
- <AlertTitle_Shadcn_ className="text-xs tracking-normal">
- Viewing protected schema
- </AlertTitle_Shadcn_>
+ <AlertTitle_Shadcn_ className="text-sm">Viewing protected schema</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_ className="text-xs">
<p className="mb-2">
This schema is managed by Supabase and is read-only through the table editor
@@ -169,67 +185,112 @@ const TableEditorMenu = () => {
</AlertDescription_Shadcn_>
</Alert_Shadcn_>
)}
-
- {/* Table search input */}
- <div className="mb-2 block">
- <Input
- className="table-editor-search border-none"
- icon={
- isSearching ? (
- <IconLoader
- className="animate-spin text-foreground-lighter"
- size={12}
- strokeWidth={1.5}
- />
- ) : (
- <IconSearch className="text-foreground-lighter" size={12} strokeWidth={1.5} />
- )
- }
- placeholder="Search tables"
- 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>
- )
- }
- />
- </div>
</div>
- <nav className="flex flex-auto flex-col gap-2 pb-4 px-2">
- <div className="flex items-center justify-between w-full px-3">
- <div className="flex items-center gap-1 text-sm text-foreground-lighter">
- <p>Tables</p>
- {totalCount !== undefined && (
- <p style={{ fontVariantNumeric: 'tabular-nums' }}>({totalCount})</p>
- )}
+ <div className="flex flex-auto flex-col gap-2 pb-4 px-2">
+ <div className="relative">
+ <div className="relative flex items-center text-foreground-lighter">
+ <AnimatePresence>
+ {isSearchOpen && (
+ <motion.div
+ initial={{ x: 10, opacity: 0 }}
+ animate={{ x: 0, opacity: 1, transition: { duration: 0.2 } }}
+ exit={{ x: 20, opacity: 0, transition: { duration: 0 } }}
+ className="absolute top-0 left-2"
+ >
+ <label htmlFor={'search-tables'} className="relative">
+ <span className="sr-only">Search tables</span>
+ <input
+ id="search-tables"
+ name="search-tables"
+ type="text"
+ placeholder="Search..."
+ className={cn(
+ 'bg-default text-foreground rounded-none px-1 py-1 h-5 w-44 text-sm',
+ 'border-b outline-none ',
+ 'border-transparent focus:border-transparent focus:ring-2'
+ )}
+ 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('')
+ }
+ if (e.key === 'Backspace' && searchText.length === 0) {
+ setIsSearchOpen(false)
+ }
+ }}
+ />
+ <div
+ className={cn(
+ 'absolute -bottom-1 w-full h-px bg-border transition-colors',
+ isSearchInputFocused && 'bg-border-stronger'
+ )}
+ ></div>
+ </label>
+ </motion.div>
+ )}
+ </AnimatePresence>
+ <motion.button
+ onClick={
+ !isSearchOpen
+ ? () => expandSearch()
+ : () => {
+ setSearchText('')
+ expandSearch()
+ }
+ }
+ initial={{ x: 0 }}
+ animate={{ x: isSearchOpen ? 185 : 0, transition: { duration: 0 } }}
+ className="px-2 py-0.5 rounded-md mt-1 transition transform hover:scale-105 focus:ring-2 "
+ >
+ {isSearchOpen ? (
+ isSearching ? (
+ <Loader2
+ className="w-4 h-4 animate-spin text-foreground"
+ size={15}
+ strokeWidth={1}
+ />
+ ) : (
+ <IconX className={cn('w-4 h-4 hover:text-foreground transition-colors')} />
+ )
+ ) : (
+ <IconSearch className={cn('w-4 h-4 hover:text-foreground transition-colors')} />
+ )}
+ </motion.button>
</div>
-
- <div className="flex gap-3 items-center">
+ <div className="flex gap-3 items-center absolute right-1 top-1.5">
<DropdownMenu>
<Tooltip.Root delayDuration={0}>
<DropdownMenuTrigger asChild>
<Tooltip.Trigger>
- <div className="text-foreground-lighter transition-colors hover:text-foreground">
- <IconChevronsDown size={18} strokeWidth={1} />
- </div>
+ <IconChevronsDown
+ size={18}
+ strokeWidth={1}
+ className="text-foreground-lighter transition-colors hover:text-foreground"
+ />
</Tooltip.Trigger>
</DropdownMenuTrigger>
<Tooltip.Portal>
- <Tooltip.Content side="bottom">
+ <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" />
- <div
- className={[
- 'rounded bg-alternative py-1 px-2 leading-none shadow',
- 'border border-background',
- ].join(' ')}
- >
- <span className="text-xs">Sort By</span>
- </div>
+ Sort By
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
@@ -248,13 +309,6 @@ const TableEditorMenu = () => {
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
-
- <button
- className="cursor-pointer text-foreground-lighter transition-colors hover:text-foreground"
- onClick={refreshTables}
- >
- <IconRefreshCw className={isRefetching ? 'animate-spin' : ''} size={14} />
- </button>
</div>
</div>
@@ -288,7 +342,6 @@ const TableEditorMenu = () => {
</p>
</div>
)}
-
{(entityTypes?.length ?? 0) > 0 && (
<div className="flex flex-1">
<InfiniteList
@@ -308,7 +361,7 @@ const TableEditorMenu = () => {
)}
</>
)}
- </nav>
+ </div>
</div>
<ProtectedSchemaModal visible={showModal} onClose={() => setShowModal(false)} />
diff --git a/apps/studio/data/entity-types/entity-type-query.ts b/apps/studio/data/entity-types/entity-type-query.ts
index 36bb8c2dd97..fd421fdd095 100644
--- a/apps/studio/data/entity-types/entity-type-query.ts
+++ b/apps/studio/data/entity-types/entity-type-query.ts
@@ -42,6 +42,7 @@ export type Entity = {
name: string
type: ENTITY_TYPE
comment: string | null
+ rls_enabled: boolean
}
export type EntityType = Entity | null
diff --git a/apps/studio/data/entity-types/entity-types-infinite-query.ts b/apps/studio/data/entity-types/entity-types-infinite-query.ts
index 328f3bb4bd7..8e911e2af3d 100644
--- a/apps/studio/data/entity-types/entity-types-infinite-query.ts
+++ b/apps/studio/data/entity-types/entity-types-infinite-query.ts
@@ -49,7 +49,8 @@ export async function getEntityTypes(
when 'p' then 5
end as "type_sort",
obj_description(c.oid) as "comment",
- count(*) over() as "count"
+ count(*) over() as "count",
+ c.relrowsecurity as "rls_enabled"
from
pg_namespace nc
join pg_class c on nc.oid = c.relnamespace
@@ -78,7 +79,8 @@ export async function getEntityTypes(
'schema', r.schema,
'name', r.name,
'type', r.type,
- 'comment', r.comment
+ 'comment', r.comment,
+ 'rls_enabled', r.rls_enabled
)
order by ${outerOrderBy}
), '[]'::jsonb),