-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(seer-activity): Add the frontend form for seer activity condition #116689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
leeandher
merged 5 commits into
master
from
leanderrodrigues/iswf-2721-implement-the-frontend-for-the-new-data-condition
Jun 2, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
static/app/views/automations/components/actionFilters/seerActivityTrigger.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| import {DataConditionFixture} from 'sentry-fixture/automations'; | ||
|
|
||
| import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import {DataConditionType} from 'sentry/types/workflowEngine/dataConditions'; | ||
| import { | ||
| SeerActivityTriggerDetails, | ||
| SeerActivityTriggerNode, | ||
| validateSeerActivityTriggerCondition, | ||
| } from 'sentry/views/automations/components/actionFilters/seerActivityTrigger'; | ||
| import {AutomationBuilderErrorContext} from 'sentry/views/automations/components/automationBuilderErrorContext'; | ||
| import {DataConditionNodeContext} from 'sentry/views/automations/components/dataConditionNodes'; | ||
|
|
||
| describe('SeerActivityTriggerDetails', () => { | ||
| it('renders single-stage text', () => { | ||
| render( | ||
| <SeerActivityTriggerDetails | ||
| condition={DataConditionFixture({ | ||
| type: DataConditionType.SEER_ACTIVITY_TRIGGER, | ||
| comparison: ['pr_created'], | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByText("Seer reaches the 'Pull request created' stage") | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders multi-stage text', () => { | ||
| render( | ||
| <SeerActivityTriggerDetails | ||
| condition={DataConditionFixture({ | ||
| type: DataConditionType.SEER_ACTIVITY_TRIGGER, | ||
| comparison: ['rca_started', 'coding_completed'], | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByText( | ||
| 'Seer reaches any of these stages: Root cause analysis started, Coding completed' | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('handles empty comparison gracefully', () => { | ||
| render( | ||
| <SeerActivityTriggerDetails | ||
| condition={DataConditionFixture({ | ||
| type: DataConditionType.SEER_ACTIVITY_TRIGGER, | ||
| comparison: [], | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Seer reaches any of these stages:')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('SeerActivityTriggerNode', () => { | ||
| const dataCondition = DataConditionFixture({ | ||
| id: 'seer-1', | ||
| type: DataConditionType.SEER_ACTIVITY_TRIGGER, | ||
| comparison: ['rca_started', 'coding_completed'], | ||
| }); | ||
| const errorContext = { | ||
| errors: {}, | ||
| mutationErrors: undefined, | ||
| setErrors: jest.fn(), | ||
| removeError: jest.fn(), | ||
| }; | ||
| const dataConditionNodeContext = { | ||
| condition: dataCondition, | ||
| condition_id: dataCondition.id, | ||
| onUpdate: jest.fn(), | ||
| }; | ||
|
|
||
| it('renders the label and select', () => { | ||
| render( | ||
| <AutomationBuilderErrorContext.Provider value={errorContext}> | ||
| <DataConditionNodeContext.Provider value={dataConditionNodeContext}> | ||
| <SeerActivityTriggerNode /> | ||
| </DataConditionNodeContext.Provider> | ||
| </AutomationBuilderErrorContext.Provider> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByText('Seer runs on an issue and reaches the stage...') | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByRole('textbox', {name: 'Seer activity stages'}) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls onUpdate and removeError when a stage is selected', async () => { | ||
| render( | ||
| <AutomationBuilderErrorContext.Provider value={errorContext}> | ||
| <DataConditionNodeContext.Provider value={dataConditionNodeContext}> | ||
| <SeerActivityTriggerNode /> | ||
| </DataConditionNodeContext.Provider> | ||
| </AutomationBuilderErrorContext.Provider> | ||
| ); | ||
| await userEvent.click(screen.getByRole('textbox', {name: 'Seer activity stages'})); | ||
| await userEvent.click( | ||
| screen.getByRole('menuitemcheckbox', {name: 'Pull request created'}) | ||
| ); | ||
| await waitFor(() => { | ||
| expect(dataConditionNodeContext.onUpdate).toHaveBeenCalledWith({ | ||
| comparison: dataCondition.comparison.concat('pr_created'), | ||
| }); | ||
| }); | ||
| expect(errorContext.removeError).toHaveBeenCalledWith('seer-1'); | ||
| }); | ||
|
|
||
| it('renders pre-selected stages', () => { | ||
| render( | ||
| <AutomationBuilderErrorContext.Provider value={errorContext}> | ||
| <DataConditionNodeContext.Provider value={dataConditionNodeContext}> | ||
| <SeerActivityTriggerNode /> | ||
| </DataConditionNodeContext.Provider> | ||
| </AutomationBuilderErrorContext.Provider> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Root cause analysis started')).toBeInTheDocument(); | ||
| expect(screen.getByText('Coding completed')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('validateSeerActivityTriggerCondition', () => { | ||
| it('returns error when comparison is invalid', () => { | ||
| expect( | ||
| validateSeerActivityTriggerCondition({ | ||
| condition: DataConditionFixture({ | ||
| type: DataConditionType.SEER_ACTIVITY_TRIGGER, | ||
| comparison: [], | ||
| }), | ||
| }) | ||
| ).toBe('You must select at least one Seer stage.'); | ||
|
|
||
| expect( | ||
| validateSeerActivityTriggerCondition({ | ||
| condition: DataConditionFixture({ | ||
| type: DataConditionType.SEER_ACTIVITY_TRIGGER, | ||
| comparison: undefined, | ||
| }), | ||
| }) | ||
| ).toBe('You must select at least one Seer stage.'); | ||
| }); | ||
|
|
||
| it('returns undefined for valid comparison', () => { | ||
| expect( | ||
| validateSeerActivityTriggerCondition({ | ||
| condition: DataConditionFixture({ | ||
| type: DataConditionType.SEER_ACTIVITY_TRIGGER, | ||
| comparison: ['rca_started'], | ||
| }), | ||
| }) | ||
| ).toBeUndefined(); | ||
| }); | ||
| }); |
70 changes: 70 additions & 0 deletions
70
static/app/views/automations/components/actionFilters/seerActivityTrigger.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import {Flex} from '@sentry/scraps/layout'; | ||
| import {Text} from '@sentry/scraps/text'; | ||
|
|
||
| import {AutomationBuilderSelect} from 'sentry/components/workflowEngine/form/automationBuilderSelect'; | ||
| import {t, tct} from 'sentry/locale'; | ||
| import type {SelectValue} from 'sentry/types/core'; | ||
| import type {DataCondition} from 'sentry/types/workflowEngine/dataConditions'; | ||
| import {useAutomationBuilderErrorContext} from 'sentry/views/automations/components/automationBuilderErrorContext'; | ||
| import type {ValidateDataConditionProps} from 'sentry/views/automations/components/automationFormData'; | ||
| import {useDataConditionNodeContext} from 'sentry/views/automations/components/dataConditionNodes'; | ||
|
|
||
| const SEER_ACTIVITY_STAGE_CHOICES: Array<{label: string; value: string}> = [ | ||
| {value: 'rca_started', label: t('Root cause analysis started')}, | ||
| {value: 'rca_completed', label: t('Root cause analysis completed')}, | ||
| {value: 'solution_started', label: t('Solution search started')}, | ||
| {value: 'solution_completed', label: t('Solution search completed')}, | ||
| {value: 'coding_started', label: t('Coding started')}, | ||
| {value: 'coding_completed', label: t('Coding completed')}, | ||
| {value: 'pr_created', label: t('Pull request created')}, | ||
| ]; | ||
|
|
||
| export function SeerActivityTriggerDetails({condition}: {condition: DataCondition}) { | ||
| const stages: string[] = Array.isArray(condition.comparison) | ||
| ? condition.comparison | ||
| : []; | ||
| // The stages should all appear in SEER_ACTIVITY_STAGE_CHOICES, but for type safety we call | ||
| // call .filter(Boolean) to get rid of invalid stages when we render. | ||
| const labels = stages | ||
| .map(s => SEER_ACTIVITY_STAGE_CHOICES.find(c => c.value === s)?.label) | ||
| .filter(Boolean); | ||
|
leeandher marked this conversation as resolved.
|
||
| const details = | ||
| labels.length === 1 | ||
| ? tct("Seer reaches the '[stage]' stage", {stage: labels[0] ?? ''}) | ||
| : tct('Seer reaches any of these stages: [stages]', {stages: labels.join(', ')}); | ||
|
|
||
| return <span>{details}</span>; | ||
| } | ||
|
|
||
| export function SeerActivityTriggerNode() { | ||
| const {condition, condition_id, onUpdate} = useDataConditionNodeContext(); | ||
| const {removeError} = useAutomationBuilderErrorContext(); | ||
| const value: string[] = Array.isArray(condition.comparison) ? condition.comparison : []; | ||
|
|
||
| return ( | ||
| <Flex direction="column" gap="sm"> | ||
| <Text>{t('Seer runs on an issue and reaches the stage...')}</Text> | ||
| <AutomationBuilderSelect | ||
| multiple | ||
| name={`${condition_id}.comparison`} | ||
| aria-label={t('Seer activity stages')} | ||
| placeholder={t('Select a stage...')} | ||
| value={value} | ||
| options={SEER_ACTIVITY_STAGE_CHOICES} | ||
| onChange={(options: Array<SelectValue<string>>) => { | ||
| onUpdate({comparison: options.map(o => o.value)}); | ||
| removeError(condition.id); | ||
| }} | ||
| /> | ||
| </Flex> | ||
| ); | ||
| } | ||
|
|
||
| export function validateSeerActivityTriggerCondition({ | ||
| condition, | ||
| }: ValidateDataConditionProps): string | undefined { | ||
| if (!Array.isArray(condition.comparison) || condition.comparison.length === 0) { | ||
| return t('You must select at least one Seer stage.'); | ||
| } | ||
| return undefined; | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
static/app/views/automations/components/automationBuilderContext.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import {act, renderHook} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import {DataConditionType} from 'sentry/types/workflowEngine/dataConditions'; | ||
| import {dataConditionNodesMap} from 'sentry/views/automations/components/dataConditionNodes'; | ||
|
|
||
| import {useAutomationBuilderReducer} from './automationBuilderContext'; | ||
|
|
||
| describe('useAutomationBuilderReducer', () => { | ||
| it('falls back to true for when conditions without a defaultComparison', () => { | ||
| const {result} = renderHook(useAutomationBuilderReducer); | ||
|
|
||
| act(() => { | ||
| result.current.actions.addWhenCondition(DataConditionType.FIRST_SEEN_EVENT); | ||
| }); | ||
|
|
||
| const conditions = result.current.state.triggers.conditions.filter( | ||
| c => c.type === DataConditionType.FIRST_SEEN_EVENT | ||
| ); | ||
| const addedCondition = conditions.at(-1); | ||
|
|
||
| expect(addedCondition?.comparison).toBe(true); | ||
| }); | ||
|
|
||
| it('uses defaultComparison from the node map when adding a when condition', () => { | ||
| const {result} = renderHook(useAutomationBuilderReducer); | ||
|
|
||
| act(() => { | ||
| result.current.actions.addWhenCondition(DataConditionType.SEER_ACTIVITY_TRIGGER); | ||
| }); | ||
|
|
||
| const addedCondition = result.current.state.triggers.conditions.find( | ||
| c => c.type === DataConditionType.SEER_ACTIVITY_TRIGGER | ||
| ); | ||
|
|
||
| const expectedDefault = dataConditionNodesMap.get( | ||
| DataConditionType.SEER_ACTIVITY_TRIGGER | ||
| )?.defaultComparison; | ||
|
|
||
| expect(expectedDefault).toBeDefined(); | ||
| expect(addedCondition).toBeDefined(); | ||
| expect(addedCondition?.comparison).toEqual(expectedDefault); | ||
| }); | ||
|
|
||
| it('uses defaultComparison from the node map when adding an if condition', () => { | ||
| const {result} = renderHook(useAutomationBuilderReducer); | ||
| const groupId = result.current.state.actionFilters[0]!.id; | ||
|
|
||
| act(() => { | ||
| result.current.actions.addIfCondition(groupId, DataConditionType.AGE_COMPARISON); | ||
| }); | ||
|
|
||
| const addedCondition = result.current.state.actionFilters[0]?.conditions.find( | ||
| c => c.type === DataConditionType.AGE_COMPARISON | ||
| ); | ||
|
|
||
| const expectedDefault = dataConditionNodesMap.get( | ||
| DataConditionType.AGE_COMPARISON | ||
| )?.defaultComparison; | ||
|
|
||
| expect(expectedDefault).toBeDefined(); | ||
| expect(addedCondition).toBeDefined(); | ||
| expect(addedCondition?.comparison).toEqual(expectedDefault); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.