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
1 change: 1 addition & 0 deletions changelog.d/3114-session-filter-empty.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A sidebar session filter that hides every row now says why the list is empty — **No group chats**, **No direct chats** or **No unread chats** — instead of leaving a blank panel ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)).
11 changes: 11 additions & 0 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ var ZH = {
"Session filter": "会话筛选",
"Direct chats": "单聊",
Unread: "未读",
"No group chats": "没有群聊",
"No direct chats": "没有单聊",
"No unread chats": "没有未读会话",
Secrets: "密钥",
Appearance: "外观",
Theme: "主题",
Expand Down Expand Up @@ -10920,6 +10923,12 @@ function SessionFilter({ value, onChange }) {
}, label))
);
}
function sessionFilterEmpty(filter) {
if (filter === "group") return t("No group chats");
if (filter === "direct") return t("No direct chats");
if (filter === "unread") return t("No unread chats");
return null;
}
function TeamSidebar(props) {
const { wide, useRoster, useUi, useSessions, actions } = props;
const listRef = (0, import_react19.useRef)(null);
Expand Down Expand Up @@ -10973,6 +10982,7 @@ function TeamSidebar(props) {
const tree = showTree ? botTree([main, ...order.filter(listed).map((entry) => entry.item)], main.id, (id) => structure.parentOf(id)) : null;
const visibleOrder = order.filter((entry) => !(tree && inTree(entry)) && !(inTree(entry) && structure?.include?.(entry.item.id) === false) && matchesSessionFilter(entry, sessionFilter, unreadIds.has(entry.item.id)));
const showMain = !tree && main && matchesSessionFilter({ kind: "bot", item: main }, sessionFilter, unreadIds.has(main.id));
const filterEmpty = roster.ready && !showMain && !tree && visibleOrder.length === 0 ? sessionFilterEmpty(sessionFilter) : null;
useListGlide(listRef, wide, [showMain && main ? main.id : null, ...visibleOrder.map((entry) => entry.item.id)].filter(Boolean).join(","));
useLandOnMainBot(roster, useSessions, actions);
const rowProps = { roster, actions, useSessions, useUi, useSessionStatus: props.useSessionStatus, useSessionRetainInfo: props.useSessionRetainInfo, useActivity: props.useActivity, useWork: props.useWork, wide };
Expand Down Expand Up @@ -11011,6 +11021,7 @@ function TeamSidebar(props) {
{ ref: listRef, className: "bt-list", role: "region", "aria-label": t("Bot list") },
tree ? (0, import_react19.createElement)("div", { className: "bt-tree", role: "group", "aria-label": t("Bot tree") }, tree.map((node) => (0, import_react19.createElement)(TreeNode, { key: node.bot.id, node, rowProps, markedUnread, collapsed, toggle, actions: structure?.nodeActions }))) : showMain ? (0, import_react19.createElement)(BotRow, { ...rowProps, bot: main, marked: markedUnread[main.id] === true }) : roster.ready ? null : (0, import_react19.createElement)("div", { className: "bt-hint" }, t("Setting up your Main Bot…")),
visibleOrder.map((entry) => entry.kind === "bot" ? (0, import_react19.createElement)(BotRow, { key: entry.item.id, ...rowProps, bot: entry.item, marked: markedUnread[entry.item.id] === true }) : entry.kind === "room" ? (0, import_react19.createElement)(RoomRow, { key: entry.item.id, ...rowProps, room: entry.item, marked: markedUnread[entry.item.id] === true }) : (0, import_react19.createElement)(AgentRow, { key: entry.item.id, ...rowProps, agent: entry.item, marked: markedUnread[entry.item.id] === true })),
filterEmpty ? (0, import_react19.createElement)("div", { className: "bt-hint bt-session-filter-empty" }, filterEmpty) : null,
wide && sessionFilter === "all" ? (0, import_react19.createElement)(FlyBotSections, { roster, actions, renderBot: (bot) => (0, import_react19.createElement)(BotRow, { key: bot.id, ...rowProps, bot, asRow: true, marked: markedUnread[bot.id] === true }) }) : null
)
);
Expand Down
3 changes: 3 additions & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ const ZH = {
'Session filter': '会话筛选',
'Direct chats': '单聊',
Unread: '未读',
'No group chats': '没有群聊',
'No direct chats': '没有单聊',
'No unread chats': '没有未读会话',
Secrets: '密钥',
Appearance: '外观',
Theme: '主题',
Expand Down
12 changes: 12 additions & 0 deletions core/src/client/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ function SessionFilter({ value, onChange }) {
}, label)))
}

// A filter that hides every row leaves a blank panel, so the list says which filter emptied it.
function sessionFilterEmpty(filter) {
if (filter === 'group') return t('No group chats')
if (filter === 'direct') return t('No direct chats')
if (filter === 'unread') return t('No unread chats')
return null
}

export function TeamSidebar(props) {
const { wide, useRoster, useUi, useSessions, actions } = props
const listRef = useRef(null)
Expand Down Expand Up @@ -418,6 +426,9 @@ export function TeamSidebar(props) {
!(inTree(entry) && structure?.include?.(entry.item.id) === false) &&
matchesSessionFilter(entry, sessionFilter, unreadIds.has(entry.item.id)))
const showMain = !tree && main && matchesSessionFilter({ kind: 'bot', item: main }, sessionFilter, unreadIds.has(main.id))
const filterEmpty = roster.ready && !showMain && !tree && visibleOrder.length === 0
? sessionFilterEmpty(sessionFilter)
: null
useListGlide(listRef, wide, [showMain && main ? main.id : null, ...visibleOrder.map(entry => entry.item.id)].filter(Boolean).join(','))
useLandOnMainBot(roster, useSessions, actions)
const rowProps = { roster, actions, useSessions, useUi, useSessionStatus: props.useSessionStatus, useSessionRetainInfo: props.useSessionRetainInfo, useActivity: props.useActivity, useWork: props.useWork, wide }
Expand Down Expand Up @@ -453,6 +464,7 @@ export function TeamSidebar(props) {
: entry.kind === 'room'
? h(RoomRow, { key: entry.item.id, ...rowProps, room: entry.item, marked: markedUnread[entry.item.id] === true })
: h(AgentRow, { key: entry.item.id, ...rowProps, agent: entry.item, marked: markedUnread[entry.item.id] === true }))),
filterEmpty ? h('div', { className: 'bt-hint bt-session-filter-empty' }, filterEmpty) : null,
wide && sessionFilter === 'all' ? h(FlyBotSections, { roster, actions, renderBot: bot => h(BotRow, { key: bot.id, ...rowProps, bot, asRow: true, marked: markedUnread[bot.id] === true }) }) : null))
}

Expand Down
227 changes: 227 additions & 0 deletions core/test/sidebar-session-filter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
// The sidebar session filter only offers kinds the list already has: all, group
// chats, direct chats, and unread (from the same marks the rows already draw).
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { fileURLToPath } from 'node:url'
import { runInNewContext } from 'node:vm'
import { build } from 'esbuild'

const { outputFiles } = await build({
stdin: {
contents: "export { TeamSidebar } from './src/client/sidebar.js'\nexport { DICTIONARY, installLocale } from './src/client/i18n.js'",
resolveDir: fileURLToPath(new URL('..', import.meta.url)),
},
bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',
external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
})

const h = (type, props, ...children) => ({ type, props: { ...props, children: children.flat(Infinity) } })
let slots = []
let index = 0
const react = {
createElement: h, Component: class {}, Fragment: Symbol('F'),
useMemo: (fn) => { const at = index++; if (!(at in slots)) slots[at] = fn(); return slots[at] },
useState: (initial) => {
const at = index++
if (!(at in slots)) slots[at] = typeof initial === 'function' ? initial() : initial
return [slots[at], (value) => { slots[at] = typeof value === 'function' ? value(slots[at]) : value }]
},
useCallback: (fn) => fn,
useRef: (value) => { const at = index++; if (!(at in slots)) slots[at] = { current: value }; return slots[at] },
useEffect() {},
useLayoutEffect() {},
useSyncExternalStore: (_subscribe, get) => get(),
}
const win = { location: { hash: '' }, innerHeight: 800, addEventListener() {}, removeEventListener() {}, matchMedia: () => ({ matches: false, addEventListener() {}, removeEventListener() {} }) }
const module = { exports: {} }
runInNewContext(outputFiles[0].text, {
module, exports: module.exports, console, setTimeout, clearTimeout, setImmediate, queueMicrotask,
requestAnimationFrame: () => 0, cancelAnimationFrame() {},
Date, JSON, Promise, Symbol, Map, Set,
document: { hidden: false, addEventListener() {}, removeEventListener() {}, body: {}, querySelector: () => null },
navigator: { language: 'en' },
localStorage: { getItem: () => null, setItem() {} },
window: win,
__flybot__: { slots: { entries: () => [], subscribe: () => () => {}, version: () => 0 }, call: () => {} },
require: (name) => {
if (name === 'react') return react
if (name === 'react-dom') return { createPortal: node => node }
if (name === '@deepseek-ai/dsh-client-ui-primitives') return {}
throw new Error(`Unexpected platform module ${name}`)
},
})
const { TeamSidebar, DICTIONARY, installLocale } = module.exports

