Skip to content

Commit 3feb636

Browse files
committed
fix rendering of credential set name
1 parent 677332c commit 3feb636

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ const SubBlockRow = ({
371371
const { displayName: credentialName } = useCredentialName(
372372
credentialSourceId,
373373
credentialProviderId,
374-
workflowId,
375-
workspaceId
374+
workflowId
376375
)
377376

378377
const credentialId = dependencyValues.credential

apps/sim/hooks/queries/credential-sets.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ export function useCredentialSets(organizationId?: string, enabled = true) {
7878
})
7979
}
8080

81+
interface CredentialSetDetailResponse {
82+
credentialSet?: CredentialSet
83+
}
84+
85+
export async function fetchCredentialSetById(id: string): Promise<CredentialSet | null> {
86+
if (!id) return null
87+
const data = await fetchJson<CredentialSetDetailResponse>(`/api/credential-sets/${id}`)
88+
return data.credentialSet ?? null
89+
}
90+
91+
export function useCredentialSetDetail(id?: string, enabled = true) {
92+
return useQuery<CredentialSet | null>({
93+
queryKey: credentialSetKeys.detail(id),
94+
queryFn: () => fetchCredentialSetById(id ?? ''),
95+
enabled: Boolean(id) && enabled,
96+
staleTime: 60 * 1000,
97+
})
98+
}
99+
81100
export function useCredentialSetMemberships() {
82101
return useQuery<CredentialSetMembership[]>({
83102
queryKey: credentialSetKeys.memberships(),

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

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

77
interface CredentialListResponse {
@@ -62,25 +62,17 @@ export function useOAuthCredentialDetail(
6262
})
6363
}
6464

65-
export function useCredentialName(
66-
credentialId?: string,
67-
providerId?: string,
68-
workflowId?: string,
69-
workspaceId?: string
70-
) {
65+
export function useCredentialName(credentialId?: string, providerId?: string, workflowId?: string) {
7166
// Check if this is a credential set value
7267
const isCredentialSet = credentialId?.startsWith(CREDENTIAL_SET.PREFIX) ?? false
7368
const credentialSetId = isCredentialSet
7469
? credentialId?.slice(CREDENTIAL_SET.PREFIX.length)
7570
: undefined
7671

77-
// Fetch credential set memberships if this is a credential set
78-
const { data: memberships = [], isFetching: membershipsLoading } = useCredentialSetMemberships()
79-
80-
// Also fetch owned credential sets to check there
81-
const { data: ownedSets = [], isFetching: ownedSetsLoading } = useCredentialSets(
82-
workspaceId,
83-
isCredentialSet && Boolean(workspaceId)
72+
// Fetch credential set by ID directly
73+
const { data: credentialSetData, isFetching: credentialSetLoading } = useCredentialSetDetail(
74+
credentialSetId,
75+
isCredentialSet
8476
)
8577

8678
const { data: credentials = [], isFetching: credentialsLoading } = useOAuthCredentials(
@@ -102,23 +94,14 @@ export function useCredentialName(
10294

10395
const hasForeignMeta = foreignCredentials.length > 0
10496

105-
// For credential sets, find the matching membership or owned set and use its name
106-
const credentialSetName = credentialSetId
107-
? (memberships.find((m) => m.credentialSetId === credentialSetId)?.credentialSetName ??
108-
ownedSets.find((s) => s.id === credentialSetId)?.name)
109-
: undefined
110-
11197
const displayName =
112-
credentialSetName ??
98+
credentialSetData?.name ??
11399
selectedCredential?.name ??
114100
(hasForeignMeta ? 'Saved by collaborator' : null)
115101

116102
return {
117103
displayName,
118-
isLoading:
119-
credentialsLoading ||
120-
foreignLoading ||
121-
(isCredentialSet && (membershipsLoading || ownedSetsLoading)),
104+
isLoading: credentialsLoading || foreignLoading || (isCredentialSet && credentialSetLoading),
122105
hasForeignMeta,
123106
}
124107
}

0 commit comments

Comments
 (0)