Skip to content

Commit 0721536

Browse files
gggritsoclaude
andcommitted
ref(project-detail): Use relative period params for previous period queries
Replace absolute start/end date computation via parseStatsPeriod with relative statsPeriodStart/statsPeriodEnd params in the velocity and ANR score cards, matching the pattern already used by the stability card. This also removes a stray console.log from the velocity card and an unused parseStatsPeriod import from the apdex card. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8156cbe commit 0721536

File tree

5 files changed

+40
-44
lines changed

5 files changed

+40
-44
lines changed

static/app/views/projectDetail/projectScoreCards/projectAnrScoreCard.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('ProjectDetail > ProjectAnr', () => {
4646

4747
endpointMockPreviousPeriod = MockApiClient.addMockResponse({
4848
url: `/organizations/${organization.slug}/sessions/`,
49-
match: [MockApiClient.matchQuery({start: '2017-10-03T02:41:20.000'})], // setup mocks a constant current date, so this works
49+
match: [MockApiClient.matchQuery({statsPeriodStart: '14d'})],
5050
body: {
5151
groups: [
5252
{
@@ -96,15 +96,15 @@ describe('ProjectDetail > ProjectAnr', () => {
9696
`/organizations/${organization.slug}/sessions/`,
9797
expect.objectContaining({
9898
query: {
99-
end: '2017-10-10T02:41:20.000',
10099
environment: [],
101100
field: ['anr_rate()'],
102101
includeSeries: '0',
103102
includeTotals: '1',
104103
interval: '1h',
105104
project: [1],
106105
query: 'release:abc',
107-
start: '2017-10-03T02:41:20.000',
106+
statsPeriodStart: '14d',
107+
statsPeriodEnd: '7d',
108108
},
109109
})
110110
);

static/app/views/projectDetail/projectScoreCards/projectAnrScoreCard.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {doSessionsRequest} from 'sentry/actionCreators/sessions';
88
import {shouldFetchPreviousPeriod} from 'sentry/components/charts/utils';
99
import {URL_PARAM} from 'sentry/components/pageFilters/constants';
1010
import {normalizeDateTimeParams} from 'sentry/components/pageFilters/parse';
11-
import {parseStatsPeriod} from 'sentry/components/timeRangeSelector/utils';
11+
import {DEFAULT_STATS_PERIOD} from 'sentry/constants';
1212
import {t} from 'sentry/locale';
1313
import type {PageFilters} from 'sentry/types/core';
1414
import type {Organization, SessionApiResponse} from 'sentry/types/organization';
@@ -45,6 +45,11 @@ export function ProjectAnrScoreCard({
4545
const {environments, projects, datetime} = selection;
4646
const {start, end, period} = datetime;
4747

48+
const doubledPeriod = getPeriod(
49+
{period, start: undefined, end: undefined},
50+
{shouldDoublePeriod: true}
51+
).statsPeriod;
52+
4853
const api = useApi();
4954

5055
const [sessionsData, setSessionsData] = useState<SessionApiResponse | null>(null);
@@ -96,20 +101,10 @@ export function ProjectAnrScoreCard({
96101
includeSeries: false,
97102
};
98103

99-
const {start: previousStart} = parseStatsPeriod(
100-
getPeriod({period, start: undefined, end: undefined}, {shouldDoublePeriod: true})
101-
.statsPeriod!
102-
);
103-
104-
const {start: previousEnd} = parseStatsPeriod(
105-
getPeriod({period, start: undefined, end: undefined}, {shouldDoublePeriod: false})
106-
.statsPeriod!
107-
);
108-
109104
doSessionsRequest(api, {
110105
...requestData,
111-
start: previousStart,
112-
end: previousEnd,
106+
statsPeriodStart: doubledPeriod,
107+
statsPeriodEnd: period ?? DEFAULT_STATS_PERIOD,
113108
}).then(([response]) => {
114109
if (unmounted) {
115110
return;
@@ -123,7 +118,17 @@ export function ProjectAnrScoreCard({
123118
return () => {
124119
unmounted = true;
125120
};
126-
}, [start, end, period, api, organization.slug, environments, projects, query]);
121+
}, [
122+
start,
123+
end,
124+
period,
125+
doubledPeriod,
126+
api,
127+
organization.slug,
128+
environments,
129+
projects,
130+
query,
131+
]);
127132

128133
const value = sessionsData?.groups?.[0]?.totals['anr_rate()'] ?? null;
129134
const previousValue = previousSessionData?.groups?.[0]?.totals['anr_rate()'] ?? null;

static/app/views/projectDetail/projectScoreCards/projectApdexScoreCard.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Container} from '@sentry/scraps/layout';
33

44
import {shouldFetchPreviousPeriod} from 'sentry/components/charts/utils';
55
import {normalizeDateTimeParams} from 'sentry/components/pageFilters/parse';
6-
import {parseStatsPeriod} from 'sentry/components/timeRangeSelector/utils';
6+
import {DEFAULT_STATS_PERIOD} from 'sentry/constants';
77
import {t} from 'sentry/locale';
88
import type {PageFilters} from 'sentry/types/core';
99
import type {Organization} from 'sentry/types/organization';
@@ -35,18 +35,13 @@ const useApdex = (props: Props) => {
3535
isProjectStabilized &&
3636
hasTransactions
3737
);
38-
const {projects, environments: environments, datetime} = selection;
38+
const {projects, environments, datetime} = selection;
3939
const {period} = datetime;
4040

41-
const {start: previousStart} = parseStatsPeriod(
42-
getPeriod({period, start: undefined, end: undefined}, {shouldDoublePeriod: true})
43-
.statsPeriod!
44-
);
45-
46-
const {start: previousEnd} = parseStatsPeriod(
47-
getPeriod({period, start: undefined, end: undefined}, {shouldDoublePeriod: false})
48-
.statsPeriod!
49-
);
41+
const doubledPeriod = getPeriod(
42+
{period, start: undefined, end: undefined},
43+
{shouldDoublePeriod: true}
44+
).statsPeriod;
5045

5146
const commonQuery = {
5247
environment: environments,
@@ -84,8 +79,8 @@ const useApdex = (props: Props) => {
8479
{
8580
query: {
8681
...commonQuery,
87-
start: previousStart,
88-
end: previousEnd,
82+
statsPeriodStart: doubledPeriod,
83+
statsPeriodEnd: period ?? DEFAULT_STATS_PERIOD,
8984
},
9085
},
9186
],

static/app/views/projectDetail/projectScoreCards/projectVelocityScoreCard.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('ProjectDetail > ProjectVelocity', () => {
2929
version: `0.0.${index + 100}`,
3030
})),
3131
status: 200,
32+
match: [MockApiClient.matchQuery({statsPeriodStart: '28d'})],
3233
});
3334

3435
const currentDataEndpointMock = MockApiClient.addMockResponse({
@@ -73,8 +74,8 @@ describe('ProjectDetail > ProjectVelocity', () => {
7374
query: {
7475
environment: [],
7576
project: 1,
76-
start: '2017-09-19T02:41:20',
77-
end: '2017-10-03T02:41:20',
77+
statsPeriodStart: '28d',
78+
statsPeriodEnd: '14d',
7879
},
7980
})
8081
);

static/app/views/projectDetail/projectScoreCards/projectVelocityScoreCard.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Container} from '@sentry/scraps/layout';
33

44
import {shouldFetchPreviousPeriod} from 'sentry/components/charts/utils';
55
import {normalizeDateTimeParams} from 'sentry/components/pageFilters/parse';
6-
import {parseStatsPeriod} from 'sentry/components/timeRangeSelector/utils';
6+
import {DEFAULT_STATS_PERIOD} from 'sentry/constants';
77
import {t} from 'sentry/locale';
88
import type {PageFilters} from 'sentry/types/core';
99
import type {Organization} from 'sentry/types/organization';
@@ -28,15 +28,10 @@ const useReleaseCount = (props: Props) => {
2828
const {projects, environments, datetime} = selection;
2929
const {period} = datetime;
3030

31-
const {start: previousStart} = parseStatsPeriod(
32-
getPeriod({period, start: undefined, end: undefined}, {shouldDoublePeriod: true})
33-
.statsPeriod!
34-
);
35-
36-
const {start: previousEnd} = parseStatsPeriod(
37-
getPeriod({period, start: undefined, end: undefined}, {shouldDoublePeriod: false})
38-
.statsPeriod!
39-
);
31+
const doubledPeriod = getPeriod(
32+
{period, start: undefined, end: undefined},
33+
{shouldDoublePeriod: true}
34+
).statsPeriod;
4035

4136
const commonQuery = {
4237
environment: environments,
@@ -73,8 +68,8 @@ const useReleaseCount = (props: Props) => {
7368
{
7469
query: {
7570
...commonQuery,
76-
start: previousStart,
77-
end: previousEnd,
71+
statsPeriodStart: doubledPeriod,
72+
statsPeriodEnd: period ?? DEFAULT_STATS_PERIOD,
7873
},
7974
},
8075
],

0 commit comments

Comments
 (0)