Skip to content

Commit eba43d2

Browse files
committed
fix default model picking based on user config
1 parent 101eace commit eba43d2

File tree

2 files changed

+38
-15
lines changed
  • apps/sim/app/workspace/[workspaceId]/w
    • [workflowId]/components/panel/components/editor/components/sub-block/components/combobox
    • components/sidebar/components/search-modal

2 files changed

+38
-15
lines changed

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function ComboBox({
135135
const value = isPreview ? previewValue : propValue !== undefined ? propValue : storeValue
136136

137137
// Permission-based filtering for model dropdowns
138-
const { isProviderAllowed } = usePermissionConfig()
138+
const { isProviderAllowed, isLoading: isPermissionLoading } = usePermissionConfig()
139139

140140
// Evaluate static options if provided as a function
141141
const staticOptions = useMemo(() => {
@@ -269,16 +269,34 @@ export function ComboBox({
269269
setStoreInitialized(true)
270270
}, [])
271271

272-
// Set default value once store is initialized and value is undefined
272+
// Check if current value is valid (exists in allowed options)
273+
const isValueValid = useMemo(() => {
274+
if (value === null || value === undefined) return false
275+
return evaluatedOptions.some((opt) => getOptionValue(opt) === value)
276+
}, [value, evaluatedOptions, getOptionValue])
277+
278+
// Set default value once store is initialized and permissions are loaded
279+
// Also reset if current value becomes invalid (e.g., provider was blocked)
273280
useEffect(() => {
274-
if (
275-
storeInitialized &&
276-
(value === null || value === undefined) &&
277-
defaultOptionValue !== undefined
278-
) {
281+
if (isPermissionLoading) return
282+
if (!storeInitialized) return
283+
if (defaultOptionValue === undefined) return
284+
285+
const needsDefault = value === null || value === undefined
286+
const needsReset = subBlockId === 'model' && value && !isValueValid
287+
288+
if (needsDefault || needsReset) {
279289
setStoreValue(defaultOptionValue)
280290
}
281-
}, [storeInitialized, value, defaultOptionValue, setStoreValue])
291+
}, [
292+
storeInitialized,
293+
value,
294+
defaultOptionValue,
295+
setStoreValue,
296+
isPermissionLoading,
297+
subBlockId,
298+
isValueValid,
299+
])
282300

283301
// Clear fetched options and hydrated option when dependencies change
284302
useEffect(() => {

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getTriggersForSidebar, hasTriggerCapability } from '@/lib/workflows/tri
1212
import { searchItems } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-utils'
1313
import { SIDEBAR_SCROLL_EVENT } from '@/app/workspace/[workspaceId]/w/components/sidebar/sidebar'
1414
import { getAllBlocks } from '@/blocks'
15+
import { usePermissionConfig } from '@/hooks/use-permission-config'
1516

1617
interface SearchModalProps {
1718
open: boolean
@@ -99,12 +100,14 @@ export function SearchModal({
99100
const router = useRouter()
100101
const workspaceId = params.workspaceId as string
101102
const brand = useBrandConfig()
103+
const { filterBlocks } = usePermissionConfig()
102104

103105
const blocks = useMemo(() => {
104106
if (!isOnWorkflowPage) return []
105107

106108
const allBlocks = getAllBlocks()
107-
const regularBlocks = allBlocks
109+
const filteredAllBlocks = filterBlocks(allBlocks)
110+
const regularBlocks = filteredAllBlocks
108111
.filter(
109112
(block) => block.type !== 'starter' && !block.hideFromToolbar && block.category === 'blocks'
110113
)
@@ -138,16 +141,17 @@ export function SearchModal({
138141
},
139142
]
140143

141-
return [...regularBlocks, ...specialBlocks]
142-
}, [isOnWorkflowPage])
144+
return [...regularBlocks, ...filterBlocks(specialBlocks)]
145+
}, [isOnWorkflowPage, filterBlocks])
143146

144147
const triggers = useMemo(() => {
145148
if (!isOnWorkflowPage) return []
146149

147150
const allTriggers = getTriggersForSidebar()
151+
const filteredTriggers = filterBlocks(allTriggers)
148152
const priorityOrder = ['Start', 'Schedule', 'Webhook']
149153

150-
const sortedTriggers = allTriggers.sort((a, b) => {
154+
const sortedTriggers = filteredTriggers.sort((a, b) => {
151155
const aIndex = priorityOrder.indexOf(a.name)
152156
const bIndex = priorityOrder.indexOf(b.name)
153157
const aHasPriority = aIndex !== -1
@@ -170,13 +174,14 @@ export function SearchModal({
170174
config: block,
171175
})
172176
)
173-
}, [isOnWorkflowPage])
177+
}, [isOnWorkflowPage, filterBlocks])
174178

175179
const tools = useMemo(() => {
176180
if (!isOnWorkflowPage) return []
177181

178182
const allBlocks = getAllBlocks()
179-
return allBlocks
183+
const filteredAllBlocks = filterBlocks(allBlocks)
184+
return filteredAllBlocks
180185
.filter((block) => block.category === 'tools')
181186
.map(
182187
(block): ToolItem => ({
@@ -188,7 +193,7 @@ export function SearchModal({
188193
type: block.type,
189194
})
190195
)
191-
}, [isOnWorkflowPage])
196+
}, [isOnWorkflowPage, filterBlocks])
192197

193198
const pages = useMemo(
194199
(): PageItem[] => [

0 commit comments

Comments
 (0)