Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat: preview cleanup (#141)
gbirman23fb59d9476b
diff --git a/js/app/packages/app/component/Soup.tsx b/js/app/packages/app/component/Soup.tsxindex 403429cd53..656a460f3d 100644--- a/js/app/packages/app/component/Soup.tsx+++ b/js/app/packages/app/component/Soup.tsx@@ -12,6 +12,7 @@ import { fileTypeToBlockName } from '@core/constant/allBlocks';import { ENABLE_FOLDER_UPLOAD } from '@core/constant/featureFlags';import { fileFolderDrop } from '@core/directive/fileFolderDrop';import { TOKENS } from '@core/hotkey/tokens';+import type { BlockOrchestrator } from '@core/orchestrator';import {CONDITIONAL_VIEWS,DEFAULT_VIEWS,@@ -23,6 +24,7 @@ import {import { handleFileFolderDrop } from '@core/util/upload';import { ContextMenu } from '@kobalte/core/context-menu';import { Tabs } from '@kobalte/core/tabs';+import type { EntityData } from '@macro-entity';import {queryKeys,useQueryClient as useEntityQueryClient,@@ -52,6 +54,7 @@ import { HelpDrawer } from './HelpDrawer';import { SplitHeaderLeft } from './split-layout/components/SplitHeader';import { SplitTabs } from './split-layout/components/SplitTabs';import { SplitToolbarRight } from './split-layout/components/SplitToolbar';+import type { SplitPanelContextType } from './split-layout/context';import { SplitPanelContext } from './split-layout/context';import { useSplitPanelOrThrow } from './split-layout/layoutUtils';import { UnifiedListView } from './UnifiedListView';@@ -124,6 +127,87 @@ const ViewWithSearch: Component<{);};+const PreviewPanelContent: Component<{+ selectedEntity: EntityData;+ orchestrator: BlockOrchestrator;+ splitPanelContext: SplitPanelContextType;+}> = (props) => {+ const blockInstance = () =>+ props.orchestrator.createBlockInstance(+ props.selectedEntity.type === 'document'+ ? fileTypeToBlockName(props.selectedEntity.fileType)+ : props.selectedEntity.type,+ props.selectedEntity.id+ );+ const [interactedWithMouseDown, setInteractedWithMouseDown] =+ createSignal(false);++ createRenderEffect((prevId: string) => {+ const id = props.selectedEntity.id;+ if (id !== prevId) {+ setInteractedWithMouseDown(false);+ }+ return id;+ }, props.selectedEntity.id);++ return (+ <div+ class="size-full"+ onFocusIn={(event) => {+ if (interactedWithMouseDown()) return;+ const relatedTarget = event.relatedTarget as HTMLElement;+ const currentTarget = event.currentTarget as HTMLElement;++ if (!currentTarget.contains(relatedTarget)) {+ relatedTarget.focus();+ }+ }}+ onPointerDown={() => {+ setInteractedWithMouseDown(true);+ }}+ >+ <SplitPanelContext.Provider+ value={{+ ...props.splitPanelContext,+ layoutRefs: {+ ...props.splitPanelContext.layoutRefs,+ headerLeft: undefined,+ headerRight: undefined,+ },+ halfSplitState: () => ({+ side: 'right',+ percentage: 30,+ }),+ }}+ >+ <Dynamic component={blockInstance().element} />+ </SplitPanelContext.Provider>+ </div>+ );+};++const PreviewPanel: Component<{+ selectedEntity: EntityData | undefined;+ orchestrator: BlockOrchestrator;+ splitPanelContext: SplitPanelContextType;+}> = (props) => {+ return (+ <div class="flex flex-row size-full w-[70%] shrink-0">+ <Show+ when={props.selectedEntity?.type !== 'project' && props.selectedEntity}+ >+ {(selectedEntity) => (+ <PreviewPanelContent+ selectedEntity={selectedEntity()}+ orchestrator={props.orchestrator}+ splitPanelContext={props.splitPanelContext}+ />+ )}+ </Show>+ </div>+ );+};+export function Soup() {const authenticated = useIsAuthenticated();if (!authenticated()) return <Navigate href="/" />;@@ -213,17 +297,17 @@ export function Soup() {const TabContextMenu = (props: { value: ViewId; label: string }) => {const [isModalOpen, setIsModalOpen] = createSignal(false);+ const isDefaultView = () =>+ VIEWCONFIG_DEFAULTS_NAMES.includes(props.value as View);return (- <Show when={!VIEWCONFIG_DEFAULTS_NAMES.includes(props.value as any)}>+ <Show when={!isDefaultView()}><ContextMenu><ContextMenu.Trigger class="absolute inset-0" /><ContextMenu.Portal><ContextMenuContent mobileFullScreen><MenuItemtext="Rename"- disabled={VIEWCONFIG_DEFAULTS_NAMES.includes(- props.value as any- )}+ disabled={isDefaultView()}onClick={() => {setTimeout(() => {setIsModalOpen(true);@@ -233,9 +317,7 @@ export function Soup() {/><MenuItemtext="Delete"- disabled={VIEWCONFIG_DEFAULTS_NAMES.includes(- props.value as any- )}+ disabled={isDefaultView()}onClick={() => {saveViewMutation.mutate({id: props.value,@@ -336,71 +418,11 @@ export function Soup() {</Tabs></SplitPanelContext.Provider><Show when={preview()}>- <div class="flex flex-row size-full w-[70%] shrink-0">- {/* must access property, id, on selectedEntity in order to make it reactive */}- <Show when={!!selectedEntity()?.id && selectedEntity()}>- {(selectedEntity) => {- const entity = selectedEntity();- if (entity.type === 'project') return null;- const blockInstance = () =>- orchestrator.createBlockInstance(- entity.type === 'document'- ? fileTypeToBlockName(entity.fileType)- : entity.type,- entity.id- );- const [interactedWithMouseDown, setInteractedWithMouseDown] =- createSignal(false);-- // Reset interaction state whenever the previewed entity changes- createRenderEffect(- (prevId: string | undefined) => {- const id = entity.id as string | undefined;- if (id !== prevId) {- setInteractedWithMouseDown(false);- }- return id;- },- entity.id as string | undefined- );-- return (- <div- class="size-full"- onFocusIn={(event) => {- if (interactedWithMouseDown()) return;- const relatedTarget = event.relatedTarget as HTMLElement;- const currentTarget = event.currentTarget as HTMLElement;-- if (!currentTarget.contains(relatedTarget)) {- relatedTarget.focus();- }- }}- onPointerDown={() => {- setInteractedWithMouseDown(true);- }}- >- <SplitPanelContext.Provider- value={{- ...splitPanelContext,- layoutRefs: {- ...splitPanelContext.layoutRefs,- headerLeft: undefined,- headerRight: undefined,- },- halfSplitState: () => ({- side: 'right',- percentage: 30,- }),- }}- >- <Dynamic component={blockInstance().element} />- </SplitPanelContext.Provider>- </div>- );- }}- </Show>- </div>+ <PreviewPanel+ selectedEntity={selectedEntity()}+ orchestrator={orchestrator}+ splitPanelContext={splitPanelContext}+ /></Show></div><Show when={showHelpDrawer().has(selectedView())}>@@ -455,15 +477,18 @@ export const useUpsertSavedViewMutation = () => {id: ViewConfigDefaultsName | string;}) => {+ const isDefaultView = VIEWCONFIG_DEFAULTS_NAMES.includes(+ viewData.id as View+ );if ('config' in viewData) {// if data id is in defaults, exclude default, set up args to create new view- if (VIEWCONFIG_DEFAULTS_NAMES.includes(viewData.id as any)) {+ if (isDefaultView) {// don't exclude default view on editing default view config// await storageServiceClient.views.excludeDefaultView({// defaultViewId: viewData.id!,// });viewData.id = undefined;- viewData.name = 'My ' + viewData.name;+ viewData.name = `My ${viewData.name}`;}// create new viewif (!viewData.id) {@@ -481,7 +506,7 @@ export const useUpsertSavedViewMutation = () => {}} else {// delete or exclude view- if (VIEWCONFIG_DEFAULTS_NAMES.includes(viewData.id as any)) {+ if (isDefaultView) {// for now don't exclude default view// return await storageServiceClient.views.excludeDefaultView({// defaultViewId: viewData.id,diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsxindex add6e48695..f68218125d 100644--- a/js/app/packages/app/component/SoupContext.tsx+++ b/js/app/packages/app/component/SoupContext.tsx@@ -45,7 +45,7 @@ import {export type UnifiedListContext = {viewsDataStore: Store<ViewDataMap>;- setViewDataStore: SetStoreFunction<ViewDataMap>;+ setViewDataStore: SetStoreFunction<Partial<ViewDataMap>>;selectedView: Accessor<ViewId>;setSelectedView: Setter<ViewId>;virtualizerHandleSignal: Signal<VirtualizerHandle | undefined>;diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsxindex 6179139e98..0e7078c9ce 100644--- a/js/app/packages/app/component/UnifiedListView.tsx+++ b/js/app/packages/app/component/UnifiedListView.tsx@@ -1321,106 +1321,105 @@ export function UnifiedListView(props: UnifiedListViewProps) {entity={contextAndModalState.selectedEntity}/><ContextMenu.Portal>- <ContextMenuContent mobileFullScreen>- <Show when={isTouchDevice && isMobileWidth()}>- <Entity- entity={contextAndModalState.selectedEntity!}- timestamp={- sortType() === 'viewed_at'- ? contextAndModalState.selectedEntity!.viewedAt- : sortType() === 'created_at'- ? contextAndModalState.selectedEntity!.createdAt- : undefined- }- />- <MenuSeparator />- </Show>- <Show when={markEntityAsDone}>- {(fnAccessor) => (+ <Show when={contextAndModalState.selectedEntity}>+ {(selectedEntity) => (+ <ContextMenuContent mobileFullScreen>+ <Show when={isTouchDevice && isMobileWidth()}>+ <Entity+ entity={selectedEntity()}+ timestamp={+ sortType() === 'viewed_at'+ ? selectedEntity().viewedAt+ : sortType() === 'created_at'+ ? selectedEntity().createdAt+ : undefined+ }+ />+ <MenuSeparator />+ </Show>+ <Show when={markEntityAsDone}>+ {(fnAccessor) => {+ const entityDisabled = (+ entity: WithNotification<EntityData>+ ) => {+ return entity.type === 'email'+ ? entity.done+ : entity.notifications?.().every(({ done }) => done);+ };+ return (+ <MenuItem+ text="Mark as Done"+ onClick={() => fnAccessor()(selectedEntity())}+ disabled={entityDisabled(selectedEntity())}+ />+ );+ }}+ </Show><MenuItem- text="Mark as Done"- onClick={() =>- fnAccessor()(contextAndModalState.selectedEntity!)+ text="Delete"+ onClick={() => deleteDssItem(selectedEntity())}+ disabled={+ selectedEntity().type !== 'document' &&+ selectedEntity().type !== 'project' &&+ selectedEntity().type !== 'chat'}+ />+ <MenuItem+ text="Rename"+ onClick={() => openEntityModal('rename')}disabled={- contextAndModalState.selectedEntity?.type === 'email'- ? contextAndModalState.selectedEntity.done- : contextAndModalState.selectedEntity- ?.notifications?.()- .every(({ done }) => done)+ selectedEntity().type !== 'document' &&+ selectedEntity().type !== 'chat'}/>- )}- </Show>- <MenuItem- text="Delete"- onClick={() =>- deleteDssItem(contextAndModalState.selectedEntity!)- }- disabled={- contextAndModalState.selectedEntity?.type !== 'document' &&- contextAndModalState.selectedEntity?.type !== 'project' &&- contextAndModalState.selectedEntity?.type !== 'chat'- }- />- <MenuItem- text="Rename"- onClick={() => openEntityModal('rename')}- disabled={- contextAndModalState.selectedEntity?.type !== 'document' &&- contextAndModalState.selectedEntity?.type !== 'chat'- }- />- <MenuItem- text="Move to Project"- onClick={() => {- openEntityModal('moveToProject');- }}- disabled={- contextAndModalState.selectedEntity?.type !== 'document' &&- contextAndModalState.selectedEntity?.type !== 'project' &&- contextAndModalState.selectedEntity?.type !== 'chat'- // https://github.com/macro-inc/macro-api/pull/2395- // || !hasProjectPermissions()- }- />- <MenuItem- text="Copy"- onClick={() => {- copyDssItem({ entity: contextAndModalState.selectedEntity! });- }}- disabled={- contextAndModalState.selectedEntity?.type !== 'document' &&- contextAndModalState.selectedEntity?.type !== 'chat'- }- />- <MenuItem- text="Open in new split"- onClick={() => {- const splitManager = globalSplitManager();- if (!splitManager) {- console.error('No split manager available');- return;- }- if (- contextAndModalState.selectedEntity?.type === 'document'- ) {- const { fileType, id } =- contextAndModalState.selectedEntity!;- splitManager.createNewSplit({- type: fileTypeToBlockName(fileType),- id,- });- } else {- const { id, type } = contextAndModalState.selectedEntity!;- splitManager.createNewSplit({- type,- id,- });- }- }}- />- </ContextMenuContent>+ <MenuItem+ text="Move to Project"+ onClick={() => {+ openEntityModal('moveToProject');+ }}+ disabled={+ selectedEntity().type !== 'document' &&+ selectedEntity().type !== 'project' &&+ selectedEntity().type !== 'chat'+ }+ />+ <MenuItem+ text="Copy"+ onClick={() => {+ copyDssItem({ entity: selectedEntity() });+ }}+ disabled={+ selectedEntity().type !== 'document' &&+ selectedEntity().type !== 'chat'+ }+ />+ <MenuItem+ text="Open in new split"+ onClick={() => {+ const splitManager = globalSplitManager();+ if (!splitManager) {+ console.error('No split manager available');+ return;+ }+ const entity = selectedEntity();+ if (entity.type === 'document') {+ const { fileType, id } = entity;+ splitManager.createNewSplit({+ type: fileTypeToBlockName(fileType),+ id,+ });+ } else {+ const { id, type } = entity;+ splitManager.createNewSplit({+ type,+ id,+ });+ }+ }}+ />+ </ContextMenuContent>+ )}+ </Show></ContextMenu.Portal></ContextMenu.Trigger></ContextMenu>diff --git a/js/app/packages/app/component/split-layout/context.ts b/js/app/packages/app/component/split-layout/context.tsindex 1bb80186f7..7033da7521 100644--- a/js/app/packages/app/component/split-layout/context.ts+++ b/js/app/packages/app/component/split-layout/context.ts@@ -12,7 +12,7 @@ export type HalfSplitState = {side: 'left' | 'right';};-export const SplitPanelContext = createContext<{+export type SplitPanelContextType = {handle: SplitHandle;splitHotkeyScope: string;unifiedListContext: UnifiedListContext;@@ -28,4 +28,6 @@ export const SplitPanelContext = createContext<{toolbarLeft?: HTMLDivElement;toolbarRight?: HTMLDivElement;};-}>();+};++export const SplitPanelContext = createContext<SplitPanelContextType>();diff --git a/js/app/packages/block-project/component/Block.tsx b/js/app/packages/block-project/component/Block.tsxindex d8cf452adc..18bf31c7b3 100644--- a/js/app/packages/block-project/component/Block.tsx+++ b/js/app/packages/block-project/component/Block.tsx@@ -75,16 +75,12 @@ const Block: Component = () => {};const splitContext = useSplitPanelOrThrow();- const { selectedView, setSelectedView, setViewDataStore, viewsDataStore } =+ const { selectedView, setSelectedView, setViewDataStore } =splitContext.unifiedListContext;- const isPreview = viewsDataStore[selectedView()].display.preview;-createRenderEffect(() => {const previousView = untrack(selectedView);- if (isPreview) return;-setSelectedView(projectId);setViewDataStore(projectId, {@@ -98,7 +94,7 @@ const Block: Component = () => {onCleanup(() => {setSelectedView(previousView);- (setViewDataStore as any)(projectId, undefined);+ setViewDataStore(projectId, undefined);});});