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
91 changes: 91 additions & 0 deletions browser_tests/tests/agent/agentPanelLifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,97 @@ test.describe(
await expect(page.getByTestId('integrated-tab-bar-actions')).toBeVisible()
})

test('shrinks a maximized panel to stay inside a narrowed window', async ({
page
}) => {
await page.setViewportSize({ width: 1600, height: 900 })
await bootAgentApp(page, true)

await page
.getByRole('button', { name: OPEN_AGENT_LABEL, exact: true })
.click()
const panel = page.getByTestId('docked-agent-panel')
await expect(panel).toBeVisible()

await panel
.getByRole('button', { name: enMessages.agent.maximize })
.click()
await expect
.poll(async () => (await panel.boundingBox())?.width ?? 0)
.toBe(960)

await page.setViewportSize({ width: 900, height: 900 })

await expect
.poll(async () => (await panel.boundingBox())?.width ?? 0)
.toBeLessThan(960)
const box = await panel.boundingBox()
expect(box).not.toBeNull()
expect(box!.x).toBeGreaterThanOrEqual(-1)
expect(box!.x + box!.width).toBeLessThanOrEqual(901)

// "Inside the window" is not enough on its own: a panel that ignored the
// sidebar and took all 900px would satisfy every bound above. Pin it
// against the workspace it is supposed to be reserving room for.
const sideToolbar = page.getByTestId('side-toolbar')
const railBox = await sideToolbar.boundingBox()
expect(railBox).not.toBeNull()
expect(box!.x).toBeGreaterThanOrEqual(railBox!.x + railBox!.width - 1)

// Still maximized, so the header offers to minimize rather than maximize.
await expect(
panel.getByRole('button', { name: enMessages.agent.minimize })
).toBeVisible()
})

test('keeps the canvas toolbar clear of the sidebar as the panel squeezes it', async ({
page
}) => {
// 1300 puts the canvas at roughly 284px: narrower than the toolbar, so
// the overhang this fix prevents is actually in play, but not the
// degenerate case. At 900 a maximized panel leaves the canvas at zero
// and the toolbar collapses to 8px, which tests the unreserved-canvas
// gap rather than this fix. `agentPanelViewportDrag.spec.ts` owns that.
await page.setViewportSize({ width: 1300, height: 900 })
await bootAgentApp(page, true)

await page
.getByRole('button', { name: OPEN_AGENT_LABEL, exact: true })
.click()
const panel = page.getByTestId('docked-agent-panel')
await expect(panel).toBeVisible()
await panel
.getByRole('button', { name: enMessages.agent.maximize })
.click()

const toolbar = page.getByRole('toolbar', {
name: enMessages.graphCanvasMenu.canvasToolbar
})
const sideToolbar = page.getByTestId('side-toolbar')
await expect(toolbar).toBeVisible()

const toolbarBox = await toolbar.boundingBox()
const sideToolbarBox = await sideToolbar.boundingBox()
expect(toolbarBox).not.toBeNull()
expect(sideToolbarBox).not.toBeNull()

// Both edges matter. Checking only the left edge passes a toolbar that
// overhangs the other way, out from under the canvas and beneath the
// expanded panel, which is the case this fix is actually about.
expect(toolbarBox!.x).toBeGreaterThanOrEqual(
sideToolbarBox!.x + sideToolbarBox!.width - 1
)
// Position alone is satisfied by a toolbar squeezed to nothing, so prove
// the controls at both ends survived and are still operable.
expect(toolbarBox!.width).toBeGreaterThan(64)
await expect(
toolbar.getByRole('button', { name: enMessages.zoomControls.label })
).toBeVisible()
await toolbar
.getByRole('button', { name: enMessages.graphCanvasMenu.fitView })
.click()
})

