mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-09 07:42:39 +02:00
fix: debounce logs message filter to prevent UI jank
- Add local state for message filter input with 300ms debounce - Use useDebouncedValue hook to delay table filter updates - Prevents full filtering pipeline from running on every keystroke - Improves responsiveness for large log datasets
This commit is contained in:
parent
36391acfd0
commit
c8ff3d7e76
1 changed files with 16 additions and 5 deletions
|
|
@ -44,8 +44,9 @@ import {
|
||||||
import { AnimatePresence, motion, type Variants } from "motion/react";
|
import { AnimatePresence, motion, type Variants } from "motion/react";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import React, { useCallback, useContext, useId, useMemo, useRef, useState } from "react";
|
import React, { useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { useDebouncedValue } from "@/hooks/use-debounced-value";
|
||||||
import {
|
import {
|
||||||
createLogMutationAtom,
|
createLogMutationAtom,
|
||||||
deleteLogMutationAtom,
|
deleteLogMutationAtom,
|
||||||
|
|
@ -706,6 +707,15 @@ function LogsFilters({
|
||||||
id: string;
|
id: string;
|
||||||
}) {
|
}) {
|
||||||
const t = useTranslations("logs");
|
const t = useTranslations("logs");
|
||||||
|
const [filterInput, setFilterInput] = useState(
|
||||||
|
(table.getColumn("message")?.getFilterValue() ?? "") as string
|
||||||
|
);
|
||||||
|
const debouncedFilter = useDebouncedValue(filterInput, 300);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
table.getColumn("message")?.setFilterValue(debouncedFilter || undefined);
|
||||||
|
}, [debouncedFilter, table]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
className="flex flex-wrap items-center justify-start gap-3 w-full"
|
className="flex flex-wrap items-center justify-start gap-3 w-full"
|
||||||
|
|
@ -720,22 +730,23 @@ function LogsFilters({
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
className={cn(
|
className={cn(
|
||||||
"peer w-full sm:min-w-60 ps-9",
|
"peer w-full sm:min-w-60 ps-9",
|
||||||
Boolean(table.getColumn("message")?.getFilterValue()) && "pe-9"
|
Boolean(filterInput) && "pe-9"
|
||||||
)}
|
)}
|
||||||
value={(table.getColumn("message")?.getFilterValue() ?? "") as string}
|
value={filterInput}
|
||||||
onChange={(e) => table.getColumn("message")?.setFilterValue(e.target.value)}
|
onChange={(e) => setFilterInput(e.target.value)}
|
||||||
placeholder={t("filter_by_message")}
|
placeholder={t("filter_by_message")}
|
||||||
type="text"
|
type="text"
|
||||||
/>
|
/>
|
||||||
<div className="pointer-events-none absolute inset-y-0 start-0 flex items-center justify-center ps-3 text-muted-foreground/80">
|
<div className="pointer-events-none absolute inset-y-0 start-0 flex items-center justify-center ps-3 text-muted-foreground/80">
|
||||||
<ListFilter size={16} strokeWidth={2} />
|
<ListFilter size={16} strokeWidth={2} />
|
||||||
</div>
|
</div>
|
||||||
{Boolean(table.getColumn("message")?.getFilterValue()) && (
|
{Boolean(filterInput) && (
|
||||||
<Button
|
<Button
|
||||||
className="absolute inset-y-0 end-0 flex h-full w-9 items-center justify-center rounded-e-lg text-muted-foreground/80 hover:text-foreground"
|
className="absolute inset-y-0 end-0 flex h-full w-9 items-center justify-center rounded-e-lg text-muted-foreground/80 hover:text-foreground"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
setFilterInput("");
|
||||||
table.getColumn("message")?.setFilterValue("");
|
table.getColumn("message")?.setFilterValue("");
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue