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 @@ -14,7 +14,7 @@ jest.mock('sentry/utils/usePageFilters');

describe('PerformanceScoreBreakdownChart', function () {
const organization = OrganizationFixture();
let eventsMock, eventsStatsMock;
let eventsStatsMock;

beforeEach(function () {
jest.mocked(useLocation).mockReturnValue({
Expand Down Expand Up @@ -43,12 +43,6 @@ describe('PerformanceScoreBreakdownChart', function () {
},
});

eventsMock = MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/events/`,
body: {
data: [],
},
});
eventsStatsMock = MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/events-stats/`,
body: {},
Expand All @@ -71,35 +65,6 @@ describe('PerformanceScoreBreakdownChart', function () {
});
render(<PerformanceScoreBreakdownChart />, {organization});
await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
expect(eventsMock).toHaveBeenCalledTimes(1);
expect(eventsMock).toHaveBeenCalledWith(
'/organizations/org-slug/events/',
expect.objectContaining({
method: 'GET',
query: expect.objectContaining({
field: [
'performance_score(measurements.score.lcp)',
'performance_score(measurements.score.fcp)',
'performance_score(measurements.score.cls)',
'performance_score(measurements.score.inp)',
'performance_score(measurements.score.ttfb)',
'avg(measurements.score.total)',
'avg(measurements.score.weight.lcp)',
'avg(measurements.score.weight.fcp)',
'avg(measurements.score.weight.cls)',
'avg(measurements.score.weight.inp)',
'avg(measurements.score.weight.ttfb)',
'count()',
'count_scores(measurements.score.total)',
'count_scores(measurements.score.lcp)',
'count_scores(measurements.score.fcp)',
'count_scores(measurements.score.cls)',
'count_scores(measurements.score.ttfb)',
'count_scores(measurements.score.inp)',
],
}),
})
);

expect(eventsStatsMock).toHaveBeenCalledWith(
'/organizations/org-slug/events-stats/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import {space} from 'sentry/styles/space';
import type {Series} from 'sentry/types/echarts';
import usePageFilters from 'sentry/utils/usePageFilters';
import {ORDER} from 'sentry/views/insights/browser/webVitals/components/charts/performanceScoreChart';
import {calculatePerformanceScoreFromStoredTableDataRow} from 'sentry/views/insights/browser/webVitals/queries/storedScoreQueries/calculatePerformanceScoreFromStored';
import {useProjectWebVitalsScoresQuery} from 'sentry/views/insights/browser/webVitals/queries/storedScoreQueries/useProjectWebVitalsScoresQuery';
import {
useProjectWebVitalsScoresTimeseriesQuery,
type WebVitalsScoreBreakdown,
} from 'sentry/views/insights/browser/webVitals/queries/storedScoreQueries/useProjectWebVitalsScoresTimeseriesQuery';
import {applyStaticWeightsToTimeseries} from 'sentry/views/insights/browser/webVitals/utils/applyStaticWeightsToTimeseries';
import type {BrowserType} from 'sentry/views/insights/browser/webVitals/utils/queryParameterDecoders/browserType';
import {PERFORMANCE_SCORE_WEIGHTS} from 'sentry/views/insights/browser/webVitals/utils/scoreThresholds';
import {useStaticWeightsSetting} from 'sentry/views/insights/browser/webVitals/utils/useStaticWeightsSetting';
import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';

type Props = {
Expand Down Expand Up @@ -54,22 +51,12 @@ export function PerformanceScoreBreakdownChart({transaction, browserTypes}: Prop

const {data: timeseriesData, isLoading: isTimeseriesLoading} =
useProjectWebVitalsScoresTimeseriesQuery({transaction, browserTypes});
const {data: projectScores, isLoading: isProjectScoresLoading} =
useProjectWebVitalsScoresQuery({transaction, browserTypes});

const projectScore = isProjectScoresLoading
? undefined
: calculatePerformanceScoreFromStoredTableDataRow(projectScores?.data?.[0]);

const period = pageFilters.selection.datetime.period;
const performanceScoreSubtext = (period && DEFAULT_RELATIVE_PERIODS[period]) ?? '';
const chartSeriesOrder = ORDER;

const shouldUseStaticWeights = useStaticWeightsSetting();

const weightedTimeseriesData = shouldUseStaticWeights
? applyStaticWeightsToTimeseries(timeseriesData)
: timeseriesData;
const weightedTimeseriesData = applyStaticWeightsToTimeseries(timeseriesData);

const weightedTimeseries = formatTimeSeriesResultsToChartData(
weightedTimeseriesData,
Expand All @@ -93,17 +80,7 @@ export function PerformanceScoreBreakdownChart({transaction, browserTypes}: Prop
);

const weightsSeries = weightedTimeseries[0].data.map(({name}) => {
const value = shouldUseStaticWeights
? PERFORMANCE_SCORE_WEIGHTS
: projectScore !== undefined
? {
lcp: projectScore.lcpWeight,
fcp: projectScore.fcpWeight,
inp: projectScore.inpWeight,
cls: projectScore.clsWeight,
ttfb: projectScore.ttfbWeight,
}
: undefined;
const value = PERFORMANCE_SCORE_WEIGHTS;
return {name, value};
});

Expand All @@ -117,7 +94,7 @@ export function PerformanceScoreBreakdownChart({transaction, browserTypes}: Prop
height={180}
data={isTimeseriesLoading ? [] : weightedTimeseries}
disableXAxis
loading={isTimeseriesLoading || isProjectScoresLoading}
loading={isTimeseriesLoading}
type={ChartType.AREA}
grid={{
left: 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {
WebVitals,
} from 'sentry/views/insights/browser/webVitals/types';
import {PERFORMANCE_SCORE_WEIGHTS} from 'sentry/views/insights/browser/webVitals/utils/scoreThresholds';
import {useStaticWeightsSetting} from 'sentry/views/insights/browser/webVitals/utils/useStaticWeightsSetting';
import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';

import {getFormattedDuration} from './webVitalMeters';
Expand Down Expand Up @@ -163,19 +162,7 @@ function PerformanceScoreRingWithTooltips({
});
}

const shouldUseStaticWeights = useStaticWeightsSetting();
const weights =
['lcpWeight', 'fcpWeight', 'inpWeight', 'clsWeight', 'ttfbWeight'].every(
key => projectScore[key] === 0
) || shouldUseStaticWeights
? PERFORMANCE_SCORE_WEIGHTS
: {
lcp: projectScore.lcpWeight,
fcp: projectScore.fcpWeight,
inp: projectScore.inpWeight,
cls: projectScore.clsWeight,
ttfb: projectScore.ttfbWeight,
};
const weights = PERFORMANCE_SCORE_WEIGHTS;

const commonWebVitalLabelProps = {
organization,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('PagePerformanceTable', function () {
});
render(<PagePerformanceTable />, {organization});
await waitFor(() => {
expect(eventsMock).toHaveBeenCalledTimes(2);
expect(eventsMock).toHaveBeenCalledTimes(1);
expect(eventsMock).toHaveBeenLastCalledWith(
'/organizations/org-slug/events/',
expect.objectContaining({
Expand Down Expand Up @@ -172,6 +172,6 @@ describe('PagePerformanceTable', function () {
expect(screen.getByRole('cell', {name: '0.18'})).toBeInTheDocument();
expect(screen.getByRole('cell', {name: '783ms'})).toBeInTheDocument();
expect(screen.getByRole('cell', {name: 'Meh 85'})).toBeInTheDocument();
expect(screen.getByRole('cell', {name: '18.25'})).toBeInTheDocument();
expect(screen.getByRole('cell', {name: '0.01'})).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ import {escapeFilterValue} from 'sentry/utils/tokenizeSearch';
import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {PerformanceBadge} from 'sentry/views/insights/browser/webVitals/components/performanceBadge';
import {useProjectWebVitalsScoresQuery} from 'sentry/views/insights/browser/webVitals/queries/storedScoreQueries/useProjectWebVitalsScoresQuery';
import {useTransactionWebVitalsScoresQuery} from 'sentry/views/insights/browser/webVitals/queries/storedScoreQueries/useTransactionWebVitalsScoresQuery';
import {MODULE_DOC_LINK} from 'sentry/views/insights/browser/webVitals/settings';
import type {RowWithScoreAndOpportunity} from 'sentry/views/insights/browser/webVitals/types';
import {SORTABLE_FIELDS} from 'sentry/views/insights/browser/webVitals/types';
import decodeBrowserTypes from 'sentry/views/insights/browser/webVitals/utils/queryParameterDecoders/browserType';
import {useStaticWeightsSetting} from 'sentry/views/insights/browser/webVitals/utils/useStaticWeightsSetting';
import {useWebVitalsSort} from 'sentry/views/insights/browser/webVitals/utils/useWebVitalsSort';
import {ModuleName, SpanIndexedField} from 'sentry/views/insights/types';

Expand Down Expand Up @@ -64,16 +62,13 @@ const DEFAULT_SORT: Sort = {
export function PagePerformanceTable() {
const location = useLocation();
const organization = useOrganization();
const shouldUseStaticWeights = useStaticWeightsSetting();

const columnOrder = COLUMN_ORDER;

const query = decodeScalar(location.query.query, '');
const browserTypes = decodeBrowserTypes(location.query[SpanIndexedField.BROWSER_NAME]);

const sort = useWebVitalsSort({defaultSort: DEFAULT_SORT});
const {data: projectScoresData, isLoading: isProjectScoresLoading} =
useProjectWebVitalsScoresQuery({browserTypes});

const {
data,
Expand All @@ -88,15 +83,9 @@ export function PagePerformanceTable() {
browserTypes,
});

const scoreCount = projectScoresData?.data?.[0]?.[
'count_scores(measurements.score.total)'
] as number;

const tableData: RowWithScoreAndOpportunity[] = data.map(row => ({
...row,
opportunity:
(((row as RowWithScoreAndOpportunity).opportunity ?? 0) * 100) /
(shouldUseStaticWeights ? 1 : scoreCount), // static weight keys are already normalized
opportunity: ((row as RowWithScoreAndOpportunity).opportunity ?? 0) * 100,
}));
const getFormattedDuration = (value: number) => {
return getDuration(value, value < 1 ? 0 : 2, true);
Expand Down Expand Up @@ -310,7 +299,7 @@ export function PagePerformanceTable() {
/>
<StyledPagination
pageLinks={pageLinks}
disabled={isProjectScoresLoading || isTransactionWebVitalsQueryLoading}
disabled={isTransactionWebVitalsQueryLoading}
size="md"
/>
{/* The Pagination component disappears if pageLinks is not defined,
Expand All @@ -336,7 +325,7 @@ export function PagePerformanceTable() {
<GridContainer>
<GridEditable
aria-label={t('Pages')}
isLoading={isProjectScoresLoading || isTransactionWebVitalsQueryLoading}
isLoading={isTransactionWebVitalsQueryLoading}
columnOrder={columnOrder}
columnSortBy={[]}
data={tableData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('WebVitalsDetailPanel', function () {
'performance_score(measurements.score.cls)',
`performance_score(measurements.score.inp)`,
'performance_score(measurements.score.ttfb)',
'avg(measurements.score.total)',
'performance_score(measurements.score.total)',
'avg(measurements.score.weight.lcp)',
'avg(measurements.score.weight.fcp)',
'avg(measurements.score.weight.cls)',
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('WebVitalsDetailPanel', function () {
'p75(measurements.inp)',
'performance_score(measurements.score.lcp)',
'opportunity_score(measurements.score.lcp)',
'avg(measurements.score.total)',
'performance_score(measurements.score.total)',
'count()',
'count_scores(measurements.score.lcp)',
'count_scores(measurements.score.fcp)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import usePageFilters from 'sentry/utils/usePageFilters';
import {DEFAULT_QUERY_FILTER} from 'sentry/views/insights/browser/webVitals/settings';
import type {WebVitals} from 'sentry/views/insights/browser/webVitals/types';
import type {BrowserType} from 'sentry/views/insights/browser/webVitals/utils/queryParameterDecoders/browserType';
import {useStaticWeightsSetting} from 'sentry/views/insights/browser/webVitals/utils/useStaticWeightsSetting';
import {SpanIndexedField} from 'sentry/views/insights/types';

type Props = {
Expand All @@ -32,7 +31,6 @@ export const useProjectWebVitalsScoresQuery = ({
const organization = useOrganization();
const pageFilters = usePageFilters();
const location = useLocation();
const shouldUseStaticWeights = useStaticWeightsSetting();

const search = new MutableSearch([]);
if (transaction) {
Expand All @@ -53,9 +51,7 @@ export const useProjectWebVitalsScoresQuery = ({
'performance_score(measurements.score.cls)',
`performance_score(measurements.score.inp)`,
'performance_score(measurements.score.ttfb)',
...(shouldUseStaticWeights
? ['performance_score(measurements.score.total)']
: ['avg(measurements.score.total)']),
'performance_score(measurements.score.total)',
'avg(measurements.score.weight.lcp)',
'avg(measurements.score.weight.fcp)',
'avg(measurements.score.weight.cls)',
Expand Down Expand Up @@ -96,7 +92,6 @@ export const useProjectWebVitalsScoresQuery = ({

// Map performance_score(measurements.score.total) to avg(measurements.score.total) so we don't have to handle both keys in the UI
if (
shouldUseStaticWeights &&
result.data?.data?.[0]?.['performance_score(measurements.score.total)'] !== undefined
) {
result.data.data[0]['avg(measurements.score.total)'] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
WebVitals,
} from 'sentry/views/insights/browser/webVitals/types';
import type {BrowserType} from 'sentry/views/insights/browser/webVitals/utils/queryParameterDecoders/browserType';
import {useStaticWeightsSetting} from 'sentry/views/insights/browser/webVitals/utils/useStaticWeightsSetting';
import {useWebVitalsSort} from 'sentry/views/insights/browser/webVitals/utils/useWebVitalsSort';
import {SpanIndexedField} from 'sentry/views/insights/types';

Expand Down Expand Up @@ -43,10 +42,9 @@ export const useTransactionWebVitalsScoresQuery = ({
const organization = useOrganization();
const pageFilters = usePageFilters();
const location = useLocation();
const shouldUseStaticWeights = useStaticWeightsSetting();

const sort = useWebVitalsSort({sortName, defaultSort});
if (sort !== undefined && shouldUseStaticWeights) {
if (sort !== undefined) {
if (sort.field === 'avg(measurements.score.total)') {
sort.field = 'performance_score(measurements.score.total)';
}
Expand Down Expand Up @@ -80,9 +78,7 @@ export const useTransactionWebVitalsScoresQuery = ({
? [`performance_score(measurements.score.${webVital})`]
: []),
`opportunity_score(measurements.score.${webVital})`,
...(shouldUseStaticWeights
? ['performance_score(measurements.score.total)']
: ['avg(measurements.score.total)']),
'performance_score(measurements.score.total)',
'count()',
`count_scores(measurements.score.lcp)`,
`count_scores(measurements.score.fcp)`,
Expand Down Expand Up @@ -117,10 +113,7 @@ export const useTransactionWebVitalsScoresQuery = ({
!isLoading && data?.data.length
? data.data.map(row => {
// Map back performance score key so we don't have to handle both keys in the UI
if (
shouldUseStaticWeights &&
row['performance_score(measurements.score.total)'] !== undefined
) {
if (row['performance_score(measurements.score.total)'] !== undefined) {
row['avg(measurements.score.total)'] =
row['performance_score(measurements.score.total)'];
}
Expand Down Expand Up @@ -159,7 +152,7 @@ export const useTransactionWebVitalsScoresQuery = ({
inpScore: inpScore ?? 0,
// Map back opportunity score key so we don't have to handle both keys in the UI
opportunity: row[
shouldUseStaticWeights && webVital === 'total'
webVital === 'total'
? 'total_opportunity_score()'
: `opportunity_score(measurements.score.${webVital})`
] as number,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('PageOverview', function () {
'performance_score(measurements.score.cls)',
`performance_score(measurements.score.inp)`,
'performance_score(measurements.score.ttfb)',
'avg(measurements.score.total)',
'performance_score(measurements.score.total)',
'avg(measurements.score.weight.lcp)',
'avg(measurements.score.weight.fcp)',
'avg(measurements.score.weight.cls)',
Expand Down
Loading