test('restores an open panel after a browser reload', async ({ page }) => {
await bootAgentApp(page, true)

Expand Down
43 changes: 42 additions & 1 deletion src/components/LiteGraphCanvasSplitterOverlay.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTestingPinia } from '@pinia/testing'
import { render, screen } from '@testing-library/vue'
import { readFileSync } from 'fs'
import { setActivePinia } from 'pinia'
import { getActivePinia, setActivePinia } from 'pinia'
import { resolve } from 'path'
import { describe, expect, it, vi } from 'vitest'
import { nextTick } from 'vue'
Expand All @@ -12,7 +12,12 @@ import { useSettingStore } from '@/platform/settings/settingStore'
import { useAgentNodeSelectionStore } from '@/stores/agentNodeSelectionStore'
import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore'
import { useBottomPanelStore } from '@/stores/workspace/bottomPanelStore'
import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore'
import type { SidebarTabExtension } from '@/types/extensionTypes'

// This branch stubs the auth store directly rather than mocking `firebase/auth`
// the way main does, so the incoming `vi.mock(import('firebase/auth'))` is
// dropped and the existing stub kept.
vi.mock('@/stores/authStore', () => ({
useAuthStore: vi.fn(() => ({ currentUser: null, loading: false }))
}))
Expand Down Expand Up @@ -120,6 +125,42 @@ describe('LiteGraphCanvasSplitterOverlay', () => {

expect(screen.getByTestId('topmenu')).toBeInTheDocument()
})
it('reserves room for the sidebar so the Agent panel stops before it', async () => {
const agentPanelStore = useAgentPanelStore()
const sidebarTabStore = useSidebarTabStore()
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: { en: { sideToolbar: { sidebar: 'Sidebar' } } }
})

render(LiteGraphCanvasSplitterOverlay, {
global: {
plugins: [getActivePinia()!, i18n],
stubs: { Splitter: true, SplitterPanel: true }
}
})

window.innerWidth = 1200
window.dispatchEvent(new Event('resize'))
agentPanelStore.toggleMaximize()
await nextTick()
const widthWithoutSidebar = agentPanelStore.width

sidebarTabStore.sidebarTabs = [
{ id: 'probe', title: 'Probe' } as SidebarTabExtension
]
sidebarTabStore.activeSidebarTabId = 'probe'
await nextTick()

expect(agentPanelStore.width).toBeLessThan(widthWithoutSidebar)

sidebarTabStore.activeSidebarTabId = null
await nextTick()

expect(agentPanelStore.width).toBe(widthWithoutSidebar)
})

it('refreshes the splitter only when the Agent panel becomes visible', async () => {
const agentPanelStore = useAgentPanelStore()
agentPanelStore.enabled = true
Expand Down
23 changes: 21 additions & 2 deletions src/components/LiteGraphCanvasSplitterOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,17 @@ import { storeToRefs } from 'pinia'
import Splitter from 'primevue/splitter'
import type { SplitterResizeStartEvent } from 'primevue/splitter'
import SplitterPanel from 'primevue/splitterpanel'
import { computed } from 'vue'
import { computed, watchEffect } from 'vue'
import { useI18n } from 'vue-i18n'

import { useAppMode } from '@/composables/useAppMode'
import {
BUILDER_MIN_SIZE,
CENTER_PANEL_SIZE,
SIDEBAR_MIN_SIZE,
SIDE_PANEL_SIZE
SIDEBAR_MIN_WIDTH,
SIDE_PANEL_SIZE,
SIDE_TOOLBAR_WIDTH
} from '@/constants/splitterConstants'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useAgentNodeSelectionStore } from '@/stores/agentNodeSelectionStore'
Expand Down Expand Up @@ -223,6 +225,23 @@ const sidebarPanelVisible = computed(
() => activeSidebarTab.value !== null && !isBuilderMode.value
)

/**
* The sidebar can never be squeezed past `min-w-78`, so it and the toolbar
* rail are the floor the agent panel has to respect. Feeding the floor rather
* than the sidebar's live width keeps this one-way: a panel that shrank would
* otherwise widen the sidebar and shrink itself again.
*/
watchEffect(() => {
agentPanelStore.setReservedWorkspaceWidth(
SIDE_TOOLBAR_WIDTH +
(sidebarPanelVisible.value &&
!focusMode.value &&
!agentNodeSelectionActive.value
? SIDEBAR_MIN_WIDTH
: 0)
)
})

const firstPanelVisible = computed(
() => sidebarLocation.value === 'left' || showOffsideSplitter.value
)
Expand Down
150 changes: 78 additions & 72 deletions src/components/graph/GraphCanvasMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,80 +9,86 @@
@click="hideModal"
></div>

<ButtonGroup
role="toolbar"
:aria-label="t('graphCanvasMenu.canvasToolbar')"
class="absolute right-0 bottom-0 z-1200 flex-row gap-1 border border-interface-stroke bg-comfy-menu-bg p-2"
:style="{
...stringifiedMinimapStyles.buttonGroupStyles
}"
@wheel="canvasInteractions.handleWheel"
>
<CanvasModeSelector
:button-styles="stringifiedMinimapStyles.buttonStyles"
/>

<div class="h-[27px] w-px self-center bg-node-divider" />

<Button
v-tooltip.top="fitViewTooltip"
variant="secondary"
:aria-label="fitViewTooltip"
:style="stringifiedMinimapStyles.buttonStyles"
class="size-8 bg-comfy-menu-bg p-0 hover:bg-interface-button-hover-surface!"
@click="() => commandStore.execute('Comfy.Canvas.FitView')"
>
<i class="icon-[lucide--focus] size-4" aria-hidden="true" />
</Button>

