-
Notifications
You must be signed in to change notification settings - Fork 326
feat: use checkboxes to render multi-select field #4380
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
63 changes: 63 additions & 0 deletions
63
web_src/src/ui/configurationFieldRenderer/MultiSelectFieldRenderer.spec.tsx
This file contains hidden or 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,63 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { ConfigurationField } from "@/api-client"; | ||
| import { MultiSelectFieldRenderer } from "./MultiSelectFieldRenderer"; | ||
|
|
||
| function createField(useCheckboxes: boolean): ConfigurationField { | ||
| return { | ||
| name: "deliveryChannels", | ||
| label: "Delivery channels", | ||
| type: "multi-select", | ||
| typeOptions: { | ||
| multiSelect: { | ||
| useCheckboxes, | ||
| options: [ | ||
| { | ||
| label: "Email", | ||
| value: "email", | ||
| description: "Send notifications by email.", | ||
| }, | ||
| { | ||
| label: "Slack", | ||
| value: "slack", | ||
| description: "Post notifications to a Slack channel.", | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| describe("MultiSelectFieldRenderer", () => { | ||
| it("renders checkbox options with descriptions when useCheckboxes is enabled", () => { | ||
| render(<MultiSelectFieldRenderer field={createField(true)} value={["email"]} onChange={vi.fn()} />); | ||
|
|
||
| expect(screen.getByRole("checkbox", { name: /Email/ })).toHaveAttribute("aria-checked", "true"); | ||
| expect(screen.getByRole("checkbox", { name: /Slack/ })).toHaveAttribute("aria-checked", "false"); | ||
| expect(screen.getByText("Send notifications by email.")).toBeInTheDocument(); | ||
| expect(screen.getByText("Post notifications to a Slack channel.")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("adds values when a checkbox is checked", async () => { | ||
| const user = userEvent.setup(); | ||
| const handleChange = vi.fn(); | ||
|
|
||
| render(<MultiSelectFieldRenderer field={createField(true)} value={[]} onChange={handleChange} />); | ||
|
|
||
| await user.click(screen.getByRole("checkbox", { name: /Email/ })); | ||
|
|
||
| expect(handleChange).toHaveBeenCalledWith(["email"]); | ||
| }); | ||
|
|
||
| it("sends undefined when the last selected value is unchecked", async () => { | ||
| const user = userEvent.setup(); | ||
| const handleChange = vi.fn(); | ||
|
|
||
| render(<MultiSelectFieldRenderer field={createField(true)} value={["email"]} onChange={handleChange} />); | ||
|
|
||
| await user.click(screen.getByRole("checkbox", { name: /Email/ })); | ||
|
|
||
| expect(handleChange).toHaveBeenCalledWith(undefined); | ||
| }); | ||
| }); |
141 changes: 112 additions & 29 deletions
141
web_src/src/ui/configurationFieldRenderer/MultiSelectFieldRenderer.tsx
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.