Skip to content

Commit 1db3e33

Browse files
committed
return data to render credential set in block preview
1 parent d908a28 commit 1db3e33

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

apps/sim/hooks/queries/oauth-credentials.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useQuery } from '@tanstack/react-query'
22
import type { Credential } from '@/lib/oauth'
3+
import { CREDENTIAL_SET } from '@/executor/constants'
4+
import { useCredentialSetMemberships } from '@/hooks/queries/credential-sets'
35
import { fetchJson } from '@/hooks/selectors/helpers'
46

57
interface CredentialListResponse {
@@ -61,14 +63,25 @@ export function useOAuthCredentialDetail(
6163
}
6264

6365
export function useCredentialName(credentialId?: string, providerId?: string, workflowId?: string) {
66+
// Check if this is a credential set value
67+
const isCredentialSet = credentialId?.startsWith(CREDENTIAL_SET.PREFIX) ?? false
68+
const credentialSetId = isCredentialSet
69+
? credentialId?.slice(CREDENTIAL_SET.PREFIX.length)
70+
: undefined
71+
72+
// Fetch credential set memberships if this is a credential set
73+
const { data: memberships = [], isFetching: membershipsLoading } = useCredentialSetMemberships()
74+
6475
const { data: credentials = [], isFetching: credentialsLoading } = useOAuthCredentials(
6576
providerId,
66-
Boolean(providerId)
77+
Boolean(providerId) && !isCredentialSet
6778
)
6879

6980
const selectedCredential = credentials.find((cred) => cred.id === credentialId)
7081

71-
const shouldFetchDetail = Boolean(credentialId && !selectedCredential && providerId && workflowId)
82+
const shouldFetchDetail = Boolean(
83+
credentialId && !selectedCredential && providerId && workflowId && !isCredentialSet
84+
)
7285

7386
const { data: foreignCredentials = [], isFetching: foreignLoading } = useOAuthCredentialDetail(
7487
shouldFetchDetail ? credentialId : undefined,
@@ -78,11 +91,19 @@ export function useCredentialName(credentialId?: string, providerId?: string, wo
7891

7992
const hasForeignMeta = foreignCredentials.length > 0
8093

81-
const displayName = selectedCredential?.name ?? (hasForeignMeta ? 'Saved by collaborator' : null)
94+
// For credential sets, find the matching membership and use its name
95+
const credentialSetName = credentialSetId
96+
? memberships.find((m) => m.credentialSetId === credentialSetId)?.credentialSetName
97+
: undefined
98+
99+
const displayName =
100+
credentialSetName ??
101+
selectedCredential?.name ??
102+
(hasForeignMeta ? 'Saved by collaborator' : null)
82103

83104
return {
84105
displayName,
85-
isLoading: credentialsLoading || foreignLoading,
106+
isLoading: credentialsLoading || foreignLoading || (isCredentialSet && membershipsLoading),
86107
hasForeignMeta,
87108
}
88109
}

0 commit comments

Comments
 (0)