Skip to content

Commit 55d532a

Browse files
committed
Create custom filter type component
1 parent 9de7d66 commit 55d532a

5 files changed

Lines changed: 28 additions & 84 deletions

File tree

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { FC } from 'react'
22
import { useTranslation } from 'react-i18next'
3-
import { Select } from '@oasisprotocol/ui-library/src/components/select'
4-
import Typography from '@mui/material/Typography'
53
import { ConsensusEventType, Layer } from '../../../oasis-nexus/api'
64
import { ConsensusEventFilteringType } from '../../hooks/useCommonParams'
75
import { TFunction } from 'i18next'
86
import { paraTimesConfig } from '../../../config'
97
import { ParamSetterFunction } from '../../hooks/useTypedSearchParam'
108
import { getConsensusEventTypeLabel } from './ConsensusEventDetails'
9+
import { FilterByType } from '../FilterByType'
1110

1211
type Option = {
1312
value: ConsensusEventFilteringType
@@ -26,24 +25,6 @@ const getConsensusEventTypeOptions = (t: TFunction, layer: Layer) => {
2625
)
2726
}
2827

29-
const FilterLabel: FC = () => {
30-
const { t } = useTranslation()
31-
return (
32-
<Typography
33-
component={'span'}
34-
sx={{
35-
fontStyle: 'normal',
36-
fontWeight: 700,
37-
fontSize: 16,
38-
lineHeight: '150%',
39-
marginRight: 4,
40-
}}
41-
>
42-
{t('event.filterByType')}
43-
</Typography>
44-
)
45-
}
46-
4728
export const ConsensusEventTypeFilter: FC<{
4829
layer: Layer
4930
value: ConsensusEventFilteringType
@@ -57,5 +38,5 @@ export const ConsensusEventTypeFilter: FC<{
5738
? [...defaultOptions, ...customOptions]
5839
: [...defaultOptions, ...getConsensusEventTypeOptions(t, layer)]
5940

60-
return <Select options={options} value={value} handleChange={setValue} />
41+
return <FilterByType options={options} value={value} handleChange={setValue} />
6142
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Select, SelectOption } from '@oasisprotocol/ui-library/src/components/select'
2+
3+
type FilterByTypeProps<T extends string = string> = {
4+
options: SelectOption<T>[]
5+
handleChange?: (value: T) => void
6+
value: T
7+
}
8+
9+
export const FilterByType = <T extends string = string>({
10+
handleChange,
11+
options,
12+
value,
13+
}: FilterByTypeProps<T>) => {
14+
return (
15+
<div className="flex gap-2 items-center">
16+
<div className="text-muted-foreground text-sm font-medium">Filter by type</div>
17+
<Select className="min-w-[150px]" options={options} value={value} handleChange={handleChange} />
18+
</div>
19+
)
20+
}
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { FC } from 'react'
22
import { useTranslation } from 'react-i18next'
3-
import { Select } from '@oasisprotocol/ui-library/src/components/select'
4-
import Typography from '@mui/material/Typography'
53
import { Layer, RuntimeEventType } from '../../../oasis-nexus/api'
64
import { RuntimeEventFilteringType } from '../../hooks/useCommonParams'
75
import { TFunction } from 'i18next'
86
import { paraTimesConfig } from '../../../config'
97
import { getRuntimeEventMethodLabel } from './RuntimeEventDetails'
8+
import { FilterByType } from '../FilterByType'
109

1110
type RuntimeEventTypeFilterOption = { value: RuntimeEventFilteringType; label: string }
1211

@@ -22,24 +21,6 @@ const getRuntimeEventTypeOptions = (t: TFunction, layer: Layer) => {
2221
)
2322
}
2423

