Skip to content

Commit 0c7181e

Browse files
committed
Use refactored Select in Filters component
1 parent 3a13589 commit 0c7181e

File tree

2 files changed

+21
-63
lines changed

2 files changed

+21
-63
lines changed

features/issues/components/filters/filters.styled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const Select = styled(UnstyledSelect)`
2222
@media (min-width: ${breakpoint("desktop")}) {
2323
width: 10rem;
2424
}
25-
`;
25+
` as typeof UnstyledSelect;
2626

2727
export const Input = styled(UnstyledInput)`
2828
width: 100%;

features/issues/components/filters/filters.tsx

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
import React, { useState } from "react";
22
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";
64
import { useFilters } from "../../hooks/use-filters";
75
import * as S from "./filters.styled";
86

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+
];
1812

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+
];
2519

2620
export function Filters() {
2721
const { handleFilters, filters } = useFilters();
@@ -34,57 +28,21 @@ export function Filters() {
3428
debouncedHandleFilters({ project: project.toLowerCase() });
3529
};
3630

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-
5431
return (
5532
<S.Container>
5633
<S.Select
5734
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+
/>
7039

7140
<S.Select
7241
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+
/>
8846

8947
<S.Input
9048
handleChange={handleChange}

0 commit comments

Comments
 (0)