Skip to content

Commit 3d507f5

Browse files
committed
feat: search notifications
Signed-off-by: Adam Setch <[email protected]>
1 parent 02aca71 commit 3d507f5

File tree

5 files changed

+127
-39
lines changed

5 files changed

+127
-39
lines changed

src/renderer/components/filters/SearchFilter.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export const SearchFilter: FC = () => {
120120
<TokenSearchInput
121121
icon={CheckCircleFillIcon}
122122
iconColorClass={IconColor.GREEN}
123-
isDetailedNotificationsEnabled={settings.detailedNotifications}
124123
label="Include"
125124
onAdd={addIncludeSearchToken}
126125
onRemove={removeIncludeSearchToken}
@@ -131,7 +130,6 @@ export const SearchFilter: FC = () => {
131130
<TokenSearchInput
132131
icon={NoEntryFillIcon}
133132
iconColorClass={IconColor.RED}
134-
isDetailedNotificationsEnabled={settings.detailedNotifications}
135133
label="Exclude"
136134
onAdd={addExcludeSearchToken}
137135
onRemove={removeExcludeSearchToken}

src/renderer/components/filters/SearchFilterSuggestions.test.tsx

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,113 @@
11
import { render } from '@testing-library/react';
22

3+
import { mockSettings } from '../../__mocks__/state-mocks';
4+
import { AppContext } from '../../context/App';
5+
import type { SettingsState } from '../../types';
36
import { SearchFilterSuggestions } from './SearchFilterSuggestions';
47

58
describe('renderer/components/filters/SearchFilterSuggestions.tsx', () => {
69
const mockOnClose = jest.fn();
710

811
it('should render itself & its children - closed', () => {
912
const tree = render(
10-
<SearchFilterSuggestions
11-
inputValue={''}
12-
isDetailedNotificationsEnabled={false}
13-
onClose={mockOnClose}
14-
open={false}
15-
/>,
13+
<AppContext.Provider
14+
value={{
15+
settings: {
16+
...mockSettings,
17+
detailedNotifications: false,
18+
} as SettingsState,
19+
}}
20+
>
21+
<SearchFilterSuggestions
22+
inputValue={''}
23+
onClose={mockOnClose}
24+
open={false}
25+
/>
26+
</AppContext.Provider>,
1627
);
1728

1829
expect(tree).toMatchSnapshot();
1930
});
2031

2132
it('should render itself & its children - open', () => {
2233
const tree = render(
23-
<SearchFilterSuggestions
24-
inputValue={''}
25-
isDetailedNotificationsEnabled={false}
26-
onClose={mockOnClose}
27-
open={true}
28-
/>,
34+
<AppContext.Provider
35+
value={{
36+
settings: {
37+
...mockSettings,
38+
detailedNotifications: true,
39+
} as SettingsState,
40+
}}
41+
>
42+
<SearchFilterSuggestions
43+
inputValue={''}
44+
onClose={mockOnClose}
45+
open={true}
46+
/>
47+
</AppContext.Provider>,
2948
);
3049

3150
expect(tree).toMatchSnapshot();
3251
});
3352

3453
it('should render itself & its children - open with detailed enabled', () => {
3554
const tree = render(
36-
<SearchFilterSuggestions
37-
inputValue={''}
38-
isDetailedNotificationsEnabled={true}
39-
onClose={mockOnClose}
40-
open={true}
41-
/>,
55+
<AppContext.Provider
56+
value={{
57+
settings: {
58+
...mockSettings,
59+
detailedNotifications: true,
60+
} as SettingsState,
61+
}}
62+
>
63+
<SearchFilterSuggestions
64+
inputValue={''}
65+
onClose={mockOnClose}
66+
open={true}
67+
/>
68+
</AppContext.Provider>,
4269
);
4370

4471
expect(tree).toMatchSnapshot();
4572
});
4673

4774
it('should render itself & its children - input token invalid', () => {
4875
const tree = render(
49-
<SearchFilterSuggestions
50-
inputValue={'invalid'}
51-
isDetailedNotificationsEnabled={false}
52-
onClose={mockOnClose}
53-
open={true}
54-
/>,
76+
<AppContext.Provider
77+
value={{
78+
settings: {
79+
...mockSettings,
80+
detailedNotifications: false,
81+
} as SettingsState,
82+
}}
83+
>
84+
<SearchFilterSuggestions
85+
inputValue={'invalid'}
86+
onClose={mockOnClose}
87+
open={true}
88+
/>
89+
</AppContext.Provider>,
5590
);
5691

5792
expect(tree).toMatchSnapshot();
5893
});
5994

6095
it('should render itself & its children - input token valid', () => {
6196
const tree = render(
62-
<SearchFilterSuggestions
63-
inputValue={'repo:'}
64-
isDetailedNotificationsEnabled={false}
65-
onClose={mockOnClose}
66-
open={true}
67-
/>,
97+
<AppContext.Provider
98+
value={{
99+
settings: {
100+
...mockSettings,
101+
detailedNotifications: false,
102+
} as SettingsState,
103+
}}
104+
>
105+
<SearchFilterSuggestions
106+
inputValue={'repo:'}
107+
onClose={mockOnClose}
108+
open={true}
109+
/>
110+
</AppContext.Provider>,
68111
);
69112

70113
expect(tree).toMatchSnapshot();

src/renderer/components/filters/SearchFilterSuggestions.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FC } from 'react';
1+
import { useContext, type FC } from 'react';
22

33
import { Box, Popover, Stack, Text } from '@primer/react';
44

@@ -9,26 +9,28 @@ import {
99
BASE_SEARCH_QUALIFIERS,
1010
SEARCH_DELIMITER,
1111
} from '../../utils/notifications/filters/search';
12+
import { AppContext } from '../../context/App';
1213

1314
interface SearchFilterSuggestionsProps {
1415
open: boolean;
1516
inputValue: string;
16-
isDetailedNotificationsEnabled: boolean;
1717
onClose: () => void;
1818
}
1919

2020
export const SearchFilterSuggestions: FC<SearchFilterSuggestionsProps> = ({
2121
open,
2222
inputValue,
23-
isDetailedNotificationsEnabled,
2423
onClose,
2524
}) => {
25+
26+
const { settings } = useContext(AppContext);
27+
2628
if (!open) {
2729
return null;
2830
}
2931

3032
const lower = inputValue.toLowerCase();
31-
const base = isDetailedNotificationsEnabled
33+
const base = settings.detailedNotifications
3234
? ALL_SEARCH_QUALIFIERS
3335
: BASE_SEARCH_QUALIFIERS;
3436
const suggestions = base.filter(

src/renderer/components/filters/TokenSearchInput.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interface TokenSearchInputProps {
1515
iconColorClass: string;
1616
tokens: readonly SearchToken[]; // raw token strings
1717
showSuggestionsOnFocusIfEmpty: boolean;
18-
isDetailedNotificationsEnabled: boolean;
1918
onAdd: (token: SearchToken) => void;
2019
onRemove: (token: SearchToken) => void;
2120
}
@@ -28,7 +27,6 @@ export const TokenSearchInput: FC<TokenSearchInputProps> = ({
2827
iconColorClass,
2928
tokens,
3029
showSuggestionsOnFocusIfEmpty,
31-
isDetailedNotificationsEnabled,
3230
onAdd,
3331
onRemove,
3432
}) => {
@@ -117,7 +115,6 @@ export const TokenSearchInput: FC<TokenSearchInputProps> = ({
117115
/>
118116
<SearchFilterSuggestions
119117
inputValue={inputValue}
120-
isDetailedNotificationsEnabled={isDetailedNotificationsEnabled}
121118
onClose={() => setShowSuggestions(false)}
122119
open={showSuggestions}
123120
/>

src/renderer/components/filters/__snapshots__/SearchFilterSuggestions.test.tsx.snap

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)