From 180e7eef7d345ff46a88dd18a01ffc95a37c2f4e Mon Sep 17 00:00:00 2001 From: centdix <40307056+centdix@users.noreply.github.com> Date: Mon, 28 Apr 2025 21:33:34 +0200 Subject: [PATCH] add current workspace if not in workspace list (#5673) --- .../components/settings/TokensTable.svelte | 21 ++++++-- frontend/src/lib/stores.ts | 51 ++++++++++--------- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/frontend/src/lib/components/settings/TokensTable.svelte b/frontend/src/lib/components/settings/TokensTable.svelte index 1d46fc11cc..2333d446ef 100644 --- a/frontend/src/lib/components/settings/TokensTable.svelte +++ b/frontend/src/lib/components/settings/TokensTable.svelte @@ -5,7 +5,7 @@ import { UserService } from '$lib/gen' import { Button } from '$lib/components/common' import { Clipboard, Plus } from 'lucide-svelte' - import { workspaceStore, userWorkspaces } from '$lib/stores' + import { workspaceStore, userWorkspaces, type UserWorkspace } from '$lib/stores' import { createEventDispatcher } from 'svelte' import ToggleButtonGroup from '../common/toggleButton-v2/ToggleButtonGroup.svelte' import ToggleButton from '../common/toggleButton-v2/ToggleButton.svelte' @@ -42,6 +42,21 @@ let newMcpScope = $state('favorites') let newMcpToken = $state(undefined) + function ensureCurrentWorkspaceIncluded( + workspacesList: UserWorkspace[], + currentWorkspace: string | undefined + ) { + if (!currentWorkspace) { + return workspacesList + } + const hasCurrentWorkspace = workspacesList.some((w) => w.id === currentWorkspace) + if (hasCurrentWorkspace) { + return workspacesList + } + return [{ id: currentWorkspace, name: currentWorkspace }, ...workspacesList] + } + + const workspaces = $derived(ensureCurrentWorkspaceIncluded($userWorkspaces, $workspaceStore)) const mcpBaseUrl = $derived(`${window.location.origin}/api/mcp/w/${newTokenWorkspace}/sse?token=`) const dispatch = createEventDispatcher() @@ -221,8 +236,8 @@
- + {#each workspaces as workspace} {/each} diff --git a/frontend/src/lib/stores.ts b/frontend/src/lib/stores.ts index 20e48d235c..a38b0be146 100644 --- a/frontend/src/lib/stores.ts +++ b/frontend/src/lib/stores.ts @@ -28,6 +28,14 @@ export interface UserExt { folders_owners: string[] } +export interface UserWorkspace { + id: string + name: string + username: string + color: string | null + operator_settings?: OperatorSettings +} + const persistedWorkspace = BROWSER && getWorkspace() function getWorkspace(): string | undefined { @@ -60,31 +68,26 @@ export const superadmin = writable(undefined) export const devopsRole = writable(undefined) export const lspTokenStore = writable(undefined) export const hubBaseUrlStore = writable('https://hub.windmill.dev') -export const userWorkspaces: Readable< - Array<{ - id: string - name: string - username: string - color: string | null - operator_settings?: OperatorSettings - }> -> = derived([usersWorkspaceStore, superadmin], ([store, superadmin]) => { - const originalWorkspaces = store?.workspaces ?? [] - if (superadmin) { - return [ - ...originalWorkspaces.filter((x) => x.id != 'admins'), - { - id: 'admins', - name: 'Admins', - username: 'superadmin', - color: null, - operator_settings: null - } - ] - } else { - return originalWorkspaces +export const userWorkspaces: Readable> = derived( + [usersWorkspaceStore, superadmin], + ([store, superadmin]) => { + const originalWorkspaces = store?.workspaces ?? [] + if (superadmin) { + return [ + ...originalWorkspaces.filter((x) => x.id != 'admins'), + { + id: 'admins', + name: 'Admins', + username: 'superadmin', + color: null, + operator_settings: null + } + ] + } else { + return originalWorkspaces + } } -}) +) export const copilotInfo = writable<{ enabled: boolean codeCompletionModel?: AIProviderModel