const chief = { id: 'chief', name: 'Chief' }
const writer = { id: 'writer', name: 'Writer' }
const room = { id: 'room-1', name: 'Review room', origin: 'group' }
const statuses = new Map([
['writer', { completionUnread: true }],
])
const roster = {
ready: true, bots: [chief, writer], rooms: [room], agents: [],
byId: { chief, writer }, roomsById: { 'room-1': room }, mainBotId: 'chief',
}
const OPAQUE = new Set(['BotRow', 'RoomRow', 'AgentRow', 'InboxRow', 'KanbanRow', 'ProjectsNav', 'FlyBotSections', 'TreeNode', 'UpdateButton', 'BrandMark', 'BrandName'])
const expand = (node) => {
if (Array.isArray(node)) return node.map(expand)
if (!node || typeof node !== 'object') return node
if (typeof node.type === 'function' && !OPAQUE.has(node.type.name)) return expand(node.type(node.props ?? {}))
const props = node.props ?? {}
return { ...node, props: { ...props, children: expand(props.children) } }
}
const all = (node, out = []) => {
if (node == null) return out
if (Array.isArray(node)) { for (const item of node) all(item, out); return out }
if (typeof node !== 'object') return out
out.push(node)
all(node.props?.children, out)
return out
}
const ownText = (node) => {
const walk = (value) => {
if (Array.isArray(value)) return value.map(walk).join('')
if (typeof value === 'string' || typeof value === 'number') return String(value)
if (value && typeof value === 'object') return walk(value.props?.children)
return ''
}
return walk(node?.props?.children)
}
const hasClass = (node, name) => String(node.props?.className ?? '').split(/\s+/).includes(name)

const mount = () => {
slots = []
const draw = () => {
index = 0
return all(expand(TeamSidebar({
wide: true,
useRoster: select => select(roster),
useUi: select => select({ unread: {} }),
useSessions: select => select({ ids: ['chief', 'writer', 'room-1'], byId: { chief: { updatedAt: 3 }, writer: { updatedAt: 2 }, 'room-1': { updatedAt: 1 } } }),
useRegistry: () => {},
useUpdate: select => select({}),
useWork: select => select({}),
useSessionStatus: select => select(statuses),
useSessionRetainInfo: select => select({}),
useActivity: select => select({}),
actions: {
openInbox() {}, openBoard() {}, openPalette() {}, openNewChat() {},
landOnMainBot() {}, clearUnread() {}, isAgentSession: () => false,
},
})))
}
return draw
}

test('the wide sidebar offers All, Group chats, Direct chats, and Unread, and no Read chip', () => {
const nodes = mount()()
const bar = nodes.find(node => hasClass(node, 'bt-session-filter'))
assert.ok(bar, 'the session filter is drawn above the list')
const chips = nodes.filter(node => hasClass(node, 'bt-session-filter-btn'))
assert.deepEqual(chips.map(ownText), ['All', 'Group chats', 'Direct chats', 'Unread'])
assert.equal(chips.find(node => ownText(node) === 'All').props['aria-checked'], true)
assert.equal(nodes.some(node => ownText(node) === 'Read' && hasClass(node, 'bt-session-filter-btn')), false)
const kinds = nodes.filter(node => typeof node.type === 'function').map(node => node.type.name)
assert.ok(kinds.includes('BotRow'))
assert.ok(kinds.includes('RoomRow'))
})

