Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): add issues to the corresponding pages #1313

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { HTTPClient } from "./http";
* @typedef {(issues: Issues) => void} IssuesHandler
*/

const createIssuesList = (product, software, storage, users) => {
const createIssuesList = (product = [], software = [], storage = [], users = []) => {
const list = { product, storage, software, users };
list.isEmpty = !Object.values(list).some(v => v.length > 0);
return list;
Expand Down Expand Up @@ -155,4 +155,4 @@ const createDefaultClient = async () => {
return createClient(httpUrl);
};

export { createClient, createDefaultClient, phase };
export { createClient, createDefaultClient, phase, createIssuesList };
43 changes: 43 additions & 0 deletions web/src/components/core/IssuesHint.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) [2023] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact SUSE LLC.
*
* To contact SUSE LLC about this file by physical or electronic mail, you may
* find current contact information at www.suse.com.
*/

import React from "react";
import { Hint, HintBody, List, ListItem, Stack } from "@patternfly/react-core";
import { _ } from "~/i18n";

export default function IssuesHint({ issues }) {
if (issues === undefined || issues.length === 0) return;

return (
<Hint>
<HintBody>
<Stack hasGutter>
<p>
{_("Please, pay attention to the following tasks:")}
</p>
<List>
{issues.map((i, idx) => <ListItem key={idx}>{i.description}</ListItem>)}
</List>
</Stack>
</HintBody>
</Hint>
);
}
35 changes: 35 additions & 0 deletions web/src/components/core/IssuesHint.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) [2022-2023] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact SUSE LLC.
*
* To contact SUSE LLC about this file by physical or electronic mail, you may
* find current contact information at www.suse.com.
*/

import React from "react";
import { screen } from "@testing-library/react";
import { plainRender } from "~/test-utils";
import { IssuesHint } from "~/components/core";

it("renders a list of issues", () => {
const issue = {
description: "You need to create a user",
source: "config",
severity: "error"
};
plainRender(<IssuesHint issues={[issue]} />);
expect(screen.getByText(issue.description)).toBeInTheDocument();
});
1 change: 1 addition & 0 deletions web/src/components/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export { default as InstallationFinished } from "./InstallationFinished";
export { default as InstallationProgress } from "./InstallationProgress";
export { default as InstallButton } from "./InstallButton";
export { default as IssuesDialog } from "./IssuesDialog";
export { default as IssuesHint } from "./IssuesHint";
export { default as SectionSkeleton } from "./SectionSkeleton";
export { default as ListSearch } from "./ListSearch";
export { default as LoginPage } from "./LoginPage";
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/overview/OverviewPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const IssuesList = ({ issues }) => {
issues.forEach((issue, idx) => {
const link = (
<ListItem key={idx}>
<Link to={scope}>{issue.description}</Link>
<Link to={`/${scope}`}>{issue.description}</Link>
</ListItem>
);
list.push(link);
Expand Down Expand Up @@ -114,7 +114,7 @@ export default function OverviewPage() {
</CardField>
</GridItem>
<GridItem sm={12} xl={6}>
<CardField label="Installation">
<CardField>
<CardBody>
<Stack hasGutter>
{issues.isEmpty ? <ReadyForInstallation /> : <IssuesList issues={issues} />}
Expand Down
11 changes: 7 additions & 4 deletions web/src/components/software/SoftwarePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
// @ts-check

import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";

import { ButtonLink, CardField, Page, Section, SectionSkeleton } from "~/components/core";
import UsedSize from "./UsedSize";
import { useInstallerClient } from "~/context/installer";
import { useCancellablePromise } from "~/utils";
import { useIssues } from "~/context/issues";
import { BUSY } from "~/client/status";
import { _ } from "~/i18n";
import { ButtonLink, CardField, IssuesHint, Page, SectionSkeleton } from "~/components/core";
import UsedSize from "./UsedSize";
import { SelectedBy } from "~/client/software";
import {
Card,
CardBody,
DescriptionList,
DescriptionListDescription,
Expand Down Expand Up @@ -109,6 +108,7 @@ const SelectedPatternsList = ({ patterns }) => {
* @returns {JSX.Element}
*/
function SoftwarePage() {
const { software: issues } = useIssues();
const [status, setStatus] = useState(BUSY);
const [patterns, setPatterns] = useState([]);
const [isLoading, setIsLoading] = useState(true);
Expand Down Expand Up @@ -157,6 +157,9 @@ function SoftwarePage() {

<Page.MainContent>
<Grid hasGutter>
<GridItem sm={12}>
<IssuesHint issues={issues} />
</GridItem>
<GridItem sm={12} xl={6}>
<CardField
label={_("Selected patterns")}
Expand Down
10 changes: 8 additions & 2 deletions web/src/components/users/UsersPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import React from "react";

import { _ } from "~/i18n";
import { CardField, Page } from "~/components/core";
import { CardField, IssuesHint, Page } from "~/components/core";
import { FirstUser, RootAuthMethods } from "~/components/users";
import { Card, CardBody, Grid, GridItem, Stack } from "@patternfly/react-core";
import { CardBody, Grid, GridItem, Stack } from "@patternfly/react-core";
import { useIssues } from "~/context/issues";

export default function UsersPage() {
const { users: issues } = useIssues();

return (
<>
<Page.Header>
Expand All @@ -35,6 +38,9 @@ export default function UsersPage() {

<Page.MainContent>
<Grid hasGutter>
<GridItem sm={12}>
<IssuesHint issues={issues} />
</GridItem>
<GridItem sm={12} xl={6}>
<CardField label={_("First user")}>
<CardBody>
Expand Down
5 changes: 4 additions & 1 deletion web/src/context/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { InstallerClientProvider } from "./installer";
import { InstallerL10nProvider } from "./installerL10n";
import { L10nProvider } from "./l10n";
import { ProductProvider } from "./product";
import { IssuesProvider } from "./issues";

/**
* Combines all application providers.
Expand All @@ -39,7 +40,9 @@ function AppProviders({ children }) {
<InstallerL10nProvider>
<L10nProvider>
<ProductProvider>
{children}
<IssuesProvider>
{children}
</IssuesProvider>
</ProductProvider>
</L10nProvider>
</InstallerL10nProvider>
Expand Down
73 changes: 73 additions & 0 deletions web/src/context/issues.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) [2024] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact SUSE LLC.
*
* To contact SUSE LLC about this file by physical or electronic mail, you may
* find current contact information at www.suse.com.
*/

import React, { useContext, useEffect, useState } from "react";
import { useCancellablePromise } from "~/utils";
import { useInstallerClient } from "./installer";
import { createIssuesList } from "~/client";

/**
* @typedef {import ("~/client").Issues} Issues list
*/

const IssuesContext = React.createContext({});

function IssuesProvider({ children }) {
const [issues, setIssues] = useState(createIssuesList());
const { cancellablePromise } = useCancellablePromise();
const client = useInstallerClient();

useEffect(() => {
const loadIssues = async () => {
const issues = await cancellablePromise(client.issues());
setIssues(issues);
};

if (client) {
loadIssues();
}
}, [client, cancellablePromise, setIssues]);

useEffect(() => {
if (!client) return;

return client.onIssuesChange((updated) => {
setIssues({ ...issues, ...updated });
});
}, [client, issues, setIssues]);

return <IssuesContext.Provider value={issues}>{children}</IssuesContext.Provider>;
}

/**
* @return {Issues}
*/
function useIssues() {
const context = useContext(IssuesContext);

if (!context) {
throw new Error("useIssues must be used within an IssuesProvider");
}

return context;
}

export { IssuesProvider, useIssues };
Loading