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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.root {
display: flex;
min-inline-size: 0;
flex-direction: column;
align-items: flex-start;
gap: var(--openbitfun-space-3);
}

.message {
min-inline-size: 0;
}

.checkbox {
--btw-warning-icon-size: var(--openbitfun-layout-confirm-dialog-icon-glyph-size);
--btw-warning-column-gap: var(--openbitfun-layout-confirm-dialog-message-gap);
--btw-checkbox-control-size: 12px;

/* Center the checkbox control in the warning-icon column while keeping its
label aligned with the confirmation message column. */
align-self: flex-start;
margin-inline-start: calc(
-1 * (var(--btw-warning-icon-size) + var(--btw-warning-column-gap))
+ (var(--btw-warning-icon-size) - var(--btw-checkbox-control-size)) / 2
);
gap: calc(
var(--btw-warning-column-gap)
+ (var(--btw-warning-icon-size) - var(--btw-checkbox-control-size)) / 2
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Checkbox } from '@openbitfun/ui';
import { useI18n } from '@/infrastructure/i18n';
import styles from './BtwCloseConfirmation.module.css';

interface BtwCloseConfirmationProps {
onSkipChange: (skip: boolean) => void;
}

export function BtwCloseConfirmation({ onSkipChange }: BtwCloseConfirmationProps) {
const { t } = useI18n('components');

return (
<div
className={styles.root}
data-openbitfun-component="confirm-dialog"
data-openbitfun-part="message"
>
<div className={styles.message}>{t('tabs.confirmCloseBtw')}</div>
<Checkbox
className={styles.checkbox}
size="sm"
label={t('tabs.skipCloseBtwConfirmation')}
onCheckedChange={onSkipChange}
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ vi.mock('@/shared/services/destroyTerminalSession', () => ({ destroyTerminalSess
import { useTabLifecycle } from './useTabLifecycle';
import { CanvasStoreModeContext, clearAgentCanvasForPeerSwitch, switchAgentCanvasScope, useAgentCanvasStore } from '../stores';
import { useConfirmDialogStore } from '@/infrastructure/confirm-dialog/confirmDialogService';
import { BTW_CLOSE_CONFIRMATION_STORAGE_KEY } from '@/infrastructure/preferences/btwCloseConfirmation';

describe('BTW tab close transitions', () => {
let root: Root;
Expand All @@ -37,6 +38,7 @@ describe('BTW tab close transitions', () => {
beforeEach(async () => {
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
vi.resetAllMocks();
localStorage.removeItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY);
state.sessions.clear();
state.discard.mockResolvedValue(undefined);
state.save.mockResolvedValue(undefined);
Expand Down Expand Up @@ -124,6 +126,40 @@ describe('BTW tab close transitions', () => {
expect(useAgentCanvasStore.getState().closedTabs).toEqual([]);
});

it('remembers the opt-out only after confirming and skips future warnings', async () => {
let id!: string;
await act(async () => { id = addBtw('child'); });
const { pending } = await beginClose(() => lifecycle.handleCloseWithDirtyCheck(id, 'primary'));
const message = useConfirmDialogStore.getState().options?.message as React.ReactElement<{ onSkipChange: (skip: boolean) => void }>;
message.props.onSkipChange(true);
await act(async () => { useConfirmDialogStore.getState().confirm(); expect(await pending).toBe(true); });
expect(localStorage.getItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY)).toBe('true');

await act(async () => { addBtw('child-2'); });
const nextId = useAgentCanvasStore.getState().primaryGroup.tabs.at(-1)!.id;
const nextClose = lifecycle.handleCloseWithDirtyCheck(nextId, 'primary');
expect(useConfirmDialogStore.getState().isOpen).toBe(false);
await expect(nextClose).resolves.toBe(true);
expect(state.discard).toHaveBeenCalledWith('child-2');
});

it('does not remember the opt-out when cancelling or saving as a fork', async () => {
let id!: string;
await act(async () => { id = addBtw('child'); });
const { pending } = await beginClose(() => lifecycle.handleCloseWithDirtyCheck(id, 'primary'));
const message = useConfirmDialogStore.getState().options?.message as React.ReactElement<{ onSkipChange: (skip: boolean) => void }>;
message.props.onSkipChange(true);
useConfirmDialogStore.getState().cancel();
expect(await pending).toBe(false);
expect(localStorage.getItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY)).toBeNull();

const retry = lifecycle.handleCloseWithDirtyCheck(id, 'primary');
const retryMessage = useConfirmDialogStore.getState().options?.message as React.ReactElement<{ onSkipChange: (skip: boolean) => void }>;
retryMessage.props.onSkipChange(true);
await act(async () => { useConfirmDialogStore.getState().secondary(); expect(await retry).toBe(true); });
expect(localStorage.getItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY)).toBeNull();
});

it('keeps the tab and reports cleanup failure', async () => {
let id!: string;
await act(async () => { id = addBtw('child'); });
Expand All @@ -141,7 +177,9 @@ describe('BTW tab close transitions', () => {
useAgentCanvasStore.getState().addTab({ type: 'btw-session', title: 'review', data: { childSessionId: 'review' } }, 'active');
});
const { pending } = await beginClose(() => lifecycle.handleCloseAllWithDirtyCheck('primary'));
expect(useConfirmDialogStore.getState().options?.message).toBe('tabs.confirmCloseBtw');
expect(useConfirmDialogStore.getState().options?.message).toMatchObject({
props: { onSkipChange: expect.any(Function) },
});
await act(async () => { useConfirmDialogStore.getState().confirm(); expect(await pending).toBe(true); });
expect(state.discard.mock.calls.map(call => call[0]).sort()).toEqual(['child-a', 'child-b']);
expect(useAgentCanvasStore.getState().primaryGroup.tabs.map(tab => tab.title)).toEqual(['pinned-child']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - Pin action -> pinned
*/

import { useCallback, useEffect } from 'react';
import { createElement, useCallback, useEffect } from 'react';
import {
useCanvasStore,
useAgentCanvasStore,
Expand All @@ -28,6 +28,8 @@ import { flowChatStore } from '@/flow_chat/store/FlowChatStore';
import { canSaveBtwSessionAsFork, discardBtwSession, saveBtwSessionAsFork } from '@/flow_chat/services/BtwSessionLifecycle';
import { getActiveSurfaceScope, isSurfaceChangedError } from '@/infrastructure/peer-device/deviceSurface';
import { notificationService } from '@/shared/notification-system';
import { shouldConfirmBtwClose, setConfirmBtwClose } from '@/infrastructure/preferences/btwCloseConfirmation';
import { BtwCloseConfirmation } from './BtwCloseConfirmation';

const log = createLogger('useTabLifecycle');
interface UseTabLifecycleOptions {
Expand Down Expand Up @@ -94,9 +96,12 @@ export const useTabLifecycle = (options: UseTabLifecycleOptions = {}): UseTabLif
const confirmBtwClose = useCallback(async (tabs: { title: string; content: PanelContent }[]) => {
const btwTabs = tabs.filter(isBtwTab);
if (btwTabs.length === 0) return 'confirm';
return confirmDialogChoice({
if (!shouldConfirmBtwClose()) return 'confirm';

let skipConfirmation = false;
const choice = await confirmDialogChoice({
title: t('tabs.closeBtwTitle'),
message: t('tabs.confirmCloseBtw'),
message: createElement(BtwCloseConfirmation, { onSkipChange: (checked) => { skipConfirmation = checked; } }),
type: 'warning',
confirmDanger: true,
confirmText: t('tabs.close'),
Expand All @@ -105,6 +110,8 @@ export const useTabLifecycle = (options: UseTabLifecycleOptions = {}): UseTabLif
secondaryText: btwTabs.some(tab => canSaveBtwSessionAsFork(tab.content.data.childSessionId))
? t('tabs.saveBtwAsFork') : undefined,
});
if (choice === 'confirm' && skipConfirmation) setConfirmBtwClose(false);
return choice;
}, [isBtwTab, t]);

const closeTerminalSession = useCallback(async (tab: { content: PanelContent }): Promise<boolean> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useState } from 'react';
import { Switch } from '@openbitfun/ui';
import { useI18n } from '@/infrastructure/i18n';
import { ConfigPageRow, ConfigPageSection } from '@/infrastructure/config/components/common';
import { setConfirmBtwClose, shouldConfirmBtwClose } from '@/infrastructure/preferences/btwCloseConfirmation';
import { useSettingsSectionAnchor } from '../shared/useSettingsSectionAnchor';

export default function BtwCloseConfirmationSettingsSection() {
const { t } = useI18n('settings/application');
const [enabled, setEnabled] = useState(shouldConfirmBtwClose);
const sectionAnchor = useSettingsSectionAnchor('btw-close-confirmation', true);

return (
<div id={sectionAnchor}>
<ConfigPageSection title={t('btwCloseConfirmation.title')}>
<ConfigPageRow label={t('btwCloseConfirmation.label')} description={t('btwCloseConfirmation.description')} align="center">
<Switch
checked={enabled}
onCheckedChange={(next) => {
setEnabled(next);
setConfirmBtwClose(next);
}}
aria-label={t('btwCloseConfirmation.label')}
/>
</ConfigPageRow>
</ConfigPageSection>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import KeyboardShortcutsSection from './KeyboardShortcutsSection';
import VoiceSettingsSection from './VoiceSettingsSection';
import TextSelectionSettingsSection from './TextSelectionSettingsSection';
import MessageSendingSettingsSection from './MessageSendingSettingsSection';
import BtwCloseConfirmationSettingsSection from './BtwCloseConfirmationSettingsSection';

export default function InputSettingsPage() {
return (
<SettingsPage pageId="application.input">
<VoiceSettingsSection />
<MessageSendingSettingsSection />
<BtwCloseConfirmationSettingsSection />
<TextSelectionSettingsSection />
<KeyboardShortcutsSection />
</SettingsPage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('settings information architecture', () => {
expect(new Set(SETTINGS_PAGE_MANIFESTS.map(page => page.id)).size).toBe(20);
expect(SETTINGS_PAGE_MANIFESTS.filter(page => page.views?.length).map(page => page.id)).toEqual(['tools.external-agents']);
expect(getSettingsPageManifest('tools.external-agents').views?.map(view => view.id)).toEqual(['local', 'ssh', 'json']);
expect(getSettingsPageManifest('application.input').sections?.map(section => section.id)).toEqual(['voice', 'message-sending', 'text-selection', 'shortcuts']);
expect(getSettingsPageManifest('application.input').sections?.map(section => section.id)).toEqual(['voice', 'message-sending', 'btw-close-confirmation', 'text-selection', 'shortcuts']);
expect(getSettingsPageManifest('application.pet').sections?.map(section => section.id)).toEqual(['voice-call', 'pet', 'desktop-cards']);
expect(resolveSettingsDestination({ pageId: 'application.appearance', sectionId: 'sidebar-navigation' }))
.toEqual({ pageId: 'application.appearance', sectionId: 'sidebar-navigation' });
Expand Down
6 changes: 6 additions & 0 deletions src/web-ui/src/app/scenes/settings/settingsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ export const SETTINGS_PAGE_MANIFESTS: readonly SettingsPageManifest[] = [
keywords: ['message', 'send', 'queue', 'immediate', 'steering', 'flowchat'],
searchPhrases: [phrase('settings/application', 'messageSending.title'), phrase('settings/application', 'messageSending.duringTurn'), phrase('settings/application', 'messageSending.description')],
},
{
id: 'btw-close-confirmation',
labelKey: 'navigation.sections.btw-close-confirmation',
keywords: ['btw', 'side conversation', 'close', 'confirmation', 'prompt'],
searchPhrases: [phrase('settings/application', 'btwCloseConfirmation.title'), phrase('settings/application', 'btwCloseConfirmation.label')],
},
{
id: 'text-selection',
labelKey: 'navigation.sections.text-selection',
Expand Down
1 change: 1 addition & 0 deletions src/web-ui/src/app/scenes/settings/settingsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type SettingsViewId =
export type SettingsSectionId =
| 'sidebar-navigation'
| 'message-sending'
| 'btw-close-confirmation'
| 'text-selection'
| 'pet'
| 'desktop-cards'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @vitest-environment jsdom
import { beforeEach, describe, expect, it } from 'vitest';
import {
BTW_CLOSE_CONFIRMATION_STORAGE_KEY,
setConfirmBtwClose,
shouldConfirmBtwClose,
} from './btwCloseConfirmation';

describe('BTW close confirmation preference', () => {
beforeEach(() => localStorage.clear());

it('confirms by default', () => {
expect(shouldConfirmBtwClose()).toBe(true);
});

it('persists the disabled state and restores it', () => {
setConfirmBtwClose(false);
expect(localStorage.getItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY)).toBe('true');
expect(shouldConfirmBtwClose()).toBe(false);

setConfirmBtwClose(true);
expect(localStorage.getItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY)).toBeNull();
expect(shouldConfirmBtwClose()).toBe(true);
});
});
18 changes: 18 additions & 0 deletions src/web-ui/src/infrastructure/preferences/btwCloseConfirmation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const BTW_CLOSE_CONFIRMATION_STORAGE_KEY = 'openbitfun:preferences:skip-btw-close-confirmation:v1';

export function shouldConfirmBtwClose(): boolean {
try {
return globalThis.localStorage?.getItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY) !== 'true';
} catch {
return true;
}
}

export function setConfirmBtwClose(enabled: boolean): void {
try {
if (enabled) globalThis.localStorage?.removeItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY);
else globalThis.localStorage?.setItem(BTW_CLOSE_CONFIRMATION_STORAGE_KEY, 'true');
} catch {
// A storage failure must not block the settings interaction.
}
}
1 change: 1 addition & 0 deletions src/web-ui/src/locales/en-US/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
"saveBtwAsFork": "Save as fork",
"saveBtwFailed": "Could not save. The side thread is still open; try again.",
"confirmCloseBtw": "Closing discards the conversation permanently.",
"skipCloseBtwConfirmation": "Don't ask again",
"closeBtwFailed": "Could not close the side conversation. The tab is still open; please try again.",
"popOut": "Pop out as scene",
"closeOthers": "Close Others",
Expand Down
1 change: 1 addition & 0 deletions src/web-ui/src/locales/en-US/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"sections": {
"text-selection": "Text selection",
"message-sending": "Message sending",
"btw-close-confirmation": "Side conversation closing",
"voice": "Voice",
"shortcuts": "Keyboard Shortcuts",
"session": "Session Defaults",
Expand Down
5 changes: 5 additions & 0 deletions src/web-ui/src/locales/en-US/settings/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"loadFailed": "Failed to load text selection preferences",
"saveFailed": "Failed to save text selection preferences"
},
"btwCloseConfirmation": {
"title": "Side conversation closing",
"label": "Confirm before closing side conversations",
"description": "Closing a side conversation permanently discards its content. Turn this off to skip the confirmation."
},
"applicationGroups": {
"startupAndUpdates": {
"title": "Startup & updates",
Expand Down
1 change: 1 addition & 0 deletions src/web-ui/src/locales/zh-CN/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
"close": "关闭",
"closeBtwTitle": "关闭侧问?",
"confirmCloseBtw": "关闭后对话将消失,无法恢复。",
"skipCloseBtwConfirmation": "不再提示",
"saveBtwAsFork": "保存为 Fork 会话",
"saveBtwFailed": "保存失败,侧问已保留,请重试。",
"closeBtwFailed": "暂时无法关闭侧问,标签页已保留,请重试。",
Expand Down
1 change: 1 addition & 0 deletions src/web-ui/src/locales/zh-CN/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"sections": {
"text-selection": "文本选择",
"message-sending": "消息发送",
"btw-close-confirmation": "侧问关闭",
"voice": "语音",
"shortcuts": "快捷键",
"session": "会话默认行为",
Expand Down
5 changes: 5 additions & 0 deletions src/web-ui/src/locales/zh-CN/settings/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"loadFailed": "加载文本选择偏好失败",
"saveFailed": "保存文本选择偏好失败"
},
"btwCloseConfirmation": {
"title": "侧问关闭",
"label": "关闭侧问前确认",
"description": "关闭侧问会永久丢弃对话内容;关闭后不再显示确认提示。"
},
"applicationGroups": {
"startupAndUpdates": {
"title": "启动与更新",
Expand Down
1 change: 1 addition & 0 deletions src/web-ui/src/locales/zh-TW/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
"saveBtwAsFork": "儲存為 Fork 對話",
"saveBtwFailed": "儲存失敗,側問已保留,請重試。",
"confirmCloseBtw": "關閉後對話將消失,無法復原。",
"skipCloseBtwConfirmation": "不再提示",
"closeBtwFailed": "暫時無法關閉側問,標籤頁已保留,請重試。",
"popOut": "彈出為獨立場景",
"closeOthers": "關閉其他",
Expand Down
1 change: 1 addition & 0 deletions src/web-ui/src/locales/zh-TW/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"sections": {
"text-selection": "文字選取",
"message-sending": "訊息傳送",
"btw-close-confirmation": "側問關閉",
"voice": "語音",
"shortcuts": "快捷鍵",
"session": "工作階段預設行為",
Expand Down
5 changes: 5 additions & 0 deletions src/web-ui/src/locales/zh-TW/settings/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"loadFailed": "載入文字選取偏好失敗",
"saveFailed": "儲存文字選取偏好失敗"
},
"btwCloseConfirmation": {
"title": "側問關閉",
"label": "關閉側問前確認",
"description": "關閉側問會永久捨棄對話內容;關閉後不再顯示確認提示。"
},
"applicationGroups": {
"startupAndUpdates": {
"title": "啟動與更新",
Expand Down
Loading