Skip to content

Commit a77f0c5

Browse files
committed
fix rest of cases
1 parent 0bd1959 commit a77f0c5

14 files changed

Lines changed: 584 additions & 329 deletions

File tree

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

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useState } from 'react'
1+
import { useCallback, useState } from 'react'
22
import { Check, ChevronDown, Hash, Lock, RefreshCw } from 'lucide-react'
33
import { SlackIcon } from '@/components/icons'
44
import { Button } from '@/components/ui/button'
@@ -42,9 +42,19 @@ export function SlackChannelSelector({
4242
const [loading, setLoading] = useState(false)
4343
const [error, setError] = useState<string | null>(null)
4444
const [open, setOpen] = useState(false)
45-
const [selectedChannel, setSelectedChannel] = useState<SlackChannelInfo | null>(null)
4645
const [initialFetchDone, setInitialFetchDone] = useState(false)
4746

47+
// Get cached display name
48+
const cachedChannelName = useDisplayNamesStore(
49+
useCallback(
50+
(state) => {
51+
if (!credential || !value) return null
52+
return state.cache.channels[credential]?.[value] || null
53+
},
54+
[credential, value]
55+
)
56+
)
57+
4858
// Fetch channels from Slack API
4959
const fetchChannels = useCallback(async () => {
5060
if (!credential) return
@@ -110,27 +120,7 @@ export function SlackChannelSelector({
110120
}
111121
}
112122

113-
// Sync selected channel with value prop
114-
useEffect(() => {
115-
if (value && channels.length > 0) {
116-
const channelInfo = channels.find((c) => c.id === value)
117-
setSelectedChannel(channelInfo || null)
118-
} else if (!value) {
119-
setSelectedChannel(null)
120-
}
121-
}, [value, channels])
122-
123-
// If we have a value but no channel info and haven't fetched yet, get just that channel
124-
useEffect(() => {
125-
if (value && !selectedChannel && !loading && !initialFetchDone && credential) {
126-
// For now, we'll fetch all channels when needed
127-
// In the future, we could optimize to fetch just the selected channel
128-
fetchChannels()
129-
}
130-
}, [value, selectedChannel, loading, initialFetchDone, credential, fetchChannels])
131-
132123
const handleSelectChannel = (channel: SlackChannelInfo) => {
133-
setSelectedChannel(channel)
134124
onChange(channel.id, channel)
135125
setOpen(false)
136126
}
@@ -156,15 +146,10 @@ export function SlackChannelSelector({
156146
>
157147
<div className='flex max-w-[calc(100%-20px)] items-center gap-2 overflow-hidden'>
158148
<SlackIcon className='h-4 w-4 text-[#611f69]' />
159-
{selectedChannel ? (
160-
<>
161-
{getChannelIcon(selectedChannel)}
162-
<span className='truncate font-normal'>{formatChannelName(selectedChannel)}</span>
163-
</>
164-
) : value ? (
149+
{cachedChannelName ? (
165150
<>
166151
<Hash className='h-1.5 w-1.5' />
167-
<span className='truncate font-normal'>{value}</span>
152+
<span className='truncate font-normal'>{cachedChannelName}</span>
168153
</>
169154
) : (
170155
<span className='truncate text-muted-foreground'>{label}</span>

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,6 @@ export function DocumentSelector({
122122
setError(null)
123123
}, [normalizedKnowledgeBaseId])
124124

125-
useEffect(() => {
126-
if (normalizedKnowledgeBaseId && !isPreview && !isDisabled) {
127-
if (
128-
!documentsCache ||
129-
!documentsCache.documents.length ||
130-
(value && !documents.find((doc) => doc.id === value))
131-
) {
132-
void loadDocuments()
133-
}
134-
}
135-
}, [
136-
normalizedKnowledgeBaseId,
137-
isPreview,
138-
isDisabled,
139-
documentsCache,
140-
documents,
141-
value,
142-
loadDocuments,
143-
])
144-
145125
useEffect(() => {
146126
if (!normalizedKnowledgeBaseId || documents.length === 0) return
147127

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,22 @@ export function ConfluenceFileSelector({
7171
const [files, setFiles] = useState<ConfluenceFileInfo[]>([])
7272
const [selectedCredentialId, setSelectedCredentialId] = useState<string>(credentialId || '')
7373
const [selectedFileId, setSelectedFileId] = useState(value)
74-
const [selectedFile, setSelectedFile] = useState<ConfluenceFileInfo | null>(null)
7574
const [isLoading, setIsLoading] = useState(false)
7675
const [showOAuthModal, setShowOAuthModal] = useState(false)
7776
const initialFetchRef = useRef(false)
7877
const [error, setError] = useState<string | null>(null)
78+
79+
// Get cached display name
80+
const cachedFileName = useDisplayNamesStore(
81+
useCallback(
82+
(state) => {
83+
const effectiveCredentialId = credentialId || selectedCredentialId
84+
if (!effectiveCredentialId || !value) return null
85+
return state.cache.files[effectiveCredentialId]?.[value] || null
86+
},
87+
[credentialId, selectedCredentialId, value]
88+
)
89+
)
7990
// Keep internal credential in sync with prop (handles late arrival and BFCache restores)
8091
useEffect(() => {
8192
if (credentialId && credentialId !== selectedCredentialId) {
@@ -199,7 +210,6 @@ export function ConfluenceFileSelector({
199210

200211
const data = await response.json()
201212
if (data.file) {
202-
setSelectedFile(data.file)
203213
onFileInfoChange?.(data.file)
204214
} else {
205215
const fileInfo: ConfluenceFileInfo = {
@@ -211,7 +221,6 @@ export function ConfluenceFileSelector({
211221
spaceId: undefined,
212222
url: undefined,
213223
}
214-
setSelectedFile(fileInfo)
215224
onFileInfoChange?.(fileInfo)
216225
}
217226
} catch (error) {
@@ -319,12 +328,11 @@ export function ConfluenceFileSelector({
319328
useDisplayNamesStore.getState().setDisplayNames('files', selectedCredentialId, fileMap)
320329
}
321330

322-
// If we have a selected file ID, find the file info
323-
if (selectedFileId) {
331+
// If we have a selected file ID, notify parent if callback exists
332+
if (selectedFileId && onFileInfoChange) {
324333
const fileInfo = data.files.find((file: ConfluenceFileInfo) => file.id === selectedFileId)
325334
if (fileInfo) {
326-
setSelectedFile(fileInfo)
327-
onFileInfoChange?.(fileInfo)
335+
onFileInfoChange(fileInfo)
328336
} else if (!searchQuery && selectedFileId) {
329337
// If we can't find the file in the list, try to fetch it directly
330338
fetchPageInfo(selectedFileId)
@@ -389,18 +397,16 @@ export function ConfluenceFileSelector({
389397
}
390398
}, [value])
391399

392-
// Clear preview when value is cleared (e.g., collaborator cleared or domain change cascade)
400+
// Clear callback when value is cleared
393401
useEffect(() => {
394402
if (!value) {
395-
setSelectedFile(null)
396403
onFileInfoChange?.(null)
397404
}
398405
}, [value, onFileInfoChange])
399406

400407
// Handle file selection
401408
const handleSelectFile = (file: ConfluenceFileInfo) => {
402409
setSelectedFileId(file.id)
403-
setSelectedFile(file)
404410
onChange(file.id, file)
405411
onFileInfoChange?.(file)
406412
setOpen(false)
@@ -416,7 +422,6 @@ export function ConfluenceFileSelector({
416422
// Clear selection
417423
const handleClearSelection = () => {
418424
setSelectedFileId('')
419-
setSelectedFile(null)
420425
onChange('', undefined)
421426
onFileInfoChange?.(null)
422427
}
@@ -434,10 +439,10 @@ export function ConfluenceFileSelector({
434439
disabled={disabled || !domain || isForeignCredential}
435440
>
436441
<div className='flex min-w-0 items-center gap-2 overflow-hidden'>
437-
{selectedFile ? (
442+
{cachedFileName ? (
438443
<>
439444
<ConfluenceIcon className='h-4 w-4' />
440-
<span className='truncate font-normal'>{selectedFile.name}</span>
445+
<span className='truncate font-normal'>{cachedFileName}</span>
441446
</>
442447
) : (
443448
<>

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

Lines changed: 25 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@/components/ui/command'
1515
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
1616
import { createLogger } from '@/lib/logs/console/logger'
17+
import { useDisplayNamesStore } from '@/stores/display-names/store'
1718

1819
const logger = createLogger('GoogleCalendarSelector')
1920

@@ -51,11 +52,21 @@ export function GoogleCalendarSelector({
5152
const [open, setOpen] = useState(false)
5253
const [calendars, setCalendars] = useState<GoogleCalendarInfo[]>([])
5354
const [selectedCalendarId, setSelectedCalendarId] = useState(value)
54-
const [selectedCalendar, setSelectedCalendar] = useState<GoogleCalendarInfo | null>(null)
5555
const [isLoading, setIsLoading] = useState(false)
5656
const [error, setError] = useState<string | null>(null)
5757
const [initialFetchDone, setInitialFetchDone] = useState(false)
5858

59+
// Get cached display name
60+
const cachedCalendarName = useDisplayNamesStore(
61+
useCallback(
62+
(state) => {
63+
if (!credentialId || !value) return null
64+
return state.cache.files[credentialId]?.[value] || null
65+
},
66+
[credentialId, value]
67+
)
68+
)
69+
5970
const fetchCalendarsFromAPI = useCallback(async (): Promise<GoogleCalendarInfo[]> => {
6071
if (!credentialId) {
6172
throw new Error('Google Calendar account is required')
@@ -87,15 +98,13 @@ export function GoogleCalendarSelector({
8798
const calendars = await fetchCalendarsFromAPI()
8899
setCalendars(calendars)
89100

90-
const currentSelectedId = selectedCalendarId
91-
if (currentSelectedId) {
92-
const calendarInfo = calendars.find(
93-
(calendar: GoogleCalendarInfo) => calendar.id === currentSelectedId
94-
)
95-
if (calendarInfo) {
96-
setSelectedCalendar(calendarInfo)
97-
onCalendarInfoChange?.(calendarInfo)
98-
}
101+
// Cache calendar names
102+
if (credentialId && calendars.length > 0) {
103+
const calendarMap = calendars.reduce<Record<string, string>>((acc, cal) => {
104+
acc[cal.id] = cal.summary
105+
return acc
106+
}, {})
107+
useDisplayNamesStore.getState().setDisplayNames('files', credentialId, calendarMap)
99108
}
100109
} catch (error) {
101110
logger.error('Error fetching calendars:', error)
@@ -105,7 +114,7 @@ export function GoogleCalendarSelector({
105114
setIsLoading(false)
106115
setInitialFetchDone(true)
107116
}
108-
}, [fetchCalendarsFromAPI, selectedCalendarId, onCalendarInfoChange])
117+
}, [fetchCalendarsFromAPI, credentialId])
109118

110119
const handleOpenChange = (isOpen: boolean) => {
111120
setOpen(isOpen)
@@ -115,72 +124,16 @@ export function GoogleCalendarSelector({
115124
}
116125
}
117126

118-
const fetchSelectedCalendarInfo = useCallback(async () => {
119-
if (!selectedCalendarId) return
120-
121-
setIsLoading(true)
122-
setError(null)
123-
124-
try {
125-
const calendars = await fetchCalendarsFromAPI()
126-
127-
if (calendars.length > 0) {
128-
const calendarInfo = calendars.find(
129-
(calendar: GoogleCalendarInfo) => calendar.id === selectedCalendarId
130-
)
131-
if (calendarInfo) {
132-
setSelectedCalendar(calendarInfo)
133-
onCalendarInfoChange?.(calendarInfo)
134-
}
135-
}
136-
} catch (error) {
137-
logger.error('Error fetching calendar info:', error)
138-
setError((error as Error).message)
139-
} finally {
140-
setIsLoading(false)
141-
}
142-
}, [fetchCalendarsFromAPI, selectedCalendarId, onCalendarInfoChange])
143-
144-
// Fetch selected calendar info when component mounts or dependencies change
145-
useEffect(() => {
146-
if (value && credentialId && (!selectedCalendar || selectedCalendar.id !== value)) {
147-
fetchSelectedCalendarInfo()
148-
}
149-
}, [value, credentialId, selectedCalendar, fetchSelectedCalendarInfo])
150-
151-
// Sync with external value
127+
// Sync selected ID with external value
152128
useEffect(() => {
153129
if (value !== selectedCalendarId) {
154130
setSelectedCalendarId(value)
155-
156-
// Find calendar info for the new value
157-
if (value && calendars.length > 0) {
158-
const calendarInfo = calendars.find((calendar) => calendar.id === value)
159-
setSelectedCalendar(calendarInfo || null)
160-
onCalendarInfoChange?.(calendarInfo || null)
161-
} else if (value) {
162-
// If we have a value but no calendar info, we might need to fetch it
163-
if (!selectedCalendar || selectedCalendar.id !== value) {
164-
fetchSelectedCalendarInfo()
165-
}
166-
} else {
167-
setSelectedCalendar(null)
168-
onCalendarInfoChange?.(null)
169-
}
170131
}
171-
}, [
172-
value,
173-
calendars,
174-
selectedCalendarId,
175-
selectedCalendar,
176-
fetchSelectedCalendarInfo,
177-
onCalendarInfoChange,
178-
])
132+
}, [value, selectedCalendarId])
179133

180134
// Handle calendar selection
181135
const handleSelectCalendar = (calendar: GoogleCalendarInfo) => {
182136
setSelectedCalendarId(calendar.id)
183-
setSelectedCalendar(calendar)
184137
onChange(calendar.id, calendar)
185138
onCalendarInfoChange?.(calendar)
186139
setOpen(false)
@@ -189,7 +142,6 @@ export function GoogleCalendarSelector({
189142
// Clear selection
190143
const handleClearSelection = () => {
191144
setSelectedCalendarId('')
192-
setSelectedCalendar(null)
193145
onChange('', undefined)
194146
onCalendarInfoChange?.(null)
195147
setError(null)
@@ -215,17 +167,10 @@ export function GoogleCalendarSelector({
215167
disabled={disabled || !credentialId}
216168
>
217169
<div className='flex min-w-0 items-center gap-2 overflow-hidden'>
218-
{selectedCalendar ? (
170+
{cachedCalendarName ? (
219171
<>
220-
<div
221-
className='h-3 w-3 flex-shrink-0 rounded-full'
222-
style={{
223-
backgroundColor: selectedCalendar.backgroundColor || '#4285f4',
224-
}}
225-
/>
226-
<span className='truncate font-normal'>
227-
{getCalendarDisplayName(selectedCalendar)}
228-
</span>
172+
<GoogleCalendarIcon className='h-4 w-4' />
173+
<span className='truncate font-normal'>{cachedCalendarName}</span>
229174
</>
230175
) : (
231176
<>

0 commit comments

Comments
 (0)