Skip to content

Commit

Permalink
Save in store both created and applied partitioning
Browse files Browse the repository at this point in the history
  • Loading branch information
KKoukiou committed Apr 4, 2024
1 parent a3421bb commit 96a966b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/actions/storage-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ export const getDiskSelectionAction = () => {
};
};

export const getPartitioningDataAction = ({ partitioning, requests }) => {
export const getPartitioningDataAction = ({ isApplied, partitioning, requests }) => {
return async (dispatch) => {
try {
const props = { path: partitioning };
const convertRequests = reqs => reqs.map(request => Object.entries(request).reduce((acc, [key, value]) => ({ ...acc, [key]: value.v }), {}));

if (!requests) {
if (partitioning && !requests) {
props.method = await getPartitioningMethod({ partitioning });
if (props.method === "MANUAL") {
const reqs = await gatherRequests({ partitioning });
Expand All @@ -112,13 +112,13 @@ export const getPartitioningDataAction = ({ partitioning, requests }) => {

props.requests = convertRequests([reqs]);
}
} else {
} else if (partitioning && requests) {
props.requests = convertRequests(requests);
}

return dispatch({
payload: { partitioningData: props, path: partitioning },
type: "GET_PARTITIONING_DATA"
type: isApplied ? "GET_APPLIED_PARTITIONING_DATA" : "GET_CREATED_PARTITIONING_DATA",
});
} catch (error) {
return dispatch(setCriticalErrorAction(error));
Expand Down
4 changes: 3 additions & 1 deletion src/apis/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export class StorageClient {
this.dispatch(getPartitioningDataAction({ partitioning: path, requests: [args[1].Request.v] }));
} else if (args[0] === INTERFACE_NAME && Object.hasOwn(args[1], "CreatedPartitioning")) {
const last = args[1].CreatedPartitioning.v.length - 1;
this.dispatch(getPartitioningDataAction({ partitioning: args[1].CreatedPartitioning.v[last] }));
this.dispatch(getPartitioningDataAction({ isApplied: false, partitioning: args[1].CreatedPartitioning.v[last] }));
} else if (args[0] === INTERFACE_NAME && Object.hasOwn(args[1], "AppliedPartitioning")) {
this.dispatch(getPartitioningDataAction({ isApplied: true, partitioning: args[1].AppliedPartitioning.v }));
} else {
debug(`Unhandled signal on ${path}: ${iface}.${signal} ${JSON.stringify(args)}`);
}
Expand Down
10 changes: 8 additions & 2 deletions src/components/storage/MountPointMapping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ const MountPointMapping = ({
setIsFormValid,
setStepNotification,
}) => {
const { devices, diskSelection, partitioning } = useContext(StorageContext);
const { createdPartitioning, devices, diskSelection } = useContext(StorageContext);
const partitioning = createdPartitioning;
const [usedPartitioning, setUsedPartitioning] = useState();
const canReusePartitioning = useMemo(() => {
// The partitioning can be reused if the devices in the partitioning requests and children
Expand All @@ -624,7 +625,12 @@ const MountPointMapping = ({
const children = devices[device].children.v;
const ancestors = getDeviceAncestors(devices, device);

return children.length === 0 && diskSelection.selectedDisks.some(disk => ancestors.includes(disk));
// btrfs snapshots should not be available
if (devices[device].type.v === "btrfs snapshot") {
return false;
}

return (children.length === 0 || devices[device].type.v === "btrfs subvolume") && diskSelection.selectedDisks.some(disk => ancestors.includes(disk));
});

const usedDevices = partitioning?.requests?.map(r => r["device-spec"]) || [];
Expand Down
5 changes: 4 additions & 1 deletion src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useCallback, useReducer } from "react";

/* Initial state for the storeage store substate */
export const storageInitialState = {
createdPartitioning: {},
deviceNames: [],
devices: {},
diskSelection: {
Expand Down Expand Up @@ -111,8 +112,10 @@ export const storageReducer = (state = storageInitialState, action) => {
return { ...state, deviceNames: action.payload.deviceNames, devices: action.payload.devices };
} else if (action.type === "GET_DISK_SELECTION") {
return { ...state, diskSelection: action.payload.diskSelection };
} else if (action.type === "GET_PARTITIONING_DATA") {
} else if (action.type === "GET_APPLIED_PARTITIONING_DATA") {
return { ...state, partitioning: { ...state.partitioning, ...action.payload.partitioningData } };
} else if (action.type === "GET_CREATED_PARTITIONING_DATA") {
return { ...state, createdPartitioning: { ...state.createdPartitioning, ...action.payload.partitioningData } };
} else if (action.type === "SET_STORAGE_SCENARIO") {
return { ...state, storageScenarioId: action.payload.scenario };
} else {
Expand Down

0 comments on commit 96a966b

Please sign in to comment.