Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type {Color} from 'app/utils/theme';

import {transactionSummaryRouteWithQuery} from '../../performance/transactionSummary/utils';

import {groupByTrend} from './utils';

type TeamMiseryProps = {
organization: Organization;
location: Location;
Expand All @@ -31,7 +33,7 @@ type TeamMiseryProps = {
};

/** The number of elements to display before collapsing */
const COLLAPSE_COUNT = 8;
const COLLAPSE_COUNT = 5;

function TeamMisery({
organization,
Expand Down Expand Up @@ -69,10 +71,7 @@ function TeamMisery({
.filter(x => x.trend !== null)
.sort((a, b) => Math.abs(b.trend) - Math.abs(a.trend));

const worseItems = sortedTableData.filter(x => Math.round(x.trend) < 0);
const betterItems = sortedTableData.filter(x => Math.round(x.trend) > 0);
const zeroItems = sortedTableData.filter(x => Math.round(x.trend) === 0);
const groupedData = [...worseItems, ...betterItems, ...zeroItems];
const groupedData = groupByTrend(sortedTableData);

return (
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import space from 'app/styles/space';
import {Organization, Project} from 'app/types';
import {Color, Theme} from 'app/utils/theme';

import {barAxisLabel, convertDaySeriesToWeeks} from './utils';
import {barAxisLabel, convertDaySeriesToWeeks, groupByTrend} from './utils';

type Props = AsyncComponent['props'] & {
theme: Theme;
Expand Down Expand Up @@ -172,6 +172,12 @@ class TeamReleases extends AsyncComponent<Props, State> {
const {projects, period, theme} = this.props;
const {periodReleases} = this.state;

const sortedProjects = projects
.map(project => ({project, trend: this.getTrend(Number(project.id)) ?? 0}))
.sort((a, b) => Math.abs(b.trend) - Math.abs(a.trend));

const groupedProjects = groupByTrend(sortedProjects);

const data = Object.entries(periodReleases?.release_counts ?? {}).map(
([bucket, count]) => ({
value: Math.ceil(count),
Expand Down Expand Up @@ -209,6 +215,9 @@ class TeamReleases extends AsyncComponent<Props, State> {
lineStyle: {color: theme.gray200, type: 'dashed', width: 1},
// @ts-expect-error yAxis type not correct
data: [{yAxis: totalPeriodAverage}],
label: {
show: false,
},
}),
},
]}
Expand Down Expand Up @@ -247,7 +256,7 @@ class TeamReleases extends AsyncComponent<Props, State> {
<RightAligned key="diff">{t('Difference')}</RightAligned>,
]}
>
{projects.map(project => (
{groupedProjects.map(({project}) => (
<Fragment key={project.id}>
<ProjectBadgeContainer>
<ProjectBadge avatarSize={18} project={project} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {getCrashFreeRate} from 'app/utils/sessions';
import {Color} from 'app/utils/theme';
import {displayCrashFreePercent} from 'app/views/releases/utils';

import {groupByTrend} from './utils';

type Props = AsyncComponent['props'] & {
organization: Organization;
projects: Project[];
Expand Down Expand Up @@ -171,6 +173,12 @@ class TeamStability extends AsyncComponent<Props, State> {
renderBody() {
const {projects, period} = this.props;

const sortedProjects = projects
.map(project => ({project, trend: this.getTrend(Number(project.id)) ?? 0}))
.sort((a, b) => Math.abs(b.trend) - Math.abs(a.trend));

const groupedProjects = groupByTrend(sortedProjects);

return (
<StyledPanelTable
isEmpty={projects.length === 0}
Expand All @@ -181,7 +189,7 @@ class TeamStability extends AsyncComponent<Props, State> {
<RightAligned key="diff">{t('Difference')}</RightAligned>,
]}
>
{projects.map(project => (
{groupedProjects.map(({project}) => (
<Fragment key={project.id}>
<ProjectBadgeContainer>
<ProjectBadge avatarSize={18} project={project} />
Expand Down
10 changes: 10 additions & 0 deletions static/app/views/organizationStats/teamInsights/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export function convertDayValueObjectToSeries(
}));
}

/**
* Takes a sorted array of trend items and groups them by worst/better/no chagne
*/
export function groupByTrend<T extends {trend: number}>(data: T[]): T[] {
const worseItems = data.filter(x => Math.round(x.trend) < 0);
const betterItems = data.filter(x => Math.round(x.trend) > 0);
const zeroItems = data.filter(x => Math.round(x.trend) === 0);
return [...worseItems, ...betterItems, ...zeroItems];
}

export const barAxisLabel = (
dataEntries: number
): React.ComponentProps<typeof BaseChart>['xAxis'] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ describe('TeamMisery', () => {
expect(periodMisery).toHaveBeenCalledTimes(1);

// Should have 8 items, the rest are collapsed.
expect(screen.getAllByText(project.slug)).toHaveLength(8);
expect(screen.getAllByText(project.slug)).toHaveLength(5);

expect(screen.getByText('10% better')).toBeInTheDocument();
expect(screen.getByText('25% worse')).toBeInTheDocument();
expect(screen.getAllByText('0% change')).toHaveLength(6);
expect(screen.getAllByText('0% change')).toHaveLength(3);

expect(screen.getByText('More')).toBeInTheDocument();
fireEvent.click(screen.getByText('More'));
Expand Down