fix: move leave workspace out of the settings menu (#12123)

* fix: move leave workspace out of the settings menu

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: use Alert for the leave workspace warning

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Guilhem
2026-10-30 12:34:35 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent ac795bcd25
commit 1c8d60dd43
5 changed files with 92 additions and 147 deletions
@@ -0,0 +1,58 @@
<script lang="ts">
import { Alert } from '$lib/components/common'
import ConfirmationModal from '$lib/components/common/confirmationModal/ConfirmationModal.svelte'
import { WorkspaceService } from '$lib/gen'
import { goto } from '$lib/navigation'
import { clearStores } from '$lib/storeUtils'
import { userWorkspaces, workspaceStore } from '$lib/stores'
import { sendUserToast } from '$lib/toast'
const workspaceName = $derived(
$userWorkspaces.find((w) => w.id === $workspaceStore)?.name ?? $workspaceStore ?? ''
)
let confirmOpen = $state(false)
async function leave() {
await WorkspaceService.leaveWorkspace({ workspace: $workspaceStore ?? '' })
sendUserToast(`You left ${workspaceName}`)
clearStores()
await goto('/user/workspaces')
}
</script>
<div class="flex flex-col gap-6 max-w-2xl py-6">
<div class="flex flex-col gap-1">
<span class="text-sm font-semibold text-emphasis">You are a member of {workspaceName}</span>
<p class="text-xs text-secondary">
Only workspace admins can change its settings. Ask one of them if something here needs to
change.
</p>
</div>
<Alert
type="error"
title="Leave workspace"
actions={[
{ label: `Leave ${workspaceName}`, variant: 'accent', onClick: () => (confirmOpen = true) }
]}
>
Leaving removes your access to <b>{workspaceName}</b> right away: its scripts, flows, apps, resources
and runs. You cannot rejoin by yourself. A workspace admin has to add you again.
</Alert>
</div>
<ConfirmationModal
open={confirmOpen}
title="Leave {workspaceName}?"
confirmationText="Leave workspace"
onCanceled={() => (confirmOpen = false)}
onConfirmed={() => {
confirmOpen = false
void leave()
}}
>
<p>
You will lose access to <b>{workspaceName}</b>. Only a workspace admin can add you back.
</p>
</ConfirmationModal>
@@ -24,12 +24,10 @@
import { goto } from '$lib/navigation'
import { type Item } from '$lib/utils'
import { logout } from '$lib/logoutKit'
import { leaveCurrentWorkspace } from './leaveWorkspace'
import { isCloudHosted } from '$lib/cloud'
import DropdownV2 from '$lib/components/DropdownV2.svelte'
import ConfirmationModal from '../common/confirmationModal/ConfirmationModal.svelte'
import DeleteForkedWorkspaceModal from './DeleteForkedWorkspaceModal.svelte'
import { workspaceIsFork, isForkOwner } from '$lib/utils/workspaceHierarchy'
import { workspaceIsFork } from '$lib/utils/workspaceHierarchy'
import DarkModeObserver from '../DarkModeObserver.svelte'
import DiscordIcon from '../icons/brands/Discord.svelte'
import MenuLink from './MenuLink.svelte'
@@ -57,9 +55,8 @@
// Session mode: workspace the workspace-settings entry should target —
// the session's own (possibly forked) workspace, which can differ from
// the rail's active workspace, so the entry's href carries it as the
// `workspace` query param. Also hides "Leave workspace" (leaving a
// workspace from the session rail makes no sense). Unset = navigation
// mode, entry targets the active workspace.
// `workspace` query param. Unset = navigation mode, entry targets the
// active workspace.
workspaceSettingsTarget = undefined,
numUnacknowledgedCriticalAlerts = 0,
// Overridable so the kitchen-sink page can preview the cloud variant
@@ -80,14 +77,6 @@
: undefined
)
// The fork-owner grant must be checked against the workspace the settings entry
// actually points at — the session target when in session mode, else the active
// workspace — otherwise ownership of the wrong workspace could hide the entry or
// expose a dead link to a fork the user doesn't own.
const settingsWs = $derived(workspaceSettingsTarget ? settingsTargetWs : currentWs)
const canManageWorkspace = $derived(
$userStore?.is_admin || $superadmin || isForkOwner(settingsWs, $userStore?.email)
)
// Fork/dev workspaces are detected by their parent link, not the `wm-fork-` id prefix. A dev
// workspace is excluded: it is a standing environment its whole team works in, torn down by
// detaching it in the dev-workspace settings, so offering a one-click delete beside the account
@@ -101,7 +90,6 @@
!currentWs.is_dev_workspace
)
let leaveWorkspaceModal = $state(false)
let deleteForkModal = $state<DeleteForkedWorkspaceModal>()
const { recent: recentChangelogs, hasNew } = readRecentChangelogs()
@@ -157,20 +145,10 @@
// Account / instance actions gathered under one "Settings" dropdown, shared by
// the session rail and the global sidebar so both expose the same entry point.
// Logout lives inside the user submenu with the other account-scoped entries.
// Workspace- and instance-scoped entries anchor the bottom of the menu,
// instance settings last.
// Workspace- and instance-scoped entries sit between the account entries and Logout.
// Leaving a workspace lives on the workspace settings page, which every member reaches,
// not in this menu next to Logout: only a workspace admin can undo a leave.
const workspaceInstanceItems = $derived<Item[]>([
...(!canManageWorkspace && !workspaceSettingsTarget
? [
{
displayName: 'Leave workspace',
icon: LogOut,
type: 'delete' as const,
action: () => (leaveWorkspaceModal = true)
}
]
: []),
// Fork deletion is a global-sidebar action on the active workspace, so keep it
// out of the session rail's per-target settings entry (`workspaceSettingsTarget`).
...(currentWsIsThrowawayFork && !workspaceSettingsTarget
@@ -183,23 +161,19 @@
}
]
: []),
...(canManageWorkspace
? [
workspaceSettingsTarget
? {
displayName: `${settingsTargetWs?.name ?? workspaceSettingsTarget} settings`,
icon: Building,
// The `workspace` query param switches the app to the target
// workspace on arrival (full loads and client-side navs alike).
href: `/workspace_settings?workspace=${workspaceSettingsTarget}`
}
: {
displayName: `${currentWs?.name ?? $workspaceStore ?? 'Workspace'} settings`,
icon: Building,
href: '/workspace_settings'
}
]
: []),
workspaceSettingsTarget
? {
displayName: `${settingsTargetWs?.name ?? workspaceSettingsTarget} settings`,
icon: Building,
// The `workspace` query param switches the app to the target
// workspace on arrival (full loads and client-side navs alike).
href: `/workspace_settings?workspace=${workspaceSettingsTarget}`
}
: {
displayName: `${currentWs?.name ?? $workspaceStore ?? 'Workspace'} settings`,
icon: Building,
href: '/workspace_settings'
},
...($superadmin
? [
{
@@ -268,18 +242,16 @@
disabled: true
}
]
: []),
{ displayName: 'Logout', icon: LogOut, action: () => logout() }
: [])
]
},
...workspaceInstanceItems.map((item, i) => (i === 0 ? { ...item, separatorTop: true } : item))
...workspaceInstanceItems.map((item, i) => (i === 0 ? { ...item, separatorTop: true } : item)),
{ displayName: 'Logout', icon: LogOut, action: () => logout(), separatorTop: true }
])
const logsItems = $derived<Item[]>([
{ displayName: 'Audit logs', icon: Eye, href: '/audit_logs' },
...($devopsRole
? [{ displayName: 'Service logs', icon: Logs, href: '/service_logs' }]
: []),
...($devopsRole ? [{ displayName: 'Service logs', icon: Logs, href: '/service_logs' }] : []),
...($enterpriseLicense
? [
{
@@ -408,26 +380,6 @@
{/snippet}
</DropdownV2>
<!-- `alwaysPortal`: the sidebar's mobile slide-in panel keeps a `transform` that would
otherwise confine the dialog to the panel's width. -->
<ConfirmationModal
open={leaveWorkspaceModal}
alwaysPortal
title="Leave workspace"
confirmationText="Leave workspace"
on:canceled={() => {
leaveWorkspaceModal = false
}}
on:confirmed={() => {
leaveWorkspaceModal = false
void leaveCurrentWorkspace()
}}
>
<div class="flex flex-col w-full space-y-4">
<span>Are you sure you want to leave this workspace?</span>
</div>
</ConfirmationModal>
<DeleteForkedWorkspaceModal bind:this={deleteForkModal} />
<DarkModeObserver bind:darkMode />
@@ -4,14 +4,12 @@
superadmin,
usedTriggerKinds,
userStore,
userWorkspaces,
workspaceStore,
isCriticalAlertsUIOpen,
enterpriseLicense,
devopsRole,
roleCapabilities
} from '$lib/stores'
import { isForkOwner } from '$lib/utils/workspaceHierarchy'
import { SIDEBAR_SHOW_SCHEDULES } from '$lib/consts'
import { NAV_PAGES } from './navPages'
import {
@@ -23,7 +21,6 @@
FolderCog,
Github,
HelpCircle,
LogOut,
Newspaper,
Route,
Settings,
@@ -40,7 +37,6 @@
import { slide } from 'svelte/transition'
import UserMenu from './UserMenu.svelte'
import DiscordIcon from '../icons/brands/Discord.svelte'
import ConfirmationModal from '../common/confirmationModal/ConfirmationModal.svelte'
import { twMerge } from 'tailwind-merge'
import { page } from '$app/state'
import SideBarNotification from './SideBarNotification.svelte'
@@ -65,7 +61,6 @@
import MenuButton from './MenuButton.svelte'
import GoogleCloudIcon from '../icons/triggers/GoogleCloudIcon.svelte'
import AzureIcon from '../icons/triggers/AzureIcon.svelte'
import { leaveCurrentWorkspace } from './leaveWorkspace'
import type { VisibilityKey } from '$lib/roleCapabilities'
import { markChangelogsOpened, readRecentChangelogs } from './changelogs'
@@ -173,8 +168,6 @@
excludeMainLabels = []
}: Props = $props()
let leaveWorkspaceModal = $state(false)
function computeAllNotificationsCount(menuItems: any[]) {
let count = 0
for (const menuItem of menuItems) {
@@ -183,7 +176,6 @@
return count
}
const currentWs = $derived($userWorkspaces?.find((w) => w.id === $workspaceStore))
function allows(key: VisibilityKey) {
return $roleCapabilities.visibility[key]
}
@@ -372,11 +364,6 @@
let showTriggersGroup = $derived(
showAddTriggerMenu || triggerMenuLinks.some((link) => !link.disabled)
)
// Admins, superadmins, and fork creators reach workspace settings (the latter
// for the fork members screen; see isForkOwner / backend authorize_fork_owner_add_user).
const canManageWorkspace = $derived(
$userStore?.is_admin || $superadmin || isForkOwner(currentWs, $userStore?.email)
)
let secondaryMenuLinks = $derived([
// {
// label: 'Workspace',
@@ -399,18 +386,14 @@
aiDescription: 'Button to navigate to account settings',
faIcon: undefined
},
...(canManageWorkspace
? [
{
label: 'Workspace',
href: '/workspace_settings',
icon: FolderCog,
aiId: 'sidebar-menu-link-workspace',
aiDescription: 'Button to navigate to workspace settings',
faIcon: undefined
}
]
: []),
{
label: 'Workspace',
href: '/workspace_settings',
icon: FolderCog,
aiId: 'sidebar-menu-link-workspace',
aiDescription: 'Button to navigate to workspace settings',
faIcon: undefined
},
...($superadmin
? [
{
@@ -422,19 +405,6 @@
faIcon: undefined
}
]
: []),
...(!$superadmin && !$userStore?.is_admin
? [
{
label: 'Leave workspace',
action: () => {
leaveWorkspaceModal = true
},
class: 'text-red-400',
icon: LogOut,
faIcon: undefined
}
]
: [])
],
disabled: !$roleCapabilities.code
@@ -721,22 +691,3 @@
{/if}
</div></nav
>
<!-- `alwaysPortal`: the sidebar's mobile slide-in panel keeps a `transform` that would
otherwise confine the dialog to the panel's width. -->
<ConfirmationModal
open={leaveWorkspaceModal}
alwaysPortal
title="Leave workspace"
confirmationText="Leave workspace"
on:canceled={() => {
leaveWorkspaceModal = false
}}
on:confirmed={() => {
void leaveCurrentWorkspace()
}}
>
<div class="flex flex-col w-full space-y-4">
<span>Are you sure you want to leave this workspace?</span>
</div>
</ConfirmationModal>
@@ -1,15 +0,0 @@
import { get } from 'svelte/store'
import { goto } from '$lib/navigation'
import { WorkspaceService } from '$lib/gen'
import { sendUserToast } from '$lib/toast'
import { clearStores } from '$lib/storeUtils'
import { workspaceStore } from '$lib/stores'
// Leave the active workspace and land on the workspace list. Shared by the
// settings dropdown and the sidebar menu.
export async function leaveCurrentWorkspace(): Promise<void> {
await WorkspaceService.leaveWorkspace({ workspace: get(workspaceStore) ?? '' })
sendUserToast('You left the workspace')
clearStores()
await goto('/user/workspaces')
}
@@ -28,6 +28,7 @@
import WorkspaceUserSettings from '$lib/components/settings/WorkspaceUserSettings.svelte'
import ForkMemberSettings from '$lib/components/settings/ForkMemberSettings.svelte'
import SettingsPageHeader from '$lib/components/settings/SettingsPageHeader.svelte'
import MemberWorkspaceSettings from '$lib/components/settings/MemberWorkspaceSettings.svelte'
import { WORKSPACE_SHOW_SLACK_CMD, WORKSPACE_SHOW_WEBHOOK_CLI_SYNC } from '$lib/consts'
import {
OauthService,
@@ -2840,10 +2841,8 @@ export async function main(
</div>
</div>
{:else}
<div class="bg-red-100 border-l-4 border-red-600 text-orange-700 p-4 m-4" role="alert">
<p class="font-bold">Not an admin</p>
<p>Workspace settings are only available for admin of workspaces</p>
</div>
<PageHeaderContent separator="always" />
<MemberWorkspaceSettings />
{/if}
</CenteredPage>