25-
const FilterLabel: FC = () => {
26-
const { t } = useTranslation()
27-
return (
28-
<Typography
29-
component={'span'}
30-
sx={{
31-
fontStyle: 'normal',
32-
fontWeight: 700,
33-
fontSize: 16,
34-
lineHeight: '150%',
35-
marginRight: 4,
36-
}}
37-
>
38-
{t('event.filterByType')}
39-
</Typography>
40-
)
41-
}
42-
4324
export const RuntimeEventTypeFilter: FC<{
4425
layer: Layer
4526
value: RuntimeEventFilteringType
@@ -56,5 +37,5 @@ export const RuntimeEventTypeFilter: FC<{
5637
? [...defaultOptions, ...customOptions]
5738
: [...defaultOptions, ...getRuntimeEventTypeOptions(t, layer)]
5839

59-
return <Select options={options} value={value} handleChange={setValue} />
40+
return <FilterByType options={options} value={value} handleChange={setValue} />
6041
}

src/app/components/Transactions/ConsensusTransactionMethodFilter.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
11
import { FC } from 'react'
22
import { getConsensusTxMethodOptions, ConsensusTxMethodFilterOption } from '../ConsensusTransactionMethod'
33
import { useTranslation } from 'react-i18next'
4-
import { Select } from '@oasisprotocol/ui-library/src/components/select'
5-
import Typography from '@mui/material/Typography'
64
import { ParamSetterFunction } from '../../hooks/useTypedSearchParam'
7-
8-
const FilterLabel: FC = () => {
9-
const { t } = useTranslation()
10-
return (
11-
<Typography
12-
component={'span'}
13-
sx={{
14-
fontStyle: 'normal',
15-
fontWeight: 700,
16-
fontSize: 16,
17-
lineHeight: '150%',
18-
marginRight: 4,
19-
}}
20-
>
21-
{t('transactions.filterByMethod')}
22-
</Typography>
23-
)
24-
}
5+
import { FilterByType } from '../FilterByType'
256

267
export const ConsensusTransactionMethodFilter: FC<{
278
value: ConsensusTxMethodFilterOption
@@ -30,7 +11,7 @@ export const ConsensusTransactionMethodFilter: FC<{
3011
}> = ({ value, setValue, expand }) => {
3112
const { t } = useTranslation()
3213
return (
33-
<Select
14+
<FilterByType
3415
options={[{ value: 'any', label: 'Any' }, ...getConsensusTxMethodOptions(t)]}
3516
value={value}
3617
handleChange={setValue}
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
import { FC } from 'react'
22
import { getRuntimeTxMethodOptions, RuntimeTxMethodFilterOption } from '../RuntimeTransactionMethod'
33
import { useTranslation } from 'react-i18next'
4-
import { Select } from '@oasisprotocol/ui-library/src/components/select'
5-
import Typography from '@mui/material/Typography'
64
import { Layer } from '../../../oasis-nexus/api'
75
import { ParamSetterFunction } from '../../hooks/useTypedSearchParam'
86
import { RuntimeTxMethodFilteringType } from '../../hooks/useCommonParams'
9-
10-
const FilterLabel: FC = () => {
11-
const { t } = useTranslation()
12-
return (
13-
<Typography
14-
component={'span'}
15-
sx={{
16-
fontStyle: 'normal',
17-
fontWeight: 700,
18-
fontSize: 16,
19-
lineHeight: '150%',
20-
marginRight: 4,
21-
}}
22-
>
23-
{t('transactions.filterByMethod')}
24-
</Typography>
25-
)
26-
}
7+
import { FilterByType } from '../FilterByType'
278

289
export const RuntimeTransactionMethodFilter: FC<{
2910
layer: Layer
@@ -38,5 +19,5 @@ export const RuntimeTransactionMethodFilter: FC<{
3819
? [...defaultOptions, ...customOptions]
3920
: [...defaultOptions, ...getRuntimeTxMethodOptions(t, layer)]
4021

41-
return <Select options={options} value={value} handleChange={setValue} />
22+
return <FilterByType options={options} value={value} handleChange={setValue} />
4223
}

0 commit comments

Comments
 (0)