Skip to content
Merged
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,7 +20,6 @@ import {useQueryParamState} from 'sentry/utils/url/useQueryParamState';
import {useDebouncedValue} from 'sentry/utils/useDebouncedValue';
import useAttributeBreakdownComparison from 'sentry/views/explore/hooks/useAttributeBreakdownComparison';
import {useQueryParamsVisualizes} from 'sentry/views/explore/queryParams/context';
import {prettifyAggregation} from 'sentry/views/explore/utils';

import {Chart} from './cohortComparisonChart';
import {AttributeBreakdownsComponent} from './styles';
Expand All @@ -29,7 +28,6 @@ type SortingMethod = 'rrr';

const CHARTS_COLUMN_COUNT = 3;
const CHARTS_PER_PAGE = CHARTS_COLUMN_COUNT * 4;
const PERCENTILE_FUNCTION_PREFIXES = ['p50', 'p75', 'p90', 'p95', 'p99', 'avg'];

export function CohortComparison({
selection,
Expand Down Expand Up @@ -90,7 +88,7 @@ export function CohortComparison({
setPage(0);
}, [filteredRankedAttributes]);

const selectionHint = useMemo(() => {
const selectedRangeToDates = useMemo(() => {
if (!selection) {
return null;
}
Expand All @@ -102,31 +100,14 @@ export function CohortComparison({
startTimestamp = Math.min(startTimestamp, endTimestamp - 60_000);

const userTimezone = getUserTimezone() || moment.tz.guess();
const startDate = moment
.tz(startTimestamp, userTimezone)
.format('MMM D YYYY h:mm A z');
const endDate = moment.tz(endTimestamp, userTimezone).format('MMM D YYYY h:mm A z');

// Check if yAxis is a percentile function (only these functions should include "and is greater than or equal to")
const yAxisLower = yAxis.toLowerCase();
const isPercentileFunction = PERCENTILE_FUNCTION_PREFIXES.some(prefix =>
yAxisLower.startsWith(prefix)
);

const formattedFunction = prettifyAggregation(yAxis) ?? yAxis;
const start = moment.tz(startTimestamp, userTimezone).format('MMM D YYYY h:mm A z');
const end = moment.tz(endTimestamp, userTimezone).format('MMM D YYYY h:mm A z');

return {
selection: isPercentileFunction
? t(
`Selection is data between %s - %s and is greater than or equal to %s`,
startDate,
endDate,
formattedFunction
)
: t(`Selection is data between %s - %s`, startDate, endDate),
baseline: t('Baseline is all other spans from your query'),
start,
end,
};
}, [selection, yAxis]);
}, [selection]);

if (isError) {
return <LoadingError message={t('Failed to load attribute breakdowns')} />;
Expand All @@ -150,12 +131,18 @@ export function CohortComparison({
<AttributeBreakdownsComponent.LoadingCharts />
) : (
<Fragment>
{selectionHint && (
{selectedRangeToDates && (
<SelectionHintContainer>
<SelectionHint color={theme.chart.getColorPalette(0)?.[0]}>
{selectionHint.selection}
{t(
'Selection is data between %s - %s',
selectedRangeToDates.start,
selectedRangeToDates.end
)}
</SelectionHint>
<SelectionHint color="#A29FAA">
{t('Baseline is all other spans from your query')}
</SelectionHint>
<SelectionHint color="#A29FAA">{selectionHint.baseline}</SelectionHint>
</SelectionHintContainer>
)}
{filteredRankedAttributes.length > 0 ? (
Expand Down
Loading