Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(channels): give chat rail favorites a context menu (#6934)

Peter Chinman458ede8e3a67
diff --git a/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.test.tsx b/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.test.tsx
new file mode 100644
index 0000000000..936b1fffda
--- /dev/null
+++ b/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.test.tsx
@@ -0,0 +1,172 @@
+import type { ChannelEntity } from '@entity';
+import type { Favorite } from '@service-storage/generated/schemas/favorite';
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import {
+ type ComponentProps,
+ createSignal,
+ type JSX,
+ type ParentProps,
+ type Setter,
+ splitProps,
+} from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { ChannelFavoriteRow } from './ChannelFavoriteRows';
+
+const rail = vi.hoisted(() => ({
+ channelById: (_channelId: string): ChannelEntity | undefined => undefined,
+ activateRow: vi.fn(),
+ list: { focus: { set: vi.fn() } },
+}));
+
+vi.mock('./ChannelsRailContext', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('./ChannelsRailContext')>()),
+ useChannelsRail: () => rail,
+}));
+vi.mock('./ChannelsRailSection', () => ({}));
+vi.mock('./hooks/useChannelRailState', () => ({
+ useChannelRailFavoriteItemState: () => () => ({
+ domId: 'rail-favorite-row',
+ selected: false,
+ focused: false,
+ muted: false,
+ }),
+ useChannelRailFavoritesState: () => () => ({
+ items: [],
+ open: true,
+ focused: false,
+ containsFocus: false,
+ domId: 'rail-favorites-section',
+ }),
+}));
+vi.mock('./ChannelRailItems', () => ({
+ isPrimaryMouseDown: (event: MouseEvent) => event.button === 0,
+ ChannelRailItemContextMenu: (
+ props: ParentProps<{
+ channel: ChannelEntity;
+ rowId?: string;
+ extraItems?: JSX.Element;
+ }>
+ ) => (
+ <div
+ data-testid="channel-actions"
+ data-channel={props.channel.id}
+ data-row-id={props.rowId}
+ >
+ {props.children}
+ {props.extraItems}
+ </div>
+ ),
+}));
+vi.mock('./ChannelLabelRows', () => ({
+ ChannelLabelMenuItems: (props: { channel: ChannelEntity }) => (
+ <span data-testid="label-actions" data-channel={props.channel.id} />
+ ),
+}));
+vi.mock('@app/features/favorites/FavoriteContextMenu', () => ({
+ FavoriteContextMenu: (
+ props: ParentProps<{
+ favorite: Favorite;
+ onOpenChange?: (open: boolean) => void;
+ }>
+ ) => (
+ <div data-testid="favorite-actions" data-entity={props.favorite.entityId}>
+ <button type="button" onClick={() => props.onOpenChange?.(true)}>
+ Open favorite menu
+ </button>
+ {props.children}
+ </div>
+ ),
+}));
+vi.mock('@app/features/favorites/FavoriteIcon', () => ({
+ FavoriteIcon: () => <span />,
+}));
+vi.mock('@app/util/favorites', () => ({
+ useFavoriteDisplayName: () => () => 'Design',
+}));
+vi.mock('@app/components/view-shell', () => ({
+ ViewSidebar: {
+ Item: (
+ props: ComponentProps<'div'> & { as?: string; active?: boolean }
+ ) => {
+ const [, rest] = splitProps(props, ['as', 'active']);
+ return <div {...rest} />;
+ },
+ Icon: (props: ParentProps) => <span>{props.children}</span>,
+ },
+}));
+vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice: () => false }));
+vi.mock('@ui', () => ({
+ cn: (...values: unknown[]) => values.filter(Boolean).join(' '),
+}));
+
+const favorite: Favorite = {
+ entityType: 'channel',
+ entityId: 'design',
+ sortOrder: 0,
+ createdAt: '2026-01-01',
+};
+const channel = {
+ id: 'design',
+ type: 'channel',
+ name: 'Design',
+ ownerId: 'viewer',
+ channelType: 'team',
+} as ChannelEntity;
+
+let setChannel: Setter<ChannelEntity | undefined>;
+beforeEach(() => {
+ vi.clearAllMocks();
+ const [loaded, update] = createSignal<ChannelEntity | undefined>(undefined);
+ setChannel = update;
+ rail.channelById = (channelId) =>
+ loaded()?.id === channelId ? loaded() : undefined;
+});
+afterEach(cleanup);
+
+describe('favorite rows in the chat rail', () => {
+ it('gives a favorited channel its channel actions, aimed at the favorite row', () => {
+ setChannel(channel);
+ render(() => <ChannelFavoriteRow favorite={favorite} />);
+
+ const menu = screen.getByTestId('channel-actions');
+ expect(menu.getAttribute('data-channel')).toBe('design');
+ expect(menu.getAttribute('data-row-id')).toBe('favorite:channel:design');
+ expect(screen.getByTestId('label-actions')).toBeTruthy();
+ expect(screen.queryByTestId('favorite-actions')).toBeNull();
+ });
+
+ it('keeps the shared favorite actions until the channel loads', () => {
+ render(() => <ChannelFavoriteRow favorite={favorite} />);
+
+ expect(
+ screen.getByTestId('favorite-actions').getAttribute('data-entity')
+ ).toBe('design');
+ expect(screen.queryByTestId('channel-actions')).toBeNull();
+ const row = screen.getByRole('treeitem');
+
+ setChannel(channel);
+ expect(screen.getByTestId('channel-actions')).toBeTruthy();
+ expect(screen.queryByTestId('favorite-actions')).toBeNull();
+ expect(screen.getByRole('treeitem')).toBe(row);
+ });
+
+ it('focuses the favorite row when the fallback menu opens', () => {
+ render(() => <ChannelFavoriteRow favorite={favorite} />);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Open favorite menu' }));
+ expect(rail.list.focus.set).toHaveBeenCalledWith(
+ 'favorite:channel:design',
+ { reason: 'pointer', force: true }
+ );
+ });
+
+ it('still activates the favorite row on click', () => {
+ render(() => <ChannelFavoriteRow favorite={favorite} />);
+
+ fireEvent.click(screen.getByRole('treeitem'));
+ expect(rail.activateRow).toHaveBeenCalledWith(
+ 'favorite:channel:design',
+ expect.anything()
+ );
+ });
+});
diff --git a/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.tsx b/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.tsx
new file mode 100644
index 0000000000..99c3f367af
--- /dev/null
+++ b/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.tsx
@@ -0,0 +1,147 @@
+import { ViewSidebar } from '@app/components/view-shell';
+import { FavoriteContextMenu } from '@app/features/favorites/FavoriteContextMenu';
+import { FavoriteIcon } from '@app/features/favorites/FavoriteIcon';
+import { useFavoriteDisplayName } from '@app/util/favorites';
+import { ChannelMutedIndicator } from '@channel/components/ChannelMutedIndicator';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
+import CaretDownIcon from '@phosphor/caret-down.svg';
+import type { Favorite } from '@service-storage/generated/schemas/favorite';
+import { cn } from '@ui';
+import { For, Show } from 'solid-js';
+import { ChannelLabelMenuItems } from './ChannelLabelRows';
+import {
+ ChannelRailItemContextMenu,
+ isPrimaryMouseDown,
+} from './ChannelRailItems';
+import { rowKeyForFavorite, useChannelsRail } from './ChannelsRailContext';
+import { CollapsibleSection } from './ChannelsRailSection';
+import {
+ useChannelRailFavoriteItemState,
+ useChannelRailFavoritesState,
+} from './hooks/useChannelRailState';
+
+/**
+ * A favorite row in the Chat sidebar. The rail only favorites channels, so the
+ * row carries the same actions as the channel's row in the sections below;
+ * until its channel loads (or for a favorite of another kind) it falls back to
+ * the shared favorite actions.
+ */
+export function ChannelFavoriteRow(props: { favorite: Favorite }) {
+ const rail = useChannelsRail();
+ const displayName = useFavoriteDisplayName(props.favorite);
+ const item = useChannelRailFavoriteItemState(() => props.favorite);
+ const channel = () =>
+ props.favorite.entityType === 'channel'
+ ? rail.channelById(props.favorite.entityId)
+ : undefined;
+ const focusRow = () => {
+ rail.list.focus.set(rowKeyForFavorite(props.favorite), {
+ reason: 'pointer',
+ force: true,
+ });
+ };
+
+ const row = (
+ <ViewSidebar.Item
+ as="div"
+ id={item().domId}
+ role="treeitem"
+ tabIndex={-1}
+ class={cn(
+ 'group/channel-option relative',
+ !item().selected &&
+ !isTouchDevice() &&
+ item().focused &&
+ 'bg-hover text-ink'
+ )}
+ active={item().selected && !isTouchDevice()}
+ aria-current={item().selected ? 'page' : undefined}
+ onClick={(event) => {
+ if (!isPrimaryMouseDown(event)) return;
+ rail.activateRow(rowKeyForFavorite(props.favorite), event);
+ }}
+ >
+ <ViewSidebar.Icon>
+ <FavoriteIcon favorite={props.favorite} class="size-4" />
+ </ViewSidebar.Icon>
+ <span class="min-w-0 flex-1 truncate">{displayName()}</span>
+ <ChannelMutedIndicator muted={item().muted} />
+ </ViewSidebar.Item>
+ );
+
+ return (
+ <Show
+ when={channel()}
+ fallback={
+ <FavoriteContextMenu
+ favorite={props.favorite}
+ triggerClass="block"
+ onOpenChange={(open) => {
+ if (open) focusRow();
+ }}
+ >
+ {row}
+ </FavoriteContextMenu>
+ }
+ >
+ {(channel) => (
+ <ChannelRailItemContextMenu
+ channel={channel()}
+ rowId={rowKeyForFavorite(props.favorite)}
+ class="block w-full"
+ extraItems={<ChannelLabelMenuItems channel={channel()} />}
+ >
+ {row}
+ </ChannelRailItemContextMenu>
+ )}
+ </Show>
+ );
+}
+
+/** The Chat sidebar's Favorites section, above the channel and DM sections. */
+export function ChannelFavoritesSection() {
+ const rail = useChannelsRail();
+ const section = useChannelRailFavoritesState();
+
+ return (
+ <Show when={section().items.length > 0}>
+ <CollapsibleSection.Root open={section().open} sizing="content">
+ <CollapsibleSection.Header
+ focused={section().focused}
+ focusWithin={section().containsFocus}
+ >
+ <button
+ id={section().domId}
+ type="button"
+ role="treeitem"
+ tabIndex={-1}
+ class="relative flex h-full min-w-0 flex-1 items-center gap-1 rounded-xl px-2 text-left outline-none"
+ aria-expanded={section().open}
+ onMouseDown={(event) => {
+ if (!isPrimaryMouseDown(event)) return;
+ event.preventDefault();
+ rail.toggleGroup('favorites');
+ }}
+ >
+ <span class="min-w-0 truncate">Favorites</span>
+ <CaretDownIcon
+ class={cn(
+ 'size-2.5 shrink-0 opacity-0 transition-[opacity,rotate] duration-200 motion-reduce:transition-none group-hover/sidebar-section:opacity-100',
+ !section().open && '-rotate-90 opacity-100'
+ )}
+ />
+ </button>
+ </CollapsibleSection.Header>
+ <CollapsibleSection.Content
+ open={section().open}
+ contentRef={(element) => rail.registerScrollRef('favorites', element)}
+ class="flex min-h-0 flex-col gap-0.5"
+ >
+ <For each={section().items}>
+ {(favorite) => <ChannelFavoriteRow favorite={favorite} />}
+ </For>
+ </CollapsibleSection.Content>
+ </CollapsibleSection.Root>
+ </Show>
+ );
+}
diff --git a/apps/web/src/features/channels-view/components/rail/ChannelRailItems.tsx b/apps/web/src/features/channels-view/components/rail/ChannelRailItems.tsx
index 6c0bb05835..b256b5c64d 100644
--- a/apps/web/src/features/channels-view/components/rail/ChannelRailItems.tsx
+++ b/apps/web/src/features/channels-view/components/rail/ChannelRailItems.tsx
@@ -23,7 +23,11 @@ import { getBotDisplayName } from '@queries/messages/message-sender';
import { Button, cn, Tooltip } from '@ui';
import { type JSX, Match, type ParentProps, Show, Switch } from 'solid-js';
import { formatDetailedTimestamp, isDirectMessage } from '../../utils';
-import { rowKeyForChannel, useChannelsRail } from './ChannelsRailContext';
+import {
+ type ChannelRailRow,
+ rowKeyForChannel,
+ useChannelsRail,
+} from './ChannelsRailContext';
export type ChannelCallStatus = 'active' | 'incoming';
@@ -58,6 +62,8 @@ export function isPrimaryMouseDown(event: MouseEvent) {
export function ChannelRailItemContextMenu(
props: ParentProps<{
channel: ChannelEntity;
+ /** The row the menu opens from; defaults to the channel's own row. */
+ rowId?: ChannelRailRow['id'];
class?: string;
/** Rail-specific items shown after the entity actions. */
extraItems?: JSX.Element;
@@ -66,7 +72,13 @@ export function ChannelRailItemContextMenu(
const rail = useChannelsRail();
const actionList = toEntityActionListState({
controller: rail.list,
- getEntity: (row) => (row.kind === 'conversation' ? row.channel : undefined),
+ getEntity: (row) => {
+ if (row.kind === 'conversation') return row.channel;
+ if (row.kind === 'favorite' && row.favorite.entityType === 'channel') {
+ return rail.channelById(row.favorite.entityId);
+ }
+ return undefined;
+ },
});
return (
@@ -80,7 +92,7 @@ export function ChannelRailItemContextMenu(
onOpenChange={(open) => {
if (!open) return;
- rail.list.focus.set(rowKeyForChannel(props.channel.id), {
+ rail.list.focus.set(props.rowId ?? rowKeyForChannel(props.channel.id), {
reason: 'pointer',
force: true,
});
diff --git a/apps/web/src/features/channels-view/components/rail/ChannelsRail.test.tsx b/apps/web/src/features/channels-view/components/rail/ChannelsRail.test.tsx
index bc6603bb11..17f3faa210 100644
--- a/apps/web/src/features/channels-view/components/rail/ChannelsRail.test.tsx
+++ b/apps/web/src/features/channels-view/components/rail/ChannelsRail.test.tsx
@@ -174,6 +174,8 @@ vi.mock('../../queries', () => ({
).values(),
],
useChannelsByIdsQuery: () => ({ isEnabled: false }),
+ // What the real helper answers for the disabled lookup above.
+ resolveReferencedChannels: (previous: ChannelEntity[]) => previous,
}));
vi.mock('./ChannelLabelNameDialog', () => ({ promptLabelName: vi.fn() }));
vi.mock('./SmartTagDialog', () => ({ promptSmartTag: vi.fn() }));
diff --git a/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx b/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx
index 456b409676..75ffe7e8cf 100644
--- a/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx
+++ b/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx
@@ -32,11 +32,7 @@ import { toast } from '@core/component/Toast/Toast';
import { enableChannelTags } from '@core/constant/featureFlags';
import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';
import { thrownResultErrorHasCode } from '@core/util/result';
-import {
- type ChannelEntity,
- isChannelEntity,
- type WithNotification,
-} from '@entity';
+import type { ChannelEntity, WithNotification } from '@entity';
import { notificationIsRead } from '@entity/utils/notification';
import { ensureNotificationSourceLoaded } from '@notifications/notification-helpers';
import { hydrateChannelNotificationSelection } from '@queries/channel/notification-selection';
@@ -73,6 +69,7 @@ import {
type ChannelsSourceScope,
type ChannelsSources,
deduplicateChannels,
+ resolveReferencedChannels,
useChannelsByIdsQuery,
} from '../../queries';
import type {
@@ -347,25 +344,44 @@ export function ChannelsRail(props: ChannelsRailProps) {
return 'Channel labels are unavailable right now.';
};
- // A labelled channel renders under its label even before the paginated
- // Channels source reaches it, so fetch the ones the sources have not loaded.
- const labelledChannelIds = createMemo(() => [
- ...new Set(labels().flatMap((label) => label.channelIds)),
+ const favorites = createMemo(() => favoritesData()?.favorites ?? []);
+ const favoriteChannelIds = createMemo(() =>
+ favorites()
+ .filter((favorite) => favorite.entityType === 'channel')
+ .map((favorite) => favorite.entityId)
+ );
+
+ // A labelled or favorited channel has a row before the paginated Channels
+ // source reaches it, so fetch the ones the sources have not loaded: a label
+ // needs them to list its channels, a favorite row to act on its channel.
+ const referencedChannelIds = createMemo(() => [
+ ...new Set([
+ ...labels().flatMap((label) => label.channelIds),
+ ...favoriteChannelIds(),
+ ]),
]);
- const missingLabelledIds = createMemo(() => {
+ const missingChannelIds = createMemo(() => {
const loaded = new Set(channels().map((channel) => channel.id));
- return labelledChannelIds().filter((id) => !loaded.has(id));
+ return referencedChannelIds().filter((id) => !loaded.has(id));
});
- const labelledChannelsQuery = useChannelsByIdsQuery(missingLabelledIds);
- const labelledChannels = createMemo<ChannelEntity[]>((previous) => {
+ const referencedChannelsQuery = useChannelsByIdsQuery(missingChannelIds);
+ const referencedChannels = createMemo<ChannelEntity[]>(
+ (previous) =>
+ resolveReferencedChannels(previous, {
+ isEnabled: referencedChannelsQuery.isEnabled,
+ isLoading: referencedChannelsQuery.isLoading,
+ error: referencedChannelsQuery.error,
+ entities: referencedChannelsQuery.data?.entities,
+ }),
+ []
+ );
+ // Only a label puts a fetched channel in a section. A favorited one stays
+ // out of the section lists, and so out of their unread counts.
+ const labelledChannels = createMemo<ChannelEntity[]>(() => {
if (!channelTagsEnabled()) return [];
- if (!labelledChannelsQuery.isEnabled || labelledChannelsQuery.isLoading)
- return previous;
- return deduplicateChannels([
- (labelledChannelsQuery.data?.entities ?? []).filter(isChannelEntity),
- previous,
- ]);
- }, []);
+ const labelled = new Set(labels().flatMap((label) => label.channelIds));
+ return referencedChannels().filter((channel) => labelled.has(channel.id));
+ });
const allChannels = createMemo(() =>
deduplicateChannels([channels(), labelledChannels()])
@@ -373,11 +389,12 @@ export function ChannelsRail(props: ChannelsRailProps) {
const channelsById = createMemo(
() => new Map(allChannels().map((channel) => [channel.id, channel]))
);
+ const channelById = (channelId: string) =>
+ channelsById().get(channelId) ??
+ referencedChannels().find((channel) => channel.id === channelId);
const channelActivity = useChannelRailActivity(allChannels, channelCalls);
- const favorites = createMemo(() => favoritesData()?.favorites ?? []);
-
const isLabelOpen = (labelId: string) =>
!state.collapsedLabels.includes(labelId);
@@ -482,9 +499,7 @@ export function ChannelsRail(props: ChannelsRailProps) {
item.kind === 'favorite' ? item.favorite.entityId : item.channel.id;
const channel =
- item.kind === 'conversation'
- ? item.channel
- : channelsById().get(channelId);
+ item.kind === 'conversation' ? item.channel : channelById(channelId);
if (channel) activateChannel(channel, openInNewSplit);
else {
const request = ++activation;
@@ -1157,6 +1172,7 @@ export function ChannelsRail(props: ChannelsRailProps) {
selectTab,
sources: props.sources,
favorites,
+ channelById,
selectedChannel,
threadsEnabled,
threadsChannelId,
diff --git a/apps/web/src/features/channels-view/components/rail/ChannelsRailContext.ts b/apps/web/src/features/channels-view/components/rail/ChannelsRailContext.ts
index e712b5b138..8d78e3b9ba 100644
--- a/apps/web/src/features/channels-view/components/rail/ChannelsRailContext.ts
+++ b/apps/web/src/features/channels-view/components/rail/ChannelsRailContext.ts
@@ -125,6 +125,11 @@ export type ChannelsRailContext = {
selectTab: (tab: ChannelsTab) => void;
sources: ChannelsSources;
favorites: Accessor<readonly Favorite[]>;
+ /**
+ * A channel the rail has loaded, from its sections or fetched by id for a
+ * label or favorite row. Undefined until the fetch settles.
+ */
+ channelById: (channelId: string) => ChannelEntity | undefined;
selectedChannel: Accessor<ChannelPreviewSelection | undefined>;
/** Whether the Threads tab is available to this user. */
threadsEnabled: Accessor<boolean>;
diff --git a/apps/web/src/features/channels-view/components/rail/ExpandedChannelsRail.tsx b/apps/web/src/features/channels-view/components/rail/ExpandedChannelsRail.tsx
index 4987aa5fcb..765de28929 100644
--- a/apps/web/src/features/channels-view/components/rail/ExpandedChannelsRail.tsx
+++ b/apps/web/src/features/channels-view/components/rail/ExpandedChannelsRail.tsx
@@ -1,8 +1,6 @@
import { SearchBar, ViewSidebar } from '@app/components/view-shell';
import { runCreateAction } from '@app/features/command/Launcher';
-import { FavoriteIcon } from '@app/features/favorites/FavoriteIcon';
import { DEBUG_SETTING_KEYS, useDebugSetting } from '@app/lib/debugSettings';
-import { useFavoriteDisplayName } from '@app/util/favorites';
import { openNewChannelModal } from '@channel/CreateChannelModal';
import { ChannelMutedIndicator } from '@channel/components/ChannelMutedIndicator';
import { useUserId } from '@core/context/user';
@@ -18,7 +16,6 @@ import MagnifyingGlassIcon from '@phosphor/magnifying-glass.svg';
import PlusIcon from '@phosphor/plus.svg';
import SortIcon from '@phosphor/sort-ascending.svg';
import XIcon from '@phosphor/x.svg';
-import type { Favorite } from '@service-storage/generated/schemas/favorite';
import {
createDraggable,
createDroppable,
@@ -46,6 +43,7 @@ import type {
} from '../../types';
import { channelMentionsUser, formatDetailedTimestamp } from '../../utils';
import { ChannelsEmptyState } from '../ChannelsEmptyState';
+import { ChannelFavoritesSection } from './ChannelFavoriteRows';
import {
ChannelLabelMenuItems,
ChannelLabelRow,
@@ -68,7 +66,6 @@ import {
type ChannelSectionRow,
domIdForRow,
rowKeyForChannel,
- rowKeyForFavorite,
useChannelsRail,
} from './ChannelsRailContext';
import {
@@ -79,8 +76,6 @@ import {
RailListLoadingMore,
} from './ChannelsRailSection';
import {
- useChannelRailFavoriteItemState,
- useChannelRailFavoritesState,
useChannelRailItemState,
useChannelRailScopeState,
useChannelRailSectionState,
@@ -186,39 +181,6 @@ function ChannelSortDropdown(props: {
);
}
-function FavoriteOption(props: { favorite: Favorite }) {
- const rail = useChannelsRail();
- const displayName = useFavoriteDisplayName(props.favorite);
- const item = useChannelRailFavoriteItemState(() => props.favorite);
-
- return (
- <ViewSidebar.Item
- id={item().domId}
- type="button"
- role="treeitem"
- tabIndex={-1}
- class={cn(
- 'group/channel-option relative',
- !item().selected &&
- !isTouchDevice() &&
- item().focused &&
- 'bg-hover text-ink'
- )}
- active={item().selected && !isTouchDevice()}
- aria-current={item().selected ? 'page' : undefined}
- onClick={(event) =>
- rail.activateRow(rowKeyForFavorite(props.favorite), event)
- }
- >
- <ViewSidebar.Icon>
- <FavoriteIcon favorite={props.favorite} class="size-4" />
- </ViewSidebar.Icon>
- <span class="min-w-0 flex-1 truncate">{displayName()}</span>
- <ChannelMutedIndicator muted={item().muted} />
- </ViewSidebar.Item>
- );
-}
-
/**
* Drag a channel between labels. Registered once per Channels-section row: a
* row is the drag source, and also a drop target that means "into this row's
@@ -412,53 +374,6 @@ function ChannelOption(props: {
);
}
-function ExpandedFavoritesSection() {
- const rail = useChannelsRail();
- const section = useChannelRailFavoritesState();
-
- return (
- <Show when={section().items.length > 0}>
- <CollapsibleSection.Root open={section().open} sizing="content">
- <CollapsibleSection.Header
- focused={section().focused}
- focusWithin={section().containsFocus}
- >
- <button
- id={section().domId}
- type="button"
- role="treeitem"
- tabIndex={-1}
- class="relative flex h-full min-w-0 flex-1 items-center gap-1 rounded-xl px-2 text-left outline-none"
- aria-expanded={section().open}
- onMouseDown={(event) => {
- if (!isPrimaryMouseDown(event)) return;
- event.preventDefault();
- rail.toggleGroup('favorites');
- }}
- >
- <span class="min-w-0 truncate">Favorites</span>
- <CaretDownIcon
- class={cn(
- 'size-2.5 shrink-0 opacity-0 transition-[opacity,rotate] duration-200 motion-reduce:transition-none group-hover/sidebar-section:opacity-100',
- !section().open && '-rotate-90 opacity-100'
- )}
- />
- </button>
- </CollapsibleSection.Header>
- <CollapsibleSection.Content
- open={section().open}
- contentRef={(element) => rail.registerScrollRef('favorites', element)}
- class="flex min-h-0 flex-col gap-0.5"
- >
- <For each={section().items}>
- {(favorite) => <FavoriteOption favorite={favorite} />}
- </For>
- </CollapsibleSection.Content>
- </CollapsibleSection.Root>
- </Show>
- );
-}
-
function ExpandedHeader(props: { search: ChannelRailSearch }) {
const rail = useChannelsRail();
const selectTab = (value: string) => {
@@ -937,7 +852,7 @@ function ExpandedBrowse() {
</Match>
<Match when={true}>
<ViewSidebar.Content class="h-full overflow-hidden">
- <ExpandedFavoritesSection />
+ <ChannelFavoritesSection />
{/* The groups split the height left after favorites between them.
Their half-height caps resolve against this column, not the
whole sidebar, so favorites is never squeezed out. */}
diff --git a/apps/web/src/features/channels-view/queries.test.ts b/apps/web/src/features/channels-view/queries.test.ts
index 3b2fc97d5f..10baab3a9b 100644
--- a/apps/web/src/features/channels-view/queries.test.ts
+++ b/apps/web/src/features/channels-view/queries.test.ts
@@ -1,3 +1,4 @@
+import type { ChannelEntity } from '@entity/types/entity';
import { QueryClient } from '@tanstack/query-core';
import { createRoot } from 'solid-js';
import { describe, expect, it, vi } from 'vitest';
@@ -24,7 +25,20 @@ vi.mock('@entity', () => ({
}));
vi.mock('@core/context/user', () => ({ useUserId: () => () => 'user-1' }));
-import { useChannelByIdQuery, useChannelsSources } from './queries';
+import {
+ resolveReferencedChannels,
+ useChannelByIdQuery,
+ useChannelsSources,
+} from './queries';
+
+const channelEntity = (id: string) =>
+ ({
+ id,
+ type: 'channel',
+ name: id,
+ ownerId: 'viewer',
+ channelType: 'team',
+ }) as ChannelEntity;
describe('channel list query selection', () => {
it('refreshes a newly cached full edge instead of reusing it for 30 seconds', async () => {
@@ -90,6 +104,62 @@ describe('channel list query selection', () => {
});
});
+describe('channels resolved by id', () => {
+ const resolved = [channelEntity('design'), channelEntity('support')];
+ const settled = {
+ isEnabled: true,
+ isLoading: false,
+ error: undefined,
+ entities: undefined,
+ };
+
+ it('replaces the previous answer, dropping channels the lookup stops returning', () => {
+ expect(
+ resolveReferencedChannels(resolved, {
+ ...settled,
+ entities: [
+ channelEntity('design'),
+ { id: 'note', type: 'document' } as never,
+ ],
+ })
+ ).toEqual([channelEntity('design')]);
+ });
+
+ it('keeps the previous answer while the lookup is disabled or loading', () => {
+ expect(
+ resolveReferencedChannels(resolved, {
+ ...settled,
+ isEnabled: false,
+ entities: [],
+ })
+ ).toBe(resolved);
+ expect(
+ resolveReferencedChannels(resolved, {
+ ...settled,
+ isLoading: true,
+ entities: [],
+ })
+ ).toBe(resolved);
+ });
+
+ it('keeps the previous answer when a page fails instead of emptying the rows', () => {
+ expect(
+ resolveReferencedChannels(resolved, {
+ ...settled,
+ error: new Error('page failed'),
+ entities: [channelEntity('design')],
+ })
+ ).toBe(resolved);
+ // A failed first page leaves no data behind at all.
+ expect(
+ resolveReferencedChannels(resolved, {
+ ...settled,
+ error: new Error('lookup failed'),
+ })
+ ).toBe(resolved);
+ });
+});
+
describe('Threads rail source', () => {
it('lists only channels holding the user’s threads', () => {
const thread = (
diff --git a/apps/web/src/features/channels-view/queries.ts b/apps/web/src/features/channels-view/queries.ts
index af24292369..5f348e3403 100644
--- a/apps/web/src/features/channels-view/queries.ts
+++ b/apps/web/src/features/channels-view/queries.ts
@@ -175,6 +175,29 @@ export function useChannelsByIdsQuery(channelIds: Accessor<readonly string[]>) {
return query;
}
+/**
+ * The channels a by-id lookup has resolved.
+ *
+ * A settled lookup answers for every id it asked about — its data covers the
+ * pages fetched so far — so it replaces the previous answer and a channel it
+ * stops returning reads as unresolved. A pending or failed lookup keeps the
+ * last answer instead, so a failed page does not empty the rows built from it.
+ */
+export function resolveReferencedChannels(
+ previous: ChannelEntity[],
+ lookup: {
+ isEnabled: boolean;
+ isLoading: boolean;
+ error: unknown;
+ entities: readonly EntityData[] | undefined;
+ }
+): ChannelEntity[] {
+ if (!lookup.isEnabled || lookup.isLoading || lookup.error || !lookup.entities)
+ return previous;
+
+ return lookup.entities.filter(isChannelEntity);
+}
+
export function deduplicateChannels(
collections: readonly (readonly ChannelEntity[])[]
): ChannelEntity[] {
diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.md
index 19656c7fde..befdb4e00b 100644
--- a/docs/AGENT_GUIDE/channels.md
+++ b/docs/AGENT_GUIDE/channels.md
@@ -423,6 +423,11 @@ Deferred navigation waits until the destination is applied; an unavailable split
must leave unread state unchanged. Join-only channels remain
blocked after hydration, including on mobile.
+Right-clicking a favorite opens the same menu as its channel's row in the
+sections below — `Mark Read`, `Unfavorite`, `Mute notifications`, `Copy Link`,
+and the label actions when channel labels are enabled — and focuses the
+favorite row rather than the channel's own row.
+
### Threads tab
The `enable-channel-threads-preview` feature flag adds a third `Threads` tab.