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.

fix(sidebar): make open full screen behave consistently (#4830)

Seamus87ce8f63e88c
diff --git a/apps/web/src/components/app/app-sidebar/sidebar.tsx b/apps/web/src/components/app/app-sidebar/sidebar.tsx
index de9d3fd396..0fcb2ac7b2 100644
--- a/apps/web/src/components/app/app-sidebar/sidebar.tsx
+++ b/apps/web/src/components/app/app-sidebar/sidebar.tsx
@@ -672,11 +672,20 @@ const SidebarDropdownLink = (
const canOpenInNewSplit = () =>
globalSplitManager()?.canAppendSplit() ?? false;
+ const canOpenFullscreen = () => layout.getSplitCount() > 1;
const openInNewSplit = () => {
if (canOpenInNewSplit()) open(true);
};
const openInCurrentSplit = () => open(false);
- const openFullscreen = () => open(false)?.toggleSpotlight(true);
+ const openFullscreen = () => {
+ analytics.track('sidebar_click', { view: props.id });
+ const handle = layout.replaceAllSplits(
+ { type: 'component', id: props.id, params: props.params },
+ { referredFrom: 'sidebar' }
+ );
+ if (props.id === 'search' && handle) requestSearchFocus(handle.id);
+ globalSplitManager()?.returnFocus();
+ };
const ContextMenuTriggerItem = (
triggerProps: ComponentProps<typeof ContextMenu.Trigger>
@@ -690,7 +699,9 @@ const SidebarDropdownLink = (
onClick={openInNewSplit}
disabled={!canOpenInNewSplit()}
/>
- <MenuItem text="Open fullscreen" onClick={openFullscreen} />
+ <Show when={canOpenFullscreen()}>
+ <MenuItem text="Open fullscreen" onClick={openFullscreen} />
+ </Show>
<MenuItem text="Open in current split" onClick={openInCurrentSplit} />
</ContextMenuContent>
</ContextMenu.Portal>
@@ -1511,6 +1522,7 @@ const SidebarLink = (props: SidebarLinkProps) => {
}) as const;
const canOpenInNewSplit = () =>
globalSplitManager()?.canAppendSplit() ?? true;
+ const canOpenFullscreen = () => layout.getSplitCount() > 1;
const openInCurrentSplit = () =>
layout.openWithSplit(content(), {
@@ -1534,8 +1546,11 @@ const SidebarLink = (props: SidebarLinkProps) => {
};
const openFullscreen = () => {
- const split = openInCurrentSplit();
- split?.toggleSpotlight(true);
+ const split = layout.replaceAllSplits(content(), {
+ referredFrom: 'sidebar',
+ });
+ if (props.id === 'search' && split) requestSearchFocus(split.id);
+ globalSplitManager()?.returnFocus();
};
return (
@@ -1660,7 +1675,9 @@ const SidebarLink = (props: SidebarLinkProps) => {
onClick={openInNewSplit}
disabled={!canOpenInNewSplit()}
/>
- <MenuItem text="Open fullscreen" onClick={openFullscreen} />
+ <Show when={canOpenFullscreen()}>
+ <MenuItem text="Open fullscreen" onClick={openFullscreen} />
+ </Show>
<MenuItem text="Open in current split" onClick={openInCurrentSplit} />
</ContextMenuContent>
</ContextMenu.Portal>
diff --git a/apps/web/src/components/app/split-layout/layoutManager.ts b/apps/web/src/components/app/split-layout/layoutManager.ts
index 5f88c2bc73..419cce39e9 100644
--- a/apps/web/src/components/app/split-layout/layoutManager.ts
+++ b/apps/web/src/components/app/split-layout/layoutManager.ts
@@ -327,7 +327,7 @@ export type SplitManager = {
/** Replace all splits with a single split containing the given content. */
replaceAllSplits: (
content: SplitContent,
- options?: { referredFrom?: string | null }
+ options?: { referredFrom?: ReferredFrom }
) => SplitHandle;
/** Check if a split exists by its split id */
@@ -1374,12 +1374,39 @@ export function createSplitLayout(
content: SplitContent,
options: { referredFrom?: ReferredFrom } = {}
): SplitHandle {
- reconcileSplits([content]);
- const handle = getSplitByContent(content.type, content.id);
+ const visibleSplits = state.splits.filter((split) => !isExcluded(split));
+ const splitToKeep =
+ visibleSplits.find((split) => sameContent(split.content, content)) ??
+ visibleSplits[0];
+
+ if (!splitToKeep) {
+ return createNewSplit({
+ content,
+ activate: true,
+ referredFrom: options.referredFrom ?? null,
+ });
+ }
+
+ for (const split of visibleSplits) {
+ if (split.id !== splitToKeep.id) {
+ removeSplit(split.id, false);
+ }
+ }
+
+ const handle = getSplit(splitToKeep.id);
if (handle) {
+ if (!sameContent(splitToKeep.content, content)) {
+ handle.replace({
+ next: content,
+ mergeHistory: false,
+ referredFrom: options.referredFrom,
+ });
+ }
handle.activate();
+ unSpotlightSplit();
return handle;
}
+
return createNewSplit({
content,
activate: true,
diff --git a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
index 0abf5f0d8c..caab4aa709 100644
--- a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
+++ b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
@@ -185,6 +185,69 @@ describe('layoutManager', () => {
});
});
+ describe('replaceAllSplits', () => {
+ it('keeps the first split that already contains the target content', () => {
+ createRoot((dispose) => {
+ const target = {
+ type: 'component',
+ id: 'documents',
+ } satisfies SplitContent;
+ const manager = createSplitLayout(createMockOrchestrator(), [
+ { type: 'component', id: 'inbox' },
+ target,
+ { type: 'component', id: 'documents' },
+ { type: 'md', id: 'right' },
+ ]);
+
+ const keptSplitId = manager.splits()[1].id;
+ const keptSplit = manager.getSplit(keptSplitId)!;
+ const historyBefore = keptSplit.history();
+ const handle = manager.replaceAllSplits(target, {
+ referredFrom: 'sidebar',
+ });
+
+ expect(manager.splits()).toHaveLength(1);
+ expect(manager.splits()[0].id).toBe(keptSplitId);
+ expect(manager.splits()[0].content).toEqual(target);
+ expect(manager.activeSplitId()).toBe(handle.id);
+ expect(handle.history()).toEqual(historyBefore);
+
+ dispose();
+ });
+ });
+
+ it('keeps the 0th split and replaces it when the target content is not open', () => {
+ createRoot((dispose) => {
+ const manager = createSplitLayout(createMockOrchestrator(), [
+ { type: 'component', id: 'inbox' },
+ { type: 'md', id: 'right' },
+ ]);
+ const keptSplitId = manager.splits()[0].id;
+ manager.spotlightSplit(manager.splits()[1].id);
+
+ const target = {
+ type: 'component',
+ id: 'documents',
+ } satisfies SplitContent;
+ const handle = manager.replaceAllSplits(target, {
+ referredFrom: 'sidebar',
+ });
+
+ expect(manager.splits()).toHaveLength(1);
+ expect(manager.splits()[0].id).toBe(keptSplitId);
+ expect(manager.splits()[0].content).toEqual(target);
+ expect(manager.activeSplitId()).toBe(handle.id);
+ expect(handle.isSpotLight()).toBe(false);
+ expect(handle.previousContent()).toEqual({
+ type: 'component',
+ id: 'inbox',
+ });
+
+ dispose();
+ });
+ });
+ });
+
describe('indexed insertion', () => {
it('creates a split at the requested index', () => {
createRoot((dispose) => {
diff --git a/apps/web/src/features/channel/sidebar/channels-unread-widget.tsx b/apps/web/src/features/channel/sidebar/channels-unread-widget.tsx
index a717f68dd4..362d025a23 100644
--- a/apps/web/src/features/channel/sidebar/channels-unread-widget.tsx
+++ b/apps/web/src/features/channel/sidebar/channels-unread-widget.tsx
@@ -11,6 +11,7 @@ import {
useGlobalBlockOrchestrator,
useGlobalNotificationSource,
} from '@components/app/GlobalAppState';
+import { useSplitLayout } from '@components/app/split-layout/layout';
import {
ContextMenuContent,
MenuGroup,
@@ -204,6 +205,7 @@ function ChannelGroupItem(props: {
isSlim?: boolean;
onFloatingOpenChange?: (open: boolean) => void;
}) {
+ const layout = useSplitLayout();
const notificationSource = useGlobalNotificationSource();
const [isVisible, setIsVisible] = createSignal(!props.animate);
@@ -232,6 +234,7 @@ function ChannelGroupItem(props: {
const canOpenInNewSplit = () =>
globalSplitManager()?.canAppendSplit() ?? false;
+ const canOpenFullscreen = () => layout.getSplitCount() > 1;
const navigateToLatestNotification = (newSplit = false) => {
const manager = globalSplitManager();
@@ -259,13 +262,16 @@ function ChannelGroupItem(props: {
const openFullscreen = () => {
const { params } = getChannelNotificationParams(latestNotification());
- globalSplitManager()?.createPopoverSplit({
- content: {
+ const split = layout.replaceAllSplits(
+ {
type: 'channel',
id: props.group.entityId,
params,
},
- });
+ { referredFrom: 'sidebar' }
+ );
+ globalSplitManager()?.returnFocus();
+ return split;
};
const isSlim = () => props.isSlim ?? false;
@@ -356,7 +362,9 @@ function ChannelGroupItem(props: {
onClick={openInNewSplit}
disabled={!canOpenInNewSplit()}
/>
- <MenuItem text="Open fullscreen" onClick={openFullscreen} />
+ <Show when={canOpenFullscreen()}>
+ <MenuItem text="Open fullscreen" onClick={openFullscreen} />
+ </Show>
<MenuItem
text="Open in current split"
onClick={openInCurrentSplit}
diff --git a/apps/web/src/features/favorites/sidebar/favorites-section.tsx b/apps/web/src/features/favorites/sidebar/favorites-section.tsx
index 75fe84fc5b..81e3a496a8 100644
--- a/apps/web/src/features/favorites/sidebar/favorites-section.tsx
+++ b/apps/web/src/features/favorites/sidebar/favorites-section.tsx
@@ -385,11 +385,18 @@ const FavoriteRow = (props: {
const open = (e: MouseEvent) => openFavorite(e.shiftKey);
const canOpenInNewSplit = () =>
globalSplitManager()?.canAppendSplit() ?? false;
+ const canOpenFullscreen = () => layout.getSplitCount() > 1;
const openInCurrentSplit = () => openFavorite(false);
const openInNewSplit = () => {
if (canOpenInNewSplit()) openFavorite(true);
};
- const openFullscreen = () => layout.popoverSplit(content());
+ const openFullscreen = () => {
+ const split = layout.replaceAllSplits(content(), {
+ referredFrom: 'sidebar',
+ });
+ globalSplitManager()?.returnFocus();
+ return split;
+ };
const markAllAsRead = () => {
void notificationSource.bulkMarkAsRead(props.notifications());
};
@@ -476,7 +483,9 @@ const FavoriteRow = (props: {
onClick={openInNewSplit}
disabled={!canOpenInNewSplit()}
/>
- <MenuItem text="Open fullscreen" onClick={openFullscreen} />
+ <Show when={canOpenFullscreen()}>
+ <MenuItem text="Open fullscreen" onClick={openFullscreen} />
+ </Show>
<MenuItem
text="Open in current split"
onClick={openInCurrentSplit}