forked from nervosnetwork/ckb-explorer-frontend
-
Notifications
You must be signed in to change notification settings - Fork 6
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(xudt-tag): add xudt tag column in xudt page #378
Merged
Merged
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ac7c451
feat(xudt-tag): add xudt tag column in xudt page
Daryl-L d0565ea
feat(xudt): add filter to filter tags
Daryl-L afedc9c
fix(multi-filter-button): use filter name
Daryl-L 1255041
style(multi-filter-button): use URLSearchParams
Daryl-L 147bd6e
feat(multi_button_filter): use i18n for select
Daryl-L a8cb2c7
style(xudt-tag): move function to object for filter item list
Daryl-L fdff98b
feat(tag-filter): can select all
Daryl-L d53ab25
style(xudt-tags): add `isAllSelected` and `isNoneSelected`
Daryl-L dd9cab8
style(multi-filter-button): filteredList -> filterList
Daryl-L 8393116
fix(multi-filter-button): lost other parameters
Daryl-L 74c9baa
feat(xudt-tag): no record when not choose any tags
Daryl-L 26dc5bb
fix(xudt-tag): remove category
Daryl-L b548c85
style(xudt): use `!!` instead of `!== ''`
Daryl-L 567643c
feat(xudt): use union params
Daryl-L 3fce98f
feat(xudt-tag): remove category
Daryl-L 49c6cc5
feat(xudt-tag): add tag
Daryl-L a0bc5d7
feat(xudt-tag): add and remove tags
Daryl-L d2e1d60
feat(xudt-tags): multi select remove page parameter
Daryl-L a573a1c
feat(xudt-tags): mobile empty for not select any tags
Daryl-L bea35d6
feat(xudt-tags): only 1 page when not select any tags
Daryl-L b4b27d1
feat(multi-filter): highlight
Daryl-L 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,92 @@ | ||
import { Link, useLocation } from 'react-router-dom' | ||
import { Popover } from 'antd' | ||
import { useTranslation } from 'react-i18next' | ||
import { ReactComponent as FilterIcon } from '../../assets/filter_icon.svg' | ||
import { ReactComponent as SelectedIcon } from '../../assets/selected-icon.svg' | ||
import { ReactComponent as NotSelectedIcon } from '../../assets/not-selected-icon.svg' | ||
import { ReactComponent as PartialSelectedIcon } from '../../assets/partial-selected-icon.svg' | ||
import { useSearchParams } from '../../hooks' | ||
import styles from './styles.module.scss' | ||
|
||
export function MultiFilterButton({ | ||
filterList, | ||
isMobile, | ||
filterName, | ||
}: { | ||
filterName: string | ||
filterList: { key: string; value: string; to: string; title: string | JSX.Element }[] | ||
isMobile?: boolean | ||
}) { | ||
const { t } = useTranslation() | ||
const params = useSearchParams(filterName) | ||
const filter = params[filterName] | ||
let types = filterList.map(f => f.value) | ||
if (filter !== undefined) { | ||
types = filter.split(',').filter(t => !!t) | ||
} | ||
|
||
const isAllSelected = types.length === filterList.length | ||
const isNoneSelected = types.length === 0 | ||
const search = new URLSearchParams(useLocation().search) | ||
search.delete(filterName) | ||
search.delete('page') | ||
|
||
return ( | ||
<Popover | ||
className={styles.container} | ||
placement="bottomRight" | ||
trigger={isMobile ? 'click' : 'hover'} | ||
overlayClassName={styles.antPopover} | ||
content={ | ||
<div className={styles.filterItems}> | ||
<div className={styles.selectTitle}> | ||
<h2>{t('components.multi_filter_button.select')}</h2> | ||
<Link | ||
key="all" | ||
to={() => { | ||
const newSearch = new URLSearchParams(search) | ||
if (!isNoneSelected && isAllSelected) { | ||
newSearch.append(filterName, '') | ||
} | ||
return `${filterList[0].to}?${newSearch.toString()}` | ||
}} | ||
> | ||
{types.length > 0 ? ( | ||
<>{isAllSelected ? <SelectedIcon /> : <PartialSelectedIcon />}</> | ||
) : ( | ||
<NotSelectedIcon /> | ||
)} | ||
</Link> | ||
</div> | ||
{filterList.map(f => ( | ||
<Link | ||
key={f.key} | ||
to={() => { | ||
const subTypes = new Set(types) | ||
if (subTypes.has(f.value)) { | ||
subTypes.delete(f.value) | ||
} else { | ||
subTypes.add(f.value) | ||
} | ||
|
||
const newSearch = new URLSearchParams(search) | ||
newSearch.append(filterName, Array.from(subTypes).join(',')) | ||
return `${f.to}?${newSearch.toString()}` | ||
}} | ||
data-is-active={types.includes(f.value)} | ||
> | ||
{f.title} | ||
{types.includes(f.value) ? <SelectedIcon /> : <NotSelectedIcon />} | ||
</Link> | ||
))} | ||
</div> | ||
} | ||
> | ||
<FilterIcon className={styles.filter} /> | ||
</Popover> | ||
) | ||
} | ||
|
||
MultiFilterButton.displayName = 'MultiFilterButton' | ||
|
||
export default MultiFilterButton |
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,75 @@ | ||
.container { | ||
appearance: none; | ||
border: none; | ||
outline: none; | ||
background: none; | ||
display: inline-flex; | ||
vertical-align: text-top; | ||
margin-left: 8px; | ||
cursor: pointer; | ||
} | ||
|
||
.antPopover { | ||
:global { | ||
/* stylelint-disable-next-line selector-class-pattern */ | ||
.ant-popover-inner { | ||
border-radius: 8px; | ||
box-shadow: 0 2px 10px 0 #eee; | ||
} | ||
|
||
/* stylelint-disable-next-line selector-class-pattern */ | ||
.ant-popover-inner-content { | ||
padding: 14px 24px 14px 16px; | ||
} | ||
} | ||
} | ||
|
||
.filter { | ||
margin-left: 8px; | ||
color: #999; | ||
} | ||
|
||
.filterItems { | ||
display: flex; | ||
flex-direction: column; | ||
width: 200px; | ||
|
||
.selectTitle { | ||
color: var(--primary-color); | ||
|
||
h2 { | ||
color: #333; | ||
font-size: 14px; | ||
font-style: normal; | ||
font-weight: 500; | ||
line-height: normal; | ||
} | ||
|
||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 10px; | ||
border-radius: 8px; | ||
|
||
a { | ||
padding: 0; | ||
} | ||
} | ||
|
||
a { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 10px; | ||
border-radius: 8px; | ||
|
||
svg { | ||
color: var(--primary-color); | ||
} | ||
|
||
&:hover { | ||
background: var(--primary-hover-bg-color); | ||
cursor: pointer; | ||
} | ||
} | ||
} |
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.
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.
It can be simplified as
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.
filterName
should befilterNames
if it's designed to be multiple filters.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.
For me, the
filters
from the URL are more likefilteredList
because they are effective/workingfilters
whilefilteredList
in thecomponent params
is a list of filters.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.
I think there would be only one filter for each filter button, so I think "s" is not necessary here.
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.
There are three values for the
filterName
.undefined
, which means to entry the page without any filter parameters, for "all selected".''
, liketags=
which means "not selected any value".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.
works well for these 3 cases
when
params[filterName]
is undefined,types
is undefined, meansall selected
when
params[filterName]
is an empty string,types
is an empty array, meansnot selected any value
when
params[filterName]
is a string,types
is expected to be an array with items, meanssome selected
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.
Any update on this conversation?
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.
The
filterName
means the name of the filter, andA,B,C
should be the values of this filter, not the name.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.
The result of
!t
istrue
when it is an empty string, but the empty string should filtered to the resultThere 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.
My typo,
.filter(t => !t)
should be.filter(t => !!t)
to return truty values