@@ -19,6 +19,7 @@ import NextLink from "next/link";
1919import { useTranslation } from "next-i18next" ;
2020import { useMemo , useState } from "react" ;
2121import { useCallback } from "react" ;
22+ import { useCurrentLocale } from "src/hooks/locale/useCurrentLocale" ;
2223import { useDeleteMessage } from "src/hooks/message/useDeleteMessage" ;
2324import { get } from "src/lib/api" ;
2425import { API_ROUTES , ROUTES } from "src/lib/routes" ;
@@ -27,7 +28,7 @@ import { isKnownEmoji } from "src/types/Emoji";
2728import useSWRImmutable from "swr/immutable" ;
2829
2930import { useUndeleteMessage } from "../../hooks/message/useUndeleteMessage" ;
30- import { DataTable , DataTableRowPropsCallback } from "../DataTable/DataTable" ;
31+ import { DataTable , DataTableRowPropsCallback , FilterItem } from "../DataTable/DataTable" ;
3132import { DataTableAction } from "../DataTable/DataTableAction" ;
3233import { useCursorPagination } from "../DataTable/useCursorPagination" ;
3334import { UserDisplayNameCell } from "../UserDisplayNameCell" ;
@@ -54,7 +55,17 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
5455 const [ deleteMessageId , setDeleteMessageId ] = useState < string | null > ( null ) ;
5556 const [ undeleteMessageId , setUndeleteMessageId ] = useState < string | null > ( null ) ;
5657 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+
5869 const {
5970 data : res ,
6071 isLoading,
@@ -65,6 +76,8 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
6576 direction : pagination . direction ,
6677 user_id : userId ,
6778 include_user : includeUser ,
79+ search_query,
80+ lang,
6881 } ) ,
6982 get ,
7083 {
@@ -110,14 +123,17 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
110123 } ,
111124 } ) ,
112125 columnHelper . accessor ( "text" , {
126+ meta : {
127+ filterable : true ,
128+ } ,
113129 cell : ( { getValue, row } ) => {
114130 const limit = 95 ;
115131 const text = getValue ( ) ;
116132 const isActive = row . original . isActive ;
117133 const renderText = isActive ? text : text . length > limit ? `${ text . slice ( 0 , limit ) } ...` : text ;
118134
119135 return (
120- < Box display = "-webkit-box" wordBreak = "break-all" whiteSpace = "pre-wrap" w = "md" >
136+ < Box wordBreak = "break-all" whiteSpace = "pre-wrap" w = "md" >
121137 < Avatar
122138 size = "xs"
123139 mr = "2"
@@ -139,7 +155,6 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
139155 ) ;
140156 } ,
141157 } ) ,
142-
143158 columnHelper . accessor ( "lang" , {
144159 header : "Language" ,
145160 cell : ( { getValue } ) => < Badge textTransform = "uppercase" > { getValue ( ) } </ Badge > ,
@@ -238,6 +253,7 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
238253 [ setActiveMessageId ]
239254 ) ;
240255 const columnVisibility = useMemo ( ( ) => ( { user : ! ! includeUser } ) , [ includeUser ] ) ;
256+
241257 return (
242258 < >
243259 < Modal isOpen = { isOpen } onClose = { onClose } isCentered >
@@ -280,6 +296,8 @@ export const AdminMessageTable = ({ userId, includeUser }: { userId?: string; in
280296 onPreviousClick = { ( ) => toPreviousPage ( res ) }
281297 columnVisibility = { columnVisibility }
282298 isLoading = { isLoading }
299+ filterValues = { filterValues }
300+ onFilterChange = { handleFilterValuesChange }
283301 > </ DataTable >
284302 </ >
285303 ) ;
0 commit comments