- Expecting to see your projects? - -
> } /> diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.test.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.test.tsx index a5f604a2db9..2188f845e92 100644 --- a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.test.tsx +++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.test.tsx @@ -1,7 +1,7 @@ import { fireEvent, screen, waitFor } from '@testing-library/react' import { mockIntersectionObserver } from 'jsdom-testing-mocks' import { HttpResponse } from 'msw' -import { describe, expect, test, vi } from 'vitest' +import { describe, expect, test } from 'vitest' import { OAuthAppsAuthorizeScreen } from './OAuthAppsAuthorizeScreen' import { OAuthAppsAuthorizeApproveData } from '@/data/oauth-apps/oauth-apps-authorize-approve-mutation' @@ -28,7 +28,6 @@ function renderScreen({ organizationSlug, projectRef }: RenderScreenOptions = {} authId="authId" organizationSlug={organizationSlug} projectRef={projectRef} - navigate={vi.fn()} />, { profileContext: createMockProfileContext(), @@ -51,7 +50,7 @@ async function toggleProject(projectName: string) { } async function selectProject(projectName: string) { - fireEvent.click(await screen.findByRole('combobox')) + fireEvent.click(await screen.findByRole('combobox', { name: 'Projects' })) await toggleProject(projectName) } @@ -370,7 +369,6 @@ describe('OAuthAppsAuthorizeScreen', () => { }) renderScreen() - await screen.findByRole('combobox') await selectProject('northwind-storefront') fireEvent.click(await enabledAuthorizeButton(/Authorize Vercel/)) @@ -508,7 +506,7 @@ describe('OAuthAppsAuthorizeScreen', () => { expect(await screen.findByText('All projects, including future ones')).toBeInTheDocument() expect(await enabledAuthorizeButton()).toBeEnabled() - expect(screen.queryByRole('combobox')).not.toBeInTheDocument() + expect(screen.queryByRole('combobox', { name: 'Projects' })).not.toBeInTheDocument() expect( screen.queryByText('Must select at least one project to authorize.') ).not.toBeInTheDocument() @@ -670,7 +668,7 @@ describe('OAuthAppsAuthorizeScreen', () => { fireEvent.click(screen.getByRole('checkbox')) - expect(screen.queryByRole('combobox')).not.toBeInTheDocument() + expect(screen.queryByRole('combobox', { name: 'Projects' })).not.toBeInTheDocument() const authorizeButton = screen.getByRole('button', { name: /Authorize Vercel/ }) expect(authorizeButton).toBeEnabled() fireEvent.click(authorizeButton) diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.tsx index 72fcc2d70db..19692e08394 100644 --- a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.tsx +++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.tsx @@ -1,5 +1,5 @@ import { useQuery } from '@tanstack/react-query' -import { useEffect, useMemo, useRef, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import { toast } from 'sonner' import { Button } from 'ui' import { Admonition } from 'ui-patterns/Admonition' @@ -9,6 +9,7 @@ import { AuthorizeSuccessScreen } from './AuthorizeSuccessScreen' import { AuthorizingAsCard } from './AuthorizingAsCard' import { NoProjectsNotice } from './NoProjectsNotice' import { getFailedProjects, getPreselectedProjectRefs } from './OAuthAppsAuthorizeScreen.utils' +import { OrganizationSelect } from './OrganizationSelect' import { MAX_SELECTED_PROJECTS, ProjectMultiSelect } from './ProjectMultiSelect' import { ScopeGroupCard } from './ScopeGroupCard' import { ScopeGroupCardWithDiff } from './ScopeGroupCardWithDiff' @@ -38,14 +39,12 @@ export interface OAuthAppsAuthorizeScreenProps { authId?: string organizationSlug?: string projectRef?: string - navigate: (destination: string) => void } export const OAuthAppsAuthorizeScreen = ({ authId, - organizationSlug, + organizationSlug: initialOrganizationSlug, projectRef, - navigate, }: OAuthAppsAuthorizeScreenProps) => { const signOut = useSignOut() @@ -75,6 +74,8 @@ export const OAuthAppsAuthorizeScreen = ({ isError: isErrorIdentity, } = useProfile() + const [organizationSlug, setOrganizationSlug] = useState(initialOrganizationSlug) + const { data: memberOrg, error: memberOrgError, @@ -85,8 +86,17 @@ export const OAuthAppsAuthorizeScreen = ({ projectRef, request, }) + const [search, setSearch] = useState('') + const handleOrganizationChange = (slug: string) => { + if (slug === memberOrg?.slug) return + setOrganizationSlug(slug) + setSelectedProjectRefs([]) + setAllProjectsSelected(false) + setSearch('') + } + const { data: projectsData, isPending: isPendingProjects, @@ -171,17 +181,14 @@ export const OAuthAppsAuthorizeScreen = ({ } ) - const seeded = useRef(false) useEffect(() => { - if (seeded.current || !preflightData || !memberOrg) return + if (!preflightData || !memberOrg) return const grant = preflightData.existing_grant const hasAllProjectsGrant = grant !== null && (grant?.project_refs == null || grant?.project_refs?.length === 0) if (!hasAllProjectsGrant && !initialProjectsData) return - seeded.current = true - if (hasAllProjectsGrant && isProjectScopingModeEnabled) { setAllProjectsSelected(true) return @@ -380,13 +387,11 @@ export const OAuthAppsAuthorizeScreen = ({ window.location.reload() } - const handleSwitchOrg = () => navigate('/organizations') - const handleDeselectFlagged = () => setSelectedProjectRefs((refs) => refs.filter((ref) => !flaggedRefs.includes(ref))) const handleApprove = () => { - if (hasNoSelection) return + if (hasNoSelection || isBlockedOnProjects) return const approveBody = usesSelectedProjects ? { project_refs: selectedProjectRefs } : {} approveMutation.mutate({ auth_id: authId, slug: memberOrg.slug, body: approveBody }) } @@ -462,19 +467,16 @@ export const OAuthAppsAuthorizeScreen = ({