Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion static/app/components/selectMembers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Props = {
onChange: (value: any) => any;
organization: Organization;
value: any;
ariaLabel?: string;
disabled?: boolean;
onInputChange?: (value: any) => any;
placeholder?: string;
Expand Down Expand Up @@ -174,7 +175,7 @@ class SelectMembers extends Component<Props, State> {
};

render() {
const {placeholder, styles} = this.props;
const {placeholder, styles, ariaLabel} = this.props;

// If memberList is still loading we need to disable a placeholder Select,
// otherwise `react-select` will call `loadOptions` and prematurely load
Expand All @@ -185,6 +186,7 @@ class SelectMembers extends Component<Props, State> {

return (
<StyledSelectControl
aria-label={ariaLabel}
filterOption={(option: FilterOption<MentionableUser>, filterText: string) =>
option?.data?.searchKey?.indexOf(filterText) > -1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function IdentifierField() {
return (
<SelectWrapper>
<SelectMembers
aria-label={t('User')}
ariaLabel={t('User')}
organization={organization}
key={`${actionId}.config.targetIdentifier`}
value={action.config.targetIdentifier}
Expand Down
16 changes: 13 additions & 3 deletions static/app/views/automations/components/automationFormData.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {FieldValue} from 'sentry/components/forms/model';
import {t} from 'sentry/locale';
import type {Action} from 'sentry/types/workflowEngine/actions';
import {ActionType, type Action} from 'sentry/types/workflowEngine/actions';
import type {Automation, NewAutomation} from 'sentry/types/workflowEngine/automations';
import type {DataCondition} from 'sentry/types/workflowEngine/dataConditions';
import {actionNodesMap} from 'sentry/views/automations/components/actionNodes';
Expand Down Expand Up @@ -35,8 +35,18 @@ const stripSubfilterId = (subfilter: any) => {
return subfilterWithoutId;
};

const stripActionId = (action: any) => {
const stripActionFields = (action: Action) => {
const {id: _id, ...actionWithoutId} = action;

// Strip targetDisplay from email action config
if (action.type === ActionType.EMAIL && action.config) {
const {targetDisplay: _targetDisplay, ...configWithoutTargetDisplay} = action.config;
return {
...actionWithoutId,
config: configWithoutTargetDisplay,
};
}

return actionWithoutId;
};

Expand All @@ -45,7 +55,7 @@ const stripDataConditionGroupId = (group: any) => {
return {
...groupWithoutId,
conditions: group.conditions?.map(stripDataConditionId) || [],
actions: group.actions?.map(stripActionId) || [],
actions: group.actions?.map(stripActionFields) || [],
};
};

Expand Down
41 changes: 38 additions & 3 deletions static/app/views/automations/new.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {AutomationFixture} from 'sentry-fixture/automations';
import {MemberFixture} from 'sentry-fixture/member';
import {OrganizationFixture} from 'sentry-fixture/organization';
import {UserFixture} from 'sentry-fixture/user';
import {
ActionHandlerFixture,
DataConditionHandlerFixture,
Expand All @@ -18,6 +20,9 @@ import AutomationNewSettings from 'sentry/views/automations/new';

describe('AutomationNewSettings', () => {
const organization = OrganizationFixture({features: ['workflow-engine-ui']});
const mockMember = MemberFixture({
user: UserFixture({id: '1', name: 'Moo Deng', email: '[email protected]'}),
});

beforeEach(() => {
MockApiClient.clearMockResponses();
Expand All @@ -32,6 +37,11 @@ describe('AutomationNewSettings', () => {
handlerGroup: ActionGroup.NOTIFICATION,
integrations: [{id: '1', name: 'My Slack Workspace'}],
}),
ActionHandlerFixture({
type: ActionType.EMAIL,
handlerGroup: ActionGroup.NOTIFICATION,
integrations: [],
}),
],
});

Expand Down Expand Up @@ -63,11 +73,16 @@ describe('AutomationNewSettings', () => {
],
});

// Users endpoint fetched by AutomationBuilder for member selectors
// Users/members endpoints fetched by AutomationBuilder for member selectors
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/users/`,
method: 'GET',
body: [],
body: [mockMember],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/members/`,
method: 'GET',
body: [mockMember],
});

// Detectors list used by EditConnectedMonitors inside the form
Expand Down Expand Up @@ -107,6 +122,17 @@ describe('AutomationNewSettings', () => {
await selectEvent.select(screen.getByRole('textbox', {name: 'Add action'}), 'Slack');
await userEvent.type(screen.getByRole('textbox', {name: 'Target'}), '#alerts');

// Add an email action
await selectEvent.select(
screen.getByRole('textbox', {name: 'Add action'}),
'Notify on preferred channel'
);
await selectEvent.select(
screen.getByRole('textbox', {name: 'Notification target type'}),
'Member'
);
await selectEvent.select(screen.getByRole('textbox', {name: 'User'}), 'Moo Deng');

// Submit the form
await userEvent.click(screen.getByRole('button', {name: 'Create Alert'}));

Expand All @@ -115,7 +141,7 @@ describe('AutomationNewSettings', () => {
expect.anything(),
expect.objectContaining({
data: {
name: 'Notify #alerts via Slack',
name: 'Notify #alerts via Slack, Notify Moo Deng',
triggers: {
logicType: 'any-short',
conditions: [
Expand Down Expand Up @@ -148,6 +174,15 @@ describe('AutomationNewSettings', () => {
data: {},
status: 'active',
},
{
type: 'email',
config: {
targetType: 'user',
targetIdentifier: '1',
},
data: {},
status: 'active',
},
],
},
],
Expand Down
Loading