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.

Scope inline preview panels to project content (#7468)

Jacob Beckerman788f2f5377f5
diff --git a/apps/web/src/features/block-project/component/Block.tsx b/apps/web/src/features/block-project/component/Block.tsx
index a58f9c9b8a..de287e50d0 100644
--- a/apps/web/src/features/block-project/component/Block.tsx
+++ b/apps/web/src/features/block-project/component/Block.tsx
@@ -10,6 +10,7 @@ import { SoupViewList } from '@app/features/next-soup/soup-view/soup-view';
import { SoupViewContextProvider } from '@app/features/next-soup/soup-view/soup-view-context';
import { getIsSpecialProject } from '@block-project/isSpecial';
import { SidePanel } from '@components/app/side-panel';
+import { SplitPanelContext } from '@components/app/split-layout/context';
import { useBlockId } from '@core/block';
import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';
import { FileDropOverlay } from '@core/component/FileDropOverlay';
@@ -25,6 +26,7 @@ import {
import { refetchSoupEntity } from '@queries/soup/cache';
import { refetchResources } from '@service-storage/util/refetchResources';
import { type Component, createSignal, Show } from 'solid-js';
+import { useProjectScopedPanel } from './project-scoped-panel';
import { ProjectSidePanelSections } from './sidepanel/ProjectSidePanelSections';
import { TopBar } from './TopBar';
@@ -101,7 +103,7 @@ const Block: Component = () => {
return (
<DocumentBlockContainer>
<div
- class="size-full bg-surface flex flex-col relative"
+ class="size-full flex flex-col relative"
use:fileFolderDrop={{
onDragStart: () => setIsDragging(true),
onDragEnd: () => setIsDragging(false),
@@ -134,11 +136,21 @@ const Block: Component = () => {
);
};
-const ProjectEntityList = (props: {
+type ProjectEntityListProps = {
scopeId: string;
projectId: string;
soup: SoupState;
-}) => {
+};
+
+const ProjectEntityList = (props: ProjectEntityListProps) => {
+ return (
+ <SplitPanelContext.Provider value={useProjectScopedPanel(props.projectId)}>
+ <ProjectEntityListContent {...props} />
+ </SplitPanelContext.Provider>
+ );
+};
+
+const ProjectEntityListContent = (props: ProjectEntityListProps) => {
return (
<SoupContextProvider soup={props.soup}>
<SoupViewContextProvider
diff --git a/apps/web/src/features/block-project/component/project-scoped-panel.test.tsx b/apps/web/src/features/block-project/component/project-scoped-panel.test.tsx
new file mode 100644
index 0000000000..49fc43ef32
--- /dev/null
+++ b/apps/web/src/features/block-project/component/project-scoped-panel.test.tsx
@@ -0,0 +1,53 @@
+import {
+ SplitPanelContext,
+ type SplitPanelContextType,
+} from '@components/app/split-layout/context';
+import type { SplitContent } from '@components/app/split-layout/layoutManager';
+import { cleanup, render } from '@solidjs/testing-library';
+import { afterEach, expect, it, vi } from 'vitest';
+import { useProjectScopedPanel } from './project-scoped-panel';
+
+afterEach(cleanup);
+
+const homeContent: SplitContent = { type: 'component', id: 'home' };
+
+function hostPanel(isInlinePreview: boolean) {
+ const goBack = vi.fn();
+ return {
+ goBack,
+ panel: {
+ isInlinePreview,
+ handle: { content: () => homeContent, goBack },
+ } as unknown as SplitPanelContextType,
+ };
+}
+
+function scopedPanelIn(host: SplitPanelContextType) {
+ let scoped: SplitPanelContextType | undefined;
+ render(() => (
+ <SplitPanelContext.Provider value={host}>
+ {(() => {
+ scoped = useProjectScopedPanel('project-1');
+ return null;
+ })()}
+ </SplitPanelContext.Provider>
+ ));
+ if (!scoped) throw new Error('hook did not run');
+ return scoped;
+}
+
+it('scopes an inline preview to the project instead of the host view', () => {
+ const host = hostPanel(true);
+ const scoped = scopedPanelIn(host.panel);
+
+ expect(scoped.handle.content()).toEqual({ type: 'project', id: 'project-1' });
+ expect(scoped.isInlinePreview).toBe(true);
+ scoped.handle.goBack();
+ expect(host.goBack).toHaveBeenCalledOnce();
+});
+
+it('keeps the panel of a project opened in its own split', () => {
+ const host = hostPanel(false);
+
+ expect(scopedPanelIn(host.panel)).toBe(host.panel);
+});
diff --git a/apps/web/src/features/block-project/component/project-scoped-panel.ts b/apps/web/src/features/block-project/component/project-scoped-panel.ts
new file mode 100644
index 0000000000..229d4d92cf
--- /dev/null
+++ b/apps/web/src/features/block-project/component/project-scoped-panel.ts
@@ -0,0 +1,23 @@
+import type { SplitPanelContextType } from '@components/app/split-layout/context';
+import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+
+/**
+ * An inline preview (e.g. a folder opened from Home) shares its host's panel,
+ * whose content is the host's list view. The soup list derives its view, tab
+ * presets, and persisted filters from that content, so it would treat the
+ * folder as the host view and drop the folder's own filters. Scope the
+ * content to this project, as it is when the folder has its own split.
+ */
+export function useProjectScopedPanel(
+ projectId: string
+): SplitPanelContextType {
+ const panel = useSplitPanelOrThrow();
+ if (!panel.isInlinePreview) return panel;
+ return {
+ ...panel,
+ handle: {
+ ...panel.handle,
+ content: () => ({ type: 'project', id: projectId }),
+ },
+ };
+}