-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(aci): correctly load condition sub-filters on alert edit #101972
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,48 +148,42 @@ function Branch({lastChild}: BranchProps) { | |
| function ComparisonTypeField() { | ||
| const {subfilter, subfilter_id, onUpdate} = useSubfilterContext(); | ||
|
|
||
| if (!subfilter.type) { | ||
| if ('attribute' in subfilter || 'key' in subfilter) { | ||
| return ( | ||
| <AutomationBuilderSelect | ||
| name={`${subfilter_id}.type`} | ||
| aria-label={t('Comparison type')} | ||
| value={subfilter.type ?? ''} | ||
| placeholder={t('Select value type')} | ||
| options={[ | ||
| { | ||
| label: t('Attribute'), | ||
| value: DataConditionType.EVENT_ATTRIBUTE, | ||
| }, | ||
| { | ||
| label: t('Tag'), | ||
| value: DataConditionType.TAGGED_EVENT, | ||
| }, | ||
| ]} | ||
| onChange={(option: SelectValue<DataConditionType>) => { | ||
| onUpdate({ | ||
| id: subfilter.id, | ||
| type: option.value, | ||
| match: MatchType.EQUAL, | ||
| value: '', | ||
| ...(option.value === DataConditionType.EVENT_ATTRIBUTE | ||
| ? {attribute: Attributes.MESSAGE} | ||
| : {}), | ||
| }); | ||
| }} | ||
| /> | ||
| <Fragment> | ||
| {'attribute' in subfilter ? <AttributeField /> : <KeyField />} | ||
| <MatchField /> | ||
| <ValueField /> | ||
| </Fragment> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Fragment> | ||
| {subfilter.type === DataConditionType.EVENT_ATTRIBUTE ? ( | ||
| <AttributeField /> | ||
| ) : ( | ||
| <KeyField /> | ||
| )} | ||
| <MatchField /> | ||
| <ValueField /> | ||
| </Fragment> | ||
| <AutomationBuilderSelect | ||
| name={`${subfilter_id}.type`} | ||
| aria-label={t('Comparison type')} | ||
| value={subfilter.type ?? ''} | ||
| placeholder={t('Select value type')} | ||
| options={[ | ||
| { | ||
| label: t('Attribute'), | ||
| value: DataConditionType.EVENT_ATTRIBUTE, | ||
| }, | ||
| { | ||
| label: t('Tag'), | ||
| value: DataConditionType.TAGGED_EVENT, | ||
| }, | ||
| ]} | ||
| onChange={(option: SelectValue<DataConditionType>) => { | ||
| onUpdate({ | ||
| id: subfilter.id, | ||
| match: MatchType.EQUAL, | ||
| value: '', | ||
| ...(option.value === DataConditionType.EVENT_ATTRIBUTE | ||
| ? {attribute: Attributes.MESSAGE} | ||
| : {key: undefined}), | ||
| }); | ||
| }} | ||
| /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Subfilter Type Switching Causes Property ConflictsSwitching subfilter types in Additional Locations (1)There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. incorrect, once you select a type you can't change it since the selector disappears |
||
| ); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful to define the types as
type Subfilter = AttributeSubfilter | KeySubfilterAnd then you can use a user defined type predicate to narrow the type:
This improves the readability and gives better type safety.
I'm noticing that
subfilteris typed asRecord<string, any>which we can definitely go back and improve at some point (doesn't have to be in this PR)