Skip to content
Open
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
16 changes: 12 additions & 4 deletions e2e/workspace-switch-no-browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { captureHostWindow } from './support/windowCapture'
const UNAVAILABLE_COPY = en.devPlatform.workspace.switchUnavailable
const RETRYABLE_COPY = en.devPlatform.workspace.switchRetryable
const FAILURE_CAPTION = '[data-testid="chooser-workspace-switch-failure"]'
const SELECTOR = '[data-testid="devplatform-workspace-selector"]'
const SELECTOR = '[data-testid="workspace-switcher-trigger"]'
const SWITCH = '[data-testid="workspace-switch-action"]'
const REFRESH = '[data-testid="chooser-workspace-refresh"]'
const SIGN_IN = '[data-testid="devplatform-account-signin"]'
const SETTLE_MS = 1_500
Expand Down Expand Up @@ -62,7 +63,13 @@ async function expectActive(workspaceId: string): Promise<void> {

async function expectSelected(workspaceId: string): Promise<void> {
await expect
.poll(() => panel().textOf(`${SELECTOR} .workspace-selector__name`), { timeout: 15_000 })
.poll(
() =>
panel().evaluate<string | null>(
`document.querySelector('${SELECTOR}')?.getAttribute('aria-label') ?? null`
),
{ timeout: 15_000 }
)
.toBe(`Workspace ${workspaceId}`)
}

Expand All @@ -71,9 +78,10 @@ async function expectBuildsFrom(workspaceId: string): Promise<void> {
}

async function select(workspaceId: string): Promise<void> {
const item = `[data-testid="devplatform-workspace-${workspaceId}"]`
const item = `[data-testid="workspace-option-${workspaceId}"]`
await panel().waitForVisible(SELECTOR)
await panel().clickUntilVisible(SELECTOR, item)
await panel().clickUntilVisible(SELECTOR, SWITCH)
await panel().clickUntilVisible(SWITCH, item)
expect(await panel().click(item), `selected ${workspaceId}`).toBe(true)
}

Expand Down
23 changes: 20 additions & 3 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1547,16 +1547,13 @@
"cta": "Log in"
},
"account": {
"signOut": "Sign out",
"signedInAs": "Signed in as {email}",
"installationInProgressTitle": "Installation in progress",
"installationInProgressMessage": "Signing out will cancel the installation. Do you want to cancel the installation and sign out?",
"cancelInstallationAndSignOut": "Cancel Installation & Sign Out"
},
"workspace": {
"personalLabel": "Personal",
"switchLabel": "Workspace",
"currentFallback": "Current workspace",
"switchUnavailable": "This workspace is unavailable.",
"switchRetryable": "Couldn't switch workspace. Check your connection and try again.",
"instanceCountLabel": "INSTANCES",
Expand All @@ -1569,6 +1566,26 @@
"promoteFailedTitle": "Could not upload build",
"promoteFailedMessage": "Could not create a draft in Comfy Developer Platform."
},
"workspaceMenu": {
"switchWorkspace": "Switch workspace",
"workspaceSettings": "Workspace settings",
"managePlanAndCredits": "Manage plan & credits",
"logOut": "Log Out",
"plan": {
"FREE": "Free",
"STANDARD": "Standard",
"CREATOR": "Creator",
"PRO": "Pro",
"FOUNDERS_EDITION": "Founders",
"TEAM": "Team",
"ENTERPRISE": "Enterprise"
},
"role": {
"owner": "Owner",
"admin": "Admin",
"member": "Member"
}
},
"build": {
"version": "Build v{version}",
"loadError": "Couldn't load builds. Retry"
Expand Down
23 changes: 20 additions & 3 deletions locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1547,16 +1547,13 @@
"cta": "登录"
},
"account": {
"signOut": "退出登录",
"signedInAs": "已登录为 {email}",
"installationInProgressTitle": "安装正在进行中",
"installationInProgressMessage": "退出登录将取消安装。是否取消安装并退出登录?",
"cancelInstallationAndSignOut": "取消安装并退出登录"
},
"workspace": {
"personalLabel": "个人",
"switchLabel": "工作区",
"currentFallback": "当前工作区",
"switchUnavailable": "此工作区不可用。",
"switchRetryable": "无法切换工作区。请检查网络连接后重试。",
"instanceCountLabel": "实例",
Expand All @@ -1569,6 +1566,26 @@
"promoteFailedTitle": "无法上传构建",
"promoteFailedMessage": "无法在 Comfy Developer Platform 中创建草稿。"
},
"workspaceMenu": {
"switchWorkspace": "切换工作区",
"workspaceSettings": "工作区设置",
"managePlanAndCredits": "管理套餐和积分",
"logOut": "退出登录",
"plan": {
"FREE": "免费版",
"STANDARD": "标准版",
"CREATOR": "创作者版",
"PRO": "专业版",
"FOUNDERS_EDITION": "创始版",
"TEAM": "团队版",
"ENTERPRISE": "企业版"
},
"role": {
"owner": "所有者",
"admin": "管理员",
"member": "成员"
}
},
"build": {
"version": "构建 v{version}",
"loadError": "无法加载构建,请重试"
Expand Down
2 changes: 1 addition & 1 deletion src/main/cloud/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface Workspace {
name: string
type: string
role: string
subscriptionTier?: string
subscriptionTier?: string | null
createdAt?: string
joinedAt?: string
}
Expand Down
32 changes: 32 additions & 0 deletions src/main/cloud/workspaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@ describe('listWorkspaces', () => {
])
})

