Skip to content
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

[OUR415-314] Fixes eligibility and category lists in Browse Experience #258

Merged
merged 22 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions app/components/search/Refinements/BrowseRefinementList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,17 @@ import { InstantSearch } from "react-instantsearch-core";
import { render, screen, waitFor } from "@testing-library/react";
import BrowseRefinementList from "components/search/Refinements/BrowseRefinementList";
import { createSearchClient } from "../../../../test/helpers/createSearchClient";
import { createRandomCategories } from "../../../../test/helpers/createRandomCategories";

describe("BrowseRefinementList", () => {
test("renders the default limit of 10 refinements", async () => {
test("renders all categories returned by the search client", async () => {
const numCategories = 25;
const searchClient = createSearchClient({
facets: {
categories: {
A: 54,
B: 35,
C: 28,
D: 24,
E: 18,
F: 14,
G: 14,
H: 12,
I: 45,
J: 79,
K: 1,
L: 31,
},
categories: createRandomCategories(numCategories),
},
});

const expected = 10;

render(
<InstantSearch
searchClient={searchClient}
Expand All @@ -38,7 +25,7 @@ describe("BrowseRefinementList", () => {

await waitFor(() => {
expect(screen.getAllByTestId("browserefinementlist-item")).toHaveLength(
expected
numCategories
);
});
});
Expand Down
4 changes: 4 additions & 0 deletions app/components/search/Refinements/BrowseRefinementList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ interface Props extends UseRefinementListProps {
attribute: string;
}

// Arbitrary upper limit to ensure all refinements are displayed
const MAXIMUM_ITEMS = 9999;

/**
* Facet refinement list component for browse interfaces
*/
Expand All @@ -16,6 +19,7 @@ const BrowseRefinementList = ({ attribute, transform }: Props) => {
attribute,
sortBy: ["name:asc"],
transformItems: transform,
limit: MAXIMUM_ITEMS,
});

useEffect(() => {
Expand Down
3 changes: 2 additions & 1 deletion app/components/search/Refinements/SearchRefinementList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ interface Props extends UseRefinementListProps {
}

const DEFAULT_CONFIG = {
limit: 100,
// Arbitrary upper limit to ensure all refinements are displayed
limit: 9999,
operator: "or" as const,
};

Expand Down
3 changes: 2 additions & 1 deletion app/components/search/Sidebar/Sidebar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
align-self: flex-start;
border-right: 0;
background-color: #fff;
z-index: $z-index-filters-menu;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Discovered a bug where the filters were not on top.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of z-indexes. The category dropdown appears to have a higher z-index than the navigation bar. If that would be a quick fix, might make sense to put it in this PR

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What browser/resolution is that? I don't even know how to get in that state 😅

}

@media screen and (max-width: $break-tablet-s) {
Expand Down Expand Up @@ -67,7 +68,7 @@

@media screen and (max-width: $break-tablet-s) {
width: 100%;
top: 65px;
top: 131px;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
animation-name: slideUp;
Expand Down
24 changes: 11 additions & 13 deletions app/components/ui/Navigation/DropdownMenu.module.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
@import "../../../styles/utils/_helpers.scss";
@import "../../../styles/utils/_colors.scss";

.navigationMenuContainer {
// Important to override react-burger-menu lib styles
display: flex !important;
flex-direction: column;
align-items: center;
Comment on lines -5 to -8
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: We got rid of the react-burger-menu lib so these declarations are no longer necessary.


> * {
font-size: 18px;
font-family: Montserrat;
}
.navigationMenuContainer > * {
font-size: 18px;
font-family: Montserrat;
}

.navigationSubMenu {
Expand All @@ -22,6 +15,11 @@
border-radius: $rounded-md;
overflow: hidden;
font-weight: 400;
width: max-content;

@media screen and (max-width: $break-tablet-s) {
top: 46px;
}
}

.navigationMenuHeader {
Expand Down Expand Up @@ -92,11 +90,11 @@

.categoryMenuContainer {
position: relative;
min-width: 160px;

.navigationSubMenu {
top: 50px;
left: 0;
@include r_max($break-tablet-s) {
width: calc(100vw - $general-spacing-xs);
}
Comment on lines +95 to +97
Copy link
Collaborator Author

@rosschapman rosschapman Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This expands the top level category dropdown full width. Had not implemented it yet.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering - Is there a reason for choosing general-spacing-xs? Or for adding that only on the category dropdown rather the nav dropdown too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only that I discovered this variable defined the correct spacing.

}

.navigationMenuHeader {
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@babel/preset-typescript": "^7.24.7",
"@babel/register": "^7.4.4",
"@eslint/js": "^9.10.0",
"@faker-js/faker": "^9.2.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
Expand Down
20 changes: 20 additions & 0 deletions test/helpers/createRandomCategories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { faker } from "@faker-js/faker";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: cool 😎


/**
* Generates an object of categories for use in search refinement components
*
* @param size Customize the number of categories
*/
export function createRandomCategories(size: number) {
const result: { [key: string]: number } = {};

for (let i = 0; i < size; i++) {
// Append incrementor because the current version of faker does not support
// uniqueness
const key = `${faker.company.name()}_${i}`;
const value = faker.number.int(100);
result[key] = value;
}

return result;
}
Loading