Skip to content

Commit b40fa3a

Browse files
fix(picker-ui): picker UI confusing when credential not set + Microsoft OAuth Fixes (#1016)
* fix(picker-ui): picker UI confusing when credential not set * remove comments * remove chevron down * fix collaboration oauth * fix jira" * fix * fix ms excel selector * fix selectors for MS blocks * fix ms selectors * fix * fix ms onedrive and sharepoint * fix to grey out dropdowns * fix background fetches * fix planner * fix confluence * fix * fix confluence realtime sharing * fix outlook folder selector * check outlook folder * make shared hook --------- Co-authored-by: waleedlatif1 <[email protected]>
1 parent f924edd commit b40fa3a

File tree

14 files changed

+1308
-1079
lines changed

14 files changed

+1308
-1079
lines changed

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,37 @@ export function ChannelSelectorInput({
3333

3434
// Use the proper hook to get the current value and setter (same as file-selector)
3535
const [storeValue, setStoreValue] = useSubBlockValue(blockId, subBlock.id)
36+
// Reactive upstream fields
37+
const [authMethod] = useSubBlockValue(blockId, 'authMethod')
38+
const [botToken] = useSubBlockValue(blockId, 'botToken')
39+
const [connectedCredential] = useSubBlockValue(blockId, 'credential')
3640
const [selectedChannelId, setSelectedChannelId] = useState<string>('')
3741
const [_channelInfo, setChannelInfo] = useState<SlackChannelInfo | null>(null)
3842

3943
// Get provider-specific values
4044
const provider = subBlock.provider || 'slack'
4145
const isSlack = provider === 'slack'
4246

43-
// Get the credential for the provider - use provided credential or fall back to store
44-
const authMethod = getValue(blockId, 'authMethod') as string
45-
const botToken = getValue(blockId, 'botToken') as string
46-
47+
// Get the credential for the provider - use provided credential or fall back to reactive values
4748
let credential: string
4849
if (providedCredential) {
4950
credential = providedCredential
50-
} else if (authMethod === 'bot_token' && botToken) {
51-
credential = botToken
51+
} else if ((authMethod as string) === 'bot_token' && (botToken as string)) {
52+
credential = botToken as string
5253
} else {
53-
credential = (getValue(blockId, 'credential') as string) || ''
54+
credential = (connectedCredential as string) || ''
5455
}
5556

5657
// Use preview value when in preview mode, otherwise use store value
5758
const value = isPreview ? previewValue : storeValue
5859

5960
// Get the current value from the store or prop value if in preview mode (same pattern as file-selector)
6061
useEffect(() => {
61-
if (isPreview && previewValue !== undefined) {
62-
const value = previewValue
63-
if (value && typeof value === 'string') {
64-
setSelectedChannelId(value)
65-
}
66-
} else {
67-
const value = getValue(blockId, subBlock.id)
68-
if (value && typeof value === 'string') {
69-
setSelectedChannelId(value)
70-
}
62+
const val = isPreview && previewValue !== undefined ? previewValue : storeValue
63+
if (val && typeof val === 'string') {
64+
setSelectedChannelId(val)
7165
}
72-
}, [blockId, subBlock.id, getValue, isPreview, previewValue])
66+
}, [isPreview, previewValue, storeValue])
7367

7468
// Handle channel selection (same pattern as file-selector)
7569
const handleChannelChange = (channelId: string, info?: SlackChannelInfo) => {

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,10 @@ export function CredentialSelector({
124124
}
125125
}, [effectiveProviderId, selectedId, activeWorkflowId])
126126

127-
// Fetch credentials on initial mount
127+
// Fetch credentials on initial mount and whenever the subblock value changes externally
128128
useEffect(() => {
129129
fetchCredentials()
130-
// This effect should only run once on mount, so empty dependency array
131-
// eslint-disable-next-line react-hooks/exhaustive-deps
132-
}, [])
130+
}, [fetchCredentials, effectiveValue])
133131

134132
// When the selectedId changes (e.g., collaborator saved a credential), determine if it's foreign
135133
useEffect(() => {
@@ -180,6 +178,19 @@ export function CredentialSelector({
180178
}
181179
}, [fetchCredentials])
182180

181+
// Also handle BFCache restores (back/forward navigation) where visibility change may not fire reliably
182+
useEffect(() => {
183+
const handlePageShow = (event: any) => {
184+
if (event?.persisted) {
185+
fetchCredentials()
186+
}
187+
}
188+
window.addEventListener('pageshow', handlePageShow)
189+
return () => {
190+
window.removeEventListener('pageshow', handlePageShow)
191+
}
192+
}, [fetchCredentials])
193+
183194
// Handle popover open to fetch fresh credentials
184195
const handleOpenChange = (isOpen: boolean) => {
185196
setOpen(isOpen)
@@ -193,6 +204,13 @@ export function CredentialSelector({
193204
const selectedCredential = credentials.find((cred) => cred.id === selectedId)
194205
const isForeign = !!(selectedId && !selectedCredential && hasForeignMeta)
195206

207+
// If the list doesn’t contain the effective value but meta says it exists, synthesize a non-leaky placeholder to render stable UI
208+
const displayName = selectedCredential
209+
? selectedCredential.name
210+
: isForeign
211+
? 'Saved by collaborator'
212+
: undefined
213+
196214
// Handle selection
197215
const handleSelect = (credentialId: string) => {
198216
const previousId = selectedId || (effectiveValue as string) || ''
@@ -263,15 +281,9 @@ export function CredentialSelector({
263281
<div className='flex max-w-[calc(100%-20px)] items-center gap-2 overflow-hidden'>
264282
{getProviderIcon(provider)}
265283
<span
266-
className={
267-
selectedCredential ? 'truncate font-normal' : 'truncate text-muted-foreground'
268-
}
284+
className={displayName ? 'truncate font-normal' : 'truncate text-muted-foreground'}
269285
>
270-
{selectedCredential
271-
? selectedCredential.name
272-
: isForeign
273-
? 'Saved by collaborator'
274-
: label}
286+
{displayName || label}
275287
</span>
276288
</div>
277289
<ChevronDown className='absolute right-3 h-4 w-4 shrink-0 opacity-50' />

0 commit comments

Comments
 (0)