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
fix(soup): preview panel stability (#4714)
dev-rbacfd069668da
diff --git a/js/app/packages/app/component/SoupChatInput.tsx b/js/app/packages/app/component/SoupChatInput.tsxindex 7063eefd9e..3a2e465f78 100644--- a/js/app/packages/app/component/SoupChatInput.tsx+++ b/js/app/packages/app/component/SoupChatInput.tsx@@ -1,5 +1,4 @@import { useAnalytics } from '@app/component/analytics-context';-import { useSoup } from '@app/component/next-soup/soup-context';import { buildChatEditor } from '@core/component/AI/component/input/buildChatEditor';import type { ChatSendInput } from '@core/component/AI/component/input/buildRequest';import {@@ -28,7 +27,6 @@ import { useSplitPanelOrThrow } from './split-layout/layoutUtils';function SoupChatInputInner() {const analytics = useAnalytics();const splitPanelContext = useSplitPanelOrThrow();- const soup = useSoup();const input = useChatInputContext();const { getAttachmentFromMention } = useGetChatAttachmentInfo();@@ -126,7 +124,7 @@ function SoupChatInputInner() {<divref={containerRef}class="absolute bottom-0 inset-x-px pb-2 px-2 flex justify-center pointer-events-none"- classList={{ hidden: !!soup.previewEntity() }}+ classList={{ hidden: splitPanelContext.previewState[0]() }}style={{'background-image': `linear-gradient(transparent, var(--color-surface) 85%)`,}}diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsxindex 789ab2c2a4..c34c27e123 100644--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx@@ -5,6 +5,7 @@ import { SoupViewContextGroup } from '@app/component/next-soup/soup-view/filtersimport { SoupViewContextSort } from '@app/component/next-soup/soup-view/filters-bar/soup-view-context-sort';import { UnifiedFilterDropdown } from '@app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown';import { useFilterRefinements } from '@app/component/next-soup/soup-view/filters-bar/use-filter-refinements';+import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-context';import { usePreviewPaneVisiblity } from '@app/component/next-soup/soup-view/use-preview-pane-visibility';import {SplitToolbarLeft,@@ -34,36 +35,21 @@ export function SoupFiltersBar() {const panel = useSplitPanelOrThrow();const analytics = useAnalytics();const soup = useSoup();+ const { setPreviewOpen } = useSoupView();- const { isWideSplitPanel } = usePreviewPaneVisiblity();+ const { isWideSplitPanel, previewOpen, selectedEntity } =+ usePreviewPaneVisiblity();const togglePreview = () => {- const currentPreview = soup.previewEntity();- if (currentPreview) {+ if (previewOpen()) {+ setPreviewOpen(false);soup.setPreviewEntity(undefined);return;}- let focused = soup.focus.id();-- if (!focused) {- const allRows = soup.rows();-- const firstEntityIndex = allRows.findIndex(- (row) => !row.getIsGrouped() && !row.getIsLoadMore()- );-- if (firstEntityIndex === -1) return;-- const result = soup.navigate.toIndex(firstEntityIndex);-- if (!result) return;-- focused = result.row.id;- }-analytics.track('preview_panel_use');- soup.setPreviewEntity(focused);+ soup.setPreviewEntity(selectedEntity()?.id);+ setPreviewOpen(true);};registerHotkey({@@ -126,7 +112,7 @@ export function SoupFiltersBar() {class="bg-surface"disabled={!isWideSplitPanel()}>- {soup.previewEntity() ? <EyeSlashIcon /> : <EyeIcon />}+ {previewOpen() ? <EyeSlashIcon /> : <EyeIcon />}<span>Preview</span></Button></Tooltip>diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsxindex f0bac4dfff..d5d301d0c5 100644--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx@@ -129,6 +129,8 @@ interface SoupViewContextValues {featuredIds: Accessor<string[]>;items: Accessor<SoupEntity[]>;rows: Accessor<SoupRow[]>;+ previewOpen: Accessor<boolean>;+ setPreviewOpen: Setter<boolean>;isSearchServiceLoading: Accessor<boolean>;isLocalSearchSettling: Accessor<boolean>;queryFilters: QueryStore;@@ -186,6 +188,7 @@ export const SoupViewContextProvider: FlowComponent<SoupViewContextProviderProps> = (props) => {const soup = props.soup ?? createSoupState();+ const [previewOpen, setPreviewOpen] = createSignal(false);const [enabled, setEnabled] = createSignal(props.initialEnabled ?? false);const [config, setConfig] = createSignal<SoupViewInitializeOptions>({initialQuery: props.initialQuery,@@ -1026,6 +1029,8 @@ export const SoupViewContextProvider: FlowComponent<},items,rows,+ previewOpen,+ setPreviewOpen,searchText: search.searchText,setSearchText: search.setSearchText,searchPaused: sourceSearchPaused,diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsxindex a9a2053af3..103ab2654b 100644--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx@@ -44,7 +44,6 @@ import {import {useIsNewInboxEnabled,usePreviewPaneVisiblity,- WIDE_SPLIT_PANEL_BREAKPOINT,} from '@app/component/next-soup/soup-view/use-preview-pane-visibility';import { CompanyKanban } from '@app/component/next-soup/soup-view/views/companies/CompanyKanban';import { CompanyListEntity } from '@app/component/next-soup/soup-view/views/companies/CompanyListEntity';@@ -305,6 +304,8 @@ const useSoupNotificationInvalidators = () => {};const SOUP_LIST_STATE_ENTRY_KEY = 'soup.listState';+const SOUP_PREVIEW_ENTITY_ENTRY_KEY = 'soup.preview';+const SOUP_PREVIEW_OPEN_ENTRY_KEY = 'soup.previewOpen';type SoupListEntryState = {focus: string | undefined;@@ -383,10 +384,18 @@ export const SoupView = (props: SoupViewProps) => {const soup = useSoup();const panel = useSplitPanelOrThrow();const soupView = useSoupView();+ const isNewInboxEnabled = useIsNewInboxEnabled();const entryState = panel.handle.currentEntryState();const contentId = panel.handle.content().id;+ const persistedPreviewEntity = entryState?.[SOUP_PREVIEW_ENTITY_ENTRY_KEY] as+ | string+ | undefined;+ const persistedPreviewOpen = entryState?.[SOUP_PREVIEW_OPEN_ENTRY_KEY] as+ | boolean+ | undefined;+const searchTags = useSearchTagsFlag();// The search view must not initialize with tag filters while the rollout@@ -455,6 +464,14 @@ export const SoupView = (props: SoupViewProps) => {if (init) return;init = true;batch(() => {+ soup.setPreviewEntity(persistedPreviewEntity);+ // Existing entries only stored the symbolic entity id. Treat one as an+ // open pane while allowing new entries to use their view default.+ soupView.setPreviewOpen(+ persistedPreviewOpen ??+ (persistedPreviewEntity ? true : isNewInboxEnabled())+ );+soupView.initialize({initialQuery: stripGatedTagFilters(initialCrmView@@ -517,6 +534,17 @@ export const SoupView = (props: SoupViewProps) => {});});+ const previewEntityCaptorTeardown = panel.handle.registerEntryStateCaptor(+ SOUP_PREVIEW_ENTITY_ENTRY_KEY,+ () => soup.previewEntity()+ );+ const previewOpenCaptorTeardown = panel.handle.registerEntryStateCaptor(+ SOUP_PREVIEW_OPEN_ENTRY_KEY,+ () => soupView.previewOpen()+ );+ onCleanup(previewEntityCaptorTeardown);+ onCleanup(previewOpenCaptorTeardown);+onMount(() => {if (contentId !== 'documents') return;@@ -609,18 +637,21 @@ export const SoupView = (props: SoupViewProps) => {},});- const { paneVisible } = usePreviewPaneVisiblity();+ const { paneVisible, previewVisible } = usePreviewPaneVisiblity();- const isNewInboxEnabled = useIsNewInboxEnabled();+ createEffect(() => {+ const visible = paneVisible();+ const [getPreview, setPreview] = panel.previewState;+ if (visible !== getPreview()) setPreview(visible);+ });+ onCleanup(() => panel.previewState[1](false));return (<SplitPanelContext.Providervalue={{...panel,halfSplitState: () =>- soup.previewEntity() && soup.focus.item()- ? { side: 'left', percentage: 30 }- : undefined,+ previewVisible() ? { side: 'left', percentage: 30 } : undefined,}}><div class="size-full flex flex-col" data-list-view={activeListView()}>@@ -828,7 +859,7 @@ export const SoupViewList = (props: SoupViewListProps) => {return isListViewID(id) ? id : undefined;});- const { paneVisible, placeholderVisible, previewVisible } =+ const { paneVisible, previewVisible, previewOpen, selectedEntity } =usePreviewPaneVisiblity();const focusFirstEntity = () => {@@ -959,7 +990,7 @@ export const SoupViewList = (props: SoupViewListProps) => {soup,splitHandle: panel.handle,virtualizerHandle,- previewState: () => !!soup.previewEntity(),+ previewState: previewVisible,currentView,activeTab,applyTabPreset,@@ -1010,10 +1041,7 @@ export const SoupViewList = (props: SoupViewListProps) => {return;}- if (- placeholderVisible() ||- (previewVisible() && soup.previewEntity() && type === 'entity')- ) {+ if (paneVisible() && type === 'entity') {if (args.rowIndex !== undefined) soup.focus.setIndex(args.rowIndex);else soup.focus.set(entity.id);@@ -1161,21 +1189,7 @@ export const SoupViewList = (props: SoupViewListProps) => {| SoupListEntryState| undefined;- // Preview-pane open state is transient per history entry: captured into- // per-entry state on nav-away and restored on back/forward. Read- // synchronously in the body so the first render sees the correct value- // and we avoid a transient flash where the pane is closed.- const persistedPreview = panel.handle.currentEntryState()?.['soup.preview'] as- | string- | undefined;- soup.setPreviewEntity(persistedPreview);- const previewCaptorTeardown = panel.handle.registerEntryStateCaptor(- 'soup.preview',- () => soup.previewEntity()- );- onCleanup(previewCaptorTeardown);-- // Which groups are collapsed is also per-entry state: captured on nav-away+ // Which groups are collapsed is per-entry state: captured on nav-away// and restored on back/forward.const collapsedCaptorTeardown = panel.handle.registerEntryStateCaptor('soup.collapsedGroups',@@ -1244,23 +1258,6 @@ export const SoupViewList = (props: SoupViewListProps) => {const featuredCount = createMemo(() => featuredIds().length);- const isWideSplitPanel = createMemo(() => {- return (panel.panelSize.width ?? 0) > WIDE_SPLIT_PANEL_BREAKPOINT;- });-- createEffect(() => {- const hasPreviewEntity = !!soup.previewEntity();- const [getPreview, setPreview] = panel.previewState;- if (hasPreviewEntity !== getPreview()) {- setPreview(hasPreviewEntity);- }- });-- // The preview flag lives on the panel, so clear it when the soup view- // unmounts (e.g. pressing enter replaces the split with the full entity);- // otherwise it stays stale-true and the entity's toolbar keeps the border.- onCleanup(() => panel.previewState[1](false));-return (<MaybeSoupEntityActionDrawerManager><div@@ -1535,7 +1532,7 @@ export const SoupViewList = (props: SoupViewListProps) => {onMouseMove={() => {if (isKeypressActive()) return;if (- soup.previewEntity() ||+ previewOpen() ||isNewInboxEnabled())return;@@ -1657,18 +1654,9 @@ export const SoupViewList = (props: SoupViewListProps) => {percent: isNewInboxEnabled() ? 55 : 70,}}>- <div- class={cn(- 'size-full',- !isWideSplitPanel() && 'border-t border-t-edge-muted'- )}- >+ <div class="size-full"><Show- when={- (soup.focus.row() && !isNewInboxEnabled()) ||- (soup.focus.row()?.getIsGrouped() === false &&- isNewInboxEnabled())- }+ when={selectedEntity()}fallback={<EmptyStatePanelgraphic={EmptyStatePreviewIcon}@@ -1682,14 +1670,16 @@ export const SoupViewList = (props: SoupViewListProps) => {/>}>- <PreviewPanel- selectedEntity={soup.focus.item()}- orchestrator={orchestrator}- splitPanelContext={panel}- onFocusOut={() => {- soupViewRef()?.focus();- }}- />+ {(entity) => (+ <PreviewPanel+ selectedEntity={entity()}+ orchestrator={orchestrator}+ splitPanelContext={panel}+ onFocusOut={() => {+ soupViewRef()?.focus();+ }}+ />+ )}</Show></div></Resize.Panel>diff --git a/js/app/packages/app/component/next-soup/soup-view/use-preview-pane-visibility.ts b/js/app/packages/app/component/next-soup/soup-view/use-preview-pane-visibility.tsindex 653486508a..9588edd64b 100644--- a/js/app/packages/app/component/next-soup/soup-view/use-preview-pane-visibility.ts+++ b/js/app/packages/app/component/next-soup/soup-view/use-preview-pane-visibility.ts@@ -6,6 +6,7 @@ import {ENABLE_NEW_INBOX_FLAG,ENABLE_NEW_INBOX_OVERRIDE,} from '@core/constant/featureFlags';+import { isMobile } from '@core/mobile/isMobile';import { createMemo } from 'solid-js';export const WIDE_SPLIT_PANEL_BREAKPOINT = 640;@@ -31,36 +32,30 @@ export function useIsNewInboxEnabled() {export function usePreviewPaneVisiblity() {const panel = useSplitPanelOrThrow();+ const { soup, previewOpen } = useSoupView();- const { soup, rows } = useSoupView();-- const isNewInboxEnabled = useIsNewInboxEnabled();-- const isWideSplitPanel = createMemo(() => {- return (panel.panelSize.width ?? 0) > WIDE_SPLIT_PANEL_BREAKPOINT;- });-- const previewVisible = createMemo(- () =>- isWideSplitPanel() &&- (!!soup.previewEntity() || panel.previewState[0]()) &&- !!soup.focus.item()+ const isWideSplitPanel = createMemo(+ () => (panel.panelSize.width ?? 0) > WIDE_SPLIT_PANEL_BREAKPOINT);- // Placeholder display only for new inbox where the preview panel is open by default- // Only open while no items are focused- const previewPlaceholderVisible = createMemo(() => {- return isWideSplitPanel() && isNewInboxEnabled() && !soup.focus.item();+ // Group headers and load-more rows carry a representative entity, but they+ // are navigation controls rather than user-selectable preview items.+ const selectedEntity = createMemo(() => {+ const row = soup.focus.row();+ if (!row || row.getIsGrouped() || row.getIsLoadMore()) return;+ return row.original;});- const previewPaneVisible = createMemo(- () => rows().length > 0 && (previewVisible() || previewPlaceholderVisible())+ const paneVisible = createMemo(+ () => !isMobile() && isWideSplitPanel() && previewOpen());+ const previewVisible = createMemo(() => paneVisible() && !!selectedEntity());return {- paneVisible: previewPaneVisible,- placeholderVisible: previewPlaceholderVisible,+ paneVisible,previewVisible,+ previewOpen,+ selectedEntity,isWideSplitPanel,};}diff --git a/js/app/packages/app/component/next-soup/soup-view/views/companies/CompanyKanban.tsx b/js/app/packages/app/component/next-soup/soup-view/views/companies/CompanyKanban.tsxindex 14659ea12a..f87e8d54d3 100644--- a/js/app/packages/app/component/next-soup/soup-view/views/companies/CompanyKanban.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/views/companies/CompanyKanban.tsx@@ -28,14 +28,7 @@ import CircleDashed from '@phosphor/circle-dashed.svg';import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';import { EntityType } from '@service-properties/generated/schemas/entityType';import { cn, EmptyStatePanel, Layer } from '@ui';-import {- createEffect,- createMemo,- createSignal,- For,- onCleanup,- Show,-} from 'solid-js';+import { createMemo, createSignal, For, Show } from 'solid-js';/** Column key for companies without a Stage value. */const NO_STAGE_KEY = '';@@ -75,31 +68,7 @@ export function CompanyKanban() {{ key: NO_STAGE_KEY, label: 'No stage' },]);- // Preview-pane open state is per history entry, mirroring SoupViewList:- // restored synchronously so the first render sees the pane, captured on- // nav-away so back/forward returns to the same state.- const persistedPreview = panel.handle.currentEntryState()?.['soup.preview'] as- | string- | undefined;- soup.setPreviewEntity(persistedPreview);- const previewCaptorTeardown = panel.handle.registerEntryStateCaptor(- 'soup.preview',- () => soup.previewEntity()- );- onCleanup(previewCaptorTeardown);-- const { paneVisible, previewVisible } = usePreviewPaneVisiblity();-- // Keep the panel-level preview flag in sync (entity toolbars read it),- // and clear it when the board unmounts so it doesn't go stale.- createEffect(() => {- const hasPreviewEntity = !!soup.previewEntity();- const [getPreview, setPreview] = panel.previewState;- if (hasPreviewEntity !== getPreview()) {- setPreview(hasPreviewEntity);- }- });- onCleanup(() => panel.previewState[1](false));+ const { paneVisible, selectedEntity } = usePreviewPaneVisiblity();const companies = createMemo(() => source.data().filter(isCrmCompanyEntity));@@ -154,7 +123,7 @@ export function CompanyKanban() {// While the preview pane is open, card clicks retarget it instead of// replacing the split (mirrors the list view's behavior).- if (previewVisible() && soup.previewEntity()) {+ if (paneVisible()) {soup.setPreviewEntity(entity.id);return;}@@ -263,7 +232,7 @@ export function CompanyKanban() {target={{ kind: 'percent', percent: 70 }}><Show- when={soup.focus.item()}+ when={selectedEntity()}fallback={<EmptyStatePanelgraphic={EmptyStatePreviewIcon}@@ -273,11 +242,13 @@ export function CompanyKanban() {/>}>- <PreviewPanel- selectedEntity={soup.focus.item()}- orchestrator={orchestrator}- splitPanelContext={panel}- />+ {(entity) => (+ <PreviewPanel+ selectedEntity={entity()}+ orchestrator={orchestrator}+ splitPanelContext={panel}+ />+ )}</Show></Resize.Panel></Show>