Skip to content

Commit 384b6c4

Browse files
alaisterjoshenlim
andauthored
Braching fixes 06/03 (supabase#21800)
* branching fixes 06/03 * fix width in project linker * add space * Fix --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
1 parent cea8e45 commit 384b6c4

File tree

4 files changed

+93
-56
lines changed

4 files changed

+93
-56
lines changed

apps/studio/components/interfaces/Integrations/IntegrationPanels.tsx

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -165,46 +165,56 @@ const IntegrationConnection = React.forwardRef<HTMLLIElement, IntegrationConnect
165165
<div
166166
className={cn(
167167
orientation === 'horizontal'
168-
? 'flex items-center justify-between'
168+
? 'flex items-center justify-between gap-2'
169169
: 'flex flex-col gap-3',
170170
'bg-surface-100 border shadow-sm px-6 py-4 rounded-lg',
171171
className
172172
)}
173173
>
174-
<div className={'flex flex-col gap-1'}>
175-
<div className="flex gap-2 items-center">
176-
<HandleIcon type={'Supabase'} />
177-
<span title={project?.name} className="text-sm truncate">
178-
{project?.name}
179-
</span>
180-
<IconArrowRight size={14} className="text-foreground-lighter" strokeWidth={1.5} />
181-
{!connection?.metadata?.framework ? (
182-
<div className="bg-black text-white w-4 h-4 rounded flex items-center justify-center">
183-
<HandleIcon type={type} className={'!w-2.5'} />
184-
</div>
185-
) : (
186-
<img
187-
src={`${BASE_PATH}/img/icons/frameworks/${connection.metadata.framework}.svg`}
188-
width={21}
189-
height={21}
190-
alt={`icon`}
191-
/>
192-
)}
193-
{type === 'GitHub' ? (
194-
<a
195-
title={connection.metadata.name}
196-
href={`https://github.com/${connection.metadata?.name}`}
197-
className="text-sm truncate"
198-
target="_blank"
199-
rel="noreferrer"
200-
>
201-
{connection.metadata?.name}
202-
</a>
203-
) : (
204-
<span title={connection.metadata.name} className="text-sm truncate">
205-
{connection.metadata?.name}
174+
<div className="flex flex-col gap-1 min-w-0">
175+
<div className="flex items-center gap-2">
176+
<div className="flex-shrink-0 flex gap-x-2 items-center max-w-40 ">
177+
<HandleIcon type={'Supabase'} />
178+
<span title={project?.name} className="text-sm truncate">
179+
{project?.name}
206180
</span>
207-
)}
181+
</div>
182+
183+
<IconArrowRight
184+
size={14}
185+
className="flex-shrink-0 text-foreground-lighter"
186+
strokeWidth={1.5}
187+
/>
188+
189+
<div className="flex-1 min-w-0 flex gap-2 items-center">
190+
{!connection?.metadata?.framework ? (
191+
<div className="bg-black text-white w-4 h-4 rounded flex items-center justify-center">
192+
<HandleIcon type={type} className={'!w-2.5'} />
193+
</div>
194+
) : (
195+
<img
196+
src={`${BASE_PATH}/img/icons/frameworks/${connection.metadata.framework}.svg`}
197+
width={21}
198+
height={21}
199+
alt={`icon`}
200+
/>
201+
)}
202+
{type === 'GitHub' ? (
203+
<a
204+
title={connection.metadata.name}
205+
href={`https://github.com/${connection.metadata?.name}`}
206+
className="text-sm truncate"
207+
target="_blank"
208+
rel="noreferrer"
209+
>
210+
{connection.metadata?.name}
211+
</a>
212+
) : (
213+
<span title={connection.metadata.name} className="text-sm truncate">
214+
{connection.metadata?.name}
215+
</span>
216+
)}
217+
</div>
208218
</div>
209219

210220
<div className="flex flex-col gap-0">
@@ -217,7 +227,7 @@ const IntegrationConnection = React.forwardRef<HTMLLIElement, IntegrationConnect
217227
</div>
218228
</div>
219229

220-
<div>{actions}</div>
230+
<div className="flex-shrink-0">{actions}</div>
221231
</div>
222232
</li>
223233
)

