Skip to content

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

Refactor menu items for storage, sql editor and table editor

Joshen Lime8b67a555710
diff --git a/studio/components/layouts/SQLEditorLayout/QueryItem.tsx b/studio/components/layouts/SQLEditorLayout/QueryItem.tsx
index ef34223da2c..fc80ba9a50a 100644
--- a/studio/components/layouts/SQLEditorLayout/QueryItem.tsx
+++ b/studio/components/layouts/SQLEditorLayout/QueryItem.tsx
@@ -1,7 +1,6 @@
import { useState } from 'react'
import { useParams } from 'common'
import QueryTab from 'localStores/sqlEditor/QueryTab'
-import ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem'
import ConfirmationModal from 'components/ui/ConfirmationModal'
import { useContentDeleteMutation } from 'data/content/content-delete-mutation'
import { useStore } from 'hooks'
@@ -9,26 +8,38 @@ import { IS_PLATFORM } from 'lib/constants'
import { observer } from 'mobx-react-lite'
import { Dropdown, IconEdit2, IconTrash, Button, IconChevronDown, Modal } from 'ui'
import RenameQueryModal from 'components/interfaces/SQLEditor/RenameQueryModal'
+import clsx from 'clsx'
+import Link from 'next/link'
export interface QueryItemProps {
tabInfo: QueryTab
- canCreateSQLSnippet: boolean
}
-const QueryItem = ({ tabInfo, canCreateSQLSnippet }: QueryItemProps) => {
+const QueryItem = ({ tabInfo }: QueryItemProps) => {
const { ref, id: activeId } = useParams()
const { id, name } = tabInfo || {}
- const active = id === activeId
+ const isActive = id === activeId
return (
- <ProductMenuItem
+ <div
key={id}
- isActive={active}
- name={name}
- action={active && canCreateSQLSnippet && <QueryItemActions tabInfo={tabInfo} />}
- textClassName="w-44"
- url={`/project/${ref}/sql/${id}`}
- />
+ className={clsx(
+ 'flex items-center justify-between rounded-md group',
+ isActive && 'text-scale-1200 bg-scale-300'
+ )}
+ >
+ <Link href={`/project/${ref}/sql/${id}`}>
+ <a className="py-1 px-3 w-full">
+ <p
+ title={name}
+ className="text-sm text-scale-1100 group-hover:text-scale-1200 transition"
+ >
+ {name}
+ </p>
+ </a>
+ </Link>
+ <div className="pr-3">{isActive && <QueryItemActions tabInfo={tabInfo} />}</div>
+ </div>
)
}
@@ -92,7 +103,7 @@ const QueryItemActions = observer(({ tabInfo }: { tabInfo: QueryTab }) => {
<Button
as="span"
type="text"
- icon={<IconChevronDown size={12} />}
+ icon={<IconChevronDown size="tiny" strokeWidth={2} className="text-scale-1100" />}
style={{ padding: '3px' }}
/>
</Dropdown>
diff --git a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
index b438b64be45..05bd2cdb057 100644
--- a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
+++ b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
@@ -137,13 +137,7 @@ const SideBarContent = observer(() => {
<div className="space-y-1">
{favouriteTabs.map((tabInfo: any) => {
const { id } = tabInfo || {}
- return (
- <QueryItem
- key={id}
- tabInfo={tabInfo}
- canCreateSQLSnippet={canCreateSQLSnippet}
- />
- )
+ return <QueryItem key={id} tabInfo={tabInfo} />
})}
</div>
</div>
@@ -154,13 +148,7 @@ const SideBarContent = observer(() => {
<div className="space-y-1">
{queryTabs.map((tabInfo: any) => {
const { id } = tabInfo || {}
- return (
- <QueryItem
- key={id}
- tabInfo={tabInfo}
- canCreateSQLSnippet={canCreateSQLSnippet}
- />
- )
+ return <QueryItem key={id} tabInfo={tabInfo} />
})}
</div>
</div>
diff --git a/studio/components/layouts/StorageLayout/BucketRow.tsx b/studio/components/layouts/StorageLayout/BucketRow.tsx
index 79e9cf91ace..e2784a7a87a 100644
--- a/studio/components/layouts/StorageLayout/BucketRow.tsx
+++ b/studio/components/layouts/StorageLayout/BucketRow.tsx
@@ -1,12 +1,12 @@
-import { FC } from 'react'
-import { Badge, Dropdown, IconLoader, IconMoreVertical, IconTrash } from 'ui'
+import { Badge, Button, Dropdown, IconChevronDown, IconLoader, IconTrash } from 'ui'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { checkPermissions } from 'hooks'
-import ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem'
import { STORAGE_ROW_STATUS } from 'components/to-be-cleaned/Storage/Storage.constants'
+import clsx from 'clsx'
+import Link from 'next/link'
-interface Props {
+interface BucketRowProps {
bucket: any
projectRef?: string
isSelected: boolean
@@ -14,32 +14,40 @@ interface Props {
onSelectToggleBucketPublic: (bucket: any) => void
}
-const BucketRow: FC<Props> = ({
+const BucketRow = ({
bucket = {},
projectRef = '',
isSelected = false,
onSelectDeleteBucket = () => {},
onSelectToggleBucketPublic = () => {},
-}) => {
+}: BucketRowProps) => {
const canUpdateBuckets = checkPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
return (
- <ProductMenuItem
+ <div
key={bucket.id}
- name={
- <div className="flex items-center justify-between space-x-2 truncate w-full">
- <p className="truncate" title={bucket.name}>
- {bucket.name}
- </p>
- {bucket.public && <Badge color="yellow">Public</Badge>}
- </div>
- }
- url={`/project/${projectRef}/storage/buckets/${bucket.id}`}
- isActive={isSelected}
- action={
- bucket.status === STORAGE_ROW_STATUS.LOADING ? (
+ className={clsx(
+ 'group flex items-center justify-between rounded-md',
+ isSelected && 'text-scale-1200 bg-scale-300'
+ )}
+ >
+ <Link href={`/project/${projectRef}/storage/buckets/${bucket.id}`}>
+ <a className="py-1 px-3 w-full">
+ <div className="flex items-center justify-between space-x-2 truncate w-full">
+ <p
+ className="text-sm text-scale-1100 group-hover:text-scale-1200 transition truncate"
+ title={bucket.name}
+ >
+ {bucket.name}
+ </p>
+ {bucket.public && <Badge color="yellow">Public</Badge>}
+ </div>
+ </a>
+ </Link>
+ <div className="pr-3">
+ {bucket.status === STORAGE_ROW_STATUS.LOADING ? (
<IconLoader className="animate-spin" size={16} strokeWidth={2} />
- ) : canUpdateBuckets && bucket.status === STORAGE_ROW_STATUS.READY ? (
+ ) : canUpdateBuckets && bucket.status === STORAGE_ROW_STATUS.READY && isSelected ? (
<Dropdown
side="bottom"
align="start"
@@ -60,17 +68,16 @@ const BucketRow: FC<Props> = ({
</Dropdown.Item>,
]}
>
- <IconMoreVertical
- className="opacity-0 group-hover:opacity-100"
- size="tiny"
- strokeWidth={2}
+ <Button
+ as="span"
+ type="text"
+ icon={<IconChevronDown size="tiny" strokeWidth={2} className="text-scale-1100" />}
+ style={{ padding: '3px' }}
/>
</Dropdown>
- ) : (
- <div />
- )
- }
- />
+ ) : null}
+ </div>
+ </div>
)
}
diff --git a/studio/components/layouts/TableEditorLayout/EntityListItem.tsx b/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
new file mode 100644
index 00000000000..8d1de94835b
--- /dev/null
+++ b/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
@@ -0,0 +1,169 @@
+import clsx from 'clsx'
+import SVG from 'react-inlinesvg'
+import * as Tooltip from '@radix-ui/react-tooltip'
+import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
+import { Entity } from 'data/entity-types/entity-type-query'
+import Link from 'next/link'
+import { Dropdown, IconEdit, IconCopy, IconLock, IconTrash, IconChevronDown } from 'ui'
+import { BASE_PATH } from 'lib/constants'
+
+export interface EntityListItemProps {
+ id: number
+ projectRef: string
+ item: Entity
+ isLocked: boolean
+ onEditTable: (table: Entity) => void
+ onDeleteTable: (table: Entity) => void
+ onDuplicateTable: (table: Entity) => void
+ isLoadingTableMetadata?: boolean
+}
+
+const EntityListItem = ({
+ id,
+ projectRef,
+ item: entity,
+ isLocked,
+ onEditTable,
+ onDeleteTable,
+ onDuplicateTable,
+ isLoadingTableMetadata,
+}: EntityListItemProps) => {
+ const isActive = Number(id) === entity.id
+ const formatTooltipText = (entityType: string) => {
+ return Object.entries(ENTITY_TYPE)
+ .find(([, value]) => value === entityType)?.[0]
+ ?.toLowerCase()
+ ?.split('_')
+ ?.join(' ')
+ }
+
+ return (
+ <div
+ className={clsx(
+ 'group flex items-center justify-between rounded-md',
+ isActive && 'text-scale-1200 bg-scale-300'
+ )}
+ >
+ <Link href={`/project/${projectRef}/editor/${entity.id}`}>
+ <a className="flex items-center py-1 px-3 w-full space-x-3">
+ <Tooltip.Root delayDuration={0} disableHoverableContent={true}>
+ <Tooltip.Trigger className="flex items-center">
+ {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"')
+ }
+ />
+ ) : 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"')
+ }
+ />
+ ) : (
+ <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-scale-1100 bg-scale-800'
+ )}
+ >
+ {Object.entries(ENTITY_TYPE)
+ .find(([, value]) => value === entity.type)?.[0]?.[0]
+ ?.toUpperCase()}
+ </div>
+ )}
+ </Tooltip.Trigger>
+ <Tooltip.Portal>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',
+ 'border border-scale-200',
+ ].join(' ')}
+ >
+ <span className="text-xs text-scale-1200 capitalize">
+ {formatTooltipText(entity.type)}
+ </span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ </Tooltip.Root>
+ <p
+ title={entity.name}
+ className="text-sm text-scale-1100 group-hover:text-scale-1200 transition"
+ >
+ {entity.name}
+ </p>
+ </a>
+ </Link>
+ <div className="pr-3">
+ {entity.type === ENTITY_TYPE.TABLE && isActive && !isLocked && (
+ <Dropdown
+ size="small"
+ side="bottom"
+ align="start"
+ overlay={[
+ <Dropdown.Item
+ key="edit-table"
+ icon={<IconEdit size="tiny" />}
+ onClick={(e) => {
+ e.stopPropagation()
+ onEditTable(entity)
+ }}
+ disabled={isLoadingTableMetadata}
+ >
+ Edit Table
+ </Dropdown.Item>,
+ <Dropdown.Item
+ key="duplicate-table"
+ icon={<IconCopy size="tiny" />}
+ onClick={(e) => {
+ e.stopPropagation()
+ onDuplicateTable(entity)
+ }}
+ disabled={isLoadingTableMetadata}
+ >
+ Duplicate Table
+ </Dropdown.Item>,
+ <Link href={`/project/${projectRef}/auth/policies?search=${entity.id}`}>
+ <a>
+ <Dropdown.Item key="delete-table" icon={<IconLock size="tiny" />}>
+ View Policies
+ </Dropdown.Item>
+ </a>
+ </Link>,
+ <Dropdown.Separator key="separator" />,
+ <Dropdown.Item
+ key="delete-table"
+ icon={<IconTrash size="tiny" />}
+ onClick={(e) => {
+ e.stopPropagation()
+ onDeleteTable(entity)
+ }}
+ disabled={isLoadingTableMetadata}
+ >
+ Delete Table
+ </Dropdown.Item>,
+ ]}
+ >
+ <div className="text-scale-900 transition-colors hover:text-scale-1200">
+ <IconChevronDown size={14} strokeWidth={2} />
+ </div>
+ </Dropdown>
+ )}
+ </div>
+ </div>
+ )
+}
+
+export default EntityListItem
diff --git a/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx b/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
index 3622dc6ad62..c143cfa0398 100644
--- a/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
+++ b/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
@@ -1,21 +1,15 @@
-import SVG from 'react-inlinesvg'
import { useMemo, useState } from 'react'
-import Link from 'next/link'
import { noop, partition } from 'lodash'
import { observer } from 'mobx-react-lite'
import {
Button,
Dropdown,
IconCheck,
- IconChevronDown,
IconChevronsDown,
- IconCopy,
IconEdit,
IconLoader,
- IconLock,
IconRefreshCw,
IconSearch,
- IconTrash,
IconX,
Input,
Listbox,
@@ -26,15 +20,12 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import type { PostgresSchema } from '@supabase/postgres-meta'
import { useParams } from 'common/hooks'
-import { BASE_PATH } from 'lib/constants'
import { checkPermissions, useStore, useLocalStorage } from 'hooks'
-import ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem'
import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-query'
-import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { Entity } from 'data/entity-types/entity-type-query'
import { useProjectContext } from '../ProjectLayout/ProjectContext'
import InfiniteList from 'components/ui/InfiniteList'
-import clsx from 'clsx'
+import EntityListItem from './EntityListItem'
export interface TableEditorMenuProps {
selectedSchema?: string
@@ -363,154 +354,3 @@ const TableEditorMenu = ({
}
export default observer(TableEditorMenu)
-
-export interface EntityListItemProps {
- id: number
- projectRef: string
- item: Entity
- isLocked: boolean
- onEditTable: (table: Entity) => void
- onDeleteTable: (table: Entity) => void
- onDuplicateTable: (table: Entity) => void
- isLoadingTableMetadata?: boolean
-}
-
-const EntityListItem = ({
- id,
- projectRef,
- item: entity,
- isLocked,
- onEditTable,
- onDeleteTable,
- onDuplicateTable,
- isLoadingTableMetadata = false,
-}: EntityListItemProps) => {
- const isActive = Number(id) === entity.id
- const formatTooltipText = (entityType: string) => {
- return Object.entries(ENTITY_TYPE)
- .find(([, value]) => value === entityType)?.[0]
- ?.toLowerCase()
- ?.split('_')
- ?.join(' ')
- }
-
- return (
- <ProductMenuItem
- url={`/project/${projectRef}/editor/${entity.id}`}
- name={entity.name}
- hoverText={entity.comment ? entity.comment : entity.name}
- isActive={isActive}
- icon={
- <Tooltip.Root delayDuration={0} disableHoverableContent={true}>
- <Tooltip.Trigger className="w-full flex items-center">
- {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"')
- }
- />
- ) : 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"')
- }
- />
- ) : (
- <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-scale-1100 bg-scale-800'
- )}
- >
- {Object.entries(ENTITY_TYPE)
- .find(([, value]) => value === entity.type)?.[0]?.[0]
- ?.toUpperCase()}
- </div>
- )}
- </Tooltip.Trigger>
- <Tooltip.Portal>
- <Tooltip.Content side="bottom">
- <Tooltip.Arrow className="radix-tooltip-arrow" />
- <div
- className={[
- 'rounded bg-scale-100 py-1 px-2 leading-none shadow',
- 'border border-scale-200',
- ].join(' ')}
- >
- <span className="text-xs text-scale-1200 capitalize">
- {formatTooltipText(entity.type)}
- </span>
- </div>
- </Tooltip.Content>
- </Tooltip.Portal>
- </Tooltip.Root>
- }
- action={
- entity.type === ENTITY_TYPE.TABLE &&
- isActive &&
- !isLocked && (
- <Dropdown
- size="small"
- side="bottom"
- align="start"
- overlay={[
- <Dropdown.Item
- key="edit-table"
- icon={<IconEdit size="tiny" />}
- onClick={(e) => {
- e.stopPropagation()
- onEditTable(entity)
- }}
- disabled={isLoadingTableMetadata}
- >
- Edit Table
- </Dropdown.Item>,
- <Dropdown.Item
- key="duplicate-table"
- icon={<IconCopy size="tiny" />}
- onClick={(e) => {
- e.stopPropagation()
- onDuplicateTable(entity)
- }}
- disabled={isLoadingTableMetadata}
- >
- Duplicate Table
- </Dropdown.Item>,
- <Link href={`/project/${projectRef}/auth/policies?search=${entity.id}`}>
- <a>
- <Dropdown.Item key="delete-table" icon={<IconLock size="tiny" />}>
- View Policies
- </Dropdown.Item>
- </a>
- </Link>,
- <Dropdown.Separator key="separator" />,
- <Dropdown.Item
- key="delete-table"
- icon={<IconTrash size="tiny" />}
- onClick={(e) => {
- e.stopPropagation()
- onDeleteTable(entity)
- }}
- disabled={isLoadingTableMetadata}
- >
- Delete Table
- </Dropdown.Item>,
- ]}
- >
- <div className="text-scale-900 transition-colors hover:text-scale-1200">
- <IconChevronDown size={14} strokeWidth={2} />
- </div>
- </Dropdown>
- )
- }
- />
- )
-}
diff --git a/studio/components/ui/ProductMenu/ProductMenuItem.tsx b/studio/components/ui/ProductMenu/ProductMenuItem.tsx
index 2b8dedb6ec3..0b7904e8a1f 100644
--- a/studio/components/ui/ProductMenu/ProductMenuItem.tsx
+++ b/studio/components/ui/ProductMenu/ProductMenuItem.tsx
@@ -1,13 +1,12 @@
import Link from 'next/link'
-import { FC, ReactNode } from 'react'
-import { Badge, Button, Menu } from 'ui'
+import { ReactNode } from 'react'
+import { Button, Menu } from 'ui'
-interface Props {
+interface ProductMenuItemProps {
name: string | ReactNode
isActive: boolean
isExternal?: boolean
icon?: ReactNode
- action?: ReactNode
url?: string
target?: '_blank' | '_self'
onClick?: () => void
@@ -16,45 +15,18 @@ interface Props {
label?: string
}
-const Label = ({ label }: { label: string }) => {
- const color =
- label.toLowerCase() === 'new' ? 'text-brand-900 bg-brand-500' : 'text-amber-900 bg-amber-500'
-
- return (
- <span
- className={[
- `text-mono
- h-[18px],
- flex
- items-center
- justify-center
- px-1.5
- rounded-full
- tracking-widest
- text-[10px]
- font-medium
- truncate`,
- color,
- ].join(' ')}
- >
- {label}
- </span>
- )
-}
-
-const ProductMenuItem: FC<Props> = ({
+const ProductMenuItem = ({
name = '',
isActive,
isExternal,
icon,
- action,
url = '',
target = '_self',
onClick,
textClassName = '',
hoverText = '',
label,
-}) => {
+}: ProductMenuItemProps) => {
const menuItem = (
<Menu.Item icon={icon} rounded active={isActive} onClick={onClick}>
<div className="flex w-full items-center justify-between gap-1">
@@ -62,12 +34,11 @@ const ProductMenuItem: FC<Props> = ({
title={hoverText ? hoverText : typeof name === 'string' ? name : ''}
className={'flex items-center gap-2 truncate w-full ' + textClassName}
>
- <span className="truncate">{name}{' '}</span>
+ <span className="truncate">{name} </span>
{label !== undefined && (
<span className="text-orange-800 text-xs font-normal truncate">{label}</span>
)}
</div>
- {action}
</div>
</Menu.Item>
)