Skip to content

Commit 5f6826e

Browse files
authored
disable monitorType on edit & update hover states & modify serializer… (#69541)
… to not allow update ![Screenshot 2024-04-23 at 2 18 28 PM](https://github.com/getsentry/sentry/assets/6186377/7e1d5f72-be0c-4889-91e9-5bf882e1691a)
1 parent fda1a56 commit 5f6826e

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

src/sentry/incidents/serializers/alert_rule.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,12 @@ def update(self, instance, validated_data):
503503
triggers = validated_data.pop("triggers")
504504
if "id" in validated_data:
505505
validated_data.pop("id")
506+
if "monitor_type" in validated_data:
507+
"""
508+
TODO: enable monitor type editing
509+
requires creating/disabling activations accordingly
510+
"""
511+
validated_data.pop("monitor_type")
506512
with transaction.atomic(router.db_for_write(AlertRule)):
507513
alert_rule = update_alert_rule(
508514
instance,

static/app/views/alerts/rules/metric/ruleConditionsForm.tsx

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type Props = {
6868
comparisonType: AlertRuleComparisonType;
6969
dataset: Dataset;
7070
disabled: boolean;
71+
isEditing: boolean;
7172
onComparisonDeltaChange: (value: number) => void;
7273
onFilterSearch: (query: string, isQueryValid) => void;
7374
onMonitorTypeSelect: (activatedAlertFields: {
@@ -402,12 +403,14 @@ class RuleConditionsForm extends PureComponent<Props, State> {
402403
}
403404

404405
renderMonitorTypeSelect() {
406+
// TODO: disable select on edit
405407
const {
406-
onMonitorTypeSelect,
407-
monitorType,
408408
activationCondition,
409-
timeWindow,
409+
isEditing,
410+
monitorType,
411+
onMonitorTypeSelect,
410412
onTimeWindowChange,
413+
timeWindow,
411414
} = this.props;
412415

413416
return (
@@ -420,25 +423,32 @@ class RuleConditionsForm extends PureComponent<Props, State> {
420423
<FormRow>
421424
<MonitorSelect>
422425
<MonitorCard
426+
disabled={isEditing}
423427
position="left"
424428
isSelected={monitorType === MonitorType.CONTINUOUS}
425429
onClick={() =>
426-
onMonitorTypeSelect({
427-
monitorType: MonitorType.CONTINUOUS,
428-
activationCondition,
429-
})
430+
isEditing
431+
? null
432+
: onMonitorTypeSelect({
433+
monitorType: MonitorType.CONTINUOUS,
434+
activationCondition,
435+
})
430436
}
431437
>
432438
<strong>{t('Continuous')}</strong>
433439
<div>{t('Continuously monitor trends for the metrics outlined below')}</div>
434440
</MonitorCard>
435441
<MonitorCard
442+
disabled={isEditing}
436443
position="right"
437444
isSelected={monitorType === MonitorType.ACTIVATED}
438445
onClick={() =>
439-
onMonitorTypeSelect({
440-
monitorType: MonitorType.ACTIVATED,
441-
})
446+
isEditing
447+
? null
448+
: onMonitorTypeSelect({
449+
monitorType: MonitorType.ACTIVATED,
450+
activationCondition,
451+
})
442452
}
443453
>
444454
<strong>Conditional</strong>
@@ -448,6 +458,7 @@ class RuleConditionsForm extends PureComponent<Props, State> {
448458
<SelectControl
449459
name="activationCondition"
450460
styles={this.selectControlStyles}
461+
disabled={isEditing}
451462
options={[
452463
{
453464
value: ActivationConditionType.RELEASE_CREATION,
@@ -780,21 +791,28 @@ type MonitorCardProps = {
780791
* Adds hover and focus states to the card
781792
*/
782793
position: 'left' | 'right';
794+
disabled?: boolean;
783795
};
784796

785797
const MonitorCard = styled('div')<MonitorCardProps>`
786798
padding: ${space(1)};
787799
display: flex;
788800
flex-grow: 1;
789801
flex-direction: column;
790-
cursor: pointer;
802+
cursor: ${p => (p.disabled || p.isSelected ? 'default' : 'pointer')};
791803
justify-content: center;
804+
background-color: ${p =>
805+
p.disabled && !p.isSelected ? p.theme.backgroundSecondary : p.theme.background};
792806
793807
&:focus,
794808
&:hover {
795-
outline: 1px solid ${p => p.theme.purple200};
796-
background-color: ${p => p.theme.backgroundSecondary};
797-
margin: 0;
809+
${p =>
810+
p.disabled || p.isSelected
811+
? ''
812+
: `
813+
outline: 1px solid ${p.theme.purple200};
814+
background-color: ${p.theme.backgroundSecondary};
815+
`}
798816
}
799817
800818
border-top-left-radius: ${p => (p.position === 'left' ? p.theme.borderRadius : 0)};

static/app/views/alerts/rules/metric/ruleForm.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import type {
3232
Organization,
3333
Project,
3434
} from 'sentry/types';
35-
import {type ActivationConditionType, MonitorType} from 'sentry/types/alerts';
35+
import {ActivationConditionType, MonitorType} from 'sentry/types/alerts';
3636
import {defined} from 'sentry/utils';
3737
import {metric, trackAnalytics} from 'sentry/utils/analytics';
3838
import type EventView from 'sentry/utils/discover/eventView';
@@ -237,7 +237,8 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
237237
monitorType: hasActivatedAlerts
238238
? rule.monitorType || MonitorType.CONTINUOUS
239239
: undefined,
240-
activationCondition: rule.activationCondition,
240+
activationCondition:
241+
rule.activationCondition || ActivationConditionType.RELEASE_CREATION,
241242
};
242243
}
243244

@@ -1183,6 +1184,7 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
11831184
monitorType={monitorType}
11841185
activationCondition={activationCondition}
11851186
onMonitorTypeSelect={this.handleMonitorTypeSelect}
1187+
isEditing={Boolean(ruleId)}
11861188
/>
11871189
<AlertListItem>{t('Set thresholds')}</AlertListItem>
11881190
{thresholdTypeForm(formDisabled)}

tests/sentry/incidents/endpoints/test_organization_alert_rule_details.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def test_monitor_type_with_condition(self):
391391
assert resp.data == serialize(alert_rule)
392392

393393
# TODO: determine how to convert activated alert into continuous alert and vice versa (see logic.py)
394+
# requires creating/disabling activations accordingly
394395
# assert resp.data["monitorType"] == AlertRuleMonitorType.ACTIVATED.value
395396
# assert (
396397
# resp.data["activationCondition"]

0 commit comments

Comments
 (0)