-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): show issues on their related section
- Loading branch information
Showing
8 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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>; | ||
} | ||
|
||
function useIssues() { | ||
const context = useContext(IssuesContext); | ||
|
||
if (!context) { | ||
throw new Error("useIssues must be used within an IssuesProvider"); | ||
} | ||
|
||
return context; | ||
} | ||
|
||
export { IssuesProvider, useIssues }; |