fix: filtering
This commit is contained in:
		
							parent
							
								
									bb601d3c82
								
							
						
					
					
						commit
						3b32316688
					
				| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
import { Genre } from "@prisma/client";
 | 
			
		||||
import { FilterFn, Row } from "@tanstack/react-table";
 | 
			
		||||
 | 
			
		||||
export const genrePickerFilterFn = (row: Row<any>, columnId: string, filterValue: any) => {
 | 
			
		||||
 | 
			
		||||
	const genres: Genre[] = row.getValue(columnId)
 | 
			
		||||
 | 
			
		||||
	for (let index = 0; index < genres.length; index++) {
 | 
			
		||||
		if (genres[genres.length - 1].name.includes(filterValue)) {
 | 
			
		||||
			return true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ import { selectCol } from "app/ui/tables/selectColumn"
 | 
			
		|||
import NumberInputCell from "app/ui/tables/inputs/numberInput"
 | 
			
		||||
import { pubSchema } from "app/ui/forms/schemas"
 | 
			
		||||
import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput"
 | 
			
		||||
import { genrePickerFilterFn } from "app/lib/filterFns"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const columnHelper = createColumnHelper<PubWithGenres>()
 | 
			
		||||
| 
						 | 
				
			
			@ -66,10 +67,10 @@ export const columns: ColumnDef<PubWithGenres>[] = [
 | 
			
		|||
      </div>
 | 
			
		||||
    ),
 | 
			
		||||
    cell: GenrePickerInputCell,
 | 
			
		||||
    filterFn: "arrIncludes"
 | 
			
		||||
    //TODO - write custom filter function, to account for an array of objects
 | 
			
		||||
    filterFn: genrePickerFilterFn
 | 
			
		||||
  }),
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    accessorKey: "query_after_days",
 | 
			
		||||
    header: () => (
 | 
			
		||||
| 
						 | 
				
			
			@ -78,6 +79,7 @@ export const columns: ColumnDef<PubWithGenres>[] = [
 | 
			
		|||
        <span className="sm:hidden"><Clock /></span>
 | 
			
		||||
      </div>
 | 
			
		||||
    ),
 | 
			
		||||
    enableColumnFilter: false,
 | 
			
		||||
    cell: cell => (
 | 
			
		||||
      <>
 | 
			
		||||
        {/* @ts-ignore */}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ import NumberInputCell from "app/ui/tables/inputs/numberInput"
 | 
			
		|||
import { storySchema } from "app/ui/forms/schemas"
 | 
			
		||||
import { TextInputCell } from "app/ui/tables/inputs/textInput"
 | 
			
		||||
import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput"
 | 
			
		||||
import { genrePickerFilterFn } from "app/lib/filterFns"
 | 
			
		||||
const columnHelper = createColumnHelper<StoryWithGenres>()
 | 
			
		||||
 | 
			
		||||
export const columns: ColumnDef<StoryWithGenres>[] = [
 | 
			
		||||
| 
						 | 
				
			
			@ -78,7 +79,7 @@ export const columns: ColumnDef<StoryWithGenres>[] = [
 | 
			
		|||
      </div>
 | 
			
		||||
    ),
 | 
			
		||||
    cell: GenrePickerInputCell,
 | 
			
		||||
    filterFn: "arrIncludes",
 | 
			
		||||
    filterFn: genrePickerFilterFn,
 | 
			
		||||
    meta: {}
 | 
			
		||||
  }),
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue