Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(project): use hasFlags flag for CTA check #83282

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -16,6 +16,7 @@ import {
MOCK_FLAGS,
NO_FLAG_CONTEXT_SECTION_PROPS_CTA,
NO_FLAG_CONTEXT_SECTION_PROPS_NO_CTA,
NO_FLAG_CONTEXT_WITH_FLAGS_SECTION_PROPS_NO_CTA,
} from 'sentry/components/events/featureFlags/testUtils';

// Needed to mock useVirtualizer lists.
Expand Down Expand Up @@ -247,6 +248,26 @@ describe('EventFeatureFlagList', function () {
expect(screen.getByText('Feature Flags')).toBeInTheDocument();
});

it('renders empty state if event.contexts.flags is not set but should not show cta - flags already sent', function () {
const org = OrganizationFixture({features: ['feature-flag-cta']});

render(
<EventFeatureFlagList {...NO_FLAG_CONTEXT_WITH_FLAGS_SECTION_PROPS_NO_CTA} />,
{
organization: org,
}
);

const control = screen.queryByRole('button', {name: 'Sort Flags'});
expect(control).not.toBeInTheDocument();
const search = screen.queryByRole('button', {name: 'Open Feature Flag Search'});
expect(search).not.toBeInTheDocument();
expect(screen.getByRole('button', {name: 'Set Up Integration'})).toBeInTheDocument();
expect(
screen.getByText('No feature flags were found for this event')
).toBeInTheDocument();
});

it('renders nothing if event.contexts.flags is not set and should not show cta - wrong platform', async function () {
const org = OrganizationFixture({features: ['feature-flag-cta']});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import FeatureFlagInlineCTA from 'sentry/components/events/featureFlags/featureFlagInlineCTA';
import FeatureFlagSort from 'sentry/components/events/featureFlags/featureFlagSort';
import {useFeatureFlagOnboarding} from 'sentry/components/events/featureFlags/useFeatureFlagOnboarding';
import useIssueEvents from 'sentry/components/events/featureFlags/useIssueEvents';
import {
FlagControlOptions,
OrderBy,
Expand Down Expand Up @@ -79,12 +78,6 @@ export function EventFeatureFlagList({
},
});

const {
data: relatedEvents,
isPending: isRelatedEventsPending,
isError: isRelatedEventsError,
} = useIssueEvents({issueId: group.id});

const {activateSidebarSkipConfigure} = useFeatureFlagOnboarding();

const {
Expand All @@ -105,10 +98,6 @@ export function EventFeatureFlagList({
}, [isSuspectError, isSuspectPending, suspectFlags]);

const hasFlagContext = Boolean(event.contexts?.flags?.values);
const anyEventHasContext =
isRelatedEventsPending || isRelatedEventsError
? false
: relatedEvents.filter(e => Boolean(e.contexts?.flags?.values)).length > 0;

const eventFlags: Required<FeatureFlag>[] = useMemo(() => {
// At runtime there's no type guarantees on the event flags. So we have to
Expand All @@ -126,8 +115,8 @@ export function EventFeatureFlagList({
const hasFlags = hasFlagContext && eventFlags.length > 0;

const showCTA =
!project.hasFlags &&
!hasFlagContext &&
!anyEventHasContext &&
featureFlagOnboardingPlatforms.includes(project.platform ?? 'other') &&
organization.features.includes('feature-flag-cta');

Expand Down Expand Up @@ -207,8 +196,8 @@ export function EventFeatureFlagList({
return <FeatureFlagInlineCTA projectId={event.projectID} />;
}

// if contexts.flags is not set, hide the section
if (!hasFlagContext) {
// if contexts.flags is not set and project has not set up flags, hide the section
if (!hasFlagContext && !project.hasFlags) {
return null;
}

Expand Down
12 changes: 11 additions & 1 deletion static/app/components/events/featureFlags/testUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ export const NO_FLAG_CONTEXT_SECTION_PROPS_CTA = {
contexts: {other: {}},
platform: 'javascript',
}),
project: ProjectFixture({platform: 'javascript'}),
project: ProjectFixture({platform: 'javascript', hasFlags: false}),
group: GroupFixture({platform: 'javascript'}),
};

export const NO_FLAG_CONTEXT_WITH_FLAGS_SECTION_PROPS_NO_CTA = {
event: EventFixture({
id: 'abc123def456ghi789jkl',
contexts: {other: {}},
platform: 'javascript',
}),
project: ProjectFixture({platform: 'javascript', hasFlags: true}),
group: GroupFixture({platform: 'javascript'}),
};
21 changes: 0 additions & 21 deletions static/app/components/events/featureFlags/useIssueEvents.tsx

This file was deleted.

1 change: 1 addition & 0 deletions static/app/types/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Project = {
hasAccess: boolean;
hasCustomMetrics: boolean;
hasFeedbacks: boolean;
hasFlags: boolean;
hasInsightsAppStart: boolean;
hasInsightsAssets: boolean;
hasInsightsCaches: boolean;
Expand Down
1 change: 1 addition & 0 deletions tests/js/fixtures/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function ProjectFixture(params: Partial<Project> = {}): Project {
hasMinifiedStackTrace: false,
hasProfiles: false,
hasReplays: false,
hasFlags: false,
hasSessions: false,
hasMonitors: false,
hasInsightsHttp: false,
Expand Down
Loading