Skip to content

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

chore: use comboboxes. fix: issues with validation and loading states

Jonathan Summers-Muir57b7cafc22cc
diff --git a/studio/components/interfaces/Integrations/ProjectLinker.tsx b/studio/components/interfaces/Integrations/ProjectLinker.tsx
index 3c03dbf58f4..d0b66326a9c 100644
--- a/studio/components/interfaces/Integrations/ProjectLinker.tsx
+++ b/studio/components/interfaces/Integrations/ProjectLinker.tsx
@@ -1,6 +1,3 @@
-import { useRef, useState } from 'react'
-import { toast } from 'react-hot-toast'
-
import { ENV_VAR_RAW_KEYS } from 'components/interfaces/Integrations/Integrations-Vercel.constants'
import { Markdown } from 'components/interfaces/Markdown'
import { vercelIcon } from 'components/to-be-cleaned/ListIcons'
@@ -10,6 +7,8 @@ import { VercelProjectsResponse } from 'data/integrations/integrations-vercel-pr
import { IntegrationProjectConnection } from 'data/integrations/integrations.types'
import { useSelectedOrganization } from 'hooks'
import { BASE_PATH } from 'lib/constants'
+import { useRef, useState } from 'react'
+import { toast } from 'react-hot-toast'
import {
Button,
CommandEmpty_Shadcn_,
@@ -19,8 +18,6 @@ import {
CommandList_Shadcn_,
Command_Shadcn_,
IconChevronDown,
- IconHexagon,
- Listbox,
PopoverContent_Shadcn_,
PopoverTrigger_Shadcn_,
Popover_Shadcn_,
@@ -41,10 +38,10 @@ export interface ProjectLinkerProps {
installedConnections: IntegrationProjectConnection[] | undefined
setLoading?: (x: boolean) => void
showSkip?: boolean
+ loadingForeignProjects?: boolean
+ loadingSupabaseProjects?: boolean
}
-const UNDEFINED_SELECT_VALUE = 'undefined'
-
const ProjectLinker = ({
organizationIntegrationId,
foreignProjects,
@@ -53,6 +50,8 @@ const ProjectLinker = ({
installedConnections = [],
setLoading,
showSkip = false,
+ loadingForeignProjects,
+ loadingSupabaseProjects,
}: ProjectLinkerProps) => {
const [supabaseProjectsComboBoxOpen, setSupabaseProjectsComboboxOpen] = useState(false)
const [vercelProjectsComboBoxOpen, setVercelProjectsComboboxOpen] = useState(false)
@@ -61,8 +60,8 @@ const ProjectLinker = ({
const selectedOrganization = useSelectedOrganization()
- const [supabaseProjectRef, setSupabaseProjectRef] = useState(UNDEFINED_SELECT_VALUE)
- const [vercelProjectId, setVercelProjectId] = useState(UNDEFINED_SELECT_VALUE)
+ const [supabaseProjectRef, setSupabaseProjectRef] = useState<string | undefined>(undefined)
+ const [vercelProjectId, setVercelProjectId] = useState<string | undefined>(undefined)
const { mutateAsync: syncEnvs } = useIntegrationsVercelConnectionSyncEnvsMutation()
const { mutate: createConnections, isLoading } = useIntegrationConnectionsCreateMutation({
@@ -113,7 +112,7 @@ const ProjectLinker = ({
return (
<div
className={cn(
- 'flex flex-col gap-6 px-5 mx-auto w-full justify-center items-center',
+ 'flex flex-col grow gap-6 px-5 mx-auto w-full justify-center items-center',
className
)}
{...props}
@@ -133,6 +132,20 @@ const ProjectLinker = ({
}
)
+ const selectedSupabaseProject = supabaseProjectRef
+ ? supabaseProjects.find((x) => x.ref?.toLowerCase() === supabaseProjectRef?.toLowerCase())
+ : undefined
+ const selectedVercelProject = vercelProjectId
+ ? filteredForeignProjects.find((x) => x.id?.toLowerCase() === vercelProjectId?.toLowerCase())
+ : undefined
+
+ // console.log('selectedSupabaseProject', selectedSupabaseProject)
+ console.log('filteredForeignProjects', filteredForeignProjects)
+ console.log('vercelProjectId', vercelProjectId)
+ console.log('selectedVercelProject', selectedVercelProject)
+
+ // console.log('supabaseProjects', supabaseProjects)
+
return (
<div className="flex flex-col gap-4">
<div className="relative border rounded-lg p-12 bg shadow">
@@ -156,6 +169,8 @@ const ProjectLinker = ({
type="default"
size="medium"
block
+ disabled={loadingSupabaseProjects}
+ loading={loadingSupabaseProjects}
className="justify-start"
icon={
<div className="bg-white shadow border rounded p-1 w-6 h-6 flex justify-center items-center">
@@ -172,12 +187,7 @@ const ProjectLinker = ({
</span>
}
>
- <span className="flex gap-2">
- {supabaseProjectRef ?? UNDEFINED_SELECT_VALUE}
- {/* {selectedOrg?.installationInstalled && (
- <Badge color="scale">Integration Installed</Badge>
- )} */}
- </span>
+ {selectedSupabaseProject ? selectedSupabaseProject.name : 'Choose Project'}
</Button>
</PopoverTrigger_Shadcn_>
<PopoverContent_Shadcn_
@@ -188,7 +198,7 @@ const ProjectLinker = ({
>
<Command_Shadcn_>
<CommandInput_Shadcn_ placeholder="Search organization..." />
- <CommandList_Shadcn_>
+ <CommandList_Shadcn_ className="!max-h-[170px]">
<CommandEmpty_Shadcn_>No results found.</CommandEmpty_Shadcn_>
<CommandGroup_Shadcn_>
{supabaseProjects.map((project) => {
@@ -218,38 +228,6 @@ const ProjectLinker = ({
</Command_Shadcn_>
</PopoverContent_Shadcn_>
</Popover_Shadcn_>
-
- <Listbox
- className="w-full"
- value={supabaseProjectRef ?? UNDEFINED_SELECT_VALUE}
- onChange={(e) => setSupabaseProjectRef(e)}
- >
- <Listbox.Option value={UNDEFINED_SELECT_VALUE} label="Choose a project" disabled>
- Choose project
- </Listbox.Option>
- {supabaseProjects.map((project) => (
- <Listbox.Option
- key={project.id}
- value={project.ref}
- label={project.name}
- addOnBefore={() => {
- return (
- <>
- <div className="bg-white shadow border rounded p-1 w-6 h-6 flex justify-center items-center">
- <img
- src={`${BASE_PATH}/img/supabase-logo.svg`}
- alt="Supabase"
- className="w-4"
- />
- </div>
- </>
- )
- }}
- >
- {project.name}
- </Listbox.Option>
- ))}
- </Listbox>
</Panel>
<div className="border border-scale-1000 h-px w-16 border-dashed self-end mb-5"></div>
<Panel>
@@ -271,46 +249,48 @@ const ProjectLinker = ({
>
<PopoverTrigger_Shadcn_ asChild>
<Button
- ref={supabaseProjectsComboBoxRef}
+ ref={vercelProjectsComboBoxRef}
type="default"
size="medium"
block
+ disabled={loadingForeignProjects}
+ loading={loadingForeignProjects}
className="justify-start"
- // icon={
- // !project?.framework ? (
- // vercelIcon
- // ) : (
- // <img
- // src={`${BASE_PATH}/img/icons/frameworks/${project.framework}.svg`}
- // width={21}
- // height={21}
- // alt={`icon`}
- // />
- // )
- // }
+ icon={
+ selectedVercelProject ? (
+ selectedVercelProject?.framework ? (
+ vercelIcon
+ ) : (
+ <img
+ src={`${BASE_PATH}/img/icons/frameworks/${selectedVercelProject.framework}.svg`}
+ width={21}
+ height={21}
+ alt={`icon`}
+ />
+ )
+ ) : (
+ <></>
+ )
+ }
iconRight={
<span className="grow flex justify-end">
<IconChevronDown className={''} />
</span>
}
>
- <span className="flex gap-2">
- {/* {supabaseProjectRef ?? UNDEFINED_SELECT_VALUE} */}
- {/* {selectedOrg?.installationInstalled && (
- <Badge color="scale">Integration Installed</Badge>
- )} */}
- </span>
+ {(selectedVercelProject && selectedVercelProject.name) ??
+ 'Choose a Vercel Project'}
</Button>
</PopoverTrigger_Shadcn_>
<PopoverContent_Shadcn_
className="p-0 w-full"
side="bottom"
align="center"
- style={{ width: supabaseProjectsComboBoxRef.current?.offsetWidth }}
+ style={{ width: vercelProjectsComboBoxRef.current?.offsetWidth }}
>
<Command_Shadcn_>
<CommandInput_Shadcn_ placeholder="Search organization..." />
- <CommandList_Shadcn_>
+ <CommandList_Shadcn_ className="!max-h-[170px]">
<CommandEmpty_Shadcn_>No results found.</CommandEmpty_Shadcn_>
<CommandGroup_Shadcn_>
{filteredForeignProjects.map((project) => {
@@ -319,9 +299,10 @@ const ProjectLinker = ({
value={project.id}
key={project.id}
className="flex gap-2 items-center"
- onSelect={(ref) => {
- if (ref) setSupabaseProjectRef(ref)
- setSupabaseProjectsComboboxOpen(false)
+ onSelect={(id) => {
+ console.log('id set', id)
+ if (id) setVercelProjectId(id)
+ setVercelProjectsComboboxOpen(false)
}}
>
{!project?.framework ? (
@@ -343,43 +324,6 @@ const ProjectLinker = ({
</Command_Shadcn_>
</PopoverContent_Shadcn_>
</Popover_Shadcn_>
-
- <Listbox
- className="w-full"
- value={vercelProjectId ?? UNDEFINED_SELECT_VALUE}
- onChange={(e) => setVercelProjectId(e)}
- >
- <Listbox.Option value={UNDEFINED_SELECT_VALUE} label="Choose a project" disabled>
- Choose Vercel project
- </Listbox.Option>
- {filteredForeignProjects.map((project) => {
- return (
- <Listbox.Option
- key={project.id}
- value={project.id}
- label={project.name}
- addOnBefore={() => {
- return (
- <>
- {!project?.framework ? (
- vercelIcon
- ) : (
- <img
- src={`${BASE_PATH}/img/icons/frameworks/${project.framework}.svg`}
- width={21}
- height={21}
- alt={`icon`}
- />
- )}
- </>
- )
- }}
- >
- {project.name}
- </Listbox.Option>
- )
- })}
- </Listbox>
</Panel>
</div>
</div>
@@ -400,7 +344,15 @@ const ProjectLinker = ({
className="self-end"
onClick={onCreateConnections}
loading={isLoading}
- disabled={isLoading}
+ disabled={
+ // data loading states
+ loadingForeignProjects ||
+ loadingSupabaseProjects ||
+ isLoading ||
+ // check wether both project types are not undefined
+ !selectedSupabaseProject ||
+ !selectedVercelProject
+ }
>
Connect project
</Button>
diff --git a/studio/components/layouts/IntegrationWindowLayout.tsx b/studio/components/layouts/IntegrationWindowLayout.tsx
index 123e42f205c..48391679396 100644
--- a/studio/components/layouts/IntegrationWindowLayout.tsx
+++ b/studio/components/layouts/IntegrationWindowLayout.tsx
@@ -36,7 +36,7 @@ const Header: FC<any> = ({ organization, project }) => {
return (
<div className="bg">
- <ScaffoldContainer className={cn('py-3 border-b', INTEGRATION_LAYOUT_MAX_WIDTH)}>
+ <ScaffoldContainer className={cn('py-3', INTEGRATION_LAYOUT_MAX_WIDTH)}>
<div className="flex items-center gap-6 w-full">
<div className="flex gap-2 items-center">
<div className="bg-white shadow border rounded p-1 w-8 h-8 flex justify-center items-center">
diff --git a/studio/components/layouts/Scaffold.tsx b/studio/components/layouts/Scaffold.tsx
index aec55712385..bcf1cfd9bd3 100644
--- a/studio/components/layouts/Scaffold.tsx
+++ b/studio/components/layouts/Scaffold.tsx
@@ -53,7 +53,7 @@ const ScaffoldColumn = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTM
<div
ref={ref}
{...props}
- className={cn('flex flex-col gap-3 py-6', maxWidthClassesColumn, className)}
+ className={cn('flex flex-col gap-3', maxWidthClassesColumn, className)}
/>
)
}
diff --git a/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx b/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
index bbb7dbd0b86..fa67ca265bb 100644
--- a/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
+++ b/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
@@ -4,7 +4,7 @@ import { useParams } from 'common'
import ProjectLinker from 'components/interfaces/Integrations/ProjectLinker'
import { Markdown } from 'components/interfaces/Markdown'
import IntegrationWindowLayout from 'components/layouts/IntegrationWindowLayout'
-import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
+import { ScaffoldColumn, ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
@@ -35,9 +35,11 @@ const VercelIntegration: NextPageWithLayout = () => {
const integration = integrationData?.find((x) => x.metadata?.configuration_id === configurationId)
- const { data: supabaseProjectsData } = useProjectsQuery({
- enabled: integration?.id !== undefined,
- })
+ const { data: supabaseProjectsData, isLoading: isLoadingSupabaseProjectsData } = useProjectsQuery(
+ {
+ enabled: integration?.id !== undefined,
+ }
+ )
const supabaseProjects = useMemo(
() =>
@@ -48,45 +50,50 @@ const VercelIntegration: NextPageWithLayout = () => {
[organizationSlug, supabaseProjectsData]
)
- const { data: vercelProjectsData } = useVercelProjectsQuery(
- {
- organization_integration_id: integration?.id,
- },
- { enabled: integration?.id !== undefined }
- )
+ const { data: vercelProjectsData, isLoading: isLoadingVercelProjectsData } =
+ useVercelProjectsQuery(
+ {
+ organization_integration_id: integration?.id,
+ },
+ { enabled: integration?.id !== undefined }
+ )
const vercelProjects = useMemo(() => vercelProjectsData ?? EMPTY_ARR, [vercelProjectsData])
return (
<>
+ <LoadingLine loading={loading} />
<main className="overflow-auto flex flex-col h-full">
- <LoadingLine loading={loading} />
<>
<ScaffoldContainer className="flex flex-col gap-6 grow py-8">
- <header>
- <h1 className="text-xl text-scale-1200">
- Link a Supabase project to a Vercel project
- </h1>
- <Markdown
- className="text-scale-900"
- content={`
+ <ScaffoldColumn className="!max-w-[900px] mx-auto w-full">
+ <header>
+ <h1 className="text-xl text-scale-1200">
+ Link a Supabase project to a Vercel project
+ </h1>
+ <Markdown
+ className="text-scale-900"
+ content={`
This Supabase integration manages your environment variables automatically to provide the latest keys in the unlikely event that you will need to refresh your JWT token.
`}
+ />
+ </header>
+ <ProjectLinker
+ organizationIntegrationId={integration?.id}
+ foreignProjects={vercelProjects}
+ supabaseProjects={supabaseProjects}
+ onCreateConnections={() => {
+ if (next) {
+ window.location.href = next
+ }
+ }}
+ installedConnections={integration?.connections}
+ setLoading={setLoading}
+ showSkip={true}
+ loadingForeignProjects={isLoadingVercelProjectsData}
+ loadingSupabaseProjects={isLoadingSupabaseProjectsData}
/>
- </header>
- <ProjectLinker
- organizationIntegrationId={integration?.id}
- foreignProjects={vercelProjects}
- supabaseProjects={supabaseProjects}
- onCreateConnections={() => {
- if (next) {
- window.location.href = next
- }
- }}
- installedConnections={integration?.connections}
- setLoading={setLoading}
- showSkip={true}
- />
+ </ScaffoldColumn>
</ScaffoldContainer>
</>
diff --git a/studio/pages/integrations/vercel/install.tsx b/studio/pages/integrations/vercel/install.tsx
index 0dd64d5af11..28b4b5017c8 100644
--- a/studio/pages/integrations/vercel/install.tsx
+++ b/studio/pages/integrations/vercel/install.tsx
@@ -1,7 +1,7 @@
import { useParams } from 'common'
import { Markdown } from 'components/interfaces/Markdown'
import IntegrationWindowLayout from 'components/layouts/IntegrationWindowLayout'
-import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
+import { ScaffoldColumn, ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
import { useIntegrationsQuery } from 'data/integrations/integrations-query'
import { IntegrationName } from 'data/integrations/integrations.types'
import { useVercelIntegrationCreateMutation } from 'data/integrations/vercel-integration-create-mutation'
@@ -29,7 +29,6 @@ import {
IconHexagon,
IconInfo,
IconLifeBuoy,
- Listbox,
LoadingLine,
PopoverContent_Shadcn_,
PopoverTrigger_Shadcn_,
@@ -205,9 +204,9 @@ const VercelIntegration: NextPageWithLayout = () => {
const dataLoading = isLoadingVercelIntegrationCreateMutation || isLoadingOrganizationsQuery
const disableInstallationForm =
- isLoadingVercelIntegrationCreateMutation ||
+ (isLoadingVercelIntegrationCreateMutation && !dataLoading) ||
// disables installation button if integration is already installed and it is Marketplace flow
- (selectedOrg && selectedOrg?.installationInstalled && source === 'marketplace')
+ (selectedOrg && selectedOrg?.installationInstalled && source === 'marketplace' && !dataLoading)
? true
: false
@@ -219,50 +218,52 @@ const VercelIntegration: NextPageWithLayout = () => {
<LoadingLine loading={isLoadingVercelIntegrationCreateMutation} />
{organizationIntegrationId === null && (
<>
- <ScaffoldContainer className="max-w-md flex flex-col gap-6 grow py-8">
- <h1 className="text-xl text-scale-1200">Choose organization</h1>
- <>
- <Markdown content={`Choose the Supabase organization you wish to install in`} />
- <OrganizationPicker
- integrationName="Vercel"
- organizationsWithInstalledData={organizationsWithInstalledData}
- onSelectedOrgChange={(e: string) => {
- console.log('e:', e)
-
- const org = organizationsWithInstalledData?.find((org) => org.slug === e)
- console.log('const:', org)
-
- if (org) {
- setSelectedOrg(org)
- router.query.organizationSlug = org.slug
- }
- }}
- selectedOrg={selectedOrg}
- dataLoading={dataLoading}
- />
- {disableInstallationForm && (
- <Alert_Shadcn_ variant="warning">
- <IconAlertTriangle className="h-4 w-4" strokeWidth={2} />
- <AlertTitle_Shadcn_>
- Vercel Integration is already installed.
- </AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- You will need to choose another organization to install the integration.
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- )}
- <div className="flex flex-row w-full justify-end">
- <Button
- size="medium"
- className="self-end"
- disabled={disableInstallationForm}
- loading={isLoadingVercelIntegrationCreateMutation}
- onClick={onInstall}
- >
- Install integration
- </Button>
- </div>
- </>
+ <ScaffoldContainer className="flex flex-col gap-6 grow py-8">
+ <ScaffoldColumn className="mx-auto w-full max-w-md">
+ <h1 className="text-xl text-scale-1200">Choose organization</h1>
+ <>
+ <Markdown content={`Choose the Supabase organization you wish to install in`} />
+ <OrganizationPicker
+ integrationName="Vercel"
+ organizationsWithInstalledData={organizationsWithInstalledData}
+ onSelectedOrgChange={(e: string) => {
+ console.log('e:', e)
+
+ const org = organizationsWithInstalledData?.find((org) => org.slug === e)
+ console.log('const:', org)
+
+ if (org) {
+ setSelectedOrg(org)
+ router.query.organizationSlug = org.slug
+ }
+ }}
+ selectedOrg={selectedOrg}
+ dataLoading={dataLoading}
+ />
+ {disableInstallationForm && (
+ <Alert_Shadcn_ variant="warning">
+ <IconAlertTriangle className="h-4 w-4" strokeWidth={2} />
+ <AlertTitle_Shadcn_>
+ Vercel Integration is already installed.
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ You will need to choose another organization to install the integration.
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+ <div className="flex flex-row w-full justify-end">
+ <Button
+ size="medium"
+ className="self-end"
+ disabled={disableInstallationForm}
+ loading={isLoadingVercelIntegrationCreateMutation}
+ onClick={onInstall}
+ >
+ Install integration
+ </Button>
+ </div>
+ </>
+ </ScaffoldColumn>
</ScaffoldContainer>
<ScaffoldContainer className="flex flex-col gap-6 py-3">
<Alert_Shadcn_ variant="default">
@@ -280,7 +281,7 @@ const VercelIntegration: NextPageWithLayout = () => {
<ScaffoldDivider />
</main>
- <ScaffoldContainer className="bg-body flex flex-row gap-6 py-6 border-t">
+ <ScaffoldContainer className="bg-body flex flex-row gap-6 py-6">
<div className="flex items-center gap-2 text-xs text-scale-900">
<IconBook size={16} /> Docs
</div>
@@ -313,16 +314,6 @@ const OrganizationPicker = ({
const [open, setOpen] = useState(false)
const ref = useRef<HTMLButtonElement>(null)
- if (dataLoading) {
- return (
- <Listbox label={label} value="loading" disabled>
- <Listbox.Option key="loading" value="loading" label="Loading...">
- Loading...
- </Listbox.Option>
- </Listbox>
- )
- }
-
return (
<>
<Popover_Shadcn_ open={open} onOpenChange={setOpen}>
@@ -334,6 +325,8 @@ const OrganizationPicker = ({
block
className="justify-start"
icon={<IconHexagon />}
+ loading={dataLoading}
+ disabled={dataLoading}
iconRight={
<span className="grow flex justify-end">
<IconChevronDown className={''} />
@@ -341,7 +334,7 @@ const OrganizationPicker = ({
}
>
<span className="flex gap-2">
- {selectedOrg?.name}
+ <span className="truncate">{selectedOrg?.name}</span>
{selectedOrg?.installationInstalled && (
<Badge color="scale">Integration Installed</Badge>
)}
@@ -371,9 +364,11 @@ const OrganizationPicker = ({
}}
>
<IconHexagon />
- <span>{org.name}</span>{' '}
+ <span className="truncate">{org.name}</span>{' '}
{org?.installationInstalled && (
- <Badge color="scale">Integration Installed</Badge>
+ <Badge color="scale" className="!flex-none">
+ Integration Installed
+ </Badge>
)}
</CommandItem_Shadcn_>
)