11import React from "react"
2- import { ColumnDef , createColumnHelper } from "@tanstack/react-table"
2+ import { ColumnDef , FilterFn , createColumnHelper } from "@tanstack/react-table"
33import { TaskLogToggleModal } from "../../components/TaskLogToggleModal"
44import { ProcessedIndividualTaskLog , ProcessedTeamTaskLog } from "../processing/processTaskLogs"
55import ToggleModal from "src/core/components/ToggleModal"
@@ -18,10 +18,63 @@ import {
1818} from "@heroicons/react/24/outline"
1919import TaskLogHistoryModal from "src/tasklogs/components/TaskLogHistoryModal"
2020import DateFormat from "src/core/components/DateFormat"
21+ import { createDateTextFilter } from "src/core/utils/tableFilters"
2122
2223// Column helper
2324const columnHelper = createColumnHelper < ProcessedIndividualTaskLog | ProcessedTeamTaskLog > ( )
2425
26+ const lastUpdateFilter = createDateTextFilter ( { emptyLabel : "no date" } )
27+
28+ const statusFilter : FilterFn < ProcessedIndividualTaskLog | ProcessedTeamTaskLog > = (
29+ row ,
30+ columnId ,
31+ filterValue
32+ ) => {
33+ const selected = String ( filterValue ?? "" )
34+ . trim ( )
35+ . toLowerCase ( )
36+
37+ if ( ! selected ) {
38+ return true
39+ }
40+
41+ const value = String ( row . getValue ( columnId ) ?? "" )
42+ . trim ( )
43+ . toLowerCase ( )
44+
45+ return value === selected
46+ }
47+
48+ const approvalFilter : FilterFn < ProcessedIndividualTaskLog | ProcessedTeamTaskLog > = (
49+ row ,
50+ columnId ,
51+ filterValue
52+ ) => {
53+ const selected = String ( filterValue ?? "" )
54+ . trim ( )
55+ . toLowerCase ( )
56+
57+ if ( ! selected ) {
58+ return true
59+ }
60+
61+ const value = row . getValue < boolean | null > ( columnId )
62+
63+ if ( selected === "approved" ) {
64+ return value === true
65+ }
66+
67+ if ( selected === "not approved" ) {
68+ return value === false
69+ }
70+
71+ if ( selected === "pending" ) {
72+ return value === null
73+ }
74+
75+ return true
76+ }
77+
2578// ColumnDefs
2679// Table for assignment without a form
2780export const TaskLogCompleteColumns : ColumnDef <
@@ -82,7 +135,7 @@ export const TaskLogCompleteColumns: ColumnDef<
82135 < HandRaisedIcon className = "h-5 w-5 inline-block" />
83136 </ span >
84137 ) }
85- < DateFormat date = { info . getValue ( ) } preset = "dateShort " />
138+ < DateFormat date = { info . getValue ( ) } preset = "date " />
86139 </ div >
87140 )
88141 } ,
@@ -101,13 +154,19 @@ export const TaskLogCompleteColumns: ColumnDef<
101154 </ div >
102155 ) ,
103156 id : "updatedAt" ,
157+ enableColumnFilter : true ,
158+ enableSorting : true ,
159+ filterFn : lastUpdateFilter ,
160+ meta : {
161+ filterVariant : "text" ,
162+ } ,
104163 } ) ,
105164 columnHelper . accessor ( "status" , {
106165 cell : ( info ) => {
107166 const value = info . getValue ( )
108167 const isCompleted = value === "Completed"
109168 return (
110- < div className = "flex justify-center items-center " >
169+ < div className = "flex" >
111170 { isCompleted ? (
112171 < CheckCircleIcon className = "h-6 w-6 text-success" title = "Completed" />
113172 ) : (
@@ -120,8 +179,13 @@ export const TaskLogCompleteColumns: ColumnDef<
120179 id : "status" ,
121180 enableColumnFilter : true ,
122181 enableSorting : true ,
182+ filterFn : statusFilter ,
123183 meta : {
124184 filterVariant : "select" ,
185+ selectOptions : [
186+ { label : "Completed" , value : "completed" } ,
187+ { label : "Not completed" , value : "not completed" } ,
188+ ] ,
125189 } ,
126190 } ) ,
127191 columnHelper . accessor ( "approved" , {
@@ -135,14 +199,20 @@ export const TaskLogCompleteColumns: ColumnDef<
135199 } else {
136200 icon = < ClockIcon className = "h-6 w-6 text-warning" title = "Pending" />
137201 }
138- return < div className = "flex justify-center items-center " > { icon } </ div >
202+ return < div className = "flex" > { icon } </ div >
139203 } ,
140204 header : "Approved" ,
141205 id : "approved" ,
142206 enableColumnFilter : true ,
143207 enableSorting : true ,
208+ filterFn : approvalFilter ,
144209 meta : {
145210 filterVariant : "select" ,
211+ selectOptions : [
212+ { label : "Approved" , value : "approved" } ,
213+ { label : "Pending" , value : "pending" } ,
214+ { label : "Not approved" , value : "not approved" } ,
215+ ] ,
146216 } ,
147217 } ) ,
148218 columnHelper . accessor ( "taskHistory" , {
0 commit comments