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
2 changes: 2 additions & 0 deletions static/app/types/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {ProductSelectionProps} from 'sentry/components/onboarding/productSe
import type DateRange from 'sentry/components/timeRangeSelector/dateRange';
import type SelectorItems from 'sentry/components/timeRangeSelector/selectorItems';
import type {SentryRouteObject} from 'sentry/router/types';
import type {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
import type {WidgetType} from 'sentry/views/dashboards/types';
import type {OrganizationStatsProps} from 'sentry/views/organizationStats';
import type {RouteAnalyticsContext} from 'sentry/views/routeAnalyticsContextProvider';
Expand Down Expand Up @@ -331,6 +332,7 @@ type ReactHooks = {
dataset: WidgetType;
}) => number;
'react-hook:use-get-max-retention-days': () => number | undefined;
'react-hook:use-max-pickable-days': typeof useMaxPickableDays;
'react-hook:use-metric-detector-limit': () => {
detectorCount: number;
detectorLimit: number;
Expand Down
25 changes: 12 additions & 13 deletions static/app/utils/useMaxPickableDays.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import {OrganizationFixture} from 'sentry-fixture/organization';

import {renderHook} from 'sentry-test/reactTestingLibrary';
import {renderHookWithProviders} from 'sentry-test/reactTestingLibrary';

import {DataCategory} from 'sentry/types/core';

import {useMaxPickableDays} from './useMaxPickableDays';

describe('useMaxPickableDays', () => {
it('returns 30/90 for spans without flag', () => {
const {result} = renderHook(() =>
const {result} = renderHookWithProviders(() =>
useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization: OrganizationFixture({features: []}),
})
);

Expand All @@ -23,11 +22,14 @@ describe('useMaxPickableDays', () => {
});

it('returns 90/90 for spans with flag', () => {
const {result} = renderHook(() =>
useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
const {result} = renderHookWithProviders(
() =>
useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
}),
{
organization: OrganizationFixture({features: ['visibility-explore-range-high']}),
})
}
);

expect(result.current).toEqual({
Expand All @@ -38,10 +40,9 @@ describe('useMaxPickableDays', () => {
});

it('returns 30/30 days for tracemetrics', () => {
const {result} = renderHook(() =>
const {result} = renderHookWithProviders(() =>
useMaxPickableDays({
dataCategories: [DataCategory.TRACE_METRICS],
organization: OrganizationFixture(),
})
);

Expand All @@ -53,10 +54,9 @@ describe('useMaxPickableDays', () => {
});

it('returns 30/30 days for logs', () => {
const {result} = renderHook(() =>
const {result} = renderHookWithProviders(() =>
useMaxPickableDays({
dataCategories: [DataCategory.LOG_BYTE, DataCategory.LOG_ITEM],
organization: OrganizationFixture(),
})
);

Expand All @@ -68,7 +68,7 @@ describe('useMaxPickableDays', () => {
});

it('returns 30/90 for many without flag', () => {
const {result} = renderHook(() =>
const {result} = renderHookWithProviders(() =>
useMaxPickableDays({
dataCategories: [
DataCategory.SPANS,
Expand All @@ -77,7 +77,6 @@ describe('useMaxPickableDays', () => {
DataCategory.LOG_BYTE,
DataCategory.LOG_ITEM,
],
organization: OrganizationFixture(),
})
);

Expand Down
23 changes: 17 additions & 6 deletions static/app/utils/useMaxPickableDays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {useMemo, type ReactNode} from 'react';
import HookOrDefault from 'sentry/components/hookOrDefault';
import type {DatePageFilterProps} from 'sentry/components/organizations/datePageFilter';
import {t} from 'sentry/locale';
import HookStore from 'sentry/stores/hookStore';
import {DataCategory} from 'sentry/types/core';
import type {Organization} from 'sentry/types/organization';
import useOrganization from 'sentry/utils/useOrganization';

export interface MaxPickableDaysOptions {
/**
Expand All @@ -19,15 +21,20 @@ export interface MaxPickableDaysOptions {
upsellFooter?: ReactNode;
}

interface UseMaxPickableDaysProps {
export interface UseMaxPickableDaysProps {
dataCategories: readonly [DataCategory, ...DataCategory[]];
organization: Organization;
}

export function useMaxPickableDays({
dataCategories,
organization,
}: UseMaxPickableDaysProps): MaxPickableDaysOptions {
const useMaxPickableDaysHook =
HookStore.get('react-hook:use-max-pickable-days')[0] ?? useMaxPickableDaysImpl;
return useMaxPickableDaysHook({dataCategories});
}

function useMaxPickableDaysImpl({dataCategories}: UseMaxPickableDaysProps) {
const organization = useOrganization();
return useMemo(() => {
function getMaxPickableDaysFor(dataCategory: DataCategory) {
return getMaxPickableDays(dataCategory, organization);
Expand All @@ -37,7 +44,7 @@ export function useMaxPickableDays({
}, [dataCategories, organization]);
}

function getBestMaxPickableDays(
export function getBestMaxPickableDays(
dataCategories: readonly [DataCategory, ...DataCategory[]],
getMaxPickableDaysFor: (dataCategory: DataCategory) => MaxPickableDaysOptions
) {
Expand Down Expand Up @@ -69,7 +76,7 @@ function max(

const DESCRIPTION = t('To query over longer time ranges, upgrade to Business');

function getMaxPickableDays(
export function getMaxPickableDays(
dataCategory: DataCategory,
organization: Organization
): MaxPickableDaysOptions {
Expand All @@ -84,7 +91,7 @@ function getMaxPickableDays(
return {
maxPickableDays,
maxUpgradableDays: 90,
upsellFooter: <UpsellFooterHook description={DESCRIPTION} source="spans" />,
upsellFooter: SpansUpsellFooter,
};
}
case DataCategory.TRACE_METRICS:
Expand All @@ -106,3 +113,7 @@ const UpsellFooterHook = HookOrDefault({
hookName: 'component:header-date-page-filter-upsell-footer',
defaultComponent: () => null,
});

export const SpansUpsellFooter = (
<UpsellFooterHook description={DESCRIPTION} source="spans" />
);
1 change: 0 additions & 1 deletion static/app/views/explore/logs/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default function LogsContent() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.LOG_BYTE],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
1 change: 0 additions & 1 deletion static/app/views/explore/metrics/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export default function MetricsContent() {
const onboardingProject = useOnboardingProject({property: 'hasTraceMetrics'});
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.TRACE_METRICS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);
return (
Expand Down
2 changes: 0 additions & 2 deletions static/app/views/explore/multiQueryMode/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ function Content({datePageFilterProps}: ContentProps) {
}

export function MultiQueryModeContent() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
1 change: 0 additions & 1 deletion static/app/views/explore/spans/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function ExploreContent() {
const onboardingProject = useOnboardingProject();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/c
import {DataCategory} from 'sentry/types/core';
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
import useOrganization from 'sentry/utils/useOrganization';
import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext';
import {TraceItemDataset} from 'sentry/views/explore/types';
import {InsightsEnvironmentSelector} from 'sentry/views/insights/common/components/enviornmentSelector';
Expand Down Expand Up @@ -98,10 +97,8 @@ function AgentModelsLandingPage({datePageFilterProps}: AgentModelsLandingPagePro
}

function PageWithProviders() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/c
import {DataCategory} from 'sentry/types/core';
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
import useOrganization from 'sentry/utils/useOrganization';
import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext';
import {TraceItemDataset} from 'sentry/views/explore/types';
import {InsightsEnvironmentSelector} from 'sentry/views/insights/common/components/enviornmentSelector';
Expand Down Expand Up @@ -94,10 +93,8 @@ function AgentToolsLandingPage({datePageFilterProps}: AgentToolsLandingPageProps
}

function PageWithProviders() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
2 changes: 0 additions & 2 deletions static/app/views/insights/aiGenerations/views/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,8 @@ function AIGenerationsPage({datePageFilterProps}: AIGenerationsPageProps) {
}

function PageWithProviders() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/c
import {DataCategory} from 'sentry/types/core';
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
import useOrganization from 'sentry/utils/useOrganization';
import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext';
import {TraceItemDataset} from 'sentry/views/explore/types';
import {InsightsEnvironmentSelector} from 'sentry/views/insights/common/components/enviornmentSelector';
Expand Down Expand Up @@ -93,10 +92,8 @@ function McpPromptsLandingPage({datePageFilterProps}: McpPromptsLandingPageProps
}

function PageWithProviders() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/c
import {DataCategory} from 'sentry/types/core';
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
import useOrganization from 'sentry/utils/useOrganization';
import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext';
import {TraceItemDataset} from 'sentry/views/explore/types';
import {InsightsEnvironmentSelector} from 'sentry/views/insights/common/components/enviornmentSelector';
Expand Down Expand Up @@ -93,10 +92,8 @@ function McpResourcesLandingPage({datePageFilterProps}: McpResourcesLandingPageP
}

function PageWithProviders() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/c
import {DataCategory} from 'sentry/types/core';
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
import useOrganization from 'sentry/utils/useOrganization';
import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext';
import {TraceItemDataset} from 'sentry/views/explore/types';
import {InsightsEnvironmentSelector} from 'sentry/views/insights/common/components/enviornmentSelector';
Expand Down Expand Up @@ -93,10 +92,8 @@ function McpToolsLandingPage({datePageFilterProps}: McpToolsLandingPageProps) {
}

function PageWithProviders() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
2 changes: 0 additions & 2 deletions static/app/views/insights/pages/agents/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ function AgentsOverviewPage({datePageFilterProps}: AgentsOverviewPageProps) {
}

function PageWithProviders() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
2 changes: 0 additions & 2 deletions static/app/views/insights/pages/mcp/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ function McpOverviewPage({datePageFilterProps}: McpOverviewPageProps) {
}

function PageWithProviders() {
const organization = useOrganization();
const maxPickableDays = useMaxPickableDays({
dataCategories: [DataCategory.SPANS],
organization,
});
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);

Expand Down
Loading
Loading