it('keeps a null plan apart from a missing one, so the avatar can tell Free from unknown', async () => {
stub(200, {
workspaces: [
{ id: 'w-1', name: 'Personal', type: 'personal', role: 'owner', subscription_tier: null },
{ id: 'w-2', name: 'Team', type: 'team', role: 'member' }
]
})
const ws = await listWorkspaces('tok', { apiBase: 'https://cloud/api' })
expect(ws).toEqual([
{ id: 'w-1', name: 'Personal', type: 'personal', role: 'owner', subscriptionTier: null },
{ id: 'w-2', name: 'Team', type: 'team', role: 'member' }
])
})

it('drops an empty or non-text plan, so it reads as unknown', async () => {
stub(200, {
workspaces: [
{ id: 'w-1', name: 'One', type: 'team', role: 'owner', subscription_tier: 7 },
{ id: 'w-2', name: 'Two', type: 'team', role: 'owner', subscription_tier: { tier: 'PRO' } },
{ id: 'w-3', name: 'Three', type: 'team', role: 'owner', subscription_tier: ['PRO'] },
{ id: 'w-4', name: 'Four', type: 'team', role: 'owner', subscription_tier: '' }
]
})
const ws = await listWorkspaces('tok', { apiBase: 'https://cloud/api' })
expect(ws.map((workspace) => 'subscriptionTier' in workspace)).toEqual([
false,
false,
false,
false
])
})

it.each([
{ status: 404, body: {}, error: /HTTP 404/ },
{ status: 401, body: {}, error: /authorized/i },
Expand Down
8 changes: 6 additions & 2 deletions src/main/cloud/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface WorkspaceRow {
name: string
type: string
role: string
subscription_tier?: string
subscription_tier?: unknown
created_at?: string
joined_at?: string
}
Expand All @@ -32,6 +32,10 @@ interface WorkspaceMembersResponse {
pagination?: { has_more?: boolean }
}

function isPlanTier(value: unknown): value is string | null {
return value === null || (typeof value === 'string' && value !== '')
}

function isWorkspaceRow(value: unknown): value is WorkspaceRow {
if (!value || typeof value !== 'object') return false
const row = value as Partial<WorkspaceRow>
Expand Down Expand Up @@ -66,7 +70,7 @@ export async function listWorkspaces(
name: w.name,
type: w.type,
role: w.role,
...(w.subscription_tier ? { subscriptionTier: w.subscription_tier } : {}),
...(isPlanTier(w.subscription_tier) ? { subscriptionTier: w.subscription_tier } : {}),
...(w.created_at ? { createdAt: w.created_at } : {}),
...(w.joined_at ? { joinedAt: w.joined_at } : {})
}))
Expand Down
8 changes: 8 additions & 0 deletions src/main/devplatform/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ export const BUILDER_BASE_URL = process.env.COMFY_BUILDER_BASE_URL || PROD_BUILD

export const PLATFORM_WEB_BASE_URL =
process.env.COMFY_PLATFORM_WEB_BASE_URL || PROD_PLATFORM_WEB_BASE_URL

export const PLATFORM_SETTINGS_PATHS = {
general: '/settings/general',
people: '/settings/people',
billing: '/settings/billing'
} as const

export type PlatformSettingsPage = keyof typeof PLATFORM_SETTINGS_PATHS
26 changes: 26 additions & 0 deletions src/main/lib/ipc/registerDevPlatformHandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@ describe('registerDevPlatformHandlers', () => {
)
})

