-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WD-8528 - feat: Display errors in Actions Panel (#1691)
- Loading branch information
1 parent
aa059d2
commit 0559f36
Showing
6 changed files
with
195 additions
and
32 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
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,49 @@ | ||
import { render } from "@testing-library/react"; | ||
|
||
import PanelInlineErrors from "./PanelInlineErrors"; | ||
|
||
describe("PanelInlineErrors", () => { | ||
it("shouldn't render if there is no inline error", () => { | ||
render(<PanelInlineErrors inlineErrors={[null]} />); | ||
const notifications = document.getElementsByClassName( | ||
"p-notification__message", | ||
); | ||
expect(notifications).toHaveLength(0); | ||
}); | ||
|
||
it("should render inline errors", () => { | ||
render( | ||
<PanelInlineErrors | ||
inlineErrors={["Error 1", <button>Error 2</button>]} | ||
/>, | ||
); | ||
const notifications = document.getElementsByClassName( | ||
"p-notification__message", | ||
); | ||
expect(notifications).toHaveLength(2); | ||
expect(notifications[0]).toHaveTextContent(/Error 1/); | ||
expect(notifications[1]).toHaveTextContent(/Error 2/); | ||
}); | ||
|
||
it("shouldn't scroll on render in there is no inline error", () => { | ||
render( | ||
<PanelInlineErrors | ||
inlineErrors={[null]} | ||
scrollArea={document.createElement("div")} | ||
/>, | ||
); | ||
expect(window.HTMLElement.prototype.scrollIntoView).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should scroll on render if there are inline errors", () => { | ||
render( | ||
<PanelInlineErrors | ||
inlineErrors={[<button>Error</button>]} | ||
scrollArea={document.createElement("div")} | ||
/>, | ||
); | ||
expect(window.HTMLElement.prototype.scrollIntoView).toHaveBeenCalledWith({ | ||
behavior: "smooth", | ||
}); | ||
}); | ||
}); |
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,27 @@ | ||
import { Notification } from "@canonical/react-components"; | ||
import type { ReactNode } from "react"; | ||
|
||
import ScrollOnRender from "components/ScrollOnRender"; | ||
|
||
type Props = { | ||
inlineErrors: ReactNode[] | null; | ||
scrollArea?: HTMLElement | null; | ||
}; | ||
|
||
const PanelInlineErrors = ({ | ||
inlineErrors, | ||
scrollArea, | ||
}: Props): JSX.Element | null => | ||
inlineErrors && inlineErrors.some((error) => error) ? ( | ||
<ScrollOnRender scrollArea={scrollArea}> | ||
{inlineErrors.map((error, index) => | ||
error ? ( | ||
<Notification key={index} severity="negative"> | ||
{error} | ||
</Notification> | ||
) : null, | ||
)} | ||
</ScrollOnRender> | ||
) : null; | ||
|
||
export default PanelInlineErrors; |
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 @@ | ||
export { default } from "./PanelInlineErrors"; |