apps/studio/components/interfaces/Integrations/ProjectLinker.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { PlusIcon } from 'lucide-react'
2+
import { useRouter } from 'next/router'
23
import { ReactNode, useEffect, useRef, useState } from 'react'
34
import { toast } from 'react-hot-toast'
5+
6+
import ShimmerLine from 'components/ui/ShimmerLine'
7+
import {
8+
IntegrationConnectionsCreateVariables,
9+
IntegrationProjectConnection,
10+
} from 'data/integrations/integrations.types'
11+
import { useSelectedOrganization } from 'hooks'
12+
import { BASE_PATH } from 'lib/constants'
13+
import { openInstallGitHubIntegrationWindow } from 'lib/github'
14+
import { EMPTY_ARR } from 'lib/void'
415
import {
516
Button,
617
CommandEmpty_Shadcn_,
@@ -16,16 +27,6 @@ import {
1627
Popover_Shadcn_,
1728
cn,
1829
} from 'ui'
19-
import { useRouter } from 'next/router'
20-
21-
import ShimmerLine from 'components/ui/ShimmerLine'
22-
import {
23-
IntegrationConnectionsCreateVariables,
24-
IntegrationProjectConnection,
25-
} from 'data/integrations/integrations.types'
26-
import { useSelectedOrganization } from 'hooks'
27-
import { BASE_PATH } from 'lib/constants'
28-
import { openInstallGitHubIntegrationWindow } from 'lib/github'
2930

3031
export interface Project {
3132
id: string
@@ -63,7 +64,7 @@ const ProjectLinker = ({
6364
foreignProjects,
6465
supabaseProjects,
6566
onCreateConnections: _onCreateConnections,
66-
installedConnections = [],
67+
installedConnections = EMPTY_ARR,
6768
isLoading,
6869
integrationIcon,
6970
getForeignProjectIcon,
@@ -147,7 +148,7 @@ const ProjectLinker = ({
147148
return (
148149
<div
149150
className={cn(
150-
'flex flex-col grow gap-6 px-5 mx-auto w-full justify-center items-center',
151+
'flex-1 min-w-0 flex flex-col grow gap-6 px-5 mx-auto w-full justify-center items-center',
151152
className
152153
)}
153154
{...props}
@@ -282,7 +283,7 @@ const ProjectLinker = ({
282283
</Popover_Shadcn_>
283284
</Panel>
284285

285-
<div className="border border-foreground-lighter h-px w-16 border-dashed self-end mb-4" />
286+
<div className="border border-foreground-lighter h-px w-8 border-dashed self-end mb-4" />
286287

287288
<Panel>
288289
<div className="bg-black shadow rounded p-1 w-12 h-12 flex justify-center items-center">
@@ -302,9 +303,11 @@ const ProjectLinker = ({
302303
loading={loadingForeignProjects}
303304
className="justify-start"
304305
icon={
305-
selectedForeignProject
306-
? getForeignProjectIcon?.(selectedForeignProject)
307-
: integrationIcon
306+
<div>
307+
{selectedForeignProject
308+
? getForeignProjectIcon?.(selectedForeignProject) ?? integrationIcon
309+
: integrationIcon}
310+
</div>
308311
}
309312
iconRight={
310313
<span className="grow flex justify-end">

apps/studio/components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { useMemo } from 'react'
22
import toast from 'react-hot-toast'
3-
import { Button, SidePanel } from 'ui'
43

54
import ProjectLinker from 'components/interfaces/Integrations/ProjectLinker'
65
import { Markdown } from 'components/interfaces/Markdown'
76
import { useGitHubAuthorizationQuery } from 'data/integrations/github-authorization-query'
87
import { useGitHubConnectionCreateMutation } from 'data/integrations/github-connection-create-mutation'
8+
import { useGitHubConnectionsQuery } from 'data/integrations/github-connections-query'
99
import { useGitHubRepositoriesQuery } from 'data/integrations/github-repositories-query'
1010
import type { IntegrationConnectionsCreateVariables } from 'data/integrations/integrations.types'
1111
import { useProjectsQuery } from 'data/projects/projects-query'
1212
import { useSelectedOrganization } from 'hooks'
1313
import { openInstallGitHubIntegrationWindow } from 'lib/github'
1414
import { EMPTY_ARR } from 'lib/void'
1515
import { useSidePanelsStateSnapshot } from 'state/side-panels'
16+
import { Button, SidePanel } from 'ui'
17+
import { useGitHubConnectionDeleteMutation } from 'data/integrations/github-connection-delete-mutation'
1618

1719
const GITHUB_ICON = (
1820
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 96" className="w-6">
@@ -64,14 +66,20 @@ const SidePanelGitHubRepoLinker = ({ projectRef }: SidePanelGitHubRepoLinkerProp
6466
[githubReposData]
6567
)
6668

67-
const { mutate: createConnections, isLoading: isCreatingConnection } =
69+
const { data: connections } = useGitHubConnectionsQuery({
70+
organizationId: selectedOrganization?.id,
71+
})
72+
73+
const { mutate: createConnection, isLoading: isCreatingConnection } =
6874
useGitHubConnectionCreateMutation({
6975
onSuccess() {
7076
toast.success('Successfully linked project to repository!')
7177
sidePanelStateSnapshot.setGithubConnectionsOpen(false)
7278
},
7379
})
7480

81+
const { mutateAsync: deleteConnection } = useGitHubConnectionDeleteMutation()
82+
7583
const createGithubConnection = async (variables: IntegrationConnectionsCreateVariables) => {
7684
if (!selectedOrganization?.id) {
7785
throw new Error('No organization id')
@@ -80,7 +88,23 @@ const SidePanelGitHubRepoLinker = ({ projectRef }: SidePanelGitHubRepoLinkerProp
8088
throw new Error('No new connection')
8189
}
8290

83-
createConnections({
91+
const existingConnection = connections?.find(
92+
(connection) => connection.project.ref === projectRef
93+
)
94+
95+
if (existingConnection) {
96+
// remove existing connection so we can recreate it or update it
97+
try {
98+
await deleteConnection({
99+
organizationId: selectedOrganization.id,
100+
connectionId: existingConnection.id,
101+
})
102+
} catch (error) {
103+
// ignore the error to let createConnection handle it
104+
}
105+
}
106+
107+
createConnection({
84108
organizationId: selectedOrganization.id,
85109
connection: variables.new,
86110
})
@@ -95,7 +119,7 @@ const SidePanelGitHubRepoLinker = ({ projectRef }: SidePanelGitHubRepoLinkerProp
95119
onCancel={() => sidePanelStateSnapshot.setGithubConnectionsOpen(false)}
96120
>
97121
<div className="py-10 flex flex-col gap-6 bg-studio h-full">
98-
<SidePanel.Content>
122+
<SidePanel.Content className="flex flex-col gap-4">
99123
<Markdown
100124
content={`
101125
### Choose repository to connect to

apps/studio/lib/github.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const GITHUB_INTEGRATION_INSTALLATION_URL =
33
? `https://github.com/apps/supabase/installations/new`
44
: process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
55
? `https://github.com/apps/supabase-staging/installations/new`
6-
: `https://github.com/apps/supabase-github-v2-migration-test/installations/new`
6+
: `https://github.com/apps/supabase-local-testing/installations/new`
77

88
const GITHUB_INTEGRATION_CLIENT_ID =
99
process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod'

0 commit comments

Comments
 (0)