-
Notifications
You must be signed in to change notification settings - Fork 28
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
WD-8399 - Create add secrets panel #1692
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { screen } from "@testing-library/react"; | ||
|
||
import { renderComponent } from "testing/utils"; | ||
|
||
import AddSecretPanel, { TestId } from "./AddSecretPanel"; | ||
|
||
describe("AddSecretPanel", () => { | ||
it("renders", async () => { | ||
renderComponent(<AddSecretPanel />); | ||
expect(screen.getByTestId(TestId.PANEL)).toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { | ||
ActionButton, | ||
Button, | ||
Notification, | ||
} from "@canonical/react-components"; | ||
import { Form, Formik } from "formik"; | ||
import { useId, useState, useRef } from "react"; | ||
|
||
import Panel from "components/Panel"; | ||
import ScrollOnRender from "components/ScrollOnRender"; | ||
import { usePanelQueryParams } from "panels/hooks"; | ||
|
||
import Fields from "./Fields"; | ||
import { RotatePolicy, type FormFields } from "./types"; | ||
|
||
export enum TestId { | ||
PANEL = "add-secret-panel", | ||
} | ||
|
||
export enum Label { | ||
CANCEL = "Cancel", | ||
SUBMIT = "Add secret", | ||
} | ||
|
||
const AddSecretPanel = () => { | ||
const scrollArea = useRef<HTMLDivElement>(null); | ||
const formId = useId(); | ||
const [, , handleRemovePanelQueryParams] = usePanelQueryParams<{ | ||
panel: string | null; | ||
}>({ | ||
panel: null, | ||
}); | ||
const [inlineError, setInlineError] = useState<string[] | null>(null); | ||
const [saving, setSaving] = useState<boolean>(false); | ||
return ( | ||
<> | ||
{inlineError ? ( | ||
<ScrollOnRender scrollArea={scrollArea?.current}> | ||
<Notification severity="negative">{inlineError}</Notification> | ||
</ScrollOnRender> | ||
) : null} | ||
<Panel | ||
data-testid={TestId.PANEL} | ||
drawer={ | ||
<> | ||
<Button onClick={handleRemovePanelQueryParams}> | ||
{Label.CANCEL} | ||
</Button> | ||
<ActionButton | ||
appearance="positive" | ||
disabled={saving} | ||
form={formId} | ||
loading={saving} | ||
type="submit" | ||
> | ||
{Label.SUBMIT} | ||
</ActionButton> | ||
</> | ||
} | ||
onRemovePanelQueryParams={handleRemovePanelQueryParams} | ||
ref={scrollArea} | ||
title="Add a secret" | ||
width="narrow" | ||
> | ||
<Formik<FormFields> | ||
initialValues={{ | ||
content: "", | ||
description: "", | ||
expiryTime: "", | ||
isBase64: false, | ||
label: "", | ||
rotatePolicy: RotatePolicy.NEVER, | ||
}} | ||
onSubmit={(values) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the secret will be created in https://warthogs.atlassian.net/browse/WD-8546. |
||
setSaving(true); | ||
setInlineError(null); | ||
handleRemovePanelQueryParams(); | ||
}} | ||
> | ||
<Form id={formId}> | ||
<Fields /> | ||
</Form> | ||
</Formik> | ||
</Panel> | ||
</> | ||
); | ||
}; | ||
|
||
export default AddSecretPanel; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { screen } from "@testing-library/react"; | ||
import { Formik } from "formik"; | ||
|
||
import { renderComponent } from "testing/utils"; | ||
|
||
import Fields from "./Fields"; | ||
|
||
describe("Fields", () => { | ||
it("renders", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a placeholder test for when the functionality is added in https://warthogs.atlassian.net/browse/WD-8546. |
||
renderComponent( | ||
<Formik initialValues={{}} onSubmit={jest.fn()}> | ||
<Fields /> | ||
</Formik>, | ||
); | ||
expect(screen.getByRole("textbox", { name: "Label" })).toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Input, Select, Textarea } from "@canonical/react-components"; | ||
import { Field } from "formik"; | ||
|
||
import { RotatePolicy } from "../types"; | ||
|
||
export enum Label { | ||
CONTENT = "Content", | ||
DESCRIPTION = "Description", | ||
EXPIRY_TIME = "Expiry time", | ||
IS_BASE_64 = "Is base64 encoded", | ||
LABEL = "Label", | ||
ROTATE_POLICY = "Rotate policy", | ||
} | ||
|
||
const Fields = (): JSX.Element => { | ||
return ( | ||
<> | ||
<Field | ||
// Have to manually set the id until this issue has been fixed: | ||
// https://github.com/canonical/react-components/issues/957 | ||
id={Label.LABEL} | ||
label={Label.LABEL} | ||
name="label" | ||
as={Input} | ||
type="text" | ||
/> | ||
<Field | ||
// Have to manually set the id until this issue has been fixed: | ||
// https://github.com/canonical/react-components/issues/957 | ||
id={Label.DESCRIPTION} | ||
label={Label.DESCRIPTION} | ||
name="description" | ||
as={Textarea} | ||
/> | ||
<Field | ||
// Have to manually set the id until this issue has been fixed: | ||
// https://github.com/canonical/react-components/issues/957 | ||
id={Label.CONTENT} | ||
label={Label.CONTENT} | ||
name="content" | ||
as={Textarea} | ||
/> | ||
<Field | ||
// Have to manually set the id until this issue has been fixed: | ||
// https://github.com/canonical/react-components/issues/957 | ||
id={Label.IS_BASE_64} | ||
label={Label.IS_BASE_64} | ||
name="isBase64" | ||
as={Input} | ||
type="checkbox" | ||
/> | ||
<Field | ||
type="datetime-local" | ||
// Have to manually set the id until this issue has been fixed: | ||
// https://github.com/canonical/react-components/issues/957 | ||
id={Label.EXPIRY_TIME} | ||
label={Label.EXPIRY_TIME} | ||
name="expire-time" | ||
as={Input} | ||
/> | ||
<Field | ||
// Have to manually set the id until this issue has been fixed: | ||
// https://github.com/canonical/react-components/issues/957 | ||
id={Label.ROTATE_POLICY} | ||
label={Label.ROTATE_POLICY} | ||
name="rotate-policy" | ||
as={Select} | ||
options={Object.values(RotatePolicy).map((option) => ({ | ||
label: option, | ||
value: option, | ||
}))} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default Fields; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./Fields"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./AddSecretPanel"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export enum RotatePolicy { | ||
NEVER = "never", | ||
HOURLY = "hourly", | ||
DAILY = "daily", | ||
WEEKLY = "weekly", | ||
MONTHLY = "monthly", | ||
QUARTERLY = "quarterly", | ||
YEARLY = "yearly", | ||
} | ||
|
||
export type FormFields = { | ||
content: string; | ||
description: string; | ||
expiryTime: string; | ||
isBase64: boolean; | ||
label: string; | ||
rotatePolicy: RotatePolicy; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a placeholder test for when the functionality is added in https://warthogs.atlassian.net/browse/WD-8546.