Skip to content

Commit aaf5045

Browse files
committed
Makes LogsSearchInput more generic as it’s being used in multiple places
1 parent e64b101 commit aaf5045

File tree

4 files changed

+34
-54
lines changed
  • apps/webapp/app
    • components/primitives
    • routes
      • _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.branches
      • _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors._index
      • _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.logs

4 files changed

+34
-54
lines changed

apps/webapp/app/components/logs/LogsSearchInput.tsx renamed to apps/webapp/app/components/primitives/SearchInput.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@ import { ShortcutKey } from "~/components/primitives/ShortcutKey";
66
import { useSearchParams } from "~/hooks/useSearchParam";
77
import { cn } from "~/utils/cn";
88

9-
export type LogsSearchInputProps = {
9+
export type SearchInputProps = {
1010
placeholder?: string;
11+
/** Additional URL params to reset when searching or clearing (e.g. pagination). Defaults to ["cursor", "direction"]. */
12+
resetParams?: string[];
1113
};
1214

13-
export function LogsSearchInput({ placeholder = "Search logs…" }: LogsSearchInputProps) {
15+
export function SearchInput({
16+
placeholder = "Search logs…",
17+
resetParams = ["cursor", "direction"],
18+
}: SearchInputProps) {
1419
const inputRef = useRef<HTMLInputElement>(null);
1520

1621
const { value, replace, del } = useSearchParams();
1722

18-
// Get initial search value from URL
1923
const initialSearch = value("search") ?? "";
2024

2125
const [text, setText] = useState(initialSearch);
2226
const [isFocused, setIsFocused] = useState(false);
2327

24-
// Update text when URL search param changes (only when not focused to avoid overwriting user input)
2528
useEffect(() => {
2629
const urlSearch = value("search") ?? "";
2730
if (urlSearch !== text && !isFocused) {
@@ -30,21 +33,22 @@ export function LogsSearchInput({ placeholder = "Search logs…" }: LogsSearchIn
3033
}, [value, text, isFocused]);
3134

3235
const handleSubmit = useCallback(() => {
36+
const resetValues = Object.fromEntries(resetParams.map((p) => [p, undefined]));
3337
if (text.trim()) {
34-
replace({ search: text.trim() });
38+
replace({ search: text.trim(), ...resetValues });
3539
} else {
36-
del("search");
40+
del(["search", ...resetParams]);
3741
}
38-
}, [text, replace, del]);
42+
}, [text, replace, del, resetParams]);
3943

4044
const handleClear = useCallback(
4145
(e: React.MouseEvent<HTMLButtonElement>) => {
4246
e.preventDefault();
4347
e.stopPropagation();
4448
setText("");
45-
del(["search", "cursor", "direction"]);
49+
del(["search", ...resetParams]);
4650
},
47-
[del]
51+
[del, resetParams]
4852
);
4953

5054
return (
@@ -82,12 +86,12 @@ export function LogsSearchInput({ placeholder = "Search logs…" }: LogsSearchIn
8286
icon={<MagnifyingGlassIcon className="size-4" />}
8387
accessory={
8488
text.length > 0 ? (
85-
<div className="-mr-1 flex items-center gap-1">
86-
<ShortcutKey shortcut={{ key: "enter" }} variant="small" />
89+
<div className="-mr-1 flex items-center gap-1.5">
90+
<ShortcutKey shortcut={{ key: "enter" }} variant="medium" className="border-none" />
8791
<button
8892
type="button"
8993
onClick={handleClear}
90-
className="flex size-4.5 items-center justify-center rounded-[2px] border border-text-dimmed/40 text-text-dimmed hover:bg-charcoal-700 hover:text-text-bright"
94+
className="flex size-4.5 items-center justify-center rounded-[2px] border border-text-dimmed/40 text-text-dimmed transition hover:bg-charcoal-600 hover:text-text-bright"
9195
title="Clear search"
9296
>
9397
<XMarkIcon className="size-3" />

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.branches/route.tsx

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { conform, useForm } from "@conform-to/react";
22
import { parse } from "@conform-to/zod";
3-
import {
4-
ArrowRightIcon,
5-
ArrowUpCircleIcon,
6-
CheckIcon,
7-
MagnifyingGlassIcon,
8-
PlusIcon,
9-
} from "@heroicons/react/20/solid";
3+
import { ArrowRightIcon, ArrowUpCircleIcon, CheckIcon, PlusIcon } from "@heroicons/react/20/solid";
104
import { BookOpenIcon } from "@heroicons/react/24/solid";
115
import { DialogClose } from "@radix-ui/react-dialog";
126
import { Form, useActionData, useLocation, useSearchParams } from "@remix-run/react";
137
import { type ActionFunctionArgs, json, type LoaderFunctionArgs } from "@remix-run/server-runtime";
148
import { GitMeta } from "@trigger.dev/core/v3";
159
import { useCallback, useEffect, useState } from "react";
10+
import { SearchInput } from "~/components/primitives/SearchInput";
1611
import { typedjson, useTypedLoaderData } from "remix-typedjson";
1712
import { z } from "zod";
1813
import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons";
@@ -62,7 +57,7 @@ import { InfoIconTooltip, SimpleTooltip } from "~/components/primitives/Tooltip"
6257
import { useEnvironment } from "~/hooks/useEnvironment";
6358
import { useOrganization } from "~/hooks/useOrganizations";
6459
import { useProject } from "~/hooks/useProject";
65-
import { useThrottle } from "~/hooks/useThrottle";
60+
6661
import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
6762
import { BranchesPresenter } from "~/presenters/v3/BranchesPresenter.server";
6863
import { logger } from "~/services/logger.server";
@@ -434,42 +429,23 @@ export default function Page() {
434429

435430
export function BranchFilters() {
436431
const [searchParams, setSearchParams] = useSearchParams();
437-
const { search, showArchived, page } = BranchesOptions.parse(
438-
Object.fromEntries(searchParams.entries())
439-
);
432+
const { showArchived } = BranchesOptions.parse(Object.fromEntries(searchParams.entries()));
440433

441-
const handleFilterChange = useCallback((filterType: string, value: string | undefined) => {
434+
const handleArchivedChange = useCallback((checked: boolean) => {
442435
setSearchParams((s) => {
443-
if (value) {
444-
searchParams.set(filterType, value);
436+
if (checked) {
437+
s.set("showArchived", "true");
445438
} else {
446-
searchParams.delete(filterType);
439+
s.delete("showArchived");
447440
}
448-
searchParams.delete("page");
449-
return searchParams;
441+
s.delete("page");
442+
return s;
450443
});
451444
}, []);
452445

453-
const handleArchivedChange = useCallback((checked: boolean) => {
454-
handleFilterChange("showArchived", checked ? "true" : undefined);
455-
}, []);
456-
457-
const handleSearchChange = useThrottle((value: string) => {
458-
handleFilterChange("search", value.length === 0 ? undefined : value);
459-
}, 300);
460-
461446
return (
462-
<div className="flex w-full gap-2">
463-
<Input
464-
name="search"
465-
placeholder="Search branch name"
466-
icon={MagnifyingGlassIcon}
467-
variant="tertiary"
468-
className="grow"
469-
defaultValue={search}
470-
onChange={(e) => handleSearchChange(e.target.value)}
471-
/>
472-
447+
<div className="flex w-full items-center justify-between gap-2">
448+
<SearchInput placeholder="Search branch name" resetParams={["page"]} />
473449
<Switch
474450
checked={showArchived ?? false}
475451
onCheckedChange={handleArchivedChange}

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors._index/route.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from "recharts";
1515
import { TypedAwait, typeddefer, useTypedLoaderData } from "remix-typedjson";
1616
import { PageBody } from "~/components/layout/AppLayout";
17-
import { LogsSearchInput } from "~/components/logs/LogsSearchInput";
17+
import { SearchInput } from "~/components/primitives/SearchInput";
1818
import { LogsTaskFilter } from "~/components/logs/LogsTaskFilter";
1919
import { Button } from "~/components/primitives/Buttons";
2020
import { Callout } from "~/components/primitives/Callout";
@@ -255,7 +255,7 @@ function FiltersBar({
255255
maxPeriodDays={retentionLimitDays}
256256
labelName="Occurred"
257257
/>
258-
<LogsSearchInput placeholder="Search errors..." />
258+
<SearchInput placeholder="Search errors" />
259259
{hasFilters && (
260260
<Form className="h-6">
261261
<Button
@@ -270,7 +270,7 @@ function FiltersBar({
270270
<>
271271
<LogsTaskFilter possibleTasks={[]} />
272272
<TimeFilter defaultPeriod={defaultPeriod} maxPeriodDays={retentionLimitDays} />
273-
<LogsSearchInput placeholder="Search errors..." />
273+
<SearchInput placeholder="Search errors" />
274274
{hasFilters && (
275275
<Form className="h-6">
276276
<Button

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.logs/route.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Paragraph } from "~/components/primitives/Paragraph";
2626
import { Callout } from "~/components/primitives/Callout";
2727
import { LogsTable } from "~/components/logs/LogsTable";
2828
import { LogDetailView } from "~/components/logs/LogDetailView";
29-
import { LogsSearchInput } from "~/components/logs/LogsSearchInput";
29+
import { SearchInput } from "~/components/primitives/SearchInput";
3030
import { LogsLevelFilter } from "~/components/logs/LogsLevelFilter";
3131
import { LogsTaskFilter } from "~/components/logs/LogsTaskFilter";
3232
import { LogsRunIdFilter } from "~/components/logs/LogsRunIdFilter";
@@ -271,7 +271,7 @@ function FiltersBar({
271271
<LogsRunIdFilter />
272272
<TimeFilter defaultPeriod={defaultPeriod} maxPeriodDays={retentionLimitDays} />
273273
<LogsLevelFilter />
274-
<LogsSearchInput />
274+
<SearchInput />
275275
{hasFilters && (
276276
<Form className="h-6">
277277
<Button
@@ -288,7 +288,7 @@ function FiltersBar({
288288
<LogsRunIdFilter />
289289
<TimeFilter defaultPeriod={defaultPeriod} maxPeriodDays={retentionLimitDays} />
290290
<LogsLevelFilter />
291-
<LogsSearchInput />
291+
<SearchInput />
292292
{hasFilters && (
293293
<Form className="h-6">
294294
<Button

0 commit comments

Comments
 (0)