-
Notifications
You must be signed in to change notification settings - Fork 152
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
feat: add show only framed works filter #15108
Open
MounirDhahri
wants to merge
2
commits into
main
Choose a base branch
from
feat/support-framed-filtering
base: main
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,11 +94,12 @@ export const AlertProvider: FC<React.PropsWithChildren<AlertProviderProps>> = ({ | |
if (isEditMode || isAlertArtworksView) return | ||
const criteria = getAllowedSearchCriteria(initialCriteria ?? {}) | ||
|
||
// `forSale` is allowed as a filter criterion, | ||
// `forSale` and `framed` are allowed as a filter criterion, | ||
// but NOT as an alert criterion, so we remove it. | ||
// (Alerts, by definition, stipulate forSale=true | ||
// when they are created in Gravity.) | ||
delete criteria.forSale | ||
delete criteria.framed | ||
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. thought (non-blocking): I think this makes sense for now. Maybe a product decision about whether this would be a desirable alert criteria, but we can always follow up on that. |
||
|
||
dispatch({ type: "SET_CRITERIA", payload: criteria }) | ||
}, [initialCriteria, isEditMode, isAlertArtworksView]) | ||
|
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
44 changes: 44 additions & 0 deletions
44
src/Components/ArtworkFilter/ArtworkFilters/FramedFilter.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,44 @@ | ||
import { Checkbox } from "@artsy/palette" | ||
import { | ||
SelectedFiltersCountsLabels, | ||
useArtworkFilterContext, | ||
useCurrentlySelectedFilters, | ||
} from "Components/ArtworkFilter/ArtworkFilterContext" | ||
import { FilterExpandable } from "Components/ArtworkFilter/ArtworkFilters/FilterExpandable" | ||
import { useFilterLabelCountByKey } from "Components/ArtworkFilter/Utils/useFilterLabelCountByKey" | ||
|
||
interface FramedFilterProps { | ||
expanded?: boolean | ||
} | ||
|
||
export const FramedFilter: React.FC<FramedFilterProps> = ({ expanded }) => { | ||
const { unsetFilter, setFilter } = useArtworkFilterContext() | ||
const currentSelectedFilters = useCurrentlySelectedFilters() | ||
|
||
const filtersCount = useFilterLabelCountByKey( | ||
SelectedFiltersCountsLabels.framed, | ||
) | ||
const label = `Framed${filtersCount}` | ||
|
||
const isSelected = currentSelectedFilters?.framed | ||
|
||
const handleOnSelect = (selected: boolean) => { | ||
if (selected) { | ||
setFilter("framed", true) | ||
} else { | ||
unsetFilter("framed") | ||
} | ||
} | ||
|
||
return ( | ||
<FilterExpandable label={label} expanded={isSelected || expanded}> | ||
<Checkbox | ||
selected={!!currentSelectedFilters?.framed} | ||
onSelect={handleOnSelect} | ||
my={1} | ||
> | ||
Only framed works | ||
</Checkbox> | ||
</FilterExpandable> | ||
) | ||
} |
108 changes: 108 additions & 0 deletions
108
src/Components/ArtworkFilter/ArtworkFilters/__tests__/FramedFilter.jest.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,108 @@ | ||
import { screen } from "@testing-library/react" | ||
import userEvent from "@testing-library/user-event" | ||
import { useArtworkFilterContext } from "Components/ArtworkFilter/ArtworkFilterContext" | ||
import { FramedFilter } from "Components/ArtworkFilter/ArtworkFilters/FramedFilter" | ||
import { | ||
createArtworkFilterTestRenderer, | ||
currentArtworkFilterContext, | ||
} from "Components/ArtworkFilter/ArtworkFilters/__tests__/Utils" | ||
import { __internal__useMatchMedia } from "Utils/Hooks/useMatchMedia" | ||
import { useEffect } from "react" | ||
|
||
jest.mock("Utils/Hooks/useMatchMedia") | ||
|
||
const render = createArtworkFilterTestRenderer() | ||
|
||
describe(FramedFilter, () => { | ||
it("renders a toggle", () => { | ||
render(<FramedFilter expanded />) | ||
expect(screen.getByText("Only framed works")).toBeInTheDocument() | ||
}) | ||
|
||
it("updates context on filter change", () => { | ||
render(<FramedFilter expanded />) | ||
expect(currentArtworkFilterContext().filters?.framed).toBeFalsy() | ||
|
||
userEvent.click(screen.getAllByRole("checkbox")[0]) | ||
expect(currentArtworkFilterContext().filters?.framed).toBeTruthy() | ||
|
||
userEvent.click(screen.getAllByRole("checkbox")[0]) | ||
expect(currentArtworkFilterContext().filters?.framed).toBeNull() | ||
}) | ||
|
||
it("clears local input state after Clear All", () => { | ||
render(<FramedFilter expanded />) | ||
userEvent.click(screen.getAllByRole("checkbox")[0]) | ||
expect(currentArtworkFilterContext().filters?.framed).toBeTruthy() | ||
|
||
userEvent.click(screen.getByText("Clear all")) | ||
|
||
expect(currentArtworkFilterContext().filters?.framed).toBeUndefined() | ||
}) | ||
|
||
describe("mobile-specific behavior", () => { | ||
beforeEach(() => { | ||
// Simulate the media query that checks for xs size and returns true | ||
;(__internal__useMatchMedia as jest.Mock).mockImplementation(() => true) | ||
|
||
/* | ||
* A test component that simulates the usage of | ||
* the FramedFilter inside ArtworkFilterMobileOverlay | ||
*/ | ||
const MobileVersionOfFramedFilter = () => { | ||
const filterContext = useArtworkFilterContext() | ||
|
||
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation> | ||
useEffect(() => { | ||
// on mount, initialize the staged filters | ||
filterContext.setShouldStageFilterChanges?.(true) | ||
if (filterContext.filters) { | ||
filterContext.setStagedFilters?.(filterContext.filters) | ||
} | ||
}, []) | ||
|
||
return <FramedFilter expanded /> | ||
} | ||
render(<MobileVersionOfFramedFilter />) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it("stages the filter change instead of applying", () => { | ||
expect(currentArtworkFilterContext().filters?.framed).toBeFalsy() | ||
|
||
userEvent.click(screen.getAllByRole("checkbox")[0]) | ||
|
||
expect(currentArtworkFilterContext().filters?.framed).toBeFalsy() | ||
expect(currentArtworkFilterContext().stagedFilters?.framed).toBeTruthy() | ||
}) | ||
|
||
it("displays a filter count inline", () => { | ||
expect(screen.getByText("Framed")).toBeInTheDocument() | ||
expect(screen.queryByText("Framed • 1")).not.toBeInTheDocument() | ||
|
||
userEvent.click(screen.getAllByRole("checkbox")[0]) | ||
|
||
expect(screen.getByText("Framed • 1")).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe("the `expanded` prop", () => { | ||
it("hides the filter controls when not set", () => { | ||
render(<FramedFilter />) | ||
expect(screen.queryAllByRole("checkbox").length).toBe(0) | ||
}) | ||
|
||
it("hides the filter controls when `false`", () => { | ||
render(<FramedFilter expanded={false} />) | ||
expect(screen.queryAllByRole("checkbox").length).toBe(0) | ||
}) | ||
|
||
it("shows the filter controls when `true`", () => { | ||
render(<FramedFilter expanded />) | ||
expect(screen.queryAllByRole("checkbox").length).not.toBe(0) | ||
}) | ||
}) | ||
}) |
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
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.
Do we really need the feature flag? In case something goes wrong, we cand simply roll back the feature.
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.
FWIW I'm in favor of the feature flag. Gives us the ability to do more fine-grained QA (in staging, or per user) before launching. I love the velocity of Hackathon but I appreciate rolling things out intentionally like this 😄
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.
True, the feature flag gives more flexibility for the release (and frees us from having to follow the bug-free programming principle 😄).