@@ -19,6 +19,7 @@ import NextLink from "next/link";
19
19
import { useTranslation } from "next-i18next" ;
20
20
import { useMemo , useState } from "react" ;
21
21
import { useCallback } from "react" ;
22
+ import { useCurrentLocale } from "src/hooks/locale/useCurrentLocale" ;
22
23
import { useDeleteMessage } from "src/hooks/message/useDeleteMessage" ;
23
24
import { get } from "src/lib/api" ;
24
25
import { API_ROUTES , ROUTES } from "src/lib/routes" ;
@@ -27,7 +28,7 @@ import { isKnownEmoji } from "src/types/Emoji";
27
28
import useSWRImmutable from "swr/immutable" ;
28
29
29
30
import { useUndeleteMessage } from "../../hooks/message/useUndeleteMessage" ;
30
- import { DataTable , DataTableRowPropsCallback } from "../DataTable/DataTable" ;
31
+ import { DataTable , DataTableRowPropsCallback , FilterItem } from "../DataTable/DataTable" ;
31
32
import { DataTableAction } from "../DataTable/DataTableAction" ;
32
33
import { useCursorPagination } from "../DataTable/useCursorPagination" ;
33
34
import { UserDisplayNameCell } from "../UserDisplayNameCell" ;
@@ -54,7 +55,17 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
54
55
const [ deleteMessageId , setDeleteMessageId ] = useState < string | null > ( null ) ;
55
56
const [ undeleteMessageId , setUndeleteMessageId ] = useState < string | null > ( null ) ;
56
57
const [ activeMessageId , setActiveMessageId ] = useState < string > ( ) ;
57
- const { pagination, toNextPage, toPreviousPage } = useCursorPagination ( ) ;
58
+ const { pagination, toNextPage, toPreviousPage, resetCursor } = useCursorPagination ( ) ;
59
+ const [ filterValues , setFilterValues ] = useState < FilterItem [ ] > ( [ ] ) ;
60
+ const handleFilterValuesChange = ( values : FilterItem [ ] ) => {
61
+ setFilterValues ( values ) ;
62
+ resetCursor ( ) ;
63
+ } ;
64
+
65
+ const currentLang = useCurrentLocale ( ) ;
66
+ const search_query = filterValues . find ( ( f ) => f . id === "text" ) ?. value || undefined ; // avoid empty search
67
+ const lang = search_query ? currentLang : undefined ;
68
+
58
69
const {
59
70
data : res ,
60
71
isLoading,
@@ -65,6 +76,8 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
65
76
direction : pagination . direction ,
66
77
user_id : userId ,
67
78
include_user : includeUser ,
79
+ search_query,
80
+ lang,
68
81
} ) ,
69
82
get ,
70
83
{
@@ -110,14 +123,17 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
110
123
} ,
111
124
} ) ,
112
125
columnHelper . accessor ( "text" , {
126
+ meta : {
127
+ filterable : true ,
128
+ } ,
113
129
cell : ( { getValue, row } ) => {
114
130
const limit = 95 ;
115
131
const text = getValue ( ) ;
116
132
const isActive = row . original . isActive ;
117
133
const renderText = isActive ? text : text . length > limit ? `${ text . slice ( 0 , limit ) } ...` : text ;
118
134
119
135
return (
120
- < Box display = "-webkit-box" wordBreak = "break-all" whiteSpace = "pre-wrap" w = "md" >
136
+ < Box wordBreak = "break-all" whiteSpace = "pre-wrap" w = "md" >
121
137
< Avatar
122
138
size = "xs"
123
139
mr = "2"
@@ -139,7 +155,6 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
139
155
) ;
140
156
} ,
141
157
} ) ,
142
-
143
158
columnHelper . accessor ( "lang" , {
144
159
header : "Language" ,
145
160
cell : ( { getValue } ) => < Badge textTransform = "uppercase" > { getValue ( ) } </ Badge > ,
@@ -238,6 +253,7 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
238
253
[ setActiveMessageId ]
239
254
) ;
240
255
const columnVisibility = useMemo ( ( ) => ( { user : ! ! includeUser } ) , [ includeUser ] ) ;
256
+
241
257
return (
242
258
< >
243
259
< Modal isOpen = { isOpen } onClose = { onClose } isCentered >
@@ -280,6 +296,8 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
280
296
onPreviousClick = { ( ) => toPreviousPage ( res ) }
281
297
columnVisibility = { columnVisibility }
282
298
isLoading = { isLoading }
299
+ filterValues = { filterValues }
300
+ onFilterChange = { handleFilterValuesChange }
283
301
> </ DataTable >
284
302
</ >
285
303
) ;
0 commit comments