Skip to content

Commit 947b1cd

Browse files
committed
Fix dropdown
1 parent 08ddf19 commit 947b1cd

3 files changed

Lines changed: 70 additions & 30 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/file-selector/file-selector-input.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export function FileSelectorInput({
4242
const params = useParams()
4343
const workflowIdFromUrl = (params?.workflowId as string) || activeWorkflowId || ''
4444
// Central dependsOn gating for this selector instance
45-
const { finalDisabled } = useDependsOnGate(blockId, subBlock, {
46-
disabled,
47-
isPreview,
48-
previewContextValues
45+
const { finalDisabled, dependsOn } = useDependsOnGate(blockId, subBlock, {
46+
disabled,
47+
isPreview,
48+
previewContextValues,
4949
})
5050

5151
// Helper to coerce various preview value shapes into a string ID
@@ -73,7 +73,7 @@ export function FileSelectorInput({
7373
const [planIdValueFromStore] = useSubBlockValue(blockId, 'planId')
7474
const [teamIdValueFromStore] = useSubBlockValue(blockId, 'teamId')
7575
const [operationValueFromStore] = useSubBlockValue(blockId, 'operation')
76-
76+
7777
// Use previewContextValues if provided (for tools inside agent blocks), otherwise use store values
7878
const connectedCredential = previewContextValues?.credential ?? connectedCredentialFromStore
7979
const domainValue = previewContextValues?.domain ?? domainValueFromStore
@@ -88,7 +88,7 @@ export function FileSelectorInput({
8888
? getProviderIdFromServiceId(subBlock.serviceId)
8989
: (subBlock.provider as string) || ''
9090
const { isForeignCredential } = useForeignCredential(
91-
foreignCheckProvider,
91+
subBlock.provider || subBlock.serviceId || 'outlook',
9292
(connectedCredential as string) || ''
9393
)
9494

@@ -121,6 +121,20 @@ export function FileSelectorInput({
121121
// Use preview value when in preview mode, otherwise use store value
122122
const value = isPreview ? previewValue : storeValue
123123

124+
const credentialDependencySatisfied = (() => {
125+
if (!dependsOn.includes('credential')) return true
126+
const normalizedCredential = coerceToIdString(connectedCredential)
127+
if (!normalizedCredential || normalizedCredential.trim().length === 0) {
128+
return false
129+
}
130+
if (isForeignCredential) {
131+
return false
132+
}
133+
return true
134+
})()
135+
136+
const shouldForceDisable = !credentialDependencySatisfied
137+
124138
// For Google Drive
125139
const clientId = getEnv('NEXT_PUBLIC_GOOGLE_CLIENT_ID') || ''
126140
const apiKey = getEnv('NEXT_PUBLIC_GOOGLE_API_KEY') || ''
@@ -144,7 +158,7 @@ export function FileSelectorInput({
144158
collaborativeSetSubblockValue(blockId, subBlock.id, val)
145159
}}
146160
label={subBlock.placeholder || 'Select Google Calendar'}
147-
disabled={finalDisabled}
161+
disabled={finalDisabled || shouldForceDisable}
148162
showPreview={true}
149163
credentialId={credential}
150164
workflowId={workflowIdFromUrl}
@@ -178,7 +192,7 @@ export function FileSelectorInput({
178192
requiredScopes={subBlock.requiredScopes || []}
179193
serviceId={subBlock.serviceId}
180194
label={subBlock.placeholder || 'Select Confluence page'}
181-
disabled={finalDisabled}
195+
disabled={finalDisabled || shouldForceDisable}
182196
showPreview={true}
183197
credentialId={credential}
184198
workflowId={workflowIdFromUrl}
@@ -212,7 +226,7 @@ export function FileSelectorInput({
212226
requiredScopes={subBlock.requiredScopes || []}
213227
serviceId={subBlock.serviceId}
214228
label={subBlock.placeholder || 'Select Jira issue'}
215-
disabled={finalDisabled}
229+
disabled={finalDisabled || shouldForceDisable}
216230
showPreview={true}
217231
credentialId={credential}
218232
projectId={(projectIdValue as string) || ''}
@@ -242,7 +256,7 @@ export function FileSelectorInput({
242256
requiredScopes={subBlock.requiredScopes || []}
243257
serviceId={subBlock.serviceId}
244258
label={subBlock.placeholder || 'Select Microsoft Excel file'}
245-
disabled={finalDisabled}
259+
disabled={finalDisabled || shouldForceDisable}
246260
showPreview={true}
247261
workflowId={activeWorkflowId || ''}
248262
credentialId={credential}
@@ -272,7 +286,7 @@ export function FileSelectorInput({
272286
requiredScopes={subBlock.requiredScopes || []}
273287
serviceId={subBlock.serviceId}
274288
label={subBlock.placeholder || 'Select Microsoft Word document'}
275-
disabled={finalDisabled}
289+
disabled={finalDisabled || shouldForceDisable}
276290
showPreview={true}
277291
/>
278292
</div>
@@ -300,7 +314,7 @@ export function FileSelectorInput({
300314
serviceId={subBlock.serviceId}
301315
mimeType={subBlock.mimeType}
302316
label={subBlock.placeholder || 'Select OneDrive folder'}
303-
disabled={finalDisabled}
317+
disabled={finalDisabled || shouldForceDisable}
304318
showPreview={true}
305319
workflowId={activeWorkflowId || ''}
306320
credentialId={credential}
@@ -330,7 +344,7 @@ export function FileSelectorInput({
330344
requiredScopes={subBlock.requiredScopes || []}
331345
serviceId={subBlock.serviceId}
332346
label={subBlock.placeholder || 'Select SharePoint site'}
333-
disabled={finalDisabled}
347+
disabled={finalDisabled || shouldForceDisable}
334348
showPreview={true}
335349
workflowId={activeWorkflowId || ''}
336350
credentialId={credential}
@@ -366,7 +380,7 @@ export function FileSelectorInput({
366380
requiredScopes={subBlock.requiredScopes || []}
367381
serviceId='microsoft-planner'
368382
label={subBlock.placeholder || 'Select task'}
369-
disabled={finalDisabled}
383+
disabled={finalDisabled || shouldForceDisable}
370384
showPreview={true}
371385
planId={planId}
372386
workflowId={activeWorkflowId || ''}
@@ -424,7 +438,7 @@ export function FileSelectorInput({
424438
requiredScopes={subBlock.requiredScopes || []}
425439
serviceId={subBlock.serviceId}
426440
label={subBlock.placeholder || 'Select Teams message location'}
427-
disabled={finalDisabled}
441+
disabled={finalDisabled || shouldForceDisable}
428442
showPreview={true}
429443
credential={credential}
430444
selectionType={selectionType}
@@ -467,7 +481,7 @@ export function FileSelectorInput({
467481
requiredScopes={subBlock.requiredScopes || []}
468482
serviceId={subBlock.serviceId}
469483
label={subBlock.placeholder || `Select ${itemType}`}
470-
disabled={finalDisabled}
484+
disabled={finalDisabled || shouldForceDisable}
471485
showPreview={true}
472486
credentialId={credential}
473487
itemType={itemType}
@@ -508,7 +522,7 @@ export function FileSelectorInput({
508522
provider={provider}
509523
requiredScopes={subBlock.requiredScopes || []}
510524
label={subBlock.placeholder || 'Select file'}
511-
disabled={finalDisabled}
525+
disabled={finalDisabled || shouldForceDisable}
512526
serviceId={subBlock.serviceId}
513527
mimeTypeFilter={subBlock.mimeType}
514528
showPreview={true}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/project-selector/project-selector-input.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ export function ProjectSelectorInput({
4848
const [connectedCredentialFromStore] = useSubBlockValue(blockId, 'credential')
4949
const [linearTeamIdFromStore] = useSubBlockValue(blockId, 'teamId')
5050
const [jiraDomainFromStore] = useSubBlockValue(blockId, 'domain')
51-
51+
5252
// Use previewContextValues if provided (for tools inside agent blocks), otherwise use store values
5353
const connectedCredential = previewContextValues?.credential ?? connectedCredentialFromStore
5454
const linearCredential = previewContextValues?.credential ?? connectedCredentialFromStore
5555
const linearTeamId = previewContextValues?.teamId ?? linearTeamIdFromStore
5656
const jiraDomain = previewContextValues?.domain ?? jiraDomainFromStore
57-
57+
5858
const { isForeignCredential } = useForeignCredential(
5959
subBlock.provider || subBlock.serviceId || 'jira',
6060
(connectedCredential as string) || ''
6161
)
6262
const activeWorkflowId = useWorkflowRegistry((s) => s.activeWorkflowId) as string | null
63-
const { finalDisabled } = useDependsOnGate(blockId, subBlock, {
64-
disabled,
65-
isPreview,
66-
previewContextValues
63+
const { finalDisabled } = useDependsOnGate(blockId, subBlock, {
64+
disabled,
65+
isPreview,
66+
previewContextValues,
6767
})
6868

6969
// Get provider-specific values

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/hooks/use-depends-on-gate.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,51 @@ export function useDependsOnGate(
2424
// Use only explicit dependsOn from block config. No inference.
2525
const dependsOn: string[] = (subBlock.dependsOn as string[] | undefined) || []
2626

27+
const normalizeDependencyValue = (rawValue: unknown): unknown => {
28+
if (rawValue === null || rawValue === undefined) return null
29+
30+
if (typeof rawValue === 'object') {
31+
if (Array.isArray(rawValue)) {
32+
if (rawValue.length === 0) return null
33+
return rawValue.map((item) => normalizeDependencyValue(item))
34+
}
35+
36+
const record = rawValue as Record<string, any>
37+
if ('value' in record) {
38+
return normalizeDependencyValue(record.value)
39+
}
40+
if ('id' in record) {
41+
return record.id
42+
}
43+
44+
return record
45+
}
46+
47+
return rawValue
48+
}
49+
2750
const dependencyValues = useSubBlockStore((state) => {
2851
if (dependsOn.length === 0) return [] as any[]
29-
52+
3053
// If previewContextValues are provided (e.g., tool parameters), use those first
3154
if (previewContextValues) {
32-
return dependsOn.map((depKey) => previewContextValues[depKey] ?? null)
55+
return dependsOn.map((depKey) => normalizeDependencyValue(previewContextValues[depKey]))
3356
}
34-
57+
3558
if (!activeWorkflowId) return dependsOn.map(() => null)
3659
const workflowValues = state.workflowValues[activeWorkflowId] || {}
3760
const blockValues = (workflowValues as any)[blockId] || {}
38-
return dependsOn.map((depKey) => (blockValues as any)[depKey] ?? null)
61+
return dependsOn.map((depKey) => normalizeDependencyValue((blockValues as any)[depKey]))
3962
}) as any[]
4063

4164
const depsSatisfied = useMemo(() => {
4265
if (dependsOn.length === 0) return true
43-
return dependencyValues.every((v) =>
44-
typeof v === 'string' ? v.trim().length > 0 : v !== null && v !== undefined && v !== ''
45-
)
66+
return dependencyValues.every((value) => {
67+
if (value === null || value === undefined) return false
68+
if (typeof value === 'string') return value.trim().length > 0
69+
if (Array.isArray(value)) return value.length > 0
70+
return value !== ''
71+
})
4672
}, [dependencyValues, dependsOn])
4773

4874
// Block everything except the credential field itself until dependencies are set

0 commit comments

Comments
 (0)