From a605909191b803d892e0e59dc92adb899a5a948a Mon Sep 17 00:00:00 2001 From: MaheshtheDev <38828053+MaheshtheDev@users.noreply.github.com> Date: Mon, 4 May 2026 17:15:10 +0000 Subject: [PATCH] fix: space selector dropdown (#898) --- apps/web/components/select-spaces-modal.tsx | 53 +++++--- apps/web/components/space-selector.tsx | 139 +++++++++++--------- apps/web/lib/chat-space-label.ts | 5 +- apps/web/lib/ingest-auto-space.ts | 38 ++++++ 4 files changed, 152 insertions(+), 83 deletions(-) create mode 100644 apps/web/lib/ingest-auto-space.ts diff --git a/apps/web/components/select-spaces-modal.tsx b/apps/web/components/select-spaces-modal.tsx index d190052c..31ae6364 100644 --- a/apps/web/components/select-spaces-modal.tsx +++ b/apps/web/components/select-spaces-modal.tsx @@ -9,6 +9,10 @@ import { XIcon, Search, Check } from "lucide-react" import { Button } from "@ui/components/button" import { DEFAULT_PROJECT_ID } from "@lib/constants" import type { ContainerTagListType } from "@lib/types" +import { + compareSpacesUserFirst, + spaceSelectorDisplayName, +} from "@/lib/ingest-auto-space" interface SelectSpacesModalProps { isOpen: boolean @@ -75,24 +79,26 @@ export function SelectSpacesModal({ name: "My Space", emoji: "📁", containerTag: DEFAULT_PROJECT_ID, + isExperimental: false, + isNova: false, + createdAt: "", + updatedAt: "", + } as ContainerTagListType + + const rest = projects + .filter((p) => p.containerTag !== DEFAULT_PROJECT_ID) + .sort(compareSpacesUserFirst) + + const allSpaces = [defaultSpace, ...rest] + if (!searchQuery.trim()) { + return allSpaces } - - const allSpaces = [ - defaultSpace, - ...projects.filter((p) => p.containerTag !== DEFAULT_PROJECT_ID), - ] - - let result = allSpaces - if (searchQuery.trim()) { - const query = searchQuery.toLowerCase() - result = allSpaces.filter( - (p) => - p.containerTag.toLowerCase().includes(query) || - p.name?.toLowerCase().includes(query), - ) - } - - return result + const query = searchQuery.trim().toLowerCase() + return allSpaces.filter( + (p) => + p.containerTag.toLowerCase().includes(query) || + (p.name ?? "").toLowerCase().includes(query), + ) }, [projects, searchQuery]) return ( @@ -169,7 +175,7 @@ export function SelectSpacesModal({ type="button" onClick={() => handleToggle(project.containerTag)} className={cn( - "flex items-center gap-3 w-full px-3 py-2.5 rounded-[12px] cursor-pointer transition-colors text-left", + "flex min-w-0 max-w-full items-center gap-3 w-full px-3 py-2.5 rounded-[12px] cursor-pointer transition-colors text-left", isSelected ? "bg-[#14161A] border border-[rgba(82,89,102,0.3)]" : "bg-transparent border border-transparent hover:bg-[#14161A]/50", @@ -198,9 +204,14 @@ export function SelectSpacesModal({ {isSelected && } )} - {project.emoji || "📁"} - - {project.name ?? project.containerTag} + + {project.emoji || "📁"} + + + {spaceSelectorDisplayName(project, project.containerTag)} ) diff --git a/apps/web/components/space-selector.tsx b/apps/web/components/space-selector.tsx index e8e2e68c..248889b7 100644 --- a/apps/web/components/space-selector.tsx +++ b/apps/web/components/space-selector.tsx @@ -34,6 +34,10 @@ import { } from "@repo/ui/components/select" import { Button } from "@repo/ui/components/button" import { analytics } from "@/lib/analytics" +import { + compareSpacesUserFirst, + spaceSelectorDisplayName, +} from "@/lib/ingest-auto-space" export interface SpaceSelectorProps { selectedProjects: string[] @@ -89,9 +93,19 @@ export function SpaceSelector({ const { allProjects, isLoading } = useContainerTags() + const sortedOtherSpaces = useMemo( + () => + allProjects + .filter( + (p: ContainerTagListType) => p.containerTag !== DEFAULT_PROJECT_ID, + ) + .sort(compareSpacesUserFirst), + [allProjects], + ) + const displayInfo = useMemo(() => { if (selectedProjects.length === 1) { - const containerTag = selectedProjects[0] + const containerTag = selectedProjects[0] ?? "" if (containerTag === DEFAULT_PROJECT_ID) { return { name: "My Space", emoji: "📁", isMultiple: false } } @@ -99,7 +113,7 @@ export function SpaceSelector({ (p: ContainerTagListType) => p.containerTag === containerTag, ) return { - name: found?.name || containerTag, + name: spaceSelectorDisplayName(found, containerTag), emoji: found?.emoji || "📁", isMultiple: false, } @@ -113,7 +127,6 @@ export function SpaceSelector({ } } - // Nothing selected — default to "My Space" return { name: "My Space", emoji: "📁", isMultiple: false } }, [allProjects, selectedProjects]) @@ -261,6 +274,7 @@ export function SpaceSelector({ "min-w-0 truncate text-sm font-medium text-white", "max-w-[10rem] md:max-w-[15rem]", )} + title={isLoading ? undefined : displayInfo.name} > {isLoading ? "…" : displayInfo.name} @@ -285,7 +299,7 @@ export function SpaceSelector({ -
-
-
- - My Spaces - -
+
+
+ + My Spaces + +
+
handleSelectSingleSpace(DEFAULT_PROJECT_ID)} className={cn( - "flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer text-white text-sm font-medium", + "flex min-w-0 max-w-full items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer text-white text-sm font-medium", selectedProjects.length === 1 && selectedProjects[0] === DEFAULT_PROJECT_ID ? "bg-[#293952]/40" @@ -312,59 +331,57 @@ export function SpaceSelector({ )} > 📁 - My Space + My Space - {allProjects - .filter( - (p: ContainerTagListType) => - p.containerTag !== DEFAULT_PROJECT_ID, - ) - .map((project: ContainerTagListType) => ( - - handleSelectSingleSpace(project.containerTag) - } - className={cn( - "flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer text-white text-sm font-medium group", - selectedProjects.length === 1 && - selectedProjects[0] === project.containerTag - ? "bg-[#293952]/40" - : "opacity-60 hover:opacity-100 hover:bg-[#293952]/40", - )} + {sortedOtherSpaces.map((project: ContainerTagListType) => ( + handleSelectSingleSpace(project.containerTag)} + className={cn( + "flex min-w-0 max-w-full items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer text-white text-sm font-medium group", + selectedProjects.length === 1 && + selectedProjects[0] === project.containerTag + ? "bg-[#293952]/40" + : "opacity-60 hover:opacity-100 hover:bg-[#293952]/40", + )} + > + + {project.emoji || "📁"} + + - - {project.emoji || "📁"} - - - {project.name ?? project.containerTag} - - {enableDelete && ( - - )} - - ))} + {spaceSelectorDisplayName(project, project.containerTag)} + + {enableDelete && ( + + )} + + ))}
- +