Skip to content

Commit 4f31c3e

Browse files
committed
feat: search notifications
Signed-off-by: Adam Setch <[email protected]>
1 parent ee00527 commit 4f31c3e

File tree

3 files changed

+19
-38
lines changed

3 files changed

+19
-38
lines changed

src/renderer/routes/__snapshots__/Filters.test.tsx.snap

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

src/renderer/utils/notifications/filters/search.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import {
66
filterNotificationBySearchTerm,
77
matchQualifierByPrefix,
88
ORG_PREFIX,
9+
QUALIFIERS,
910
REPO_PREFIX,
10-
SEARCH_PREFIXES,
11-
SEARCH_QUALIFIERS,
1211
} from './search';
1312

1413
// (helper removed – no longer used)
@@ -25,16 +24,11 @@ describe('renderer/utils/notifications/filters/search.ts', () => {
2524
});
2625

2726
it('matches each known qualifier by its exact prefix and additional value', () => {
28-
for (const prefix of SEARCH_PREFIXES) {
29-
const token = prefix + 'someValue';
27+
for (const q of QUALIFIERS) {
28+
const token = q.prefix + 'someValue';
3029
const qualifier = matchQualifierByPrefix(token);
3130
expect(qualifier).not.toBeNull();
32-
if (qualifier) {
33-
const found = Object.values(SEARCH_QUALIFIERS).find(
34-
(q) => q.prefix === prefix,
35-
);
36-
expect(qualifier).toBe(found);
37-
}
31+
expect(qualifier).toBe(q);
3832
}
3933
});
4034

src/renderer/utils/notifications/filters/search.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Notification } from '../../../typesGitHub';
33

44
export const SEARCH_DELIMITER = ':';
55

6-
export const SEARCH_QUALIFIERS = {
6+
const SEARCH_QUALIFIERS = {
77
author: {
88
prefix: 'author:',
99
description: 'filter by notification author',
@@ -25,23 +25,13 @@ export const SEARCH_QUALIFIERS = {
2525
},
2626
} as const;
2727

28-
export type SearchQualifierKey = keyof typeof SEARCH_QUALIFIERS;
29-
export type SearchQualifier = (typeof SEARCH_QUALIFIERS)[SearchQualifierKey];
28+
type SearchQualifierKey = keyof typeof SEARCH_QUALIFIERS;
29+
type SearchQualifier = (typeof SEARCH_QUALIFIERS)[SearchQualifierKey];
3030
export type SearchPrefix = SearchQualifier['prefix'];
3131

32-
export const SEARCH_PREFIXES: readonly SearchPrefix[] = Object.values(
32+
export const QUALIFIERS: readonly SearchQualifier[] = Object.values(
3333
SEARCH_QUALIFIERS,
34-
).map((q) => q.prefix) as readonly SearchPrefix[];
35-
36-
// Map prefix -> qualifier for fast lookup after prefix detection
37-
export const QUALIFIER_BY_PREFIX: Record<SearchPrefix, SearchQualifier> =
38-
Object.values(SEARCH_QUALIFIERS).reduce(
39-
(acc, q) => {
40-
acc[q.prefix as SearchPrefix] = q;
41-
return acc;
42-
},
43-
{} as Record<SearchPrefix, SearchQualifier>,
44-
);
34+
) as readonly SearchQualifier[];
4535

4636
export const AUTHOR_PREFIX: SearchPrefix = SEARCH_QUALIFIERS.author.prefix;
4737
export const ORG_PREFIX: SearchPrefix = SEARCH_QUALIFIERS.org.prefix;
@@ -73,10 +63,9 @@ export function hasExcludeSearchFilters(settings: SettingsState) {
7363
}
7464

7565
export function matchQualifierByPrefix(token: string) {
76-
// Iterate prefixes (tiny list) then direct map lookup; preserves ordering behavior
77-
for (const prefix of SEARCH_PREFIXES) {
78-
if (token.startsWith(prefix)) {
79-
return QUALIFIER_BY_PREFIX[prefix] || null;
66+
for (const qualifier of QUALIFIERS) {
67+
if (token.startsWith(qualifier.prefix)) {
68+
return qualifier;
8069
}
8170
}
8271
return null;
@@ -115,18 +104,18 @@ export function normalizeSearchInputToToken(raw: string): string | null {
115104
}
116105

117106
const lower = value.toLowerCase();
118-
const matched = SEARCH_PREFIXES.find((p) => lower.startsWith(p));
107+
const matchedQualifier = QUALIFIERS.find((q) => lower.startsWith(q.prefix));
119108

120-
if (!matched) {
109+
if (!matchedQualifier) {
121110
return null;
122111
}
123112

124-
const rest = value.substring(matched.length);
113+
const rest = value.substring(matchedQualifier.prefix.length);
125114
if (rest.length === 0) {
126115
return null; // prefix only, incomplete token
127116
}
128117

129-
return `${matched}${rest}`;
118+
return `${matchedQualifier.prefix}${rest}`;
130119
}
131120

132121
export function filterNotificationBySearchTerm(

0 commit comments

Comments
 (0)