Skip to content

Commit 94d0764

Browse files
authored
Support fuzzy match when picking repo [INS-1460] (#9504)
* tmp * Fuzzy match for selecting branch
1 parent a4250a5 commit 94d0764

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/insomnia/src/ui/components/git-credentials/git-remote-branch-select.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Button, ComboBox, Input, Label, ListBox, ListBoxItem, Popover } from 'r
33
import * as reactUse from 'react-use';
44
import { z } from 'zod/v4';
55

6+
import { fuzzyMatch } from '~/common/misc';
67
import type { GitCredentials } from '~/models/git-repository';
78
import { useGitRemoteBranchesActionFetcher } from '~/routes/git.remote-branches';
89

@@ -66,11 +67,14 @@ export const GitRemoteBranchSelect = ({
6667
className="w-full"
6768
defaultSelectedKey={remoteBranches[0]}
6869
isDisabled={isComboboxDisabled}
69-
items={remoteBranches.map(branch => ({
70+
defaultItems={remoteBranches.map(branch => ({
7071
id: branch,
7172
name: branch,
7273
}))}
7374
menuTrigger="focus"
75+
defaultFilter={(branch: string, inputValue: string) =>
76+
Boolean(fuzzyMatch(inputValue, branch, { splitSpace: true, loose: false })?.indexes)
77+
}
7478
>
7579
<div className="flex w-full items-center gap-2">
7680
<div className="group flex h-(--line-height-xs) flex-1 items-center gap-2 rounded-xs border border-solid border-(--hl-sm) bg-(--color-bg) text-(--color-font) transition-colors focus:ring-1 focus:ring-(--hl-md) focus:outline-hidden">

packages/insomnia/src/ui/components/git-credentials/github-repository-select.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { useEffect, useState } from 'react';
22
import { Button, ComboBox, FieldError, Input, Label, ListBox, ListBoxItem, Popover } from 'react-aria-components';
33

4+
import { fuzzyMatch } from '~/common/misc';
5+
46
import { getAppWebsiteBaseURL } from '../../../common/constants';
57
import { isGitHubAppUserToken } from '../github-app-config-link';
68
import { Icon } from '../icon';
@@ -89,6 +91,9 @@ export const GitHubRepositorySelect = ({
8991
}))}
9092
onSelectionChange={key => setSelectedRepository(repositories.find(r => r.clone_url === key) || null)}
9193
menuTrigger="focus"
94+
defaultFilter={(repoName: string, inputValue: string) =>
95+
Boolean(fuzzyMatch(inputValue, repoName, { splitSpace: true, loose: false })?.indexes)
96+
}
9297
>
9398
<div className="flex w-full items-center gap-2">
9499
<div className="group flex h-(--line-height-xs) flex-1 items-center gap-2 rounded-xs border border-solid border-(--hl-sm) bg-(--color-bg) text-(--color-font) transition-colors focus:ring-1 focus:ring-(--hl-md) focus:outline-hidden">
@@ -141,7 +146,8 @@ export const GitHubRepositorySelect = ({
141146
{isDisabled && <Icon icon="lock" className="group-aria-disabled:opacity-30" />}
142147
<span className="truncate group-aria-disabled:opacity-30">{item.name}</span>
143148
{isDisabled && (
144-
<span className="hidden rounded border border-solid border-(--hl-xl) px-2 py-1 text-(--color-font) group-hover:inline-block">
149+
/* If you use hidden here, if the drop down is a long list and you scroll to the disabled item and hover on it, the scroll bar will scroll to the top. So we use invisible instead */
150+
<span className="invisible rounded border border-solid border-(--hl-xl) px-2 py-1 text-(--color-font) group-hover:visible">
145151
Already connected to: {allConnectedRepoURIProjectNameMap[item.id]}
146152
</span>
147153
)}

0 commit comments

Comments
 (0)