-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from multiversx/staking-v4-redesign-step-2
Staking V4 Redesign: Step 2
- Loading branch information
Showing
142 changed files
with
3,916 additions
and
2,195 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
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
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,80 @@ | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import classNames from 'classnames'; | ||
import { Dropdown, Anchor } from 'react-bootstrap'; | ||
import { useSelector } from 'react-redux'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
import { ShardSpan } from 'components'; | ||
import { useFetchShards } from 'hooks'; | ||
import { faFilter } from 'icons/regular'; | ||
import { faFilter as faFilterSolid } from 'icons/solid'; | ||
import { shardsSelector } from 'redux/selectors'; | ||
import { TableFilterUIType } from 'types'; | ||
|
||
export const ShardFilter = ({ text, hideFilters }: TableFilterUIType) => { | ||
const shards = useSelector(shardsSelector); | ||
|
||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const { shard, page, size, ...rest } = Object.fromEntries(searchParams); | ||
|
||
useFetchShards(); | ||
|
||
const setShardfilter = (shard: string) => { | ||
const nextUrlParams = { | ||
...rest, | ||
...(shard ? { shard } : {}) | ||
}; | ||
|
||
setSearchParams(nextUrlParams); | ||
}; | ||
|
||
if (hideFilters) { | ||
return text; | ||
} | ||
|
||
return ( | ||
<div | ||
className={classNames({ | ||
'text-primary-100': shard !== undefined | ||
})} | ||
> | ||
{text} | ||
<Dropdown | ||
className='d-inline-flex' | ||
onSelect={(eventKey: any) => { | ||
return setShardfilter(eventKey ?? ''); | ||
}} | ||
> | ||
<Dropdown.Toggle | ||
className='btn-link-unstyled side-action cursor-pointer' | ||
variant='link' | ||
> | ||
<FontAwesomeIcon | ||
icon={shard !== undefined ? faFilterSolid : faFilter} | ||
className={shard !== undefined ? 'text-primary' : ''} | ||
/> | ||
</Dropdown.Toggle> | ||
|
||
<Dropdown.Menu> | ||
<Dropdown.Item as={Anchor} eventKey=''> | ||
All | ||
</Dropdown.Item> | ||
{shards.map((entry, i) => { | ||
return ( | ||
<Dropdown.Item | ||
as={Anchor} | ||
className={`dropdown-item ${ | ||
shard === entry.shard.toString() ? 'active' : '' | ||
}`} | ||
eventKey={entry.shard} | ||
key={entry.shard + i} | ||
> | ||
<ShardSpan shard={entry.shard} /> | ||
</Dropdown.Item> | ||
); | ||
})} | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
</div> | ||
); | ||
}; |
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,103 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import classNames from 'classnames'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
import { ELLIPSIS } from 'appConstants'; | ||
import { formatBigNumber, getStringPlural } from 'helpers'; | ||
import { useGetSearch } from 'hooks'; | ||
import { faSearch, faTimes } from 'icons/regular'; | ||
import { WithClassnameType } from 'types'; | ||
|
||
export interface TableSearchUIType extends WithClassnameType { | ||
name?: string; | ||
searchValue?: string | number; | ||
placeholderText?: string; | ||
} | ||
|
||
export const TableSearch = ({ | ||
name = 'search', | ||
searchValue, | ||
placeholderText, | ||
className | ||
}: TableSearchUIType) => { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const { search } = useGetSearch(); | ||
|
||
const [inputValue, setInputValue] = useState<string>(search ?? ''); | ||
const [placeholderAddonText, setPlaceholderAddonText] = useState(''); | ||
|
||
const changeSearchValue: React.ChangeEventHandler<HTMLInputElement> = (e) => { | ||
setInputValue(e.target.value); | ||
}; | ||
|
||
const updateSearchValue = (searchValue: string) => { | ||
const { search, page, size, ...rest } = Object.fromEntries(searchParams); | ||
const nextUrlParams = { | ||
...rest, | ||
...(searchValue ? { search: searchValue } : {}) | ||
}; | ||
|
||
setSearchParams(nextUrlParams); | ||
}; | ||
|
||
useEffect(() => { | ||
const searchPlaceholder = | ||
searchValue && searchValue !== ELLIPSIS | ||
? getStringPlural(searchValue, { string: placeholderText }) | ||
: ''; | ||
const placeholderAddonText = search | ||
? '' | ||
: `${ | ||
searchValue && searchValue !== ELLIPSIS | ||
? `${formatBigNumber({ value: searchValue })} ` | ||
: '' | ||
}${searchPlaceholder}`; | ||
|
||
setPlaceholderAddonText(placeholderAddonText); | ||
}, [searchValue]); | ||
|
||
return ( | ||
<div | ||
role='search' | ||
className={classNames( | ||
'search-md input-group input-group-search input-group-seamless', | ||
className | ||
)} | ||
> | ||
<input | ||
type='text' | ||
className='form-control' | ||
value={inputValue || ''} | ||
onChange={changeSearchValue} | ||
onKeyDown={(keyEvent: React.KeyboardEvent) => { | ||
if (keyEvent.key === 'Enter') { | ||
updateSearchValue(inputValue); | ||
} | ||
}} | ||
placeholder={`Search ${placeholderAddonText}`} | ||
name={name} | ||
data-testid={name} | ||
/> | ||
|
||
{inputValue ? ( | ||
<button | ||
type='reset' | ||
className='input-group-text' | ||
onClick={() => { | ||
updateSearchValue(''); | ||
setInputValue(''); | ||
setPlaceholderAddonText(''); | ||
}} | ||
data-testid='resetSearch' | ||
> | ||
<FontAwesomeIcon icon={faTimes} /> | ||
</button> | ||
) : ( | ||
<button type='submit' className='input-group-text'> | ||
<FontAwesomeIcon icon={faSearch} /> | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}; |
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.