Skip to content

Commit

Permalink
Merge pull request #64 from oceanprotocol/feat/multiple-filters
Browse files Browse the repository at this point in the history
feat: multiple ID filter
  • Loading branch information
tom1145 authored Dec 19, 2024
2 parents d3bd0d8 + d10c791 commit 281e3f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
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 @@ export const DataProvider: React.FC<DataProviderProps> = ({ children }) => {
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
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

0 comments on commit 281e3f5

Please sign in to comment.