test('Group chats keeps rooms, Direct chats keeps Bots, Unread keeps only marked rows', () => {
const draw = mount()
let nodes = draw()
const press = label => {
const chip = nodes.find(node => hasClass(node, 'bt-session-filter-btn') && ownText(node) === label)
assert.ok(chip, label)
chip.props.onClick()
nodes = draw()
}
const names = (kind) => nodes.filter(node => node.type?.name === kind).map(node => (node.props.bot ?? node.props.room)?.name)
press('Group chats')
assert.deepEqual(names('RoomRow'), ['Review room'])
assert.deepEqual(names('BotRow'), [])
press('Direct chats')
assert.deepEqual(names('RoomRow'), [])
assert.ok(names('BotRow').includes('Chief'))
assert.ok(names('BotRow').includes('Writer'))
press('Unread')
assert.deepEqual(names('BotRow'), ['Writer'])
assert.deepEqual(names('RoomRow'), [])
press('All')
assert.ok(names('BotRow').includes('Chief'))
assert.ok(names('RoomRow').includes('Review room'))
})

test('the narrow rail does not draw session filter chips', () => {
slots = []
index = 0
const tree = TeamSidebar({
wide: false,
useRoster: select => select(roster),
useUi: select => select({ unread: {} }),
useSessions: select => select({ ids: [], byId: {} }),
useRegistry: () => {},
useUpdate: select => select({}),
useWork: select => select({}),
useSessionStatus: select => select(statuses),
useSessionRetainInfo: select => select({}),
useActivity: select => select({}),
actions: {
openInbox() {}, openBoard() {}, openPalette() {}, openNewChat() {},
landOnMainBot() {}, clearUnread() {}, isAgentSession: () => false,
},
})
const nodes = all(expand(tree))
assert.equal(nodes.some(node => hasClass(node, 'bt-session-filter')), false)
})

// A filter can hide every row. The list then says why it is empty rather than reading as a blank
// panel, and the sentence follows the interface language (#3114).
test('a filter that hides every row says why the list is empty', () => {
// Rooms and nothing unread: Unread leaves no row at all.
const quiet = {
ready: true, bots: [chief], rooms: [room], agents: [],
byId: { chief }, roomsById: { 'room-1': room }, mainBotId: 'chief',
}
const off = installLocale({
register: () => () => {},
bind: () => key => DICTIONARY.zh[key] ?? key,
getLocale: () => ({ active: 'zh' }),
})
try {
slots = []
const draw = () => {
index = 0
return all(expand(TeamSidebar({
wide: true,
useRoster: select => select(quiet),
useUi: select => select({ unread: {} }),
useSessions: select => select({ ids: ['chief', 'room-1'], byId: { chief: { updatedAt: 2 }, 'room-1': { updatedAt: 1 } } }),
useRegistry: () => {},
useUpdate: select => select({}),
useWork: select => select({}),
useSessionStatus: select => select(new Map()),
useSessionRetainInfo: select => select({}),
useActivity: select => select({}),
actions: {
openInbox() {}, openBoard() {}, openPalette() {}, openNewChat() {},
landOnMainBot() {}, clearUnread() {}, isAgentSession: () => false,
},
})))
}
const rows = nodes => nodes.filter(node => ['BotRow', 'RoomRow'].includes(node.type?.name)).map(node => node.type.name)
let nodes = draw()
assert.deepEqual(rows(nodes), ['BotRow', 'RoomRow'], 'All draws the Main Bot and the room')
assert.equal(nodes.some(node => hasClass(node, 'bt-session-filter-empty')), false)
const unread = nodes.find(node => hasClass(node, 'bt-session-filter-btn') && node.props['data-filter'] === 'unread')
assert.ok(unread, 'the Unread chip is drawn')
assert.equal(ownText(unread), '未读')
unread.props.onClick()
nodes = draw()
assert.deepEqual(rows(nodes), [], 'Unread hides every row there is')
const empty = nodes.find(node => hasClass(node, 'bt-session-filter-empty'))
assert.ok(empty, 'the empty list says why it is empty')
assert.equal(ownText(empty), '没有未读会话')
} finally {
off()
}
})
Loading
Loading