it.each([
['general', 'https://platform.comfy.org/settings/general?workspace=w1'],
['people', 'https://platform.comfy.org/settings/people?workspace=w1'],
['billing', 'https://platform.comfy.org/settings/billing?workspace=w1']
])('opens the Platform %s settings page for the workspace', async (page, url) => {
await handler('comfybuilder:openSettingsPage')({}, page, 'w1')

expect(mocks.openExternal).toHaveBeenCalledExactlyOnceWith(url)
})

it('rejects a missing workspace instead of opening an unscoped settings page', async () => {
await expect(handler('comfybuilder:openSettingsPage')({}, 'billing', '')).rejects.toThrow(
'A workspace is required to open Developer Platform settings.'
)

expect(mocks.openExternal).not.toHaveBeenCalled()
})

it('refuses a settings page Platform does not have', async () => {
await expect(handler('comfybuilder:openSettingsPage')({}, 'constructor', 'w1')).rejects.toThrow(
'Unknown Developer Platform settings page.'
)

expect(mocks.openExternal).not.toHaveBeenCalled()
})

it('rejects a missing workspace instead of opening an unscoped Builds page', async () => {
await expect(handler('comfybuilder:openBuildsPage')({}, '')).rejects.toThrow(
'A workspace is required to open Builds.'
Expand Down
21 changes: 20 additions & 1 deletion src/main/lib/ipc/registerDevPlatformHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getViewWorkspaceGrants } from '../viewWorkspaceGrants'
import { openExternalUrl } from '../openExternal'
import { openSystemModalAsync } from '../../popups/systemModal'
import { normalizeSha256 } from '../../comfybuilder/integrity'
import { PLATFORM_WEB_BASE_URL } from '../../devplatform/config'
import { PLATFORM_SETTINGS_PATHS, PLATFORM_WEB_BASE_URL } from '../../devplatform/config'
import {
getBuilderClient,
getCloudSession,
Expand Down Expand Up @@ -59,6 +59,7 @@ export const DEVPLATFORM_CHANNELS = {
switchWorkspace: 'comfybuilder:switchWorkspace',
listBuilds: 'comfybuilder:listBuilds',
openBuildsPage: 'comfybuilder:openBuildsPage',
openSettingsPage: 'comfybuilder:openSettingsPage',
installBuild: 'comfybuilder:installBuild',
promoteLocalInstance: 'comfybuilder:promoteLocalInstance'
} as const
Expand Down Expand Up @@ -228,6 +229,24 @@ export function registerDevPlatformHandlers(): void {
}
)

ipcMain.handle(
DEVPLATFORM_CHANNELS.openSettingsPage,
async (_event, page: unknown, workspaceId: unknown): Promise<void> => {
if (typeof page !== 'string' || !Object.hasOwn(PLATFORM_SETTINGS_PATHS, page)) {
throw new Error('Unknown Developer Platform settings page.')
}
const url = new URL(
PLATFORM_SETTINGS_PATHS[page as keyof typeof PLATFORM_SETTINGS_PATHS],
PLATFORM_WEB_BASE_URL
)
if (typeof workspaceId !== 'string' || workspaceId.trim().length === 0) {
throw new Error('A workspace is required to open Developer Platform settings.')
}
url.searchParams.set('workspace', workspaceId)
await openExternalUrl(url.toString())
}
)

ipcMain.handle(
DEVPLATFORM_CHANNELS.switchWorkspace,
async (_event, workspaceId: string, intent?: WorkspaceSwitchIntent) => {
Expand Down
2 changes: 2 additions & 0 deletions src/preload/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ export function buildElectronApi(): ElectronApi {
listBuilds: () => ipcRenderer.invoke('comfybuilder:listBuilds'),
openBuildsPage: (workspaceId) =>
ipcRenderer.invoke('comfybuilder:openBuildsPage', workspaceId),
openSettingsPage: (page, workspaceId) =>
ipcRenderer.invoke('comfybuilder:openSettingsPage', page, workspaceId),
installBuild: (request) => ipcRenderer.invoke('comfybuilder:installBuild', request),
promoteLocalInstance: (installationId) =>
ipcRenderer.invoke('comfybuilder:promoteLocalInstance', installationId)
Expand Down
32 changes: 32 additions & 0 deletions src/renderer/src/components/WorkspaceAvatar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'

import WorkspaceAvatar from './WorkspaceAvatar.vue'

function initialOf(workspaceName: string): string {
return mount(WorkspaceAvatar, { props: { workspaceName, subscriptionTier: null } }).text()
}

describe('WorkspaceAvatar', () => {
it('shows the first letter of the name in upper case', () => {
expect(initialOf('harbor')).toBe('H')
})

it('skips leading spaces', () => {
expect(initialOf(' harbor')).toBe('H')
})

it('keeps a whole emoji or accented letter', () => {
expect(initialOf('🇩🇪 Berlin')).toBe('🇩🇪')
expect(initialOf('👩‍💻 Studio')).toBe('👩‍💻')
expect(initialOf('école')).toBe('É')
})

it('keeps a letter whose upper case is two letters', () => {
expect(initialOf('ßtudio')).toBe('ß')
})

it('shows a question mark for a blank name', () => {
expect(initialOf(' ')).toBe('?')
})
})
41 changes: 41 additions & 0 deletions src/renderer/src/components/WorkspaceAvatar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script setup lang="ts">
import { computed } from 'vue'
import { workspaceAvatarStyle } from '@comfyorg/design-system/workspaceAvatar'

const {
workspaceName,
subscriptionTier,
size = 'md'
} = defineProps<{
workspaceName: string
subscriptionTier: string | null | undefined
size?: 'sm' | 'md'
}>()

const graphemes = new Intl.Segmenter()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Nit — new Intl.Segmenter() is constructed inside <script setup>, so every avatar instance builds its own segmenter; with one avatar per workspace row plus the trigger and submenu header this is avoidable allocation. Hoist it to module scope. Raised by 1 of 8 reviewers (gemini-3.1-pro adversarial).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: there are only a few avatars per menu, and hoisting needs a second script block. That costs more code than the allocation it saves.


function firstGrapheme(text: string): string | undefined {
return graphemes.segment(text.trim())[Symbol.iterator]().next().value?.segment
}

function initialOf(name: string): string {
const first = firstGrapheme(name)
if (!first) return '?'
const upper = first.toUpperCase()
return firstGrapheme(upper) === upper ? upper : first
}

const initial = computed(() => initialOf(workspaceName))
const avatarStyle = computed(() => workspaceAvatarStyle(workspaceName, subscriptionTier))
</script>

<template>
<span
class="inline-flex shrink-0 items-center justify-center bg-card font-semibold text-foreground"
:class="size === 'sm' ? 'size-6 rounded-sm text-xs' : 'size-8 rounded-md text-sm'"
:style="avatarStyle"
data-testid="workspace-avatar"
aria-hidden="true"
>{{ initial }}</span
>
</template>
Loading
Loading