-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(eye-icon): Change visibility eye icon to button (#765)
* wip move eye icon from table and change to button * wip show number of columns hidden * restrict button shrink to fit column text * fix column button size and wip visbility button test * wip mock onToggle * osFiltering rendering error * new test * mock state and onToggle function and clean up tests * remove old visibility code and test * add asChild prop to fix accessibility issue * address comments on PR wip * avoid min width on button * remove unused export * destructure props and make columns filter more explicit --------- Co-authored-by: Tiffany Vu <[email protected]> Co-authored-by: Tiffany Vu <[email protected]> Co-authored-by: 13bfrancis <[email protected]>
- Loading branch information
1 parent
6bad9c4
commit 45c528f
Showing
5 changed files
with
103 additions
and
24 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
react-app/src/components/Opensearch/main/Filtering/Filtering.test.tsx
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,69 @@ | ||
import { useState } from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { describe, expect, test, beforeEach } from "vitest"; | ||
import { type OsTableColumn, VisibilityPopover } from "../index"; | ||
|
||
const MockOsFilteringWrapper = () => { | ||
const [columns, setColumns] = useState<OsTableColumn[]>([ | ||
{ | ||
field: "state.keyword", | ||
label: "State", | ||
cell: () => "", | ||
}, | ||
{ | ||
field: "authority.keyword", | ||
label: "Authority", | ||
cell: () => "", | ||
}, | ||
{ | ||
field: "stateStatus.keyword", | ||
label: "Status", | ||
hidden: true, | ||
cell: () => "", | ||
}, | ||
]); | ||
|
||
const onToggle = (field: string) => { | ||
setColumns((state) => { | ||
return state?.map((S) => { | ||
if (S.field !== field) return S; | ||
return { ...S, hidden: !S.hidden }; | ||
}); | ||
}); | ||
}; | ||
|
||
return ( | ||
<VisibilityPopover | ||
list={columns.filter((COL) => !COL.locked || COL.field)} | ||
onItemClick={onToggle} | ||
hiddenColumns={columns.filter((COL) => COL.hidden === true)} | ||
/> | ||
); | ||
}; | ||
|
||
describe("Visibility button", () => { | ||
beforeEach(() => { | ||
render(<MockOsFilteringWrapper />); | ||
}); | ||
|
||
test("Visibility button should show number of hidden columns if any", async () => { | ||
expect(screen.getByText("Columns (1 hidden)")).toBeInTheDocument(); | ||
await userEvent.click(screen.getByText("Columns (1 hidden)")); | ||
|
||
const stateColumnMenuItem = screen.getByText("State"); | ||
await userEvent.click(stateColumnMenuItem); | ||
|
||
expect(screen.getByText("Columns (2 hidden)")).toBeInTheDocument(); | ||
}); | ||
|
||
test("Visibility button text should not show number if no hidden columns", async () => { | ||
expect(screen.getByText("Columns (1 hidden)")).toBeInTheDocument(); | ||
await userEvent.click(screen.getByText("Columns (1 hidden)")); | ||
|
||
const statusColumnMenuItem = screen.getByText("Status"); | ||
await userEvent.click(statusColumnMenuItem); | ||
|
||
expect(screen.getByText("Columns")).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