feat: support searchTerm in Filter Segment (#20526)

* feat: support searchTerm in Filter Segment

* update tests

* save and load searchTerm

* fix types

* add missing condition
This commit is contained in:
Eunjae Lee authored and GitHub committed 2025-04-07 05:27:58 -03:00
1 parent b6aedb830b
commit 703e20a43a
12 files changed
+133 -45

No files matched your search

@@ -1,7 +1,7 @@
"use client";
import type { Table } from "@tanstack/react-table";
import { forwardRef } from "react";
import { forwardRef, useEffect } from "react";
import type { ComponentPropsWithoutRef } from "react";
import { useState, type Ref, type ChangeEvent } from "react";
@@ -39,6 +39,10 @@ function SearchBarComponent({ className }: SearchBarProps, ref: Ref<HTMLInputEle
const { t } = useLocale();
const [localValue, setLocalValue] = useState(searchTerm);
useEffect(() => {
setLocalValue(searchTerm);
}, [searchTerm]);
const handleSearchChange = (event: ChangeEvent<HTMLInputElement>) => {
const value = event.target.value;
setLocalValue(value);
@@ -48,7 +52,7 @@ function SearchBarComponent({ className }: SearchBarProps, ref: Ref<HTMLInputEle
return (
<Input
ref={ref}
className={classNames("max-w-48" ,className)}
className={classNames("max-w-48", className)}
placeholder={t("search")}
value={localValue}
onChange={handleSearchChange}
@@ -52,6 +52,7 @@ export function SaveFilterSegmentButton() {
canSaveSegment,
setSegmentId,
pageSize,
searchTerm,
} = useDataTable();
const [saveMode, setSaveMode] = useState<"create" | "update">(() =>
@@ -105,6 +106,7 @@ export function SaveFilterSegmentButton() {
columnVisibility,
columnSizing,
perPage: pageSize,
searchTerm,
};
if (saveMode === "update") {