Skip to content

Show active filter indicator above tables #545

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions components/Layout/FiltersFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,43 @@ import ViewTogggle from '../UI/ViewToggle'

import { TbArrowsSort } from 'react-icons/tb'
import { IoMdClose } from 'react-icons/io'
import { FaFilter } from 'react-icons/fa'
import { setTabParams, useWidth } from '../../utils'
import CurrencySelect from '../UI/CurrencySelect'
import { TablePagination } from '@mui/material'

// Filter Indicator Component
function FilterIndicator({ filters }) {
// Check if any filters are active
const activeFilters = Object.entries(filters).filter(([, value]) =>
value && value !== '' && value !== null && value !== undefined
)

if (activeFilters.length === 0) {
return null
}

const renderFilterValue = (key, value) => {

return `${key.charAt(0).toUpperCase() + key.slice(1)} = ${value}`
}

return (
<div className="center mb-2">
<FaFilter />
<span>
Filter applied: {activeFilters.map(([key, value], index) => (
<span key={key}>
{index > 0 && index === activeFilters.length - 1 ? ' and ' : ''}
{index > 0 && index < activeFilters.length - 1 ? ', ' : ''}
{renderFilterValue(key, value)}
</span>
))}
</span>
</div>
)
}

export default function FiltersFrame({
children,
order,
Expand All @@ -33,7 +66,9 @@ export default function FiltersFrame({
setPage,
rowsPerPage,
setRowsPerPage,
onlyCsv
onlyCsv,
filters = {},
showFilterIndicator = false
}) {
const { t } = useTranslation()
const router = useRouter()
Expand Down Expand Up @@ -118,7 +153,7 @@ export default function FiltersFrame({
</>
) : (
''
)}
)}

{orderList && (
<>
Expand Down Expand Up @@ -190,7 +225,14 @@ export default function FiltersFrame({
>
{children[0]}
</LeftFilters>

<div className="content-text" style={contentStyle}>
{/* Filter Indicator */}
{showFilterIndicator && (
<FilterIndicator
filters={filters}
/>
)}
{children[1]}
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions pages/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ export default function Tokens({
setFiltersHide={setFiltersHide}
setSelectedCurrency={setSelectedCurrency}
selectedCurrency={selectedCurrency}
filters={{
issuer: issuer || '',
currency: currency || ''
}}
showFilterIndicator={width > 1300 ? filtersHide : !filtersHide}
>
{/* Left filters */}
<>
Expand Down