@@ -5,11 +5,9 @@ import {
5
5
SelectTrigger ,
6
6
SelectValue ,
7
7
} from "@/components/ui/select" ;
8
+ import { filterJobs } from "@/lib/jobs-filter" ;
8
9
import type { JobDto } from "@/tsr" ;
9
10
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" ;
13
11
14
12
type JobsFilterProps = {
15
13
jobs : JobDto [ ] ;
@@ -25,38 +23,65 @@ export function JobsFilter({ jobs, filter, onChange }: JobsFilterProps) {
25
23
return acc ;
26
24
} , [ ] ) ;
27
25
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
+
28
33
const filteredJobs = filterJobs ( jobs , filter ) ;
29
34
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
+
30
55
return (
31
56
< div className = "flex gap-2" >
32
57
< 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 >
60
85
</ div >
61
86
</ div >
62
87
) ;
0 commit comments