Skip to content

Commit fe1d17f

Browse files
Adam GoughAdam Gough
authored andcommitted
fixed move folder tool, infinite oauth fetching
1 parent 275daf0 commit fe1d17f

File tree

3 files changed

+64
-29
lines changed

3 files changed

+64
-29
lines changed

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useEffect, useState } from 'react'
3+
import { useCallback, useEffect, useState } from 'react'
44
import {
55
type FolderInfo,
66
FolderSelector,
@@ -33,6 +33,11 @@ export function FolderSelectorInput({
3333
const { activeWorkflowId } = useWorkflowRegistry()
3434
const [selectedFolderId, setSelectedFolderId] = useState<string>('')
3535
const [_folderInfo, setFolderInfo] = useState<FolderInfo | null>(null)
36+
const provider = (subBlock.provider || subBlock.serviceId || 'google-email').toLowerCase()
37+
const isCopyDestinationSelector =
38+
subBlock.canonicalParamId === 'copyDestinationId' ||
39+
subBlock.id === 'copyDestinationFolder' ||
40+
subBlock.id === 'manualCopyDestinationFolder'
3641
const { isForeignCredential } = useForeignCredential(
3742
subBlock.provider || subBlock.serviceId || 'outlook',
3843
(connectedCredential as string) || ''
@@ -54,11 +59,15 @@ export function FolderSelectorInput({
5459
setSelectedFolderId(current)
5560
return
5661
}
57-
// Set default INBOX if empty
58-
const defaultValue = 'INBOX'
59-
setSelectedFolderId(defaultValue)
60-
if (!isPreview) {
61-
collaborativeSetSubblockValue(blockId, subBlock.id, defaultValue)
62+
const shouldDefaultInbox = provider !== 'outlook' && !isCopyDestinationSelector
63+
if (shouldDefaultInbox) {
64+
const defaultValue = 'INBOX'
65+
setSelectedFolderId(defaultValue)
66+
if (!isPreview) {
67+
collaborativeSetSubblockValue(blockId, subBlock.id, defaultValue)
68+
}
69+
} else {
70+
setSelectedFolderId('')
6271
}
6372
}, [
6473
blockId,
@@ -71,19 +80,22 @@ export function FolderSelectorInput({
7180
])
7281

7382
// Handle folder selection
74-
const handleFolderChange = (folderId: string, info?: FolderInfo) => {
75-
setSelectedFolderId(folderId)
76-
setFolderInfo(info || null)
77-
if (!isPreview) {
78-
collaborativeSetSubblockValue(blockId, subBlock.id, folderId)
79-
}
80-
}
83+
const handleFolderChange = useCallback(
84+
(folderId: string, info?: FolderInfo) => {
85+
setSelectedFolderId(folderId)
86+
setFolderInfo(info || null)
87+
if (!isPreview) {
88+
collaborativeSetSubblockValue(blockId, subBlock.id, folderId)
89+
}
90+
},
91+
[blockId, subBlock.id, collaborativeSetSubblockValue, isPreview]
92+
)
8193

8294
return (
8395
<FolderSelector
8496
value={selectedFolderId}
8597
onChange={handleFolderChange}
86-
provider={subBlock.provider || 'google-email'}
98+
provider={provider}
8799
requiredScopes={subBlock.requiredScopes || []}
88100
label={subBlock.placeholder || 'Select folder'}
89101
disabled={finalDisabled}

apps/sim/blocks/blocks/gmail.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,15 @@ export const GmailBlock: BlockConfig<GmailToolResponse> = {
412412

413413
// Handle move operation
414414
if (rest.operation === 'move_gmail') {
415-
rest.messageId = moveMessageId
416-
rest.addLabelIds = (destinationLabel || manualDestinationLabel || '').trim()
417-
rest.removeLabelIds = (sourceLabel || manualSourceLabel || '').trim()
415+
if (moveMessageId) {
416+
rest.messageId = moveMessageId
417+
}
418+
if (!rest.addLabelIds) {
419+
rest.addLabelIds = (destinationLabel || manualDestinationLabel || '').trim()
420+
}
421+
if (!rest.removeLabelIds) {
422+
rest.removeLabelIds = (sourceLabel || manualSourceLabel || '').trim()
423+
}
418424
}
419425

420426
// Handle simple message ID operations
@@ -427,13 +433,18 @@ export const GmailBlock: BlockConfig<GmailToolResponse> = {
427433
'delete_gmail',
428434
].includes(rest.operation)
429435
) {
430-
rest.messageId = actionMessageId
436+
if (actionMessageId) {
437+
rest.messageId = actionMessageId
438+
}
431439
}
432440

433-
// Handle label management operations
434441
if (['add_label_gmail', 'remove_label_gmail'].includes(rest.operation)) {
435-
rest.messageId = labelActionMessageId
436-
rest.labelIds = (labelManagement || manualLabelManagement || '').trim()
442+
if (labelActionMessageId) {
443+
rest.messageId = labelActionMessageId
444+
}
445+
if (!rest.labelIds) {
446+
rest.labelIds = (labelManagement || manualLabelManagement || '').trim()
447+
}
437448
}
438449

439450
return {

apps/sim/blocks/blocks/outlook.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,26 +363,38 @@ export const OutlookBlock: BlockConfig<OutlookResponse> = {
363363

364364
// Handle move operation
365365
if (rest.operation === 'move_outlook') {
366-
rest.messageId = moveMessageId
367-
rest.destinationId = (destinationFolder || manualDestinationFolder || '').trim()
366+
if (moveMessageId) {
367+
rest.messageId = moveMessageId
368+
}
369+
if (!rest.destinationId) {
370+
rest.destinationId = (destinationFolder || manualDestinationFolder || '').trim()
371+
}
368372
}
369373

370-
// Handle simple message ID operations
371374
if (
372375
['mark_read_outlook', 'mark_unread_outlook', 'delete_outlook'].includes(rest.operation)
373376
) {
374-
rest.messageId = actionMessageId
377+
if (actionMessageId) {
378+
rest.messageId = actionMessageId
379+
}
375380
}
376381

377-
// Handle copy operation
378382
if (rest.operation === 'copy_outlook') {
379-
rest.messageId = copyMessageId
380-
rest.destinationId = (copyDestinationFolder || manualCopyDestinationFolder || '').trim()
383+
if (copyMessageId) {
384+
rest.messageId = copyMessageId
385+
}
386+
// Handle copyDestinationId (from UI canonical param) or destinationId (from trigger)
387+
if (rest.copyDestinationId) {
388+
rest.destinationId = rest.copyDestinationId
389+
rest.copyDestinationId = undefined
390+
} else if (!rest.destinationId) {
391+
rest.destinationId = (copyDestinationFolder || manualCopyDestinationFolder || '').trim()
392+
}
381393
}
382394

383395
return {
384396
...rest,
385-
credential, // Keep the credential parameter
397+
credential,
386398
}
387399
},
388400
},

0 commit comments

Comments
 (0)