Skip to content

Commit

Permalink
feat(nav-views): Enforce no deletion on last view (#85998)
Browse files Browse the repository at this point in the history
[Last PR](#85959) failed because
that branch didn't have some tests that were in master. This PR fixes
the tests to expect the new param.
  • Loading branch information
MichaelSun48 authored Feb 26, 2025
1 parent dfd33f2 commit b57ecf9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrar

import {IssueSortOptions} from 'sentry/views/issueList/utils';

import {IssueViewNavEllipsisMenu} from './issueViewNavEllipsisMenu';
import {
IssueViewNavEllipsisMenu,
type IssueViewNavEllipsisMenuProps,
} from './issueViewNavEllipsisMenu';

describe('IssueViewNavEllipsisMenu', () => {
const mockView = {
Expand All @@ -23,13 +26,14 @@ describe('IssueViewNavEllipsisMenu', () => {
label: 'Test View',
};

const defaultProps = {
const defaultProps: IssueViewNavEllipsisMenuProps = {
baseUrl: '/organizations/sentry/issues',
deleteView: jest.fn(),
duplicateView: jest.fn(),
setIsEditing: jest.fn(),
updateView: jest.fn(),
view: mockView,
isLastView: false,
};

beforeEach(() => {
Expand Down Expand Up @@ -97,4 +101,10 @@ describe('IssueViewNavEllipsisMenu', () => {
expect(screen.queryByText('Rename')).not.toBeInTheDocument();
});
});

it('disables delete button when isLastView is true', () => {
render(<IssueViewNavEllipsisMenu {...defaultProps} isLastView />);

expect(screen.queryByText('Delete')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {useNavigate} from 'sentry/utils/useNavigate';
import useOrganization from 'sentry/utils/useOrganization';
import type {IssueView} from 'sentry/views/issueList/issueViews/issueViews';

interface IssueViewNavEllipsisMenuProps {
export interface IssueViewNavEllipsisMenuProps {
baseUrl: string;
deleteView: () => void;
duplicateView: () => void;
isLastView: boolean;
setIsEditing: (isEditing: boolean) => void;
updateView: (view: IssueView) => void;
view: IssueView;
Expand All @@ -32,6 +33,7 @@ export function IssueViewNavEllipsisMenu({
duplicateView,
updateView,
baseUrl,
isLastView,
}: IssueViewNavEllipsisMenuProps) {
const navigate = useNavigate();
const organization = useOrganization();
Expand Down Expand Up @@ -127,6 +129,7 @@ export function IssueViewNavEllipsisMenu({
label: t('Delete'),
priority: 'danger',
onAction: deleteView,
disabled: isLastView,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export interface IssueViewNavItemContentProps {
* Whether the item is active.
*/
isActive: boolean;
/**
* Whether the item is the last view in the list.
* This will be removed once view sharing/starring is implemented.
*/
isLastView: boolean;
/**
* A callback function that updates the view with new params.
*/
Expand All @@ -65,6 +70,7 @@ export function IssueViewNavItemContent({
updateView,
deleteView,
duplicateView,
isLastView,
}: IssueViewNavItemContentProps) {
const organization = useOrganization();
const location = useLocation();
Expand Down Expand Up @@ -137,6 +143,7 @@ export function IssueViewNavItemContent({
>
<IssueViewNavQueryCount view={view} />
<IssueViewNavEllipsisMenu
isLastView={isLastView}
setIsEditing={setIsEditing}
view={view}
updateView={updateView}
Expand Down
1 change: 1 addition & 0 deletions static/app/components/nav/issueViews/issueViewNavItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export function IssueViewNavItems({
updateView={updatedView => handleUpdateView(view, updatedView)}
deleteView={() => handleDeleteView(view)}
duplicateView={() => handleDuplicateView(view)}
isLastView={views.length === 1}
/>
</AnimatePresence>
))}
Expand Down

0 comments on commit b57ecf9

Please sign in to comment.