<Button
v-tooltip.top="t('zoomControls.label')"
variant="secondary"
:class="zoomButtonClass"
:aria-label="t('zoomControls.label')"
data-testid="zoom-controls-button"
:style="stringifiedMinimapStyles.buttonStyles"
@click="toggleModal"
>
<span class="inline-flex items-center gap-1 px-2 text-xs">
<span>{{ canvasStore.appScalePercentage }}%</span>
<i class="icon-[lucide--chevron-down] size-4" aria-hidden="true" />
</span>
</Button>

<div class="h-[27px] w-px self-center bg-node-divider" />

<Button
v-tooltip.top="minimapTooltip"
variant="secondary"
:aria-label="minimapTooltip"
data-testid="toggle-minimap-button"
:style="stringifiedMinimapStyles.buttonStyles"
:class="minimapButtonClass"
@click="onMinimapToggleClick"
>
<i class="icon-[lucide--map] size-4" aria-hidden="true" />
</Button>

<Button
v-tooltip.top="{
value: linkVisibilityTooltip,
pt: {
root: {
style: 'z-index: 2; transform: translateY(-20px);'
}
}
<!-- Right-anchoring alone lets a toolbar wider than the canvas overhang its
left edge and cover the sidebar. Spanning the canvas and pushing with an
auto margin pins the toolbar to the right instead, and the width cap keeps
any overflow inside the canvas as a scroll. -->
<div class="pointer-events-none absolute inset-x-0 bottom-0 z-1200 flex">
<ButtonGroup
role="toolbar"
:aria-label="t('graphCanvasMenu.canvasToolbar')"
class="pointer-events-auto ml-auto max-w-full min-w-0 flex-row gap-1 overflow-x-auto border border-interface-stroke bg-comfy-menu-bg p-2"
:style="{
...stringifiedMinimapStyles.buttonGroupStyles
}"
variant="secondary"
:class="linkVisibleClass"
:aria-label="linkVisibilityAriaLabel"
data-testid="toggle-link-visibility-button"
:style="stringifiedMinimapStyles.buttonStyles"
@click="onLinkVisibilityToggleClick"
@wheel="canvasInteractions.handleWheel"
>
<i class="icon-[lucide--route-off] size-4" aria-hidden="true" />
</Button>
</ButtonGroup>
<CanvasModeSelector
:button-styles="stringifiedMinimapStyles.buttonStyles"
/>

<div class="h-[27px] w-px self-center bg-node-divider" />

<Button
v-tooltip.top="fitViewTooltip"
variant="secondary"
:aria-label="fitViewTooltip"
:style="stringifiedMinimapStyles.buttonStyles"
class="size-8 bg-comfy-menu-bg p-0 hover:bg-interface-button-hover-surface!"
@click="() => commandStore.execute('Comfy.Canvas.FitView')"
>
<i class="icon-[lucide--focus] size-4" aria-hidden="true" />
</Button>

<Button
v-tooltip.top="t('zoomControls.label')"
variant="secondary"
:class="zoomButtonClass"
:aria-label="t('zoomControls.label')"
data-testid="zoom-controls-button"
:style="stringifiedMinimapStyles.buttonStyles"
@click="toggleModal"
>
<span class="inline-flex items-center gap-1 px-2 text-xs">
<span>{{ canvasStore.appScalePercentage }}%</span>
<i class="icon-[lucide--chevron-down] size-4" aria-hidden="true" />
</span>
</Button>

<div class="h-[27px] w-px self-center bg-node-divider" />

<Button
v-tooltip.top="minimapTooltip"
variant="secondary"
:aria-label="minimapTooltip"
data-testid="toggle-minimap-button"
:style="stringifiedMinimapStyles.buttonStyles"
:class="minimapButtonClass"
@click="onMinimapToggleClick"
>
<i class="icon-[lucide--map] size-4" aria-hidden="true" />
</Button>

<Button
v-tooltip.top="{
value: linkVisibilityTooltip,
pt: {
root: {
style: 'z-index: 2; transform: translateY(-20px);'
}
}
}"
variant="secondary"
:class="linkVisibleClass"
:aria-label="linkVisibilityAriaLabel"
data-testid="toggle-link-visibility-button"
:style="stringifiedMinimapStyles.buttonStyles"
@click="onLinkVisibilityToggleClick"
>
<i class="icon-[lucide--route-off] size-4" aria-hidden="true" />
</Button>
</ButtonGroup>
</div>
</div>
</template>

Expand Down
9 changes: 9 additions & 0 deletions src/constants/splitterConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ export const SIDEBAR_MIN_SIZE = 10

/** Minimum panel size (%) for the builder panel */
export const BUILDER_MIN_SIZE = 15

/** Minimum sidebar panel width (px). The twin of `min-w-78` on `.side-bar-panel`. */
export const SIDEBAR_MIN_WIDTH = 312

/**
* Width (px) of the side toolbar rail: `--sidebar-default-floating-width` plus
* `--sidebar-padding` on each side, which is the wider connected variant.
*/
export const SIDE_TOOLBAR_WIDTH = 56
Loading
Loading