From 522a921fda1b876e02c5fd338dd3755ffa76d893 Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Mon, 2 Oct 2023 13:09:34 -0230 Subject: [PATCH] Chore/add settings panels to cmdk (#17784) * Fix searchable item command, add settings panel ids * Update * Add support for hash urls to no-project-selected page (_). * Fix some of the labels. --------- Co-authored-by: Ivan Vasilov --- .../src/components/Command/SearchOnlyItem.tsx | 28 +++- .../Command/SearchableStudioItems.tsx | 9 +- .../Command/utils/shared-nav-items.json | 132 ++++++++++++------ .../Settings/Database/BannedIPs.tsx | 2 +- .../Settings/Database/ConnectionPooling.tsx | 2 +- .../DatabaseSettings/DatabaseSettings.tsx | 2 +- .../DatabaseSettings/ResetDbPassword.tsx | 5 +- .../NetworkRestrictions.tsx | 2 +- .../Settings/Database/SSLConfiguration.tsx | 2 +- .../CustomDomainConfig/CustomDomainConfig.tsx | 2 +- .../DeleteProjectPanel/DeleteProjectPanel.tsx | 2 +- .../interfaces/Settings/General/General.tsx | 7 +- .../TransferProjectPanel.tsx | 2 +- studio/pages/project/_/[[...routeSlug]].tsx | 16 ++- 14 files changed, 143 insertions(+), 70 deletions(-) diff --git a/packages/ui/src/components/Command/SearchOnlyItem.tsx b/packages/ui/src/components/Command/SearchOnlyItem.tsx index f6c13c8e6c6..948d65d6df3 100644 --- a/packages/ui/src/components/Command/SearchOnlyItem.tsx +++ b/packages/ui/src/components/Command/SearchOnlyItem.tsx @@ -1,5 +1,29 @@ import { CommandItem } from './Command.utils' +import { useRouter } from 'next/router' +import { useCommandMenu } from './CommandMenuProvider' -export default function SearchOnlyItem({ children, isSubItem, ...props }: any) { - return {children} +interface SearchOnlyItemProps { + children: React.ReactNode + url: string +} + +export default function SearchOnlyItem({ children, url }: SearchOnlyItemProps) { + const { project, setIsOpen, setSearch } = useCommandMenu() + const router = useRouter() + + const baseURL = process.env.NEXT_PUBLIC_SITE_URL + function handleRouteChange(url: string) { + const localizedURL = project?.ref + ? `${baseURL}${url.replace('/_/', `/${project?.ref}/`)}` + : `${baseURL}${url}` + + router.push(localizedURL) + setIsOpen(false) + setSearch('') + } + return ( + handleRouteChange(url)}> + {children} + + ) } diff --git a/packages/ui/src/components/Command/SearchableStudioItems.tsx b/packages/ui/src/components/Command/SearchableStudioItems.tsx index 9073944bf08..9da3925c58e 100644 --- a/packages/ui/src/components/Command/SearchableStudioItems.tsx +++ b/packages/ui/src/components/Command/SearchableStudioItems.tsx @@ -1,23 +1,16 @@ import { CommandGroup } from './Command.utils' import SearchOnlyItem from './SearchOnlyItem' -import { useRouter } from 'next/router' import sharedItems from './utils/shared-nav-items.json' export default function SearchableStudioItems() { - const router = useRouter() - return ( {sharedItems.tools .filter((item) => item.subItems) // filter items with subItems .flatMap((item) => item.subItems?.map((subItem) => ( - router.push(subItem.url)} - > + {subItem.label} )) diff --git a/packages/ui/src/components/Command/utils/shared-nav-items.json b/packages/ui/src/components/Command/utils/shared-nav-items.json index ef67f827328..2e6faf98096 100644 --- a/packages/ui/src/components/Command/utils/shared-nav-items.json +++ b/packages/ui/src/components/Command/utils/shared-nav-items.json @@ -2,171 +2,211 @@ "tools": [ { "label": "Table Editor", - "url": "https://supabase.com/dashboard/project/_/editor" + "url": "/project/_/editor" }, { "label": "SQL Editor", - "url": "https://supabase.com/dashboard/project/_/sql" + "url": "/project/_/sql" }, { "label": "Database", - "url": "https://supabase.com/dashboard/project/_/database/tables", + "url": "/project/_/database/tables", "subItems": [ { "label": "Tables", - "url": "https://supabase.com/dashboard/project/_/database/tables" + "url": "/project/_/database/tables" }, { "label": "Triggers", - "url": "https://supabase.com/dashboard/project/_/database/triggers" + "url": "/project/_/database/triggers" }, { "label": "Functions", - "url": "https://supabase.com/dashboard/project/_/database/functions" + "url": "/project/_/database/functions" }, { "label": "Extensions", - "url": "https://supabase.com/dashboard/project/_/database/extensions" + "url": "/project/_/database/extensions" }, { "label": "Roles", - "url": "https://supabase.com/dashboard/project/_/database/roles" + "url": "/project/_/database/roles" }, { "label": "Replication", - "url": "https://supabase.com/dashboard/project/_/database/replication" + "url": "/project/_/database/replication" }, { "label": "Webhooks", - "url": "https://supabase.com/dashboard/project/_/database/webhooks" + "url": "/project/_/database/hooks" }, { "label": "Backups", - "url": "https://supabase.com/dashboard/project/_/database/backups/scheduled" + "url": "/project/_/database/backups/scheduled" } ] }, { "label": "Auth", - "url": "https://supabase.com/dashboard/project/_/auth/users", + "url": "/project/_/auth/users", "subItems": [ { "label": "Users", - "url": "https://supabase.com/dashboard/project/_/auth/users" + "url": "/project/_/auth/users" }, { "label": "Policies", - "url": "https://supabase.com/dashboard/project/_/auth/policies" + "url": "/project/_/auth/policies" }, { "label": "Providers", - "url": "https://supabase.com/dashboard/project/_/auth/providers" + "url": "/project/_/auth/providers" }, { "label": "Email Templates", - "url": "https://supabase.com/dashboard/project/_/auth/templates" + "url": "/project/_/auth/templates" }, { "label": "URL Configuration", - "url": "https://supabase.com/dashboard/project/_/auth/url-configuration" + "url": "/project/_/auth/url-configuration" } ] }, { "label": "Storage", - "url": "https://supabase.com/dashboard/project/_/storage" + "url": "/project/_/storage" }, { "label": "Edge Functions", - "url": "https://supabase.com/dashboard/project/_/functions" + "url": "/project/_/functions" }, { "label": "Logs", - "url": "https://supabase.com/dashboard/project/_/logs/explorer", + "url": "/project/_/logs/explorer", "subItems": [ { "label": "Postgres logs", - "url": "https://supabase.com/dashboard/project/_/logs/postgres-logs" + "url": "/project/_/logs/postgres-logs" }, { "label": "PostgREST logs", - "url": "https://supabase.com/dashboard/project/_/logs/postgrest-logs" + "url": "/project/_/logs/postgrest-logs" }, { "label": "Pooler logs", - "url": "https://supabase.com/dashboard/project/_/logs/pooler-logs" + "url": "/project/_/logs/pooler-logs" }, { - "label": "Auth logs logs", - "url": "https://supabase.com/dashboard/project/_/logs/auth-logs" + "label": "Auth logs", + "url": "/project/_/logs/auth-logs" }, { "label": "Storage logs", - "url": "https://supabase.com/dashboard/project/_/logs/storage-logs" + "url": "/project/_/logs/storage-logs" }, { - "label": "realtime logs", - "url": "https://supabase.com/dashboard/project/_/logs/realtime-logs" + "label": "Realtime logs", + "url": "/project/_/logs/realtime-logs" } ] }, { "label": "API Docs", - "url": "https://supabase.com/dashboard/project/_/api", + "url": "/project/_/api", "subItems": [ { "label": "Auth docs", - "url": "https://supabase.com/dashboard/project/_/api?page=auth" + "url": "/project/_/api?page=auth" }, { "label": "User management docs", - "url": "https://supabase.com/dashboard/project/_/api?page=users" + "url": "/project/_/api?page=users" }, { - "label": "Graphql", - "url": "https://supabase.com/dashboard/project/_/api/graphiql" + "label": "GraphQL", + "url": "/project/_/api/graphiql" } ] }, { "label": "Project Settings", - "url": "https://supabase.com/dashboard/project/_/settings/general", + "url": "/project/_/settings/general", "subItems": [ { "label": "General settings", - "url": "https://supabase.com/dashboard/project/_/settings/general" + "url": "/project/_/settings/general" }, { "label": "Database settings", - "url": "https://supabase.com/dashboard/project/_/settings/database" + "url": "/project/_/settings/database" }, { "label": "API settings", - "url": "https://supabase.com/dashboard/project/_/settings/api" + "url": "/project/_/settings/api" }, { "label": "Auth settings", - "url": "https://supabase.com/dashboard/project/_/settings/auth" + "url": "/project/_/settings/auth" }, { "label": "Storage settings", - "url": "https://supabase.com/dashboard/project/_/settings/storage" + "url": "/project/_/settings/storage" }, { "label": "Subscription settings", - "url": "https://supabase.com/dashboard/project/_/settings/billing/subscription" + "url": "/project/_/settings/billing/subscription" }, { "label": "Project Usage", - "url": "https://supabase.com/dashboard/project/_/settings/billing/usage" + "url": "/project/_/settings/billing/usage" }, { "label": "Project Invoices", - "url": "https://supabase.com/dashboard/project/_/settings/billing/invoices" + "url": "/project/_/settings/billing/invoices" }, { - "label": "Project Invoices", - "url": "https://supabase.com/dashboard/project/_/settings/billing/invoices" + "label": "Custom Domains", + "url": "/project/_/settings/general#custom-domains" + }, + { + "label": "Restart project", + "url": "/project/_/settings/general#restart-project" + }, + { + "label": "Pause project", + "url": "/project/_/settings/general#pause-project" + }, + { + "label": "Transfer project", + "url": "/project/_/settings/general#transfer-project" + }, + { + "label": "Delete project", + "url": "/project/_/settings/general#delete-project" + }, + { + "label": "Database password", + "url": "/project/_/settings/database#database-password" + }, + { + "label": "Connection string", + "url": "/project/_/settings/database#connection-string" + }, + { + "label": "Connection pooling", + "url": "/project/_/settings/database#connection-pooling" + }, + { + "label": "SSL Configuration", + "url": "/project/_/settings/database#ssl-configuration" + }, + { + "label": "Network Restrictions", + "url": "/project/_/settings/database#network-restrictions" + }, + { + "label": "Banned IPs", + "url": "/project/_/settings/database#banned-ips" } ] } @@ -174,11 +214,11 @@ "projectTools": [ { "label": "Your Projects", - "url": "https://supabase.com/dashboard/projects" + "url": "/projects" }, { "label": "Project API Keys", - "url": "https://supabase.com/dashboard/project/_/settings/api" + "url": "/project/_/settings/api" } ], "support": [ diff --git a/studio/components/interfaces/Settings/Database/BannedIPs.tsx b/studio/components/interfaces/Settings/Database/BannedIPs.tsx index 8184e550073..e4c9b33560f 100644 --- a/studio/components/interfaces/Settings/Database/BannedIPs.tsx +++ b/studio/components/interfaces/Settings/Database/BannedIPs.tsx @@ -61,7 +61,7 @@ const BannedIPs = () => { } return ( -
+
+
{
+
Connection string
} diff --git a/studio/components/interfaces/Settings/Database/DatabaseSettings/ResetDbPassword.tsx b/studio/components/interfaces/Settings/Database/DatabaseSettings/ResetDbPassword.tsx index 15876cce29d..e7192c94fe4 100644 --- a/studio/components/interfaces/Settings/Database/DatabaseSettings/ResetDbPassword.tsx +++ b/studio/components/interfaces/Settings/Database/DatabaseSettings/ResetDbPassword.tsx @@ -100,7 +100,10 @@ const ResetDbPassword = ({ disabled = false }) => { <> -
+

Database password

diff --git a/studio/components/interfaces/Settings/Database/NetworkRestrictions/NetworkRestrictions.tsx b/studio/components/interfaces/Settings/Database/NetworkRestrictions/NetworkRestrictions.tsx index c1662c1ee65..0814036169f 100644 --- a/studio/components/interfaces/Settings/Database/NetworkRestrictions/NetworkRestrictions.tsx +++ b/studio/components/interfaces/Settings/Database/NetworkRestrictions/NetworkRestrictions.tsx @@ -103,7 +103,7 @@ const NetworkRestrictions = ({}) => { return ( <> -

+
{ } return ( -
+
diff --git a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx index c1fc13403f3..4ee6623daaf 100644 --- a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx +++ b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx @@ -34,7 +34,7 @@ const CustomDomainConfig = () => { const isLoading = isSettingsLoading || isCustomDomainsLoading return ( -
+
{isLoading ? ( diff --git a/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel.tsx b/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel.tsx index b4afefdac56..31520100d9d 100644 --- a/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel.tsx +++ b/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel.tsx @@ -10,7 +10,7 @@ const DeleteProjectPanel = () => { if (project === undefined) return null return ( -
+
diff --git a/studio/components/interfaces/Settings/General/General.tsx b/studio/components/interfaces/Settings/General/General.tsx index 311e032e43b..c922bf2dad7 100644 --- a/studio/components/interfaces/Settings/General/General.tsx +++ b/studio/components/interfaces/Settings/General/General.tsx @@ -118,7 +118,7 @@ const General = () => { )} {!isBranch && isOrgBilling && ( <> -
+
@@ -131,7 +131,10 @@ const General = () => {
-
+

Pause project

diff --git a/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel.tsx b/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel.tsx index 3b7805bdf0c..438e64c1787 100644 --- a/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel.tsx +++ b/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel.tsx @@ -11,7 +11,7 @@ const TransferProjectPanel = () => { if (project === undefined) return <> return ( -
+
{ const urlRewriterFactory = (slug: string | string[] | undefined) => { return (projectRef: string) => { + const hash = location.hash + if (!Array.isArray(slug)) { - return `/project/${projectRef}?${queryString}` + return [`/project/${projectRef}`, queryString ?? `?${queryString}`, hash ?? `#${hash}`] + .filter(Boolean) + .join('') } - const slugPath = slug.reduce((a: string, b: string) => `${a}/${b}`, '').slice(1) - return `/project/${projectRef}/${slugPath}?${queryString}` + const slugPath = slug.reduce((a, b) => `${a}/${b}`, '').slice(1) + return [ + `/project/${projectRef}/${slugPath}`, + queryString ?? `?${queryString}`, + hash ?? `#${hash}`, + ] + .filter(Boolean) + .join('') } }