Skip to content

Commit d488cbe

Browse files
authored
update search bar (#28)
1 parent ebc3e41 commit d488cbe

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

dashboard/log-analyzer/src/components/filters/SearchBar.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
import { Input } from "@/components/ui/input";
44
import { Search, X } from "lucide-react";
55
import { useRouter, useSearchParams, usePathname } from "next/navigation";
6-
import { useDebouncedCallback } from "use-debounce";
76
import { Button } from "@/components/ui/button";
8-
import { useState } from "react";
7+
import { useState, useEffect } from "react";
98

109
export function SearchBar() {
1110
const router = useRouter();
1211
const pathname = usePathname();
1312
const searchParams = useSearchParams();
14-
const [searchTerm, setSearchTerm] = useState(searchParams.get('message') ?? '');
13+
const [inputValue, setInputValue] = useState('');
1514

16-
const handleSearch = useDebouncedCallback((term: string) => {
15+
useEffect(() => {
16+
setInputValue(searchParams.get('message') ?? '');
17+
}, [searchParams]);
18+
19+
const handleSearch = (term: string) => {
1720
const params = new URLSearchParams(searchParams.toString());
1821

1922
if (term) {
@@ -23,26 +26,30 @@ export function SearchBar() {
2326
}
2427

2528
router.replace(`${pathname}?${params.toString()}`);
26-
}, 300);
29+
};
2730

2831
const handleClear = () => {
29-
setSearchTerm('');
32+
setInputValue('');
3033
handleSearch('');
3134
};
3235

36+
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
37+
if (e.key === 'Enter') {
38+
handleSearch(inputValue);
39+
}
40+
};
41+
3342
return (
3443
<div className="relative flex-1">
3544
<Search className="absolute left-3 top-3 h-4 w-4 text-[var(--button-text)]" />
3645
<Input
3746
placeholder="Search logs..."
3847
className="h-10 pl-9 pr-9 border-[var(--border-gray)]"
39-
value={searchTerm}
40-
onChange={(e) => {
41-
setSearchTerm(e.target.value);
42-
handleSearch(e.target.value);
43-
}}
48+
value={inputValue}
49+
onChange={(e) => setInputValue(e.target.value)}
50+
onKeyDown={handleKeyDown}
4451
/>
45-
{searchTerm && (
52+
{inputValue && (
4653
<Button
4754
variant="ghost"
4855
size="icon"

tinybird/datasources/logs.datasource

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ SCHEMA >
1919

2020
ENGINE "MergeTree"
2121
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
22-
ENGINE_SORTING_KEY "timestamp, service, level"
22+
ENGINE_SORTING_KEY "timestamp, environment, service, level"
2323
ENGINE_TTL "toDateTime(timestamp) + INTERVAL 180 DAY"
2424

0 commit comments

Comments
 (0)