Skip to content

Commit 87aaba9

Browse files
authored
Launchpad filter now does a fuzzy match and can also match by PR number (#39)
1 parent 7f387d2 commit 87aaba9

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/popup/components/FocusView.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { GitPullRequest } from '@gitkraken/provider-apis';
12
import { GitProviderUtils } from '@gitkraken/provider-apis';
23
import { useQueryClient } from '@tanstack/react-query';
34
import React, { useEffect, useMemo, useState } from 'react';
@@ -21,6 +22,25 @@ type PullRequestRowProps = {
2122
draftCount?: number;
2223
};
2324

25+
const pullRequestFuzzyMatch = (pullRequest: GitPullRequest, filterString: string) => {
26+
if (pullRequest.number.toString().includes(filterString)) {
27+
return true;
28+
}
29+
30+
// Do a "fuzzy match" on the PR title
31+
const title = pullRequest.title.toLowerCase();
32+
let filterIndex = 0;
33+
for (const char of title) {
34+
if (char === filterString[filterIndex]) {
35+
filterIndex++;
36+
}
37+
if (filterIndex === filterString.length) {
38+
return true;
39+
}
40+
}
41+
return false;
42+
};
43+
2444
const PullRequestRow = ({ userId, pullRequest, provider, draftCount = 0 }: PullRequestRowProps) => {
2545
const queryClient = useQueryClient();
2646
const deepLinkUrl = getGitKrakenDeepLinkUrl(provider, pullRequest.url);
@@ -150,9 +170,7 @@ export const FocusView = ({ userId }: { userId: string }) => {
150170
? pullRequestBuckets
151171
?.map(bucket => ({
152172
...bucket,
153-
pullRequests: bucket.pullRequests.filter(pr =>
154-
pr.title.toLowerCase().includes(lowercaseFilterString),
155-
),
173+
pullRequests: bucket.pullRequests.filter(pr => pullRequestFuzzyMatch(pr, lowercaseFilterString)),
156174
}))
157175
.filter(bucket => bucket.pullRequests.length)
158176
: pullRequestBuckets;

0 commit comments

Comments
 (0)