Skip to content

Commit ad68dc1

Browse files
improvement(grain): make trigger names in line with API since resource type not known (#3598)
* improvement(grain): make trigger names in line with API since resource type not known * address comments
1 parent 7ecd377 commit ad68dc1

File tree

11 files changed

+239
-30
lines changed

11 files changed

+239
-30
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1414
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
1515

1616
/**
17-
* Dropdown option type - can be a simple string or an object with label, id, and optional icon
17+
* Dropdown option type - can be a simple string or an object with label, id, and optional icon.
18+
* Options with `hidden: true` are excluded from the picker but still resolve for label display,
19+
* so existing workflows that reference them continue to work.
1820
*/
1921
type DropdownOption =
2022
| string
21-
| { label: string; id: string; icon?: React.ComponentType<{ className?: string }> }
23+
| {
24+
label: string
25+
id: string
26+
icon?: React.ComponentType<{ className?: string }>
27+
hidden?: boolean
28+
}
2229

2330
/**
2431
* Props for the Dropdown component
@@ -185,13 +192,12 @@ export const Dropdown = memo(function Dropdown({
185192
return fetchedOptions.map((opt) => ({ label: opt.label, id: opt.id }))
186193
}, [fetchedOptions])
187194

188-
const availableOptions = useMemo(() => {
195+
const allOptions = useMemo(() => {
189196
let opts: DropdownOption[] =
190197
fetchOptions && normalizedFetchedOptions.length > 0
191198
? normalizedFetchedOptions
192199
: evaluatedOptions
193200

194-
// Merge hydrated option if not already present
195201
if (hydratedOption) {
196202
const alreadyPresent = opts.some((o) =>
197203
typeof o === 'string' ? o === hydratedOption.id : o.id === hydratedOption.id
@@ -204,21 +210,19 @@ export const Dropdown = memo(function Dropdown({
204210
return opts
205211
}, [fetchOptions, normalizedFetchedOptions, evaluatedOptions, hydratedOption])
206212

207-
/**
208-
* Convert dropdown options to Combobox format
209-
*/
210213
const comboboxOptions = useMemo((): ComboboxOption[] => {
211-
return availableOptions.map((opt) => {
214+
return allOptions.map((opt) => {
212215
if (typeof opt === 'string') {
213216
return { label: opt.toLowerCase(), value: opt }
214217
}
215218
return {
216219
label: opt.label.toLowerCase(),
217220
value: opt.id,
218221
icon: 'icon' in opt ? opt.icon : undefined,
222+
hidden: opt.hidden,
219223
}
220224
})
221-
}, [availableOptions])
225+
}, [allOptions])
222226

223227
const optionMap = useMemo(() => {
224228
return new Map(comboboxOptions.map((opt) => [opt.value, opt.label]))

apps/sim/blocks/blocks/grain.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,17 @@ Return ONLY the search term - no explanations, no quotes, no extra text.`,
268268
type: 'dropdown',
269269
mode: 'trigger',
270270
options: grainTriggerOptions,
271-
value: () => 'grain_webhook',
271+
value: () => 'grain_item_added',
272272
required: true,
273273
},
274+
...getTrigger('grain_item_added').subBlocks,
275+
...getTrigger('grain_item_updated').subBlocks,
276+
...getTrigger('grain_webhook').subBlocks,
274277
...getTrigger('grain_recording_created').subBlocks,
275278
...getTrigger('grain_recording_updated').subBlocks,
276279
...getTrigger('grain_highlight_created').subBlocks,
277280
...getTrigger('grain_highlight_updated').subBlocks,
278281
...getTrigger('grain_story_created').subBlocks,
279-
...getTrigger('grain_webhook').subBlocks,
280282
],
281283
tools: {
282284
access: [
@@ -447,12 +449,14 @@ Return ONLY the search term - no explanations, no quotes, no extra text.`,
447449
triggers: {
448450
enabled: true,
449451
available: [
452+
'grain_item_added',
453+
'grain_item_updated',
454+
'grain_webhook',
450455
'grain_recording_created',
451456
'grain_recording_updated',
452457
'grain_highlight_created',
453458
'grain_highlight_updated',
454459
'grain_story_created',
455-
'grain_webhook',
456460
],
457461
},
458462
}

apps/sim/blocks/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,14 @@ export interface SubBlockConfig {
233233
id: string
234234
icon?: React.ComponentType<{ className?: string }>
235235
group?: string
236+
hidden?: boolean
236237
}[]
237238
| (() => {
238239
label: string
239240
id: string
240241
icon?: React.ComponentType<{ className?: string }>
241242
group?: string
243+
hidden?: boolean
242244
}[])
243245
min?: number
244246
max?: number

apps/sim/components/emcn/components/combobox/combobox.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const comboboxVariants = cva(
4545
export type ComboboxOption = {
4646
label: string
4747
value: string
48+
/** When true, hidden from the picker list but still resolves for display */
49+
hidden?: boolean
4850
/** Icon component to render */
4951
icon?: React.ComponentType<{ className?: string }>
5052
/** Pre-rendered icon element (alternative to icon component) */
@@ -207,12 +209,11 @@ const Combobox = memo(
207209
* Filter options based on current value or search query
208210
*/
209211
const filteredOptions = useMemo(() => {
210-
let result = allOptions
212+
let result = allOptions.filter((opt) => !opt.hidden)
211213

212-
// Filter by editable input value
213214
if (filterOptions && value && open) {
214215
const currentValue = value.toString().toLowerCase()
215-
const exactMatch = allOptions.find(
216+
const exactMatch = result.find(
216217
(opt) => opt.value === value || opt.label.toLowerCase() === currentValue
217218
)
218219
if (!exactMatch) {
@@ -224,7 +225,6 @@ const Combobox = memo(
224225
}
225226
}
226227

227-
// Filter by search query (for searchable mode)
228228
if (searchable && searchQuery) {
229229
const query = searchQuery.toLowerCase()
230230
result = result.filter((option) => {
@@ -242,10 +242,18 @@ const Combobox = memo(
242242
*/
243243
const filteredGroups = useMemo(() => {
244244
if (!groups) return null
245-
if (!searchable || !searchQuery) return groups
245+
246+
const baseGroups = groups
247+
.map((group) => ({
248+
...group,
249+
items: group.items.filter((opt) => !opt.hidden),
250+
}))
251+
.filter((group) => group.items.length > 0)
252+
253+
if (!searchable || !searchQuery) return baseGroups
246254

247255
const query = searchQuery.toLowerCase()
248-
return groups
256+
return baseGroups
249257
.map((group) => ({
250258
...group,
251259
items: group.items.filter((option) => {

apps/sim/lib/webhooks/provider-subscriptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,8 @@ export async function createGrainWebhookSubscription(
12581258
}
12591259

12601260
const actionMap: Record<string, Array<'added' | 'updated' | 'removed'>> = {
1261+
grain_item_added: ['added'],
1262+
grain_item_updated: ['updated'],
12611263
grain_recording_created: ['added'],
12621264
grain_recording_updated: ['updated'],
12631265
grain_highlight_created: ['added'],
@@ -1267,6 +1269,8 @@ export async function createGrainWebhookSubscription(
12671269

12681270
const eventTypeMap: Record<string, string[]> = {
12691271
grain_webhook: [],
1272+
grain_item_added: [],
1273+
grain_item_updated: [],
12701274
grain_recording_created: ['recording_added'],
12711275
grain_recording_updated: ['recording_updated'],
12721276
grain_highlight_created: ['highlight_added'],

apps/sim/triggers/grain/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export { grainHighlightCreatedTrigger } from './highlight_created'
22
export { grainHighlightUpdatedTrigger } from './highlight_updated'
3+
export { grainItemAddedTrigger } from './item_added'
4+
export { grainItemUpdatedTrigger } from './item_updated'
35
export { grainRecordingCreatedTrigger } from './recording_created'
46
export { grainRecordingUpdatedTrigger } from './recording_updated'
57
export { grainStoryCreatedTrigger } from './story_created'
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { GrainIcon } from '@/components/icons'
2+
import type { TriggerConfig } from '@/triggers/types'
3+
import { buildGenericOutputs, grainV2SetupInstructions } from './utils'
4+
5+
export const grainItemAddedTrigger: TriggerConfig = {
6+
id: 'grain_item_added',
7+
name: 'Grain Item Added',
8+
provider: 'grain',
9+
description: 'Trigger when a new item is added to a Grain view (recording, highlight, or story)',
10+
version: '1.0.0',
11+
icon: GrainIcon,
12+
13+
subBlocks: [
14+
{
15+
id: 'apiKey',
16+
title: 'API Key',
17+
type: 'short-input',
18+
placeholder: 'Enter your Grain API key (Personal Access Token)',
19+
description: 'Required to create the webhook in Grain.',
20+
password: true,
21+
required: true,
22+
mode: 'trigger',
23+
condition: {
24+
field: 'selectedTriggerId',
25+
value: 'grain_item_added',
26+
},
27+
},
28+
{
29+
id: 'viewId',
30+
title: 'View ID',
31+
type: 'short-input',
32+
placeholder: 'Enter Grain view UUID',
33+
description:
34+
'The view determines which content type fires events (recordings, highlights, or stories).',
35+
required: true,
36+
mode: 'trigger',
37+
condition: {
38+
field: 'selectedTriggerId',
39+
value: 'grain_item_added',
40+
},
41+
},
42+
{
43+
id: 'triggerSave',
44+
title: '',
45+
type: 'trigger-save',
46+
hideFromPreview: true,
47+
mode: 'trigger',
48+
triggerId: 'grain_item_added',
49+
condition: {
50+
field: 'selectedTriggerId',
51+
value: 'grain_item_added',
52+
},
53+
},
54+
{
55+
id: 'triggerInstructions',
56+
title: 'Setup Instructions',
57+
hideFromPreview: true,
58+
type: 'text',
59+
defaultValue: grainV2SetupInstructions('item added'),
60+
mode: 'trigger',
61+
condition: {
62+
field: 'selectedTriggerId',
63+
value: 'grain_item_added',
64+
},
65+
},
66+
],
67+
68+
outputs: buildGenericOutputs(),
69+
70+
webhook: {
71+
method: 'POST',
72+
headers: {
73+
'Content-Type': 'application/json',
74+
},
75+
},
76+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { GrainIcon } from '@/components/icons'
2+
import type { TriggerConfig } from '@/triggers/types'
3+
import { buildGenericOutputs, grainV2SetupInstructions } from './utils'
4+
5+
export const grainItemUpdatedTrigger: TriggerConfig = {
6+
id: 'grain_item_updated',
7+
name: 'Grain Item Updated',
8+
provider: 'grain',
9+
description: 'Trigger when an item is updated in a Grain view (recording, highlight, or story)',
10+
version: '1.0.0',
11+
icon: GrainIcon,
12+
13+
subBlocks: [
14+
{
15+
id: 'apiKey',
16+
title: 'API Key',
17+
type: 'short-input',
18+
placeholder: 'Enter your Grain API key (Personal Access Token)',
19+
description: 'Required to create the webhook in Grain.',
20+
password: true,
21+
required: true,
22+
mode: 'trigger',
23+
condition: {
24+
field: 'selectedTriggerId',
25+
value: 'grain_item_updated',
26+
},
27+
},
28+
{
29+
id: 'viewId',
30+
title: 'View ID',
31+
type: 'short-input',
32+
placeholder: 'Enter Grain view UUID',
33+
description:
34+
'The view determines which content type fires events (recordings, highlights, or stories).',
35+
required: true,
36+
mode: 'trigger',
37+
condition: {
38+
field: 'selectedTriggerId',
39+
value: 'grain_item_updated',
40+
},
41+
},
42+
{
43+
id: 'triggerSave',
44+
title: '',
45+
type: 'trigger-save',
46+
hideFromPreview: true,
47+
mode: 'trigger',
48+
triggerId: 'grain_item_updated',
49+
condition: {
50+
field: 'selectedTriggerId',
51+
value: 'grain_item_updated',
52+
},
53+
},
54+
{
55+
id: 'triggerInstructions',
56+
title: 'Setup Instructions',
57+
hideFromPreview: true,
58+
type: 'text',
59+
defaultValue: grainV2SetupInstructions('item updated'),
60+
mode: 'trigger',
61+
condition: {
62+
field: 'selectedTriggerId',
63+
value: 'grain_item_updated',
64+
},
65+
},
66+
],
67+
68+
outputs: buildGenericOutputs(),
69+
70+
webhook: {
71+
method: 'POST',
72+
headers: {
73+
'Content-Type': 'application/json',
74+
},
75+
},
76+
}

0 commit comments

Comments
 (0)