Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(notifications): credentials connection notifs showing up in right resource#3599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -20,6 +20,7 @@ import { | ||
| Tooltip, | ||
| } from '@/components/emcn' | ||
| import { useSession } from '@/lib/auth/auth-client' | ||
| import { consumeOAuthReturnContext, writeOAuthReturnContext } from '@/lib/credentials/client-state' | ||
| import { | ||
| getCanonicalScopesForProvider, | ||
| getProviderIdFromServiceId, | ||
| @@ -288,8 +289,25 @@ export function AddConnectorModal({ open, onOpenChange, knowledgeBaseId }: AddCo | ||
| return | ||
| } | ||
| writeOAuthReturnContext({ | ||
| origin: 'kb-connectors', | ||
| knowledgeBaseId, | ||
| displayName, | ||
| providerId: connectorProviderId, | ||
| preCount: credentials.length, | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| workspaceId, | ||
| requestedAt: Date.now(), | ||
| }) | ||
| setShowOAuthModal(true) | ||
| }, [connectorConfig, connectorProviderId, workspaceId, session?.user?.name]) | ||
| }, [ | ||
| connectorConfig, | ||
| connectorProviderId, | ||
| workspaceId, | ||
| session?.user?.name, | ||
| knowledgeBaseId, | ||
| credentials.length, | ||
| ]) | ||
| const filteredEntries = useMemo(() => { | ||
| const term = searchTerm.toLowerCase().trim() | ||
| @@ -575,11 +593,14 @@ export function AddConnectorModal({ open, onOpenChange, knowledgeBaseId }: AddCo | ||
| {connectorConfig && connectorConfig.auth.mode === 'oauth' && connectorProviderId && ( | ||
| <OAuthRequiredModal | ||
| isOpen={showOAuthModal} | ||
| onClose={() => setShowOAuthModal(false)} | ||
| onClose={() => { | ||
| consumeOAuthReturnContext() | ||
| setShowOAuthModal(false) | ||
| }} | ||
| provider={connectorProviderId} | ||
| toolName={connectorConfig.name} | ||
| requiredScopes={getCanonicalScopesForProvider(connectorProviderId)} | ||
| newScopes={connectorConfig.auth.requiredScopes || []} | ||
| newScopes={[]} | ||
| serviceId={connectorConfig.auth.provider} | ||
| /> | ||
| )} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -27,6 +27,7 @@ import { | ||
| Tooltip, | ||
| } from '@/components/emcn' | ||
| import { cn } from '@/lib/core/utils/cn' | ||
| import { consumeOAuthReturnContext, writeOAuthReturnContext } from '@/lib/credentials/client-state' | ||
| import { | ||
| getCanonicalScopesForProvider, | ||
| getProviderIdFromServiceId, | ||
| @@ -444,7 +445,18 @@ function ConnectorCard({ | ||
| {canEdit && ( | ||
| <Button | ||
| variant='active' | ||
| onClick={() => setShowOAuthModal(true)} | ||
| onClick={() => { | ||
| writeOAuthReturnContext({ | ||
| origin: 'kb-connectors', | ||
| knowledgeBaseId, | ||
| displayName: connectorDef?.name ?? connector.connectorType, | ||
| providerId: providerId!, | ||
| preCount: credentials?.length ?? 0, | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| workspaceId, | ||
| requestedAt: Date.now(), | ||
| }) | ||
| setShowOAuthModal(true) | ||
| }} | ||
| className='w-full px-[8px] py-[4px] font-medium text-[12px]' | ||
| > | ||
| Update access | ||
| @@ -463,7 +475,10 @@ function ConnectorCard({ | ||
| {showOAuthModal && serviceId && providerId && ( | ||
| <OAuthRequiredModal | ||
| isOpen={showOAuthModal} | ||
| onClose={() => setShowOAuthModal(false)} | ||
| onClose={() => { | ||
| consumeOAuthReturnContext() | ||
| setShowOAuthModal(false) | ||
| }} | ||
| provider={providerId as OAuthProvider} | ||
| toolName={connectorDef?.name ?? connector.connectorType} | ||
| requiredScopes={getCanonicalScopesForProvider(providerId)} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| 'use client' | ||
| import { createElement, useCallback, useEffect, useMemo, useState } from 'react' | ||
| import { createElement, useCallback, useEffect, useMemo, useRef, useState } from 'react' | ||
| import { createLogger } from '@sim/logger' | ||
| import { AlertTriangle, Check, Clipboard, Plus, Search, Share2 } from 'lucide-react' | ||
| import { useParams } from 'next/navigation' | ||
| @@ -28,6 +28,7 @@ import { | ||
| PENDING_CREDENTIAL_CREATE_REQUEST_EVENT, | ||
| type PendingCredentialCreateRequest, | ||
| readPendingCredentialCreateRequest, | ||
| writeOAuthReturnContext, | ||
| } from '@/lib/credentials/client-state' | ||
| import { | ||
| getCanonicalScopesForProvider, | ||
| @@ -54,6 +55,7 @@ import { | ||
| useOAuthConnections, | ||
| } from '@/hooks/queries/oauth/oauth-connections' | ||
| import { useWorkspacePermissionsQuery } from '@/hooks/queries/workspace' | ||
| import { useOAuthReturnRouter } from '@/hooks/use-oauth-return' | ||
| const logger = createLogger('IntegrationsManager') | ||
| @@ -66,6 +68,8 @@ export function IntegrationsManager() { | ||
| const params = useParams() | ||
| const workspaceId = (params?.workspaceId as string) || '' | ||
| useOAuthReturnRouter() | ||
| const [searchTerm, setSearchTerm] = useState('') | ||
| const [selectedCredentialId, setSelectedCredentialId] = useState<string | null>(null) | ||
| const [memberRole, setMemberRole] = useState<WorkspaceCredentialRole>('admin') | ||
| @@ -84,6 +88,11 @@ export function IntegrationsManager() { | ||
| const [showDeleteConfirmDialog, setShowDeleteConfirmDialog] = useState(false) | ||
| const [deleteError, setDeleteError] = useState<string | null>(null) | ||
| const [showUnsavedChangesAlert, setShowUnsavedChangesAlert] = useState(false) | ||
| const pendingReturnOriginRef = useRef< | ||
| | { type: 'workflow'; workflowId: string } | ||
| | { type: 'kb-connectors'; knowledgeBaseId: string } | ||
| | undefined | ||
| >(undefined) | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const { data: session } = useSession() | ||
| const currentUserId = session?.user?.id || '' | ||
| @@ -278,6 +287,8 @@ export function IntegrationsManager() { | ||
| if (request.type !== 'oauth') return | ||
| pendingReturnOriginRef.current = request.returnOrigin | ||
| setShowCreateModal(true) | ||
| setShowCreateOAuthRequiredModal(false) | ||
| setCreateError(null) | ||
| @@ -350,6 +361,7 @@ export function IntegrationsManager() { | ||
| setCreateOAuthProviderId('') | ||
| setCreateError(null) | ||
| setShowCreateOAuthRequiredModal(false) | ||
| pendingReturnOriginRef.current = undefined | ||
| } | ||
| const handleSelectCredential = (credential: WorkspaceCredential) => { | ||
| @@ -397,15 +409,42 @@ export function IntegrationsManager() { | ||
| }), | ||
| }) | ||
| window.sessionStorage.setItem( | ||
| 'sim.oauth-connect-pending', | ||
| JSON.stringify({ | ||
| const oauthPreCount = credentials.filter( | ||
| (c) => c.type === 'oauth' && c.providerId === selectedOAuthService.providerId | ||
| ).length | ||
| const returnOrigin = pendingReturnOriginRef.current | ||
| pendingReturnOriginRef.current = undefined | ||
| if (returnOrigin?.type === 'workflow') { | ||
| writeOAuthReturnContext({ | ||
| origin: 'workflow', | ||
| workflowId: returnOrigin.workflowId, | ||
| displayName, | ||
| providerId: selectedOAuthService.providerId, | ||
| preCount: credentials.filter((c) => c.type === 'oauth').length, | ||
| preCount: oauthPreCount, | ||
| workspaceId, | ||
| requestedAt: Date.now(), | ||
| }) | ||
| ) | ||
| } else if (returnOrigin?.type === 'kb-connectors') { | ||
| writeOAuthReturnContext({ | ||
| origin: 'kb-connectors', | ||
| knowledgeBaseId: returnOrigin.knowledgeBaseId, | ||
| displayName, | ||
| providerId: selectedOAuthService.providerId, | ||
| preCount: oauthPreCount, | ||
| workspaceId, | ||
| requestedAt: Date.now(), | ||
| }) | ||
| } else { | ||
| writeOAuthReturnContext({ | ||
| origin: 'integrations', | ||
| displayName, | ||
| providerId: selectedOAuthService.providerId, | ||
| preCount: oauthPreCount, | ||
| workspaceId, | ||
| requestedAt: Date.now(), | ||
| }) | ||
| } | ||
| await connectOAuthService.mutateAsync({ | ||
| providerId: selectedOAuthService.providerId, | ||
| @@ -512,16 +551,18 @@ export function IntegrationsManager() { | ||
| }), | ||
| }) | ||
| window.sessionStorage.setItem( | ||
| 'sim.oauth-connect-pending', | ||
| JSON.stringify({ | ||
| displayName: selectedCredential.displayName, | ||
| providerId: selectedCredential.providerId, | ||
| preCount: credentials.filter((c) => c.type === 'oauth').length, | ||
| workspaceId, | ||
| reconnect: true, | ||
| }) | ||
| ) | ||
| const oauthPreCount = credentials.filter( | ||
| (c) => c.type === 'oauth' && c.providerId === selectedCredential.providerId | ||
| ).length | ||
| writeOAuthReturnContext({ | ||
| origin: 'integrations', | ||
| displayName: selectedCredential.displayName, | ||
| providerId: selectedCredential.providerId, | ||
| preCount: oauthPreCount, | ||
| workspaceId, | ||
| reconnect: true, | ||
| requestedAt: Date.now(), | ||
| }) | ||
| await connectOAuthService.mutateAsync({ | ||
| providerId: selectedCredential.providerId, | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.