1
1
import React , { useState } from "react" ;
2
2
import { useDebouncedCallback } from "use-debounce" ;
3
- import { capitalize } from "lodash" ;
4
- import { Option } from "@features/ui" ;
5
- import { IssueFilters , IssueLevel , IssueStatus } from "@api/issues.types" ;
3
+ import { IssueLevel , IssueStatus } from "@api/issues.types" ;
6
4
import { useFilters } from "../../hooks/use-filters" ;
7
5
import * as S from "./filters.styled" ;
8
6
9
- function getStatusDefaultValue ( filters : IssueFilters ) {
10
- if ( ! filters . status ) {
11
- return "Status" ;
12
- }
13
- if ( filters . status === IssueStatus . open ) {
14
- return "Unresolved" ;
15
- }
16
- return "Resolved" ;
17
- }
7
+ const statusOptions = [
8
+ { value : undefined , label : "--None--" } ,
9
+ { value : IssueStatus . open , label : "Unresolved" } ,
10
+ { value : IssueStatus . resolved , label : "Resolved" } ,
11
+ ] ;
18
12
19
- function getLevelDefaultValue ( filters : IssueFilters ) {
20
- if ( ! filters . level ) {
21
- return "Level" ;
22
- }
23
- return capitalize ( filters . level ) ;
24
- }
13
+ const levelOptions = [
14
+ { value : undefined , label : "--None--" } ,
15
+ { value : IssueLevel . error , label : "Error" } ,
16
+ { value : IssueLevel . warning , label : "Warning" } ,
17
+ { value : IssueLevel . info , label : "Info" } ,
18
+ ] ;
25
19
26
20
export function Filters ( ) {
27
21
const { handleFilters, filters } = useFilters ( ) ;
@@ -34,57 +28,21 @@ export function Filters() {
34
28
debouncedHandleFilters ( { project : project . toLowerCase ( ) } ) ;
35
29
} ;
36
30
37
- const handleLevel = ( level ?: string ) => {
38
- if ( level ) {
39
- level = level . toLowerCase ( ) ;
40
- }
41
- handleFilters ( { level : level as IssueLevel } ) ;
42
- } ;
43
-
44
- const handleStatus = ( status ?: string ) => {
45
- if ( status === "Unresolved" ) {
46
- status = "open" ;
47
- }
48
- if ( status ) {
49
- status = status . toLowerCase ( ) ;
50
- }
51
- handleFilters ( { status : status as IssueStatus } ) ;
52
- } ;
53
-
54
31
return (
55
32
< S . Container >
56
33
< S . Select
57
34
placeholder = "Status"
58
- defaultValue = { getStatusDefaultValue ( filters ) }
59
- >
60
- < Option value = { undefined } handleCallback = { handleStatus } >
61
- --None--
62
- </ Option >
63
- < Option value = "Unresolved" handleCallback = { handleStatus } >
64
- Unresolved
65
- </ Option >
66
- < Option value = "Resolved" handleCallback = { handleStatus } >
67
- Resolved
68
- </ Option >
69
- </ S . Select >
35
+ value = { filters . status }
36
+ options = { statusOptions }
37
+ onChange = { ( status ) => handleFilters ( { status } ) }
38
+ />
70
39
71
40
< S . Select
72
41
placeholder = "Level"
73
- defaultValue = { getLevelDefaultValue ( filters ) }
74
- >
75
- < Option value = { undefined } handleCallback = { handleLevel } >
76
- --None--
77
- </ Option >
78
- < Option value = "Error" handleCallback = { handleLevel } >
79
- Error
80
- </ Option >
81
- < Option value = "Warning" handleCallback = { handleLevel } >
82
- Warning
83
- </ Option >
84
- < Option value = "Info" handleCallback = { handleLevel } >
85
- Info
86
- </ Option >
87
- </ S . Select >
42
+ value = { filters . level }
43
+ options = { levelOptions }
44
+ onChange = { ( level ) => handleFilters ( { level } ) }
45
+ />
88
46
89
47
< S . Input
90
48
handleChange = { handleChange }
0 commit comments