Skip to content

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

Chore/update query performance page (#22467)

Joshen Lim65d572e1d28f
diff --git a/apps/studio/components/interfaces/Account/AuditLogs.tsx b/apps/studio/components/interfaces/Account/AuditLogs.tsx
index 2273b229437..5af85ed5787 100644
--- a/apps/studio/components/interfaces/Account/AuditLogs.tsx
+++ b/apps/studio/components/interfaces/Account/AuditLogs.tsx
@@ -3,10 +3,11 @@ import dayjs from 'dayjs'
import { useEffect, useState } from 'react'
import { Alert, Button, IconArrowDown, IconArrowUp, IconRefreshCw } from 'ui'
-import { FilterPopover, LogDetailsPanel } from 'components/interfaces/AuditLogs'
+import { LogDetailsPanel } from 'components/interfaces/AuditLogs'
import Table from 'components/to-be-cleaned/Table'
import AlertError from 'components/ui/AlertError'
import { DatePicker } from 'components/ui/DatePicker'
+import { FilterPopover } from 'components/ui/FilterPopover'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import type { AuditLog } from 'data/organizations/organization-audit-logs-query'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
diff --git a/apps/studio/components/interfaces/AuditLogs/index.ts b/apps/studio/components/interfaces/AuditLogs/index.ts
index 082c6e83fde..25dafb4f074 100644
--- a/apps/studio/components/interfaces/AuditLogs/index.ts
+++ b/apps/studio/components/interfaces/AuditLogs/index.ts
@@ -1,2 +1 @@
-export { default as FilterPopover } from './FilterPopover'
export { default as LogDetailsPanel } from './LogDetailsPanel'
diff --git a/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx b/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
index 62a2fcd0390..6a2aabfa437 100644
--- a/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
+++ b/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
@@ -7,7 +7,6 @@ import { Button, IconExternalLink, IconSearch, Input } from 'ui'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import AlertError from 'components/ui/AlertError'
-import { FormHeader } from 'components/ui/Forms'
import NoSearchResults from 'components/ui/NoSearchResults'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useDatabaseHooksQuery } from 'data/database-triggers/database-triggers-query'
@@ -45,95 +44,87 @@ const HooksList = ({ createHook = noop, editHook = noop, deleteHook = noop }: Ho
const isPermissionsLoaded = usePermissionsLoaded()
return (
- <>
+ <div className="w-full space-y-4">
<div className="flex items-center justify-between">
- <FormHeader
- title="Database Webhooks"
- description="Send real-time data from your database to another system whenever a table event occurs"
+ <Input
+ placeholder="Search for a webhook"
+ size="small"
+ icon={<IconSearch size="tiny" />}
+ value={filterString}
+ className="w-64"
+ onChange={(e) => setFilterString(e.target.value)}
/>
- </div>
- <div className="w-full space-y-4">
- <div className="flex items-center justify-between">
- <Input
- placeholder="Search for a webhook"
- size="small"
- icon={<IconSearch size="tiny" />}
- value={filterString}
- className="w-64"
- onChange={(e) => setFilterString(e.target.value)}
- />
- <div className="flex items-center space-x-2">
- <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>
- <Link
- href="https://supabase.com/docs/guides/database/webhooks"
- target="_blank"
- rel="noreferrer"
+ <div className="flex items-center space-x-2">
+ <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>
+ <Link
+ href="https://supabase.com/docs/guides/database/webhooks"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Documentation
+ </Link>
+ </Button>
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger asChild>
+ <Button
+ disabled={!isPermissionsLoaded || !canCreateWebhooks}
+ onClick={() => createHook()}
>
- Documentation
- </Link>
- </Button>
- <Tooltip.Root delayDuration={0}>
- <Tooltip.Trigger asChild>
- <Button
- disabled={!isPermissionsLoaded || !canCreateWebhooks}
- onClick={() => createHook()}
- >
- Create a new hook
- </Button>
- </Tooltip.Trigger>
- {isPermissionsLoaded && !canCreateWebhooks && (
- <Tooltip.Portal>
- <Tooltip.Content side="bottom">
- <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">
- You need additional permissions to create webhooks
- </span>
- </div>
- </Tooltip.Content>
- </Tooltip.Portal>
- )}
- </Tooltip.Root>
- </div>
+ Create a new hook
+ </Button>
+ </Tooltip.Trigger>
+ {isPermissionsLoaded && !canCreateWebhooks && (
+ <Tooltip.Portal>
+ <Tooltip.Content side="bottom">
+ <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">
+ You need additional permissions to create webhooks
+ </span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ )}
+ </Tooltip.Root>
</div>
+ </div>
- {isLoading && (
- <div className="py-4">
- <GenericSkeletonLoader />
- </div>
- )}
+ {isLoading && (
+ <div className="py-4">
+ <GenericSkeletonLoader />
+ </div>
+ )}
- {isError && <AlertError error={error} subject="Failed to retrieve database webhooks" />}
+ {isError && <AlertError error={error} subject="Failed to retrieve database webhooks" />}
- {isSuccess &&
- (hooks.length <= 0 ? (
- <HooksListEmpty />
- ) : (
- <>
- {filteredHooks.length <= 0 && (
- <NoSearchResults
- searchString={filterString}
- onResetFilter={() => setFilterString('')}
- />
- )}
- {filteredHookSchemas.map((schema: any) => (
- <SchemaTable
- key={schema}
- filterString={filterString}
- schema={schema}
- editHook={editHook}
- deleteHook={deleteHook}
- />
- ))}
- </>
- ))}
- </div>
- </>
+ {isSuccess &&
+ (hooks.length <= 0 ? (
+ <HooksListEmpty />
+ ) : (
+ <>
+ {filteredHooks.length <= 0 && (
+ <NoSearchResults
+ searchString={filterString}
+ onResetFilter={() => setFilterString('')}
+ />
+ )}
+ {filteredHookSchemas.map((schema: any) => (
+ <SchemaTable
+ key={schema}
+ filterString={filterString}
+ schema={schema}
+ editHook={editHook}
+ deleteHook={deleteHook}
+ />
+ ))}
+ </>
+ ))}
+ </div>
)
}
diff --git a/apps/studio/components/interfaces/Database/Indexes/Indexes.tsx b/apps/studio/components/interfaces/Database/Indexes/Indexes.tsx
index bcf10959d40..14f9af79eaa 100644
--- a/apps/studio/components/interfaces/Database/Indexes/Indexes.tsx
+++ b/apps/studio/components/interfaces/Database/Indexes/Indexes.tsx
@@ -1,23 +1,10 @@
import { partition, sortBy } from 'lodash'
-import Link from 'next/link'
import { useEffect, useState } from 'react'
import toast from 'react-hot-toast'
-import {
- AlertDescription_Shadcn_,
- AlertTitle_Shadcn_,
- Alert_Shadcn_,
- Button,
- IconAlertCircle,
- IconAlertTriangle,
- IconExternalLink,
- IconSearch,
- IconTrash,
- Input,
- Modal,
- SidePanel,
-} from 'ui'
+import { Button, IconAlertCircle, IconSearch, IconTrash, Input, SidePanel } from 'ui'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
+import { useParams } from 'common'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import Table from 'components/to-be-cleaned/Table'
import AlertError from 'components/ui/AlertError'
@@ -30,7 +17,6 @@ import { useExecuteSqlMutation } from 'data/sql/execute-sql-mutation'
import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas'
import ProtectedSchemaWarning from '../ProtectedSchemaWarning'
import CreateIndexSidePanel from './CreateIndexSidePanel'
-import { useParams } from 'common'
const Indexes = () => {
const { project } = useProjectContext()
@@ -110,35 +96,6 @@ const Indexes = () => {
return (
<>
<div className="pb-8">
- <div className="flex items-center justify-between mb-6">
- <div className="space-y-1">
- <h3 className="text-xl text-foreground">Database Indexes</h3>
- <div className="text-sm text-foreground-lighter">
- Improve query performance against your database
- </div>
- </div>
- <div className="flex items-center space-x-2">
- <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>
- <Link
- href="https://supabase.com/docs/guides/database/query-optimization"
- target="_blank"
- rel="noreferrer"
- >
- Documentation
- </Link>
- </Button>
- <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>
- <Link
- href="https://supabase.com/docs/guides/database/extensions/index_advisor"
- target="_blank"
- rel="noreferrer"
- >
- Optimization with index_advisor
- </Link>
- </Button>
- </div>
- </div>
-
<div className="flex flex-col gap-y-4">
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
diff --git a/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx b/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
index d752098009c..74896cc2b27 100644
--- a/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
+++ b/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
@@ -1,7 +1,7 @@
import dayjs from 'dayjs'
import Link from 'next/link'
import { useState } from 'react'
-import { Alert, Button, IconExternalLink, IconSearch, Input, SidePanel } from 'ui'
+import { Alert, Button, IconSearch, Input, SidePanel } from 'ui'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import Table from 'components/to-be-cleaned/Table'
@@ -28,131 +28,109 @@ const Migrations = () => {
return (
<>
- <div>
- <div className="flex items-center justify-between mb-6">
- <div>
- <h3 className="mb-1 text-xl text-foreground">Database Migrations</h3>
- <div className="text-sm text-foreground-lighter">
- History of migrations that have been run on your database
- </div>
- </div>
- <div className="flex items-center space-x-2">
- <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>
- <Link
- href="https://supabase.com/docs/guides/getting-started/local-development#database-migrations"
- target="_blank"
- rel="noreferrer"
- >
- Documentation
- </Link>
- </Button>
- </div>
+ {isLoading && (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
</div>
+ )}
- {isLoading && (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
+ <div>
+ {isError && (
+ <Alert
+ withIcon
+ variant="warning"
+ title="Failed to retrieve migration history for database"
+ actions={[
+ <Button key="contact-support" asChild type="default" className="ml-4">
+ <Link
+ href={`/support/new?ref=${project?.ref}&category=dashboard_bug&subject=Unable%20to%20view%20database%20migrations`}
+ >
+ Contact support
+ </Link>
+ </Button>,
+ ]}
+ >
+ <p className="mb-1">
+ Try refreshing your browser, but if the issue persists, please reach out to us via
+ support.
+ </p>
+ <p>Error: {(error as any)?.message ?? 'Unknown'}</p>
+ </Alert>
)}
+ {isSuccess && (
+ <div>
+ {data.result.length <= 0 && <MigrationsEmptyState />}
- <div>
- {isError && (
- <Alert
- withIcon
- variant="warning"
- title="Failed to retrieve migration history for database"
- actions={[
- <Button key="contact-support" asChild type="default" className="ml-4">
- <Link
- href={`/support/new?ref=${project?.ref}&category=dashboard_bug&subject=Unable%20to%20view%20database%20migrations`}
- >
- Contact support
- </Link>
- </Button>,
- ]}
- >
- <p className="mb-1">
- Try refreshing your browser, but if the issue persists, please reach out to us via
- support.
- </p>
- <p>Error: {(error as any)?.message ?? 'Unknown'}</p>
- </Alert>
- )}
- {isSuccess && (
- <div>
- {data.result.length <= 0 && <MigrationsEmptyState />}
-
- {data.result.length > 0 && (
- <>
- <div className="w-80 mb-4">
- <Input
- size="small"
- placeholder="Search for a migration"
- value={search}
- onChange={(e: any) => setSearch(e.target.value)}
- icon={<IconSearch size="tiny" />}
- />
- </div>
- <Table
- head={[
- <Table.th key="version" style={{ width: '180px' }}>
- Version
- </Table.th>,
- <Table.th key="version">Name</Table.th>,
- <Table.th key="version">Inserted at (UTC)</Table.th>,
- <Table.th key="buttons"></Table.th>,
- ]}
- body={
- migrations.length > 0 ? (
- migrations.map((migration) => {
- // [Joshen] LEFT OFF HERE
- const insertedAt = dayjs(migration.version, 'YYYYMMDDHHmmss').format(
- 'DD MMM YYYY, HH:mm:ss'
- )
+ {data.result.length > 0 && (
+ <>
+ <div className="w-80 mb-4">
+ <Input
+ size="small"
+ placeholder="Search for a migration"
+ value={search}
+ onChange={(e: any) => setSearch(e.target.value)}
+ icon={<IconSearch size="tiny" />}
+ />
+ </div>
+ <Table
+ head={[
+ <Table.th key="version" style={{ width: '180px' }}>
+ Version
+ </Table.th>,
+ <Table.th key="version">Name</Table.th>,
+ <Table.th key="version">Inserted at (UTC)</Table.th>,
+ <Table.th key="buttons"></Table.th>,
+ ]}
+ body={
+ migrations.length > 0 ? (
+ migrations.map((migration) => {
+ // [Joshen] LEFT OFF HERE
+ const insertedAt = dayjs(migration.version, 'YYYYMMDDHHmmss').format(
+ 'DD MMM YYYY, HH:mm:ss'
+ )
- return (
- <Table.tr key={migration.version}>
- <Table.td>{migration.version}</Table.td>
- <Table.td
- className={
- (migration?.name ?? '').length === 0
- ? '!text-foreground-lighter'
- : ''
- }
+ return (
+ <Table.tr key={migration.version}>
+ <Table.td>{migration.version}</Table.td>
+ <Table.td
+ className={
+ (migration?.name ?? '').length === 0
+ ? '!text-foreground-lighter'
+ : ''
+ }
+ >
+ {migration?.name ?? 'Name not available'}
+ </Table.td>
+ <Table.td>{insertedAt}</Table.td>
+ <Table.td align="right">
+ <Button
+ type="default"
+ onClick={() => setSelectedMigration(migration)}
>
- {migration?.name ?? 'Name not available'}
- </Table.td>
- <Table.td>{insertedAt}</Table.td>
- <Table.td align="right">
- <Button
- type="default"
- onClick={() => setSelectedMigration(migration)}
- >
- View migration SQL
- </Button>
- </Table.td>
- </Table.tr>
- )
- })
- ) : (
- <Table.tr>
- <Table.td colSpan={3}>
- <p className="text-sm text-foreground">No results found</p>
- <p className="text-sm text-foreground-light">
- Your search for "{search}" did not return any results
- </p>
- </Table.td>
- </Table.tr>
- )
- }
- />
- </>
- )}
- </div>
- )}
- </div>
+ View migration SQL
+ </Button>
+ </Table.td>
+ </Table.tr>
+ )
+ })
+ ) : (
+ <Table.tr>
+ <Table.td colSpan={3}>
+ <p className="text-sm text-foreground">No results found</p>
+ <p className="text-sm text-foreground-light">
+ Your search for "{search}" did not return any results
+ </p>
+ </Table.td>
+ </Table.tr>
+ )
+ }
+ />
+ </>
+ )}
+ </div>
+ )}
</div>
<SidePanel
diff --git a/apps/studio/components/interfaces/Database/Roles/RolesList.tsx b/apps/studio/components/interfaces/Database/Roles/RolesList.tsx
index 9fc98db4db5..c1b88c56e26 100644
--- a/apps/studio/components/interfaces/Database/Roles/RolesList.tsx
+++ b/apps/studio/components/interfaces/Database/Roles/RolesList.tsx
@@ -1,16 +1,16 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { partition, sortBy } from 'lodash'
+import { Plus, Search, X } from 'lucide-react'
import { useState } from 'react'
-import { Badge, Button, IconPlus, IconSearch, IconX, Input } from 'ui'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
-import { FormHeader } from 'components/ui/Forms'
import NoSearchResults from 'components/ui/NoSearchResults'
import SparkBar from 'components/ui/SparkBar'
import { useDatabaseRolesQuery } from 'data/database-roles/database-roles-query'
import { useMaxConnectionsQuery } from 'data/database/max-connections-query'
import { useCheckPermissions } from 'hooks'
+import { Badge, Button, Input } from 'ui'
import CreateRolePanel from './CreateRolePanel'
import DeleteRoleModal from './DeleteRoleModal'
import RoleRow from './RoleRow'
@@ -59,135 +59,128 @@ const RolesList = () => {
return (
<>
- <div>
- <div className="flex items-center justify-between">
- <FormHeader
- title="Database Roles"
- description="Manage access control to your database through users, groups, and permissions"
+ <div className="mb-4 flex items-center justify-between">
+ <div className="flex items-center space-x-4">
+ <Input
+ size="small"
+ placeholder="Search for a role"
+ icon={<Search size={12} />}
+ value={filterString}
+ onChange={(event: any) => setFilterString(event.target.value)}
+ actions={
+ filterString && (
+ <Button
+ size="tiny"
+ type="text"
+ onClick={() => setFilterString('')}
+ className="px-1 mr-1"
+ >
+ <X size={12} strokeWidth={2} />
+ </Button>
+ )
+ }
/>
+ <div className="flex items-center border border-strong rounded-full w-min h-[34px]">
+ <button
+ className={[
+ 'text-xs w-[90px] h-full text-center rounded-l-full flex items-center justify-center transition',
+ filterType === 'all'
+ ? 'bg-overlay-hover text-foreground'
+ : 'hover:bg-surface-200 text-foreground-light',
+ ].join(' ')}
+ onClick={() => setFilterType('all')}
+ >
+ All roles
+ </button>
+ <div className="h-full w-[1px] border-r border-strong"></div>
+ <button
+ className={[
+ 'text-xs w-[90px] h-full text-center rounded-r-full flex items-center justify-center transition',
+ filterType === 'active'
+ ? 'bg-overlay-hover text-foreground'
+ : 'hover:bg-surface-200 text-foreground-light',
+ ].join(' ')}
+ onClick={() => setFilterType('active')}
+ >
+ Active roles
+ </button>
+ </div>
</div>
-
- <div className="mb-4 flex items-center justify-between">
- <div className="flex items-center space-x-4">
- <Input
- size="small"
- placeholder="Search for a role"
- icon={<IconSearch size="tiny" />}
- value={filterString}
- onChange={(event: any) => setFilterString(event.target.value)}
- actions={
- filterString && (
- <Button
- size="tiny"
- type="text"
- onClick={() => setFilterString('')}
- className="px-1 mr-1"
- >
- <IconX size={12} strokeWidth={2} />
- </Button>
- )
- }
- />
- <div className="flex items-center border border-strong rounded-full w-min h-[34px]">
- <button
+ <div className="flex items-center space-x-6">
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger>
+ <div className="w-42">
+ <SparkBar
+ type="horizontal"
+ // if the maxConnectionLimit is undefined, set totalActiveConnections so that
+ // the width of the bar is set to 100%
+ max={maxConnectionLimit || totalActiveConnections}
+ value={totalActiveConnections}
+ barClass={
+ maxConnectionLimit === 0 || maxConnectionLimit === undefined
+ ? 'bg-control'
+ : totalActiveConnections > 0.9 * maxConnectionLimit
+ ? 'bg-red-800'
+ : totalActiveConnections > 0.75 * maxConnectionLimit
+ ? 'bg-amber-900'
+ : 'bg-green-800'
+ }
+ labelTop={
+ Number.isInteger(maxConnectionLimit)
+ ? `${totalActiveConnections}/${maxConnectionLimit}`
+ : `${totalActiveConnections}`
+ }
+ labelBottom="Active connections"
+ />
+ </div>
+ </Tooltip.Trigger>
+ <Tooltip.Content align="start" side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
className={[
- 'text-xs w-[90px] h-full text-center rounded-l-full flex items-center justify-center transition',
- filterType === 'all'
- ? 'bg-overlay-hover text-foreground'
- : 'hover:bg-surface-200 text-foreground-light',
+ 'rounded bg-alternative py-1 px-2 leading-none shadow',
+ 'border border-background space-y-1',
].join(' ')}
- onClick={() => setFilterType('all')}
>
- All roles
- </button>
- <div className="h-full w-[1px] border-r border-strong"></div>
- <button
- className={[
- 'text-xs w-[90px] h-full text-center rounded-r-full flex items-center justify-center transition',
- filterType === 'active'
- ? 'bg-overlay-hover text-foreground'
- : 'hover:bg-surface-200 text-foreground-light',
- ].join(' ')}
- onClick={() => setFilterType('active')}
+ <p className="text-xs text-foreground-light pr-2">Connections by roles:</p>
+ {rolesWithActiveConnections.map((role) => (
+ <div key={role.id} className="text-xs text-foreground">
+ {role.name}: {role.active_connections}
+ </div>
+ ))}
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Root>
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger asChild>
+ <Button
+ type="primary"
+ disabled={!canUpdateRoles}
+ icon={<Plus size={12} />}
+ onClick={() => setIsCreatingRole(true)}
>
- Active roles
- </button>
- </div>
- </div>
- <div className="flex items-center space-x-6">
- <Tooltip.Root delayDuration={0}>
- <Tooltip.Trigger>
- <div className="w-42">
- <SparkBar
- type="horizontal"
- // if the maxConnectionLimit is undefined, set totalActiveConnections so that
- // the width of the bar is set to 100%
- max={maxConnectionLimit || totalActiveConnections}
- value={totalActiveConnections}
- barClass={
- maxConnectionLimit === 0 || maxConnectionLimit === undefined
- ? 'bg-control'
- : totalActiveConnections > 0.9 * maxConnectionLimit
- ? 'bg-red-800'
- : totalActiveConnections > 0.75 * maxConnectionLimit
- ? 'bg-amber-900'
- : 'bg-green-800'
- }
- labelTop={
- Number.isInteger(maxConnectionLimit)
- ? `${totalActiveConnections}/${maxConnectionLimit}`
- : `${totalActiveConnections}`
- }
- labelBottom="Active connections"
- />
- </div>
- </Tooltip.Trigger>
+ Add role
+ </Button>
+ </Tooltip.Trigger>
+ {!canUpdateRoles && (
<Tooltip.Content align="start" side="bottom">
<Tooltip.Arrow className="radix-tooltip-arrow" />
<div
className={[
'rounded bg-alternative py-1 px-2 leading-none shadow',
- 'border border-background space-y-1',
+ 'border border-background text-xs',
].join(' ')}
>
- <p className="text-xs text-foreground-light pr-2">Connections by roles:</p>
- {rolesWithActiveConnections.map((role) => (
- <div key={role.id} className="text-xs text-foreground">
- {role.name}: {role.active_connections}
- </div>
- ))}
+ You need additional permissions to add a new role
</div>
</Tooltip.Content>
- </Tooltip.Root>
- <Tooltip.Root delayDuration={0}>
- <Tooltip.Trigger asChild>
- <Button
- type="primary"
- disabled={!canUpdateRoles}
- icon={<IconPlus size="tiny" />}
- onClick={() => setIsCreatingRole(true)}
- >
- Add role
- </Button>
- </Tooltip.Trigger>
- {!canUpdateRoles && (
- <Tooltip.Content align="start" side="bottom">
- <Tooltip.Arrow className="radix-tooltip-arrow" />
- <div
- className={[
- 'rounded bg-alternative py-1 px-2 leading-none shadow',
- 'border border-background text-xs',
- ].join(' ')}
- >
- You need additional permissions to add a new role
- </div>
- </Tooltip.Content>
- )}
- </Tooltip.Root>
- </div>
+ )}
+ </Tooltip.Root>
</div>
+ </div>
- <div className="space-y-4">
+ <div className="space-y-4">
+ {supabaseRoles.length > 0 && (
<div>
<div className="bg-surface-100 border border-default px-6 py-3 rounded-t flex items-center space-x-4">
<p className="text-sm text-foreground-light">Roles managed by Supabase</p>
@@ -196,7 +189,7 @@ const RolesList = () => {
{isLoading
? Array.from({ length: 5 }).map((_, i) => <RoleRowSkeleton key={i} index={i} />)
- : supabaseRoles.map((role, i: number) => (
+ : supabaseRoles.map((role) => (
<RoleRow
disabled
key={role.id}
@@ -205,7 +198,9 @@ const RolesList = () => {
/>
))}
</div>
+ )}
+ {otherRoles.length > 0 && (
<div>
<div className="bg-surface-100 border border-default px-6 py-3 rounded-t">
<p className="text-sm text-foreground-light">Other database roles</p>
@@ -213,7 +208,7 @@ const RolesList = () => {
{isLoading
? Array.from({ length: 3 }).map((_, i) => <RoleRowSkeleton key={i} index={i} />)
- : otherRoles.map((role, i: number) => (
+ : otherRoles.map((role) => (
<RoleRow
key={role.id}
disabled={!canUpdateRoles}
@@ -222,13 +217,13 @@ const RolesList = () => {
/>
))}
</div>
- </div>
-
- {filterString.length > 0 && filteredRoles.length === 0 && (
- <NoSearchResults searchString={filterString} onResetFilter={() => setFilterString('')} />
)}
</div>
+ {filterString.length > 0 && filteredRoles.length === 0 && (
+ <NoSearchResults searchString={filterString} onResetFilter={() => setFilterString('')} />
+ )}
+
<CreateRolePanel visible={isCreatingRole} onClose={() => setIsCreatingRole(false)} />
<DeleteRoleModal
diff --git a/apps/studio/components/interfaces/Database/Tables/ColumnList.tsx b/apps/studio/components/interfaces/Database/Tables/ColumnList.tsx
index ef4a2db6432..de1d1753549 100644
--- a/apps/studio/components/interfaces/Database/Tables/ColumnList.tsx
+++ b/apps/studio/components/interfaces/Database/Tables/ColumnList.tsx
@@ -9,8 +9,6 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
- IconChevronLeft,
- IconChevronRight,
IconEdit,
IconMoreVertical,
IconPlus,
@@ -27,7 +25,7 @@ import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useCheckPermissions } from 'hooks'
import useTable from 'hooks/misc/useTable'
import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas'
-import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
+import { ChevronLeft } from 'lucide-react'
import ProtectedSchemaWarning from '../ProtectedSchemaWarning'
interface ColumnListProps {
@@ -55,24 +53,12 @@ const ColumnList = ({
return (
<div className="space-y-4">
- <div className="flex items-center space-x-2">
- <div className="flex items-center space-x-2">
- <h3 className="text-xl text-foreground">Database Tables</h3>
- <IconChevronRight strokeWidth={1.5} className="text-foreground-light" />
- {isLoading ? (
- <ShimmeringLoader className="w-40" />
- ) : (
- <h3 className="text-xl text-foreground">{selectedTable?.name}</h3>
- )}
- </div>
- </div>
-
<div className="flex items-center justify-between">
<div className="flex items-center space-x-4">
<Button
asChild
type="outline"
- icon={<IconChevronLeft size="small" />}
+ icon={<ChevronLeft size={14} />}
style={{ padding: '5px' }}
>
<Link href={`/project/${ref}/database/tables`} />
diff --git a/apps/studio/components/interfaces/Database/Tables/TableList.tsx b/apps/studio/components/interfaces/Database/Tables/TableList.tsx
index 2657508f44e..798c1944424 100644
--- a/apps/studio/components/interfaces/Database/Tables/TableList.tsx
+++ b/apps/studio/components/interfaces/Database/Tables/TableList.tsx
@@ -99,8 +99,6 @@ const TableList = ({
return (
<div className="space-y-4">
- <h3 className="text-xl text-foreground">Database Tables</h3>
-
<div className="flex items-center justify-between">
<div className="flex items-center space-x-4">
<SchemaSelector
diff --git a/apps/studio/components/interfaces/Database/Wrappers/Wrappers.tsx b/apps/studio/components/interfaces/Database/Wrappers/Wrappers.tsx
index bc5f3358a6d..05b2d08d4ae 100644
--- a/apps/studio/components/interfaces/Database/Wrappers/Wrappers.tsx
+++ b/apps/studio/components/interfaces/Database/Wrappers/Wrappers.tsx
@@ -1,30 +1,20 @@
import { groupBy } from 'lodash'
-import Link from 'next/link'
import { useState } from 'react'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
-import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
-import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'
import { FDW, useFDWsQuery } from 'data/fdw/fdws-query'
-import { Button, IconExternalLink } from 'ui'
import DeleteWrapperModal from './DeleteWrapperModal'
import WrapperRow from './WrapperRow'
import { WRAPPERS } from './Wrappers.constants'
import WrappersDisabledState from './WrappersDisabledState'
import WrappersDropdown from './WrappersDropdown'
-const Wrappers = () => {
+const Wrappers = ({ isEnabled }: { isEnabled: boolean }) => {
const { project } = useProjectContext()
- const { data, isLoading } = useFDWsQuery({
+ const { data } = useFDWsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
- const { data: exts, isLoading: isLoadingExtensions } = useDatabaseExtensionsQuery({
- projectRef: project?.ref,
- connectionString: project?.connectionString,
- })
- const wrappersExtension = (exts ?? []).find((ext) => ext.name === 'wrappers')
- const vaultExtension = (exts ?? []).find((ext) => ext.name === 'supabase_vault')
const [open, setOpen] = useState<string>('')
const [selectedWrapperToDelete, setSelectedWrapperToDelete] = useState<FDW>()
@@ -32,82 +22,50 @@ const Wrappers = () => {
const wrappers = data?.result ?? []
const groupedWrappers = groupBy(wrappers, 'handler')
- const isWrappersEnabled =
- wrappersExtension !== undefined &&
- wrappersExtension.installed_version !== null &&
- vaultExtension !== undefined &&
- vaultExtension.installed_version !== null
-
return (
<>
- <div>
- <div className="flex items-center justify-between mb-6">
- <div>
- <h3 className="mb-1 text-xl text-foreground">Foreign Data Wrappers</h3>
- <div className="text-sm text-foreground-lighter">
- Query your data warehouse directly from your database, or third-party APIs using SQL.
+ {isEnabled ? (
+ <div>
+ {wrappers.length === 0 ? (
+ <div
+ className={[
+ 'border rounded border-default px-20 py-16',
+ 'flex flex-col items-center justify-center space-y-4',
+ ].join(' ')}
+ >
+ <p className="text-sm">No wrappers created yet</p>
+ <WrappersDropdown align="center" buttonText="Create a new wrapper" />
</div>
- </div>
- <div className="flex items-center space-x-2">
- <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>
- <Link
- href="https://supabase.com/docs/guides/database/extensions/wrappers/overview"
- target="_blank"
- rel="noreferrer"
- >
- Documentation
- </Link>
- </Button>
- {isWrappersEnabled && <WrappersDropdown />}
- </div>
+ ) : (
+ <>
+ {/* [Joshen] This probably needs to change anyways so dont get too stuck with this */}
+ {WRAPPERS.map((wrapper, i) => {
+ const createdWrappers = groupedWrappers[wrapper.handlerName] ?? []
+ if (createdWrappers.length > 0) {
+ return (
+ <WrapperRow
+ key={i}
+ wrapperMeta={wrapper}
+ wrappers={createdWrappers}
+ isOpen={open === wrapper.name}
+ onOpen={(wrapperName) => {
+ if (open !== wrapperName) setOpen(wrapperName)
+ else setOpen('')
+ }}
+ onSelectDelete={setSelectedWrapperToDelete}
+ />
+ )
+ } else {
+ return null
+ }
+ })}
+ </>
+ )}
</div>
+ ) : (
+ <WrappersDisabledState />
+ )}
- {isLoadingExtensions || isLoading ? (
- <div className="p-12 space-y-2 border rounded border-default">
- <GenericSkeletonLoader />
- </div>
- ) : isWrappersEnabled ? (
- <div>
- {wrappers.length === 0 ? (
- <div
- className={[
- 'border rounded border-default px-20 py-16',
- 'flex flex-col items-center justify-center space-y-4',
- ].join(' ')}
- >
- <p className="text-sm">No wrappers created yet</p>
- <WrappersDropdown align="center" buttonText="Create a new wrapper" />
- </div>
- ) : (
- <>
- {/* [Joshen] This probably needs to change anyways so dont get too stuck with this */}
- {WRAPPERS.map((wrapper, i) => {
- const createdWrappers = groupedWrappers[wrapper.handlerName] ?? []
- if (createdWrappers.length > 0) {
- return (
- <WrapperRow
- key={i}
- wrapperMeta={wrapper}
- wrappers={createdWrappers}
- isOpen={open === wrapper.name}
- onOpen={(wrapperName) => {
- if (open !== wrapperName) setOpen(wrapperName)
- else setOpen('')
- }}
- onSelectDelete={setSelectedWrapperToDelete}
- />
- )
- } else {
- return null
- }
- })}
- </>
- )}
- </div>
- ) : (
- <WrappersDisabledState />
- )}
- </div>
<DeleteWrapperModal
selectedWrapper={selectedWrapperToDelete}
onClose={() => setSelectedWrapperToDelete(undefined)}
diff --git a/apps/studio/components/interfaces/Organization/AuditLogs/AuditLogs.tsx b/apps/studio/components/interfaces/Organization/AuditLogs/AuditLogs.tsx
index f5e5e328ad5..0fb189e20da 100644
--- a/apps/studio/components/interfaces/Organization/AuditLogs/AuditLogs.tsx
+++ b/apps/studio/components/interfaces/Organization/AuditLogs/AuditLogs.tsx
@@ -17,11 +17,12 @@ import {
IconUser,
} from 'ui'
-import { FilterPopover, LogDetailsPanel } from 'components/interfaces/AuditLogs'
+import { LogDetailsPanel } from 'components/interfaces/AuditLogs'
import { ScaffoldContainerLegacy } from 'components/layouts/Scaffold'
import Table from 'components/to-be-cleaned/Table'
import AlertError from 'components/ui/AlertError'
import { DatePicker } from 'components/ui/DatePicker'
+import { FilterPopover } from 'components/ui/FilterPopover'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import {
AuditLog,
diff --git a/apps/studio/components/interfaces/QueryPerformance/IndexEfficiencyNotice.tsx b/apps/studio/components/interfaces/QueryPerformance/IndexEfficiencyNotice.tsx
new file mode 100644
index 00000000000..dee58df8a37
--- /dev/null
+++ b/apps/studio/components/interfaces/QueryPerformance/IndexEfficiencyNotice.tsx
@@ -0,0 +1,87 @@
+import { AlertCircle, CheckCircle } from 'lucide-react'
+
+import { AccordionTrigger } from '@ui/components/shadcn/ui/accordion'
+import { useParams } from 'common'
+import { AccordionContent_Shadcn_, AccordionItem_Shadcn_, Accordion_Shadcn_ } from 'ui'
+import { PRESET_CONFIG } from '../Reports/Reports.constants'
+import { Presets } from '../Reports/Reports.types'
+import { queriesFactory } from '../Reports/Reports.utils'
+
+interface IndexEfficiencyNoticeProps {
+ isLoading: boolean
+}
+
+export const IndexEfficiencyNotice = ({ isLoading }: IndexEfficiencyNoticeProps) => {
+ const { ref: projectRef } = useParams()
+ const config = PRESET_CONFIG[Presets.QUERY_PERFORMANCE]
+ const hooks = queriesFactory(config.queries, projectRef ?? 'default')
+
+ const queryHitRate = hooks.queryHitRate()
+ const indexHitRate = queryHitRate.data?.[0]?.ratio
+ const tableHitRate = queryHitRate.data?.[1]?.ratio
+ const showIndexWarning =
+ indexHitRate && tableHitRate && (indexHitRate <= 0.99 || tableHitRate <= 0.99)
+
+ const checkAlert = <CheckCircle strokeWidth={2} size={16} className="text-brand" />
+ const warnAlert = <AlertCircle strokeWidth={2} size={16} className="text-warning" />
+ const dangerAlert = <AlertCircle strokeWidth={2} size={16} className="text-destructive" />
+
+ return (
+ <Accordion_Shadcn_ type="single" collapsible>
+ <AccordionItem_Shadcn_ value="1" className="border-none">
+ <AccordionTrigger className="p-4 bg-surface-100 rounded border [&[data-state=open]]:rounded-b-none hover:no-underline">
+ <div className="flex flex-row gap-x-2 items-center">
+ <span className="text-sm">Index Efficiency</span>
+ {showIndexWarning ? warnAlert : checkAlert}
+ </div>
+ </AccordionTrigger>
+ <AccordionContent_Shadcn_ className="p-4 bg-surface-100 rounded-b border border-t-0 [&>div]:pb-0">
+ {!isLoading && queryHitRate && (
+ <div className="flex flex-col gap-y-4">
+ <div className="flex flex-row gap-4">
+ <div className="w-1/2 bg-slate-200 rounded-md p-4">
+ <p>Index Hit Rate</p>
+ <div className="flex items-center gap-x-3">
+ {indexHitRate >= 0.99
+ ? checkAlert
+ : indexHitRate >= 0.95
+ ? warnAlert
+ : dangerAlert}
+ <div className="flex items-baseline">
+ <span className="text-3xl">
+ {queryHitRate?.data && (queryHitRate?.data[0]?.ratio * 100).toFixed(2)}
+ </span>
+ <span className="text-xl">%</span>
+ </div>
+ </div>
+ </div>
+
+ <div className="w-1/2 bg-slate-200 rounded-md p-4">
+ {queryHitRate?.data![1]?.name == 'table hit rate' && 'Table Hit Rate'}
+ <div className="flex items-center gap-2">
+ {tableHitRate >= 0.99
+ ? checkAlert
+ : tableHitRate >= 0.95
+ ? warnAlert
+ : dangerAlert}
+ <div className="flex items-baseline">
+ <span className="text-3xl">
+ {queryHitRate?.data && (queryHitRate?.data[1]?.ratio * 100).toFixed(2)}
+ </span>
+ <span className="text-xl">%</span>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <p className="text-foreground-light text-sm max-w-2xl">
+ For best performance, ensure that the cache hit rate ratios above 99%. <br />{' '}
+ Consider upgrading to an instance with more memory if the ratios dip below 95%.
+ </p>
+ </div>
+ )}
+ </AccordionContent_Shadcn_>
+ </AccordionItem_Shadcn_>
+ </Accordion_Shadcn_>
+ )
+}
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryPerformance.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryPerformance.tsx
new file mode 100644
index 00000000000..3f9b663f2a6
--- /dev/null
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryPerformance.tsx
@@ -0,0 +1,236 @@
+import { useRouter } from 'next/router'
+
+import Table from 'components/to-be-cleaned/Table'
+import { DbQueryHook } from 'hooks/analytics/useDbQuery'
+import { Tabs } from 'ui'
+import { Markdown } from '../Markdown'
+import ReportQueryPerformanceTableRow from '../Reports/ReportQueryPerformanceTableRow'
+import { PresetHookResult } from '../Reports/Reports.utils'
+import { QueryPerformanceFilterBar } from './QueryPerformanceFilterBar'
+import { QueryPerformanceLoadingRow } from './QueryPerformanceLoadingRow'
+import { ResetAnalysisNotice } from './ResetAnalysisNotice'
+
+type QueryPerformancePreset = 'time' | 'frequent' | 'slowest'
+
+const panelClassNames = 'text-sm max-w-none flex flex-col gap-4'
+
+const TimeConsumingHelperText = `This table lists queries ordered by their cumulative total execution time.
+
+It displays the total time a query has spent running and the proportion of total execution time the query has consumed.
+`
+
+const MostFrequentHelperText = `This table lists queries in order of their execution count, providing insights into the most frequently executed queries.
+
+Pay attention to queries with high max_time or mean_time values that are called frequently, as they may benefit from optimization.
+`
+
+const SlowestExecutionHelperText = `This table lists queries ordered by their maximum execution time. It shows outliers with high execution times.
+
+Look for queries with high or mean execution times as these are often good candidates for optimization.
+`
+
+interface QueryPerformanceProps {
+ queryHitRate: PresetHookResult
+ queryPerformanceQuery: DbQueryHook<any>
+}
+
+export const QueryPerformance = ({
+ queryHitRate,
+ queryPerformanceQuery,
+}: QueryPerformanceProps) => {
+ const router = useRouter()
+ const isLoading = [queryPerformanceQuery.isLoading, queryHitRate.isLoading].every(
+ (value) => value
+ )
+
+ const handleRefresh = async () => {
+ queryPerformanceQuery.runQuery()
+ queryHitRate.runQuery()
+ }
+
+ return (
+ <Tabs
+ type="underlined"
+ size="medium"
+ onChange={(e: string) => {
+ // To reset the search and sort query params when switching tabs
+ const { sort, search, ...rest } = router.query
+ router.push({
+ ...router,
+ query: {
+ ...rest,
+ preset: e,
+ },
+ })
+ }}
+ >
+ <Tabs.Panel key="time" id="time" label="Most time consuming">
+ <div className={panelClassNames}>
+ <Markdown
+ content={TimeConsumingHelperText}
+ className="max-w-full [&>p]:mt-0 [&>p]:m-0 space-y-2"
+ />
+ <ResetAnalysisNotice handleRefresh={handleRefresh} />
+ <div className="thin-scrollbars max-w-full overflow-auto">
+ <QueryPerformanceFilterBar onRefreshClick={handleRefresh} isLoading={isLoading} />
+ <Table
+ className="table-fixed"
+ head={
+ <>
+ <Table.th className="text-ellipsis overflow-hidden">Role</Table.th>
+ <Table.th className="w-[300px]">Query</Table.th>
+ <Table.th className="text-right">Calls</Table.th>
+ <Table.th className="text-right">Time Consumed</Table.th>
+ <Table.th className="text-right">Total Latency</Table.th>
+ </>
+ }
+ body={
+ !queryPerformanceQuery.isLoading ? (
+ queryPerformanceQuery?.data?.map((item, i) => {
+ return (
+ <ReportQueryPerformanceTableRow
+ key={i + '-mosttimeconsumed'}
+ sql={item.query}
+ colSpan={5}
+ >
+ <Table.td className="truncate" title={item.rolname}>
+ {item.rolname}
+ </Table.td>
+ <Table.td className="max-w-xs">
+ <p className="font-mono line-clamp-2 text-xs">{item.query}</p>
+ </Table.td>
+ <Table.td className="truncate text-right">{item.calls}</Table.td>
+ <Table.td className="truncate text-right">{item.prop_total_time}</Table.td>
+ <Table.td className="truncate text-right">
+ {item.total_time.toFixed(2)}ms
+ </Table.td>
+ </ReportQueryPerformanceTableRow>
+ )
+ })
+ ) : (
+ <QueryPerformanceLoadingRow colSpan={5} />
+ )
+ }
+ />
+ </div>
+ </div>
+ </Tabs.Panel>
+ <Tabs.Panel key="frequent" id="frequent" label="Most frequent">
+ <div className={panelClassNames}>
+ <Markdown
+ content={MostFrequentHelperText}
+ className="max-w-full [&>p]:mt-0 [&>p]:m-0 space-y-2"
+ />
+ <ResetAnalysisNotice handleRefresh={handleRefresh} />
+ <div className="thin-scrollbars max-w-full overflow-auto">
+ <QueryPerformanceFilterBar onRefreshClick={handleRefresh} isLoading={isLoading} />
+ <Table
+ head={
+ <>
+ <Table.th className="">Role</Table.th>
+ <Table.th className="w-[300px]">Query</Table.th>
+ <Table.th className="text-right">Avg. Roles</Table.th>
+ <Table.th className="text-right">Calls</Table.th>
+ <Table.th className="text-right">Max Time</Table.th>
+ <Table.th className="text-right">Mean Time</Table.th>
+ <Table.th className="text-right">Min Time</Table.th>
+ <Table.th className="text-right">Total Latency</Table.th>
+ </>
+ }
+ body={
+ queryPerformanceQuery.isLoading ? (
+ <QueryPerformanceLoadingRow colSpan={8} />
+ ) : (
+ queryPerformanceQuery.data?.map((item, i) => {
+ return (
+ <ReportQueryPerformanceTableRow
+ key={i + '-mostfreq'}
+ sql={item.query}
+ colSpan={8}
+ >
+ <Table.td className="truncate" title={item.rolname}>
+ {item.rolname}
+ </Table.td>
+ <Table.td className="min-w-xs">
+ <p className="text-xs font-mono line-clamp-2">{item.query}</p>
+ </Table.td>
+ <Table.td className="truncate text-right">{item.avg_rows}</Table.td>
+ <Table.td className="truncate text-right">{item.calls}</Table.td>
+ <Table.td className="truncate text-right">
+ {item.max_time?.toFixed(2)}ms
+ </Table.td>
+ <Table.td className="text-right truncate">
+ {item.mean_time?.toFixed(2)}ms
+ </Table.td>
+ <Table.td className="text-right truncate">
+ {item.min_time?.toFixed(2)}ms
+ </Table.td>
+ <Table.td className="text-right truncate">
+ {item.total_time?.toFixed(2)}ms
+ </Table.td>
+ </ReportQueryPerformanceTableRow>
+ )
+ })
+ )
+ }
+ />
+ </div>
+ </div>
+ </Tabs.Panel>
+ <Tabs.Panel key="slowest" id="slowest" label="Slowest execution time">
+ <div className={panelClassNames}>
+ <Markdown
+ content={SlowestExecutionHelperText}
+ className="max-w-full [&>p]:mt-0 [&>p]:m-0 space-y-2"
+ />
+ <ResetAnalysisNotice handleRefresh={handleRefresh} />
+ <div className="thin-scrollbars max-w-full overflow-auto">
+ <QueryPerformanceFilterBar onRefreshClick={handleRefresh} isLoading={isLoading} />
+ <Table
+ head={
+ <>
+ <Table.th className="table-cell">Role</Table.th>
+ <Table.th className="table-cell">Query</Table.th>
+ <Table.th className="table-cell">Avg Rows</Table.th>
+ <Table.th className="table-cell">Calls</Table.th>
+ <Table.th className="table-cell">Max Time</Table.th>
+ <Table.th className="table-cell">Mean Time</Table.th>
+ <Table.th className="table-cell">Min Time</Table.th>
+ <Table.th className="table-cell">Total Latency</Table.th>
+ </>
+ }
+ body={
+ queryPerformanceQuery.isLoading ? (
+ <QueryPerformanceLoadingRow colSpan={8} />
+ ) : (
+ queryPerformanceQuery.data?.map((item, i) => {
+ return (
+ <ReportQueryPerformanceTableRow
+ key={i + '-slowestexec'}
+ sql={item.query}
+ colSpan={8}
+ >
+ <Table.td className="truncate" title={item.rolname}>
+ {item.rolname}
+ </Table.td>
+ <Table.td className="max-w-xs">
+ <p className="font-mono line-clamp-2 text-xs">{item.query}</p>
+ </Table.td>
+ <Table.td className="truncate">{item.avg_rows}</Table.td>
+ <Table.td className="truncate">{item.calls}</Table.td>
+ <Table.td className="truncate">{item.max_time?.toFixed(2)}ms</Table.td>
+ <Table.td className="truncate">{item.mean_time?.toFixed(2)}ms</Table.td>
+ <Table.td className="truncate">{item.min_time?.toFixed(2)}ms</Table.td>
+ <Table.td className="truncate">{item.total_time?.toFixed(2)}ms</Table.td>
+ </ReportQueryPerformanceTableRow>
+ )
+ })
+ )
+ }
+ />
+ </div>
+ </div>
+ </Tabs.Panel>
+ </Tabs>
+ )
+}
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceFilterBar.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceFilterBar.tsx
index 8343086ccf9..ad69fbb90c0 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceFilterBar.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceFilterBar.tsx
@@ -1,5 +1,10 @@
+import { ArrowDown, ArrowUp, RefreshCw } from 'lucide-react'
import { useRouter } from 'next/router'
import { useState } from 'react'
+
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
+import { FilterPopover } from 'components/ui/FilterPopover'
+import { useDatabaseRolesQuery } from 'data/database-roles/database-roles-query'
import {
Button,
DropdownMenu,
@@ -7,12 +12,8 @@ import {
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuTrigger,
- IconArrowDown,
- IconArrowUp,
- IconRefreshCw,
- IconSearch,
- Input,
} from 'ui'
+import { TextSearchPopover } from './TextSearchPopover'
export const QueryPerformanceFilterBar = ({
isLoading,
@@ -22,10 +23,23 @@ export const QueryPerformanceFilterBar = ({
onRefreshClick: () => void
}) => {
const router = useRouter()
+ const { project } = useProjectContext()
const defaultSearchQueryValue = router.query.search ? String(router.query.search) : ''
const defaultSortByValue = router.query.sort ? String(router.query.sort) : 'lat_desc'
- const [searchInputVal, setSearchInputVal] = useState(defaultSearchQueryValue)
+ const defaultFilterRoles = router.query.roles ? (router.query.roles as string[]) : []
+
const [sortByValue, setSortByValue] = useState(defaultSortByValue)
+ const [searchInputVal, setSearchInputVal] = useState(defaultSearchQueryValue)
+ const [filters, setFilters] = useState<{ roles: string[]; query: string }>({
+ roles: typeof defaultFilterRoles === 'string' ? [defaultFilterRoles] : defaultFilterRoles,
+ query: '',
+ })
+
+ const { data, isLoading: isLoadingRoles } = useDatabaseRolesQuery({
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ })
+ const roles = (data ?? []).sort((a, b) => a.name.localeCompare(b.name))
function getSortButtonLabel() {
const sort = router.query.sort as 'lat_desc' | 'lat_asc'
@@ -37,109 +51,83 @@ export const QueryPerformanceFilterBar = ({
}
}
- function onSortChange(sort: string) {
- setSortByValue(sort)
- router.push({
- ...router,
- query: {
- ...router.query,
- sort,
- },
- })
+ const onSearchQueryChange = (value: string) => {
+ setSearchInputVal(value)
+
+ if (!value || typeof value !== 'string') {
+ // if user has deleted the search query, remove it from the url
+ const { search, ...rest } = router.query
+ router.push({ ...router, query: { ...rest } })
+ } else {
+ router.push({ ...router, query: { ...router.query, search: value } })
+ }
}
- const ButtonIcon = sortByValue === 'lat_desc' ? IconArrowDown : IconArrowUp
+ const onFilterRolesChange = (roles: string[]) => {
+ setFilters({ ...filters, roles })
+ router.push({ ...router, query: { ...router.query, roles } })
+ }
- return (
- <>
- <div className="flex justify-between items-center">
- <form
- className="py-3 flex gap-4"
- id="log-panel-search"
- onSubmit={(e) => {
- e.preventDefault()
- const formData = new FormData(e.target as HTMLFormElement)
- const searchQuery = formData.get('search')
+ const onSortChange = (sort: string) => {
+ setSortByValue(sort)
+ router.push({ ...router, query: { ...router.query, sort } })
+ }
- if (!searchQuery || typeof searchQuery !== 'string') {
- // if user has deleted the search query, remove it from the url
- const { search, ...rest } = router.query
- router.push({
- ...router,
- query: {
- ...rest,
- },
- })
- return
- }
+ const ButtonIcon = sortByValue === 'lat_desc' ? ArrowDown : ArrowUp
- router.push({
- ...router,
- query: {
- ...router.query,
- search: searchQuery,
- },
- })
- }}
- >
- <Input
- className="w-60 group"
- size="tiny"
- placeholder="Search roles or queries"
- name="search"
- value={searchInputVal}
- onChange={(e) => setSearchInputVal(e.target.value)}
- autoComplete="off"
- icon={
- <div className="text-foreground-lighter">
- <IconSearch size={14} />
- </div>
- }
- actions={
- searchInputVal !== '' && (
- <button className="mx-2 text-foreground-light hover:text-foreground">{'↲'}</button>
- )
- }
+ return (
+ <div className="flex justify-between items-center mb-3">
+ <div className="flex items-center gap-x-4">
+ <div className="flex items-center gap-x-2">
+ <p className="text-xs prose">Filter by</p>
+ <FilterPopover
+ name="Roles"
+ options={roles}
+ labelKey="name"
+ valueKey="name"
+ activeOptions={isLoadingRoles ? [] : filters.roles}
+ onSaveFilters={onFilterRolesChange}
/>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button icon={<ButtonIcon />}>{getSortButtonLabel()}</Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent className="w-56">
- <DropdownMenuRadioGroup value={sortByValue} onValueChange={onSortChange}>
- <DropdownMenuRadioItem
- defaultChecked={router.query.sort === 'lat_desc'}
- value={'lat_desc'}
- >
- Sort by latency - high to low
- </DropdownMenuRadioItem>
- <DropdownMenuRadioItem
- value={'lat_asc'}
- defaultChecked={router.query.sort === 'lat_asc'}
- >
- Sort by latency - low to high
- </DropdownMenuRadioItem>
- </DropdownMenuRadioGroup>
- </DropdownMenuContent>
- </DropdownMenu>
- </form>
- <div>
- <Button
- type="default"
- size="tiny"
- onClick={onRefreshClick}
- disabled={isLoading ? true : false}
- icon={
- <IconRefreshCw
- size="tiny"
- className={`text-foreground-light ${isLoading ? 'animate-spin' : ''}`}
- />
- }
- >
- {isLoading ? 'Refreshing' : 'Refresh'}
- </Button>
+ <TextSearchPopover name="Query" value={searchInputVal} onSaveText={onSearchQueryChange} />
</div>
+ <div className="border-r border-strong h-6" />
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button icon={<ButtonIcon />}>{getSortButtonLabel()}</Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className="w-56">
+ <DropdownMenuRadioGroup value={sortByValue} onValueChange={onSortChange}>
+ <DropdownMenuRadioItem
+ value="lat_desc"
+ defaultChecked={router.query.sort === 'lat_desc'}
+ >
+ Sort by latency - high to low
+ </DropdownMenuRadioItem>
+ <DropdownMenuRadioItem
+ value="lat_asc"
+ defaultChecked={router.query.sort === 'lat_asc'}
+ >
+ Sort by latency - low to high
+ </DropdownMenuRadioItem>
+ </DropdownMenuRadioGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
</div>
- </>
+
+ <Button
+ type="default"
+ size="tiny"
+ onClick={onRefreshClick}
+ disabled={isLoading ? true : false}
+ icon={
+ <RefreshCw
+ size={12}
+ className={`text-foreground-light ${isLoading ? 'animate-spin' : ''}`}
+ />
+ }
+ >
+ {isLoading ? 'Refreshing' : 'Refresh'}
+ </Button>
+ </div>
)
}
diff --git a/apps/studio/components/interfaces/QueryPerformance/ResetAnalysisNotice.tsx b/apps/studio/components/interfaces/QueryPerformance/ResetAnalysisNotice.tsx
new file mode 100644
index 00000000000..44df82f2578
--- /dev/null
+++ b/apps/studio/components/interfaces/QueryPerformance/ResetAnalysisNotice.tsx
@@ -0,0 +1,53 @@
+import { useState } from 'react'
+import toast from 'react-hot-toast'
+
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
+import { executeSql } from 'data/sql/execute-sql-query'
+import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui'
+import ConfirmModal from 'ui-patterns/Dialogs/ConfirmDialog'
+
+export const ResetAnalysisNotice = ({ handleRefresh }: { handleRefresh: () => void }) => {
+ const { project } = useProjectContext()
+ const [showResetgPgStatStatements, setShowResetgPgStatStatements] = useState(false)
+
+ return (
+ <>
+ <Alert_Shadcn_>
+ <AlertTitle_Shadcn_>
+ Consider resetting the analysis after optimizing any queries
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ This will ensure that the performance metrics are updated with the latest changes
+ </AlertDescription_Shadcn_>
+ <Button type="default" className="mt-3" onClick={() => setShowResetgPgStatStatements(true)}>
+ Reset performance analysis
+ </Button>
+ </Alert_Shadcn_>
+
+ <ConfirmModal
+ danger
+ visible={showResetgPgStatStatements}
+ title="Reset query performance analysis"
+ description={
+ 'This will reset the `extensions.pg_stat_statements` table that is used to calculate query performance. This data will repopulate immediately after.'
+ }
+ buttonLabel="Clear table"
+ buttonLoadingLabel="Deleting"
+ onSelectCancel={() => setShowResetgPgStatStatements(false)}
+ onSelectConfirm={async () => {
+ try {
+ await executeSql({
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ sql: `SELECT pg_stat_statements_reset();`,
+ })
+ handleRefresh()
+ setShowResetgPgStatStatements(false)
+ } catch (error: any) {
+ toast.error(`Failed to reset analysis: ${error.message}`)
+ }
+ }}
+ />
+ </>
+ )
+}
diff --git a/apps/studio/components/interfaces/QueryPerformance/TextSearchPopover.tsx b/apps/studio/components/interfaces/QueryPerformance/TextSearchPopover.tsx
new file mode 100644
index 00000000000..737faea9b3d
--- /dev/null
+++ b/apps/studio/components/interfaces/QueryPerformance/TextSearchPopover.tsx
@@ -0,0 +1,70 @@
+import { useState } from 'react'
+import {
+ Button,
+ PopoverContent_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
+ TextArea_Shadcn_,
+} from 'ui'
+
+interface TextSearchPopoverProps {
+ name: string
+ value: string
+ onSaveText: (value: string) => void
+}
+
+export const TextSearchPopover = ({ name, value = '', onSaveText }: TextSearchPopoverProps) => {
+ const [open, setOpen] = useState(false)
+ const [search, setSearch] = useState<string>(value)
+
+ return (
+ <Popover_Shadcn_ open={open} onOpenChange={setOpen} modal={false}>
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button
+ asChild
+ type={value.length > 0 ? 'default' : 'dashed'}
+ onClick={() => setOpen(false)}
+ >
+ <div className="max-w-[170px]">
+ <span>{name}</span>
+ {value.length > 0 && <span className="mr-1">:</span>}
+ <span className="truncate">{value}</span>
+ </div>
+ </Button>
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_ className="p-0" side="bottom" align="start">
+ <div className="space-y-4 p-3 min-w-[170px]">
+ <TextArea_Shadcn_
+ value={search}
+ onChange={(event) => setSearch(event.target.value)}
+ rows={4}
+ className="text-xs font-mono tracking-tight"
+ placeholder="Search for a query"
+ />
+ </div>
+ <div className="flex items-center justify-end gap-2 border-t border-overlay bg-surface-200 py-2 px-3">
+ <Button
+ size="tiny"
+ type="default"
+ onClick={() => {
+ onSaveText('')
+ setSearch('')
+ setOpen(false)
+ }}
+ >
+ Clear
+ </Button>
+ <Button
+ type="primary"
+ onClick={() => {
+ onSaveText(search)
+ setOpen(false)
+ }}
+ >
+ Save
+ </Button>
+ </div>
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ )
+}
diff --git a/apps/studio/components/interfaces/Reports/ReportHeader.tsx b/apps/studio/components/interfaces/Reports/ReportHeader.tsx
index 39a68e44057..65eee3aefe3 100644
--- a/apps/studio/components/interfaces/Reports/ReportHeader.tsx
+++ b/apps/studio/components/interfaces/Reports/ReportHeader.tsx
@@ -2,11 +2,9 @@ import { Button, IconRefreshCw } from 'ui'
interface Props {
title: string
- onRefresh: () => void
- isLoading: boolean
}
-const ReportHeader: React.FC<Props> = ({ title, onRefresh, isLoading }) => (
+const ReportHeader: React.FC<Props> = ({ title }) => (
<div className="flex flex-row justify-between gap-4 items-center">
<h1 className="text-2xl text-foreground">{title}</h1>
</div>
diff --git a/apps/studio/components/interfaces/Reports/Reports.queries.ts b/apps/studio/components/interfaces/Reports/Reports.queries.ts
index a20c94b481b..1f943b04e29 100644
--- a/apps/studio/components/interfaces/Reports/Reports.queries.ts
+++ b/apps/studio/components/interfaces/Reports/Reports.queries.ts
@@ -6,11 +6,13 @@ type QueryPerformanceQueryOpts = {
searchQuery: string
preset: 'mostFrequentlyInvoked' | 'mostTimeConsuming' | 'slowestExecutionTime' | 'queryHitRate'
orderBy: string | 'lat_asc' | 'lat_desc'
+ roles?: string[]
}
export const useQueryPerformanceQuery = ({
preset,
orderBy,
searchQuery,
+ roles,
}: QueryPerformanceQueryOpts) => {
const queryPerfQueries = PRESET_CONFIG[Presets.QUERY_PERFORMANCE]
const baseSQL = queryPerfQueries.queries[preset]
@@ -20,9 +22,15 @@ export const useQueryPerformanceQuery = ({
orderBy = 'lat_desc'
}
- const whereSql = searchQuery
- ? `WHERE auth.rolname ~ '${searchQuery}' OR statements.query ~ '${searchQuery}'`
- : ''
+ const whereSql = [
+ roles !== undefined && roles.length > 0
+ ? `WHERE auth.rolname in (${roles.map((r) => `'${r}'`).join(', ')})`
+ : '',
+ searchQuery.length > 0 ? `statements.query ~ '${searchQuery}'` : '',
+ ]
+ .filter((x) => x.length > 0)
+ .join(' OR ')
+
const orderBySql = orderBy === 'lat_asc' ? 'ORDER BY total_time asc' : 'ORDER BY total_time desc'
const sql = baseSQL.sql([], whereSql, orderBySql)
diff --git a/apps/studio/components/interfaces/Reports/Reports.utils.tsx b/apps/studio/components/interfaces/Reports/Reports.utils.tsx
index cbf86b4693c..eede5de73bc 100644
--- a/apps/studio/components/interfaces/Reports/Reports.utils.tsx
+++ b/apps/studio/components/interfaces/Reports/Reports.utils.tsx
@@ -10,7 +10,7 @@ export const queryParamsToObject = (params: string) => {
}
// generate hooks based on preset config
-type PresetHookResult = LogsQueryHook | DbQueryHook
+export type PresetHookResult = LogsQueryHook | DbQueryHook
type PresetHooks = Record<keyof PresetConfig['queries'], () => PresetHookResult>
export const queriesFactory = <T extends string>(
diff --git a/apps/studio/components/layouts/Scaffold.tsx b/apps/studio/components/layouts/Scaffold.tsx
index 71d3ea68279..8b53eaca7c0 100644
--- a/apps/studio/components/layouts/Scaffold.tsx
+++ b/apps/studio/components/layouts/Scaffold.tsx
@@ -3,11 +3,8 @@ import { cn } from 'ui'
const maxWidthClasses = 'mx-auto w-full max-w-[1600px]'
const paddingClasses = 'px-6 lg:px-14 xl:px-28 2xl:px-32'
-
const maxWidthClassesColumn = 'min-w-[420px]'
-// lg: pt - 8
-
const ScaffoldHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => {
return (
diff --git a/apps/studio/components/interfaces/AuditLogs/FilterPopover.tsx b/apps/studio/components/ui/FilterPopover.tsx
similarity index 70%
rename from apps/studio/components/interfaces/AuditLogs/FilterPopover.tsx
rename to apps/studio/components/ui/FilterPopover.tsx
index aadc264bdd4..54a60936aa2 100644
--- a/apps/studio/components/interfaces/AuditLogs/FilterPopover.tsx
+++ b/apps/studio/components/ui/FilterPopover.tsx
@@ -1,5 +1,5 @@
import { useState } from 'react'
-import { Button, Checkbox, Popover } from 'ui'
+import { Button, Checkbox, Popover, ScrollArea } from 'ui'
interface FilterPopoverProps {
options: any[]
@@ -13,7 +13,7 @@ interface FilterPopoverProps {
// [Joshen] Form + Checkbox.Group doesn't seem to work properly RE form state
// hence why the manual implementation here as a workaround
-const FilterPopover = ({
+export const FilterPopover = ({
options = [],
activeOptions = [],
valueKey,
@@ -39,24 +39,26 @@ const FilterPopover = ({
overlay={
<>
<div className="space-y-4 px-3 py-3 min-w-[170px]">
- <Checkbox.Group
- id="projects"
- onChange={(event) => {
- const value = event.target.value
- if (selectedOptions.includes(value)) {
- setSelectedOptions(selectedOptions.filter((x) => x !== value))
- } else {
- setSelectedOptions(selectedOptions.concat(value))
- }
- }}
- options={options.map((option) => {
- return {
- value: option[valueKey],
- label: option[labelKey],
- defaultChecked: activeOptions.includes(option[valueKey]),
- }
- })}
- />
+ <ScrollArea className={options.length > 7 ? 'h-[205px]' : ''}>
+ <Checkbox.Group
+ id="projects"
+ onChange={(event) => {
+ const value = event.target.value
+ if (selectedOptions.includes(value)) {
+ setSelectedOptions(selectedOptions.filter((x) => x !== value))
+ } else {
+ setSelectedOptions(selectedOptions.concat(value))
+ }
+ }}
+ options={options.map((option) => {
+ return {
+ value: option[valueKey],
+ label: option[labelKey],
+ defaultChecked: activeOptions.includes(option[valueKey]),
+ }
+ })}
+ />
+ </ScrollArea>
</div>
<div className="flex items-center justify-end gap-2 border-t border-overlay bg-surface-200 py-2 px-3">
<Button
@@ -102,5 +104,3 @@ const FilterPopover = ({
</Popover>
)
}
-
-export default FilterPopover
diff --git a/apps/studio/components/ui/Forms/FormHeader.tsx b/apps/studio/components/ui/Forms/FormHeader.tsx
index e860564c56c..0e5c0ad4606 100644
--- a/apps/studio/components/ui/Forms/FormHeader.tsx
+++ b/apps/studio/components/ui/Forms/FormHeader.tsx
@@ -1,6 +1,9 @@
+import { ExternalLink } from 'lucide-react'
import Link from 'next/link'
import ReactMarkdown from 'react-markdown'
-import { Button, IconExternalLink } from 'ui'
+
+import { Markdown } from 'components/interfaces/Markdown'
+import { Button } from 'ui'
const FormHeader = ({
title,
@@ -21,14 +24,10 @@ const FormHeader = ({
{title}
</ReactMarkdown>
</h3>
- {description && (
- <div className="text-foreground-lighter text-sm">
- <ReactMarkdown>{description}</ReactMarkdown>
- </div>
- )}
+ {description && <Markdown content={description} className="max-w-full" />}
</div>
{docsUrl !== undefined && (
- <Button asChild type="default" icon={<IconExternalLink />}>
+ <Button asChild type="default" icon={<ExternalLink size={14} />}>
<Link href={docsUrl} target="_blank" rel="noreferrer">
Documentation
</Link>
diff --git a/apps/studio/pages/project/[ref]/database/backups/pitr.tsx b/apps/studio/pages/project/[ref]/database/backups/pitr.tsx
index 7e8b641d68a..dfd2e0b03c6 100644
--- a/apps/studio/pages/project/[ref]/database/backups/pitr.tsx
+++ b/apps/studio/pages/project/[ref]/database/backups/pitr.tsx
@@ -1,9 +1,11 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import DatabaseBackupsNav from 'components/interfaces/Database/Backups/DatabaseBackupsNav'
import { PITRNotice, PITRSelection } from 'components/interfaces/Database/Backups/PITR'
import { DatabaseLayout } from 'components/layouts'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
import AlertError from 'components/ui/AlertError'
+import { FormHeader } from 'components/ui/Forms'
import NoPermission from 'components/ui/NoPermission'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import UpgradeToPro from 'components/ui/UpgradeToPro'
@@ -11,7 +13,6 @@ import { useBackupsQuery } from 'data/database/backups-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useCheckPermissions, usePermissionsLoaded, useSelectedOrganization } from 'hooks'
import type { NextPageWithLayout } from 'types'
-import DatabaseBackupsNav from 'components/interfaces/Database/Backups/DatabaseBackupsNav'
const DatabasePhysicalBackups: NextPageWithLayout = () => {
const { project } = useProjectContext()
@@ -22,7 +23,7 @@ const DatabasePhysicalBackups: NextPageWithLayout = () => {
<ScaffoldSection>
<div className="col-span-12">
<div className="space-y-6">
- <h3 className="text-xl text-foreground">Database Backups</h3>
+ <FormHeader className="!mb-0" title="Database Backups" />
<DatabaseBackupsNav active="pitr" projRef={ref} />
<div className="space-y-8">
<PITR />
diff --git a/apps/studio/pages/project/[ref]/database/backups/scheduled.tsx b/apps/studio/pages/project/[ref]/database/backups/scheduled.tsx
index d702ce67417..ed71ee3b923 100644
--- a/apps/studio/pages/project/[ref]/database/backups/scheduled.tsx
+++ b/apps/studio/pages/project/[ref]/database/backups/scheduled.tsx
@@ -1,19 +1,19 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useRouter } from 'next/router'
import { BackupsList } from 'components/interfaces/Database'
+import DatabaseBackupsNav from 'components/interfaces/Database/Backups/DatabaseBackupsNav'
import { DatabaseLayout } from 'components/layouts'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
import AlertError from 'components/ui/AlertError'
+import { FormHeader } from 'components/ui/Forms'
import InformationBox from 'components/ui/InformationBox'
import NoPermission from 'components/ui/NoPermission'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useBackupsQuery } from 'data/database/backups-query'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks'
import type { NextPageWithLayout } from 'types'
-import { IconInfo, Tabs } from 'ui'
-import DatabaseBackupsNav from 'components/interfaces/Database/Backups/DatabaseBackupsNav'
+import { IconInfo } from 'ui'
const DatabaseScheduledBackups: NextPageWithLayout = () => {
const { project } = useProjectContext()
@@ -36,7 +36,7 @@ const DatabaseScheduledBackups: NextPageWithLayout = () => {
<ScaffoldSection>
<div className="col-span-12">
<div className="space-y-6">
- <h3 className="text-xl text-foreground">Database Backups</h3>
+ <FormHeader className="!mb-0" title="Database Backups" />
<DatabaseBackupsNav active="scheduled" projRef={ref} />
<div className="space-y-8">
diff --git a/apps/studio/pages/project/[ref]/database/extensions.tsx b/apps/studio/pages/project/[ref]/database/extensions.tsx
index c982c9dd42d..4341a4dd845 100644
--- a/apps/studio/pages/project/[ref]/database/extensions.tsx
+++ b/apps/studio/pages/project/[ref]/database/extensions.tsx
@@ -3,6 +3,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { Extensions } from 'components/interfaces/Database'
import { DatabaseLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import NoPermission from 'components/ui/NoPermission'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks'
import type { NextPageWithLayout } from 'types'
@@ -22,7 +23,7 @@ const DatabaseExtensions: NextPageWithLayout = () => {
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
- <h3 className="mb-4 text-xl text-foreground">Database Extensions</h3>
+ <FormHeader title="Database Extensions" />
<Extensions />
</div>
</ScaffoldSection>
diff --git a/apps/studio/pages/project/[ref]/database/functions.tsx b/apps/studio/pages/project/[ref]/database/functions.tsx
index 1d425a91d41..168eb7932e5 100644
--- a/apps/studio/pages/project/[ref]/database/functions.tsx
+++ b/apps/studio/pages/project/[ref]/database/functions.tsx
@@ -6,6 +6,7 @@ import { CreateFunction, DeleteFunction } from 'components/interfaces/Database'
import FunctionsList from 'components/interfaces/Database/Functions/FunctionsList/FunctionsList'
import { DatabaseLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import NoPermission from 'components/ui/NoPermission'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks'
import type { NextPageWithLayout } from 'types'
@@ -42,7 +43,7 @@ const FunctionsPage: NextPageWithLayout = () => {
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
- <h3 className=" mb-4 text-xl text-foreground">Database Functions</h3>
+ <FormHeader title="Database Functions" />
<FunctionsList
createFunction={createFunction}
editFunction={editFunction}
diff --git a/apps/studio/pages/project/[ref]/database/hooks.tsx b/apps/studio/pages/project/[ref]/database/hooks.tsx
index 1d54496413a..746c898d35a 100644
--- a/apps/studio/pages/project/[ref]/database/hooks.tsx
+++ b/apps/studio/pages/project/[ref]/database/hooks.tsx
@@ -15,6 +15,7 @@ import { useHooksEnableMutation } from 'data/database/hooks-enable-mutation'
import { useSchemasQuery } from 'data/database/schemas-query'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks'
import type { NextPageWithLayout } from 'types'
+import { FormHeader } from 'components/ui/Forms'
const HooksPage: NextPageWithLayout = () => {
const { project } = useProjectContext()
@@ -101,6 +102,10 @@ const HooksPage: NextPageWithLayout = () => {
<ScaffoldContainer className="h-full">
<ScaffoldSection className="h-full">
<div className="col-span-12">
+ <FormHeader
+ title="Database Webhooks"
+ description="Send real-time data from your database to another system whenever a table event occurs"
+ />
<HooksList createHook={createHook} editHook={editHook} deleteHook={deleteHook} />
</div>
</ScaffoldSection>
diff --git a/apps/studio/pages/project/[ref]/database/indexes.tsx b/apps/studio/pages/project/[ref]/database/indexes.tsx
index 72c8b34d418..ffa2e05883c 100644
--- a/apps/studio/pages/project/[ref]/database/indexes.tsx
+++ b/apps/studio/pages/project/[ref]/database/indexes.tsx
@@ -1,13 +1,51 @@
+import { ExternalLink } from 'lucide-react'
+
import Indexes from 'components/interfaces/Database/Indexes/Indexes'
import { DatabaseLayout } from 'components/layouts'
-import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import {
+ ScaffoldContainer,
+ ScaffoldSection,
+ ScaffoldSectionContent,
+ ScaffoldSectionDetail,
+} from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import type { NextPageWithLayout } from 'types'
+import { Button } from 'ui'
const IndexesPage: NextPageWithLayout = () => {
return (
<ScaffoldContainer>
<ScaffoldSection>
- <div className="col-span-12">
+ <ScaffoldSectionContent className="gap-0">
+ <FormHeader
+ className="!mb-0"
+ title="Database Indexes"
+ description="Improve query performance against your database"
+ />
+ </ScaffoldSectionContent>
+ <ScaffoldSectionDetail className="flex items-center justify-end gap-x-2">
+ <Button asChild type="default" icon={<ExternalLink size={14} strokeWidth={1.5} />}>
+ <a
+ target="_blank"
+ rel="noreferrer"
+ className="no-underline"
+ href="https://supabase.com/docs/guides/database/query-optimization"
+ >
+ Documentation
+ </a>
+ </Button>
+ <Button asChild type="default" icon={<ExternalLink size={14} strokeWidth={1.5} />}>
+ <a
+ target="_blank"
+ rel="noreferrer"
+ className="no-underline"
+ href="https://supabase.com/docs/guides/database/extensions/index_advisor"
+ >
+ Optimization with index_advisor
+ </a>
+ </Button>
+ </ScaffoldSectionDetail>
+ <div className="col-span-12 mt-3">
<Indexes />
</div>
</ScaffoldSection>
diff --git a/apps/studio/pages/project/[ref]/database/linter.tsx b/apps/studio/pages/project/[ref]/database/linter.tsx
index e09407b7bcc..31f48daa024 100644
--- a/apps/studio/pages/project/[ref]/database/linter.tsx
+++ b/apps/studio/pages/project/[ref]/database/linter.tsx
@@ -3,11 +3,11 @@ import { Check, ExternalLink, Loader } from 'lucide-react'
import { useMemo, useState } from 'react'
import { AccordionTrigger } from '@ui/components/shadcn/ui/accordion'
-import { FilterPopover } from 'components/interfaces/AuditLogs'
import ReportLintsTableRow from 'components/interfaces/Reports/ReportLintsTableRow'
import { DatabaseLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
import Table from 'components/to-be-cleaned/Table'
+import { FormHeader } from 'components/ui/Forms'
import { useProjectLintsQuery } from 'data/lint/lint-query'
import { useLocalStorageQuery, useSelectedProject } from 'hooks'
import { LOCAL_STORAGE_KEYS } from 'lib/constants'
@@ -19,6 +19,7 @@ import {
Button,
LoadingLine,
} from 'ui'
+import { FilterPopover } from 'components/ui/FilterPopover'
const ProjectLints: NextPageWithLayout = () => {
const project = useSelectedProject()
@@ -59,13 +60,12 @@ const ProjectLints: NextPageWithLayout = () => {
return (
<ScaffoldContainer>
<ScaffoldSection>
- <div className="col-span-12 flex items-center justify-between">
- <div className="flec flex-col gap-y-1">
- <h3 className="text-xl text-foreground">Database Linter</h3>
- <div className="text-sm text-foreground-lighter">
- Identify common schema problems in your database
- </div>
- </div>
+ <div className="col-span-12">
+ <FormHeader
+ className="!mb-0"
+ title="Database Linter"
+ description="Identify common schema problems in your database."
+ />
</div>
<div className="col-span-12 flex items-center justify-between">
diff --git a/apps/studio/pages/project/[ref]/database/migrations.tsx b/apps/studio/pages/project/[ref]/database/migrations.tsx
index 9e8f9061dae..24a71088400 100644
--- a/apps/studio/pages/project/[ref]/database/migrations.tsx
+++ b/apps/studio/pages/project/[ref]/database/migrations.tsx
@@ -1,13 +1,41 @@
+import { ExternalLink } from 'lucide-react'
+
import Migrations from 'components/interfaces/Database/Migrations/Migrations'
import { DatabaseLayout } from 'components/layouts'
-import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import {
+ ScaffoldContainer,
+ ScaffoldSection,
+ ScaffoldSectionContent,
+ ScaffoldSectionDetail,
+} from 'components/layouts/Scaffold'
import type { NextPageWithLayout } from 'types'
+import { Button } from 'ui'
+import { FormHeader } from 'components/ui/Forms'
const MigrationsPage: NextPageWithLayout = () => {
return (
<ScaffoldContainer>
<ScaffoldSection>
- <div className="col-span-12">
+ <ScaffoldSectionContent>
+ <FormHeader
+ className="!mb-0"
+ title="Database Migrations"
+ description="History of migrations that have been run on your database"
+ />
+ </ScaffoldSectionContent>
+ <ScaffoldSectionDetail className="flex items-center justify-end gap-x-2">
+ <Button asChild type="default" icon={<ExternalLink size={14} strokeWidth={1.5} />}>
+ <a
+ target="_blank"
+ rel="noreferrer"
+ className="no-underline"
+ href="https://supabase.com/docs/guides/getting-started/local-development#database-migrations"
+ >
+ Documentation
+ </a>
+ </Button>
+ </ScaffoldSectionDetail>
+ <div className="col-span-12 mt-3">
<Migrations />
</div>
</ScaffoldSection>
diff --git a/apps/studio/pages/project/[ref]/database/query-performance.tsx b/apps/studio/pages/project/[ref]/database/query-performance.tsx
index 11b6e735c6d..25b02b9f92c 100644
--- a/apps/studio/pages/project/[ref]/database/query-performance.tsx
+++ b/apps/studio/pages/project/[ref]/database/query-performance.tsx
@@ -1,34 +1,23 @@
-import Link from 'next/link'
import { useRouter } from 'next/router'
-import { useState } from 'react'
-import ReactMarkdown from 'react-markdown'
import { useParams } from 'common'
-import { QueryPerformanceFilterBar } from 'components/interfaces/QueryPerformance/QueryPerformanceFilterBar'
-import { QueryPerformanceLoadingRow } from 'components/interfaces/QueryPerformance/QueryPerformanceLoadingRow'
-import ReportHeader from 'components/interfaces/Reports/ReportHeader'
-import ReportQueryPerformanceTableRow from 'components/interfaces/Reports/ReportQueryPerformanceTableRow'
+import { IndexEfficiencyNotice } from 'components/interfaces/QueryPerformance/IndexEfficiencyNotice'
+import { QueryPerformance } from 'components/interfaces/QueryPerformance/QueryPerformance'
import { PRESET_CONFIG } from 'components/interfaces/Reports/Reports.constants'
import { useQueryPerformanceQuery } from 'components/interfaces/Reports/Reports.queries'
import { Presets } from 'components/interfaces/Reports/Reports.types'
import { queriesFactory } from 'components/interfaces/Reports/Reports.utils'
import { DatabaseLayout } from 'components/layouts'
-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
-import Table from 'components/to-be-cleaned/Table'
-import { executeSql } from 'data/sql/execute-sql-query'
+import { FormHeader } from 'components/ui/Forms'
import { useFlag } from 'hooks'
import type { NextPageWithLayout } from 'types'
-import { Accordion, Button, IconAlertCircle, IconCheckCircle, Tabs } from 'ui'
-import ConfirmModal from 'ui-patterns/Dialogs/ConfirmDialog'
type QueryPerformancePreset = 'time' | 'frequent' | 'slowest'
const QueryPerformanceReport: NextPageWithLayout = () => {
const router = useRouter()
const { ref: projectRef } = useParams()
- const { project } = useProjectContext()
- const [showResetgPgStatStatements, setShowResetgPgStatStatements] = useState(false)
const tableIndexEfficiencyEnabled = useFlag('tableIndexEfficiency')
const config = PRESET_CONFIG[Presets.QUERY_PERFORMANCE]
@@ -37,6 +26,7 @@ const QueryPerformanceReport: NextPageWithLayout = () => {
const orderBy = (router.query.sort as 'lat_desc' | 'lat_asc') || 'lat_desc'
const searchQuery = (router.query.search as string) || ''
+ const roles = router.query.roles || []
const presetMap = {
time: 'mostTimeConsuming',
frequent: 'mostFrequentlyInvoked',
@@ -48,377 +38,34 @@ const QueryPerformanceReport: NextPageWithLayout = () => {
searchQuery,
orderBy,
preset,
+ roles: typeof roles === 'string' ? [roles] : roles,
})
const isLoading = [queryPerformanceQuery.isLoading, queryHitRate.isLoading].every(
(value) => value
)
- const handleRefresh = async () => {
- queryPerformanceQuery.runQuery()
- queryHitRate.runQuery()
- }
-
- const checkAlert = (
- <div className="w-5 h-5 text-brand-1400 text-brand flex items-center justify-center">
- <IconCheckCircle strokeWidth={2} size={16} />
- </div>
- )
- const warnAlert = (
- <div className="w-6 h-6 text-yellow-900 flex items-center justify-center">
- <IconAlertCircle strokeWidth={2} size={16} />
- </div>
- )
- const dangerAlert = (
- <div className="w-6 h-6 text-red-900 flex items-center justify-center">
- <IconAlertCircle strokeWidth={2} size={16} />
- </div>
- )
-
- const indexHitRate = queryHitRate.data?.[0]?.ratio
- const tableHitRate = queryHitRate.data?.[1]?.ratio
- const showIndexWarning =
- indexHitRate && tableHitRate && (indexHitRate <= 0.99 || tableHitRate <= 0.99)
-
- const headerText = (
- <p className="whitespace-pre-wrap prose text-sm max-w-2xl text-foreground-light">
- Identify the queries that consume the most time and database resources.
- {'\n\n'}It relies on the <code>pg_stat_statements</code> table. Read more about{' '}
- <Link
- href="https://supabase.com/docs/guides/platform/performance#examining-query-performance"
- target="_blank"
- rel="noreferrer"
- >
- examining query performance
- </Link>
- .{'\n\n'}Consider resetting the analysis after optimizing any queries.
- </p>
- )
-
- const TimeConsumingHelperText = `This table lists queries ordered by their cumulative total execution time.
-
- It displays the total time a query has spent running and the proportion of total execution time the query has consumed.
-`
-
- const MostFrequentHelperText = `This table lists queries in order of their execution count, providing insights into the most frequently executed queries.
-
- Pay attention to queries with high max_time or mean_time values that are called frequently, as they may benefit from optimization.
-`
-
- const SlowestExecutionHelperText = `This table lists queries ordered by their maximum execution time. It shows outliers with high execution times. Queries with long execution times may benefit from optimization.
-
- Look for queries with high or mean execution times. These are often good candidates for optimization.
-`
- const panelClassNames = 'text-sm max-w-none flex flex-col gap-8 py-4'
- const helperTextClassNames = 'prose text-sm max-w-2xl text-foreground-light'
-
return (
- <ScaffoldContainer>
- <ScaffoldSection>
- <div className="col-span-12">
- <ReportHeader title="Query Performance" isLoading={isLoading} onRefresh={handleRefresh} />
- {tableIndexEfficiencyEnabled && (
- <Accordion
- openBehaviour="multiple"
- chevronAlign="right"
- className="border p-2 bg-surface-100 rounded"
- >
- <Accordion.Item
- header={
- <div className="flex flex-row gap-2 items-center p-2">
- <span className="text-xl">Index Efficiency</span>
- {showIndexWarning ? warnAlert : checkAlert}
- </div>
- }
- id="1"
- className="flex flex-row gap-8"
- >
- {!isLoading && queryHitRate && (
- <div>
- <div className="flex flex-row px-8 py-4 gap-8">
- <div className="w-1/2 bg-slate-200 rounded-md p-4">
- Index Hit Rate
- <div className="flex items-center gap-2">
- {indexHitRate >= 0.99
- ? checkAlert
- : indexHitRate >= 0.95
- ? warnAlert
- : dangerAlert}
- <div className="flex items-baseline">
- <span className="text-3xl">
- {queryHitRate?.data &&
- (queryHitRate?.data[0]?.ratio * 100).toFixed(2)}
- </span>
- <span className="text-xl">%</span>
- </div>
- </div>
- </div>
-
- <div className="w-1/2 bg-slate-200 rounded-md p-4">
- {queryHitRate?.data![1]?.name == 'table hit rate' && 'Table Hit Rate'}
- <div className="flex items-center gap-2">
- {tableHitRate >= 0.99
- ? checkAlert
- : tableHitRate >= 0.95
- ? warnAlert
- : dangerAlert}
- <div className="flex items-baseline">
- <span className="text-3xl">
- {queryHitRate?.data &&
- (queryHitRate?.data[1]?.ratio * 100).toFixed(2)}
- </span>
- <span className="text-xl">%</span>
- </div>
- </div>
- </div>
- </div>
- <div className="px-8 pt-4 m-0">
- <p className="text-foreground-light text-sm max-w-2xl">
- For best performance, ensure that the cache hit rate ratios above 99%.{' '}
- <br /> Consider upgrading to an instance with more memory if the ratios dip
- below 95%.
- </p>
- </div>
- </div>
- )}
- </Accordion.Item>
- </Accordion>
- )}
-
- {headerText}
-
- <div className="mb-8">
- <Button type="default" onClick={() => setShowResetgPgStatStatements(true)}>
- Reset analysis
- </Button>
- </div>
-
- <ConfirmModal
- danger
- visible={showResetgPgStatStatements}
- title="Reset query performance analysis"
- description={
- 'This will reset the `extensions.pg_stat_statements` table that is used to calculate query performance. This data will repopulate immediately after.'
- }
- buttonLabel="Clear table"
- buttonLoadingLabel="Deleting"
- onSelectCancel={() => setShowResetgPgStatStatements(false)}
- onSelectConfirm={async () => {
- try {
- await executeSql({
- projectRef: project?.ref,
- connectionString: project?.connectionString,
- sql: `SELECT pg_stat_statements_reset();`,
- })
- setShowResetgPgStatStatements(false)
- handleRefresh()
- } catch (error) {
- console.error(error)
- }
- }}
- />
-
- <div className="flex flex-col">
- <Tabs
- type="underlined"
- size="medium"
- onChange={(e: string) => {
- // To reset the search and sort query params when switching tabs
- const { sort, search, ...rest } = router.query
- router.push({
- ...router,
- query: {
- ...rest,
- preset: e,
- },
- })
- }}
- >
- <Tabs.Panel key={'time'} id="time" label="Most time consuming">
- <div className={panelClassNames}>
- <ReactMarkdown className={helperTextClassNames}>
- {TimeConsumingHelperText}
- </ReactMarkdown>
- <div className="thin-scrollbars max-w-full overflow-auto min-h-[800px]">
- <QueryPerformanceFilterBar
- onRefreshClick={handleRefresh}
- isLoading={isLoading}
- />
- <Table
- className="table-fixed"
- head={
- <>
- <Table.th className="text-ellipsis overflow-hidden">Role</Table.th>
- <Table.th className="w-[300px]">Query</Table.th>
- <Table.th className="text-right">Calls</Table.th>
- <Table.th className="text-right">Time Consumed</Table.th>
- <Table.th className="text-right">Total Time (Latency)</Table.th>
- </>
- }
- body={
- !queryPerformanceQuery.isLoading ? (
- queryPerformanceQuery?.data?.map((item, i) => {
- return (
- <ReportQueryPerformanceTableRow
- key={i + '-mosttimeconsumed'}
- sql={item.query}
- colSpan={5}
- >
- <Table.td className="truncate" title={item.rolname}>
- {item.rolname}
- </Table.td>
- <Table.td className="max-w-xs">
- <p className="font-mono line-clamp-2 text-xs">{item.query}</p>
- </Table.td>
- <Table.td className="truncate text-right">{item.calls}</Table.td>
- <Table.td className="truncate text-right">
- {item.prop_total_time}
- </Table.td>
- <Table.td className="truncate text-right">
- {item.total_time.toFixed(2)}ms
- </Table.td>
- </ReportQueryPerformanceTableRow>
- )
- })
- ) : (
- <QueryPerformanceLoadingRow colSpan={5} />
- )
- }
- />
- </div>
- </div>
- </Tabs.Panel>
- <Tabs.Panel key={'frequent'} id="frequent" label="Most frequent">
- <div className={panelClassNames}>
- <ReactMarkdown className={helperTextClassNames}>
- {MostFrequentHelperText}
- </ReactMarkdown>
- <div className="thin-scrollbars max-w-full overflow-auto min-h-[800px]">
- <QueryPerformanceFilterBar
- onRefreshClick={handleRefresh}
- isLoading={isLoading}
- />
- <Table
- head={
- <>
- <Table.th className="">Role</Table.th>
- <Table.th className="w-[300px]">Query</Table.th>
- <Table.th className="text-right">Avg. Roles</Table.th>
- <Table.th className="text-right">Calls</Table.th>
- <Table.th className="text-right">Max Time</Table.th>
- <Table.th className="text-right">Mean Time</Table.th>
- <Table.th className="text-right">Min Time</Table.th>
- <Table.th className="text-right">Total Time (Latency)</Table.th>
- </>
- }
- body={
- queryPerformanceQuery.isLoading ? (
- <QueryPerformanceLoadingRow colSpan={8} />
- ) : (
- queryPerformanceQuery.data?.map((item, i) => {
- return (
- <ReportQueryPerformanceTableRow
- key={i + '-mostfreq'}
- sql={item.query}
- colSpan={8}
- >
- <Table.td className="truncate" title={item.rolname}>
- {item.rolname}
- </Table.td>
- <Table.td className="min-w-xs">
- <p className="text-xs font-mono line-clamp-2">{item.query}</p>
- </Table.td>
- <Table.td className="truncate text-right">{item.avg_rows}</Table.td>
- <Table.td className="truncate text-right">{item.calls}</Table.td>
- <Table.td className="truncate text-right">
- {item.max_time?.toFixed(2)}ms
- </Table.td>
- <Table.td className="text-right truncate">
- {item.mean_time?.toFixed(2)}ms
- </Table.td>
- <Table.td className="text-right truncate">
- {item.min_time?.toFixed(2)}ms
- </Table.td>
- <Table.td className="text-right truncate">
- {item.total_time?.toFixed(2)}ms
- </Table.td>
- </ReportQueryPerformanceTableRow>
- )
- })
- )
- }
- />
- </div>
- </div>
- </Tabs.Panel>
- <Tabs.Panel key={'slowest'} id="slowest" label="Slowest execution time">
- <div className={panelClassNames}>
- <ReactMarkdown className={helperTextClassNames}>
- {SlowestExecutionHelperText}
- </ReactMarkdown>
- <div className="thin-scrollbars max-w-full overflow-auto min-h-[800px]">
- <QueryPerformanceFilterBar
- onRefreshClick={handleRefresh}
- isLoading={isLoading}
- />
- <Table
- head={
- <>
- <Table.th className="table-cell">Role</Table.th>
- <Table.th className="table-cell">Query</Table.th>
- <Table.th className="table-cell">Avg Rows</Table.th>
- <Table.th className="table-cell">Calls</Table.th>
- <Table.th className="table-cell">Max Time</Table.th>
- <Table.th className="table-cell">Mean Time</Table.th>
- <Table.th className="table-cell">Min Time</Table.th>
- <Table.th className="table-cell">Total Time (Latency)</Table.th>
- </>
- }
- body={
- queryPerformanceQuery.isLoading ? (
- <QueryPerformanceLoadingRow colSpan={8} />
- ) : (
- queryPerformanceQuery.data?.map((item, i) => {
- return (
- <ReportQueryPerformanceTableRow
- key={i + '-slowestexec'}
- sql={item.query}
- colSpan={8}
- >
- <Table.td className="truncate" title={item.rolname}>
- {item.rolname}
- </Table.td>
- <Table.td className="max-w-xs">
- <p className="font-mono line-clamp-2 text-xs">{item.query}</p>
- </Table.td>
- <Table.td className="truncate">{item.avg_rows}</Table.td>
- <Table.td className="truncate">{item.calls}</Table.td>
- <Table.td className="truncate">
- {item.max_time?.toFixed(2)}ms
- </Table.td>
- <Table.td className="truncate">
- {item.mean_time?.toFixed(2)}ms
- </Table.td>
- <Table.td className="truncate">
- {item.min_time?.toFixed(2)}ms
- </Table.td>
- <Table.td className="truncate">
- {item.total_time?.toFixed(2)}ms
- </Table.td>
- </ReportQueryPerformanceTableRow>
- )
- })
- )
- }
- />
- </div>
- </div>
- </Tabs.Panel>
- </Tabs>
+ <>
+ <ScaffoldContainer>
+ <ScaffoldSection>
+ <div className="col-span-12 flex flex-col gap-y-4">
+ <FormHeader
+ className="!mb-0"
+ title="Query Performance"
+ description="Identify queries that consume the most time and database resources via the `pg_stat_statements` table"
+ docsUrl="https://supabase.com/docs/guides/platform/performance#examining-query-performance"
+ />
+
+ {tableIndexEfficiencyEnabled && <IndexEfficiencyNotice isLoading={isLoading} />}
+ <QueryPerformance
+ queryHitRate={queryHitRate}
+ queryPerformanceQuery={queryPerformanceQuery}
+ />
</div>
- </div>
- </ScaffoldSection>
- </ScaffoldContainer>
+ </ScaffoldSection>
+ </ScaffoldContainer>
+ </>
)
}
diff --git a/apps/studio/pages/project/[ref]/database/replication.tsx b/apps/studio/pages/project/[ref]/database/replication.tsx
index 68bb20bab86..5b4df2aa27d 100644
--- a/apps/studio/pages/project/[ref]/database/replication.tsx
+++ b/apps/studio/pages/project/[ref]/database/replication.tsx
@@ -9,6 +9,7 @@ import NoPermission from 'components/ui/NoPermission'
import { useDatabasePublicationsQuery } from 'data/database-publications/database-publications-query'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks'
import type { NextPageWithLayout } from 'types'
+import { FormHeader } from 'components/ui/Forms'
// [Joshen] Technically, best that we have these as separate URLs
// makes it easier to manage state, but foresee that this page might
@@ -40,9 +41,7 @@ const DatabaseReplication: NextPageWithLayout = () => {
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
- <div className="mb-4">
- <h3 className="mb-1 text-xl text-foreground">Database Replications</h3>
- </div>
+ <FormHeader title="Database Replications" />
{selectedPublication === undefined ? (
<PublicationsList onSelectPublication={setSelectedPublicationId} />
) : (
diff --git a/apps/studio/pages/project/[ref]/database/roles.tsx b/apps/studio/pages/project/[ref]/database/roles.tsx
index 6d4f48871ad..0ba69c26798 100644
--- a/apps/studio/pages/project/[ref]/database/roles.tsx
+++ b/apps/studio/pages/project/[ref]/database/roles.tsx
@@ -1,6 +1,7 @@
import { RolesList } from 'components/interfaces/Database'
import { DatabaseLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import type { NextPageWithLayout } from 'types'
const DatabaseRoles: NextPageWithLayout = () => {
@@ -8,6 +9,10 @@ const DatabaseRoles: NextPageWithLayout = () => {
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
+ <FormHeader
+ title="Database Roles"
+ description="Manage access control to your database through users, groups, and permissions"
+ />
<RolesList />
</div>
</ScaffoldSection>
diff --git a/apps/studio/pages/project/[ref]/database/tables/[id].tsx b/apps/studio/pages/project/[ref]/database/tables/[id].tsx
index 4dc8106eb50..0c30aca5cff 100644
--- a/apps/studio/pages/project/[ref]/database/tables/[id].tsx
+++ b/apps/studio/pages/project/[ref]/database/tables/[id].tsx
@@ -6,20 +6,32 @@ import { SidePanelEditor } from 'components/interfaces/TableGridEditor'
import DeleteConfirmationDialogs from 'components/interfaces/TableGridEditor/DeleteConfirmationDialogs'
import { DatabaseLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import useTable from 'hooks/misc/useTable'
+import { ChevronRight } from 'lucide-react'
import { useTableEditorStateSnapshot } from 'state/table-editor'
import type { NextPageWithLayout } from 'types'
+import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
const DatabaseTables: NextPageWithLayout = () => {
const { id } = useParams()
const snap = useTableEditorStateSnapshot()
- const { data: selectedTable } = useTable(Number(id))
+ const { data: selectedTable, isLoading } = useTable(Number(id))
return (
<>
<ScaffoldContainer>
<ScaffoldSection>
- <div className="col-span-12">
+ <div className="col-span-12 space-y-6">
+ <div className="flex items-center space-x-2">
+ <FormHeader className="!mb-0" title="Database Tables" />
+ <ChevronRight size={18} strokeWidth={1.5} className="text-foreground-light" />
+ {isLoading ? (
+ <ShimmeringLoader className="w-40" />
+ ) : (
+ <FormHeader className="!mb-0" title={selectedTable?.name ?? ''} />
+ )}
+ </div>
<ColumnList
onAddColumn={snap.onAddColumn}
onEditColumn={snap.onEditColumn}
diff --git a/apps/studio/pages/project/[ref]/database/tables/index.tsx b/apps/studio/pages/project/[ref]/database/tables/index.tsx
index 02906ad3f6b..beeb36237cf 100644
--- a/apps/studio/pages/project/[ref]/database/tables/index.tsx
+++ b/apps/studio/pages/project/[ref]/database/tables/index.tsx
@@ -1,11 +1,11 @@
import { useState } from 'react'
-import { useParams } from 'common'
import { TableList } from 'components/interfaces/Database'
import { SidePanelEditor } from 'components/interfaces/TableGridEditor'
import DeleteConfirmationDialogs from 'components/interfaces/TableGridEditor/DeleteConfirmationDialogs'
import { DatabaseLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import type { Table } from 'data/tables/table-query'
import { useTableEditorStateSnapshot } from 'state/table-editor'
import type { NextPageWithLayout } from 'types'
@@ -19,6 +19,7 @@ const DatabaseTables: NextPageWithLayout = () => {
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
+ <FormHeader title="Database Tables" />
<TableList
onAddTable={snap.onAddTable}
onEditTable={(table) => {
diff --git a/apps/studio/pages/project/[ref]/database/triggers.tsx b/apps/studio/pages/project/[ref]/database/triggers.tsx
index 4fd2c098dce..f8daed7cf35 100644
--- a/apps/studio/pages/project/[ref]/database/triggers.tsx
+++ b/apps/studio/pages/project/[ref]/database/triggers.tsx
@@ -5,6 +5,7 @@ import { CreateTrigger, DeleteTrigger } from 'components/interfaces/Database'
import TriggersList from 'components/interfaces/Database/Triggers/TriggersList/TriggersList'
import { DatabaseLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import NoPermission from 'components/ui/NoPermission'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks'
import type { NextPageWithLayout } from 'types'
@@ -41,7 +42,7 @@ const TriggersPage: NextPageWithLayout = () => {
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
- <h3 className="mb-4 text-xl text-foreground">Database Triggers</h3>
+ <FormHeader title="Database Triggers" />
<TriggersList
createTrigger={createTrigger}
editTrigger={editTrigger}
diff --git a/apps/studio/pages/project/[ref]/database/types.tsx b/apps/studio/pages/project/[ref]/database/types.tsx
index 450b9a8fee3..8c5e5737e91 100644
--- a/apps/studio/pages/project/[ref]/database/types.tsx
+++ b/apps/studio/pages/project/[ref]/database/types.tsx
@@ -1,5 +1,4 @@
-import Link from 'next/link'
-import { Button, IconExternalLink } from 'ui'
+import { ExternalLink } from 'lucide-react'
import { EnumeratedTypes } from 'components/interfaces/Database'
import { DatabaseLayout } from 'components/layouts'
@@ -9,38 +8,38 @@ import {
ScaffoldSectionContent,
ScaffoldSectionDetail,
} from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import type { NextPageWithLayout } from 'types'
+import { Button } from 'ui'
const DatabaseEnumeratedTypes: NextPageWithLayout = () => {
return (
- <>
- <ScaffoldContainer>
- <ScaffoldSection>
- <ScaffoldSectionContent className="gap-0" title="Database Enumerated Types">
- <h3 className="mb-1 text-xl text-foreground">Database Enumerated Types</h3>
- <p className="text-sm text-foreground-lighter">
- Custom data types that you can use in your database tables or functions.
- </p>
- </ScaffoldSectionContent>
- <ScaffoldSectionDetail className="flex items-center justify-end">
- <div>
- <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>
- <Link
- href="https://www.postgresql.org/docs/current/datatype-enum.html"
- target="_blank"
- rel="noreferrer"
- >
- Documentation
- </Link>
- </Button>
- </div>
- </ScaffoldSectionDetail>
- <div className="col-span-12 mt-3">
- <EnumeratedTypes />
- </div>
- </ScaffoldSection>
- </ScaffoldContainer>
- </>
+ <ScaffoldContainer>
+ <ScaffoldSection>
+ <ScaffoldSectionContent>
+ <FormHeader
+ className="!mb-0"
+ title="Database Enumerated Types"
+ description="Custom data types that you can use in your database tables or functions."
+ />
+ </ScaffoldSectionContent>
+ <ScaffoldSectionDetail className="flex items-center justify-end">
+ <Button asChild type="default" icon={<ExternalLink size={14} strokeWidth={1.5} />}>
+ <a
+ target="_blank"
+ rel="noreferrer"
+ className="no-underline"
+ href="https://www.postgresql.org/docs/current/datatype-enum.html"
+ >
+ Documentation
+ </a>
+ </Button>
+ </ScaffoldSectionDetail>
+ <div className="col-span-12 mt-3">
+ <EnumeratedTypes />
+ </div>
+ </ScaffoldSection>
+ </ScaffoldContainer>
)
}
diff --git a/apps/studio/pages/project/[ref]/database/wrappers/index.tsx b/apps/studio/pages/project/[ref]/database/wrappers/index.tsx
index 7b18ac978df..b1ed00123fc 100644
--- a/apps/studio/pages/project/[ref]/database/wrappers/index.tsx
+++ b/apps/studio/pages/project/[ref]/database/wrappers/index.tsx
@@ -1,31 +1,85 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { ExternalLink } from 'lucide-react'
import { Wrappers } from 'components/interfaces/Database'
+import WrappersDropdown from 'components/interfaces/Database/Wrappers/WrappersDropdown'
import { DatabaseLayout } from 'components/layouts'
-import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
+import {
+ ScaffoldContainer,
+ ScaffoldSection,
+ ScaffoldSectionContent,
+ ScaffoldSectionDetail,
+} from 'components/layouts/Scaffold'
+import { FormHeader } from 'components/ui/Forms'
import NoPermission from 'components/ui/NoPermission'
+import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'
+import { useFDWsQuery } from 'data/fdw/fdws-query'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks'
import type { NextPageWithLayout } from 'types'
+import { Button } from 'ui'
+import { GenericSkeletonLoader } from 'ui-patterns'
const DatabaseWrappers: NextPageWithLayout = () => {
- const canReadWrappers = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_READ, 'tables')
+ const { project } = useProjectContext()
const isPermissionsLoaded = usePermissionsLoaded()
+ const canReadWrappers = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_READ, 'tables')
- if (isPermissionsLoaded && !canReadWrappers) {
- return <NoPermission isFullPage resourceText="view foreign data wrappers" />
- }
+ const { isLoading: isLoadingFDWs } = useFDWsQuery({
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ })
+ const { data: exts, isLoading: isLoadingExtensions } = useDatabaseExtensionsQuery({
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ })
+ const wrappersExtension = (exts ?? []).find((ext) => ext.name === 'wrappers')
+ const vaultExtension = (exts ?? []).find((ext) => ext.name === 'supabase_vault')
- return <Wrappers />
-}
+ const isWrappersEnabled =
+ wrappersExtension !== undefined &&
+ wrappersExtension.installed_version !== null &&
+ vaultExtension !== undefined &&
+ vaultExtension.installed_version !== null
-DatabaseWrappers.getLayout = (page) => (
- <DatabaseLayout title="Wrappers">
+ return (
<ScaffoldContainer>
<ScaffoldSection>
- <div className="col-span-12">{page}</div>
+ <ScaffoldSectionContent>
+ <FormHeader
+ className="!mb-0"
+ title="Foreign Data Wrappers"
+ description="Query your data warehouse directly from your database, or third-party APIs using SQL"
+ />
+ </ScaffoldSectionContent>
+ <ScaffoldSectionDetail className="flex items-center justify-end gap-x-2">
+ <Button asChild type="default" icon={<ExternalLink size={14} strokeWidth={1.5} />}>
+ <a
+ target="_blank"
+ rel="noreferrer"
+ className="no-underline"
+ href="https://supabase.com/docs/guides/database/extensions/wrappers/overview"
+ >
+ Documentation
+ </a>
+ </Button>
+ {isWrappersEnabled && <WrappersDropdown />}
+ </ScaffoldSectionDetail>
+
+ <div className="col-span-12 mt-3">
+ {isLoadingExtensions || isLoadingFDWs ? (
+ <GenericSkeletonLoader />
+ ) : isPermissionsLoaded && !canReadWrappers ? (
+ <NoPermission isFullPage resourceText="view foreign data wrappers" />
+ ) : (
+ <Wrappers isEnabled={isWrappersEnabled} />
+ )}
+ </div>
</ScaffoldSection>
</ScaffoldContainer>
- </DatabaseLayout>
-)
+ )
+}
+
+DatabaseWrappers.getLayout = (page) => <DatabaseLayout title="Wrappers">{page}</DatabaseLayout>
export default DatabaseWrappers
diff --git a/apps/studio/pages/project/[ref]/reports/api-overview.tsx b/apps/studio/pages/project/[ref]/reports/api-overview.tsx
index 3e3abb54d1b..6774133f4ea 100644
--- a/apps/studio/pages/project/[ref]/reports/api-overview.tsx
+++ b/apps/studio/pages/project/[ref]/reports/api-overview.tsx
@@ -42,7 +42,7 @@ export const ApiReport: NextPageWithLayout = () => {
return (
<ReportPadding>
- <ReportHeader title="API" isLoading={report.isLoading} onRefresh={report.refresh} />
+ <ReportHeader title="API" />
<div className="w-full flex flex-col gap-1">
<ReportFilterBar
onRemoveFilters={report.removeFilters}
diff --git a/apps/studio/pages/project/[ref]/reports/storage.tsx b/apps/studio/pages/project/[ref]/reports/storage.tsx
index 330f41e045f..1a1da3f76c9 100644
--- a/apps/studio/pages/project/[ref]/reports/storage.tsx
+++ b/apps/studio/pages/project/[ref]/reports/storage.tsx
@@ -45,7 +45,7 @@ export const StorageReport: NextPageWithLayout = () => {
return (
<ReportPadding>
- <ReportHeader title="Storage" isLoading={report.isLoading} onRefresh={report.refresh} />
+ <ReportHeader title="Storage" />
<div className="w-full flex flex-col gap-1">
<div>
<DatePickers