Skip to content

improvement(grain): make trigger names in line with API since resource type not known#3598

Merged
icecrasher321 merged 2 commits intostagingfrom
improvement/grain
Mar 15, 2026
Merged

improvement(grain): make trigger names in line with API since resource type not known#3598
icecrasher321 merged 2 commits intostagingfrom
improvement/grain

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Grain view id decides resource type -- which makes current dropdown functionality quite confusing. This new version maintains alignment with actual API. No backwards compat broken.

Type of Change

  • Other: UX improvement

Testing

tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@cursor
Copy link

cursor bot commented Mar 15, 2026

PR Summary

Medium Risk
Adds new Grain webhook trigger IDs and changes how Grain subscriptions are created/scoped, plus introduces hidden dropdown options that affect option rendering across the UI. Risk is moderate because it touches webhook subscription mapping and selection UI, but aims to preserve existing workflows via hidden options.

Overview
Grain triggers are reworked to align with view-based scoping. The Grain block now defaults to grain_item_added, adds new triggers grain_item_added/grain_item_updated, and renames the generic trigger to “Grain All Events”, with updated setup instructions via grainV2SetupInstructions.

Legacy Grain trigger types are kept for compatibility but hidden in the UI. grainTriggerOptions marks recording/highlight/story-specific triggers as hidden, and the dropdown/combobox pipeline now carries a hidden flag and filters hidden options out of picker lists while still allowing stored values to resolve/display.

Webhook subscription creation is extended for the new triggers. Grain provider subscription logic maps grain_item_added/grain_item_updated to the appropriate action filters and registers the new trigger IDs in the trigger registry.

Written by Cursor Bugbot for commit f39a305. Configure here.

@vercel
Copy link

vercel bot commented Mar 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 15, 2026 7:33am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 15, 2026

Greptile Summary

This PR improves the Grain trigger UX by introducing two new API-aligned trigger types — grain_item_added and grain_item_updated — that scope events by view ID without requiring users to know the underlying resource type upfront. Legacy triggers (grain_recording_created, grain_highlight_created, etc.) are preserved for backwards compatibility by hiding them from the picker while still allowing their labels to resolve in existing workflows via a new hidden option in the dropdown.

Key changes:

  • Adds grain_item_added and grain_item_updated triggers with full registration in the registry, index, and block config
  • Introduces hidden?: boolean to SubBlockConfig dropdown option types and splits allOptions / selectableOptions in dropdown.tsx so hidden items still resolve labels for existing saved values
  • Renames grain_webhook → "Grain All Events" and adds a new grainV2SetupInstructions utility
  • Changes the default trigger from grain_webhook to grain_item_added
  • Adds grain_item_added / grain_item_updated to actionMap in provider-subscriptions.ts with actions: ['added'] / actions: ['updated'] respectively

Issues found:

  • grainV2SetupInstructions('all') produces the instruction text "will fire the all event" for the grain_webhook trigger — grammatically awkward and potentially confusing for users
  • eventTypeMap in provider-subscriptions.ts is extended for the new triggers but eventTypes is never included in the Grain API request body (pre-existing dead code pattern now extended to two new entries)

Confidence Score: 4/5

  • This PR is safe to merge with minor UX polish recommended before shipping.
  • The changes are well-scoped and backwards compatible — hidden dropdown entries ensure existing workflows continue to resolve. The core logic (webhook subscription creation with correct actions filtering) is correct. The two minor issues are cosmetic/dead-code and do not affect runtime behavior.
  • apps/sim/triggers/grain/webhook.ts (awkward instruction text) and apps/sim/lib/webhooks/provider-subscriptions.ts (unused eventTypeMap entries)

Important Files Changed

Filename Overview
apps/sim/triggers/grain/utils.ts Adds grainV2SetupInstructions and hides legacy options via hidden: true; the instruction template produces awkward text when called with 'all' for the webhook trigger.
apps/sim/triggers/grain/webhook.ts Renames trigger to "Grain All Events" and switches to grainV2SetupInstructions('all'), producing awkward instruction text "will fire the all event".
apps/sim/lib/webhooks/provider-subscriptions.ts Correctly adds grain_item_added/grain_item_updated to actionMap; extends the pre-existing pattern of populating eventTypeMap with values that are never sent to the Grain API.
apps/sim/blocks/blocks/grain.ts Registers new triggers in subBlocks and available; correctly changes default trigger value from grain_webhook to grain_item_added.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/dropdown/dropdown.tsx Clean split of allOptions (for label resolution) vs selectableOptions (for the picker UI) to support hidden dropdown entries; the optionMap now correctly sources from allOptions so hidden legacy values still resolve their labels.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User selects Grain Trigger] --> B{selectedTriggerId}

    B --> C[grain_item_added\nnew]
    B --> D[grain_item_updated\nnew]
    B --> E[grain_webhook\nAll Events]
    B --> F[grain_recording_created\nhidden - legacy]
    B --> G[grain_recording_updated\nhidden - legacy]
    B --> H[grain_highlight_created\nhidden - legacy]
    B --> I[grain_highlight_updated\nhidden - legacy]
    B --> J[grain_story_created\nhidden - legacy]

    C --> K[actionMap: added\neventTypeMap: empty]
    D --> L[actionMap: updated\neventTypeMap: empty]
    E --> M[actionMap: none\neventTypeMap: empty]
    F --> N[actionMap: added\neventTypeMap: recording_added]
    G --> O[actionMap: updated\neventTypeMap: recording_updated]

    K --> P[POST /hooks\nversion:2, view_id, actions:added]
    L --> Q[POST /hooks\nversion:2, view_id, actions:updated]
    M --> R[POST /hooks\nversion:2, view_id\nno actions filter]
    N --> P2[POST /hooks\nversion:2, view_id, actions:added]

    style C fill:#22c55e,color:#fff
    style D fill:#22c55e,color:#fff
    style F fill:#94a3b8,color:#fff
    style G fill:#94a3b8,color:#fff
    style H fill:#94a3b8,color:#fff
    style I fill:#94a3b8,color:#fff
    style J fill:#94a3b8,color:#fff
Loading

Last reviewed commit: 33cf0de

@icecrasher321
Copy link
Collaborator Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@icecrasher321 icecrasher321 merged commit ad68dc1 into staging Mar 15, 2026
12 checks passed
@icecrasher321 icecrasher321 deleted the improvement/grain branch March 15, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant