Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fc33eba
chore: change to Modal instead of FormModal so the toolbar can be cha…
kmruiz Nov 9, 2023
125dafc
chore: remove not necessary styles
kmruiz Nov 9, 2023
01d2706
chore: add favorite icon to save button
kmruiz Nov 9, 2023
ca32331
chore: add update query to saved queries
kmruiz Nov 9, 2023
d1c3b20
chore: implement interactivepopover for the bulk update dialog
kmruiz Nov 9, 2023
221b5dd
chore: make new hasCustomCloseButton prop optional
kmruiz Nov 9, 2023
9de67da
chore: store the query in the favorite storage
kmruiz Nov 9, 2023
4892985
chore: fix card styles
kmruiz Nov 9, 2023
b099486
chore: show all required fields in favorites
kmruiz Nov 9, 2023
ffe6333
chore: open update modal from favorites
kmruiz Nov 9, 2023
f9e91e2
chore: void promise
kmruiz Nov 9, 2023
c77d15c
chore: fix linting issues
kmruiz Nov 9, 2023
09dc167
chore: add opens in new tab marker to favorite items
kmruiz Nov 10, 2023
7c1b020
chore: close popover when an update favorite is chosen
kmruiz Nov 10, 2023
81c7425
chore: force toasts to be on top of overlays
kmruiz Nov 10, 2023
ab1b7a2
chore: show opens in modal marker always
kmruiz Nov 13, 2023
7847dc2
chore: merge with main
kmruiz Nov 13, 2023
91fabf2
chore: add test for interactive popover
kmruiz Nov 13, 2023
f81be67
chore: fix test related to close button
kmruiz Nov 13, 2023
706760d
chore: fix interactive popover interactions and add test to bulk upda…
kmruiz Nov 13, 2023
e28a33a
chore: test save query interaction
kmruiz Nov 13, 2023
1327610
chore: remove .only
kmruiz Nov 13, 2023
994a827
chore: test favorite storage
kmruiz Nov 13, 2023
2a1fc42
chore: test updatemany card
kmruiz Nov 13, 2023
3e5074d
chore: test query bar changes
kmruiz Nov 13, 2023
9ad913a
chore: fix linter
kmruiz Nov 13, 2023
58156f0
chore: fix some more linting issues
kmruiz Nov 13, 2023
019c461
Merge branch 'main' into feature/COMPASS-7331
kmruiz Nov 13, 2023
246e023
chore: add dependency to queries storage
kmruiz Nov 13, 2023
4d23f1f
chore: linting
kmruiz Nov 13, 2023
15d8517
chore: fix some more linting issues
kmruiz Nov 13, 2023
afa9f4b
chore: fix issues
kmruiz Nov 13, 2023
0c41f94
chore: minor refactors
kmruiz Nov 13, 2023
222ff14
chore: merge with main
kmruiz Nov 14, 2023
a1b4efd
chore: fix linting issues
kmruiz Nov 14, 2023
aba4bc1
chore: allow a custom fallback
kmruiz Nov 14, 2023
8d1b4e2
chore: use global app registry for interplugin comms and fix test on …
kmruiz Nov 14, 2023
8be853c
chore: fix linting complains
kmruiz Nov 14, 2023
7a0903f
chore: remove comment that is not informative enough
kmruiz Nov 14, 2023
754594f
chore: remove cast to any
kmruiz Nov 14, 2023
4695d5d
chore: rename trap fallback and use localAppRegistry
kmruiz Nov 14, 2023
b6a0cad
chore: group localAppRegistry events together
kmruiz Nov 14, 2023
1bf6ad5
chore: rename close button override prop
kmruiz Nov 14, 2023
3b76719
chore: linting issues
kmruiz Nov 15, 2023
6cfd14e
chore: fix linting issues
kmruiz Nov 15, 2023
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 @@ -14,6 +14,8 @@ function renderPopover(
<InteractivePopover
className=""
open={false}
hideCloseButton={props?.hideCloseButton}
customFocusTrapFallback={`#${innerContentTestId}`}
setOpen={() => {}}
trigger={({ onClick, ref, children }) => (
<>
Expand All @@ -29,6 +31,7 @@ function renderPopover(
<button
type="button"
onClick={() => {}}
id={innerContentTestId}
data-testid={innerContentTestId}
>
Action Button
Expand Down Expand Up @@ -111,4 +114,14 @@ describe('InteractivePopover Component', function () {
expect(openSpy.calledOnce).to.be.true;
expect(openSpy.firstCall.firstArg).to.equal(false);
});

it('when open with a custom button, the general close button is not visible', function () {
renderPopover({
open: true,
hideCloseButton: true,
});

expect(screen.queryByTestId('interactive-popover-close-button')).to.not
.exist;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type InteractivePopoverProps = {
ref: React.LegacyRef<HTMLButtonElement>;
children: React.ReactNode;
}) => React.ReactElement;
hideCloseButton?: boolean;
customFocusTrapFallback?: string;
open: boolean;
setOpen: (open: boolean) => void;
/**
Expand All @@ -67,6 +69,8 @@ function InteractivePopover({
className,
children,
trigger,
hideCloseButton = false,
customFocusTrapFallback = undefined,
open,
setOpen,
containedElements = [],
Expand All @@ -91,14 +95,27 @@ function InteractivePopover({
});
}, [setOpen]);

const onClickTrigger = useCallback(() => {
if (open) {
onClose();
return;
}
const onClickTrigger = useCallback(
(event) => {
if (open) {
if (
containedElements.some((selector) => {
return document
.querySelector(selector)
?.contains(event.target as Node);
})
) {
return;
}

onClose();
return;
}

setOpen(!open);
}, [open, setOpen, onClose]);
setOpen(!open);
},
[open, setOpen, onClose, containedElements]
);

// When the popover is open, close it when an item that isn't the popover
// is clicked.
Expand Down Expand Up @@ -167,7 +184,7 @@ function InteractivePopover({
focusTrapOptions={{
clickOutsideDeactivates: true,
// Tests fail without a fallback. (https://github.com/focus-trap/focus-trap-react/issues/91)
fallbackFocus: `#${closeButtonId}`,
fallbackFocus: customFocusTrapFallback || `#${closeButtonId}`,
}}
>
<div
Expand All @@ -182,19 +199,21 @@ function InteractivePopover({
>
{children}

<IconButton
className={cx(closeButtonStyles, closeButtonClassName)}
data-testid="interactive-popover-close-button"
onClick={(evt) => {
evt.stopPropagation();
onClose();
}}
aria-label="Close"
id={closeButtonId}
ref={closeButtonRef}
>
<Icon glyph="X" />
</IconButton>
{!hideCloseButton && (
<IconButton
className={cx(closeButtonStyles, closeButtonClassName)}
data-testid="interactive-popover-close-button"
onClick={(evt) => {
evt.stopPropagation();
onClose();
}}
aria-label="Close"
id={closeButtonId}
ref={closeButtonRef}
>
<Icon glyph="X" />
</IconButton>
)}
</div>
</FocusTrap>
</Popover>
Expand Down
4 changes: 3 additions & 1 deletion packages/compass-components/src/hooks/use-toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ToastProvider,
useToast as useLeafygreenToast,
} from '../components/leafygreen';
import { css } from '@leafygreen-ui/emotion';

export type ToastProperties = Pick<
ToastProps,
Expand Down Expand Up @@ -153,6 +154,7 @@ const _ToastArea: React.FunctionComponent = ({ children }) => {
);
};

const toastAreaFronLayerStyles = css({ zIndex: 1 });
const ToastAreaMountedContext = React.createContext(false);

export const ToastArea: React.FunctionComponent = ({ children }) => {
Expand All @@ -162,7 +164,7 @@ export const ToastArea: React.FunctionComponent = ({ children }) => {

return (
<ToastAreaMountedContext.Provider value={true}>
<ToastProvider>
<ToastProvider portalClassName={toastAreaFronLayerStyles}>
<_ToastArea>{children}</_ToastArea>
</ToastProvider>
</ToastAreaMountedContext.Provider>
Expand Down
2 changes: 2 additions & 0 deletions packages/compass-crud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@mongodb-js/compass-components": "^1.19.0",
"@mongodb-js/compass-editor": "^0.18.0",
"@mongodb-js/compass-logging": "^1.2.6",
"@mongodb-js/my-queries-storage": "^0.2.1",
"@mongodb-js/explain-plan-helper": "^1.1.4",
"bson": "^6.0.0",
"compass-preferences-model": "^2.15.6",
Expand Down Expand Up @@ -108,6 +109,7 @@
"@mongodb-js/compass-editor": "^0.18.0",
"@mongodb-js/compass-logging": "^1.2.6",
"@mongodb-js/explain-plan-helper": "^1.1.4",
"@mongodb-js/my-queries-storage": "^0.2.1",
"bson": "^6.0.0",
"compass-preferences-model": "^2.15.6",
"hadron-document": "^8.4.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function renderBulkUpdateDialog(
closeBulkUpdateDialog={() => {}}
updateBulkUpdatePreview={() => {}}
runBulkUpdate={() => {}}
saveUpdateQuery={() => {}}
{...props}
/>
);
Expand Down Expand Up @@ -60,8 +61,9 @@ describe('BulkUpdateDialog Component', function () {
).to.have.lengthOf(1);

// buttons
expect(screen.getByRole('button', { name: 'Close' })).to.exist;
expect(screen.getByRole('button', { name: 'Update documents' })).to.exist;
expect(screen.getByRole('button', { name: 'Cancel' })).to.exist;
expect(screen.getByRole('button', { name: 'Update 42 documents' })).to
.exist;
});

it('resets if the modal is re-opened', async function () {
Expand All @@ -87,6 +89,7 @@ describe('BulkUpdateDialog Component', function () {
closeBulkUpdateDialog={() => {}}
updateBulkUpdatePreview={() => {}}
runBulkUpdate={() => {}}
saveUpdateQuery={() => {}}
/>
);

Expand All @@ -109,6 +112,7 @@ describe('BulkUpdateDialog Component', function () {
closeBulkUpdateDialog={() => {}}
updateBulkUpdatePreview={() => {}}
runBulkUpdate={() => {}}
saveUpdateQuery={() => {}}
/>
);

Expand All @@ -125,15 +129,31 @@ describe('BulkUpdateDialog Component', function () {
const onCloseSpy = sinon.spy();
renderBulkUpdateDialog({ closeBulkUpdateDialog: onCloseSpy });

userEvent.click(screen.getByRole('button', { name: 'Close' }));
userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
expect(onCloseSpy).to.have.been.calledOnce;
});

it('runs the update when the update button is clicked', function () {
const onUpdateSpy = sinon.spy();
renderBulkUpdateDialog({ runBulkUpdate: onUpdateSpy });
renderBulkUpdateDialog({ runBulkUpdate: onUpdateSpy, count: 60 });

userEvent.click(screen.getByRole('button', { name: 'Update documents' }));
userEvent.click(
screen.getByRole('button', { name: 'Update 60 documents' })
);
expect(onUpdateSpy).to.have.been.calledOnce;
});

it('saves the query when a name is provided', function () {
const saveUpdateQuerySpy = sinon.spy();
renderBulkUpdateDialog({ saveUpdateQuery: saveUpdateQuerySpy });

userEvent.click(screen.getByTestId('inline-save-query-modal-opener'));
userEvent.type(
screen.getByTestId('inline-save-query-modal-input'),
'MySavedQuery'
);

userEvent.click(screen.getByTestId('inline-save-query-modal-submit'));
expect(saveUpdateQuerySpy).to.have.been.calledOnceWith('MySavedQuery');
});
});
Loading