-
Notifications
You must be signed in to change notification settings - Fork 256
TICKET-614: Add case sensitivy to group search #7938
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
Open
Naragod
wants to merge
3
commits into
master
Choose a base branch
from
TICKET-614_add_case_sensitivity_to_group_search
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,70 @@ export function textFilter({filter, onChange, column}) { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Locale-aware substring match with optional case sensitivity. null/undefined | ||
| * arguments are treated as the empty string, so callers do not have to guard | ||
| * against them. | ||
| */ | ||
| export function caseSensitiveIncludes(haystack, needle, caseSensitive) { | ||
| const a = haystack == null ? "" : String(haystack); | ||
| const b = needle == null ? "" : String(needle); | ||
| if (caseSensitive) return a.includes(b); | ||
| return a.toLocaleLowerCase().includes(b.toLocaleLowerCase()); | ||
| } | ||
|
|
||
| /** | ||
| * filterMethod that matches `row[filter.id]` against the filter's search text | ||
| * with the filter's own case sensitivity. Pair with `caseSensitiveTextFilter`, | ||
| * which stores `{filterValue, caseSensitive}` as the filter value. Empty | ||
| * filters match every row. | ||
| */ | ||
| export function caseSensitiveStringFilterMethod(filter, row) { | ||
| const {filterValue, caseSensitive} = filter.value; | ||
| if (!filterValue) return true; | ||
| return caseSensitiveIncludes(row[filter.id], filterValue, caseSensitive); | ||
| } | ||
|
|
||
| /** | ||
| * A Filter component pairing a text input with an "Aa" checkbox toggle for | ||
| * case-sensitive matching. It owns both the search text and the toggle, | ||
| * passing them to the table together via `onChange` as | ||
| * `{filterValue, caseSensitive}`. Matching defaults to case-sensitive. Pair | ||
| * with `caseSensitiveStringFilterMethod`, or a custom filterMethod that reads | ||
| * `filter.value.filterValue` and `filter.value.caseSensitive`. | ||
| */ | ||
| export function caseSensitiveTextFilter({filter, onChange, column}) { | ||
| const filterValue = filter ? filter.value.filterValue : ""; | ||
| const caseSensitive = filter ? filter.value.caseSensitive : true; | ||
|
Collaborator
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. let's make the default |
||
|
|
||
| return ( | ||
| <div style={{display: "flex", alignItems: "center", gap: "4px"}}> | ||
| <input | ||
| type="text" | ||
| style={{flex: 1, minWidth: 0}} | ||
| value={filterValue} | ||
| aria-label={`${I18n.t("search")} ${column.Header || ""}`} | ||
| onChange={event => onChange({filterValue: event.target.value, caseSensitive})} | ||
| /> | ||
| <label | ||
| title={I18n.t("table.case_sensitive_search")} | ||
| style={{display: "flex", alignItems: "center", cursor: "pointer"}} | ||
| > | ||
| <input | ||
| type="checkbox" | ||
| checked={caseSensitive} | ||
| onChange={event => onChange({filterValue, caseSensitive: event.target.checked})} | ||
| aria-label={I18n.t("table.case_sensitive_search")} | ||
| data-testid={`${column.id}_case_sensitive`} | ||
| /> | ||
| <span style={{fontSize: "1.05em", marginLeft: "2px"}}> | ||
| {I18n.t("table.case_sensitive_indicator")} | ||
| </span> | ||
| </label> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Select-based search filter. Options are generated from the custom column attribute | ||
| * filterOptions, which is a list of objects with keys "value" and "text". | ||
|
|
||
75 changes: 75 additions & 0 deletions
75
app/javascript/Components/__tests__/annotation_usage_panel.test.jsx
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,75 @@ | ||
| /*** | ||
| * Tests for AnnotationUsagePanel Component | ||
| */ | ||
|
|
||
| import {AnnotationUsagePanel} from "../annotation_usage_panel"; | ||
| import {render, screen, fireEvent} from "@testing-library/react"; | ||
|
|
||
| jest.mock("@fortawesome/react-fontawesome", () => ({ | ||
| FontAwesomeIcon: () => null, | ||
| })); | ||
|
|
||
| describe("For the AnnotationUsagePanel's group name search", () => { | ||
| beforeEach(async () => { | ||
| const applications = [ | ||
| { | ||
| result_id: 1, | ||
| user_name: "alice", | ||
| first_name: "Alice", | ||
| last_name: "First", | ||
| group_name: "Alpha_001", | ||
| count: 1, | ||
| }, | ||
| { | ||
| result_id: 2, | ||
| user_name: "bob", | ||
| first_name: "Bob", | ||
| last_name: "Second", | ||
| group_name: "alpha_002", | ||
| count: 1, | ||
| }, | ||
| { | ||
| result_id: 3, | ||
| user_name: "carol", | ||
| first_name: "Carol", | ||
| last_name: "Third", | ||
| group_name: "Beta_003", | ||
| count: 1, | ||
| }, | ||
| ]; | ||
| fetch.mockReset(); | ||
| fetch.mockResolvedValueOnce({ | ||
| ok: true, | ||
| json: jest.fn().mockResolvedValueOnce(applications), | ||
| }); | ||
|
|
||
| render(<AnnotationUsagePanel course_id={1} assignment_id={1} annotation_id={1} num_used={3} />); | ||
|
|
||
| fireEvent.click(screen.getByText(I18n.t("annotations.usage"))); | ||
| await screen.findByText("(alice) Alice First"); | ||
| }); | ||
|
|
||
| it("is case-sensitive by default", () => { | ||
| const groupSearch = screen.getByRole("textbox", { | ||
| name: `${I18n.t("search")} ${I18n.t("activerecord.models.submission.one")}`, | ||
| }); | ||
| fireEvent.change(groupSearch, {target: {value: "Alpha"}}); | ||
|
|
||
| expect(screen.getByText("(alice) Alice First")).toBeInTheDocument(); | ||
| expect(screen.queryByText("(bob) Bob Second")).not.toBeInTheDocument(); | ||
| expect(screen.queryByText("(carol) Carol Third")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("becomes case-insensitive when the toggle is unchecked", () => { | ||
| fireEvent.click(screen.getByTestId("group_name_case_sensitive")); | ||
|
|
||
| const groupSearch = screen.getByRole("textbox", { | ||
| name: `${I18n.t("search")} ${I18n.t("activerecord.models.submission.one")}`, | ||
| }); | ||
| fireEvent.change(groupSearch, {target: {value: "alpha"}}); | ||
|
|
||
| expect(screen.getByText("(alice) Alice First")).toBeInTheDocument(); | ||
| expect(screen.getByText("(bob) Bob Second")).toBeInTheDocument(); | ||
| expect(screen.queryByText("(carol) Carol Third")).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
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.
I don't like using
==as it introduces type coercion. Please use the more explicithaystack === null || haystack === undefinedinstead.