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
5 changes: 3 additions & 2 deletions packages/dashboard/src/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ export const Dashboard: React.FC<DashboardProps> = ({ model }) => {
}

const overlayText = selectedTab ? undefined : 'Select a session';
const modeLabel = annotating ? 'Dashboard: annotate' : recording ? 'Dashboard: record' : 'Dashboard';

return (
<div className={'dashboard-view' + (interactive ? ' interactive' : '') + (annotating ? ' annotate' : '') + (recording ? ' recording' : '')}>
<main className={'dashboard-view' + (interactive ? ' interactive' : '') + (annotating ? ' annotate' : '') + (recording ? ' recording' : '')} aria-label={modeLabel}>
{/* Toolbar */}
<div ref={toolbarRef} className='toolbar'>
{annotating ? (
Expand Down Expand Up @@ -468,6 +469,6 @@ export const Dashboard: React.FC<DashboardProps> = ({ model }) => {
)}
</div>
</div>
</div>
</main>
);
};
41 changes: 10 additions & 31 deletions packages/dashboard/src/sessionSidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -214,39 +214,32 @@
background: var(--color-neutral-muted);
}

.sidebar-tab-list {
padding: 0;
display: flex;
flex-direction: column;
gap: 0;
}

.sidebar-tabs-loading,
.sidebar-tabs-empty {
.sidebar-tabs-loading {
color: var(--color-fg-subtle);
font-size: 12px;
padding: 4px 12px 6px 38px;
margin: 0;
flex: none;
display: block;
justify-content: flex-start;
text-align: left;
}

.sidebar-tab {
.sidebar-session .list-view-entry {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: var(--color-fg-muted);
border-radius: 0;
padding: 4px 4px 4px 24px;
line-height: 1.4;
}

.sidebar-tab:hover {
.sidebar-session .list-view-entry:hover {
background: var(--color-neutral-muted);
}

.sidebar-tab.active {
background: var(--color-neutral-subtle);
color: var(--color-fg-default);
}

.sidebar-tab-favicon {
width: 14px;
height: 14px;
Expand All @@ -255,20 +248,6 @@
align-self: center;
}

.sidebar-tab-select {
display: flex;
align-items: center;
gap: 6px;
flex: 1;
min-width: 0;
cursor: pointer;
}

.sidebar-tab-select:focus-visible {
outline: 1px solid var(--color-accent-emphasis);
outline-offset: 2px;
}

.sidebar-tab-favicon.placeholder {
border-radius: 2px;
background: var(--color-fg-subtle);
Expand Down Expand Up @@ -313,7 +292,7 @@
transition: opacity 120ms ease;
}

.sidebar-tab:hover .sidebar-tab-close,
.sidebar-session .list-view-entry:hover .sidebar-tab-close,
.sidebar-tab-close:focus-visible {
opacity: 1;
pointer-events: auto;
Expand Down
165 changes: 82 additions & 83 deletions packages/dashboard/src/sessionSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import './sessionSidebar.css';
import { SettingsButton } from './settingsView';
import { BrowserIcon } from './icons';
import { ToolbarButton } from '@web/components/toolbarButton';
import { ListView } from '@web/components/listView';

import type { SessionStatus, Tab } from './dashboardChannel';
import type { DashboardModel } from './dashboardModel';
Expand All @@ -27,6 +28,8 @@ type SessionSidebarProps = {
model: DashboardModel;
};

const TabListView = ListView<Tab>;

function tabFavicon(url: string): string {
try {
const u = new URL(url);
Expand All @@ -52,6 +55,27 @@ function normalizeWorkspacePath(workspace: string, homeDir: string | undefined):
return normalized;
}

const TabRow: React.FC<{ tab: Tab; model: DashboardModel }> = ({ tab, model }) => {
return <>
{tab.faviconUrl
? <img className='sidebar-tab-favicon' src={tab.faviconUrl} alt='' aria-hidden='true' />
: <span className='sidebar-tab-favicon placeholder' aria-hidden='true'>{tabFavicon(tab.url)}</span>}
<span className='sidebar-tab-text'>
<span className='sidebar-tab-title'>{tab.title || 'New Tab'}</span>
<span className='sidebar-tab-url'>{tab.url || 'about:blank'}</span>
</span>
<ToolbarButton
className='sidebar-tab-close'
icon='close'
title='Close tab'
onClick={e => {
e.stopPropagation();
model.closeTab(tab);
}}
/>
</>;
};

export const SessionSidebar: React.FC<SessionSidebarProps> = ({ model }) => {
const { sessions, clientInfo, loadingSessions, tabs: allTabs } = model.state;
const openSessions = React.useMemo(() => sessions.filter(session => session.canConnect), [sessions]);
Expand Down Expand Up @@ -103,96 +127,71 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({ model }) => {
<SettingsButton />
</div>
<div className='dashboard-shell-sidebar-content'>
{loadingSessions && <div className='sidebar-empty' role='status' aria-live='polite'>Loading sessions...</div>}
{!loadingSessions && openSessions.length === 0 && <div className='sidebar-empty' role='status' aria-live='polite'>No open sessions.</div>}
{loadingSessions && <p className='sidebar-empty' role='status' aria-live='polite'>Loading sessions...</p>}
{!loadingSessions && openSessions.length === 0 && <p className='sidebar-empty' role='status' aria-live='polite'>No open sessions.</p>}
{workspaceGroups.map(([workspace, entries]) => {
const workspacePath = normalizeWorkspacePath(workspace, clientInfo?.homeDir);
return <section key={workspace} className='workspace-group'>
return <section key={workspace} className='workspace-group' aria-label={`Workspace ${workspacePath}`}>
<h3 className='workspace-header'>
<span className='workspace-path-full' title={workspacePath}>{workspacePath}</span>
</h3>
<div className='sidebar-session-list' role='list'>
{entries.map(session => {
const guid = session.browser.guid;
const browserType = session.browser.browserName;
const channel = session.browser.launchOptions?.channel;
const byContext = tabsByBrowserAndContext.get(guid);
const contextEntries = byContext ? [...byContext.entries()] : [];
const rows: { contextGuid: string | null; tabs: Tab[] | undefined }[] =
allTabs === null
? [{ contextGuid: null, tabs: undefined }]
: contextEntries.length === 0
? [{ contextGuid: null, tabs: [] }]
: contextEntries.map(([contextGuid, tabs]) => ({ contextGuid, tabs }));
return <React.Fragment key={guid}>
{rows.map((row, rowIdx) => <div key={row.contextGuid ?? `placeholder-${rowIdx}`} className='session-chip sidebar-session' role='listitem' title={session.title}>
<div className='sidebar-session-row'>
<div className='session-browser-icon-wrap' title={channel || browserType}>
<span className='session-browser-icon' aria-hidden='true'>
<BrowserIcon browserName={browserType} channel={channel} />
</span>
<ToolbarButton
className='session-browser-close'
icon='close'
title='Close session'
onClick={() => model.closeSession(session)}
/>
</div>
<span className='session-chip-name'>{session.title}</span>
<div className='sidebar-session-row-actions'>
{row.contextGuid && <ToolbarButton
className='sidebar-session-new-tab'
icon='add'
title='New tab'
onClick={() => model.newTab(guid, row.contextGuid!)}
/>}
</div>
{entries.map(session => {
const guid = session.browser.guid;
const browserType = session.browser.browserName;
const channel = session.browser.launchOptions?.channel;
const byContext = tabsByBrowserAndContext.get(guid);
const contextEntries = byContext ? [...byContext.entries()] : [];
const rows: { contextGuid: string | null; tabs: Tab[] | undefined }[] =
allTabs === null
? [{ contextGuid: null, tabs: undefined }]
: contextEntries.length === 0
? [{ contextGuid: null, tabs: [] }]
: contextEntries.map(([contextGuid, tabs]) => ({ contextGuid, tabs }));
return rows.map((row, rowIdx) => {
const activeTab = row.tabs?.find(t => t.context === activeContext && t.selected);
const rowKey = `${guid}-${row.contextGuid ?? `placeholder-${rowIdx}`}`;
return <section
key={rowKey}
className={'sidebar-session session-chip' + (activeTab ? ' active' : '')}
aria-label={`Session ${session.title}`}
>
<header className='sidebar-session-row'>
<div className='session-browser-icon-wrap' title={channel || browserType}>
<span className='session-browser-icon' aria-hidden='true'>
<BrowserIcon browserName={browserType} channel={channel} />
</span>
<ToolbarButton
className='session-browser-close'
icon='close'
title='Close session'
onClick={() => model.closeSession(session)}
/>
</div>
<div className='sidebar-tab-list' role='list' aria-label={`${session.title} tabs`}>
{row.tabs === undefined && <div className='sidebar-tabs-loading' role='status' aria-live='polite'>Loading tabs...</div>}
{row.tabs?.length === 0 && <div className='sidebar-tabs-empty' role='status' aria-live='polite'>No tabs open.</div>}
{row.tabs?.map(tab => <div
key={tab.page}
className={'sidebar-tab' + (tab.context === activeContext && tab.selected ? ' active' : '')}
role='listitem'
>
<div
className='sidebar-tab-select'
role='button'
tabIndex={0}
aria-current={tab.context === activeContext && tab.selected ? 'page' : undefined}
title={tab.url || tab.title}
onClick={() => model.selectTab(tab)}
onKeyDown={e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
model.selectTab(tab);
}
}}
>
{tab.faviconUrl
? <img className='sidebar-tab-favicon' src={tab.faviconUrl} alt='' aria-hidden='true' />
: <span className='sidebar-tab-favicon placeholder' aria-hidden='true'>{tabFavicon(tab.url)}</span>}
<span className='sidebar-tab-text'>
<span className='sidebar-tab-title'>{tab.title || 'New Tab'}</span>
<span className='sidebar-tab-url'>{tab.url || 'about:blank'}</span>
</span>
</div>
<ToolbarButton
className='sidebar-tab-close'
icon='close'
title='Close tab'
onClick={e => {
e.stopPropagation();
model.closeTab(tab);
}}
/>
</div>)}
<span className='session-chip-name'>{session.title}</span>
<div className='sidebar-session-row-actions'>
{row.contextGuid && <ToolbarButton
className='sidebar-session-new-tab'
icon='add'
title='New tab'
onClick={() => model.newTab(guid, row.contextGuid!)}
/>}
</div>
</div>)}
</React.Fragment>;
})}
</div>
</header>
{row.tabs === undefined
? <p className='sidebar-tabs-loading' role='status' aria-live='polite'>Loading tabs...</p>
: <TabListView
name={`sidebar-tabs-${rowKey}`}
ariaLabel={`${session.title} tabs`}
items={row.tabs}
id={tab => tab.page}
selectedItem={activeTab}
onSelected={tab => model.selectTab(tab)}
noItemsMessage='No tabs open.'
render={tab => <TabRow tab={tab} model={model} />}
/>}
</section>;
});
})}
</section>;
})}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class DashboardConnection implements Transport {
private _pushTabsScheduled = false;
private _visible = true;
private _pendingReveal: { sessionName: string; workspaceDir?: string } | undefined;
private _annotateWaitingForAttach = false;

_recordingDir: string;
_streams = new Map<string, { handle: fs.promises.FileHandle; path: string }>();
Expand Down Expand Up @@ -286,10 +287,16 @@ export class DashboardConnection implements Transport {
}

emitAnnotate() {
// Defer until a page is attached so the client can fetch a screenshot.
if (!this._attachedPage) {
this._annotateWaitingForAttach = true;
return;
}
this.sendEvent?.('annotate', {});
}

emitCancelAnnotate() {
this._annotateWaitingForAttach = false;
this.sendEvent?.('cancelAnnotate', {});
}

Expand Down Expand Up @@ -349,6 +356,10 @@ export class DashboardConnection implements Transport {
attached.dispose();
throw e;
}
if (this._annotateWaitingForAttach && this._attachedPage === attached) {
this._annotateWaitingForAttach = false;
this.sendEvent?.('annotate', {});
}
}

_handleAttachedPageClose(context: api.BrowserContext) {
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/components/listView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function ListView<T>({
itemListRef.current.scrollTop = scrollPositions.get(name) || 0;
}, [name]);

return <div className={clsx(`list-view vbox`, name + '-list-view')} role={items.length > 0 ? 'list' : undefined} aria-label={ariaLabel}>
return <div className={clsx(`list-view vbox`, name + '-list-view')} role={items.length > 0 ? 'listbox' : undefined} aria-label={ariaLabel}>
<div
className={clsx('list-view-content', notSelectable && 'not-selectable')}
tabIndex={0}
Expand Down Expand Up @@ -126,7 +126,7 @@ export function ListView<T>({
return <div
key={id?.(item, index) || index}
onDoubleClick={() => onAccepted?.(item, index)}
role='listitem'
role='option'
className={clsx(
'list-view-entry',
selectedItem === item && 'selected',
Expand Down
11 changes: 4 additions & 7 deletions tests/config/traceViewerFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class TraceViewerPage {
this.actionTitles = page.locator('.action-title');
this.actionsTree = page.getByTestId('actions-tree');
this.callLines = page.locator('.call-tab .call-line');
this.logLines = page.getByRole('list', { name: 'Log entries' }).getByRole('listitem');
this.consoleLines = page.getByRole('tabpanel', { name: 'Console' }).getByRole('listitem');
this.logLines = page.getByRole('listbox', { name: 'Log entries' }).getByRole('option');
this.consoleLines = page.getByRole('tabpanel', { name: 'Console' }).getByRole('option');
this.consoleLineMessages = page.locator('.console-line-message');
this.errorMessages = page.locator('.error-message');
this.consoleStacks = page.locator('.console-stack');
this.networkRequests = page.getByRole('list', { name: 'Network requests' }).getByRole('listitem');
this.networkRequests = page.getByRole('listbox', { name: 'Network requests' }).getByRole('option');
this.snapshotContainer = page.locator('.snapshot-container iframe.snapshot-visible[name=snapshot]');
this.metadataTab = page.getByRole('tabpanel', { name: 'Metadata' });
this.sourceCodeTab = page.getByRole('tabpanel', { name: 'Source' });
Expand All @@ -84,10 +84,7 @@ class TraceViewerPage {
}

stackFrames(options: { selected?: boolean } = {}) {
const entry = this.page.getByRole('list', { name: 'Stack trace' }).getByRole('listitem');
if (options.selected)
return entry.locator(':scope.selected');
return entry;
return this.page.getByRole('listbox', { name: 'Stack trace' }).getByRole('option', options);
}

actionIconsText(action: string) {
Expand Down
Loading
Loading