From fc80014682a963625f447a05cb5ca7cb2cb222ba Mon Sep 17 00:00:00 2001 From: Peter Makowski Date: Wed, 7 Jun 2023 07:53:38 +0200 Subject: [PATCH] refactor: rename selected state MAASENG-1837 (#4972) --- src/__snapshots__/root-reducer.test.ts.snap | 3 +- .../node/FieldlessForm/FieldlessForm.test.tsx | 2 +- .../KVMHeaderForms/AddLxd/AddLxd.test.tsx | 8 +++-- .../KVMHeaderForms/KVMHeaderForms.test.tsx | 4 +-- .../KVMHeaderForms/KVMHeaderForms.tsx | 2 +- .../LXDVMsTable/LXDVMsTable.test.tsx | 2 +- .../components/LXDVMsTable/LXDVMsTable.tsx | 4 +-- .../VMsActionBar/VMsActionBar.test.tsx | 4 +-- .../LXDVMsTable/VMsTable/VMsTable.test.tsx | 16 ++++----- .../CloneForm/CloneForm.test.tsx | 23 ++++++------ .../MachineActionFormWrapper.test.tsx | 5 ++- .../MachineActionFormWrapper.tsx | 2 +- .../ReleaseForm/ReleaseForm.test.tsx | 4 +-- .../TableCheckbox/TableCheckbox.test.tsx | 2 +- .../TableCheckbox/TableCheckbox.tsx | 2 +- .../AddBridgeForm/AddBridgeForm.test.tsx | 2 +- .../AddInterface/AddInterface.test.tsx | 2 +- .../EditBridgeForm/EditBridgeForm.test.tsx | 2 +- .../views/MachineList/MachineList.test.tsx | 6 ++-- .../views/MachineList/MachineList.tsx | 2 +- .../MachineListControls.test.tsx | 6 ++-- .../MachineListControls.tsx | 4 +-- .../MachineListHeader.test.tsx | 23 ++++++------ .../MachineListHeader/MachineListHeader.tsx | 4 +-- .../AllCheckbox/AllCheckbox.test.tsx | 14 ++++---- .../AllCheckbox/AllCheckbox.tsx | 2 +- .../GroupCheckbox/GroupCheckbox.test.tsx | 26 +++++++------- .../GroupCheckbox/GroupCheckbox.tsx | 2 +- .../MachineCheckbox/MachineCheckbox.test.tsx | 24 ++++++------- .../MachineCheckbox/MachineCheckbox.tsx | 2 +- .../MachineListSelectedCount.test.tsx | 6 ++-- .../MachineListSelectedCount.tsx | 4 +-- src/app/machines/views/Machines.tsx | 2 +- src/app/store/machine/actions.test.ts | 6 ++-- src/app/store/machine/reducers.test.ts | 24 ++++++------- src/app/store/machine/selectors.test.ts | 4 +-- src/app/store/machine/selectors.ts | 7 ++-- src/app/store/machine/slice.ts | 35 ++++--------------- src/app/store/machine/types/base.ts | 3 +- src/app/store/machine/utils/hooks.test.tsx | 16 ++++----- src/app/store/machine/utils/hooks.ts | 6 ++-- src/globals.d.ts | 3 ++ src/setupTests.ts | 5 +++ src/testing/factories/state.ts | 3 +- src/testing/utils.tsx | 8 ++++- 45 files changed, 158 insertions(+), 178 deletions(-) create mode 100644 src/globals.d.ts diff --git a/src/__snapshots__/root-reducer.test.ts.snap b/src/__snapshots__/root-reducer.test.ts.snap index c0712010a3..270fa25bc6 100644 --- a/src/__snapshots__/root-reducer.test.ts.snap +++ b/src/__snapshots__/root-reducer.test.ts.snap @@ -222,8 +222,7 @@ Object { "loading": false, "saved": false, "saving": false, - "selected": Array [], - "selectedMachines": null, + "selected": null, "statuses": Object {}, }, "message": Object { diff --git a/src/app/base/components/node/FieldlessForm/FieldlessForm.test.tsx b/src/app/base/components/node/FieldlessForm/FieldlessForm.test.tsx index 43f6f9e2e8..366ee21ac4 100644 --- a/src/app/base/components/node/FieldlessForm/FieldlessForm.test.tsx +++ b/src/app/base/components/node/FieldlessForm/FieldlessForm.test.tsx @@ -31,7 +31,7 @@ describe("FieldlessForm", () => { system_id: "abc123", }), ], - selected: [], + selected: null, statuses: { abc123: machineStatusFactory(), }, diff --git a/src/app/kvm/components/KVMHeaderForms/AddLxd/AddLxd.test.tsx b/src/app/kvm/components/KVMHeaderForms/AddLxd/AddLxd.test.tsx index 3a08658b6c..7a14e44d56 100644 --- a/src/app/kvm/components/KVMHeaderForms/AddLxd/AddLxd.test.tsx +++ b/src/app/kvm/components/KVMHeaderForms/AddLxd/AddLxd.test.tsx @@ -164,9 +164,11 @@ describe("AddLxd", () => { ); await userEvent.click(screen.getByRole("button", { name: "Next" })); - expect( - screen.getByRole("listitem", { name: "Credentials" }).firstChild - ).not.toHaveClass("is-active"); + await waitFor(() => + expect( + screen.getByRole("listitem", { name: "Credentials" }).firstChild + ).not.toHaveClass("is-active") + ); expect( screen.getByRole("listitem", { name: "Authentication" }).firstChild ).not.toHaveClass("is-active"); diff --git a/src/app/kvm/components/KVMHeaderForms/KVMHeaderForms.test.tsx b/src/app/kvm/components/KVMHeaderForms/KVMHeaderForms.test.tsx index e4e327790f..ba871bdfad 100644 --- a/src/app/kvm/components/KVMHeaderForms/KVMHeaderForms.test.tsx +++ b/src/app/kvm/components/KVMHeaderForms/KVMHeaderForms.test.tsx @@ -252,7 +252,7 @@ describe("KVMHeaderForms", () => { }); it("renders machine action forms if a machine action is selected", () => { - state.machine.selectedMachines = { items: ["abc123"] }; + state.machine.selected = { items: ["abc123"] }; renderWithBrowserRouter( { }); it("renders machine action forms with selected machine count", () => { - state.machine.selectedMachines = { items: ["abc123", "def456"] }; + state.machine.selected = { items: ["abc123", "def456"] }; renderWithBrowserRouter( { - const selectedMachines = useSelector(machineSelectors.selectedMachines); + const selectedMachines = useSelector(machineSelectors.selected); const { selectedCount } = useMachineSelectedCount(); const onRenderRef = useScrollOnRender(); const clearSidePanelContent = useCallback( diff --git a/src/app/kvm/components/LXDVMsTable/LXDVMsTable.test.tsx b/src/app/kvm/components/LXDVMsTable/LXDVMsTable.test.tsx index f757ad3045..868e5032cf 100644 --- a/src/app/kvm/components/LXDVMsTable/LXDVMsTable.test.tsx +++ b/src/app/kvm/components/LXDVMsTable/LXDVMsTable.test.tsx @@ -75,7 +75,7 @@ describe("LXDVMsTable", () => { unmount(); - const expectedAction = machineActions.setSelectedMachines(null); + const expectedAction = machineActions.setSelected(null); expect( store.getActions().find((action) => action.type === expectedAction.type) ).toStrictEqual(expectedAction); diff --git a/src/app/kvm/components/LXDVMsTable/LXDVMsTable.tsx b/src/app/kvm/components/LXDVMsTable/LXDVMsTable.tsx index a71722f956..b0c53b98de 100644 --- a/src/app/kvm/components/LXDVMsTable/LXDVMsTable.tsx +++ b/src/app/kvm/components/LXDVMsTable/LXDVMsTable.tsx @@ -71,14 +71,14 @@ const LXDVMsTable = ({ // Clear machine selection and close the action form on filters change if (searchFilter !== previousSearchFilter) { setSidePanelContent(null); - dispatch(machineActions.setSelectedMachines(null)); + dispatch(machineActions.setSelected(null)); } }, [searchFilter, previousSearchFilter, setSidePanelContent, dispatch]); useEffect( () => () => { // Clear machine selected state when unmounting. - dispatch(machineActions.setSelectedMachines(null)); + dispatch(machineActions.setSelected(null)); }, [dispatch] ); diff --git a/src/app/kvm/components/LXDVMsTable/VMsActionBar/VMsActionBar.test.tsx b/src/app/kvm/components/LXDVMsTable/VMsActionBar/VMsActionBar.test.tsx index a8e7731bc4..e11a18686c 100644 --- a/src/app/kvm/components/LXDVMsTable/VMsActionBar/VMsActionBar.test.tsx +++ b/src/app/kvm/components/LXDVMsTable/VMsActionBar/VMsActionBar.test.tsx @@ -40,7 +40,7 @@ describe("VMsActionBar", () => { it("disables VM actions if none are selected", () => { const state = rootStateFactory({ machine: machineStateFactory({ - selectedMachines: null, + selected: null, }), }); const store = mockStore(state); @@ -70,7 +70,7 @@ describe("VMsActionBar", () => { const state = rootStateFactory({ machine: machineStateFactory({ items: vms, - selectedMachines: { items: ["abc123"] }, + selected: { items: ["abc123"] }, }), }); const store = mockStore(state); diff --git a/src/app/kvm/components/LXDVMsTable/VMsTable/VMsTable.test.tsx b/src/app/kvm/components/LXDVMsTable/VMsTable/VMsTable.test.tsx index 5007da9bc0..8622ec1fe9 100644 --- a/src/app/kvm/components/LXDVMsTable/VMsTable/VMsTable.test.tsx +++ b/src/app/kvm/components/LXDVMsTable/VMsTable/VMsTable.test.tsx @@ -119,7 +119,7 @@ describe("VMsTable", () => { const state = rootStateFactory({ machine: machineStateFactory({ items: vms, - selectedMachines: null, + selected: null, }), pod: podStateFactory({ items: [pod], loaded: true }), }); @@ -144,11 +144,9 @@ describe("VMsTable", () => { ); expect( - store - .getActions() - .find((action) => action.type === "machine/setSelectedMachines") + store.getActions().find((action) => action.type === "machine/setSelected") ).toStrictEqual({ - type: "machine/setSelectedMachines", + type: "machine/setSelected", payload: { filter: { pod: [pod.name] } }, }); }); @@ -166,7 +164,7 @@ describe("VMsTable", () => { const state = rootStateFactory({ machine: machineStateFactory({ items: vms, - selectedMachines: { filter: {} }, + selected: { filter: {} }, }), pod: podStateFactory({ items: [pod], loaded: true }), }); @@ -195,11 +193,9 @@ describe("VMsTable", () => { ); expect( - store - .getActions() - .find((action) => action.type === "machine/setSelectedMachines") + store.getActions().find((action) => action.type === "machine/setSelected") ).toStrictEqual({ - type: "machine/setSelectedMachines", + type: "machine/setSelected", payload: null, }); }); diff --git a/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/CloneForm/CloneForm.test.tsx b/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/CloneForm/CloneForm.test.tsx index 02559c8fd2..9e908b0398 100644 --- a/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/CloneForm/CloneForm.test.tsx +++ b/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/CloneForm/CloneForm.test.tsx @@ -18,7 +18,12 @@ import { rootState as rootStateFactory, } from "testing/factories"; import { mockFormikFormSaved } from "testing/mockFormikFormSaved"; -import { renderWithBrowserRouter, screen, userEvent } from "testing/utils"; +import { + renderWithBrowserRouter, + screen, + userEvent, + waitFor, +} from "testing/utils"; const mockStore = configureStore(); @@ -45,8 +50,7 @@ describe("CloneForm", () => { active: null, items: machines, loaded: true, - selected: ["abc123"], - + selected: { items: ["abc123"] }, lists: { "123456": machineStateList({ groups: [ @@ -124,8 +128,7 @@ describe("CloneForm", () => { active: null, items: machines, loaded: true, - selected: ["abc123"], - + selected: { items: ["abc123"] }, lists: { "123456": machineStateList({ groups: [ @@ -151,7 +154,6 @@ describe("CloneForm", () => { const { rerender } = renderWithBrowserRouter( { rerender( ); - expect(screen.getByText("Cloning complete")).toBeInTheDocument(); + await waitFor(() => + expect(screen.getByText("Cloning complete")).toBeInTheDocument() + ); }); it("can dispatch an action to clone to the given machines", async () => { @@ -200,8 +204,7 @@ describe("CloneForm", () => { active: null, items: machines, loaded: true, - selected: ["abc123", "def456"], - + selected: { items: ["abc123", "def456"] }, lists: { "123456": machineStateList({ groups: [ diff --git a/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/MachineActionFormWrapper.test.tsx b/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/MachineActionFormWrapper.test.tsx index cbaf48c80b..7c4914805b 100644 --- a/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/MachineActionFormWrapper.test.tsx +++ b/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/MachineActionFormWrapper.test.tsx @@ -126,9 +126,8 @@ it("clears selected machines and invalidates queries on delete success", async ( ); expect( - store - .getActions() - .find((action) => action.type === "machine/setSelectedMachines").payload + store.getActions().find((action) => action.type === "machine/setSelected") + .payload ).toEqual(null); expect( store diff --git a/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/MachineActionFormWrapper.tsx b/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/MachineActionFormWrapper.tsx index c6a299d3a9..7861304a47 100644 --- a/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/MachineActionFormWrapper.tsx +++ b/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/MachineActionFormWrapper.tsx @@ -82,7 +82,7 @@ export const MachineActionFormWrapper = ({ selectedCountLoading, }; const clearSelectedMachines = () => { - dispatch(machineActions.setSelectedMachines(null)); + dispatch(machineActions.setSelected(null)); dispatch(machineActions.invalidateQueries()); }; diff --git a/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/ReleaseForm/ReleaseForm.test.tsx b/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/ReleaseForm/ReleaseForm.test.tsx index c2f08fd1d9..a13c3606dc 100644 --- a/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/ReleaseForm/ReleaseForm.test.tsx +++ b/src/app/machines/components/MachineHeaderForms/MachineActionFormWrapper/ReleaseForm/ReleaseForm.test.tsx @@ -53,7 +53,7 @@ describe("ReleaseForm", () => { }); it("sets the initial disk erase behaviour from global config", () => { - state.machine.selectedMachines = { items: ["abc123", "def456"] }; + state.machine.selected = { items: ["abc123", "def456"] }; state.config.items = [ configFactory({ name: ConfigNames.ENABLE_DISK_ERASING_ON_RELEASE, @@ -91,7 +91,7 @@ describe("ReleaseForm", () => { it("correctly dispatches action to release given machines", async () => { const store = mockStore(state); - state.machine.selectedMachines = { items: ["abc123", "def456"] }; + state.machine.selected = { items: ["abc123", "def456"] }; renderWithBrowserRouter( { { store } ); await userEvent.click(screen.getByRole("checkbox")); - const expected = machineActions.setSelectedMachines(selected); + const expected = machineActions.setSelected(selected); await waitFor(() => { expect( store.getActions().find((action) => action.type === expected.type) diff --git a/src/app/machines/components/TableCheckbox/TableCheckbox.tsx b/src/app/machines/components/TableCheckbox/TableCheckbox.tsx index 8cfcddf449..f5de45b01d 100644 --- a/src/app/machines/components/TableCheckbox/TableCheckbox.tsx +++ b/src/app/machines/components/TableCheckbox/TableCheckbox.tsx @@ -61,7 +61,7 @@ const TableCheckbox = ({ window.getSelection()?.removeAllRanges(); const isRange = !!event.nativeEvent.shiftKey; dispatch( - machineActions.setSelectedMachines( + machineActions.setSelected( onGenerateSelected(event.target.checked, isRange) ) ); diff --git a/src/app/machines/views/MachineDetails/MachineNetwork/AddBridgeForm/AddBridgeForm.test.tsx b/src/app/machines/views/MachineDetails/MachineNetwork/AddBridgeForm/AddBridgeForm.test.tsx index 2f660117ff..4cd2bbf63c 100644 --- a/src/app/machines/views/MachineDetails/MachineNetwork/AddBridgeForm/AddBridgeForm.test.tsx +++ b/src/app/machines/views/MachineDetails/MachineNetwork/AddBridgeForm/AddBridgeForm.test.tsx @@ -117,7 +117,7 @@ describe("AddBridgeForm", () => { }); it("can dispatch an action to add a bridge", async () => { - state.machine.selectedMachines = { items: ["abc123", "def456"] }; + state.machine.selected = { items: ["abc123", "def456"] }; const store = mockStore(state); renderWithBrowserRouter( { }); it("correctly dispatches actions to add a physical interface", async () => { - state.machine.selectedMachines = { items: ["abc123", "def456"] }; + state.machine.selected = { items: ["abc123", "def456"] }; const store = mockStore(state); renderWithBrowserRouter( , diff --git a/src/app/machines/views/MachineDetails/MachineNetwork/EditBridgeForm/EditBridgeForm.test.tsx b/src/app/machines/views/MachineDetails/MachineNetwork/EditBridgeForm/EditBridgeForm.test.tsx index d59a2149e4..c8a7f430e2 100644 --- a/src/app/machines/views/MachineDetails/MachineNetwork/EditBridgeForm/EditBridgeForm.test.tsx +++ b/src/app/machines/views/MachineDetails/MachineNetwork/EditBridgeForm/EditBridgeForm.test.tsx @@ -104,7 +104,7 @@ describe("EditBridgeForm", () => { }); it("can dispatch an action to update a bridge", async () => { - state.machine.selectedMachines = { items: ["abc123", "def456"] }; + state.machine.selected = { items: ["abc123", "def456"] }; const store = mockStore(state); renderWithBrowserRouter( { store.getActions().some((action) => action.type === "machine/cleanup") ).toBe(true); expect( - store - .getActions() - .find((action) => action.type === "machine/setSelectedMachines") + store.getActions().find((action) => action.type === "machine/setSelected") ).toStrictEqual({ - type: "machine/setSelectedMachines", + type: "machine/setSelected", payload: null, }); }); diff --git a/src/app/machines/views/MachineList/MachineList.tsx b/src/app/machines/views/MachineList/MachineList.tsx index e2caf52eec..30829deaa3 100644 --- a/src/app/machines/views/MachineList/MachineList.tsx +++ b/src/app/machines/views/MachineList/MachineList.tsx @@ -73,7 +73,7 @@ const MachineList = ({ () => () => { // Clear machine selected state and clean up any machine errors etc. // when closing the list. - dispatch(machineActions.setSelectedMachines(null)); + dispatch(machineActions.setSelected(null)); dispatch(machineActions.cleanup()); }, [dispatch] diff --git a/src/app/machines/views/MachineList/MachineListControls/MachineListControls.test.tsx b/src/app/machines/views/MachineList/MachineListControls/MachineListControls.test.tsx index 24baa69996..7dcb882f13 100644 --- a/src/app/machines/views/MachineList/MachineListControls/MachineListControls.test.tsx +++ b/src/app/machines/views/MachineList/MachineListControls/MachineListControls.test.tsx @@ -112,7 +112,7 @@ describe("MachineListControls", () => { }); it("hides search bar, filter accordion, and grouping select when machines are selected", () => { - initialState.machine.selectedMachines = { items: ["abc123"] }; + initialState.machine.selected = { items: ["abc123"] }; renderWithBrowserRouter( { }); it("dispatches an action to clear selected machines when the 'Clear selection' button is clicked", async () => { - initialState.machine.selectedMachines = { items: ["abc123"] }; + initialState.machine.selected = { items: ["abc123"] }; const store = mockStore(initialState); renderWithBrowserRouter( { const actions = store.getActions(); expect(actions).toEqual( - expect.arrayContaining([machineActions.setSelectedMachines(null)]) + expect.arrayContaining([machineActions.setSelected(null)]) ); }); }); diff --git a/src/app/machines/views/MachineList/MachineListControls/MachineListControls.tsx b/src/app/machines/views/MachineList/MachineListControls/MachineListControls.tsx index b5f1ccb3bd..275be29756 100644 --- a/src/app/machines/views/MachineList/MachineListControls/MachineListControls.tsx +++ b/src/app/machines/views/MachineList/MachineListControls/MachineListControls.tsx @@ -181,9 +181,7 @@ const MachineListControls = ({
diff --git a/src/app/machines/views/MachineList/MachineListHeader/MachineListHeader.test.tsx b/src/app/machines/views/MachineList/MachineListHeader/MachineListHeader.test.tsx index 0c933f764f..a56c750db9 100644 --- a/src/app/machines/views/MachineList/MachineListHeader/MachineListHeader.test.tsx +++ b/src/app/machines/views/MachineList/MachineListHeader/MachineListHeader.test.tsx @@ -68,7 +68,7 @@ describe("MachineListHeader", () => { }); it("displays a loader if machines have not loaded", () => { - state.machine.selectedMachines = { + state.machine.selected = { groups: ["admin"], grouping: FetchGroupKey.Owner, }; @@ -115,7 +115,7 @@ describe("MachineListHeader", () => { }); it("displays a spinner if the selected group count is loading", () => { - state.machine.selectedMachines = { + state.machine.selected = { groups: ["admin"], grouping: FetchGroupKey.Owner, }; @@ -139,7 +139,7 @@ describe("MachineListHeader", () => { }); it("does not display a spinner if only machines are selected and the count is loading", () => { - state.machine.selectedMachines = { items: ["abc123"] }; + state.machine.selected = { items: ["abc123"] }; state.machine.counts["mocked-nanoid-2"] = machineStateCountFactory({ count: 10, loaded: true, @@ -164,7 +164,7 @@ describe("MachineListHeader", () => { }); it("hides the add hardware menu when machines are selected", () => { - state.machine.selectedMachines = { items: ["abc123"] }; + state.machine.selected = { items: ["abc123"] }; renderWithBrowserRouter( { expect( screen.queryByTestId("add-hardware-dropdown") ).not.toBeInTheDocument(); - state.machine.selectedMachines.items = []; + state.machine.selected.items = []; renderWithBrowserRouter( { }); it("closes action form when all machines are deselected", async () => { - state.machine.selectedMachines = { items: ["abc123"] }; + state.machine.selected = { items: ["abc123"] }; const allMachinesCount = 10; state.machine.counts["mocked-nanoid-2"] = machineStateCountFactory({ count: allMachinesCount, @@ -221,7 +221,7 @@ describe("MachineListHeader", () => { ); expect(setSidePanelContent).not.toHaveBeenCalled(); expect(screen.getByText("Deploy")).toBeInTheDocument(); - state.machine.selectedMachines.items = []; + state.machine.selected = null; renderWithBrowserRouter( { setSidePanelContent={setSidePanelContent} sidePanelContent={{ view: MachineHeaderViews.DEPLOY_MACHINE }} />, - { state, route: urls.machines.index } + { + state: { ...state, machine: { ...state.machine, selected: null } }, + route: urls.machines.index, + } ); await waitFor(() => expect(setSidePanelContent).toHaveBeenCalledWith(null)); }); @@ -266,7 +269,7 @@ describe("MachineListHeader", () => { it("displays a new label for the tag action", async () => { // Set a selected machine so the take action menu becomes enabled. - state.machine.selectedMachines = { items: ["abc123"] }; + state.machine.selected = { items: ["abc123"] }; // A machine needs the tag action for it to appear in the menu. state.machine.items = [ machineFactory({ system_id: "abc123", actions: [NodeActions.TAG] }), @@ -296,7 +299,7 @@ describe("MachineListHeader", () => { it("hides the tag action's new label after it has been clicked", async () => { jest.spyOn(reduxToolkit, "nanoid").mockReturnValue("mocked-nanoid"); // Set a selected machine so the take action menu becomes enabled. - state.machine.selectedMachines = { items: ["abc123"] }; + state.machine.selected = { items: ["abc123"] }; // A machine needs the tag action for it to appear in the menu. const machine = machineFactory({ system_id: "abc123", diff --git a/src/app/machines/views/MachineList/MachineListHeader/MachineListHeader.tsx b/src/app/machines/views/MachineList/MachineListHeader/MachineListHeader.tsx index 8908291964..2ce485944a 100644 --- a/src/app/machines/views/MachineList/MachineListHeader/MachineListHeader.tsx +++ b/src/app/machines/views/MachineList/MachineListHeader/MachineListHeader.tsx @@ -56,7 +56,7 @@ export const MachineListHeader = ({ // Get the count of selected machines that match the current filter const { selectedCount, selectedCountLoading } = useMachineSelectedCount(filter); - const selectedMachines = useSelector(machineSelectors.selectedMachines); + const selectedMachines = useSelector(machineSelectors.selected); // Clear the header when there are no selected machines useEffect(() => { @@ -78,7 +78,7 @@ export const MachineListHeader = ({ // we cannot reliably preserve the selected state for groups of machines // as we are only fetching information about a group from the back-end // and the contents of a group may change when different filters are applied - dispatch(machineActions.setSelectedMachines(null)); + dispatch(machineActions.setSelected(null)); }, [dispatch, setSearchFilter] ); diff --git a/src/app/machines/views/MachineList/MachineListTable/AllCheckbox/AllCheckbox.test.tsx b/src/app/machines/views/MachineList/MachineListTable/AllCheckbox/AllCheckbox.test.tsx index 1a929e1da9..00662be034 100644 --- a/src/app/machines/views/MachineList/MachineListTable/AllCheckbox/AllCheckbox.test.tsx +++ b/src/app/machines/views/MachineList/MachineListTable/AllCheckbox/AllCheckbox.test.tsx @@ -27,7 +27,7 @@ beforeEach(() => { }); it("is unchecked if there are no filters, groups or items selected", () => { - state.machine.selectedMachines = null; + state.machine.selected = null; renderWithMockStore(, { state }); expect( screen.getByRole("checkbox", { name: Label.AllMachines }) @@ -35,7 +35,7 @@ it("is unchecked if there are no filters, groups or items selected", () => { }); it("is checked if there is a selected filter", () => { - state.machine.selectedMachines = { + state.machine.selected = { filter: { owner: "admin", }, @@ -47,7 +47,7 @@ it("is checked if there is a selected filter", () => { }); it("is partially checked if a group is selected", () => { - state.machine.selectedMachines = { + state.machine.selected = { groups: ["admin1"], }; renderWithMockStore(, { state }); @@ -57,7 +57,7 @@ it("is partially checked if a group is selected", () => { }); it("is partially checked if a machine is selected", () => { - state.machine.selectedMachines = { + state.machine.selected = { items: ["abc123"], }; renderWithMockStore(, { state }); @@ -77,7 +77,7 @@ it("can dispatch an action to select all", async () => { await userEvent.click( screen.getByRole("checkbox", { name: Label.AllMachines }) ); - const expected = machineActions.setSelectedMachines({ + const expected = machineActions.setSelected({ filter, }); expect( @@ -89,7 +89,7 @@ it("can dispatch an action to unselect all", async () => { const filter = { owner: ["admin1"], }; - state.machine.selectedMachines = { + state.machine.selected = { filter, }; const store = mockStore(state); @@ -99,7 +99,7 @@ it("can dispatch an action to unselect all", async () => { await userEvent.click( screen.getByRole("checkbox", { name: Label.AllMachines }) ); - const expected = machineActions.setSelectedMachines(null); + const expected = machineActions.setSelected(null); expect( store.getActions().find((action) => action.type === expected.type) ).toStrictEqual(expected); diff --git a/src/app/machines/views/MachineList/MachineListTable/AllCheckbox/AllCheckbox.tsx b/src/app/machines/views/MachineList/MachineListTable/AllCheckbox/AllCheckbox.tsx index cc64a2caf0..6fcf82fb0b 100644 --- a/src/app/machines/views/MachineList/MachineListTable/AllCheckbox/AllCheckbox.tsx +++ b/src/app/machines/views/MachineList/MachineListTable/AllCheckbox/AllCheckbox.tsx @@ -15,7 +15,7 @@ type Props = { }; const AllCheckbox = ({ callId, filter }: Props): JSX.Element => { - const selected = useSelector(machineSelectors.selectedMachines); + const selected = useSelector(machineSelectors.selected); // A filter exists in the selected state when all machines in the current // table are selected. const allSelected = !!selected && "filter" in selected; diff --git a/src/app/machines/views/MachineList/MachineListTable/GroupCheckbox/GroupCheckbox.test.tsx b/src/app/machines/views/MachineList/MachineListTable/GroupCheckbox/GroupCheckbox.test.tsx index 191dd5c438..13f5185c90 100644 --- a/src/app/machines/views/MachineList/MachineListTable/GroupCheckbox/GroupCheckbox.test.tsx +++ b/src/app/machines/views/MachineList/MachineListTable/GroupCheckbox/GroupCheckbox.test.tsx @@ -35,7 +35,7 @@ beforeEach(() => { }); it("is disabled if all machines are selected", () => { - state.machine.selectedMachines = { + state.machine.selected = { filter: { owner: "admin", }, @@ -98,7 +98,7 @@ it("is not disabled if there are machines in the group", () => { }); it("is unchecked if there are no filters, groups or items selected", () => { - state.machine.selectedMachines = null; + state.machine.selected = null; renderWithMockStore( { }); it("is checked if all machines are selected", () => { - state.machine.selectedMachines = { + state.machine.selected = { filter: { owner: "admin", }, @@ -134,7 +134,7 @@ it("is checked if all machines are selected", () => { }); it("is checked if the group is selected", () => { - state.machine.selectedMachines = { + state.machine.selected = { groups: ["admin-2"], }; renderWithMockStore( @@ -159,7 +159,7 @@ it("is partially checked if a machine in the group is selected", () => { value: "admin-2", }); state.machine.lists[callId].groups = [group]; - state.machine.selectedMachines = { + state.machine.selected = { items: ["abc123"], }; renderWithMockStore( @@ -191,7 +191,7 @@ it("is not checked if a selected machine is in another group", () => { }), group, ]; - state.machine.selectedMachines = { + state.machine.selected = { items: ["def456"], }; renderWithMockStore( @@ -222,7 +222,7 @@ it("can dispatch an action to select the group", async () => { } ); await userEvent.click(screen.getByRole("checkbox")); - const expected = machineActions.setSelectedMachines({ + const expected = machineActions.setSelected({ grouping: FetchGroupKey.AgentName, groups: ["admin-2"], }); @@ -239,7 +239,7 @@ it("removes selected machines that are in the group that was clicked", async () value: "admin-2", }); state.machine.lists[callId].groups = [group]; - state.machine.selectedMachines = { + state.machine.selected = { items: ["abc123", "def456"], }; const store = mockStore(state); @@ -255,7 +255,7 @@ it("removes selected machines that are in the group that was clicked", async () } ); await userEvent.click(screen.getByRole("checkbox")); - const expected = machineActions.setSelectedMachines({ + const expected = machineActions.setSelected({ items: ["def456"], groups: [], }); @@ -279,7 +279,7 @@ it("does not overwrite selected machines in different groups", async () => { }), group, ]; - state.machine.selectedMachines = { + state.machine.selected = { items: ["def456"], }; const store = mockStore(state); @@ -295,7 +295,7 @@ it("does not overwrite selected machines in different groups", async () => { } ); await userEvent.click(screen.getByRole("checkbox")); - const expected = machineActions.setSelectedMachines({ + const expected = machineActions.setSelected({ grouping: FetchGroupKey.AgentName, groups: ["admin-2"], items: ["def456"], @@ -321,7 +321,7 @@ it("can dispatch an action to unselect the group", async () => { }), group, ]; - state.machine.selectedMachines = { + state.machine.selected = { groups: ["admin-1", "admin-2"], items: ["def456"], }; @@ -338,7 +338,7 @@ it("can dispatch an action to unselect the group", async () => { } ); await userEvent.click(screen.getByRole("checkbox")); - const expected = machineActions.setSelectedMachines({ + const expected = machineActions.setSelected({ groups: ["admin-1"], items: ["def456"], }); diff --git a/src/app/machines/views/MachineList/MachineListTable/GroupCheckbox/GroupCheckbox.tsx b/src/app/machines/views/MachineList/MachineListTable/GroupCheckbox/GroupCheckbox.tsx index e4a10f50bb..e25e16ccc7 100644 --- a/src/app/machines/views/MachineList/MachineListTable/GroupCheckbox/GroupCheckbox.tsx +++ b/src/app/machines/views/MachineList/MachineListTable/GroupCheckbox/GroupCheckbox.tsx @@ -22,7 +22,7 @@ const GroupCheckbox = ({ grouping, groupName, }: Props): JSX.Element | null => { - const selected = useSelector(machineSelectors.selectedMachines); + const selected = useSelector(machineSelectors.selected); const allSelected = !!selected && "filter" in selected; if (!group) { return null; diff --git a/src/app/machines/views/MachineList/MachineListTable/MachineCheckbox/MachineCheckbox.test.tsx b/src/app/machines/views/MachineList/MachineListTable/MachineCheckbox/MachineCheckbox.test.tsx index 618b3461b0..00bfd8518a 100644 --- a/src/app/machines/views/MachineList/MachineListTable/MachineCheckbox/MachineCheckbox.test.tsx +++ b/src/app/machines/views/MachineList/MachineListTable/MachineCheckbox/MachineCheckbox.test.tsx @@ -37,7 +37,7 @@ beforeEach(() => { }); it("is disabled if all machines are selected", () => { - state.machine.selectedMachines = { + state.machine.selected = { filter: { owner: "admin", }, @@ -55,7 +55,7 @@ it("is disabled if all machines are selected", () => { }); it("is checked and disabled if the machine's group is selected", () => { - state.machine.selectedMachines = { + state.machine.selected = { groups: ["admin2"], }; renderWithMockStore( @@ -72,7 +72,7 @@ it("is checked and disabled if the machine's group is selected", () => { }); it("is checked and disabled if the machine's group is selected and is nullish", () => { - state.machine.selectedMachines = { + state.machine.selected = { groups: [""], }; renderWithMockStore( @@ -89,7 +89,7 @@ it("is checked and disabled if the machine's group is selected and is nullish", }); it("is unchecked and enabled if there are no filters or groups selected", () => { - state.machine.selectedMachines = null; + state.machine.selected = null; renderWithMockStore( }); it("is checked if the machine is selected", () => { - state.machine.selectedMachines = { + state.machine.selected = { items: ["abc123"], }; renderWithMockStore( @@ -133,14 +133,14 @@ it("can dispatch an action to select the machine", async () => { } ); await userEvent.click(screen.getByRole("checkbox")); - const expected = machineActions.setSelectedMachines({ items: ["abc123"] }); + const expected = machineActions.setSelected({ items: ["abc123"] }); expect( store.getActions().find((action) => action.type === expected.type) ).toStrictEqual(expected); }); it("can dispatch an action to unselect a machine", async () => { - state.machine.selectedMachines = { + state.machine.selected = { groups: ["admin1"], items: ["abc123", "def456"], }; @@ -157,7 +157,7 @@ it("can dispatch an action to unselect a machine", async () => { } ); await userEvent.click(screen.getByRole("checkbox")); - const expected = machineActions.setSelectedMachines({ + const expected = machineActions.setSelected({ groups: ["admin1"], items: ["def456"], }); @@ -176,13 +176,13 @@ describe("getSelectedMachinesRange tests", () => { const machines = systemIds.map((id) => machineFactory({ system_id: id })); it("getSelectedMachinesRange selects a range of machines", () => { - const selectedMachines = { groups: [""], items: [systemIds[0]] }; + const selected = { groups: [""], items: [systemIds[0]] }; const systemId = systemIds.at(-1)!; const newSelected = getSelectedMachinesRange({ systemId, machines, - selected: selectedMachines, + selected: selected, }); expect(newSelected.items?.sort()).toStrictEqual(systemIds.sort()); @@ -190,12 +190,12 @@ describe("getSelectedMachinesRange tests", () => { it("Selects only one machine if there's no previously selected machine", () => { const systemId = systemIds[0]; - const selectedMachines = { groups: [""], items: [] }; + const selected = { groups: [""], items: [] }; const newSelected = getSelectedMachinesRange({ systemId, machines, - selected: selectedMachines, + selected: selected, }); const { items } = newSelected; expect(items?.length).toBe(1); diff --git a/src/app/machines/views/MachineList/MachineListTable/MachineCheckbox/MachineCheckbox.tsx b/src/app/machines/views/MachineList/MachineListTable/MachineCheckbox/MachineCheckbox.tsx index 3b35e34506..d2b064d618 100644 --- a/src/app/machines/views/MachineList/MachineListTable/MachineCheckbox/MachineCheckbox.tsx +++ b/src/app/machines/views/MachineList/MachineListTable/MachineCheckbox/MachineCheckbox.tsx @@ -79,7 +79,7 @@ const MachineCheckbox = ({ systemId, machines, }: Props): JSX.Element => { - const selected = useSelector(machineSelectors.selectedMachines); + const selected = useSelector(machineSelectors.selected); const allSelected = !!selected && "filter" in selected; // Whether the group this machine appears in is selected. const groupSelected = diff --git a/src/app/machines/views/MachineList/MachineListTable/MachineListSelectedCount/MachineListSelectedCount.test.tsx b/src/app/machines/views/MachineList/MachineListTable/MachineListSelectedCount/MachineListSelectedCount.test.tsx index 095851c0d8..cb065578fb 100644 --- a/src/app/machines/views/MachineList/MachineListTable/MachineListSelectedCount/MachineListSelectedCount.test.tsx +++ b/src/app/machines/views/MachineList/MachineListTable/MachineListSelectedCount/MachineListSelectedCount.test.tsx @@ -91,7 +91,7 @@ describe("MachineListSelectedCount", () => { screen.getByRole("button", { name: "Select all 20 machines" }) ); - const expectedAction = machineActions.setSelectedMachines({ filter: {} }); + const expectedAction = machineActions.setSelected({ filter: {} }); expect( store.getActions().find((action) => action.type === expectedAction.type) @@ -113,7 +113,7 @@ describe("MachineListSelectedCount", () => { screen.getByRole("button", { name: "Select all 20 filtered machines" }) ); - const expectedAction = machineActions.setSelectedMachines({ + const expectedAction = machineActions.setSelected({ filter: { free_text: ["this-is-a-filter"] }, }); @@ -137,7 +137,7 @@ describe("MachineListSelectedCount", () => { screen.getByRole("button", { name: "Clear selection" }) ); - const expectedAction = machineActions.setSelectedMachines(null); + const expectedAction = machineActions.setSelected(null); expect( store.getActions().find((action) => action.type === expectedAction.type) diff --git a/src/app/machines/views/MachineList/MachineListTable/MachineListSelectedCount/MachineListSelectedCount.tsx b/src/app/machines/views/MachineList/MachineListTable/MachineListSelectedCount/MachineListSelectedCount.tsx index d366407168..85ed585f29 100644 --- a/src/app/machines/views/MachineList/MachineListTable/MachineListSelectedCount/MachineListSelectedCount.tsx +++ b/src/app/machines/views/MachineList/MachineListTable/MachineListSelectedCount/MachineListSelectedCount.tsx @@ -27,7 +27,7 @@ export const MachineListSelectedCount = ({ appearance="link" onClick={() => { dispatch( - machineActions.setSelectedMachines({ + machineActions.setSelected({ filter: FilterMachines.parseFetchFilters(filter), }) ); @@ -45,7 +45,7 @@ export const MachineListSelectedCount = ({