forked from decentraland/marketplace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add clear all filters (decentraland#412)
* feat: Add clear filters * chore: Add tests * Remove important * chore: Use omit from decentraland-commons * fix: Replace SSH for HTTPS in dep * fix: Remove decentraland-commons
- Loading branch information
1 parent
d41e03b
commit 78283e8
Showing
14 changed files
with
28,679 additions
and
49 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,32 @@ | ||
/** | ||
* Return a copy of the object, filtered to omit the blacklisted array of valid keys | ||
* @param obj | ||
* @param keys | ||
*/ | ||
export function omit( | ||
obj: Record<string, unknown>, | ||
keys: string[] | ||
): Record<string, unknown> { | ||
const newKeys = Object.keys(obj).filter(key => !keys.includes(key)) | ||
return pick(obj, newKeys) | ||
} | ||
|
||
/** | ||
* Return a copy of the object, filtered to only have values for the whitelisted array of valid keys | ||
* @param obj | ||
* @param keys | ||
*/ | ||
export function pick( | ||
obj: Record<string, unknown>, | ||
keys: string[] | ||
): Record<string, unknown> { | ||
const result = {} as Record<string, unknown> | ||
|
||
for (const key of keys) { | ||
if (obj.hasOwnProperty(key)) { | ||
result[key] = obj[key] | ||
} | ||
} | ||
|
||
return result | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Network, Rarity } from '@dcl/schemas' | ||
import { getLocation, push } from 'connected-react-router' | ||
import { expectSaga } from 'redux-saga-test-plan' | ||
import { call, select } from 'redux-saga/effects' | ||
import { AssetType } from '../asset/types' | ||
import { WearableGender } from '../nft/wearable/types' | ||
import { View } from '../ui/types' | ||
import { VendorName } from '../vendor' | ||
import { clearFilters } from './actions' | ||
import { | ||
buildBrowseURL, | ||
fetchAssetsFromRoute, | ||
getCurrentBrowseOptions, | ||
routingSaga | ||
} from './sagas' | ||
import { BrowseOptions, SortBy } from './types' | ||
|
||
describe('when handling the clear filters request action', () => { | ||
it("should fetch assets and change the URL by clearing the filter's browse options and restarting the page counter", () => { | ||
const browseOptions: BrowseOptions = { | ||
assetType: AssetType.ITEM, | ||
address: '0x...', | ||
vendor: VendorName.DECENTRALAND, | ||
section: 'aSection', | ||
page: 1, | ||
view: View.MARKET, | ||
sortBy: SortBy.NAME, | ||
search: 'aText', | ||
onlyOnSale: true, | ||
isMap: false, | ||
isFullscreen: false, | ||
wearableRarities: [Rarity.EPIC], | ||
wearableGenders: [WearableGender.FEMALE], | ||
contracts: ['aContract'], | ||
network: Network.ETHEREUM | ||
} | ||
|
||
const browseOptionsWithoutFilters: BrowseOptions = { ...browseOptions } | ||
delete browseOptionsWithoutFilters.wearableRarities | ||
delete browseOptionsWithoutFilters.wearableGenders | ||
delete browseOptionsWithoutFilters.network | ||
delete browseOptionsWithoutFilters.contracts | ||
delete browseOptionsWithoutFilters.page | ||
|
||
const pathname = 'aPath' | ||
|
||
return expectSaga(routingSaga) | ||
.provide([ | ||
[call(getCurrentBrowseOptions), browseOptions], | ||
[select(getLocation), { pathname }], | ||
[ | ||
call(fetchAssetsFromRoute, browseOptionsWithoutFilters), | ||
Promise.resolve() | ||
] | ||
]) | ||
.put(push(buildBrowseURL(pathname, browseOptionsWithoutFilters))) | ||
.dispatch(clearFilters()) | ||
.run({ silenceTimeout: true }) | ||
}) | ||
}) |
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.