Skip to content

Commit be2067b

Browse files
fix(site): Make current user first in the list and fix search (#7722)
1 parent ce6b698 commit be2067b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useQuery } from "@tanstack/react-query"
99
import { getTemplates, getUsers } from "api/api"
1010
import { WorkspaceStatuses } from "api/typesGenerated"
1111
import { getDisplayWorkspaceStatus } from "utils/workspace"
12+
import { useMe } from "hooks"
1213

1314
type UseAutocompleteOptions<TOption extends BaseOption> = {
1415
id: string
@@ -50,7 +51,7 @@ const useAutocomplete = <TOption extends BaseOption = BaseOption>({
5051
})
5152
const selectedOption = selectedOptionQuery.data
5253
const searchOptionsQuery = useQuery({
53-
queryKey: [id, "autocomplete", "search"],
54+
queryKey: [id, "autocomplete", "search", query],
5455
queryFn: () => getOptions(query),
5556
enabled,
5657
})
@@ -114,8 +115,18 @@ export const useUsersAutocomplete = (
114115
value: string | undefined,
115116
onChange: (option: OwnerOption | undefined) => void,
116117
enabled?: boolean,
117-
) =>
118-
useAutocomplete({
118+
) => {
119+
const me = useMe()
120+
121+
const addMeAsFirstOption = (options: OwnerOption[]) => {
122+
options = options.filter((option) => option.value !== me.username)
123+
return [
124+
{ label: me.username, value: me.username, avatarUrl: me.avatar_url },
125+
...options,
126+
]
127+
}
128+
129+
return useAutocomplete({
119130
onChange,
120131
enabled,
121132
value,
@@ -134,13 +145,16 @@ export const useUsersAutocomplete = (
134145
},
135146
getOptions: async (query) => {
136147
const usersRes = await getUsers({ q: query, limit: 25 })
137-
return usersRes.users.map((user) => ({
148+
let options: OwnerOption[] = usersRes.users.map((user) => ({
138149
label: user.username,
139150
value: user.username,
140151
avatarUrl: user.avatar_url,
141152
}))
153+
options = addMeAsFirstOption(options)
154+
return options
142155
},
143156
})
157+
}
144158

145159
export type UsersAutocomplete = ReturnType<typeof useUsersAutocomplete>
146160

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy