Skip to content

Commit 8b1e7e5

Browse files
committed
adjust filtering and query key
1 parent e06449c commit 8b1e7e5

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

components/dashboard/src/data/git-providers/provider-repositories-query.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ export const useProviderRepositoriesForUser = ({
2525
const { data: authProviders } = useAuthProviders();
2626
const selectedProvider = authProviders?.find((p) => p.host === providerHost);
2727

28+
const queryKey: any[] = ["provider-repositories", { userId: user?.id }, { providerHost, installationId }];
29+
30+
const isBitbucketServer = selectedProvider?.authProviderType === "BitbucketServer";
31+
if (isBitbucketServer) {
32+
queryKey.push({ search });
33+
}
34+
2835
return useQuery(
29-
["provider-repositories", { userId: user?.id }, { providerHost, installationId }],
36+
queryKey,
3037
async ({ signal }) => {
3138
// jsonrpc cancellation token that we subscribe to the abort signal provided by react-query
3239
const cancelToken = new CancellationTokenSource();
@@ -41,7 +48,7 @@ export const useProviderRepositoriesForUser = ({
4148
};
4249

4350
// TODO: Have this be the default for all providers
44-
if (selectedProvider?.authProviderType === "BitbucketServer") {
51+
if (isBitbucketServer) {
4552
params.searchString = search;
4653
params.limit = 50;
4754
params.maxPages = 1;

components/dashboard/src/hooks/use-state-with-debounce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { useEffect, useMemo, useState } from "react";
88
import debounce from "lodash.debounce";
99

10-
export const useStateWithDebounce = <T>(initialValue: T, delay = 300): [T, (value: T) => void, T] => {
10+
export const useStateWithDebounce = <T>(initialValue: T, delay = 500): [T, (value: T) => void, T] => {
1111
const [value, setValue] = useState<T>(initialValue);
1212
const [debouncedValue, setDebouncedValue] = useState<T>(initialValue);
1313

components/dashboard/src/projects/new-project/NewProjectRepoSelection.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const NewProjectRepoSelection: FC<Props> = ({ selectedProvider, onProject
5757
const noReposAvailable = !!(reposInAccounts?.length === 0 || areGitHubWebhooksUnauthorized);
5858
// TODO: check type instead of host?
5959
const isGitHub = selectedProvider?.host === "github.com";
60-
const isBitbucketServer = selectedProvider?.authProviderType !== "BitbucketServer";
60+
const isBitbucketServer = selectedProvider?.authProviderType === "BitbucketServer";
6161

6262
const accounts = useMemo(() => {
6363
const accounts = new Map<string, { avatarUrl: string }>();
@@ -76,12 +76,15 @@ export const NewProjectRepoSelection: FC<Props> = ({ selectedProvider, onProject
7676
const filteredRepos = useMemo(() => {
7777
return areGitHubWebhooksUnauthorized
7878
? []
79+
: // filtering is done on server for Bitbucket Server
80+
isBitbucketServer
81+
? Array.from(reposInAccounts || [])
7982
: Array.from(reposInAccounts || []).filter(
8083
(r) =>
81-
r.account === selectedAccount &&
84+
(!selectedAccount || r.account === selectedAccount) &&
8285
`${r.name}`.toLowerCase().includes(repoSearchFilter.toLowerCase().trim()),
8386
);
84-
}, [areGitHubWebhooksUnauthorized, repoSearchFilter, reposInAccounts, selectedAccount]);
87+
}, [areGitHubWebhooksUnauthorized, isBitbucketServer, repoSearchFilter, reposInAccounts, selectedAccount]);
8588

8689
const reconfigure = useCallback(() => {
8790
openReconfigureWindow({

0 commit comments

Comments
 (0)