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

ref(groupChart): Refactor GroupChart for readability, typing, and scoping #70966

Merged
merged 1 commit into from
May 16, 2024

Conversation

MichaelSun48
Copy link
Member

@MichaelSun48 MichaelSun48 commented May 15, 2024

This PR refactors the <GroupChart> component to have better typing, and to be more readable. It also removes the group prop, since the scope of the entire group object is beyond what the component needs. Specific details are included the comments.

No design or visual changes should be included in this PR. If you browse the preview and see any visual changes to the events graph, please comment about it and I will rectify.

High level changes:

  • Updates all instances of groupChart to reflect refactor
  • Replaces group and statsPeriod props in favor of stats and secondary stats data itself
  • Removes all uses of let in groupChart
  • Better typing

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 15, 2024
Comment on lines -22 to 26
data: Group;
statsPeriod: string;
stats: ReadonlyArray<TimeseriesValue>;
height?: number;
secondaryStats?: ReadonlyArray<TimeseriesValue>;
showMarkLine?: boolean;
showSecondaryPoints?: boolean;
Copy link
Member Author

Choose a reason for hiding this comment

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

The statsPeriod props was only being used to extract the correct series from the group prop. The GroupChart component shouldn't care about the group itself or which time period is being displayed, it should only care about and receive the actual series data itself, hence why the stats and secondaryStats props replace this.

This delegates the logic of extracting the series from the group itself to the parent component of groupChart

Comment on lines -36 to -43
const stats: ReadonlyArray<TimeseriesValue> = statsPeriod
? data.filtered
? data.filtered.stats?.[statsPeriod]
: data.stats?.[statsPeriod]
: EMPTY_STATS;

const secondaryStats: TimeseriesValue[] | null =
statsPeriod && data.filtered ? data.stats[statsPeriod] : null;
Copy link
Member Author

Choose a reason for hiding this comment

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

This was previously the logic to extract the stats from the group. As mentioned in the above comment, this is now delegated to the parent to limit the scope of this component.

@@ -12,6 +12,7 @@ import ShortId from 'sentry/components/shortId';
import GroupChart from 'sentry/components/stream/groupChart';
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe this component is actually being used anywhere, but out of an abundance of caution, I have still refactored this instance of groupChart

Copy link
Member

Choose a reason for hiding this comment

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

Hmm it looks like there must have been a recent change that redirects from the discover event details to the issue details page, but I don't know where that redirect is happening or why it was added. Probably why you can't find this anywhere.

Comment on lines -55 to -63
const marklinePoints: number[] = [];

for (let i = 0; i < stats.length; i++) {
const point = stats[i];
if (point[1] > max) {
max = point[1];
}
marklinePoints.push(point[1]);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what the purpose of this marklinePoints array was, but it was not being used anywhere.

Comment on lines +442 to +448
const groupStats: ReadonlyArray<TimeseriesValue> = group.filtered
? group.filtered.stats?.[statsPeriod]
: group.stats?.[statsPeriod];

const groupSecondaryStats: ReadonlyArray<TimeseriesValue> = group.filtered
? group.stats?.[statsPeriod]
: [];
Copy link
Member Author

Choose a reason for hiding this comment

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

This logic mirrors lines 36-43 in the old groupChart.tsx, and is one example of extracting the stats data in the parent component rather than in the groupChart component

@MichaelSun48 MichaelSun48 marked this pull request as ready for review May 15, 2024 18:48
@MichaelSun48 MichaelSun48 requested review from a team as code owners May 15, 2024 18:48
Copy link
Member

@malwilley malwilley left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for going back and refactoring

@MichaelSun48 MichaelSun48 merged commit f8c6f12 into master May 16, 2024
45 of 46 checks passed
@MichaelSun48 MichaelSun48 deleted the msun/GroupChartStyleRefactor branch May 16, 2024 17:01
cmanallen pushed a commit that referenced this pull request May 21, 2024
…ping (#70966)

This PR refactors the `<GroupChart>` component to have better typing,
and to be more readable. It also removes the `group` prop, since the
scope of the entire `group` object is beyond what the component needs.
Specific details are included the comments.

**No design or visual changes should be included in this PR. If you
browse the preview and see any visual changes to the events graph,
please comment about it and I will rectify.**

High level changes:

- Updates all instances of `groupChart` to reflect refactor
- Replaces `group` and `statsPeriod` props in favor of stats and
secondary stats data itself
- Removes all uses of `let` in groupChart
- Better typing
@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 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

2 participants