Commit 92030c31 authored by tom's avatar tom

search input

parent 45f8d4af
...@@ -3,7 +3,7 @@ import React, { useCallback, useState } from 'react'; ...@@ -3,7 +3,7 @@ import React, { useCallback, useState } from 'react';
import { TEMPORARY_DEMO_APPS } from 'data/apps'; import { TEMPORARY_DEMO_APPS } from 'data/apps';
import AppList from 'ui/apps/AppList'; import AppList from 'ui/apps/AppList';
import FilterInput from 'ui/apps/FilterInput'; import FilterInput from 'ui/shared/FilterInput';
const defaultDisplayedApps = [ ...TEMPORARY_DEMO_APPS ] const defaultDisplayedApps = [ ...TEMPORARY_DEMO_APPS ]
.sort((a, b) => a.title.localeCompare(b.title)); .sort((a, b) => a.title.localeCompare(b.title));
...@@ -23,7 +23,7 @@ const Apps = () => { ...@@ -23,7 +23,7 @@ const Apps = () => {
return ( return (
<> <>
<FilterInput onChange={ debounceFilterApps }/> <FilterInput onChange={ debounceFilterApps } marginBottom={{ base: '4', lg: '6' }} placeholder="Find app"/>
<AppList apps={ displayedApps }/> <AppList apps={ displayedApps }/>
</> </>
); );
......
import { SearchIcon } from '@chakra-ui/icons'; import { SearchIcon } from '@chakra-ui/icons';
import { Input, InputGroup, InputLeftElement, useColorModeValue } from '@chakra-ui/react'; import { Input, InputGroup, InputLeftElement, useColorModeValue, chakra } from '@chakra-ui/react';
import type { ChangeEvent } from 'react'; import type { ChangeEvent } from 'react';
import React, { useCallback, useState } from 'react'; import React, { useCallback, useState } from 'react';
type Props = { type Props = {
onChange: (q: string) => void; onChange: (searchTerm: string) => void;
className?: string;
size?: 'xs' | 'sm' | 'md' | 'lg';
placeholder: string;
} }
const FilterInput = ({ onChange }: Props) => { const FilterInput = ({ onChange, className, size = 'sm', placeholder }: Props) => {
const [ filterQuery, setFilterQuery ] = useState(''); const [ filterQuery, setFilterQuery ] = useState('');
const handleFilterQueryChange = useCallback((event: ChangeEvent<HTMLInputElement>) => { const handleFilterQueryChange = useCallback((event: ChangeEvent<HTMLInputElement>) => {
...@@ -19,7 +22,8 @@ const FilterInput = ({ onChange }: Props) => { ...@@ -19,7 +22,8 @@ const FilterInput = ({ onChange }: Props) => {
return ( return (
<InputGroup <InputGroup
size="sm" size={ size }
className={ className }
> >
<InputLeftElement <InputLeftElement
pointerEvents="none" pointerEvents="none"
...@@ -28,13 +32,13 @@ const FilterInput = ({ onChange }: Props) => { ...@@ -28,13 +32,13 @@ const FilterInput = ({ onChange }: Props) => {
</InputLeftElement> </InputLeftElement>
<Input <Input
size="sm" size={ size }
value={ filterQuery } value={ filterQuery }
onChange={ handleFilterQueryChange } onChange={ handleFilterQueryChange }
marginBottom={{ base: '4', lg: '6' }} placeholder={ placeholder }
/> />
</InputGroup> </InputGroup>
); );
}; };
export default FilterInput; export default chakra(FilterInput);
...@@ -2,15 +2,25 @@ import { Box, Flex, Table, Thead, Tbody, Tr, Th, TableContainer } from '@chakra- ...@@ -2,15 +2,25 @@ import { Box, Flex, Table, Thead, Tbody, Tr, Th, TableContainer } from '@chakra-
import React from 'react'; import React from 'react';
import type { TxInternalsType } from 'types/api/tx'; import type { TxInternalsType } from 'types/api/tx';
import type ArrayElement from 'types/utils/ArrayElement';
import { data } from 'data/txInternal'; import { data } from 'data/txInternal';
import FilterInput from 'ui/shared/FilterInput';
import TxInternalsFilter from 'ui/tx/internals/TxInternalsFilter'; import TxInternalsFilter from 'ui/tx/internals/TxInternalsFilter';
import TxInternalsTableItem from 'ui/tx/internals/TxInternalsTableItem'; import TxInternalsTableItem from 'ui/tx/internals/TxInternalsTableItem';
const DEFAULT_FILTERS: Array<TxInternalsType> = [ 'call', 'delegate_call', 'static_call', 'create', 'create2', 'self_destruct', 'reward' ]; const DEFAULT_FILTERS: Array<TxInternalsType> = [ 'call', 'delegate_call', 'static_call', 'create', 'create2', 'self_destruct', 'reward' ];
const searchFn = (searchTerm: string) => (item: ArrayElement<typeof data>): boolean => {
const formattedSearchTerm = searchTerm.toLowerCase();
return item.type.toLowerCase().includes(formattedSearchTerm) ||
item.from.toLowerCase().includes(formattedSearchTerm) ||
item.to.toLowerCase().includes(formattedSearchTerm);
};
const TxInternals = () => { const TxInternals = () => {
const [ filters, setFilters ] = React.useState<Array<TxInternalsType>>(DEFAULT_FILTERS); const [ filters, setFilters ] = React.useState<Array<TxInternalsType>>(DEFAULT_FILTERS);
const [ searchTerm, setSearchTerm ] = React.useState<string>('');
const handleFilterChange = React.useCallback((nextValue: Array<TxInternalsType>) => { const handleFilterChange = React.useCallback((nextValue: Array<TxInternalsType>) => {
setFilters(nextValue); setFilters(nextValue);
...@@ -20,6 +30,7 @@ const TxInternals = () => { ...@@ -20,6 +30,7 @@ const TxInternals = () => {
<Box> <Box>
<Flex> <Flex>
<TxInternalsFilter onFilterChange={ handleFilterChange } defaultFilters={ filters } appliedFiltersNum={ filters.length }/> <TxInternalsFilter onFilterChange={ handleFilterChange } defaultFilters={ filters } appliedFiltersNum={ filters.length }/>
<FilterInput onChange={ setSearchTerm } maxW="360px" ml={ 3 } size="xs" placeholder="Search by addresses, hash, method..."/>
</Flex> </Flex>
<TableContainer width="100%" mt={ 6 }> <TableContainer width="100%" mt={ 6 }>
<Table variant="simple" minWidth="950px" size="sm"> <Table variant="simple" minWidth="950px" size="sm">
...@@ -35,6 +46,7 @@ const TxInternals = () => { ...@@ -35,6 +46,7 @@ const TxInternals = () => {
<Tbody> <Tbody>
{ data { data
.filter(({ type }) => filters.includes(type)) .filter(({ type }) => filters.includes(type))
.filter(searchFn(searchTerm))
.map((item) => <TxInternalsTableItem key={ item.id } { ...item }/>) } .map((item) => <TxInternalsTableItem key={ item.id } { ...item }/>) }
</Tbody> </Tbody>
</Table> </Table>
......
...@@ -5,21 +5,7 @@ import type { TxInternalsType } from 'types/api/tx'; ...@@ -5,21 +5,7 @@ import type { TxInternalsType } from 'types/api/tx';
import useIsMobile from 'lib/hooks/useIsMobile'; import useIsMobile from 'lib/hooks/useIsMobile';
import FilterButton from 'ui/shared/FilterButton'; import FilterButton from 'ui/shared/FilterButton';
import { TX_INTERNALS_ITEMS } from 'ui/tx/internals/utils';
interface Filter {
title: string;
id: TxInternalsType;
}
const FILTERS: Array<Filter> = [
{ title: 'Call', id: 'call' },
{ title: 'Delegate call', id: 'delegate_call' },
{ title: 'Static call', id: 'static_call' },
{ title: 'Create', id: 'create' },
{ title: 'Create2', id: 'create2' },
{ title: 'Self-destruct', id: 'self_destruct' },
{ title: 'Reward', id: 'reward' },
];
interface Props { interface Props {
appliedFiltersNum?: number; appliedFiltersNum?: number;
...@@ -44,7 +30,7 @@ const TxInternalsFilter = ({ onFilterChange, defaultFilters, appliedFiltersNum } ...@@ -44,7 +30,7 @@ const TxInternalsFilter = ({ onFilterChange, defaultFilters, appliedFiltersNum }
<PopoverContent w="438px"> <PopoverContent w="438px">
<PopoverBody px={ 4 } py={ 6 } display="grid" gridTemplateColumns="1fr 1fr" rowGap={ 5 }> <PopoverBody px={ 4 } py={ 6 } display="grid" gridTemplateColumns="1fr 1fr" rowGap={ 5 }>
<CheckboxGroup size="lg" onChange={ onFilterChange } defaultValue={ defaultFilters }> <CheckboxGroup size="lg" onChange={ onFilterChange } defaultValue={ defaultFilters }>
{ FILTERS.map(({ title, id }) => <Checkbox key={ id } value={ id }><Text fontSize="md">{ title }</Text></Checkbox>) } { TX_INTERNALS_ITEMS.map(({ title, id }) => <Checkbox key={ id } value={ id }><Text fontSize="md">{ title }</Text></Checkbox>) }
</CheckboxGroup> </CheckboxGroup>
</PopoverBody> </PopoverBody>
</PopoverContent> </PopoverContent>
......
import { Tr, Td, Tag, Icon } from '@chakra-ui/react'; import { Tr, Td, Tag, Icon } from '@chakra-ui/react';
import capitalize from 'lodash/capitalize';
import React from 'react'; import React from 'react';
import rightArrowIcon from 'icons/arrows/right.svg'; import rightArrowIcon from 'icons/arrows/right.svg';
import Address from 'ui/shared/address/Address'; import Address from 'ui/shared/address/Address';
import AddressIcon from 'ui/shared/address/AddressIcon'; import AddressIcon from 'ui/shared/address/AddressIcon';
import AddressLink from 'ui/shared/address/AddressLink'; import AddressLink from 'ui/shared/address/AddressLink';
import { TX_INTERNALS_ITEMS } from 'ui/tx/internals/utils';
import TxStatus from 'ui/tx/TxStatus'; import TxStatus from 'ui/tx/TxStatus';
interface Props { interface Props {
...@@ -18,10 +18,12 @@ interface Props { ...@@ -18,10 +18,12 @@ interface Props {
} }
const TxInternalTableItem = ({ type, status, from, to, value, gasLimit }: Props) => { const TxInternalTableItem = ({ type, status, from, to, value, gasLimit }: Props) => {
const typeTitle = TX_INTERNALS_ITEMS.find(({ id }) => id === type)?.title;
return ( return (
<Tr alignItems="top"> <Tr alignItems="top">
<Td> <Td>
<Tag colorScheme="cyan" mr={ 2 }>{ capitalize(type) }</Tag> { typeTitle && <Tag colorScheme="cyan" mr={ 2 }>{ typeTitle }</Tag> }
<TxStatus status={ status }/> <TxStatus status={ status }/>
</Td> </Td>
<Td pr="0"> <Td pr="0">
......
import type { TxInternalsType } from 'types/api/tx';
interface TxInternalsTypeItem {
title: string;
id: TxInternalsType;
}
export const TX_INTERNALS_ITEMS: Array<TxInternalsTypeItem> = [
{ title: 'Call', id: 'call' },
{ title: 'Delegate call', id: 'delegate_call' },
{ title: 'Static call', id: 'static_call' },
{ title: 'Create', id: 'create' },
{ title: 'Create2', id: 'create2' },
{ title: 'Self-destruct', id: 'self_destruct' },
{ title: 'Reward', id: 'reward' },
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment