Skip to content

Commit

Permalink
featurebadge: remove expires and internal type (#85977)
Browse files Browse the repository at this point in the history
Dead code. Expiry functionality could be a separate component and
internal badge is unused
  • Loading branch information
JonasBa authored Feb 27, 2025
1 parent 72d4c3f commit 0d9a93e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 83 deletions.
42 changes: 0 additions & 42 deletions static/app/components/core/badge/featureBadge.spec.tsx

This file was deleted.

39 changes: 1 addition & 38 deletions static/app/components/core/badge/featureBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {useTheme} from '@emotion/react';
import styled from '@emotion/styled';
import type {SeverityLevel} from '@sentry/core';
import {captureException, withScope} from '@sentry/react';

import CircleIndicator from 'sentry/components/circleIndicator';
import {Badge} from 'sentry/components/core/badge';
Expand All @@ -17,23 +15,20 @@ const defaultTitles: Record<FeatureBadgeProps['type'], string> = {
experimental: t(
'This feature is experimental! Try it out and let us know what you think. No promises!'
),
internal: t('This feature is for internal use only'),
};

const labels: Record<FeatureBadgeProps['type'], string> = {
alpha: t('alpha'),
beta: t('beta'),
new: t('new'),
experimental: t('experimental'),
internal: t('internal'),
};

const shortLabels: Record<FeatureBadgeProps['type'], string> = {
alpha: 'A',
beta: 'B',
new: 'N',
experimental: 'E',
internal: 'I',
};

const useFeatureBadgeIndicatorColor = () => {
Expand All @@ -44,14 +39,12 @@ const useFeatureBadgeIndicatorColor = () => {
beta: theme.purple300,
new: theme.green300,
experimental: theme.gray100,
internal: theme.gray100,
} satisfies Record<FeatureBadgeProps['type'], string>;
};

export interface FeatureBadgeProps
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
type: 'alpha' | 'beta' | 'new' | 'experimental' | 'internal';
expiresAt?: Date;
type: 'alpha' | 'beta' | 'new' | 'experimental';
tooltipProps?: Partial<TooltipProps>;
variant?: 'badge' | 'indicator' | 'short';
}
Expand All @@ -60,16 +53,11 @@ function InnerFeatureBadge({
type,
variant = 'badge',
tooltipProps,
expiresAt,
...props
}: FeatureBadgeProps) {
const indicatorColors = useFeatureBadgeIndicatorColor();
const title = tooltipProps?.title?.toString() ?? defaultTitles[type] ?? '';

if (hasFeatureBadgeExpired(expiresAt, title, type)) {
return null;
}

return (
<div {...props}>
<Tooltip title={title ?? defaultTitles[type]} position="right" {...tooltipProps}>
Expand All @@ -85,31 +73,6 @@ function InnerFeatureBadge({
);
}

/**
* Checks if a feature badge has expired - if it has, reports the result to Sentry
* @param expiresAt The date the feature badge expires.
* @returns True if the feature badge has expired, false otherwise.
*/
function hasFeatureBadgeExpired(
expiresAt: Date | undefined,
title: string,
type: FeatureBadgeProps['type']
) {
if (expiresAt && expiresAt.valueOf() < Date.now()) {
// Only get 1% of events as we don't need many to know that a badge needs to be cleaned up.
if (Math.random() < 0.01) {
withScope(scope => {
scope.setTag('title', title);
scope.setTag('type', type);
scope.setLevel('warning' as SeverityLevel);
captureException(new Error('Expired Feature Badge'));
});
}
return true;
}
return false;
}

const StyledBadge = styled(Badge)`
margin: 0;
padding: 0 ${space(0.75)};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ export function ScreenDetailsPage() {
return (
<TabList.Item key={tab.key} hidden={!visible} textValue={tab.label}>
{tab.label}
{tab.featureBadge && (
<FeatureBadge type={tab.featureBadge} variant={'badge'} />
)}
{tab.featureBadge && <FeatureBadge type={tab.featureBadge} />}
</TabList.Item>
);
})}
Expand Down

0 comments on commit 0d9a93e

Please sign in to comment.