Skip to content
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

feat: Add Activated Alert Rules to alert rule index #69124

Merged
merged 10 commits into from
Apr 18, 2024

Conversation

nhsiehgit
Copy link
Member

@nhsiehgit nhsiehgit commented Apr 17, 2024

Duplicates the AlertRuleRow component to enable Activated Alert Rule rows.

Screenshot 2024-04-17 at 11 24 44 AM

Moves Alert Badge next to the rule status
Introduces a new "active state" to determine whether we are "ready to monitor" or "actively monitoring" states
cleans up the status logic

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 17, 2024
Copy link

codecov bot commented Apr 17, 2024

Bundle Report

Changes will increase total bundle size by 10.23kB ⬆️

Bundle name Size Change
app-webpack-bundle-array-push 26.24MB 10.23kB ⬆️

@nhsiehgit
Copy link
Member Author

Changed the icons

Screenshot 2024-04-17 at 11 30 38 AM

Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comments mostly focusing on the net new components.. i really recommend adding tests for the net new components as well. Maybe these could be built in a way that we could utilize the code with upcoming refactors as well?

);
}

function renderAlertRuleStatus(): React.ReactNode {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend decomposing this quite a bit.. you could really simplify this by pulling the alert status out as a different component.. then applying SOLID programming principles split this into it's most basic pieces.. each alert threshold state. Then have the AlertRuleStatus simply look at the state and decide which component to render. That would simplify the UI components, decouple your logic from presentation, and simplify testing.

{!projectsLoaded && (
<LoadingIndicator
mini
style={{height: '24px', margin: 0, marginRight: 11}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make this a styled component, looks like the LoadingIndicator will take a class name and apply it correctly.

Comment on lines 261 to 263
<AlertName>
<div>{rule.name}</div>
</AlertName>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner div isn't needed here

Suggested change
<AlertName>
<div>{rule.name}</div>
</AlertName>
<AlertName>{rule.name}</AlertName>

const MenuItemWrapper = styled('div')`
display: flex;
align-items: center;
font-size: 13px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than hard coding it, we should use something from the theme.. there's fontSizeSmall which is 12px and feels like it maps to the intent of this a little more. If you have to keep it 13px, there's codeFontSize which also maps, but doesn't make as much sense from the naming perspective.

Suggested change
font-size: 13px;
font-size: ${p.theme.codeFontSize};

`;

const Label = styled(TextOverflow)`
margin-left: 6px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
margin-left: 6px;
margin-left: $(space(0.75)};

Comment on lines 437 to 438
width: 24px;
height: 24px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
width: 24px;
height: 24px;
width: ${p.theme.iconSizes.lg};
height: ${p.theme.iconSizes.lg};

Comment on lines +354 to +366
const FlexCenter = styled('div')`
display: flex;
align-items: center;
`;

const IssueAlertStatusWrapper = styled('div')`
display: flex;
align-items: center;
gap: ${space(1)};
line-height: 2;
`;

const AlertNameWrapper = styled('div')<{isIssueAlert?: boolean}>`
${p => p.theme.overflowEllipsis}
display: flex;
align-items: center;
gap: ${space(2)};
${p => p.isIssueAlert && `padding: ${space(3)} ${space(2)}; line-height: 2.4;`}
`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to use static/app/components/profiling/flex.tsx and FlexContainer where you can here. I think you can cover most of the flex cases you have defined with that component. By reusing the component, it would likely cut down pretty substantially on the css payload of this component.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔
hmmm since most of this is just copy/pasta from the sister rules.tsx, i'm less inclined to rewrite the entire component

I can leave a note to come back to this though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good - this pattern also already exists in the code so nbd.

[rule]
);

function renderLatestActivation(): React.ReactNode {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: recommend decomposing each of the render calls. If you're accessing things like the rule it'd be extra cool to use react-query to avoid prop drilling too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm how does react-query addres prop drilling?
Or did you mean context?

for now i think i'll keep these patterns to match rules.tsx 😅
I'll create a follow up ticket to clean both of these up though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react-query uses context to store api data for you. (it also handles automatic updates and syncing data across all uses of the "store").

for example, if you wanted to fetch a specific rule you could do useRule(ruleId) -- then that hook uses the api react-query hook to fetch the data (which updates the value in the store for rule etc).


If you haven't used it before.. it's kinda a mind meld and we should def wait until later to update. i'm planning on using it for the API requests with project settings pages, so we could also take a look at it when that comes up.

type: CombinedAlertType.METRIC;
latestIncident?: Incident | null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove latestIncident? This property is returned when passing the latestIncident expand parameter https://github.com/getsentry/sentry/blob/master/static/app/views/alerts/list/rules/alertRulesList.tsx#L49 I assume the only reason this passes is because IssueAlert has latestIncident too which is probably not correct

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see its available on MetricRule

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm that's probably wrong too lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - no it's because the MetricRule that this is extending already includes the latestIncident

Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can, i'd try to add some tests for activatedRuleRow.tsx since that's a net new component. if possible, i think decomposing that class would be good follow up work.

[rule]
);

function renderLatestActivation(): React.ReactNode {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react-query uses context to store api data for you. (it also handles automatic updates and syncing data across all uses of the "store").

for example, if you wanted to fetch a specific rule you could do useRule(ruleId) -- then that hook uses the api react-query hook to fetch the data (which updates the value in the store for rule etc).


If you haven't used it before.. it's kinda a mind meld and we should def wait until later to update. i'm planning on using it for the API requests with project settings pages, so we could also take a look at it when that comes up.

Comment on lines +354 to +366
const FlexCenter = styled('div')`
display: flex;
align-items: center;
`;

const IssueAlertStatusWrapper = styled('div')`
display: flex;
align-items: center;
gap: ${space(1)};
line-height: 2;
`;

const AlertNameWrapper = styled('div')<{isIssueAlert?: boolean}>`
${p => p.theme.overflowEllipsis}
display: flex;
align-items: center;
gap: ${space(2)};
${p => p.isIssueAlert && `padding: ${space(3)} ${space(2)}; line-height: 2.4;`}
`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good - this pattern also already exists in the code so nbd.

@nhsiehgit nhsiehgit merged commit e4303d3 into master Apr 18, 2024
41 checks passed
@nhsiehgit nhsiehgit deleted the activated_alert_rule_index branch April 18, 2024 15:28
@github-actions github-actions bot locked and limited conversation to collaborators May 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants