Skip to content

Commit

Permalink
web: Load devices in the proposal page
Browse files Browse the repository at this point in the history
- Unit tests not adapted yet
  • Loading branch information
joseivanlopez committed Mar 8, 2024
1 parent acc1bf6 commit 82bad46
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions web/src/components/storage/ProposalPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const initialState = {
volumeTemplates: [],
encryptionMethods: [],
settings: {},
system: [],
staging: [],
actions: [],
errors: []
};
Expand Down Expand Up @@ -80,6 +82,11 @@ const reducer = (state, action) => {
return { ...state, settings };
}

case "UPDATE_DEVICES": {
const { system, staging } = action.payload;
return { ...state, system, staging };
}

case "UPDATE_ERRORS": {
const { errors } = action.payload;
return { ...state, errors };
Expand Down Expand Up @@ -120,6 +127,12 @@ export default function ProposalPage() {
return await cancellablePromise(client.proposal.getResult());
}, [client, cancellablePromise]);

const loadDevices = useCallback(async () => {
const system = await cancellablePromise(client.system.getDevices()) || [];
const staging = await cancellablePromise(client.staging.getDevices()) || [];
return { system, staging };
}, [client, cancellablePromise]);

const loadErrors = useCallback(async () => {
const issues = await cancellablePromise(client.getErrors());
return issues.map(toValidationError);
Expand Down Expand Up @@ -151,11 +164,14 @@ export default function ProposalPage() {
const result = await loadProposalResult();
if (result !== undefined) dispatch({ type: "UPDATE_RESULT", payload: { result } });

const devices = await loadDevices();
dispatch({ type: "UPDATE_DEVICES", payload: devices });

const errors = await loadErrors();
dispatch({ type: "UPDATE_ERRORS", payload: { errors } });

if (result !== undefined) dispatch({ type: "STOP_LOADING" });
}, [calculateProposal, cancellablePromise, client, loadAvailableDevices, loadEncryptionMethods, loadErrors, loadProposalResult, loadVolumeTemplates]);
}, [calculateProposal, cancellablePromise, client, loadAvailableDevices, loadDevices, loadEncryptionMethods, loadErrors, loadProposalResult, loadVolumeTemplates]);

const calculate = useCallback(async (settings) => {
dispatch({ type: "START_LOADING" });
Expand All @@ -165,11 +181,14 @@ export default function ProposalPage() {
const result = await loadProposalResult();
dispatch({ type: "UPDATE_RESULT", payload: { result } });

const devices = await loadDevices();
dispatch({ type: "UPDATE_DEVICES", payload: devices });

const errors = await loadErrors();
dispatch({ type: "UPDATE_ERRORS", payload: { errors } });

dispatch({ type: "STOP_LOADING" });
}, [calculateProposal, loadErrors, loadProposalResult]);
}, [calculateProposal, loadDevices, loadErrors, loadProposalResult]);

useEffect(() => {
load().catch(console.error);
Expand Down

0 comments on commit 82bad46

Please sign in to comment.