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

[Infra UI] Fix filter popovers not being closed on trigger button click #164060

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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const WaffleInventorySwitcher: React.FC = () => {
} = useWaffleOptionsContext();
const [isOpen, setIsOpen] = useState(false);
const closePopover = useCallback(() => setIsOpen(false), []);
const openPopover = useCallback(() => setIsOpen(true), []);
const togglePopover = useCallback(() => setIsOpen((currentIsOpen) => !currentIsOpen), []);
Comment on lines 33 to +34
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, there is a custom hook that could be used here. ex:

 const [isPopoverOpen, { off: closePopover, toggle: togglePopover }] = useBoolean(false);

Mentioning it for the future, if you come across anything that might be interesting to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, thank you! 👍

const goToNodeType = useCallback(
(targetNodeType: InventoryItemType) => {
closePopover();
Expand Down Expand Up @@ -127,7 +127,7 @@ export const WaffleInventorySwitcher: React.FC = () => {
const button = (
<DropdownButton
data-test-subj={'openInventorySwitcher'}
onClick={openPopover}
onClick={togglePopover}
label={i18n.translate('xpack.infra.waffle.showLabel', { defaultMessage: 'Show' })}
showKubernetesInfo={true}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,15 @@ const LABELS = {
export const WaffleSortControls = ({ sort, onChange }: Props) => {
const [isOpen, setIsOpen] = useState<boolean>(false);

const showPopover = useCallback(() => {
setIsOpen(true);
}, [setIsOpen]);

const closePopover = useCallback(() => {
setIsOpen(false);
}, [setIsOpen]);
const togglePopover = useCallback(() => setIsOpen((currentIsOpen) => !currentIsOpen), []);
const closePopover = useCallback(() => setIsOpen(false), []);

const label = LABELS[sort.by];

const button = (
<DropdownButton
label={i18n.translate('xpack.infra.waffle.sortLabel', { defaultMessage: 'Sort by' })}
onClick={showPopover}
onClick={togglePopover}
data-test-subj={'waffleSortByDropdown'}
>
{label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const MetricsExplorerChartContextMenu: React.FC<Props> = ({
];

const handleClose = () => setPopoverState(false);
const handleOpen = () => setPopoverState(true);
const togglePopover = () => setPopoverState((currentIsOpen) => !currentIsOpen);
const actionAriaLabel = i18n.translate('xpack.infra.metricsExplorer.actionsLabel.aria', {
defaultMessage: 'Actions for {grouping}',
values: { grouping: series.id },
Expand All @@ -193,7 +193,7 @@ export const MetricsExplorerChartContextMenu: React.FC<Props> = ({
<EuiButtonEmpty
data-test-subj="infraMetricsExplorerChartContextMenuButton"
contentProps={{ 'aria-label': actionAriaLabel }}
onClick={handleOpen}
onClick={togglePopover}
size="s"
iconType="arrowDown"
iconSide="right"
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/apps/infra/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.infraHome.openTimeline();
await pageObjects.infraHome.closeTimeline();
});

it('toggles the inventory switcher', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this one test just to get familiar with the testing setup.

await pageObjects.infraHome.toggleInventorySwitcher();
});
});

describe('alerts flyouts', () => {
Expand Down
11 changes: 9 additions & 2 deletions x-pack/test/functional/page_objects/infra_home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,16 @@ export function InfraHomePageProvider({ getService, getPageObjects }: FtrProvide
return timelineSelectorsVisible.every((visible) => !visible);
},

async openInvenotrySwitcher() {
async openInventorySwitcher() {
await testSubjects.click('openInventorySwitcher');
return await testSubjects.find('goToHost');
return await testSubjects.find('goToHost1');
},

async toggleInventorySwitcher() {
await testSubjects.click('openInventorySwitcher');
await testSubjects.find('goToHost');
await testSubjects.click('openInventorySwitcher');
return await testSubjects.missingOrFail('goToHost');
},

async goToHost() {
Expand Down