Skip to content

Commit 360b473

Browse files
authored
Merge pull request #440 from AppQuality/filters-drawer-read-unread
feat(filters-drawer): add read-unread filter
2 parents 894f1a6 + e28f500 commit 360b473

File tree

5 files changed

+92
-3
lines changed

5 files changed

+92
-3
lines changed

src/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_OS_SHOW_LESS_LABEL": "Show less",
7777
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_OS_SHOW_MORE_LABEL": "Show <2>{{os}}</2> more OS",
7878
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_OS_TITLE": "OS",
79+
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_READ_TITLE": "Reading",
7980
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_REPLICABILITY_ALL_LABEL": "All replicabilities",
8081
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_REPLICABILITY_SHOW_LESS_LABEL": "Show less",
8182
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_REPLICABILITY_SHOW_MORE_LABEL": "Show <2>{{replicabilities}}</2> more replicabilities",

src/locales/it/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_OS_SHOW_LESS_LABEL": "",
7979
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_OS_SHOW_MORE_LABEL": "Show <2>{{os}}</2> more OS",
8080
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_OS_TITLE": "",
81+
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_READ_TITLE": "",
8182
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_REPLICABILITY_ALL_LABEL": "",
8283
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_REPLICABILITY_SHOW_LESS_LABEL": "",
8384
"__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_REPLICABILITY_SHOW_MORE_LABEL": "Show <2>{{replicabilities}}</2> more replicabilities",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Accordion, MD, Radio, SM } from '@appquality/unguess-design-system';
2+
import { useTranslation } from 'react-i18next';
3+
import { useAppDispatch } from 'src/app/hooks';
4+
import { theme as globalTheme } from 'src/app/theme';
5+
import { Field } from '@zendeskgarden/react-forms';
6+
import { updateFilters } from 'src/features/bugsPage/bugsPageSlice';
7+
import { Divider } from 'src/common/components/divider';
8+
import { ReadFilterType } from 'src/features/bugsPage/readFilter';
9+
import { useFilterData } from './useFilterData';
10+
import { disabledStyle, LabelSpaceBetween } from './LabelWithCounter';
11+
12+
export const ReadField = ({ read }: { read: ReadFilterType['read'] }) => {
13+
const dispatch = useAppDispatch();
14+
const { t } = useTranslation();
15+
const { counters } = useFilterData('read');
16+
const { available, selected } = read;
17+
18+
if (!counters) return null;
19+
20+
return (
21+
<>
22+
<Accordion level={3}>
23+
<Accordion.Section>
24+
<Accordion.Header>
25+
<Accordion.Label>
26+
<MD isBold style={{ marginBottom: globalTheme.space.xxs }}>
27+
{t('__BUGS_PAGE_FILTER_DRAWER_BODY_FILTER_READ_TITLE')}
28+
</MD>
29+
<SM
30+
style={{
31+
color: globalTheme.palette.grey[600],
32+
textTransform: 'capitalize',
33+
}}
34+
>
35+
{selected === 'unread'
36+
? t('__BUGS_READ_FILTER_ITEM_UNREAD')
37+
: t('__BUGS_READ_FILTER_ITEM_ALL')}
38+
</SM>
39+
</Accordion.Label>
40+
</Accordion.Header>
41+
<Accordion.Panel>
42+
{available.map((item) => (
43+
<Field
44+
style={{
45+
marginBottom: globalTheme.space.xxs,
46+
}}
47+
>
48+
<Radio
49+
value={item}
50+
name="filter-read"
51+
disabled={!counters[item as string]}
52+
checked={selected && selected === item}
53+
onChange={() => {
54+
dispatch(
55+
updateFilters({
56+
filters: {
57+
read: item,
58+
},
59+
})
60+
);
61+
}}
62+
>
63+
<LabelSpaceBetween
64+
isRegular
65+
style={{
66+
textTransform: 'capitalize',
67+
...(!counters[item as string] && disabledStyle),
68+
}}
69+
>
70+
{item === 'unread'
71+
? t('__BUGS_READ_FILTER_ITEM_UNREAD')
72+
: t('__BUGS_READ_FILTER_ITEM_PLACEHOLDER')}
73+
<MD>{counters[item as string] || 0}</MD>
74+
</LabelSpaceBetween>
75+
</Radio>
76+
</Field>
77+
))}
78+
</Accordion.Panel>
79+
</Accordion.Section>
80+
</Accordion>
81+
<Divider />
82+
</>
83+
);
84+
};

src/pages/Bugs/Drawer/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import styled from 'styled-components';
1717
import { useCampaignBugs } from '../BugsTable/hooks/useCampaignBugs';
1818
import { DeviceField } from './DeviceField';
1919
import { OsField } from './OsField';
20+
import { ReadField } from './ReadField';
2021
import { ReplicabilityField } from './ReplicabilityField';
2122
import { SeverityField } from './SeverityField';
2223
import { TagField } from './TagField';
@@ -65,6 +66,7 @@ const BugsFilterDrawer = () => {
6566
devices,
6667
os,
6768
replicabilities,
69+
read,
6870
} = campaignData;
6971

7072
const memoizedFilters = useMemo(
@@ -79,7 +81,8 @@ const BugsFilterDrawer = () => {
7981
>
8082
{t('__BUGS_PAGE_FILTER_DRAWER_BODY_COMMON_LABEL')}
8183
</MD>
82-
{unique.available.length ? <UniqueField unique={unique} /> : null}
84+
<UniqueField unique={unique} />
85+
<ReadField read={read} />
8386
{severities.available.length ? (
8487
<SeverityField severities={severities} />
8588
) : null}

src/pages/Bugs/Drawer/useFilterData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export const useFilterData = (filter: Filter) => {
7373
} else if (filter === 'severities') {
7474
acc[bug.severity.id] = (acc[bug.severity.id] || 0) + 1;
7575
} else if (filter === 'read') {
76-
acc[bug.read ? 'read' : 'unread'] =
77-
(acc[bug.read ? 'read' : 'unread'] || 0) + 1;
76+
acc[bug.read ? 'all' : 'unread'] =
77+
(acc[bug.read ? 'all' : 'unread'] || 0) + 1;
7878
} else if (filter === 'unique') {
7979
if (!bug.duplicated_of_id) {
8080
acc.unique = (acc.unique || 0) + 1;

0 commit comments

Comments
 (0)