Skip to content

Commit 6038573

Browse files
authored
fix(aci): replace form input fields with regular inputs (#94483)
since the automation builder has it's own state being managed outside of the form model, there is no need for the inputs to be form fields. this also allows the inputs to be properly filled with an initial value (since it's no longer getting the value from the form model) also added default `comparison` values to the data conditions in the [dataConditionNodesMap](https://github.com/getsentry/sentry/blob/6c2ed68e9657a52dffc06d10bb33eb8bdde1533c/static/app/views/automations/components/dataConditionNodes.tsx#L97)
1 parent 9c80bbc commit 6038573

32 files changed

+271
-218
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type {ComponentProps} from 'react';
2+
import styled from '@emotion/styled';
3+
4+
import {Input} from 'sentry/components/core/input';
5+
6+
export function AutomationBuilderInput(props: ComponentProps<typeof Input>) {
7+
return <InlineInput type="text" {...props} />;
8+
}
9+
10+
const InlineInput = styled(Input)`
11+
width: auto;
12+
height: 28px;
13+
min-height: 28px;
14+
`;

static/app/components/workflowEngine/form/automationBuilderInputField.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

static/app/components/workflowEngine/form/automationBuilderNumberField.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type {ComponentProps} from 'react';
2+
import styled from '@emotion/styled';
3+
4+
import {NumberInput} from 'sentry/components/core/input/numberInput';
5+
6+
export function AutomationBuilderNumberInput(props: ComponentProps<typeof NumberInput>) {
7+
return <InlineNumberInput min={0} {...props} />;
8+
}
9+
10+
const InlineNumberInput = styled(NumberInput)`
11+
width: 90px;
12+
height: 28px;
13+
min-height: 28px;
14+
`;

static/app/components/workflowEngine/form/automationBuilderSelectField.tsx renamed to static/app/components/workflowEngine/form/automationBuilderSelect.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import type {ComponentProps} from 'react';
22
import styled from '@emotion/styled';
33

4-
import SelectField from 'sentry/components/forms/fields/selectField';
4+
import {Select} from 'sentry/components/core/select';
55

6-
type SelectFieldProps = ComponentProps<typeof SelectField>;
7-
8-
export default function AutomationBuilderSelectField(props: SelectFieldProps) {
6+
export function AutomationBuilderSelect(props: ComponentProps<typeof Select>) {
97
return (
10-
<StyledSelectField
8+
<StyledSelect
119
flexibleControlStateSize
1210
hideLabel
1311
inline
@@ -17,7 +15,7 @@ export default function AutomationBuilderSelectField(props: SelectFieldProps) {
1715
);
1816
}
1917

20-
const StyledSelectField = styled(SelectField)`
18+
const StyledSelect = styled(Select)`
2119
width: 180px;
2220
padding: 0;
2321
> div {

static/app/types/workflowEngine/actions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface Action {
77
target_display?: string;
88
target_identifier?: string;
99
};
10-
data: Record<string, unknown>;
10+
data: Record<string, any>;
1111
id: string;
1212
type: ActionType;
1313
integrationId?: string;
@@ -16,7 +16,7 @@ export interface Action {
1616
export interface TicketCreationAction extends Action {
1717
[key: string]: any;
1818
data: {
19-
additional_fields?: Record<string, unknown>;
19+
additional_fields?: Record<string, any>;
2020
dynamic_form_fields?: IssueConfigField[];
2121
};
2222
integrationId: string;

static/app/views/automations/components/actionFilters/ageComparison.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
import AutomationBuilderNumberField from 'sentry/components/workflowEngine/form/automationBuilderNumberField';
2-
import AutomationBuilderSelectField from 'sentry/components/workflowEngine/form/automationBuilderSelectField';
1+
import {AutomationBuilderNumberInput} from 'sentry/components/workflowEngine/form/automationBuilderNumberInput';
2+
import {AutomationBuilderSelect} from 'sentry/components/workflowEngine/form/automationBuilderSelect';
33
import {tct} from 'sentry/locale';
4+
import type {SelectValue} from 'sentry/types/core';
45
import type {DataCondition} from 'sentry/types/workflowEngine/dataConditions';
6+
import type {AgeComparison} from 'sentry/views/automations/components/actionFilters/constants';
57
import {
68
AGE_COMPARISON_CHOICES,
7-
type AgeComparison,
9+
TimeUnit,
810
} from 'sentry/views/automations/components/actionFilters/constants';
911
import {useDataConditionNodeContext} from 'sentry/views/automations/components/dataConditionNodes';
1012

11-
enum TimeUnit {
12-
MINUTES = 'minute',
13-
HOURS = 'hour',
14-
DAYS = 'day',
15-
WEEKS = 'week',
16-
}
17-
1813
const TIME_CHOICES = [
1914
{value: TimeUnit.MINUTES, label: 'minute(s)'},
2015
{value: TimeUnit.HOURS, label: 'hour(s)'},
@@ -50,13 +45,13 @@ export function AgeComparisonNode() {
5045
function ComparisonField() {
5146
const {condition, condition_id, onUpdate} = useDataConditionNodeContext();
5247
return (
53-
<AutomationBuilderSelectField
48+
<AutomationBuilderSelect
5449
name={`${condition_id}.comparison.comparison_type`}
5550
value={condition.comparison.comparison_type}
5651
options={AGE_COMPARISON_CHOICES}
57-
onChange={(value: AgeComparison) => {
52+
onChange={(option: SelectValue<AgeComparison>) => {
5853
onUpdate({
59-
comparison_type: value,
54+
comparison_type: option.value,
6055
});
6156
}}
6257
/>
@@ -66,30 +61,31 @@ function ComparisonField() {
6661
function ValueField() {
6762
const {condition, condition_id, onUpdate} = useDataConditionNodeContext();
6863
return (
69-
<AutomationBuilderNumberField
64+
<AutomationBuilderNumberInput
7065
name={`${condition_id}.comparison.value`}
7166
value={condition.comparison.value}
7267
min={0}
7368
step={1}
74-
onChange={(value: string) => {
69+
onChange={(value: number) => {
7570
onUpdate({
76-
value: parseInt(value, 10),
71+
value,
7772
});
7873
}}
74+
placeholder={'10'}
7975
/>
8076
);
8177
}
8278

8379
function TimeField() {
8480
const {condition, condition_id, onUpdate} = useDataConditionNodeContext();
8581
return (
86-
<AutomationBuilderSelectField
82+
<AutomationBuilderSelect
8783
name={`${condition_id}.comparison.time`}
8884
value={condition.comparison.time}
8985
options={TIME_CHOICES}
90-
onChange={(value: string) => {
86+
onChange={(option: SelectValue<TimeUnit>) => {
9187
onUpdate({
92-
time: value,
88+
time: option.value,
9389
});
9490
}}
9591
/>

static/app/views/automations/components/actionFilters/assignedTo.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@ import styled from '@emotion/styled';
22

33
import SelectMembers from 'sentry/components/selectMembers';
44
import TeamSelector from 'sentry/components/teamSelector';
5-
import AutomationBuilderSelectField, {
5+
import {
6+
AutomationBuilderSelect,
67
selectControlStyles,
7-
} from 'sentry/components/workflowEngine/form/automationBuilderSelectField';
8+
} from 'sentry/components/workflowEngine/form/automationBuilderSelect';
89
import {t, tct} from 'sentry/locale';
10+
import type {SelectValue} from 'sentry/types/core';
911
import type {DataCondition} from 'sentry/types/workflowEngine/dataConditions';
1012
import useOrganization from 'sentry/utils/useOrganization';
1113
import {useTeamsById} from 'sentry/utils/useTeamsById';
1214
import useUserFromId from 'sentry/utils/useUserFromId';
15+
import {TargetType} from 'sentry/views/automations/components/actionFilters/constants';
1316
import {useDataConditionNodeContext} from 'sentry/views/automations/components/dataConditionNodes';
1417

15-
enum TargetType {
16-
UNASSIGNED = 'Unassigned',
17-
TEAM = 'Team',
18-
MEMBER = 'Member',
19-
}
20-
2118
const TARGET_TYPE_CHOICES = [
2219
{value: TargetType.UNASSIGNED, label: 'No One'},
2320
{value: TargetType.TEAM, label: 'Team'},
@@ -57,11 +54,13 @@ export function AssignedToNode() {
5754
function TargetTypeField() {
5855
const {condition, condition_id, onUpdate} = useDataConditionNodeContext();
5956
return (
60-
<AutomationBuilderSelectField
57+
<AutomationBuilderSelect
6158
name={`${condition_id}.comparison.targetType`}
6259
value={condition.comparison.targetType}
6360
options={TARGET_TYPE_CHOICES}
64-
onChange={(value: string) => onUpdate({targetType: value, targetIdentifier: ''})}
61+
onChange={(option: SelectValue<string>) =>
62+
onUpdate({targetType: option.value, targetIdentifier: ''})
63+
}
6564
/>
6665
);
6766
}
@@ -76,7 +75,7 @@ function IdentifierField() {
7675
<TeamSelector
7776
name={`${condition_id}.data.targetIdentifier`}
7877
value={condition.comparison.targetIdentifier}
79-
onChange={(value: any) => onUpdate({targetIdentifier: value})}
78+
onChange={(value: SelectValue<string>) => onUpdate({targetIdentifier: value})}
8079
useId
8180
styles={selectControlStyles}
8281
/>

static/app/views/automations/components/actionFilters/comparisonBranches.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import AutomationBuilderNumberField from 'sentry/components/workflowEngine/form/automationBuilderNumberField';
2-
import AutomationBuilderSelectField from 'sentry/components/workflowEngine/form/automationBuilderSelectField';
1+
import {AutomationBuilderNumberInput} from 'sentry/components/workflowEngine/form/automationBuilderNumberInput';
2+
import {AutomationBuilderSelect} from 'sentry/components/workflowEngine/form/automationBuilderSelect';
33
import {tct} from 'sentry/locale';
4+
import type {SelectValue} from 'sentry/types/core';
45
import {
56
COMPARISON_INTERVAL_CHOICES,
67
INTERVAL_CHOICES,
@@ -25,30 +26,31 @@ export function PercentBranch() {
2526
function ValueField() {
2627
const {condition, condition_id, onUpdate} = useDataConditionNodeContext();
2728
return (
28-
<AutomationBuilderNumberField
29+
<AutomationBuilderNumberInput
2930
name={`${condition_id}.comparison.value`}
3031
value={condition.comparison.value}
3132
min={1}
3233
step={1}
33-
onChange={(value: string) => {
34+
onChange={(value: number) => {
3435
onUpdate({
3536
value,
3637
});
3738
}}
39+
placeholder="100"
3840
/>
3941
);
4042
}
4143

4244
function IntervalField() {
4345
const {condition, condition_id, onUpdate} = useDataConditionNodeContext();
4446
return (
45-
<AutomationBuilderSelectField
47+
<AutomationBuilderSelect
4648
name={`${condition_id}.comparison.interval`}
4749
value={condition.comparison.interval}
4850
options={INTERVAL_CHOICES}
49-
onChange={(value: string) => {
51+
onChange={(option: SelectValue<string>) => {
5052
onUpdate({
51-
interval: value,
53+
interval: option.value,
5254
});
5355
}}
5456
/>
@@ -58,13 +60,13 @@ function IntervalField() {
5860
function ComparisonIntervalField() {
5961
const {condition, condition_id, onUpdate} = useDataConditionNodeContext();
6062
return (
61-
<AutomationBuilderSelectField
63+
<AutomationBuilderSelect
6264
name={`${condition_id}.comparison.comparison_interval`}
6365
value={condition.comparison.comparison_interval}
6466
options={COMPARISON_INTERVAL_CHOICES}
65-
onChange={(value: string) => {
67+
onChange={(option: SelectValue<string>) => {
6668
onUpdate({
67-
comparison_interval: value,
69+
comparison_interval: option.value,
6870
});
6971
}}
7072
/>

static/app/views/automations/components/actionFilters/constants.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ export enum AgeComparison {
3737
NEWER = 'newer',
3838
}
3939

40+
export enum TimeUnit {
41+
MINUTES = 'minute',
42+
HOURS = 'hour',
43+
DAYS = 'day',
44+
WEEKS = 'week',
45+
}
46+
47+
export enum TargetType {
48+
UNASSIGNED = 'Unassigned',
49+
TEAM = 'Team',
50+
MEMBER = 'Member',
51+
}
52+
4053
export enum ModelAge {
4154
OLDEST = 'oldest',
4255
NEWEST = 'newest',
@@ -80,7 +93,7 @@ export enum Level {
8093
SAMPLING = 0,
8194
}
8295

83-
enum Interval {
96+
export enum Interval {
8497
ONE_MINUTE = '1m',
8598
FIVE_MINUTES = '5m',
8699
FIFTEEN_MINUTES = '15m',

0 commit comments

Comments
 (0)