Skip to content

Commit b5e789f

Browse files
committed
adjusting loading indicators
1 parent 67c2c32 commit b5e789f

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

components/dashboard/src/components/DropDown2.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import React, {
1717
} from "react";
1818
import Arrow from "./Arrow";
1919
import classNames from "classnames";
20+
import { SpinnerLoader } from "./Loader";
2021

2122
export interface DropDown2Element {
2223
id: string;
@@ -171,6 +172,9 @@ export const DropDown2: FunctionComponent<DropDown2Props> = ({
171172
[setShowDropDown],
172173
);
173174

175+
const showInputLoadingIndicator = filteredOptions.length > 0 && loading;
176+
const showResultsLoadingIndicator = filteredOptions.length === 0 && loading;
177+
174178
return (
175179
<div
176180
onKeyDown={onKeyDown}
@@ -213,16 +217,21 @@ export const DropDown2: FunctionComponent<DropDown2Props> = ({
213217
value={search}
214218
onChange={(e) => updateSearch(e.target.value)}
215219
/>
220+
{showInputLoadingIndicator && (
221+
<div className="absolute top-0 right-0 h-full flex items-center pr-2">
222+
<SpinnerLoader />
223+
</div>
224+
)}
216225
</div>
217226
)}
218227
<ul className="max-h-60 overflow-auto">
219-
{loading && (
228+
{showResultsLoadingIndicator && (
220229
<div className="flex-col space-y-2 animate-pulse">
221230
<div className="bg-gray-300 dark:bg-gray-500 h-4 rounded" />
222231
<div className="bg-gray-300 dark:bg-gray-500 h-4 rounded" />
223232
</div>
224233
)}
225-
{!loading && filteredOptions.length > 0 ? (
234+
{!showResultsLoadingIndicator && filteredOptions.length > 0 ? (
226235
filteredOptions.map((element) => {
227236
let selectionClasses = `dark:bg-gray-800 cursor-pointer`;
228237
if (element.id === selectedElementTemp) {
@@ -250,7 +259,7 @@ export const DropDown2: FunctionComponent<DropDown2Props> = ({
250259
</li>
251260
);
252261
})
253-
) : !loading ? (
262+
) : !showResultsLoadingIndicator ? (
254263
<li key="no-elements" className={"rounded-md "}>
255264
<div className="h-12 pl-8 py-3 text-gray-800 dark:text-gray-200">No results</div>
256265
</li>

components/dashboard/src/components/RepositoryFinder.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,21 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
119119
const filteredResults = filterRepos(searchString, normalizedRepos);
120120
return filteredResults.map(
121121
(repo) =>
122-
({
123-
id: repo.url,
124-
element: (
125-
<div className="flex-col ml-1 mt-1 flex-grow">
126-
<div className="flex">
127-
<div className="text-gray-700 dark:text-gray-300 font-semibold">
128-
{stripOffProtocol(repo.url)}
122+
({
123+
id: repo.url,
124+
element: (
125+
<div className="flex-col ml-1 mt-1 flex-grow">
126+
<div className="flex">
127+
<div className="text-gray-700 dark:text-gray-300 font-semibold">
128+
{stripOffProtocol(repo.url)}
129+
</div>
130+
<div className="ml-1 text-gray-400">{}</div>
129131
</div>
130-
<div className="ml-1 text-gray-400">{ }</div>
132+
<div className="flex text-xs text-gray-400">{}</div>
131133
</div>
132-
<div className="flex text-xs text-gray-400">{ }</div>
133-
</div>
134-
),
135-
isSelectable: true,
136-
} as DropDown2Element),
134+
),
135+
isSelectable: true,
136+
} as DropDown2Element),
137137
);
138138
}
139139

@@ -157,20 +157,19 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
157157
onSelectionChange={handleSelectionChange}
158158
disabled={props.disabled}
159159
// Only consider the isLoading prop if we're including projects in list
160-
loading={isLoading && includeProjectsOnCreateWorkspace}
160+
loading={includeProjectsOnCreateWorkspace && (isLoading || isSearching)}
161161
searchPlaceholder="Paste repository URL or type to find suggestions"
162162
onSearchChange={setSearchString}
163163
>
164-
{/* TODO: add a subtle indicator for the isSearching state */}
165164
<DropDown2SelectedElement
166165
icon={RepositorySVG}
167166
htmlTitle={displayContextUrl(props.selectedContextURL) || "Repository"}
168167
title={
169168
<div className="truncate w-80">
170169
{displayContextUrl(
171170
selectedSuggestion?.projectName ||
172-
selectedSuggestion?.repositoryName ||
173-
selectedSuggestion?.url,
171+
selectedSuggestion?.repositoryName ||
172+
selectedSuggestion?.url,
174173
) || "Select a repository"}
175174
</div>
176175
}
@@ -180,7 +179,7 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
180179
? displayContextUrl(selectedSuggestion?.url)
181180
: undefined
182181
}
183-
loading={isLoading && includeProjectsOnCreateWorkspace}
182+
loading={includeProjectsOnCreateWorkspace && isLoading}
184183
/>
185184
</DropDown2>
186185
);
@@ -260,7 +259,7 @@ function filterRepos(searchString: string, suggestedRepos: SuggestedRepository[]
260259
// If the normalizedSearchString is a URL, and it's not present in the proposed results, "artificially" add it here.
261260
new URL(normalizedSearchString);
262261
results.push({ url: normalizedSearchString });
263-
} catch { }
262+
} catch {}
264263
}
265264
}
266265

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const useSearchRepositories = ({ searchString }: { searchString: string }
2626
enabled: searchString.length >= 3 && !!org,
2727
// Need this to keep previous results while we wait for a new search to complete since debouncedSearchString changes and updates the key
2828
keepPreviousData: true,
29+
// We intentionally don't want to trigger refetches here
30+
refetchOnWindowFocus: false,
31+
refetchOnReconnect: false,
2932
},
3033
);
3134
};

0 commit comments

Comments
 (0)