Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/confirm-above-modals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

fix: the "discard unsaved changes" confirm no longer opens behind the edit alert modal, which left the modal impossible to close
34 changes: 34 additions & 0 deletions packages/app/src/__tests__/useConfirm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { getDefaultZIndex, Modal } from '@mantine/core';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { ConfirmProvider, useConfirm } from '@/useConfirm';

jest.mock('next/router', () => ({
useRouter: () => ({ events: { on: jest.fn(), off: jest.fn() } }),
}));

function ModalThatConfirms() {
const confirm = useConfirm();
return (
<Modal opened onClose={() => {}} title="Editor">
<button onClick={() => confirm('Discard?', 'Discard')}>Close</button>
</Modal>
);
}

describe('ConfirmProvider', () => {
it('stacks the confirm above a modal at the default z-index', async () => {
renderWithMantine(
<ConfirmProvider>
<ModalThatConfirms />
</ConfirmProvider>,
);

await userEvent.click(screen.getByRole('button', { name: 'Close' }));

const confirmModal = await screen.findByTestId('confirm-modal');
const zIndex = Number(confirmModal.style.getPropertyValue('--mb-z-index'));
expect(zIndex).toBeGreaterThan(getDefaultZIndex('modal'));
});
});
3 changes: 3 additions & 0 deletions packages/app/src/useConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export function ConfirmProvider({ children }: { children: React.ReactNode }) {
onClose={state?.onClose ?? (() => {})}
centered
withCloseButton={false}
// Above every app modal (some go to 9999) so it never opens behind
// the one that asked; below notifications and spotlight.
zIndex={100_000}
>
<Text size="sm" opacity={0.7}>
{state?.message}
Expand Down
Loading