Skip to content

Commit e4b87d9

Browse files
committed
Improved the hints panell toggle and updates search field
1 parent c715dd3 commit e4b87d9

File tree

2 files changed

+22
-18
lines changed
  • apps/webapp/app
    • components/primitives
    • routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam._index

2 files changed

+22
-18
lines changed

apps/webapp/app/components/primitives/SearchInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ export type SearchInputProps = {
1010
placeholder?: string;
1111
/** Additional URL params to reset when searching or clearing (e.g. pagination). Defaults to ["cursor", "direction"]. */
1212
resetParams?: string[];
13+
autoFocus?: boolean;
1314
};
1415

1516
export function SearchInput({
1617
placeholder = "Search logs…",
1718
resetParams = ["cursor", "direction"],
19+
autoFocus,
1820
}: SearchInputProps) {
1921
const inputRef = useRef<HTMLInputElement>(null);
2022

@@ -71,6 +73,7 @@ export function SearchInput({
7173
value={text}
7274
onChange={(e) => setText(e.target.value)}
7375
fullWidth
76+
autoFocus={autoFocus}
7477
className={cn("", isFocused && "placeholder:text-text-dimmed/70")}
7578
onKeyDown={(e) => {
7679
if (e.key === "Enter") {

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
ChevronUpIcon,
66
ExclamationTriangleIcon,
77
LightBulbIcon,
8-
MagnifyingGlassIcon,
98
UserPlusIcon,
109
VideoCameraIcon,
1110
} from "@heroicons/react/20/solid";
@@ -15,7 +14,7 @@ import { type ActionFunctionArgs, type LoaderFunctionArgs } from "@remix-run/ser
1514
import { DiscordIcon } from "@trigger.dev/companyicons";
1615
import { formatDurationMilliseconds } from "@trigger.dev/core/v3";
1716
import type { TaskRunStatus } from "@trigger.dev/database";
18-
import { Fragment, Suspense, useCallback, useEffect, useRef, useState } from "react";
17+
import { Fragment, Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
1918
import type { PanelHandle } from "react-window-splitter";
2019
import { Bar, BarChart, ResponsiveContainer, Tooltip, type TooltipProps } from "recharts";
2120
import { TypedAwait, typeddefer, useTypedLoaderData } from "remix-typedjson";
@@ -37,7 +36,7 @@ import { Callout } from "~/components/primitives/Callout";
3736
import { formatDateTime } from "~/components/primitives/DateTime";
3837
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "~/components/primitives/Dialog";
3938
import { Header2, Header3 } from "~/components/primitives/Headers";
40-
import { Input } from "~/components/primitives/Input";
39+
import { SearchInput } from "~/components/primitives/SearchInput";
4140
import { NavBar, PageAccessories, PageTitle } from "~/components/primitives/PageHeader";
4241
import { Paragraph } from "~/components/primitives/Paragraph";
4342
import { PopoverMenuItem } from "~/components/primitives/Popover";
@@ -71,7 +70,8 @@ import {
7170
} from "~/components/runs/v3/TaskTriggerSource";
7271
import { useEnvironment } from "~/hooks/useEnvironment";
7372
import { useEventSource } from "~/hooks/useEventSource";
74-
import { useFuzzyFilter } from "~/hooks/useFuzzyFilter";
73+
import { useSearchParams } from "~/hooks/useSearchParam";
74+
import { matchSorter } from "match-sorter";
7575
import { useOrganization } from "~/hooks/useOrganizations";
7676
import { useProject } from "~/hooks/useProject";
7777
import { findProjectBySlug } from "~/models/project.server";
@@ -174,10 +174,19 @@ export default function Page() {
174174
const environment = useEnvironment();
175175
const { tasks, activity, runningStats, durations, usefulLinksPreference } =
176176
useTypedLoaderData<typeof loader>();
177-
const { filterText, setFilterText, filteredItems } = useFuzzyFilter<TaskListItem>({
178-
items: tasks,
179-
keys: ["slug", "filePath", "triggerSource"],
180-
});
177+
const { value: searchValue } = useSearchParams();
178+
const search = searchValue("search") ?? "";
179+
const filteredItems = useMemo(() => {
180+
const terms = search
181+
.trim()
182+
.split(" ")
183+
.filter((t) => t !== "");
184+
if (terms.length === 0) return tasks;
185+
return terms.reduceRight(
186+
(results, term) => matchSorter(results, term, { keys: ["slug", "filePath", "triggerSource"] }),
187+
tasks
188+
);
189+
}, [tasks, search]);
181190

182191
const hasTasks = tasks.length > 0;
183192

@@ -241,16 +250,8 @@ export default function Page() {
241250
<div className="flex min-w-0 max-w-full flex-col">
242251
{tasks.length === 0 ? <UserHasNoTasks /> : null}
243252
<div className="max-h-full overflow-hidden">
244-
<div className="flex items-center gap-1 p-2">
245-
<Input
246-
placeholder="Search tasks"
247-
variant="tertiary"
248-
icon={MagnifyingGlassIcon}
249-
fullWidth={true}
250-
value={filterText}
251-
onChange={(e) => setFilterText(e.target.value)}
252-
autoFocus
253-
/>
253+
<div className="flex items-center justify-between gap-1 p-2">
254+
<SearchInput placeholder="Search tasks…" autoFocus />
254255
{!showUsefulLinks && (
255256
<Button
256257
variant="secondary/small"

0 commit comments

Comments
 (0)