-
Notifications
You must be signed in to change notification settings - Fork 583
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(ONYX-380): add colours filter to saved searches #9413
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6f85a3e
feat: create new artwork filter store
MounirDhahri 4eb5975
minor: separate filter data type
MounirDhahri f1cfd9d
feat: add filters screen wrapper
MounirDhahri cbfd7ce
feat: prepare your filters section
MounirDhahri d5319b9
refactor: move screen to savesearches directory
MounirDhahri 432c702
feat: wrap the screen with the new artwork filters store
MounirDhahri c6df76b
feat: add rarity filter functionality
MounirDhahri a4dacd1
chore: improve UX of selecting pills 👌
MounirDhahri 9c18b0f
chore: add rarity options tests
MounirDhahri 4a15749
chore: minor integrity test improvement
MounirDhahri dbf0169
fix: useDebounce logic in pill
MounirDhahri e041a4c
feat: display the applied filters on your filters
MounirDhahri 4827865
feat: add remove filter action
MounirDhahri 5a83528
chore: add note to make sure to implement clear all
MounirDhahri ba5bb99
feat: add your filters tests
MounirDhahri c223b67
feat: add clear all button
MounirDhahri 95a8b62
chore: add subtle animations: bring the screen to life
MounirDhahri b22ddb4
fix: revert disabled logic in clear all button
MounirDhahri 2591c0f
chore: remove commented line
MounirDhahri 322ed69
chore: remove unused fields from store
MounirDhahri c4038ad
refact: use SavedSearchStore for ClearAllButton
MounirDhahri 68ec793
refactor: update Applied fitlers to use SavedSearchStore
MounirDhahri cd400b0
chore: do not allow artistIDs pills removal
MounirDhahri bcd561f
chore: do not count artistIDs for clear all button counts
MounirDhahri e5c2614
refactor: use SavedSearchStoreProvider for rarity
MounirDhahri f73a374
refactor: remove new filters store
MounirDhahri 3449121
fix: rarity filter test
MounirDhahri 76dd082
chore: address review comments
MounirDhahri 9c67567
feat: add color filtering
MounirDhahri 2d4cce0
chore: address review comments
MounirDhahri 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
78 changes: 78 additions & 0 deletions
78
src/app/Scenes/SavedSearchAlert/Components/SavedSearchFilterColour.tests.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,78 @@ | ||
import { OwnerType } from "@artsy/cohesion" | ||
import { fireEvent, waitFor } from "@testing-library/react-native" | ||
import { | ||
COLORS_INDEXED_BY_VALUE, | ||
COLOR_OPTIONS, | ||
} from "app/Components/ArtworkFilter/Filters/ColorsOptions" | ||
import { SavedSearchFilterColour } from "app/Scenes/SavedSearchAlert/Components/SavedSearchFilterColour" | ||
import { | ||
SavedSearchModel, | ||
SavedSearchStoreProvider, | ||
savedSearchModel, | ||
} from "app/Scenes/SavedSearchAlert/SavedSearchStore" | ||
import { renderWithWrappers } from "app/utils/tests/renderWithWrappers" | ||
|
||
describe("SavedSearchFilterColour", () => { | ||
it("shows all available color options unselected", () => { | ||
const { getByTestId } = renderWithWrappers( | ||
<SavedSearchStoreProvider runtimeModel={initialData}> | ||
<SavedSearchFilterColour /> | ||
</SavedSearchStoreProvider> | ||
) | ||
|
||
COLOR_OPTIONS.forEach((option) => { | ||
expect(() => | ||
getByTestId(`check-icon-${COLORS_INDEXED_BY_VALUE[option.paramValue as string].name}`) | ||
).toThrow() | ||
}) | ||
}) | ||
|
||
it("shows the right selected state", () => { | ||
const { getByTestId } = renderWithWrappers( | ||
<SavedSearchStoreProvider runtimeModel={{ ...initialData, attributes: { colors: ["red"] } }}> | ||
<SavedSearchFilterColour /> | ||
</SavedSearchStoreProvider> | ||
) | ||
|
||
COLOR_OPTIONS.forEach((option) => { | ||
if (option.paramValue !== "red") { | ||
expect(() => | ||
getByTestId(`check-icon-${COLORS_INDEXED_BY_VALUE[option.paramValue as string].name}`) | ||
).toThrow() | ||
} else { | ||
expect( | ||
getByTestId(`check-icon-${COLORS_INDEXED_BY_VALUE[option.paramValue as string].name}`) | ||
).toBeDefined() | ||
} | ||
}) | ||
}) | ||
|
||
it("Updates selected filters on press", () => { | ||
const { getByTestId, getByText } = renderWithWrappers( | ||
<SavedSearchStoreProvider runtimeModel={initialData}> | ||
<SavedSearchFilterColour /> | ||
</SavedSearchStoreProvider> | ||
) | ||
|
||
fireEvent(getByText("Red"), "onPress") | ||
|
||
waitFor(() => { | ||
expect(getByTestId("check-icon-Red")).toBeDefined() | ||
}) | ||
}) | ||
}) | ||
|
||
const initialData: SavedSearchModel = { | ||
...savedSearchModel, | ||
attributes: { | ||
atAuction: true, | ||
}, | ||
entity: { | ||
artists: [{ id: "artistID", name: "Banksy" }], | ||
owner: { | ||
type: OwnerType.artist, | ||
id: "ownerId", | ||
slug: "ownerSlug", | ||
}, | ||
}, | ||
} |
77 changes: 77 additions & 0 deletions
77
src/app/Scenes/SavedSearchAlert/Components/SavedSearchFilterColour.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,77 @@ | ||
import { Flex, Spacer, Text, useScreenDimensions, useSpace } from "@artsy/palette-mobile" | ||
import { | ||
COLORS_INDEXED_BY_VALUE, | ||
COLOR_OPTIONS, | ||
SWATCHES_PER_ROW, | ||
} from "app/Components/ArtworkFilter/Filters/ColorsOptions" | ||
import { ColorsSwatch } from "app/Components/ArtworkFilter/Filters/ColorsSwatch" | ||
import { SearchCriteria } from "app/Components/ArtworkFilter/SavedSearch/types" | ||
import { SavedSearchStore } from "app/Scenes/SavedSearchAlert/SavedSearchStore" | ||
import { isValueSelected, useSearchCriteriaAttributes } from "app/Scenes/SavedSearchAlert/helpers" | ||
|
||
export const SavedSearchFilterColour = () => { | ||
const selectedAttributes = useSearchCriteriaAttributes(SearchCriteria.colors) as string[] | ||
|
||
const { width } = useScreenDimensions() | ||
const space = useSpace() | ||
|
||
const setValueToAttributesByKeyAction = SavedSearchStore.useStoreActions( | ||
(actions) => actions.setValueToAttributesByKeyAction | ||
) | ||
const removeValueFromAttributesByKeyAction = SavedSearchStore.useStoreActions( | ||
(actions) => actions.removeValueFromAttributesByKeyAction | ||
) | ||
|
||
const handlePress = (value: string) => { | ||
const isSelected = isValueSelected({ | ||
selectedAttributes, | ||
value: value, | ||
}) | ||
|
||
if (isSelected) { | ||
removeValueFromAttributesByKeyAction({ | ||
key: SearchCriteria.colors, | ||
value: value, | ||
}) | ||
} else { | ||
const newValues = (selectedAttributes || []).concat(value) | ||
setValueToAttributesByKeyAction({ | ||
key: SearchCriteria.colors, | ||
value: newValues, | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<Flex> | ||
<Text px={2} variant="sm" fontWeight={500}> | ||
Colour | ||
</Text> | ||
|
||
<Spacer y={1} /> | ||
|
||
<Flex flexDirection="row" flexWrap="wrap" px={1}> | ||
{COLOR_OPTIONS.map((option, i) => { | ||
const color = COLORS_INDEXED_BY_VALUE[String(option.paramValue)] | ||
|
||
return ( | ||
<ColorsSwatch | ||
key={i} | ||
width={(width - space(1) * 2) / SWATCHES_PER_ROW} | ||
selected={isValueSelected({ | ||
selectedAttributes, | ||
value: option.paramValue, | ||
})} | ||
name={color.name} | ||
backgroundColor={color.backgroundColor} | ||
foregroundColor={color.foregroundColor} | ||
onPress={() => { | ||
handlePress(option.paramValue as string) | ||
}} | ||
/> | ||
) | ||
})} | ||
</Flex> | ||
</Flex> | ||
) | ||
} |
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
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.
Not sure whether devs from the US will be happy with
colour
😆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.
lol - did it intentionally here to follow Barney's designs 😄