Skip to content

Commit 84fe0e4

Browse files
waleedlatif1claude
andcommitted
fix(hubspot): fall back to objectType default in selector fetchOptions
useSubBlockStore.getValue returns null for default-valued dropdowns until the user interacts with them. The properties, pipelines, stages, and ownerId selectors were treating that as "no selection" and short-circuiting, so the dropdowns appeared empty even though the trigger uses 'contact' as the visible default. Adds resolveSelectedObjectType to mirror the rendered default, so the selectors fire on first paint with a valid objectType. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1631b36 commit 84fe0e4

1 file changed

Lines changed: 31 additions & 23 deletions

File tree

apps/sim/triggers/hubspot/poller.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ import type { TriggerConfig } from '@/triggers/types'
1414

1515
const logger = createLogger('HubSpotPollingTrigger')
1616

17+
/**
18+
* Resolves the effective object type from the subblock store. `getValue` returns `null`
19+
* for fields the user hasn't interacted with yet, so we fall back to the dropdown's
20+
* default ('contact') — otherwise the cascading property selectors render empty on
21+
* first render even when the dropdown visibly shows "contact".
22+
*/
23+
function resolveSelectedObjectType(blockId: string): string | null {
24+
const objectType = useSubBlockStore.getState().getValue(blockId, 'objectType') as string | null
25+
const customId = useSubBlockStore.getState().getValue(blockId, 'customObjectTypeId') as
26+
| string
27+
| null
28+
const selected = objectType ?? 'contact'
29+
if (selected === 'custom') {
30+
const trimmed = customId?.trim()
31+
return trimmed ? trimmed : null
32+
}
33+
return selected
34+
}
35+
1736
async function fetchHubSpotProperties(blockId: string, objectType: string) {
1837
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
1938
| string
@@ -128,13 +147,7 @@ export const hubspotPollingTrigger: TriggerConfig = {
128147
placeholder: 'Select a property',
129148
options: [],
130149
fetchOptions: async (blockId: string) => {
131-
const objectType = useSubBlockStore.getState().getValue(blockId, 'objectType') as
132-
| string
133-
| null
134-
const customId = useSubBlockStore.getState().getValue(blockId, 'customObjectTypeId') as
135-
| string
136-
| null
137-
const resolved = objectType === 'custom' ? customId : objectType
150+
const resolved = resolveSelectedObjectType(blockId)
138151
if (!resolved) throw new Error('Select an object type first')
139152
try {
140153
return await fetchHubSpotProperties(blockId, resolved)
@@ -162,13 +175,7 @@ export const hubspotPollingTrigger: TriggerConfig = {
162175
placeholder: 'Select properties (optional)',
163176
options: [],
164177
fetchOptions: async (blockId: string) => {
165-
const objectType = useSubBlockStore.getState().getValue(blockId, 'objectType') as
166-
| string
167-
| null
168-
const customId = useSubBlockStore.getState().getValue(blockId, 'customObjectTypeId') as
169-
| string
170-
| null
171-
const resolved = objectType === 'custom' ? customId : objectType
178+
const resolved = resolveSelectedObjectType(blockId)
172179
if (!resolved) return []
173180
try {
174181
return await fetchHubSpotProperties(blockId, resolved)
@@ -193,10 +200,10 @@ export const hubspotPollingTrigger: TriggerConfig = {
193200
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
194201
| string
195202
| null
196-
const objectType = useSubBlockStore.getState().getValue(blockId, 'objectType') as
197-
| string
198-
| null
199-
if (!credentialId || !objectType) return []
203+
const objectType =
204+
(useSubBlockStore.getState().getValue(blockId, 'objectType') as string | null) ??
205+
'contact'
206+
if (!credentialId) throw new Error('No HubSpot credential selected')
200207
if (isCredentialSetValue(credentialId)) return []
201208
try {
202209
const data = await requestJson(hubspotPipelinesSelectorContract, {
@@ -224,14 +231,15 @@ export const hubspotPollingTrigger: TriggerConfig = {
224231
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
225232
| string
226233
| null
227-
const objectType = useSubBlockStore.getState().getValue(blockId, 'objectType') as
228-
| string
229-
| null
234+
const objectType =
235+
(useSubBlockStore.getState().getValue(blockId, 'objectType') as string | null) ??
236+
'contact'
230237
const pipelineId = useSubBlockStore.getState().getValue(blockId, 'pipelineId') as
231238
| string
232239
| null
233-
if (!credentialId || !objectType || !pipelineId) return []
240+
if (!credentialId) throw new Error('No HubSpot credential selected')
234241
if (isCredentialSetValue(credentialId)) return []
242+
if (!pipelineId) return []
235243
try {
236244
const data = await requestJson(hubspotPipelinesSelectorContract, {
237245
query: { credentialId, objectType },
@@ -259,7 +267,7 @@ export const hubspotPollingTrigger: TriggerConfig = {
259267
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
260268
| string
261269
| null
262-
if (!credentialId) return []
270+
if (!credentialId) throw new Error('No HubSpot credential selected')
263271
if (isCredentialSetValue(credentialId)) return []
264272
try {
265273
const data = await requestJson(hubspotOwnersSelectorContract, {

0 commit comments

Comments
 (0)