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

chore(issue-details): Update streamline util to better support enforcing new experience #87336

Merged
merged 6 commits into from
Mar 20, 2025
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: 1 addition & 1 deletion static/app/types/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface User extends Omit<AvatarUser, 'options'> {
clock24Hours: boolean;
defaultIssueEvent: 'recommended' | 'latest' | 'oldest';
language: string;
prefersIssueDetailsStreamlinedUI: boolean;
prefersIssueDetailsStreamlinedUI: boolean | null;
prefersSpecializedProjectOverview: {[projectId: string]: boolean};
prefersStackedNavigation: boolean;
quickStartDisplay: QuickStartDisplay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import {EventAttachmentFixture} from 'sentry-fixture/eventAttachment';
import {GroupFixture} from 'sentry-fixture/group';
import {ProjectFixture} from 'sentry-fixture/project';
import {TagsFixture} from 'sentry-fixture/tags';
import {UserFixture} from 'sentry-fixture/user';

import {initializeOrg} from 'sentry-test/initializeOrg';
import {
act,
render,
renderGlobalModal,
screen,
userEvent,
within,
} from 'sentry-test/reactTestingLibrary';

import ConfigStore from 'sentry/stores/configStore';
import GroupStore from 'sentry/stores/groupStore';
import ModalStore from 'sentry/stores/modalStore';
import ProjectsStore from 'sentry/stores/projectsStore';
Expand Down Expand Up @@ -150,6 +153,11 @@ describe('GroupEventAttachments', function () {
});

it('filters by date/query when using Streamlined UI', function () {
ConfigStore.init();
const user = UserFixture();
user.options.prefersIssueDetailsStreamlinedUI = true;
act(() => ConfigStore.set('user', user));

render(<GroupEventAttachments project={project} group={group} />, {
disableRouterMocks: true,
initialRouterConfig: {
Expand Down
20 changes: 18 additions & 2 deletions static/app/views/issueDetails/utils.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,38 @@ describe('useHasStreamlinedUI', () => {
expect(prefersStreamlineButQueryParamDisabled.current).toBe(false);
});

it('ignores preferences if enforce flag is set', () => {
it('ignores preferences if enforce flag is set and user has not opted out', () => {
const enforceOrg = OrganizationFixture({
features: ['issue-details-streamline-enforce'],
});
jest.mocked(useOrganization).mockReturnValue(enforceOrg);

ConfigStore.init();
const user = UserFixture();
user.options.prefersIssueDetailsStreamlinedUI = false;
user.options.prefersIssueDetailsStreamlinedUI = null;
act(() => ConfigStore.set('user', user));

jest.mocked(useLocation).mockReturnValue(LocationFixture());
const {result} = renderHook(useHasStreamlinedUI);
expect(result.current).toBe(true);
});

it('respects preferences if enforce flag is set and user has opted out', () => {
const enforceOrg = OrganizationFixture({
features: ['issue-details-streamline-enforce'],
});
jest.mocked(useOrganization).mockReturnValue(enforceOrg);

ConfigStore.init();
const user = UserFixture();
user.options.prefersIssueDetailsStreamlinedUI = false;
act(() => ConfigStore.set('user', user));

jest.mocked(useLocation).mockReturnValue(LocationFixture());
const {result} = renderHook(useHasStreamlinedUI);
expect(result.current).toBe(false);
});

it('ignores preferences if organization option is set to true', () => {
jest.mocked(useLocation).mockReturnValue(LocationFixture());

Expand Down
8 changes: 6 additions & 2 deletions static/app/views/issueDetails/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export function useHasStreamlinedUI() {
const location = useLocation();
const user = useUser();
const organization = useOrganization();
const userStreamlinedUIOption = user?.options?.prefersIssueDetailsStreamlinedUI;

// Allow query param to override all other settings to set the UI.
if (defined(location.query.streamline)) {
Expand All @@ -286,12 +287,15 @@ export function useHasStreamlinedUI() {
}

// If the enforce flag is set for the organization, ignore user preferences and enable the UI
if (organization.features.includes('issue-details-streamline-enforce')) {
if (
userStreamlinedUIOption !== false &&
organization.features.includes('issue-details-streamline-enforce')
) {
return true;
}

// Apply the UI based on user preferences
return !!user?.options?.prefersIssueDetailsStreamlinedUI;
return userStreamlinedUIOption ?? false;
}

export function useIsSampleEvent(): boolean {
Expand Down
Loading