Skip to content

Commit 68bd9f2

Browse files
committed
Minor fixes
1 parent 92c628c commit 68bd9f2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

site/src/pages/WorkspacesPage/filter/autocompletes.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ const useAutocomplete = <TOption extends BaseOption = BaseOption>({
6464

6565
let options = searchOptionsQuery.data as TOption[]
6666

67-
if (!selectedOption) {
68-
return options
67+
if (selectedOption) {
68+
options = options.filter(
69+
(option) => option.value !== selectedOption.value,
70+
)
71+
options = [selectedOption, ...options]
6972
}
7073

71-
options = options.filter((option) => option.value !== selectedOption.value)
72-
options.unshift(selectedOption)
7374
options = options.filter(
7475
(option) =>
7576
option.label.toLowerCase().includes(query.toLowerCase()) ||
@@ -88,6 +89,7 @@ const useAutocomplete = <TOption extends BaseOption = BaseOption>({
8889
const selectOption = (option: TOption) => {
8990
let newSelectedOptionValue: TOption | undefined = option
9091
selectedOptionsCacheRef.current[option.value] = option
92+
setQuery("")
9193

9294
if (option.value === selectedOption?.value) {
9395
newSelectedOptionValue = undefined

0 commit comments

Comments
 (0)