Skip to content

Commit

Permalink
Merge pull request #821 from openSUSE/fix-loading
Browse files Browse the repository at this point in the history
Properly track the status
  • Loading branch information
imobachgs authored Oct 26, 2023
2 parents b5920ac + 494bb5a commit ff4fc26
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 58 deletions.
7 changes: 7 additions & 0 deletions web/package/cockpit-agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Oct 26 16:07:02 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Properly track the status changes. It prevents of getting stuck
in the first page when there are multiple products
(gh#openSUSE/agama#821).

-------------------------------------------------------------------
Thu Oct 26 05:58:15 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
23 changes: 15 additions & 8 deletions web/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
Disclosure,
Installation,
IssuesLink,
LoadingEnvironment,
LogsButton,
ShowLogButton,
ShowTerminalButton,
Expand Down Expand Up @@ -63,6 +62,18 @@ function App() {
const [status, setStatus] = useState(undefined);
const [phase, setPhase] = useState(undefined);

useEffect(() => {
if (client) {
return client.manager.onPhaseChange(setPhase);
}
}, [client, setPhase]);

useEffect(() => {
if (client) {
return client.manager.onStatusChange(setStatus);
}
}, [client, setStatus]);

useEffect(() => {
const loadPhase = async () => {
const phase = await client.manager.getPhase();
Expand All @@ -71,22 +82,18 @@ function App() {
setStatus(status);
};

if (client) loadPhase().catch(console.error);
}, [client, setPhase, setStatus]);

useEffect(() => {
if (client) {
return client.manager.onPhaseChange(setPhase);
loadPhase().catch(console.error);
}
}, [client, setPhase]);
}, [client, setPhase, setStatus]);

const Content = () => {
if (!client || !products) {
return (attempt > ATTEMPTS) ? <DBusError /> : <Loading />;
}

if ((phase === STARTUP && status === BUSY) || phase === undefined || status === undefined) {
return <LoadingEnvironment onStatusChange={setStatus} />;
return <Loading />;
}

if (phase === INSTALL) {
Expand Down
13 changes: 7 additions & 6 deletions web/src/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jest.mock("~/context/software", () => ({
// Mock some components,
// See https://www.chakshunyu.com/blog/how-to-mock-a-react-component-in-jest/#default-export
jest.mock("~/components/core/DBusError", () => <div>D-BusError Mock</div>);
jest.mock("~/components/core/LoadingEnvironment", () => () => <div>LoadingEnvironment Mock</div>);
jest.mock("~/components/questions/Questions", () => () => <div>Questions Mock</div>);
jest.mock("~/components/core/Installation", () => () => <div>Installation Mock</div>);
jest.mock("~/components/core/Sidebar", () => () => <div>Sidebar Mock</div>);
Expand All @@ -56,6 +55,7 @@ const getPhaseFn = jest.fn();

// capture the latest subscription to the manager#onPhaseChange for triggering it manually
const onPhaseChangeFn = cb => { callbacks.onPhaseChange = cb };
const onStatusChangeFn = cb => { callbacks.onStatusChange = cb };
const changePhaseTo = phase => act(() => callbacks.onPhaseChange(phase));

describe("App", () => {
Expand All @@ -68,6 +68,7 @@ describe("App", () => {
getStatus: getStatusFn,
getPhase: getPhaseFn,
onPhaseChange: onPhaseChangeFn,
onStatusChange: onStatusChangeFn,
},
language: {
getUILanguage: jest.fn().mockResolvedValue("en-us"),
Expand All @@ -92,7 +93,7 @@ describe("App", () => {
mockProducts = undefined;
});

it("renders the LoadingEnvironment screen", async () => {
it("renders the Loading screen", async () => {
installerRender(<App />, { withL10n: true });
await screen.findByText(/Loading installation environment/);
});
Expand All @@ -104,9 +105,9 @@ describe("App", () => {
getStatusFn.mockResolvedValue(BUSY);
});

it("renders the LoadingEnvironment screen", async () => {
it("renders the Loading screen", async () => {
installerRender(<App />, { withL10n: true });
await screen.findByText("LoadingEnvironment Mock");
await screen.findByText(/Loading installation environment/);
});
});

Expand All @@ -116,10 +117,10 @@ describe("App", () => {
getStatusFn.mockResolvedValue(BUSY);
});

it("renders the LoadingEnvironment component", async () => {
it("renders the Loading screen", async () => {
installerRender(<App />, { withL10n: true });

await screen.findByText("LoadingEnvironment Mock");
await screen.findByText(/Loading installation environment/);
});
});

Expand Down
43 changes: 0 additions & 43 deletions web/src/components/core/LoadingEnvironment.jsx

This file was deleted.

1 change: 0 additions & 1 deletion web/src/components/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export { default as InstallButton } from "./InstallButton";
export { default as IssuesLink } from "./IssuesLink";
export { default as IssuesPage } from "./IssuesPage";
export { default as SectionSkeleton } from "./SectionSkeleton";
export { default as LoadingEnvironment } from "./LoadingEnvironment";
export { default as LogsButton } from "./LogsButton";
export { default as FileViewer } from "./FileViewer";
export { default as RowActions } from "./RowActions";
Expand Down

0 comments on commit ff4fc26

Please sign in to comment.