Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/desktop/src/main/app-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ vi.mock('electron', () => import('@/test/electron-mock'))
import { settingsRoute } from '@/main/app-routes'

describe('settingsRoute', () => {
it('opens the settings of the organization the user was last in', () => {
expect(settingsRoute('/o/org-1/search?q=x')).toBe('/o/org-1/settings/general')
it('opens the desktop settings of the organization the user was last in', () => {
expect(settingsRoute('/o/org-1/search?q=x')).toBe('/o/org-1/settings/desktop')
})

it('keeps the desktop settings of the workspace the user was last in', () => {
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/main/app-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ export function newChatRoute(lastRoute: string | undefined): string {
}

/**
* Route for "Settings…": the settings of the workspace or organization the user
* was last in. Never the app entry, which lands on a page without settings.
* Route for "Settings…": the Desktop settings of the workspace or organization the
* user was last in. Never the app entry, which lands on a page without settings.
*/
export function settingsRoute(lastRoute: string | undefined): string {
const workspaceId = workspaceIdFromRoute(lastRoute)
if (workspaceId) {
return `/workspace/${workspaceId}/settings/desktop`
}
const organizationId = organizationIdFromRoute(lastRoute)
return organizationId ? `/o/${organizationId}/settings/general` : SETTINGS_ENTRY_ROUTE
return organizationId ? `/o/${organizationId}/settings/desktop` : SETTINGS_ENTRY_ROUTE
}

/**
Expand Down
18 changes: 18 additions & 0 deletions apps/sim/app/o/[organizationId]/settings/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type { OrganizationSettingsFeatures } from '@/components/settings/navigat
import { buildOrganizationNavItems } from '@/app/o/[organizationId]/components/organization-sidebar/navigation'
import {
organizationSettingsNavigation,
organizationSurfaceSettingsNavigation,
resolveOrganizationSettingsSection,
resolveOrganizationSurfaceSection,
} from '@/app/o/[organizationId]/settings/navigation'

const enterprise: OrganizationSettingsFeatures = {
Expand All @@ -15,6 +17,22 @@ const enterprise: OrganizationSettingsFeatures = {
}

describe('organization settings navigation', () => {
it('lists Desktop settings only inside the desktop app, where the page resolves', () => {
const ids = (desktopSettings: boolean) =>
organizationSurfaceSettingsNavigation(
false,
enterprise,
{ connectedAccounts: false, search: true, desktopSettings },
false
).map(({ id }) => id)
expect(ids(true)).toContain('desktop')
expect(ids(false)).not.toContain('desktop')
expect(resolveOrganizationSurfaceSection('/o/one/settings/desktop')).toEqual({
plane: 'account',
section: 'desktop',
})
})

it('normalizes old section names and does not expose unsupported routes', () => {
expect(resolveOrganizationSettingsSection('/o/one/settings/organization?query=person')).toBe(
'members'
Expand Down
24 changes: 17 additions & 7 deletions apps/sim/app/o/[organizationId]/settings/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export type OrganizationSurfaceSettingsSection =

/**
* The account sections the organization surface hosts, rendered by the account
* plane's own renderer. General is the one that belongs to the person alone: the
* personal Subscription gives way to the organization's, which sits beside
* General in the Account group. Platform administration keeps the account
* plane's access rules; Desktop, Browser, and Terminal are workspace-bound.
* plane's own renderer. General and Desktop belong to the person and their device:
* the personal Subscription gives way to the organization's, which sits beside
* them in the Account group. Platform administration keeps the account plane's
* access rules; Browser and Terminal stay with the workspace chats that drive them.
*/
export const ORGANIZATION_SURFACE_ACCOUNT_ITEMS: SettingsNavigationItem<AccountSettingsSection>[] =
ACCOUNT_SETTINGS_ITEMS.filter((item) => item.id === 'general' || item.group === 'platform')
ACCOUNT_SETTINGS_ITEMS.filter(
(item) => item.id === 'general' || item.id === 'desktop' || item.group === 'platform'
)

export function resolveOrganizationSettingsSection(
path: string
Expand Down Expand Up @@ -108,12 +110,20 @@ export function organizationSettingsNavigation(
export function organizationSurfaceSettingsNavigation(
isAdmin: boolean,
features: OrganizationSettingsFeatures,
availability: { connectedAccounts: boolean; search: boolean; knowledgeGraphs?: boolean },
availability: {
connectedAccounts: boolean
search: boolean
knowledgeGraphs?: boolean
/** Whether the desktop app hosts this page; Desktop settings exist only there. */
desktopSettings?: boolean
},
isPlatformAdmin: boolean
): SettingsNavigationItem<AccountSettingsSection | OrganizationSettingsSection>[] {
return [
...ORGANIZATION_SURFACE_ACCOUNT_ITEMS.filter(
(item) => item.group !== 'platform' || isPlatformAdmin
(item) =>
(item.group !== 'platform' || isPlatformAdmin) &&
(item.id !== 'desktop' || availability.desktopSettings === true)
),
...organizationSettingsNavigation(isAdmin, features, availability),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
hasPaidSubscriptionStatus,
hasUsableSubscriptionAccess,
} from '@/lib/billing/subscriptions/utils'
import { hasDesktopSettings } from '@/lib/desktop'
import { organizationRoutes, WORKSPACE_SETTINGS_PATH } from '@/lib/navigation/paths'
import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider'
import {
Expand All @@ -20,6 +21,7 @@ import {
import { warmOrganizationSettingsSectionQuery } from '@/app/o/[organizationId]/settings/settings-query-warmers'
import { useFeatureFlag } from '@/app/workspace/[workspaceId]/providers/feature-flags-provider'
import { useOrganizationBillingSummary } from '@/hooks/queries/organization-billing-summary'
import { useHydrated } from '@/hooks/use-hydrated'

interface OrganizationSettingsSidebarProps {
isCollapsed: boolean
Expand All @@ -31,6 +33,7 @@ export function OrganizationSettingsSidebar(props: OrganizationSettingsSidebarPr
useOrganizationContext()
const knowledgeGraphs = useFeatureFlag('mothership-memory-spaces')
const pathname = usePathname()
const hydrated = useHydrated()
const { data: session } = useSession()
const queryClient = useQueryClient()
const refreshPlan = viewer.isAdmin && settingsFeatures.hosted && settingsFeatures.billingEnabled
Expand Down Expand Up @@ -76,6 +79,7 @@ export function OrganizationSettingsSidebar(props: OrganizationSettingsSidebarPr
connectedAccounts: connectedAccountsAvailable,
search: searchAccess.memberScoped,
knowledgeGraphs,
desktopSettings: hydrated && hasDesktopSettings(),
},
session?.user?.role === 'admin'
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
QuickChatShortcut,
} from '@sim/desktop-bridge'
import { Label, Switch, toast } from '@sim/emcn'
import { useParams, useRouter } from 'next/navigation'
import { usePathname, useRouter } from 'next/navigation'
import { getDesktopBridge, getDesktopShellVersion } from '@/lib/desktop'
import { ComputerUseSettings } from '@/app/workspace/[workspaceId]/settings/components/desktop/computer-use'
import { QuickChatShortcutSelect } from '@/app/workspace/[workspaceId]/settings/components/desktop/quick-chat-shortcut-select'
Expand All @@ -34,9 +34,8 @@ function PreferenceRow({ id, label, checked, disabled, onCheckedChange }: Prefer
}

export function Desktop() {
const params = useParams()
const pathname = usePathname()
const router = useRouter()
const workspaceId = params.workspaceId as string
const [preferences, setPreferences] = useState<DesktopPreferences | null>(null)
const [pendingPreference, setPendingPreference] = useState<DesktopPreferenceKey | null>(null)
/** Whether Sim runs chats on this device in the background; only then can sleep matter. */
Expand All @@ -47,7 +46,8 @@ export function Desktop() {
useEffect(() => {
const bridge = getDesktopBridge()
if (!bridge) {
router.replace(`/workspace/${workspaceId}/settings/general`)
// Workspace and organization settings both end in /desktop beside /general.
router.replace(pathname.replace(/\/desktop$/, '/general'))
return
}
void bridge.settings
Expand All @@ -59,7 +59,7 @@ export function Desktop() {
.then((device) => setRunsInBackground(device !== null))
.catch(() => setRunsInBackground(false))
return bridge.settings.onFullFileAccessChanged?.(setPreferences)
}, [router, workspaceId])
}, [router, pathname])

const updatePreference = async (key: DesktopPreferenceKey, value: boolean) => {
const settings = getDesktopBridge()?.settings
Expand Down
6 changes: 6 additions & 0 deletions apps/sim/components/settings/account-settings-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const Admin = dynamic(() =>
(module) => module.Admin
)
)
const Desktop = dynamic(() =>
import('@/app/workspace/[workspaceId]/settings/components/desktop/desktop').then(
(module) => module.Desktop
)
)
const Mothership = dynamic(() =>
import('@/app/workspace/[workspaceId]/settings/components/mothership/mothership').then(
(module) => module.Mothership
Expand All @@ -34,6 +39,7 @@ export function AccountSettingsRenderer({ section }: AccountSettingsRendererProp
useCaptureWhenReady('settings_tab_viewed', { plane: 'account', section }, section)

if (section === 'general') return <General />
if (section === 'desktop') return <Desktop />
if (section === 'billing') return <Billing scope='account' />
if (section === 'api-keys') return <ApiKeys scope='personal' />
if (section === 'admin') return <Admin />
Expand Down
10 changes: 9 additions & 1 deletion apps/sim/components/settings/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ import { organizationRoutes } from '@/lib/navigation/paths'

export type SettingsPlane = 'account' | 'selfhost' | 'workspace'

export type AccountSettingsSection = 'general' | 'billing' | 'api-keys' | 'admin' | 'mothership'
export type AccountSettingsSection =
| 'general'
| 'desktop'
| 'billing'
| 'api-keys'
| 'admin'
| 'mothership'

/**
* Settings a self-hoster needs from the managed service: their profile, what
Expand Down Expand Up @@ -363,6 +369,8 @@ export const SETTINGS_SECTION_REGISTRY: readonly SettingsSectionRegistryEntry[]
order: 2,
requiresDesktopSurface: 'settings',
},
/** Device settings, not workspace data, so surfaces without a workspace host them too. */
planes: { account: { id: 'desktop', group: 'account', order: 1 } },
},
{
label: 'Browser',
Expand Down
4 changes: 4 additions & 0 deletions apps/sim/components/settings/standalone-settings-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import { SettingsPendingSection } from '@/components/settings/settings-pending-s
import { SettingsSidebar } from '@/components/settings/settings-sidebar'
import type { DeploymentShape } from '@/lib/api/contracts/workspaces'
import { useDeploymentShape } from '@/lib/core/config/deployment-shape'
import { hasDesktopSettings } from '@/lib/desktop'
import { SIDEBAR_NO_MOTION_CLASS } from '@/app/workspace/[workspaceId]/w/components/sidebar/constants'
import { useHydrated } from '@/hooks/use-hydrated'
import { useSeedDeploymentShape } from '@/hooks/use-seed-deployment-shape'
import { useSidebarWidth } from '@/hooks/use-sidebar-width'

Expand Down Expand Up @@ -59,7 +61,9 @@ export function StandaloneSettingsShell(props: StandaloneSettingsShellProps) {

useSidebarWidth()

const desktopSettings = useHydrated() && hasDesktopSettings()
const accountItems = ACCOUNT_SETTINGS_ITEMS.filter((item) => {
if (item.id === 'desktop' && !desktopSettings) return false
if (item.id === 'billing' && !billingEnabled) return false
if ((item.id === 'admin' || item.id === 'mothership') && !isSuperUser) return false
return true
Expand Down
Loading