Skip to content

Commit ee00527

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

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/renderer/components/filters/TokenSearchInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const TokenSearchInput: FC<TokenSearchInputProps> = ({
3535
const [inputValue, setInputValue] = useState('');
3636
const [showSuggestions, setShowSuggestions] = useState(false);
3737

38-
// FIXME - remove this
3938
const tokenItems = tokens.map((text, id) => ({ id, text }));
4039

4140
function tryAddToken(

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export function getAvailableSearchQualifiers(
5252
detailedNotificationsEnabled: boolean,
5353
): readonly SearchQualifier[] {
5454
const all = Object.values(SEARCH_QUALIFIERS) as readonly SearchQualifier[];
55-
if (detailedNotificationsEnabled) return all;
55+
if (detailedNotificationsEnabled) {
56+
return all;
57+
}
58+
5659
return all.filter((q) => !q.requiresDetailsNotifications);
5760
}
5861

@@ -91,31 +94,50 @@ export interface ParsedSearchToken {
9194

9295
export function parseSearchToken(token: string): ParsedSearchToken | null {
9396
const qualifier = matchQualifierByPrefix(token);
94-
if (!qualifier) return null;
97+
if (!qualifier) {
98+
return null;
99+
}
100+
95101
const value = stripPrefix(token, qualifier);
96-
if (!value) return null;
102+
if (!value) {
103+
return null;
104+
}
105+
97106
return { qualifier, value, valueLower: value.toLowerCase() };
98107
}
99108

100109
// Normalize raw user input from the token text field into a SearchToken (string)
101110
// Returns null if no known prefix or no value after prefix yet.
102111
export function normalizeSearchInputToToken(raw: string): string | null {
103112
const value = raw.trim();
104-
if (!value) return null;
113+
if (!value) {
114+
return null;
115+
}
116+
105117
const lower = value.toLowerCase();
106118
const matched = SEARCH_PREFIXES.find((p) => lower.startsWith(p));
107-
if (!matched) return null;
119+
120+
if (!matched) {
121+
return null;
122+
}
123+
108124
const rest = value.substring(matched.length);
109-
if (rest.length === 0) return null; // prefix only, incomplete token
110-
return `${matched}${rest}`; // preserve original rest casing
125+
if (rest.length === 0) {
126+
return null; // prefix only, incomplete token
127+
}
128+
129+
return `${matched}${rest}`;
111130
}
112131

113132
export function filterNotificationBySearchTerm(
114133
notification: Notification,
115134
token: string,
116135
): boolean {
117136
const parsed = parseSearchToken(token);
118-
if (!parsed) return false;
137+
if (!parsed) {
138+
return false;
139+
}
140+
119141
const fieldValue = parsed.qualifier.extract(notification);
120142
return fieldValue?.toLowerCase() === parsed.valueLower;
121143
}

0 commit comments

Comments
 (0)