Skip to content

Modern Docker Management, Designed for Everyone

feat: new environment switcher dialog (#1126)

Chase Baucomcf9b4e7f4893
diff --git a/backend/internal/huma/handlers/environments.go b/backend/internal/huma/handlers/environments.go
index 2ab00f15f..3cf0d6a7f 100644
--- a/backend/internal/huma/handlers/environments.go
+++ b/backend/internal/huma/handlers/environments.go
@@ -12,6 +12,7 @@ import (
"github.com/getarcaneapp/arcane/backend/internal/services"
"github.com/getarcaneapp/arcane/backend/internal/utils"
"github.com/getarcaneapp/arcane/backend/internal/utils/mapper"
+ "github.com/getarcaneapp/arcane/backend/internal/utils/pagination"
"go.getarcane.app/types/base"
"go.getarcane.app/types/environment"
)
@@ -39,10 +40,11 @@ type EnvironmentPaginatedResponse struct {
}
type ListEnvironmentsInput struct {
- Page int `query:"pagination[page]" default:"1" doc:"Page number"`
- Limit int `query:"pagination[limit]" default:"20" doc:"Items per page"`
- SortCol string `query:"sort[column]" doc:"Column to sort by"`
- SortDir string `query:"sort[direction]" default:"asc" doc:"Sort direction"`
+ Search string `query:"search" doc:"Search query for filtering by name or API URL"`
+ Sort string `query:"sort" doc:"Column to sort by"`
+ Order string `query:"order" default:"asc" doc:"Sort direction (asc or desc)"`
+ Start int `query:"start" default:"0" doc:"Start index for pagination"`
+ Limit int `query:"limit" default:"20" doc:"Items per page"`
}
type ListEnvironmentsOutput struct {
@@ -307,7 +309,19 @@ func (h *EnvironmentHandler) ListEnvironments(ctx context.Context, input *ListEn
return nil, huma.Error500InternalServerError("service not available")
}
- params := buildPaginationParams(input.Page, input.Limit, input.SortCol, input.SortDir)
+ params := pagination.QueryParams{
+ SearchQuery: pagination.SearchQuery{
+ Search: input.Search,
+ },
+ SortParams: pagination.SortParams{
+ Sort: input.Sort,
+ Order: pagination.SortOrder(input.Order),
+ },
+ PaginationParams: pagination.PaginationParams{
+ Start: input.Start,
+ Limit: input.Limit,
+ },
+ }
envs, paginationResp, err := h.environmentService.ListEnvironmentsPaginated(ctx, params)
if err != nil {
diff --git a/frontend/src/lib/components/dialogs/environment-switcher-dialog.svelte b/frontend/src/lib/components/dialogs/environment-switcher-dialog.svelte
new file mode 100644
index 000000000..cc9d7ba6f
--- /dev/null
+++ b/frontend/src/lib/components/dialogs/environment-switcher-dialog.svelte
@@ -0,0 +1,348 @@
+<script lang="ts">
+ import { ResponsiveDialog } from '$lib/components/ui/responsive-dialog/index.js';
+ import { Button } from '$lib/components/ui/button/index.js';
+ import { Input } from '$lib/components/ui/input/index.js';
+ import { Spinner } from '$lib/components/ui/spinner/index.js';
+ import { environmentStore } from '$lib/stores/environment.store.svelte';
+ import { environmentManagementService } from '$lib/services/env-mgmt-service';
+ import type { Environment } from '$lib/types/environment.type';
+ import { goto } from '$app/navigation';
+ import { toast } from 'svelte-sonner';
+ import { m } from '$lib/paraglide/messages';
+ import { cn } from '$lib/utils';
+ import settingsStore from '$lib/stores/config-store';
+ import { debounced } from '$lib/utils/utils';
+ import type { SearchPaginationSortRequest } from '$lib/types/pagination.type';
+ import { tick } from 'svelte';
+ import { EnvironmentsIcon, RemoteEnvironmentIcon, AddIcon, SearchIcon, CloseIcon } from '$lib/icons';
+
+ type Props = {
+ open: boolean;
+ isAdmin?: boolean;
+ };
+
+ let { open = $bindable(false), isAdmin = false }: Props = $props();
+
+ let searchQuery = $state('');
+ let environments = $state<Environment[]>([]);
+ let isLoading = $state(false);
+ let isLoadingMore = $state(false);
+ let currentPage = $state(1);
+ let totalPages = $state(1);
+ let scrollContainer = $state<HTMLDivElement | null>(null);
+ let lastScrollTop = $state(0);
+ let loadError = $state<string | null>(null);
+ let environmentsPromise = $state<Promise<void> | null>(null);
+ let currentRequestId = 0;
+
+ const PAGE_SIZE = 10;
+
+ const DEFAULT_REQUEST_OPTIONS: SearchPaginationSortRequest = {
+ pagination: { page: 1, limit: PAGE_SIZE },
+ sort: { column: 'name', direction: 'asc' },
+ search: undefined
+ };
+
+ let requestOptions = $state<SearchPaginationSortRequest>(DEFAULT_REQUEST_OPTIONS);
+
+ async function resetScrollToTop() {
+ await tick();
+ if (scrollContainer) scrollContainer.scrollTop = 0;
+ lastScrollTop = 0;
+ }
+
+ function normalizeSearch(query: string): string | undefined {
+ const trimmed = query.trim();
+ return trimmed ? trimmed : undefined;
+ }
+
+ async function fetchEnvironments(options: SearchPaginationSortRequest, append: boolean, throwOnError = false) {
+ currentRequestId++;
+ const requestId = currentRequestId;
+ loadError = null;
+ requestOptions = options;
+
+ if (append) {
+ isLoadingMore = true;
+ } else {
+ isLoading = true;
+ isLoadingMore = false;
+ }
+
+ try {
+ const result = await environmentManagementService.getEnvironments(options);
+ if (requestId !== currentRequestId) return;
+
+ environments = append ? [...environments, ...result.data] : result.data;
+ currentPage = result.pagination.currentPage;
+ totalPages = result.pagination.totalPages;
+ } catch (error) {
+ if (requestId !== currentRequestId) return;
+ console.error('Failed to load environments:', error);
+ loadError = 'Failed to load environments';
+ toast.error(loadError);
+ if (throwOnError) throw error;
+ } finally {
+ if (requestId !== currentRequestId) return;
+ isLoading = false;
+ isLoadingMore = false;
+ }
+ }
+
+ async function loadInitial() {
+ environments = [];
+ currentPage = 1;
+ totalPages = 1;
+ await resetScrollToTop();
+ const options: SearchPaginationSortRequest = {
+ ...requestOptions,
+ search: normalizeSearch(searchQuery),
+ pagination: { page: 1, limit: PAGE_SIZE },
+ sort: { column: 'name', direction: 'asc' }
+ };
+ await fetchEnvironments(options, false, true);
+ }
+
+ function resetDialogState() {
+ // Invalidate any inflight request
+ currentRequestId++;
+ searchQuery = '';
+ requestOptions = DEFAULT_REQUEST_OPTIONS;
+ lastScrollTop = 0;
+ environmentsPromise = null;
+ loadError = null;
+ // Keep environments around or clear? Clear so reopening always shows a clean slate
+ environments = [];
+ currentPage = 1;
+ totalPages = 1;
+ }
+
+ function startInitialLoad() {
+ environmentsPromise = Promise.resolve().then(() => loadInitial());
+ }
+
+ function closeDialog() {
+ open = false;
+ resetDialogState();
+ }
+
+ function openSession(node: HTMLElement) {
+ // Runs when the dialog content mounts (i.e., when `open` becomes true)
+ startInitialLoad();
+ return {
+ destroy() {
+ // Runs when the dialog content unmounts (i.e., when `open` becomes false)
+ resetDialogState();
+ }
+ };
+ }
+
+ const debouncedSearch = debounced((query: string) => {
+ // Prevent stale debounced callbacks from re-applying an old query (e.g. after clearing the input)
+ if (query !== searchQuery) return;
+ const options: SearchPaginationSortRequest = {
+ ...requestOptions,
+ search: normalizeSearch(query),
+ pagination: { page: 1, limit: PAGE_SIZE },
+ sort: { column: 'name', direction: 'asc' }
+ };
+ environmentsPromise = Promise.resolve().then(async () => {
+ if (query !== searchQuery) return;
+ await resetScrollToTop();
+ await fetchEnvironments(options, false, true);
+ });
+ }, 300);
+
+ function clearSearch() {
+ searchQuery = '';
+ const options: SearchPaginationSortRequest = {
+ ...requestOptions,
+ search: undefined,
+ pagination: { page: 1, limit: PAGE_SIZE },
+ sort: { column: 'name', direction: 'asc' }
+ };
+ environmentsPromise = Promise.resolve().then(async () => {
+ await resetScrollToTop();
+ await fetchEnvironments(options, false, true);
+ });
+ }
+
+ function handleScroll(e: Event) {
+ const target = e.target as HTMLDivElement;
+ const { scrollTop, scrollHeight, clientHeight } = target;
+
+ // If content isn't scrollable yet, don't auto-fetch more pages.
+ if (scrollHeight <= clientHeight) return;
+
+ // Only react to downward scrolling; prevents programmatic scrollTop resets from triggering load-more loops.
+ if (scrollTop <= lastScrollTop) return;
+ lastScrollTop = scrollTop;
+
+ // Load more when user scrolls near the bottom (within 50px)
+ if (scrollHeight - scrollTop - clientHeight < 50) {
+ if (!isLoadingMore && currentPage < totalPages) {
+ loadMoreEnvironments();
+ }
+ }
+ }
+
+ async function loadMoreEnvironments() {
+ if (isLoading || isLoadingMore) return;
+ if (currentPage >= totalPages) return;
+ isLoadingMore = true;
+ try {
+ const options: SearchPaginationSortRequest = {
+ ...requestOptions,
+ search: normalizeSearch(searchQuery),
+ pagination: { page: currentPage + 1, limit: PAGE_SIZE },
+ sort: { column: 'name', direction: 'asc' }
+ };
+ await fetchEnvironments(options, true, false);
+ } catch {
+ // fetchEnvironments already handles toasts/errors (and stale-response protection)
+ } finally {
+ // fetchEnvironments controls isLoadingMore; this is only a safety net.
+ isLoadingMore = false;
+ }
+ }
+
+ async function handleSelect(env: Environment) {
+ if (!env || !env.enabled) return;
+ try {
+ await environmentStore.setEnvironment(env);
+ closeDialog();
+ toast.success(m.environments_switched_to({ name: env.name }));
+ } catch (error) {
+ console.error('Failed to set environment:', error);
+ toast.error('Failed to Connect to Environment');
+ }
+ }
+
+ function getConnectionString(env: Environment): string {
+ if (env.id === '0') {
+ return $settingsStore.dockerHost || 'unix:///var/run/docker.sock';
+ } else {
+ return env.apiUrl;
+ }
+ }
+</script>
+
+<ResponsiveDialog bind:open title={m.sidebar_select_environment()} contentClass="max-w-2xl">
+ {#snippet children()}
+ <div class="m-2 flex flex-col gap-4">
+ {#if open}
+ <div class="hidden" use:openSession aria-hidden="true"></div>
+ {/if}
+ <div class="relative">
+ <SearchIcon class="text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2" />
+ <Input
+ type="text"
+ placeholder={m.common_search()}
+ value={searchQuery}
+ oninput={(e) => {
+ searchQuery = (e.target as HTMLInputElement).value;
+ debouncedSearch(searchQuery);
+ }}
+ class="h-9 pr-10 pl-10"
+ />
+ {#if searchQuery}
+ <button
+ type="button"
+ onclick={clearSearch}
+ class="text-muted-foreground hover:text-foreground hover:bg-muted absolute top-1/2 right-3 -translate-y-1/2 rounded-sm p-0.5 transition-colors"
+ title="Clear search"
+ >
+ <CloseIcon class="size-4" />
+ </button>
+ {/if}
+ </div>
+
+ <div bind:this={scrollContainer} onscroll={handleScroll} class="max-h-[50vh] min-h-[200px] overflow-y-auto">
+ {#await environmentsPromise}
+ <div class="flex items-center justify-center py-10">
+ <Spinner class="size-6" />
+ </div>
+ {:then}
+ {#if environments.length === 0}
+ <div class="text-muted-foreground py-10 text-center">
+ <EnvironmentsIcon class="mx-auto mb-4 size-12 opacity-50" />
+ <p>{m.sidebar_no_environments()}</p>
+ </div>
+ {:else}
+ <div class="space-y-1">
+ {#each environments as env (env.id)}
+ {@const isActive = environmentStore.selected?.id === env.id}
+ {@const isDisabled = !env.enabled}
+ <button
+ type="button"
+ onclick={() => !isActive && !isDisabled && handleSelect(env)}
+ disabled={isDisabled}
+ class={cn(
+ 'flex w-full items-center gap-3 rounded-lg p-3 text-left transition-colors',
+ isActive && 'bg-primary/10 border-primary border font-medium',
+ !isActive && !isDisabled && 'hover:bg-muted/50',
+ isDisabled && 'cursor-not-allowed opacity-50'
+ )}
+ >
+ <div
+ class={cn(
+ 'flex size-8 shrink-0 items-center justify-center rounded-md border',
+ isActive ? 'bg-primary border-primary' : 'border-border'
+ )}
+ >
+ {#if env.id === '0'}
+ <EnvironmentsIcon class={cn('size-4', isActive && 'text-primary-foreground')} />
+ {:else}
+ <RemoteEnvironmentIcon class={cn('size-4', isActive && 'text-primary-foreground')} />
+ {/if}
+ </div>
+ <div class="flex min-w-0 flex-1 flex-col">
+ <span class="truncate">{env.name}</span>
+ <span class={cn('truncate text-xs', isActive ? 'text-primary/70' : 'text-muted-foreground')}>
+ {getConnectionString(env)}
+ </span>
+ </div>
+ {#if isActive}
+ <span class="text-primary text-xs font-medium">{m.environments_current_environment()}</span>
+ {/if}
+ </button>
+ {/each}
+
+ {#if isLoadingMore}
+ <div class="flex items-center justify-center py-4">
+ <Spinner class="size-5" />
+ </div>
+ {/if}
+ </div>
+ {/if}
+ {:catch}
+ <div class="text-destructive py-10 text-center">
+ <p>{m.error_generic()}</p>
+ </div>
+ {/await}
+ </div>
+ </div>
+ {/snippet}
+
+ {#snippet footer()}
+ <div class="flex w-full items-center justify-between gap-2">
+ {#if isAdmin}
+ <Button
+ variant="outline"
+ onclick={() => {
+ closeDialog();
+ goto('/environments');
+ }}
+ >
+ <AddIcon class="size-4" />
+ {m.sidebar_manage_environments()}
+ </Button>
+ {:else}
+ <div></div>
+ {/if}
+ <Button variant="outline" onclick={closeDialog}>
+ {m.common_close()}
+ </Button>
+ </div>
+ {/snippet}
+</ResponsiveDialog>
diff --git a/frontend/src/lib/components/mobile-nav/mobile-user-card.svelte b/frontend/src/lib/components/mobile-nav/mobile-user-card.svelte
index d5bc43061..e7e8e86f6 100644
--- a/frontend/src/lib/components/mobile-nav/mobile-user-card.svelte
+++ b/frontend/src/lib/components/mobile-nav/mobile-user-card.svelte
@@ -1,15 +1,13 @@
<script lang="ts">
- import * as Button from '$lib/components/ui/button/index.js';
- import * as Select from '$lib/components/ui/select/index.js';
import { cn } from '$lib/utils';
import { environmentStore } from '$lib/stores/environment.store.svelte';
- import type { Environment } from '$lib/types/environment.type';
import { mode, toggleMode } from 'mode-watcher';
- import { toast } from 'svelte-sonner';
import { m } from '$lib/paraglide/messages';
import type { User } from '$lib/types/user.type';
import LocalePicker from '$lib/components/locale-picker.svelte';
+ import EnvironmentSwitcherDialog from '$lib/components/dialogs/environment-switcher-dialog.svelte';
import settingsStore from '$lib/stores/config-store';
+ import * as Button from '$lib/components/ui/button/index.js';
import {
ArrowDownIcon,
MoonIcon,
@@ -17,7 +15,8 @@
LogoutIcon,
EnvironmentsIcon,
RemoteEnvironmentIcon,
- LanguageIcon
+ LanguageIcon,
+ ArrowRightIcon
} from '$lib/icons';
type Props = {
@@ -28,29 +27,19 @@
let { user, class: className = '' }: Props = $props();
let userCardExpanded = $state(false);
+ let envDialogOpen = $state(false);
const isDarkMode = $derived(mode.current === 'dark');
const effectiveUser = $derived(user);
const isAdmin = $derived(!!effectiveUser.roles?.includes('admin'));
- const selectedValue = $derived(environmentStore.selected?.id || '');
-
- async function handleEnvSelect(envId: string) {
- const env = environmentStore.available.find((e) => e.id === envId);
- if (!env || !env.enabled) return;
- try {
- await environmentStore.setEnvironment(env);
- } catch (error) {
- console.error('Failed to set environment:', error);
- toast.error('Failed to Connect to Environment');
- }
- }
- function getConnectionString(env: Environment): string {
- if (env.id === '0') {
+ function getConnectionString(): string {
+ if (!environmentStore.selected) return '';
+ if (environmentStore.selected.id === '0') {
return $settingsStore.dockerHost || 'unix:///var/run/docker.sock';
} else {
- return env.apiUrl;
+ return environmentStore.selected.apiUrl;
}
}
</script>
@@ -97,46 +86,32 @@
{#if userCardExpanded}
<div class="border-border/20 bg-muted/10 space-y-4 border-t p-4">
{#if isAdmin}
- <div class="bg-background/50 border-border/20 rounded-2xl border p-4">
- <div class="space-y-3">
- <div class="flex items-start gap-3">
- <div class="bg-primary/10 text-primary flex aspect-square size-8 shrink-0 items-center justify-center rounded-lg">
- {#if environmentStore.selected?.id === '0'}
- <EnvironmentsIcon class="size-4" />
- {:else}
- <RemoteEnvironmentIcon class="size-4" />
- {/if}
- </div>
- <div class="min-w-0 flex-1">
- <div class="text-muted-foreground/70 text-xs font-medium tracking-widest uppercase">
- {m.sidebar_environment_label()}
- </div>
- <div class="text-foreground text-sm font-medium">
- {environmentStore.selected ? environmentStore.selected.name : m.sidebar_no_environment()}
- </div>
- {#if environmentStore.selected}
- <div class="text-muted-foreground/60 text-xs">
- {getConnectionString(environmentStore.selected)}
- </div>
- {/if}
- </div>
+ <button
+ class="bg-background/50 border-border/20 hover:bg-muted/30 flex w-full items-center gap-3 rounded-2xl border p-4 text-left transition-colors"
+ onclick={() => (envDialogOpen = true)}
+ >
+ <div class="bg-primary/10 text-primary flex aspect-square size-8 shrink-0 items-center justify-center rounded-lg">
+ {#if environmentStore.selected?.id === '0'}
+ <EnvironmentsIcon class="size-4" />
+ {:else}
+ <RemoteEnvironmentIcon class="size-4" />
+ {/if}
+ </div>
+ <div class="min-w-0 flex-1">
+ <div class="text-muted-foreground/70 text-xs font-medium tracking-widest uppercase">
+ {m.sidebar_environment_label()}
+ </div>
+ <div class="text-foreground text-sm font-medium">
+ {environmentStore.selected ? environmentStore.selected.name : m.sidebar_no_environment()}
</div>
- {#if environmentStore.available.length > 1}
- <Select.Root type="single" value={selectedValue} onValueChange={handleEnvSelect}>
- <Select.Trigger class="bg-background/50 border-border/30 text-foreground h-9 w-full text-sm font-medium">
- <span class="truncate">{m.sidebar_select_environment()}</span>
- </Select.Trigger>
- <Select.Content class="max-w-[280px] min-w-[160px]">
- {#each environmentStore.available as env (env.id)}
- <Select.Item value={env.id} disabled={!env.enabled} class="text-sm">
- {env.name}
- </Select.Item>
- {/each}
- </Select.Content>
- </Select.Root>
+ {#if environmentStore.selected}
+ <div class="text-muted-foreground/60 truncate text-xs">
+ {getConnectionString()}
+ </div>
{/if}
</div>
- </div>
+ <ArrowRightIcon class="text-muted-foreground/60 size-5 shrink-0" />
+ </button>
{/if}
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2">
@@ -182,3 +157,5 @@
</div>
{/if}
</div>
+
+<EnvironmentSwitcherDialog bind:open={envDialogOpen} {isAdmin} />
diff --git a/frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte b/frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte
index 4ea726530..32aafd549 100644
--- a/frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte
+++ b/frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte
@@ -1,172 +1,60 @@
<script lang="ts">
- import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
- import { useSidebar } from '$lib/components/ui/sidebar/index.js';
import { environmentStore } from '$lib/stores/environment.store.svelte';
- import type { Environment } from '$lib/types/environment.type';
- import { goto } from '$app/navigation';
- import { toast } from 'svelte-sonner';
import { m } from '$lib/paraglide/messages';
- import { cn } from '$lib/utils';
import settingsStore from '$lib/stores/config-store';
- import { EnvironmentsIcon, RemoteEnvironmentIcon, AddIcon, ArrowsUpDownIcon } from '$lib/icons';
+ import { EnvironmentsIcon, RemoteEnvironmentIcon, ArrowsUpDownIcon } from '$lib/icons';
type Props = {
- isAdmin?: boolean;
+ onOpenDialog?: () => void;
};
- let { isAdmin = false }: Props = $props();
+ let { onOpenDialog }: Props = $props();
- const sidebar = useSidebar();
-
- let dropdownOpen = $state(false);
-
- $effect(() => {
- if (sidebar.state === 'collapsed' && !sidebar.isHovered && dropdownOpen) {
- dropdownOpen = false;
- }
- });
-
- async function handleSelect(env: Environment) {
- if (!env || !env.enabled) return;
- try {
- await environmentStore.setEnvironment(env);
- } catch (error) {
- console.error('Failed to set environment:', error);
- toast.error('Failed to Connect to Environment');
- }
- }
-
- function getConnectionString(env: Environment): string {
- if (env.id === '0') {
+ function getConnectionString(): string {
+ if (!environmentStore.selected) return '';
+ if (environmentStore.selected.id === '0') {
return $settingsStore.dockerHost || 'unix:///var/run/docker.sock';
} else {
- return env.apiUrl;
+ return environmentStore.selected.apiUrl;
}
}
</script>
<Sidebar.Menu>
<Sidebar.MenuItem>
- <DropdownMenu.Root bind:open={dropdownOpen}>
- <DropdownMenu.Trigger>
- {#snippet child({ props: childProps })}
- <Sidebar.MenuButton
- {...childProps}
- size="lg"
- tooltipContent={environmentStore.selected ? environmentStore.selected.name : m.sidebar_no_environment()}
- class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
- >
- {#if environmentStore.selected}
- <div class="bg-primary text-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg">
- {#if environmentStore.selected.id === '0'}
- <EnvironmentsIcon class="size-4" />
- {:else}
- <RemoteEnvironmentIcon class="size-4" />
- {/if}
- </div>
- <div class="grid flex-1 text-left text-sm leading-tight">
- <span class="truncate font-medium">
- {environmentStore.selected.name}
- </span>
- <span class="truncate text-xs">
- {getConnectionString(environmentStore.selected)}
- </span>
- </div>
- {:else}
- <div class="bg-primary text-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg">
- <EnvironmentsIcon class="size-4" />
- </div>
- <div class="grid flex-1 text-left text-sm leading-tight">
- <span class="truncate font-medium">{m.sidebar_no_environment()}</span>
- <span class="truncate text-xs">{m.sidebar_select_one()}</span>
- </div>
- {/if}
- <ArrowsUpDownIcon class="ml-auto" />
- </Sidebar.MenuButton>
- {/snippet}
- </DropdownMenu.Trigger>
- <DropdownMenu.Content
- class="w-(--bits-dropdown-menu-anchor-width) min-w-56 rounded-2xl border shadow-lg backdrop-blur-(--glass-blur-popup) backdrop-saturate-150"
- align="start"
- side="right"
- sideOffset={4}
- >
- <div
- role="group"
- onmouseenter={() => {
- // Keep sidebar hovered when mouse is over dropdown
- if (sidebar.state === 'collapsed') {
- sidebar.setHovered(true);
- }
- }}
- onmouseleave={() => {
- // Clear hover when leaving dropdown
- sidebar.setHovered(false, 200);
- }}
- >
- <DropdownMenu.Label class="text-muted-foreground text-xs">{m.sidebar_select_environment()}</DropdownMenu.Label>
- {#if environmentStore.available.length === 0}
- <DropdownMenu.Item disabled class="gap-2 p-2">
- <div class="flex size-6 items-center justify-center rounded-md border">
- <EnvironmentsIcon class="size-3.5 shrink-0" />
- </div>
- <span>{m.sidebar_no_environments()}</span>
- </DropdownMenu.Item>
+ <Sidebar.MenuButton
+ size="lg"
+ tooltipContent={environmentStore.selected ? environmentStore.selected.name : m.sidebar_no_environment()}
+ class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
+ onclick={() => onOpenDialog?.()}
+ >
+ {#if environmentStore.selected}
+ <div class="bg-primary text-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg">
+ {#if environmentStore.selected.id === '0'}
+ <EnvironmentsIcon class="size-4" />
{:else}
- {#each environmentStore.available.slice(0, 5) as env (env.id)}
- {@const isActive = environmentStore.selected?.id === env.id}
- {@const isDisabled = !env.enabled}
- <DropdownMenu.Item
- onSelect={() => !isActive && !isDisabled && handleSelect(env)}
- disabled={isDisabled}
- class={cn(
- 'gap-2 p-2',
- isActive && 'bg-sidebar-accent text-sidebar-accent-foreground pointer-events-none font-medium',
- isDisabled && 'cursor-not-allowed opacity-50'
- )}
- >
- <div
- class={cn(
- 'flex size-6 items-center justify-center rounded-md border',
- isActive ? 'bg-primary border-primary' : 'border-border'
- )}
- >
- {#if env.id === '0'}
- <EnvironmentsIcon class={cn('size-3.5 shrink-0', isActive && 'text-primary-foreground')} />
- {:else}
- <RemoteEnvironmentIcon class={cn('size-3.5 shrink-0', isActive && 'text-primary-foreground')} />
- {/if}
- </div>
- <div class="flex flex-col">
- <span>{env.name}</span>
- <span class={cn('text-xs', isActive ? 'text-sidebar-accent-foreground/70' : 'text-muted-foreground')}>
- {getConnectionString(env)}
- </span>
- </div>
- </DropdownMenu.Item>
- {/each}
- {#if environmentStore.available.length > 5}
- <DropdownMenu.Separator />
- <DropdownMenu.Item class="text-muted-foreground gap-2 p-2" onSelect={() => goto('/environments')}>
- <div class="flex size-6 items-center justify-center rounded-md border bg-transparent">
- <AddIcon class="size-4" />
- </div>
- <div class="font-medium">View all {environmentStore.available.length} environments</div>
- </DropdownMenu.Item>
- {/if}
- {/if}
- {#if isAdmin}
- <DropdownMenu.Separator />
- <DropdownMenu.Item class="gap-2 p-2" onSelect={() => goto('/environments')}>
- <div class="flex size-6 items-center justify-center rounded-md border bg-transparent">
- <AddIcon class="size-4" />
- </div>
- <div class="text-muted-foreground font-medium">{m.sidebar_manage_environments()}</div>
- </DropdownMenu.Item>
+ <RemoteEnvironmentIcon class="size-4" />
{/if}
</div>
- </DropdownMenu.Content>
- </DropdownMenu.Root>
+ <div class="grid flex-1 text-left text-sm leading-tight">
+ <span class="truncate font-medium">
+ {environmentStore.selected.name}
+ </span>
+ <span class="truncate text-xs">
+ {getConnectionString()}
+ </span>
+ </div>
+ {:else}
+ <div class="bg-primary text-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg">
+ <EnvironmentsIcon class="size-4" />
+ </div>
+ <div class="grid flex-1 text-left text-sm leading-tight">
+ <span class="truncate font-medium">{m.sidebar_no_environment()}</span>
+ <span class="truncate text-xs">{m.sidebar_select_one()}</span>
+ </div>
+ {/if}
+ <ArrowsUpDownIcon class="ml-auto" />
+ </Sidebar.MenuButton>
</Sidebar.MenuItem>
</Sidebar.Menu>
diff --git a/frontend/src/lib/components/sidebar/sidebar.svelte b/frontend/src/lib/components/sidebar/sidebar.svelte
index 9a77b5d47..5e52c3c49 100644
--- a/frontend/src/lib/components/sidebar/sidebar.svelte
+++ b/frontend/src/lib/components/sidebar/sidebar.svelte
@@ -6,6 +6,7 @@
import SidebarItemGroup from './sidebar-itemgroup.svelte';
import SidebarUser from './sidebar-user.svelte';
import SidebarEnvSwitcher from './sidebar-env-switcher.svelte';
+ import EnvironmentSwitcherDialog from '$lib/components/dialogs/environment-switcher-dialog.svelte';
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
import { useSidebar } from '$lib/components/ui/sidebar/index.js';
import type { ComponentProps } from 'svelte';
@@ -45,6 +46,7 @@
const isCollapsed = $derived(sidebar.state === 'collapsed' && !(sidebar.hoverExpansionEnabled && sidebar.isHovered));
const isAdmin = $derived(!!effectiveUser?.roles?.includes('admin'));
+ let envSwitcherOpen = $state(false);
// Filter out sub-items for settings on desktop since we have a dedicated settings sidebar
const desktopSettingsItems =
@@ -63,6 +65,8 @@
versionInfo={versionInformation}
/>
+<EnvironmentSwitcherDialog bind:open={envSwitcherOpen} {isAdmin} />
+
<Sidebar.Root {collapsible} {variant} {...restProps}>
<Sidebar.Header class={isCollapsed ? 'gap-0 p-1 pb-2' : ''}>
{#if isCollapsed}
@@ -80,10 +84,10 @@
</div>
{#if isCollapsed}
<div class="flex justify-center px-1">
- <SidebarEnvSwitcher {isAdmin} />
+ <SidebarEnvSwitcher onOpenDialog={() => (envSwitcherOpen = true)} />
</div>
{:else}
- <SidebarEnvSwitcher {isAdmin} />
+ <SidebarEnvSwitcher onOpenDialog={() => (envSwitcherOpen = true)} />
{/if}
</Sidebar.Header>
<Sidebar.Content class={!isCollapsed ? '-mt-2' : ''}>