Skip to content

Commit

Permalink
refactor(machines): rename selected state #1256 (#4572)
Browse files Browse the repository at this point in the history
  • Loading branch information
petermakowski authored Nov 22, 2022
1 parent f6c6f01 commit 6512639
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("ReleaseForm", () => {

it("sets the initial disk erase behaviour from global config", () => {
const store = mockStore(state);
state.machine.selected = ["abc123", "def456"];
state.machine.selectedMachines = { items: ["abc123", "def456"] };
state.config.items = [
configFactory({
name: ConfigNames.ENABLE_DISK_ERASING_ON_RELEASE,
Expand Down Expand Up @@ -97,7 +97,7 @@ describe("ReleaseForm", () => {

it("correctly dispatches action to release given machines", () => {
const store = mockStore(state);
state.machine.selected = ["abc123", "def456"];
state.machine.selectedMachines = { items: ["abc123", "def456"] };
const wrapper = mount(
<Provider store={store}>
<MemoryRouter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("AddBridgeForm", () => {
});

it("can dispatch an action to add a bridge", async () => {
state.machine.selected = ["abc123", "def456"];
state.machine.selectedMachines = { items: ["abc123", "def456"] };
const store = mockStore(state);
renderWithBrowserRouter(
<AddBridgeForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("AddInterface", () => {
});

it("correctly dispatches actions to add a physical interface", async () => {
state.machine.selected = ["abc123", "def456"];
state.machine.selectedMachines = { items: ["abc123", "def456"] };
const store = mockStore(state);
renderWithBrowserRouter(
<AddInterface close={jest.fn()} systemId="abc123" />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe("EditBridgeForm", () => {
});

it("can dispatch an action to update a bridge", () => {
state.machine.selected = ["abc123", "def456"];
state.machine.selectedMachines = { items: ["abc123", "def456"] };
const store = mockStore(state);
const wrapper = mount(
<Provider store={store}>
Expand Down
2 changes: 0 additions & 2 deletions src/app/machines/views/MachineList/MachineList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const MachineList = ({
useWindowTitle("Machines");
const dispatch = useDispatch();
const errors = useSelector(machineSelectors.errors);
const selectedIDs = useSelector(machineSelectors.selectedIDs);
const [currentPage, setCurrentPage] = useState(1);
const [sortKey, setSortKey] = useState<FetchGroupKey | null>(
DEFAULTS.sortKey
Expand Down Expand Up @@ -130,7 +129,6 @@ const MachineList = ({
machines={machines}
machinesLoading={loading}
pageSize={PAGE_SIZE}
selectedIDs={selectedIDs}
setCurrentPage={setCurrentPage}
setHiddenGroups={setHiddenGroups}
setSortDirection={setSortDirection}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ describe("MachineListTable", () => {
machineCount={10}
machines={machines}
pageSize={20}
selectedIDs={[machines[0].system_id]}
setCurrentPage={jest.fn()}
setHiddenGroups={jest.fn()}
setSortDirection={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type Props = {
machines: Machine[];
machinesLoading?: boolean | null;
pageSize: number;
selectedIDs?: Machine[MachineMeta.PK][];
setCurrentPage: (currentPage: number) => void;
setHiddenGroups?: (hiddenGroups: (string | null)[]) => void;
showActions?: boolean;
Expand All @@ -84,7 +83,6 @@ type GenerateRowParams = {
hiddenColumns: NonNullable<Props["hiddenColumns"]>;
machines: Machine[];
onToggleMenu: (systemId: Machine[MachineMeta.PK], open: boolean) => void;
selectedIDs: NonNullable<Props["selectedIDs"]>;
showActions: Props["showActions"];
showMAC: boolean;
};
Expand Down Expand Up @@ -395,7 +393,6 @@ const generateGroupRows = ({
groups,
hiddenGroups,
machines,
selectedIDs,
setHiddenGroups,
showActions,
hiddenColumns,
Expand Down Expand Up @@ -487,7 +484,6 @@ const generateGroupRows = ({
callId,
groupValue: group.value,
machines: visibleMachines,
selectedIDs,
showActions,
hiddenColumns,
})
Expand All @@ -507,7 +503,6 @@ export const MachineListTable = ({
machines,
machinesLoading,
pageSize,
selectedIDs = [],
setCurrentPage,
setHiddenGroups,
showActions = true,
Expand Down Expand Up @@ -795,7 +790,6 @@ export const MachineListTable = ({
groups,
hiddenGroups,
machines,
selectedIDs,
setHiddenGroups,
hiddenColumns,
...rowProps,
Expand Down
16 changes: 0 additions & 16 deletions src/app/store/machine/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,6 @@ describe("machine selectors", () => {
});
});

it("can get the unselected machines", () => {
const [selectedMachine, activeMachine, unselectedMachine] = [
machineFactory(),
machineFactory(),
machineFactory(),
];
const state = rootStateFactory({
machine: machineStateFactory({
active: activeMachine.system_id,
items: [activeMachine, selectedMachine, unselectedMachine],
selected: [selectedMachine.system_id],
}),
});
expect(machine.unselected(state)).toEqual([unselectedMachine]);
});

it("can get the errors state", () => {
const state = rootStateFactory({
machine: machineStateFactory({
Expand Down
43 changes: 0 additions & 43 deletions src/app/store/machine/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ const machineState = (state: RootState): MachineState =>
const activeID = (state: RootState): Machine[MachineMeta.PK] | null =>
state.machine.active;

/**
* Returns selected machine system_ids.
* @param {RootState} state - The redux state.
* @returns {Machine["system_id"][]} Selected machine system_ids.
*/
const selectedIDs = (state: RootState): Machine[MachineMeta.PK][] =>
state.machine.selected;

/**
* Returns all machine statuses.
* @param {RootState} state - The redux state.
Expand Down Expand Up @@ -153,25 +145,6 @@ const active = createSelector(
machines.find((machine) => activeID === machine.system_id)
);

/**
* Returns selected machines.
* @param {RootState} state - The redux state.
* @returns {Machine[]} Selected machines.
*/
const selected = createSelector(
[defaultSelectors.all, selectedIDs],
(machines: Machine[], selectedIDs: Machine[MachineMeta.PK][]) =>
selectedIDs.reduce<Machine[]>((selectedMachines, id) => {
const selectedMachine = machines.find(
(machine) => id === machine.system_id
);
if (selectedMachine) {
selectedMachines.push(selectedMachine);
}
return selectedMachines;
}, [])
);

/**
* Returns selected machines.
* @param {RootState} state - The redux state.
Expand All @@ -182,19 +155,6 @@ const selectedMachines = createSelector(
({ selectedMachines }) => selectedMachines
);

/**
* Returns machines that are neither active nor selected.
* @param state - The redux state.
* @returns Unselected machines.
*/
const unselected = createSelector(
[defaultSelectors.all, selectedIDs, activeID],
(machines, selectedIDs, activeID) =>
machines.filter(
(machine) => ![...selectedIDs, activeID].includes(machine.system_id)
)
);

/**
* Select the event errors for all machines.
* @param state - The redux state.
Expand Down Expand Up @@ -687,8 +647,6 @@ const selectors = {
overridingFailedTesting: statusSelectors["overridingFailedTesting"],
processing,
releasing: statusSelectors["releasing"],
selected,
selectedIDs,
selectedMachines,
settingPool: statusSelectors["settingPool"],
settingZone: statusSelectors["settingZone"],
Expand All @@ -699,7 +657,6 @@ const selectors = {
turningOn: statusSelectors["turningOn"],
unlocking: statusSelectors["unlocking"],
unlinkingSubnet: statusSelectors["unlinkingSubnet"],
unselected,
untagging: statusSelectors["untagging"],
unusedIdsInCall,
updatingTags,
Expand Down

0 comments on commit 6512639

Please sign in to comment.