Skip to content

Commit

Permalink
Fix upgrade frontend page state on success
Browse files Browse the repository at this point in the history
  • Loading branch information
jcapona committed Aug 20, 2024
1 parent 4ebba67 commit 7c7a9ae
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
6 changes: 6 additions & 0 deletions frontend/src/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export default [
rest.get("/further-url", (_, res, ctx) => {
return res(ctx.json({ url: "https://further.pi-top.com" }));
}),
rest.get("/available-space", (_, res, ctx) => {
return res(ctx.body("20378521600"));
}),
rest.get("/rover-controller-status", (_, res, ctx) => {
return res(ctx.json({ status: "inactive" }));
}),
Expand All @@ -48,6 +51,9 @@ export default [
rest.post("/rover-controller-stop", (_, res, ctx) => {
return res(ctx.body("OK"));
}),
rest.post("/restart-web-portal-service", (_, res, ctx) => {
return res(ctx.body("OK"));
}),
rest.get("/is-connected", (_, res, ctx) => {
return res(ctx.json({ connected: false }));
}),
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/pages/upgradePage/UpgradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export default ({
const [isNewOsDialogActive, setIsNewOsDialogActive] = useState(false);
const [isRetrying, setIsRetrying] = useState(false);

const displayProgressBar = false;

useEffect(() => {
setIsNewOsDialogActive(requireBurn || shouldBurn);
}, [requireBurn, shouldBurn]);
Expand Down Expand Up @@ -291,7 +293,8 @@ export default ({
{(message?.type === OSUpdaterMessageType.Upgrade ||
message?.type === OSUpdaterMessageType.UpdateSources) &&
updateState !== UpdateState.WaitingForServer &&
!hasError() && (
!hasError() &&
displayProgressBar && (
<div data-testid="progress" className={styles.progress}>
<ProgressBar
percent={message.payload.percent}
Expand Down
17 changes: 4 additions & 13 deletions frontend/src/pages/upgradePage/UpgradePageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default ({ goToNextPage, goToPreviousPage, hideSkip, isCompleted, setEnab
checkingWebPortalRef.current = true;
setState(UpdateState.UpdatingSources);
},
[socket],
[setError, setUpdateSize, setState],
)

useEffect(() => {
Expand Down Expand Up @@ -357,18 +357,9 @@ export default ({ goToNextPage, goToPreviousPage, hideSkip, isCompleted, setEnab

return (
<UpgradePage
onNextClick={() => {
setEnableDisconnectedFromApDialog && setEnableDisconnectedFromApDialog(true);
goToNextPage && goToNextPage()
}}
onSkipClick={() => {
setEnableDisconnectedFromApDialog && setEnableDisconnectedFromApDialog(true);
goToNextPage && goToNextPage()
}}
onBackClick={() => {
setEnableDisconnectedFromApDialog && setEnableDisconnectedFromApDialog(true);
goToPreviousPage && goToPreviousPage()
}}
onNextClick={goToNextPage}
onSkipClick={goToNextPage}
onBackClick={goToPreviousPage}
hideSkip={hideSkip}
onStartUpgradeClick={() => {
if (isOpen) {
Expand Down
2 changes: 0 additions & 2 deletions pt_os_web_portal/backend/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,6 @@ def os_upgrade(ws):
"prepare_web_portal": get_os_updater().stage_web_portal,
"start": get_os_updater().start_os_upgrade,
"size": get_os_updater().upgrade_size,
"legacy-updater-backend": get_os_updater().use_legacy_backend,
"default-updater-backend": get_os_updater().use_default_backend,
"state": get_os_updater().state,
}

Expand Down
13 changes: 7 additions & 6 deletions pt_os_web_portal/os_updater/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ def str_to_float(text):
return float(text)


units = {"B": 1, "KB": 10**3, "kB": 10**3, "MB": 10**6, "GB": 10**9, "TB": 10**12}


def size_str_to_bytes(size):
units = {"B": 1, "KB": 1e3, "kB": 1e3, "MB": 1e6, "GB": 1e9, "TB": 1e12}
number, unit = [string.strip() for string in size.split()]
return int(float(number) * units[unit])

Expand Down Expand Up @@ -154,12 +152,15 @@ def _parse_install_size_and_packages(self, line):
line_arr = line.split()
if "disk space" in line:
try:
# Sometimes partial downloads are required when a network error prevents from completing a previous upgrade.
# In this case, we need to get the first number before the '/'
# eg: 'Need to get 11.4 kB/1,861 kB of archives.'
self.required_space_str = (
f"{str_to_float(line_arr[3])} {line_arr[4].split('/')[0]}"
)
self._required_space = size_str_to_bytes(self.required_space_str)
except Exception:
self._required_space = 1
self._required_space = 0
self.required_space_str = f"{self._required_space} M"
elif "Need to get" in line:
try:
Expand All @@ -168,13 +169,13 @@ def _parse_install_size_and_packages(self, line):
)
self._download_size = size_str_to_bytes(self.download_size_str)
except Exception:
self._download_size = 1
self._download_size = 0
self.download_size_str = f"{self._download_size} M"
elif "newly installed" in line:
try:
self._install_count = int(line_arr[0]) + int(line_arr[2])
except Exception:
self._install_count = 1
self._install_count = 0

def _do_stage_upgrade(self, packages):
self._download_size = 0
Expand Down

0 comments on commit 7c7a9ae

Please sign in to comment.