Skip to content
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: multiple ID filter #64

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
12 changes: 8 additions & 4 deletions src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,20 @@ export default function Table({
filterable: true,
filterOperators: [
{
label: 'contains',
value: 'contains',
label: 'equals',
value: 'value',
getApplyFilterFn: (filterItem) => {
return (params) => {
if (!filterItem.value) return true
return params.value?.toLowerCase().includes(filterItem.value.toLowerCase())
const ids = filterItem.value.split(',').map((id: string) => id.trim())
return ids.includes(params.value)
}
},
InputComponent: GridFilterInputValue,
InputComponentProps: { type: 'text' }
InputComponentProps: {
type: 'text',
placeholder: 'Enter ID(s), comma separated'
}
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions src/context/DataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
return Object.entries(filters)
.filter(([_, filterData]) => filterData?.value && filterData?.operator)
.map(([field, filterData]) => {
if (field === 'id') {
const ids = filterData.value.split(',').map((id: string) => id.trim())
return `filters[${field}][value]=${ids.join(',')}`
}
return `filters[${field}][${filterData.operator}]=${filterData.value}`
})
.join('&')
Expand Down Expand Up @@ -157,7 +161,7 @@
} finally {
setLoading(false)
}
}, [fetchUrl])

Check warning on line 164 in src/context/DataContext.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has missing dependencies: 'currentPage' and 'pageSize'. Either include them or remove the dependency array

const getTotalEligible = useCallback(async () => {
setLoading(true)
Expand Down Expand Up @@ -314,7 +318,7 @@
mounted = false
controller.abort()
}
}, [

Check warning on line 321 in src/context/DataContext.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'fetchCountryStats', 'fetchData', 'fetchSystemStats', 'getTotalEligible', 'getTotalRewards', and 'systemStats.cpuCounts'. Either include them or remove the dependency array
tableType,
currentPage,
pageSize,
Expand Down
2 changes: 1 addition & 1 deletion src/types/filters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type StringFilterOperator = 'contains' | 'eq'
export type StringFilterOperator = 'contains' | 'eq' | 'value'
export type NumberFilterOperator = 'eq' | 'gt' | 'lt'
export type FilterOperator = StringFilterOperator | NumberFilterOperator

Expand Down
Loading