consolidate org switcher ui

This commit is contained in:
Nate 2025-03-21 20:45:37 -07:00
parent 77110a3cb2
commit 0090e4c583
3 changed files with 11 additions and 155 deletions

View file

@ -4,9 +4,10 @@ import { Fragment } from "react";
import { SecondaryButton } from "../../components";
import { useAuth } from "../../context/Auth";
import { ScopeSelect } from "./ScopeSelect";
export function AccountButton() {
const { session, logout, login } = useAuth();
const { session, logout, login, organizations } = useAuth();
if (!session) {
return (
@ -16,7 +17,7 @@ export function AccountButton() {
return (
<Popover className="relative">
<Popover.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground mr-4 flex h-8 w-8 cursor-pointer items-center justify-center rounded-full border border-solid">
<Popover.Button className="bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground mr-4 flex h-8 w-8 cursor-pointer items-center justify-center rounded-full border-none">
<UserCircleIcon className="h-6 w-6" />
</Popover.Button>
@ -37,6 +38,14 @@ export function AccountButton() {
{session.account.id}
</span>
</div>
{organizations.length > 0 && (
<div className="flex flex-col gap-1">
<label className="text-vsc-foreground text-sm">
Organization
</label>
<ScopeSelect />
</div>
)}
<SecondaryButton onClick={logout} className="w-full justify-center">
Sign out
</SecondaryButton>

View file

@ -1,150 +0,0 @@
import { Listbox, Transition } from "@headlessui/react";
import {
ArrowTopRightOnSquareIcon,
ChevronUpDownIcon,
PlusCircleIcon,
} from "@heroicons/react/24/outline";
import { Fragment, useContext } from "react";
import AssistantIcon from "../../components/modelSelection/platform/AssistantIcon";
import { useAuth } from "../../context/Auth";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import { selectProfileThunk } from "../../redux";
import { useAppDispatch } from "../../redux/hooks";
import { ScopeSelect } from "./ScopeSelect";
export function AccountManagement({ hubEnabled }: { hubEnabled: boolean }) {
const dispatch = useAppDispatch();
const ideMessenger = useContext(IdeMessengerContext);
const { session, login, profiles, selectedProfile, selectedOrganization } =
useAuth();
const changeProfileId = (id: string) => {
dispatch(selectProfileThunk(id));
};
function handleOpenConfig() {
if (!selectedProfile) {
return;
}
ideMessenger.post("config/openProfile", {
profileId: selectedProfile.id,
});
}
return (
<div className="flex flex-col">
<div className="flex max-w-[400px] flex-col gap-4 py-6">
<h2 className="mb-1 mt-0">Configuration</h2>
{hubEnabled ? (
// Hub: show org selector
session && (
<div className="flex flex-col gap-1.5">
<span className="text-lightgray text-sm">{`Organization`}</span>
<ScopeSelect />
</div>
)
) : (
// Continue for teams: show org text
<div>You are using Continue for Teams</div>
)}
{profiles ? (
<>
<div className="flex flex-col gap-1.5">
<div className="flex items-center justify-between gap-1.5 text-sm">
<span className="text-lightgray">{`${hubEnabled ? "Assistant" : "Profile"}`}</span>
</div>
<Listbox value={selectedProfile?.id} onChange={changeProfileId}>
{({ open }) => (
<div className="relative w-full">
<Listbox.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground relative m-0 flex w-full cursor-pointer items-center justify-between rounded-md border border-solid px-3 py-2 text-left">
<div className="flex items-center gap-2">
{selectedProfile && (
<AssistantIcon assistant={selectedProfile} />
)}
<span className="lines lines-1">
{selectedProfile?.title ?? "No Assistant Selected"}
</span>
</div>
<div className="pointer-events-none flex items-center">
<ChevronUpDownIcon
className="h-5 w-5"
aria-hidden="true"
/>
</div>
</Listbox.Button>
<Transition
as={Fragment}
show={open}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Listbox.Options className="bg-vsc-background max-h-80vh absolute z-50 mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
{profiles.map((option, idx) => (
<Listbox.Option
key={idx}
value={option.id}
className={`text-vsc-foreground hover:text-list-active-foreground flex cursor-pointer flex-row items-center gap-3 px-3 py-2 ${selectedProfile?.id === option.id ? "bg-list-active" : "bg-vsc-input-background"}`}
>
<AssistantIcon assistant={option} />
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
{option.title}
</span>
</Listbox.Option>
))}
{hubEnabled && (
<Listbox.Option
key={"no-profiles"}
value={null}
className={`text-vsc-foreground hover:bg-list-active bg-vsc-input-background flex cursor-pointer flex-row items-center gap-2 px-3 py-2`}
onClick={() => {
if (session) {
ideMessenger.post("controlPlane/openUrl", {
path: "new",
orgSlug: selectedOrganization?.slug,
});
} else {
login(false);
}
}}
>
<PlusCircleIcon className="h-4 w-4" />
<span className="lines lines-1 flex items-center justify-between text-xs">
Create new Assistant
</span>
</Listbox.Option>
)}
</Listbox.Options>
</Transition>
{selectedProfile && (
<div className="mt-3 flex w-full justify-center">
<span
className="text-lightgray flex cursor-pointer items-center gap-1 hover:underline"
onClick={handleOpenConfig}
>
<ArrowTopRightOnSquareIcon className="h-4 w-4" />
{hubEnabled
? "Open Assistant configuration"
: "View Workspace"}
</span>
</div>
)}
</div>
)}
</Listbox>
</div>
</>
) : (
<div>Loading...</div>
)}
</div>
</div>
);
}

View file

@ -17,7 +17,6 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks";
import { updateConfig } from "../../redux/slices/configSlice";
import { getFontSize } from "../../util";
import { AccountButton } from "./AccountButton";
import { AccountManagement } from "./AccountManagement";
function ConfigPage() {
useNavigationListener();
@ -121,8 +120,6 @@ function ConfigPage() {
/>
<div className="divide-x-0 divide-y-2 divide-solid divide-zinc-700 px-4">
<AccountManagement hubEnabled={hubEnabled} />
{!controlServerBetaEnabled || hubEnabled ? (
<div className="flex flex-col">
<div className="flex max-w-[400px] flex-col">