-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Give more visibility to the smart filter (#1942)
* feat: Give OnlySmart filter more visibility * chore: Add TODO * style: Fix styles reviewed in the PR * feat: Show different sections depending on the dispositive
- Loading branch information
1 parent
1e1a2fb
commit cf30ad6
Showing
16 changed files
with
230 additions
and
35 deletions.
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
74 changes: 74 additions & 0 deletions
74
webapp/src/components/AssetFilters/MoreFilters/MoreFilters.spec.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,74 @@ | ||
import { NFTCategory } from '@dcl/schemas' | ||
import { useTabletAndBelowMediaQuery } from 'decentraland-ui/dist/components/Media' | ||
import { renderWithProviders } from '../../../utils/test' | ||
import { MoreFilters, MoreFiltersProps } from './MoreFilters' | ||
|
||
jest.mock('decentraland-ui/dist/components/Media', () => ({ | ||
useTabletAndBelowMediaQuery: jest.fn() | ||
})) | ||
|
||
function renderMoreFilters(props: Partial<MoreFiltersProps> = {}) { | ||
return renderWithProviders( | ||
<MoreFilters | ||
onOnlySmartChange={jest.fn()} | ||
onSaleChange={jest.fn()} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
describe('MoreFilters', () => { | ||
let useTabletAndBelowMediaQueryMock: jest.MockedFunction<typeof useTabletAndBelowMediaQuery> | ||
|
||
beforeEach(() => { | ||
useTabletAndBelowMediaQueryMock = useTabletAndBelowMediaQuery as jest.MockedFunction< | ||
typeof useTabletAndBelowMediaQuery | ||
> | ||
}) | ||
|
||
describe('when the isOnSale filter is visible', () => { | ||
it('should render the more filters section', () => { | ||
const { container } = renderMoreFilters({ isOnSale: true }) | ||
expect(container).not.toBeEmptyDOMElement() | ||
}) | ||
}) | ||
|
||
describe('when the wearables category is selected and the dispositive is tablet or mobile', () => { | ||
beforeEach(() => { | ||
useTabletAndBelowMediaQueryMock.mockReturnValue(true) | ||
}) | ||
|
||
it('should render the more filters section', () => { | ||
const { container } = renderMoreFilters({ | ||
category: NFTCategory.WEARABLE | ||
}) | ||
expect(container).not.toBeEmptyDOMElement() | ||
}) | ||
}) | ||
|
||
describe('when the isOnSale filter is not visible', () => { | ||
describe('and the selected category is not wearables', () => { | ||
it('should not render the more filters section', () => { | ||
const { container } = renderMoreFilters({ | ||
category: NFTCategory.PARCEL, | ||
isOnSale: undefined | ||
}) | ||
expect(container).toBeEmptyDOMElement() | ||
}) | ||
}) | ||
|
||
describe('and the selected category is wearables but the dispositive is not mobile nor tablet', () => { | ||
beforeEach(() => { | ||
useTabletAndBelowMediaQueryMock.mockReturnValue(false) | ||
}) | ||
|
||
it('should not render the more filters section', () => { | ||
const { container } = renderMoreFilters({ | ||
category: NFTCategory.WEARABLE, | ||
isOnSale: undefined | ||
}) | ||
expect(container).toBeEmptyDOMElement() | ||
}) | ||
}) | ||
}) | ||
}) |
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
9 changes: 9 additions & 0 deletions
9
webapp/src/components/AssetFilters/OnlySmartFilter/OnlySmartFilter.module.css
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,9 @@ | ||
.onlySmartFilterSection { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
|
||
.onlySmartFilterSection :global(.SmartBadge:not(.clickable)) { | ||
cursor: initial; | ||
} |
45 changes: 45 additions & 0 deletions
45
webapp/src/components/AssetFilters/OnlySmartFilter/OnlySmartFilter.spec.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,45 @@ | ||
import { useTabletAndBelowMediaQuery } from 'decentraland-ui/dist/components/Media' | ||
import { renderWithProviders } from '../../../utils/test' | ||
import { OnlySmartFilter, OnlySmartFilterProps } from './OnlySmartFilter' | ||
|
||
jest.mock('decentraland-ui/dist/components/Media', () => ({ | ||
useTabletAndBelowMediaQuery: jest.fn() | ||
})) | ||
|
||
function renderOnlySmartFilter(props: Partial<OnlySmartFilterProps> = {}) { | ||
return renderWithProviders( | ||
<OnlySmartFilter onChange={jest.fn()} {...props} /> | ||
) | ||
} | ||
|
||
describe('OnlySmartFilter', () => { | ||
let useTabletAndBelowMediaQueryMock: jest.MockedFunction<typeof useTabletAndBelowMediaQuery> | ||
|
||
beforeEach(() => { | ||
useTabletAndBelowMediaQueryMock = useTabletAndBelowMediaQuery as jest.MockedFunction< | ||
typeof useTabletAndBelowMediaQuery | ||
> | ||
}) | ||
|
||
describe('when the dispositive is mobile or tablet', () => { | ||
beforeEach(() => { | ||
useTabletAndBelowMediaQueryMock.mockReturnValue(true) | ||
}) | ||
|
||
it('should not render the only smart filter section', () => { | ||
const { container } = renderOnlySmartFilter() | ||
expect(container).toBeEmptyDOMElement() | ||
}) | ||
}) | ||
|
||
describe('when the dispositive is not mobile nor tablet', () => { | ||
beforeEach(() => { | ||
useTabletAndBelowMediaQueryMock.mockReturnValue(false) | ||
}) | ||
|
||
it('should render the only smart filter section', () => { | ||
const { container } = renderOnlySmartFilter() | ||
expect(container).not.toBeEmptyDOMElement() | ||
}) | ||
}) | ||
}) |
49 changes: 49 additions & 0 deletions
49
webapp/src/components/AssetFilters/OnlySmartFilter/OnlySmartFilter.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,49 @@ | ||
import { useCallback } from 'react' | ||
import { Box, Checkbox, CheckboxProps } from 'decentraland-ui' | ||
import { useTabletAndBelowMediaQuery } from 'decentraland-ui/dist/components/Media' | ||
import SmartBadge from '../../AssetPage/SmartBadge' | ||
import styles from './OnlySmartFilter.module.css' | ||
|
||
export type OnlySmartFilterProps = { | ||
isOnlySmart?: boolean | ||
onChange: (value: boolean) => void | ||
defaultCollapsed?: boolean | ||
'data-testid'?: string | ||
} | ||
|
||
export const OnlySmartFilterContent = ( | ||
props: Pick<OnlySmartFilterProps, 'isOnlySmart' | 'onChange' | 'data-testid'> | ||
) => { | ||
const { isOnlySmart, onChange } = props | ||
|
||
const handleChange = useCallback( | ||
(_, props: CheckboxProps) => { | ||
onChange(!!props.checked) | ||
}, | ||
[onChange] | ||
) | ||
|
||
return ( | ||
<div | ||
className={styles.onlySmartFilterSection} | ||
data-testid={props['data-testid']} | ||
> | ||
<SmartBadge clickable={false} /> | ||
<Checkbox toggle checked={!!isOnlySmart} onChange={handleChange} /> | ||
</div> | ||
) | ||
} | ||
|
||
export const OnlySmartFilter = ({ | ||
isOnlySmart, | ||
onChange, | ||
defaultCollapsed = false | ||
}: OnlySmartFilterProps) => { | ||
const isMobileOrTablet = useTabletAndBelowMediaQuery() | ||
|
||
return isMobileOrTablet ? null : ( | ||
<Box className="filters-sidebar-box" defaultCollapsed={defaultCollapsed}> | ||
<OnlySmartFilterContent isOnlySmart={isOnlySmart} onChange={onChange} /> | ||
</Box> | ||
) | ||
} |
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 @@ | ||
export * from './OnlySmartFilter' |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
top: 2px; | ||
width: 14px; | ||
height: 14px; | ||
} | ||
} |
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
13 changes: 9 additions & 4 deletions
13
webapp/src/components/AssetPage/SmartBadge/SmartBadge.types.ts
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { AssetType } from '../../../modules/asset/types' | ||
|
||
export type Props = { | ||
assetType: AssetType | ||
clickable?: boolean | ||
} | ||
export type Props = | ||
| { | ||
assetType?: AssetType | ||
clickable?: false | ||
} | ||
| { | ||
assetType: AssetType | ||
clickable: true | ||
} | ||
|
||
export type OwnProps = Pick<Props, 'assetType'> |
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
Oops, something went wrong.