Skip to content

feat(flags): add setup integration modal #80437

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

Merged
merged 9 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -9,8 +9,10 @@ import {

import {EventFeatureFlagList} from 'sentry/components/events/featureFlags/eventFeatureFlagList';
import {
EMPTY_STATE_SECTION_PROPS,
MOCK_DATA_SECTION_PROPS,
MOCK_FLAGS,
NO_FLAG_CONTEXT_SECTION_PROPS,
} from 'sentry/components/events/featureFlags/testUtils';

// Needed to mock useVirtualizer lists.
Expand Down Expand Up @@ -192,4 +194,30 @@ describe('EventFeatureFlagList', function () {
.compareDocumentPosition(screen.getByText(enableReplay.flag))
).toBe(document.DOCUMENT_POSITION_FOLLOWING);
});

it('renders empty state', function () {
render(<EventFeatureFlagList {...EMPTY_STATE_SECTION_PROPS} />);

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.queryByText('No feature flags were found for this event')
).toBeInTheDocument();
});

it('renders nothing if event.contexts.flags is not set', function () {
render(<EventFeatureFlagList {...NO_FLAG_CONTEXT_SECTION_PROPS} />);

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.queryByRole('button', {name: 'Set Up Integration'})
).not.toBeInTheDocument();
expect(screen.queryByText('Feature Flags')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import {useCallback, useMemo, useRef, useState} from 'react';
import {Fragment, useCallback, useMemo, useRef, useState} from 'react';
import styled from '@emotion/styled';

import {openModal} from 'sentry/actionCreators/modal';
import {Button} from 'sentry/components/button';
import ButtonBar from 'sentry/components/buttonBar';
import EmptyStateWarning from 'sentry/components/emptyStateWarning';
import ErrorBoundary from 'sentry/components/errorBoundary';
import {
CardContainer,
FeatureFlagDrawer,
} from 'sentry/components/events/featureFlags/featureFlagDrawer';
import FeatureFlagSort from 'sentry/components/events/featureFlags/featureFlagSort';
import {
modalCss,
SetupIntegrationModal,
} from 'sentry/components/events/featureFlags/setupIntegrationModal';
import {
FlagControlOptions,
OrderBy,
Expand Down Expand Up @@ -86,6 +92,15 @@ export function EventFeatureFlagList({
event,
});

const hasFlagContext = !!event.contexts.flags;
const hasFlags = Boolean(hasFlagContext && event?.contexts?.flags?.values.length);

function handleClick() {
openModal(modalProps => <SetupIntegrationModal {...modalProps} />, {
modalCss,
});
}

const suspectFlagNames: Set<string> = useMemo(() => {
return isSuspectError || isSuspectPending
? new Set()
Expand Down Expand Up @@ -150,37 +165,50 @@ export function EventFeatureFlagList({
[openDrawer, event, group, project, hydratedFlags, organization, sortBy, orderBy]
);

if (!hydratedFlags.length) {
// TODO: for LD users, show a CTA in this section instead
// if contexts.flags is not set, hide the section
if (!hasFlagContext) {
return null;
}

const actions = (
<ButtonBar gap={1}>
{feedbackButton}
<Button
size="xs"
aria-label={t('View All')}
ref={viewAllButtonRef}
title={t('View All Flags')}
onClick={() => {
isDrawerOpen ? closeDrawer() : onViewAllFlags();
}}
>
{t('View All')}
</Button>
<Button
aria-label={t('Open Feature Flag Search')}
icon={<IconSearch size="xs" />}
size="xs"
title={t('Open Search')}
onClick={() => onViewAllFlags(FlagControlOptions.SEARCH)}
/>
<FeatureFlagSort
orderBy={orderBy}
sortBy={sortBy}
setSortBy={setSortBy}
setOrderBy={setOrderBy}
/>
{hasFlagContext && (
<Fragment>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this after the early return check above?

Suggested change
{hasFlagContext && (
{(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping this for now since it'll be useful when we add in the LD feature flag

<Button aria-label={t('Set Up Integration')} size="xs" onClick={handleClick}>
{t('Set Up Integration')}
</Button>
{hasFlags && (
<Fragment>
<Button
size="xs"
aria-label={t('View All')}
ref={viewAllButtonRef}
title={t('View All Flags')}
onClick={() => {
isDrawerOpen ? closeDrawer() : onViewAllFlags();
}}
>
{t('View All')}
</Button>
<Button
aria-label={t('Open Feature Flag Search')}
icon={<IconSearch size="xs" />}
size="xs"
title={t('Open Search')}
onClick={() => onViewAllFlags(FlagControlOptions.SEARCH)}
/>
<FeatureFlagSort
orderBy={orderBy}
sortBy={sortBy}
setSortBy={setSortBy}
setOrderBy={setOrderBy}
/>
</Fragment>
)}
</Fragment>
)}
</ButtonBar>
);

Expand All @@ -203,10 +231,16 @@ export function EventFeatureFlagList({
type={SectionKey.FEATURE_FLAGS}
actions={actions}
>
<CardContainer numCols={columnTwo.length ? 2 : 1}>
<KeyValueData.Card contentItems={columnOne} />
<KeyValueData.Card contentItems={columnTwo} />
</CardContainer>
{hasFlags ? (
<CardContainer numCols={columnTwo.length ? 2 : 1}>
<KeyValueData.Card contentItems={columnOne} />
<KeyValueData.Card contentItems={columnTwo} />
</CardContainer>
) : (
<EmptyStateWarning withIcon small>
{t('No feature flags were found for this event')}
</EmptyStateWarning>
)}
</InterimSection>
</ErrorBoundary>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function FeatureFlagSort({sortBy, orderBy, setOrderBy, setSortBy}
aria-label={t('Sort Flags')}
size="xs"
icon={<IconSort />}
title={t('Sort Flags')}
/>
)}
>
Expand Down
Loading
Loading