Skip to content

Commit f699140

Browse files
committed
feat: Filter jobs on name
1 parent 8126829 commit f699140

File tree

5 files changed

+62
-31
lines changed

5 files changed

+62
-31
lines changed

packages/dashboard/src/components/JobsFilter.tsx

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import {
55
SelectTrigger,
66
SelectValue,
77
} from "@/components/ui/select";
8+
import { filterJobs } from "@/lib/jobs-filter";
89
import type { JobDto } from "@/tsr";
910
import type { JobsFilterData } from "./types";
10-
import { Button } from "@/components/ui/button";
11-
import { X } from "lucide-react";
12-
import { filterJobs } from "@/lib/jobs-filter";
1311

1412
type JobsFilterProps = {
1513
jobs: JobDto[];
@@ -25,38 +23,65 @@ export function JobsFilter({ jobs, filter, onChange }: JobsFilterProps) {
2523
return acc;
2624
}, []);
2725

26+
const names = jobs.reduce<string[]>((acc, job) => {
27+
if (!acc.includes(job.name)) {
28+
acc.push(job.name);
29+
}
30+
return acc;
31+
}, []);
32+
2833
const filteredJobs = filterJobs(jobs, filter);
2934

35+
let tagValue = filter.tag;
36+
if (tagValue === null) {
37+
tagValue = "all";
38+
}
39+
40+
const onTagChange = (value: string) => {
41+
const tag = value === "all" ? null : value;
42+
onChange({ tag });
43+
};
44+
45+
let nameValue = filter.name;
46+
if (nameValue === null) {
47+
nameValue = "all";
48+
}
49+
50+
const onNameChange = (value: string) => {
51+
const name = value === "all" ? null : value;
52+
onChange({ name });
53+
};
54+
3055
return (
3156
<div className="flex gap-2">
3257
<div className="grow flex items-center">{filteredJobs.length} jobs</div>
33-
<div className="flex">
34-
{filter.tag ? (
35-
<div className="h-10 flex items-center">
36-
{filter.tag}
37-
<Button
38-
variant="secondary"
39-
className="ml-2"
40-
size="icon"
41-
onClick={() => onChange({ tag: null })}
42-
>
43-
<X className="w-4 h-4" />
44-
</Button>
45-
</div>
46-
) : (
47-
<Select onValueChange={(tag) => onChange({ tag })}>
48-
<SelectTrigger className="w-[180px]">
49-
<SelectValue placeholder="Select tag" />
50-
</SelectTrigger>
51-
<SelectContent>
52-
{tags.map((tag) => (
53-
<SelectItem key={tag} value={tag}>
54-
{tag}
55-
</SelectItem>
56-
))}
57-
</SelectContent>
58-
</Select>
59-
)}
58+
<div className="flex gap-2">
59+
<Select value={nameValue} onValueChange={onNameChange}>
60+
<SelectTrigger className="w-[180px]">
61+
<SelectValue placeholder="Select tag" />
62+
</SelectTrigger>
63+
<SelectContent>
64+
<SelectItem value="all">name: all</SelectItem>
65+
{names.map((name) => (
66+
<SelectItem key={name} value={name}>
67+
name: {name}
68+
</SelectItem>
69+
))}
70+
</SelectContent>
71+
</Select>
72+
<Select value={tagValue} onValueChange={onTagChange}>
73+
<SelectTrigger className="w-[180px]">
74+
<SelectValue placeholder="Select tag" />
75+
</SelectTrigger>
76+
<SelectContent>
77+
<SelectItem value="all">tag: all</SelectItem>
78+
{tags.map((tag) => (
79+
<SelectItem key={tag} value={tag}>
80+
tag: {tag}
81+
</SelectItem>
82+
))}
83+
</SelectContent>
84+
</Select>
6085
</div>
6186
</div>
6287
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export type JobsFilterData = {
22
tag: string | null;
3+
name: string | null;
34
};

packages/dashboard/src/lib/jobs-filter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ export function filterJobs(jobs: JobDto[], filter: JobsFilterData) {
66
jobs = jobs.filter((job) => job.tag === filter.tag);
77
}
88

9+
if (filter.name) {
10+
jobs = jobs.filter((job) => job.name === filter.name);
11+
}
12+
913
return jobs;
1014
}

packages/dashboard/src/pages/JobPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function JobPage() {
1515
const { job, rootTree } = data.body;
1616

1717
return (
18-
<div className="flex flex-col grow bg-white">
18+
<div className="min-h-full flex flex-col grow bg-white">
1919
<div className="p-2 border-b border-border">
2020
<Button asChild variant="ghost">
2121
<Link to="/jobs">Jobs</Link>

packages/dashboard/src/pages/JobsPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function JobsPage() {
1313

1414
const [filter, setFilter] = useQueryParams<JobsFilterData>({
1515
tag: null,
16+
name: null,
1617
});
1718

1819
return (

0 commit comments

Comments
 (0)