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

Disable Add hardware toggle when machines are selected. #960

Merged
merged 4 commits into from
Apr 8, 2020
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 @@ -29,7 +29,7 @@ const getAddHardwareLinks = (navigationOptions) => {
: links;
};

export const AddHardwareMenu = () => {
export const AddHardwareMenu = ({ disabled = false }) => {
const dispatch = useDispatch();
const navigationOptions = useSelector(generalSelectors.navigationOptions.get);

Expand All @@ -44,6 +44,7 @@ export const AddHardwareMenu = () => {
links={getAddHardwareLinks(navigationOptions)}
position="right"
toggleAppearance="neutral"
toggleDisabled={disabled}
toggleLabel="Add hardware"
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ describe("AddHardwareMenu", () => {
.children
).toBe("RSD");
});

it("can be disabled", () => {
const state = { ...initialState };

const store = mockStore(state);
const wrapper = mount(
<Provider store={store}>
<MemoryRouter
initialEntries={[{ pathname: "/machines", key: "testKey" }]}
>
<AddHardwareMenu disabled />
</MemoryRouter>
</Provider>
);

expect(wrapper.find("ContextualMenu").props().toggleDisabled).toBe(true);
});
});
8 changes: 7 additions & 1 deletion ui/src/app/machines/components/HeaderStrip/HeaderStrip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button, Col, Loader, Row } from "@canonical/react-components";
import PropTypes from "prop-types";
import pluralize from "pluralize";
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
Expand All @@ -16,6 +17,7 @@ export const HeaderStrip = () => {
const machines = useSelector(machineSelectors.all);
const machinesLoaded = useSelector(machineSelectors.loaded);
const selectedMachines = useSelector(machineSelectors.selected);
const hasSelectedMachines = selectedMachines.length > 0;

const [selectedAction, setSelectedAction] = useState();

Expand Down Expand Up @@ -64,7 +66,7 @@ export const HeaderStrip = () => {
{!selectedAction && (
<>
<li className="p-inline-list__item">
<AddHardwareMenu />
<AddHardwareMenu disabled={hasSelectedMachines} />
</li>
<li className="p-inline-list__item last-item">
<TakeActionMenu setSelectedAction={setSelectedAction} />
Expand Down Expand Up @@ -92,4 +94,8 @@ export const HeaderStrip = () => {
);
};

HeaderStrip.propTypes = {
disabled: PropTypes.bool,
};

export default HeaderStrip;
19 changes: 19 additions & 0 deletions ui/src/app/machines/components/HeaderStrip/HeaderStrip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ describe("HeaderStrip", () => {
expect(wrapper.find('Button[data-test="add-pool"]').length).toBe(0);
});

it("disables the add hardware menu when machines are selected", () => {
const state = { ...initialState };
state.machine.selected = ["foo"];
const store = mockStore(state);
const wrapper = mount(
<Provider store={store}>
<MemoryRouter
initialEntries={[{ pathname: "/machines", key: "testKey" }]}
>
<HeaderStrip selectedMachines={[]} setSelectedMachines={jest.fn()} />
</MemoryRouter>
</Provider>
);
expect(
wrapper.find('ContextualMenu[data-test="add-hardware-dropdown"]').props()
.toggleDisabled
).toBe(true);
});

it(`displays add pool button and not hardware dropdown when
at pools route`, () => {
const state = { ...initialState };
Expand Down