From 82bad46a7135c20bba5424b0f6b50ed6fe417ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 12:42:14 +0000 Subject: [PATCH] web: Load devices in the proposal page - Unit tests not adapted yet --- web/src/components/storage/ProposalPage.jsx | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/web/src/components/storage/ProposalPage.jsx b/web/src/components/storage/ProposalPage.jsx index 51ab17e7bf..ccb3bfdf4c 100644 --- a/web/src/components/storage/ProposalPage.jsx +++ b/web/src/components/storage/ProposalPage.jsx @@ -41,6 +41,8 @@ const initialState = { volumeTemplates: [], encryptionMethods: [], settings: {}, + system: [], + staging: [], actions: [], errors: [] }; @@ -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 }; @@ -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); @@ -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" }); @@ -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);