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.

soup-context: add guard to entity list navigation, rename unifiedListContext to soupContext, add open entity helper function (#843)

Caleb Taylorc9b7c8c3b169
diff --git a/js/app/packages/app/component/EntityActionsMenuItems.tsx b/js/app/packages/app/component/EntityActionsMenuItems.tsx
index 69404386f1..2e11045326 100644
--- a/js/app/packages/app/component/EntityActionsMenuItems.tsx
+++ b/js/app/packages/app/component/EntityActionsMenuItems.tsx
@@ -13,8 +13,9 @@ interface EntityActionsMenuItemsProps {
}
export const EntityActionsMenuItems = (props: EntityActionsMenuItemsProps) => {
- const { unifiedListContext } = useSplitPanelOrThrow();
- const { actionRegistry, viewsDataStore, selectedView } = unifiedListContext;
+ const { soupContext } = useSplitPanelOrThrow();
+
+ const { actionRegistry, viewsDataStore, selectedView } = soupContext;
const entities = () => {
const { multiSelectEntities } = viewsDataStore[selectedView()];
@@ -38,7 +39,7 @@ export const EntityActionsMenuItems = (props: EntityActionsMenuItemsProps) => {
};
const setSelection: Setter<EntityData[]> = (entities) => {
- return unifiedListContext.setViewDataStore(
+ return soupContext.setViewDataStore(
selectedView(),
'multiSelectEntities',
entities
@@ -90,14 +91,20 @@ export const EntityActionsMenuItems = (props: EntityActionsMenuItemsProps) => {
if (props.entity.type === 'document') {
const { fileType, id, subType } = props.entity;
splitManager.createNewSplit({
- type: fileTypeToBlockName(subType ?? fileType),
- id,
+ content: {
+ type: fileTypeToBlockName(subType ?? fileType),
+ id,
+ },
+ referredFrom: 'entity-actions-menu',
});
} else {
const { id, type } = props.entity;
splitManager.createNewSplit({
- type,
- id,
+ content: {
+ type,
+ id,
+ },
+ referredFrom: 'entity-actions-menu',
});
}
}}
diff --git a/js/app/packages/app/component/EntityModal/RenameView.tsx b/js/app/packages/app/component/EntityModal/RenameView.tsx
index 0fe3fce47c..90208e4553 100644
--- a/js/app/packages/app/component/EntityModal/RenameView.tsx
+++ b/js/app/packages/app/component/EntityModal/RenameView.tsx
@@ -49,7 +49,7 @@ export const RenameView = (props: {
let inputRef: HTMLInputElement | undefined;
const saveViewMutation = useUpsertSavedViewMutation();
const {
- unifiedListContext: { viewsDataStore: viewsData },
+ soupContext: { viewsDataStore: viewsData },
} = useSplitPanelOrThrow();
const view = createMemo(() => {
diff --git a/js/app/packages/app/component/EntityNavigationIndicator.tsx b/js/app/packages/app/component/EntityNavigationIndicator.tsx
index 6289668dd1..d6c712f7a4 100644
--- a/js/app/packages/app/component/EntityNavigationIndicator.tsx
+++ b/js/app/packages/app/component/EntityNavigationIndicator.tsx
@@ -8,7 +8,7 @@ import { Show } from 'solid-js';
const EntityNavigationIndicator = () => {
const {
- unifiedListContext: {
+ soupContext: {
entitiesSignal: [entities],
selectedView,
viewsDataStore,
@@ -23,6 +23,7 @@ const EntityNavigationIndicator = () => {
return (
<Show
when={
+ handle.referredFrom() === 'unified-list' &&
entities()?.length &&
selectedEntity() &&
handle.content().type !== 'component' &&
diff --git a/js/app/packages/app/component/GlobalHotkeys.tsx b/js/app/packages/app/component/GlobalHotkeys.tsx
index 6b6cdb9417..4575663fa1 100644
--- a/js/app/packages/app/component/GlobalHotkeys.tsx
+++ b/js/app/packages/app/component/GlobalHotkeys.tsx
@@ -126,7 +126,7 @@ export default function GlobalShortcuts() {
description: 'Create new split',
condition: canFit,
keyDownHandler: () => {
- insertSplit({ type: 'component', id: 'unified-list' });
+ insertSplit({ type: 'component', id: 'unified-list' }, 'hotkey');
return true;
},
runWithInputFocused: true,
@@ -138,7 +138,7 @@ export default function GlobalShortcuts() {
description: 'Create new split',
condition: canFit,
keyDownHandler: () => {
- insertSplit({ type: 'component', id: 'unified-list' });
+ insertSplit({ type: 'component', id: 'unified-list' }, 'hotkey');
return true;
},
});
diff --git a/js/app/packages/app/component/HelpDrawer.tsx b/js/app/packages/app/component/HelpDrawer.tsx
index 9228262155..2717ef2f63 100644
--- a/js/app/packages/app/component/HelpDrawer.tsx
+++ b/js/app/packages/app/component/HelpDrawer.tsx
@@ -269,7 +269,7 @@ export interface HelpDrawerInnerProps {
export function HelpDrawerInner(props: HelpDrawerInnerProps) {
const splitPanelContext = useSplitPanelOrThrow();
const {
- unifiedListContext: { setShowHelpDrawer },
+ soupContext: { setShowHelpDrawer },
} = splitPanelContext;
const tuturialComplete = useTutorialCompleted();
const hideAllHelpDrawers = () => {
diff --git a/js/app/packages/app/component/Launcher.tsx b/js/app/packages/app/component/Launcher.tsx
index 1539e80113..912d1f9075 100644
--- a/js/app/packages/app/component/Launcher.tsx
+++ b/js/app/packages/app/component/Launcher.tsx
@@ -50,11 +50,16 @@ const createBlock = async (spec: {
const block = { type: blockName, id };
- spec.shouldInsert ? insertSplit(block) : replaceSplit(block);
+ spec.shouldInsert
+ ? insertSplit(block, 'launcher')
+ : replaceSplit({ content: block, referredFrom: 'launcher' });
} else {
const split = spec.shouldInsert
- ? insertSplit({ type: 'component', id: 'loading' })
- : replaceSplit({ type: 'component', id: 'loading' });
+ ? insertSplit({ type: 'component', id: 'loading' }, 'launcher')
+ : replaceSplit({
+ content: { type: 'component', id: 'loading' },
+ referredFrom: 'launcher',
+ });
const id = await createFn();
if (!id) {
@@ -62,7 +67,12 @@ const createBlock = async (spec: {
return;
}
- if (split) split.replace({ type: blockName, id }, true);
+ if (split)
+ split.replace({
+ next: { type: blockName, id },
+ mergeHistory: true,
+ referredFrom: 'launcher',
+ });
}
};
@@ -78,9 +88,12 @@ const createComponent = async (spec: {
return;
}
if (spec.shouldInsert) {
- insertSplit({ type: 'component', id: spec.componentId });
+ insertSplit({ type: 'component', id: spec.componentId }, 'launcher');
} else {
- replaceSplit({ type: 'component', id: spec.componentId });
+ replaceSplit({
+ content: { type: 'component', id: spec.componentId },
+ referredFrom: 'launcher',
+ });
}
};
diff --git a/js/app/packages/app/component/QuickCreateMenu.tsx b/js/app/packages/app/component/QuickCreateMenu.tsx
index d2366bad8f..872852dc31 100644
--- a/js/app/packages/app/component/QuickCreateMenu.tsx
+++ b/js/app/packages/app/component/QuickCreateMenu.tsx
@@ -205,10 +205,13 @@ export function QuickCreateMenuInner(props: QuickCreateMenuProps) {
}
if (goToNote && documentId) {
- replaceOrInsertSplit({
- type: 'md',
- id: documentId,
- });
+ replaceOrInsertSplit(
+ {
+ type: 'md',
+ id: documentId,
+ },
+ 'launcher'
+ );
return true;
}
@@ -296,10 +299,13 @@ export function QuickCreateMenuInner(props: QuickCreateMenuProps) {
}
if (goTo) {
- replaceOrInsertSplit({
- type: 'email',
- id: 'new',
- });
+ replaceOrInsertSplit(
+ {
+ type: 'email',
+ id: 'new',
+ },
+ 'launcher'
+ );
}
return true;
diff --git a/js/app/packages/app/component/Soup.tsx b/js/app/packages/app/component/Soup.tsx
index d5dc1a5177..d78e97ae37 100644
--- a/js/app/packages/app/component/Soup.tsx
+++ b/js/app/packages/app/component/Soup.tsx
@@ -233,7 +233,7 @@ export function Soup() {
const {
handle,
splitHotkeyScope,
- unifiedListContext: {
+ soupContext: {
viewsDataStore: viewsData,
selectedView,
setSelectedView,
@@ -500,7 +500,7 @@ function EmailView() {
emailViewSignal: [emailView, setEmailView],
viewsDataStore,
selectedView,
- } = useSplitPanelOrThrow().unifiedListContext;
+ } = useSplitPanelOrThrow().soupContext;
const viewData = createMemo(() => viewsDataStore[selectedView()]);
return (
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index 608d143eca..7ed256b4bc 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -1,7 +1,6 @@
import { globalSplitManager } from '@app/signal/splitLayout';
import { useChannelsContext } from '@core/component/ChannelsProvider';
import { toast } from '@core/component/Toast/Toast';
-import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { HotkeyTags } from '@core/hotkey/constants';
import { activeScope, hotkeyScopeTree } from '@core/hotkey/state';
import { TOKENS } from '@core/hotkey/tokens';
@@ -65,6 +64,7 @@ import {
toggleKonsoleVisibility,
} from './command/state';
import { useGlobalNotificationSource } from './GlobalAppState';
+import { openEntityInSplitFromUnifiedList } from './soupContextHelpers';
import type { SplitHandle } from './split-layout/layoutManager';
import { globalRemoveFromSplitHistory } from './split-layout/layoutUtils';
import {
@@ -85,7 +85,7 @@ type NavigateListFn = (input: NavigationInput) => Promise<NavigationResult>;
type CollapseEntityFn = (entityId: string) => Promise<void>;
-export type UnifiedListContext = {
+export type SoupContext = {
viewsDataStore: Store<ViewDataMap>;
setViewDataStore: SetStoreFunction<Partial<ViewDataMap>>;
selectedView: Accessor<ViewId>;
@@ -106,7 +106,7 @@ export type UnifiedListContext = {
collapseEntitySignal: Signal<CollapseEntityFn | undefined>;
};
-export function createStubSoupContext(): UnifiedListContext {
+export function createStubSoupContext(): SoupContext {
return {
viewsDataStore: createStore({})[0],
setViewDataStore: () => {},
@@ -133,7 +133,7 @@ const DEFAULT_VIEW_ID: DefaultView = 'signal';
const DEFAULT_VIEW_IDS_SET = new Set(VIEWCONFIG_DEFAULTS_IDS);
-export function createSoupContext(): UnifiedListContext {
+export function createSoupContext(): SoupContext {
const [selectedView, setSelectedView] = createSignal<ViewId>(DEFAULT_VIEW_ID);
const [viewsDataStore, setViewDataStore] = useAllViews({
selectedViewSignal: [selectedView, setSelectedView],
@@ -247,13 +247,13 @@ export type NavigationResult = {
export function createNavigationEntityListShortcut({
splitHandle,
splitHotkeyScope,
- unifiedListContext,
+ soupContext,
previewState,
getSplitCount,
}: {
splitHandle: SplitHandle;
splitHotkeyScope: string;
- unifiedListContext: UnifiedListContext;
+ soupContext: SoupContext;
previewState: Signal<boolean>;
getSplitCount: () => number;
}) {
@@ -266,7 +266,7 @@ export function createNavigationEntityListShortcut({
setSelectedView,
entitiesSignal: [entities],
actionRegistry,
- } = unifiedListContext;
+ } = soupContext;
const viewData = createMemo(() => viewsData[selectedView()]);
const viewIds = createMemo<ViewId[]>(() => Object.keys(viewsData));
@@ -289,41 +289,14 @@ export function createNavigationEntityListShortcut({
const isViewingList = createMemo(() => {
return splitHandle.content().id === 'unified-list';
});
- let lastMultiNavigationInput: NavigationInput;
-
- // `gg` to jump to top of list (legacy behavior) via command-scope hotkeys.
- const goScope = registerHotkey({
- scopeId: splitHotkeyScope,
- hotkey: 'g',
- description: 'Go',
- keyDownHandler: () => true,
- activateCommandScope: true,
- hide: true,
- });
-
- registerHotkey({
- hotkey: ['g'],
- scopeId: goScope.commandScopeId,
- description: 'Go to top of list',
- condition: isViewingList,
- keyDownHandler: () => {
- navigateThroughList({ axis: 'start', mode: 'jump' });
- return true;
- },
- hide: true,
- });
+ const canAccessEntityList = () => {
+ if (isViewingList()) return true;
+ const result =
+ !isViewingList() && splitHandle.referredFrom() === 'unified-list';
+ return result;
+ };
- registerHotkey({
- hotkey: ['shift+g', 'end'],
- scopeId: goScope.commandScopeId,
- description: 'Go to bottom of list',
- condition: isViewingList,
- keyDownHandler: () => {
- navigateThroughList({ axis: 'end', mode: 'jump' });
- return true;
- },
- hide: true,
- });
+ let lastMultiNavigationInput: NavigationInput;
/**
* From the current selection, get the entity to try to select after a modal
@@ -449,9 +422,8 @@ export function createNavigationEntityListShortcut({
// Check if current view filters out completed items in order to know whether to run collapse animation. More robustly we would have the list of entitites itself trigger entity removal animation when the list changes, but this is complicated by our usage of queries and virtualized lists.
// NOTE: collapse animation is currently only enabled for touch modality, i.e. phone.
- const currentViewConfig =
- unifiedListContext.viewsDataStore[selectedView()];
- const [collapseEntity] = unifiedListContext.collapseEntitySignal;
+ const currentViewConfig = soupContext.viewsDataStore[selectedView()];
+ const [collapseEntity] = soupContext.collapseEntitySignal;
const shouldCollapse =
currentViewConfig?.filters?.notificationFilter === 'notDone' &&
collapseEntity() !== undefined &&
@@ -470,7 +442,7 @@ export function createNavigationEntityListShortcut({
for (const entity of multiSelectEntities) {
if (handler) {
handler(entity, {
- soupContext: unifiedListContext,
+ soupContext,
notificationSource,
});
}
@@ -814,19 +786,6 @@ export function createNavigationEntityListShortcut({
displayPriority: 10,
});
- const openEntity = (entity: EntityData) => {
- const { type, id } = entity;
- if (type === 'document') {
- const { fileType, subType } = entity;
- splitHandle.replace({
- type: fileTypeToBlockName(subType ?? fileType),
- id,
- });
- } else {
- splitHandle.replace({ type, id });
- }
- };
-
const getEntityElAtIndex = (index: number) => {
const entity = entities()?.at(index);
if (!entity) return;
@@ -1007,16 +966,9 @@ export function createNavigationEntityListShortcut({
splitHandle.content().type !== 'component' &&
splitHandle.content().type !== 'project'
) {
- const { type, id } = selectedEntity;
- if (type === 'document') {
- const { fileType, subType } = selectedEntity;
- splitHandle.replace(
- { type: fileTypeToBlockName(subType ?? fileType), id },
- true
- );
- } else {
- splitHandle.replace({ type, id }, true);
- }
+ openEntityInSplitFromUnifiedList(selectedEntity, {
+ splitHandle,
+ });
}
batch(() => {
setSelectedEntity(selectedEntity);
@@ -1061,7 +1013,7 @@ export function createNavigationEntityListShortcut({
};
};
- unifiedListContext._setNavigateThroughList(navigateThroughList);
+ soupContext._setNavigateThroughList(navigateThroughList);
const isEntitySelected = (entityID: string) => {
return (
@@ -1178,6 +1130,7 @@ export function createNavigationEntityListShortcut({
navigateThroughList({ axis: 'end', mode: 'step' });
return true;
},
+ canExecuteKeyDownHandler: () => canAccessEntityList(),
hide: true,
});
@@ -1191,7 +1144,7 @@ export function createNavigationEntityListShortcut({
lastMultiNavigationInput = navigationInput;
return handleNavigationSelection(navigationInput);
},
- canExecuteKeyDownHandler: () => isViewingList(),
+ canExecuteKeyDownHandler: () => canAccessEntityList(),
hide: true,
});
@@ -1205,6 +1158,7 @@ export function createNavigationEntityListShortcut({
navigateThroughList({ axis: 'start', mode: 'step' });
return true;
},
+ canExecuteKeyDownHandler: () => canAccessEntityList(),
hide: true,
});
@@ -1218,20 +1172,44 @@ export function createNavigationEntityListShortcut({
lastMultiNavigationInput = navigationInput;
return handleNavigationSelection(navigationInput);
},
- canExecuteKeyDownHandler: () => isViewingList(),
+ canExecuteKeyDownHandler: () => canAccessEntityList(),
hide: true,
});
registerEntityHotkey({
hotkey: ['home'],
scopeId: splitHotkeyScope,
hotkeyToken: TOKENS.entity.jump.home,
- description: 'Top',
+ description: 'Go to top of list',
keyDownHandler: () => {
navigateThroughList({ axis: 'start', mode: 'jump' });
return true;
},
+ canExecuteKeyDownHandler: () => canAccessEntityList(),
hide: true,
});
+ const {
+ registerHotkeyReturn: topGScope,
+ globalRegisterHotkeyReturn: topGScopeGlobal,
+ } = registerEntityHotkey({
+ hotkey: ['g'],
+ scopeId: splitHotkeyScope,
+ description: 'Go to top of list',
+ keyDownHandler: () => true,
+ activateCommandScope: true,
+ canExecuteKeyDownHandler: () => canAccessEntityList(),
+ hide: true,
+ });
+ registerEntityHotkey({
+ hotkey: ['g'],
+ scopeId: topGScope.commandScopeId,
+ globalCommandScope: topGScopeGlobal.commandScopeId,
+ description: 'Go to top of list',
+ keyDownHandler: () => {
+ navigateThroughList({ axis: 'start', mode: 'jump' });
+ return true;
+ },
+ canExecuteKeyDownHandler: () => canAccessEntityList(),
+ });
registerEntityHotkey({
hotkey: ['shift+g', 'end'],
scopeId: splitHotkeyScope,
@@ -1241,6 +1219,7 @@ export function createNavigationEntityListShortcut({
navigateThroughList({ axis: 'end', mode: 'jump' });
return true;
},
+ canExecuteKeyDownHandler: () => canAccessEntityList(),
hide: true,
});
@@ -1315,7 +1294,9 @@ export function createNavigationEntityListShortcut({
const entity = getSelectedEntity()?.entity;
if (!entity) return false;
- openEntity(entity);
+ openEntityInSplitFromUnifiedList(entity, {
+ splitHandle,
+ });
return true;
},
canExecuteKeyDownHandler: ({ keyboardEvent }) => {
@@ -1381,7 +1362,9 @@ export function createNavigationEntityListShortcut({
return true;
}
- openEntity(entity);
+ openEntityInSplitFromUnifiedList(entity, {
+ splitHandle,
+ });
return true;
},
canExecuteKeyDownHandler: () => isViewingList(),
@@ -1445,7 +1428,10 @@ export function createNavigationEntityListShortcut({
return true;
}
if (goHomeCondition()) {
- splitHandle.replace({ type: 'component', id: 'unified-list' });
+ splitHandle.replace({
+ next: { type: 'component', id: 'unified-list' },
+ referredFrom: 'unified-list',
+ });
return true;
}
return false;
@@ -1479,7 +1465,6 @@ const useAllViews = ({
},
}));
- // signal version
createEffect(
on(
() => savedViews.data,
diff --git a/js/app/packages/app/component/UnifiedListEmptyState.tsx b/js/app/packages/app/component/UnifiedListEmptyState.tsx
index a48ea3a220..bed9cfb734 100644
--- a/js/app/packages/app/component/UnifiedListEmptyState.tsx
+++ b/js/app/packages/app/component/UnifiedListEmptyState.tsx
@@ -23,7 +23,7 @@ function EmptyStateHelpDrawer(props: {
showDropZone?: boolean;
}) {
const {
- unifiedListContext: { setShowHelpDrawer },
+ soupContext: { setShowHelpDrawer },
} = useSplitPanelOrThrow();
let timeoutId: ReturnType<typeof setTimeout> | undefined;
diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsx
index e1067d3051..68e4c22d84 100644
--- a/js/app/packages/app/component/UnifiedListView.tsx
+++ b/js/app/packages/app/component/UnifiedListView.tsx
@@ -3,12 +3,8 @@ import {
useGlobalNotificationSource,
} from '@app/component/GlobalAppState';
import { noiseFilter, signalFilter } from '@app/component/soupFilters';
-import type { BlockChannelProps } from '@block-channel/component/Block';
import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
import { codeFileExtensions } from '@block-code/util/languageSupport';
-import { URL_PARAMS as EMAIL_PARAMS } from '@block-email/constants';
-import { URL_PARAMS as MD_PARAMS } from '@block-md/constants';
-import { URL_PARAMS as PDF_PARAMS } from '@block-pdf/signal/location';
import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';
import { DeprecatedButton } from '@core/component/FormControls/DeprecatedButton';
import DropdownMenu from '@core/component/FormControls/DropdownMenu';
@@ -19,10 +15,7 @@ import { ContextMenuContent, MenuSeparator } from '@core/component/Menu';
import { useTaskProperties } from '@core/component/Properties/hooks';
import { getSuggestedProperties } from '@core/component/Properties/utils';
import { RecipientSelector } from '@core/component/RecipientSelector';
-import {
- blockAcceptsFileExtension,
- fileTypeToBlockName,
-} from '@core/constant/allBlocks';
+import { blockAcceptsFileExtension } from '@core/constant/allBlocks';
import {
ENABLE_FRECENCY,
ENABLE_PROPERTY_DISPLAY,
@@ -51,7 +44,6 @@ import {
createSort,
createUnifiedInfiniteList,
createUnifiedSearchInfiniteQuery,
- type DocumentEntity,
Entity,
type EntityClickHandler,
type EntityData,
@@ -138,11 +130,11 @@ import { EntitySelectionToolbarModal } from './EntitySelectionToolbarModal';
import { EntityRow, EntityRowProvider } from './mobile/EntityRow';
import { PropertyDisplayControl } from './PropertyDisplayControl';
import { useUpsertSavedViewMutation } from './Soup';
+import { openEntityInSplitFromUnifiedList } from './soupContextHelpers';
import {
SplitToolbarLeft,
SplitToolbarRight,
} from './split-layout/components/SplitToolbar';
-import { useSplitLayout } from './split-layout/layout';
import { useSplitPanelOrThrow } from './split-layout/layoutUtils';
import {
type DisplayOptions,
@@ -240,7 +232,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
);
const splitContext = useSplitPanelOrThrow();
- const { isPanelActive, unifiedListContext, previewState } = splitContext;
+ const { isPanelActive, soupContext, previewState } = splitContext;
const [preview] = previewState;
const {
viewsDataStore: viewsData,
@@ -250,7 +242,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
entityListRefSignal: [, setEntityListRef],
entitiesSignal: [entities_, setEntities],
emailViewSignal: [emailView],
- } = unifiedListContext;
+ } = soupContext;
// Properties for task entities
const taskPropertiesStore = useTaskProperties(entities_);
@@ -963,7 +955,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
const notificationSource = useGlobalNotificationSource();
const markEntityAsDone = (entity: EntityData) => {
- const actions = unifiedListContext.actionRegistry;
+ const actions = soupContext.actionRegistry;
if (actions.isActionEnabled('mark_as_done', entity)) {
actions.execute('mark_as_done', entity);
return true;
@@ -971,8 +963,6 @@ export function UnifiedListView(props: UnifiedListViewProps) {
return false;
};
- const { replaceOrInsertSplit, insertSplit } = useSplitLayout();
-
const blockOrchestrator = useGlobalBlockOrchestrator();
const gotoChannelNotification = async (notification: UnifiedNotification) => {
if (
@@ -1107,39 +1097,6 @@ export function UnifiedListView(props: UnifiedListViewProps) {
});
});
- const documentEntityClickHandler: EntityClickHandler<
- DocumentEntity | WithSearch<DocumentEntity>
- > = async (entity, event, location) => {
- const { id, fileType, subType } = entity;
- const blockName = fileTypeToBlockName(subType ?? fileType);
- const handle = event.altKey
- ? insertSplit({ type: blockName, id })
- : replaceOrInsertSplit({ type: blockName, id });
-
- handle?.activate();
-
- if (!location) return;
-
- const blockHandle = await blockOrchestrator.getBlockHandle(id);
- switch (location.type) {
- case 'md':
- await blockHandle?.goToLocationFromParams({
- [MD_PARAMS.nodeId]: location.nodeId,
- });
- break;
- case 'pdf':
- await blockHandle?.goToLocationFromParams({
- [PDF_PARAMS.searchPage]: location.searchPage.toString(),
- [PDF_PARAMS.searchRawQuery]: location.searchRawQuery,
- [PDF_PARAMS.searchHighlightTerms]: JSON.stringify(
- location.highlightTerms
- ),
- [PDF_PARAMS.searchSnippet]: location.searchSnippet,
- });
- break;
- }
- };
-
const entityClickHandler: EntityClickHandler<EntityData> = async (
entity,
event,
@@ -1152,45 +1109,11 @@ export function UnifiedListView(props: UnifiedListViewProps) {
return;
}
- if (entity.type === 'document')
- return documentEntityClickHandler(entity, event, location);
-
- const params =
- entity.type === 'channel' && location?.type === 'channel'
- ? ({
- target: {
- threadId: location.threadId,
- messageId: location.messageId,
- },
- } as BlockChannelProps)
- : undefined;
-
- const handle = event.altKey
- ? insertSplit({ type: entity.type, id: entity.id, params })
- : replaceOrInsertSplit({ type: entity.type, id: entity.id, params });
-
- handle?.activate();
-
- if (!location) return;
-
- switch (location.type) {
- case 'channel': {
- // NOTE: this is handled by the channel block params but this can be used to re-flash an open channel
- const blockHandle = await blockOrchestrator.getBlockHandle(entity.id);
- await blockHandle?.goToLocationFromParams({
- [CHANNEL_PARAMS.thread]: location.threadId,
- [CHANNEL_PARAMS.message]: location.messageId,
- });
- break;
- }
- case 'email': {
- const blockHandle = await blockOrchestrator.getBlockHandle(entity.id);
- await blockHandle?.goToLocationFromParams({
- [EMAIL_PARAMS.messageId]: location.messageId,
- });
- break;
- }
- }
+ await openEntityInSplitFromUnifiedList(entity, {
+ openInNewSplit: event.altKey,
+ location,
+ splitHandle: splitContext.handle,
+ });
};
const StyledTriggerLabel = (props: ParentProps) => {
@@ -1283,7 +1206,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
entity: EntityData;
next: boolean;
}) => {
- unifiedListContext.setViewDataStore(
+ soupContext.setViewDataStore(
selectedView(),
'multiSelectEntities',
(prev) => {
@@ -1350,12 +1273,11 @@ export function UnifiedListView(props: UnifiedListViewProps) {
return;
}
- const entityList = unifiedListContext.entitiesSignal[0]();
+ const entityList = soupContext.entitiesSignal[0]();
if (!entityList) return;
const selectedEntitySet = new Set(
- unifiedListContext.viewsDataStore[unifiedListContext.selectedView()]
- .multiSelectEntities
+ soupContext.viewsDataStore[soupContext.selectedView()].multiSelectEntities
);
const anchorIndex = getSelectionAnchorIndex({
@@ -1377,7 +1299,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
targetIndex: params.entityIndex,
});
- unifiedListContext.setViewDataStore(
+ soupContext.setViewDataStore(
selectedView(),
'multiSelectEntities',
(prev) => prev.concat(newEntitiesForSelection)
@@ -1396,8 +1318,8 @@ export function UnifiedListView(props: UnifiedListViewProps) {
// reset last clicked on reset multi-selection.
createEffect(() => {
if (
- unifiedListContext.viewsDataStore[selectedView()].multiSelectEntities
- .length === 0
+ soupContext.viewsDataStore[selectedView()].multiSelectEntities.length ===
+ 0
) {
lastClickedEntityId = -1;
}
@@ -1655,7 +1577,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
canSwipeLeft={(entityId) => {
const entity = entityById().get(entityId);
if (!entity) return false;
- return unifiedListContext.actionRegistry.isActionEnabled(
+ return soupContext.actionRegistry.isActionEnabled(
'mark_as_done',
entity
);
@@ -1664,9 +1586,9 @@ export function UnifiedListView(props: UnifiedListViewProps) {
const entity = entityById().get(entityId);
if (!entity) return false;
- unifiedListContext.actionRegistry.execute('mark_as_done', entity);
+ soupContext.actionRegistry.execute('mark_as_done', entity);
}}
- setCollapseEntity={unifiedListContext.collapseEntitySignal[1]}
+ setCollapseEntity={soupContext.collapseEntitySignal[1]}
>
<UnifiedListComponent
entityListRef={setLocalEntityListRef}
@@ -1728,7 +1650,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
timestamp={timestamp()}
onClick={entityClickHandler}
onClickRowAction={
- unifiedListContext.actionRegistry.isActionEnabled(
+ soupContext.actionRegistry.isActionEnabled(
'mark_as_done',
innerProps.entity
)
@@ -1841,7 +1763,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
<EntitySelectionToolbarModal
multiSelectEntities={view()?.multiSelectEntities ?? []}
onClose={() =>
- unifiedListContext.setViewDataStore(
+ soupContext.setViewDataStore(
selectedView(),
'multiSelectEntities',
[]
@@ -1865,7 +1787,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
setKonsoleContextInformation({
selectedEntities: multiSelectEntities.slice(),
clearSelection: () => {
- unifiedListContext.setViewDataStore(
+ soupContext.setViewDataStore(
selectedView(),
'multiSelectEntities',
[]
@@ -1931,7 +1853,7 @@ function SearchBar(props: {
virtualizerHandleSignal: [virtualizerHandle],
entityListRefSignal: [entityListRef],
navigateThroughList,
- } = splitContext.unifiedListContext;
+ } = splitContext.soupContext;
const viewData = createMemo(() => viewsDataStore[selectedView()]);
const viewName = createMemo(() => viewData().view);
diff --git a/js/app/packages/app/component/ViewConfig.tsx b/js/app/packages/app/component/ViewConfig.tsx
index 732b6ae00a..b4d1370b78 100644
--- a/js/app/packages/app/component/ViewConfig.tsx
+++ b/js/app/packages/app/component/ViewConfig.tsx
@@ -23,7 +23,7 @@ import {
import { emailClient } from '@service-email/client';
import stringify from 'json-stable-stringify';
import { queryClient } from '../../macro-entity/src/queries/client';
-import type { UnifiedListContext } from './SoupContext';
+import type { SoupContext } from './SoupContext';
import { noiseFilter, signalFilter } from './soupFilters';
// for custom views that extend the unified list view
@@ -96,7 +96,7 @@ export type HotkeyOptions = {
entity: WithNotification<EntityData>,
extra?: {
notificationSource?: NotificationSource;
- soupContext?: UnifiedListContext;
+ soupContext?: SoupContext;
}
) => boolean;
};
@@ -118,7 +118,7 @@ export type ViewConfigEnhanced = {
} & ViewConfigBase;
export type ClientFilterContext = {
- soupContext?: UnifiedListContext;
+ soupContext?: SoupContext;
};
export type ClientFilter = {
diff --git a/js/app/packages/app/component/command/KonsoleItem.tsx b/js/app/packages/app/component/command/KonsoleItem.tsx
index 502f723308..73b1932c8e 100644
--- a/js/app/packages/app/component/command/KonsoleItem.tsx
+++ b/js/app/packages/app/component/command/KonsoleItem.tsx
@@ -374,10 +374,16 @@ export function useCommandItemAction(args: {
if (!item) return;
const blockName = getCommandItemBlockName(item);
const id = item.data.id;
- const split = action === 'new-split' ? insertSplit : replaceSplit;
if (blockName) {
- split({ type: blockName, id });
+ if (action === 'new-split') {
+ insertSplit({ type: blockName, id }, 'kommand-menu');
+ } else {
+ replaceSplit({
+ content: { type: blockName, id },
+ referredFrom: 'kommand-menu',
+ });
+ }
if (item.snippet) {
gotoSnippetLocation(blockOrchestrator, id, item.snippet, cleanQuery());
}
diff --git a/js/app/packages/app/component/dock/Dock.tsx b/js/app/packages/app/component/dock/Dock.tsx
index adaf424c0e..92a2ff001d 100644
--- a/js/app/packages/app/component/dock/Dock.tsx
+++ b/js/app/packages/app/component/dock/Dock.tsx
@@ -320,8 +320,11 @@ export function Dock() {
const canFit = manager.resizeContext()?.canFit({ minSize: 400 }) ?? true;
if (canFit) {
manager.createNewSplit({
- id: 'unified-list',
- type: 'component',
+ content: {
+ id: 'unified-list',
+ type: 'component',
+ },
+ referredFrom: 'dock'
});
}
}
diff --git a/js/app/packages/app/component/dock/QuickAccess.tsx b/js/app/packages/app/component/dock/QuickAccess.tsx
index 1c622582c6..165f4889a0 100644
--- a/js/app/packages/app/component/dock/QuickAccess.tsx
+++ b/js/app/packages/app/component/dock/QuickAccess.tsx
@@ -74,10 +74,13 @@ function QuickAccessItem(props: QuickAccessItemProps) {
messageId: string,
threadId?: string
) => {
- replaceOrInsertSplit({
- type: 'channel',
- id: channelId,
- });
+ replaceOrInsertSplit(
+ {
+ type: 'channel',
+ id: channelId,
+ },
+ 'quick-access'
+ );
messageLocation(channelId, messageId, threadId);
};
@@ -103,11 +106,14 @@ function QuickAccessItem(props: QuickAccessItemProps) {
metadata.threadId || undefined
);
} else {
- replaceOrInsertSplit({ type: 'channel', id: channelId });
+ replaceOrInsertSplit(
+ { type: 'channel', id: channelId },
+ 'quick-access'
+ );
}
} else {
// Default to channel for other notifications
- replaceOrInsertSplit({ type: 'channel', id: channelId });
+ replaceOrInsertSplit({ type: 'channel', id: channelId }, 'quick-access');
}
const nextIndex = (currentNotificationIndex() + 1) % notifications.length;
diff --git a/js/app/packages/app/component/mobile/MobileDock.tsx b/js/app/packages/app/component/mobile/MobileDock.tsx
index 0efdd7f929..b2e1c5c997 100644
--- a/js/app/packages/app/component/mobile/MobileDock.tsx
+++ b/js/app/packages/app/component/mobile/MobileDock.tsx
@@ -33,12 +33,14 @@ function MobileDockButton(props: MobileDockButtonProps) {
export function MobileDock() {
const splitContext = useSplitPanelOrThrow();
- const { selectedView, setSelectedView } = splitContext.unifiedListContext;
+ const { selectedView, setSelectedView } = splitContext.soupContext;
const ensureUnifiedList = () => {
const content = splitContext.handle.content();
if (content.type === 'component' && content.id === 'unified-list') return;
- splitContext.handle.replace({ type: 'component', id: 'unified-list' });
+ splitContext.handle.replace({
+ next: { type: 'component', id: 'unified-list' },
+ });
};
const focusSearchInput = (viewId: string) => {
diff --git a/js/app/packages/app/component/soupContextHelpers.ts b/js/app/packages/app/component/soupContextHelpers.ts
new file mode 100644
index 0000000000..758e474bac
--- /dev/null
+++ b/js/app/packages/app/component/soupContextHelpers.ts
@@ -0,0 +1,178 @@
+import type { BlockChannelProps } from '@block-channel/component/Block';
+import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
+import { URL_PARAMS as EMAIL_PARAMS } from '@block-email/constants';
+import { URL_PARAMS as MD_PARAMS } from '@block-md/constants';
+import { URL_PARAMS as PDF_PARAMS } from '@block-pdf/signal/location';
+import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import type { BlockOrchestrator } from '@core/orchestrator';
+import type { DocumentEntity, EntityData, SearchLocation } from '@macro-entity';
+import { globalSplitManager } from '../signal/splitLayout';
+import type { SplitContent, SplitHandle } from './split-layout/layoutManager';
+
+export interface OpenEntityOptions {
+ openInNewSplit?: boolean;
+ location?: SearchLocation;
+ splitHandle: SplitHandle;
+}
+
+/**
+ * Opens an entity in a split, handling navigation to specific locations within the entity.
+ * Supports both regular entities (channel, email, etc.) and document entities.
+ *
+ * @param entity - The entity to open
+ * @param options - Configuration options including whether to open in new split, location, and split handle
+ */
+export const openEntityInSplitFromUnifiedList = async (
+ entity: EntityData,
+ options: OpenEntityOptions
+): Promise<void> => {
+ const { openInNewSplit, location, splitHandle } = options;
+
+ // Get dependencies internally
+ const splitManager = globalSplitManager();
+ if (!splitManager) {
+ console.error('No split manager found');
+ return;
+ }
+
+ const blockOrchestrator = splitManager.getOrchestrator();
+
+ // Create split functions
+ const insertSplit = (content: SplitContent) => {
+ return splitManager.createNewSplit({
+ content,
+ activate: true,
+ referredFrom: 'unified-list',
+ });
+ };
+
+ const replaceOrInsertSplit = (content: SplitContent) => {
+ const existingSplit = splitManager.getSplitByContent(
+ content.type,
+ content.id
+ );
+ if (existingSplit) {
+ return existingSplit;
+ }
+
+ splitHandle.replace({ next: content, referredFrom: 'unified-list' });
+ return splitHandle;
+ };
+
+ // Handle document entities separately
+ if (entity.type === 'document') {
+ return openDocument(entity as DocumentEntity, {
+ openInNewSplit,
+ blockOrchestrator,
+ location,
+ insertSplit,
+ replaceOrInsertSplit,
+ });
+ }
+
+ // Build params for channel entities with location
+ const params =
+ entity.type === 'channel' && location?.type === 'channel'
+ ? ({
+ target: {
+ threadId: location.threadId,
+ messageId: location.messageId,
+ },
+ } as BlockChannelProps)
+ : undefined;
+
+ // Create or replace split based on openInNewSplit option
+ const handle = openInNewSplit
+ ? insertSplit({ type: entity.type, id: entity.id, params })
+ : replaceOrInsertSplit({ type: entity.type, id: entity.id, params });
+
+ handle?.activate();
+
+ // Navigate to specific location if provided
+ if (!location) return;
+
+ await navigateToLocation(entity.id, location, blockOrchestrator);
+};
+
+/**
+ * Opens a document entity in a split.
+ */
+async function openDocument(
+ entity: DocumentEntity,
+ options: {
+ openInNewSplit?: boolean;
+ blockOrchestrator: BlockOrchestrator;
+ location?: SearchLocation;
+ insertSplit: (content: SplitContent) => SplitHandle | undefined;
+ replaceOrInsertSplit: (content: SplitContent) => SplitHandle | undefined;
+ }
+): Promise<void> {
+ const {
+ openInNewSplit,
+ blockOrchestrator,
+ location,
+ insertSplit,
+ replaceOrInsertSplit,
+ } = options;
+
+ const { id, fileType, subType } = entity;
+ const blockName = fileTypeToBlockName(subType ?? fileType);
+
+ // Create or replace split based on openInNewSplit option
+ const handle = openInNewSplit
+ ? insertSplit({ type: blockName, id })
+ : replaceOrInsertSplit({ type: blockName, id });
+
+ handle?.activate();
+
+ // Navigate to specific location if provided
+ if (!location) return;
+
+ await navigateToLocation(id, location, blockOrchestrator);
+}
+
+/**
+ * Navigates to a specific location within a block.
+ */
+async function navigateToLocation(
+ entityId: string,
+ location: SearchLocation,
+ blockOrchestrator: BlockOrchestrator
+): Promise<void> {
+ const blockHandle = await blockOrchestrator.getBlockHandle(entityId);
+ if (!blockHandle) return;
+
+ switch (location.type) {
+ case 'channel': {
+ // NOTE: this is handled by the channel block params but this can be used to re-flash an open channel
+ await blockHandle.goToLocationFromParams({
+ [CHANNEL_PARAMS.thread]: location.threadId,
+ [CHANNEL_PARAMS.message]: location.messageId,
+ });
+ break;
+ }
+ case 'email': {
+ await blockHandle.goToLocationFromParams({
+ [EMAIL_PARAMS.messageId]: location.messageId,
+ });
+ break;
+ }
+ case 'md': {
+ await blockHandle.goToLocationFromParams({
+ [MD_PARAMS.nodeId]: location.nodeId,
+ });
+ break;
+ }
+ case 'pdf': {
+ await blockHandle.goToLocationFromParams({
+ [PDF_PARAMS.searchPage]: location.searchPage.toString(),
+ [PDF_PARAMS.searchRawQuery]: location.searchRawQuery,
+ [PDF_PARAMS.searchHighlightTerms]: JSON.stringify(
+ location.highlightTerms
+ ),
+ [PDF_PARAMS.searchSnippet]: location.searchSnippet,
+ });
+ break;
+ }
+ }
+}
diff --git a/js/app/packages/app/component/split-layout/SplitButtons.tsx b/js/app/packages/app/component/split-layout/SplitButtons.tsx
index b836b1aed8..9c58b43b65 100644
--- a/js/app/packages/app/component/split-layout/SplitButtons.tsx
+++ b/js/app/packages/app/component/split-layout/SplitButtons.tsx
@@ -44,8 +44,11 @@ export function SplitCreateButton() {
tooltip={{ label: 'Create new split' }}
onClick={() => {
context.manager.createNewSplit({
- type: 'component',
- id: 'unified-list',
+ content: {
+ type: 'component',
+ id: 'unified-list',
+ },
+ referredFrom: 'dock',
});
}}
/>
diff --git a/js/app/packages/app/component/split-layout/SplitLayout.tsx b/js/app/packages/app/component/split-layout/SplitLayout.tsx
index dcb0575d23..1e9c28cd41 100644
--- a/js/app/packages/app/component/split-layout/SplitLayout.tsx
+++ b/js/app/packages/app/component/split-layout/SplitLayout.tsx
@@ -356,7 +356,7 @@ function SplitPanel(props: SplitPanelProps) {
const panelSize = createElementSize(panelRef);
const [contentOffsetTop, setContentOffsetTop] = createSignal(0);
- const unifiedListContext = createSoupContext();
+ const soupContext = createSoupContext();
const [previewState, setPreviewState] = createSignal(false);
@@ -370,7 +370,7 @@ function SplitPanel(props: SplitPanelProps) {
goBack: () => props.handle.goBack(),
canGoForward: () => props.handle.canGoForward(),
goForward: () => props.handle.goForward(),
- setSelectedView: (view) => unifiedListContext.setSelectedView(view),
+ setSelectedView: (view) => soupContext.setSelectedView(view),
replaceSplit: splitLayoutHelpers.replaceSplit,
splitName: () => props.handle.displayName(),
getSplitCount: () => splitLayoutHelpers.getSplitCount(),
@@ -379,20 +379,20 @@ function SplitPanel(props: SplitPanelProps) {
return !(content.type === 'component' && content.id === 'unified-list');
},
});
+
createNavigationEntityListShortcut({
splitHandle: props.handle,
splitHotkeyScope,
- unifiedListContext,
+ soupContext,
previewState: [previewState, setPreviewState],
getSplitCount: () => splitLayoutHelpers.getSplitCount(),
});
-
return (
<SplitPanelContext.Provider
value={{
handle: props.handle,
splitHotkeyScope,
- unifiedListContext,
+ soupContext,
isPanelActive: () => props.active,
panelRef,
panelSize,
diff --git a/js/app/packages/app/component/split-layout/components/PopoverSplitRenderer.tsx b/js/app/packages/app/component/split-layout/components/PopoverSplitRenderer.tsx
index a956050aa1..01a352f066 100644
--- a/js/app/packages/app/component/split-layout/components/PopoverSplitRenderer.tsx
+++ b/js/app/packages/app/component/split-layout/components/PopoverSplitRenderer.tsx
@@ -84,13 +84,14 @@ function PopoverSplitModal(props: {
props.popover.mount.kind === 'component'
? (props.popover.mount as any).updateMeta
: undefined,
+ referredFrom: () => null,
};
const stubPanelContext: SplitPanelContextType = {
handle: stubHandle,
splitHotkeyScope: `popover-${props.popover.id}`,
isPanelActive: () => true,
- unifiedListContext: createStubSoupContext(),
+ soupContext: createStubSoupContext(),
panelRef,
panelSize: { width: null, height: null },
contentOffsetTop,
diff --git a/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx b/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx
index a6df0f145b..1f2721b840 100644
--- a/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx
@@ -146,10 +146,13 @@ export function SplitFileMenu(props: {
name: props.name,
});
if (res) {
- replaceOrInsertSplit({
- id: res,
- type: blockName,
- });
+ replaceOrInsertSplit(
+ {
+ id: res,
+ type: blockName,
+ },
+ 'entity-actions-menu'
+ );
}
},
icon: Copy,
diff --git a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
index b76bf43e0c..904bc13b4b 100644
--- a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
@@ -180,7 +180,7 @@ function SplitSettingsButton() {
activeSplit()?.goBack();
return;
}
- replaceSplit({ type: 'component', id: 'settings' });
+ replaceSplit({ content: { type: 'component', id: 'settings' } });
}}
>
<IconGear />
diff --git a/js/app/packages/app/component/split-layout/context.ts b/js/app/packages/app/component/split-layout/context.ts
index d5326fc386..aae728d358 100644
--- a/js/app/packages/app/component/split-layout/context.ts
+++ b/js/app/packages/app/component/split-layout/context.ts
@@ -5,7 +5,7 @@ import {
type Setter,
type Signal,
} from 'solid-js';
-import type { UnifiedListContext } from '../SoupContext';
+import type { SoupContext } from '../SoupContext';
import type { SplitHandle, SplitManager } from './layoutManager';
export const SplitLayoutContext = createContext<{
@@ -20,7 +20,7 @@ export type HalfSplitState = {
export type SplitPanelContextType = {
handle: SplitHandle;
splitHotkeyScope: string;
- unifiedListContext: UnifiedListContext;
+ soupContext: SoupContext;
isPanelActive: Accessor<boolean>;
panelRef: Accessor<HTMLElement | null>;
panelSize: NullableSize;
diff --git a/js/app/packages/app/component/split-layout/layout.ts b/js/app/packages/app/component/split-layout/layout.ts
index e742ec2eaf..1620a4bef0 100644
--- a/js/app/packages/app/component/split-layout/layout.ts
+++ b/js/app/packages/app/component/split-layout/layout.ts
@@ -1,12 +1,15 @@
import { useContext } from 'solid-js';
import { globalSplitManager } from '../../signal/splitLayout';
import { SplitPanelContext } from './context';
-import type { SplitContent } from './layoutManager';
+import type { ReferredFrom, SplitContent } from './layoutManager';
export function useSplitLayout() {
const splitPanelContext = useContext(SplitPanelContext);
- function replaceOrInsertSplit(content: SplitContent) {
+ function replaceOrInsertSplit(
+ content: SplitContent,
+ referredFrom: ReferredFrom = null
+ ) {
const splitManager = globalSplitManager();
if (!splitManager) {
console.error('No split manager found');
@@ -23,16 +26,32 @@ export function useSplitLayout() {
}
if (splitPanelContext) {
- splitPanelContext.handle.replace(content);
+ splitPanelContext.handle.replace({
+ next: content,
+ referredFrom: referredFrom ?? null,
+ });
return splitPanelContext.handle;
} else {
- return splitManager.createNewSplit(content, true);
+ return splitManager.createNewSplit({
+ content,
+ activate: true,
+ referredFrom,
+ });
}
}
- function replaceSplit(content: SplitContent, mergeHistory?: boolean) {
+ function replaceSplit(options: {
+ content: SplitContent;
+ mergeHistory?: boolean;
+ referredFrom?: ReferredFrom;
+ }) {
+ const { content, mergeHistory, referredFrom } = options;
if (splitPanelContext) {
- splitPanelContext.handle.replace(content, mergeHistory);
+ splitPanelContext.handle.replace({
+ next: content,
+ mergeHistory,
+ referredFrom: referredFrom ?? null,
+ });
return splitPanelContext.handle;
}
const splitManager = globalSplitManager();
@@ -44,18 +63,29 @@ export function useSplitLayout() {
const activeSplitId = splitManager.activeSplitId();
const activeSplit = activeSplitId && splitManager.getSplit(activeSplitId);
if (activeSplit) {
- activeSplit.replace(content, mergeHistory);
+ activeSplit.replace({
+ next: content,
+ mergeHistory,
+ referredFrom: referredFrom ?? null,
+ });
return activeSplit;
}
}
- function insertSplit(content: SplitContent) {
+ function insertSplit(
+ content: SplitContent,
+ referredFrom: ReferredFrom = null
+ ) {
const splitManager = globalSplitManager();
if (!splitManager) {
console.error('No split manager found');
return;
}
- return splitManager.createNewSplit(content, true);
+ return splitManager.createNewSplit({
+ content,
+ activate: true,
+ referredFrom,
+ });
}
function popoverSplit(content: SplitContent) {
diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.ts
index 9979a27bb2..729d0e5eee 100644
--- a/js/app/packages/app/component/split-layout/layoutManager.ts
+++ b/js/app/packages/app/component/split-layout/layoutManager.ts
@@ -94,11 +94,32 @@ export type PopoverSplitHandle = {
id: string;
};
+export type ReferredFrom =
+ | 'unified-list'
+ | 'kommand-menu'
+ | 'mention'
+ | 'attachment'
+ | 'launcher'
+ | 'dock'
+ | 'entity-actions-menu'
+ | 'hotkey'
+ | 'quick-access'
+ | 'file-upload'
+ | 'search'
+ | null;
+
export type SplitState = {
id: SplitId;
history: History<SplitContent>;
content: SplitContent; // mirror of current history entry
mount: SplitMount; // contains pinned element
+ referredFrom: ReferredFrom;
+};
+
+export type CreateNewSplitOptions = {
+ content?: SplitContent;
+ activate?: boolean;
+ referredFrom: ReferredFrom;
};
function keyOfSplitState(s: SplitState): SplitKey {
@@ -180,7 +201,7 @@ export type SplitManager = {
removeSplit: (id: SplitId) => void;
/** Create a new split with the provided initial content and activate it */
- createNewSplit: (initial?: SplitContent, activate?: boolean) => SplitHandle;
+ createNewSplit: (options: CreateNewSplitOptions) => SplitHandle;
/** Set a split as active by its split id */
activateSplit: (id: SplitId) => void;
@@ -254,7 +275,11 @@ export type SplitHandle<TMeta extends ComponentMeta = ComponentMeta> = {
registerContentChangeListener: (
cb: (payload: SplitEventPayload[SplitEvent.ContentChange]) => void
) => void;
- replace: (next: SplitContent, mergeHistory?: boolean) => void;
+ replace: (options: {
+ next: SplitContent;
+ mergeHistory?: boolean;
+ referredFrom?: ReferredFrom;
+ }) => void;
removeFromHistory: (predicate: (content: SplitContent) => boolean) => void;
toggleSpotlight: (force?: boolean) => void;
setDisplayName: (name: string) => void;
@@ -277,6 +302,7 @@ export type SplitHandle<TMeta extends ComponentMeta = ComponentMeta> = {
meta: () => Store<TMeta> | undefined;
/** Update component metadata (only available for component splits) */
updateMeta: ((data: Omit<TMeta, 'kind'>) => void) | undefined;
+ referredFrom: () => ReferredFrom;
} & UrlCapabilities;
function newSplitId(): SplitId {
@@ -399,10 +425,12 @@ export function createSplitLayout(
]);
}
- function buildSplit(
- initialContent: SplitContent,
- isDefault?: boolean
- ): SplitState {
+ function buildSplit(options: {
+ initialContent: SplitContent;
+ isDefault?: boolean;
+ referredFrom?: ReferredFrom;
+ }): SplitState {
+ const { initialContent, isDefault, referredFrom } = options;
const id = newSplitId();
const history = createHistory<SplitContent>();
const content = attachAliasContext(initialContent);
@@ -420,10 +448,15 @@ export function createSplitLayout(
history,
content,
mount,
+ referredFrom: referredFrom ?? null,
};
}
- function reattach(split: SplitState, next: SplitContent) {
+ function reattach(
+ split: SplitState,
+ next: SplitContent,
+ referredFrom?: ReferredFrom
+ ) {
const otherSplits = state.splits.filter((s) => s.id !== split.id);
const content = attachAliasContext(next);
if (isDuplicateSplit(otherSplits, next)) return;
@@ -445,20 +478,35 @@ export function createSplitLayout(
}
}
- if (sameIdentity(split.content, content))
+ if (sameIdentity(split.content, content)) {
+ // Update referredFrom if provided, even if content is the same
+ if (referredFrom !== undefined) {
+ return setState('splits', (s) => {
+ const i = s.findIndex((x) => x.id === split.id);
+ if (i < 0) return s;
+ const target = { ...s[i], content: content, referredFrom };
+ return s.with(i, target);
+ });
+ }
return setState('splits', (s) => {
const i = s.findIndex((x) => x.id === split.id);
if (i < 0) return s;
const target = { ...s[i], content: content };
return s.with(i, target);
});
+ }
const newMount = createPinnedMount(orchestrator, content);
setState('splits', (s) => {
const i = s.findIndex((x) => x.id === split.id);
if (i < 0) return s;
- const target = { ...s[i], content, mount: newMount };
+ const target = {
+ ...s[i],
+ content,
+ mount: newMount,
+ ...(referredFrom !== undefined && { referredFrom }),
+ };
return s.with(i, target);
});
}
@@ -506,7 +554,15 @@ export function createSplitLayout(
/**
* Replace the content of a split with the provided content. If mergeHistory is true, the current history index will be replaced with the new content.
*/
- function replace(id: SplitId, next: SplitContent, mergeHistory?: boolean) {
+ function replace(
+ id: SplitId,
+ options: {
+ next: SplitContent;
+ mergeHistory?: boolean;
+ referredFrom?: ReferredFrom;
+ }
+ ) {
+ const { next, mergeHistory, referredFrom } = options;
const i = state.splits.findIndex((s) => s.id === id);
if (i < 0) return console.error(`Split with id ${id} not found`);
@@ -526,7 +582,7 @@ export function createSplitLayout(
split.history.push(content);
}
- reattach(split, content);
+ reattach(split, content, referredFrom);
}
function reset(id: SplitId) {
@@ -614,8 +670,8 @@ export function createSplitLayout(
goBack: () => back(currentSplit.id),
reset: () => reset(currentSplit.id),
goForward: () => forward(currentSplit.id),
- replace: (next, mergeHistory = false) =>
- replace(currentSplit.id, next, mergeHistory),
+ replace: ({ next, mergeHistory = false, referredFrom }) =>
+ replace(currentSplit.id, { next, mergeHistory, referredFrom }),
removeFromHistory: (predicate: (content: SplitContent) => boolean) => {
removeFromHistory(currentSplit.id, predicate);
},
@@ -624,7 +680,10 @@ export function createSplitLayout(
if (state.splits.length <= 1) {
// If it's not the default split, replace it with the default
if (!sameContent(content(), DEFAULT_SPLIT_CONTENT))
- replace(currentSplit.id, DEFAULT_SPLIT_CONTENT);
+ replace(currentSplit.id, {
+ next: DEFAULT_SPLIT_CONTENT,
+ referredFrom: null,
+ });
return;
}
@@ -672,13 +731,12 @@ export function createSplitLayout(
currentSplit.mount.kind === 'component'
? currentSplit.mount.updateMeta
: undefined,
+ referredFrom: () => s()?.referredFrom ?? null,
};
};
- function createNewSplit(
- content?: SplitContent,
- activate?: boolean
- ): SplitHandle {
+ function createNewSplit(options: CreateNewSplitOptions): SplitHandle {
+ const { content, activate, referredFrom } = options;
const initialContent = content ?? DEFAULT_SPLIT_CONTENT;
const isDefault = sameContent(initialContent, DEFAULT_SPLIT_CONTENT);
@@ -692,7 +750,7 @@ export function createSplitLayout(
return getSplit(existingSplit!.id)!;
}
- const split = buildSplit(initialContent, isDefault);
+ const split = buildSplit({ initialContent, isDefault, referredFrom });
setState('splits', (previousSplits) => [...previousSplits, split]);
@@ -729,7 +787,7 @@ export function createSplitLayout(
dispatchEvent(SplitEvent.Remove, { splitId: id, splitIndex: idx });
if (nextSplits.length === 0 && createNewOnEmpty) {
- createNewSplit(DEFAULT_SPLIT_CONTENT);
+ createNewSplit({ content: DEFAULT_SPLIT_CONTENT, referredFrom: null });
}
}
@@ -783,9 +841,22 @@ export function createSplitLayout(
for (const split of newSplits) {
if (split.type === 'component') {
- newState.push(buildSplit(split));
+ newState.push(
+ buildSplit({
+ initialContent: split,
+ isDefault: false,
+ referredFrom: null,
+ })
+ );
} else {
- newState.push(lookup(split.type, split.id) ?? buildSplit(split));
+ newState.push(
+ lookup(split.type, split.id) ??
+ buildSplit({
+ initialContent: split,
+ isDefault: false,
+ referredFrom: null,
+ })
+ );
}
}
@@ -795,7 +866,7 @@ export function createSplitLayout(
const lastEvent = createMemo(() => state.events[state.events.length - 1]);
for (const split of initial) {
- createNewSplit(split, true);
+ createNewSplit({ content: split, activate: true, referredFrom: null });
}
const tabTitle = () => {
diff --git a/js/app/packages/app/component/split-layout/registerSplitHotkeys.ts b/js/app/packages/app/component/split-layout/registerSplitHotkeys.ts
index bc5eb1ada0..87a77f4f51 100644
--- a/js/app/packages/app/component/split-layout/registerSplitHotkeys.ts
+++ b/js/app/packages/app/component/split-layout/registerSplitHotkeys.ts
@@ -8,7 +8,7 @@ import type { ViewId } from '@core/types/view';
import { registerHotkey } from 'core/hotkey/hotkeys';
import { globalSplitManager } from '../../signal/splitLayout';
import { fireMacroJump } from '../MacroJump';
-import type { SplitContent } from './layoutManager';
+import type { ReferredFrom, SplitContent } from './layoutManager';
import { focusAdjacentSplit } from './layoutUtils';
import { canSpotlight } from './utils/canSpotlight';
@@ -22,7 +22,10 @@ export function registerSplitHotkeys(args: {
canGoForward: () => boolean;
goForward: () => void;
setSelectedView: (view: ViewId) => void;
- replaceSplit: (content: SplitContent) => void;
+ replaceSplit: (options: {
+ content: SplitContent;
+ referredFrom?: ReferredFrom;
+ }) => void;
splitName: () => string;
getSplitCount: () => number;
isNotUnifiedList: () => boolean;
@@ -76,7 +79,10 @@ export function registerSplitHotkeys(args: {
description: 'Go home',
condition: isNotUnifiedList,
keyDownHandler: () => {
- replaceSplit({ type: 'component', id: 'unified-list' });
+ replaceSplit({
+ content: { type: 'component', id: 'unified-list' },
+ referredFrom: 'hotkey',
+ });
return true;
},
hotkeyToken: TOKENS.split.goHome,
diff --git a/js/app/packages/app/component/useNavigatedFromJK.ts b/js/app/packages/app/component/useNavigatedFromJK.ts
index 4898d3e8d8..bb1be711e3 100644
--- a/js/app/packages/app/component/useNavigatedFromJK.ts
+++ b/js/app/packages/app/component/useNavigatedFromJK.ts
@@ -5,7 +5,7 @@ import { useSplitPanelOrThrow } from './split-layout/layoutUtils';
export function useNavigatedFromJK() {
const {
- unifiedListContext: {
+ soupContext: {
entitiesSignal: [_entities],
},
} = useSplitPanelOrThrow();
diff --git a/js/app/packages/app/util/handleFileUpload.ts b/js/app/packages/app/util/handleFileUpload.ts
index 2a98072dc5..7a68294665 100644
--- a/js/app/packages/app/util/handleFileUpload.ts
+++ b/js/app/packages/app/util/handleFileUpload.ts
@@ -56,10 +56,13 @@ export function useHandleFileUpload({
const upload = successfulUploads[0];
if (upload.type === 'document') {
- replaceOrInsertSplit({
- type: fileTypeToBlockName(upload.fileType),
- id: upload.documentId,
- });
+ replaceOrInsertSplit(
+ {
+ type: fileTypeToBlockName(upload.fileType),
+ id: upload.documentId,
+ },
+ 'file-upload'
+ );
}
};
}
diff --git a/js/app/packages/block-email/component/Compose.tsx b/js/app/packages/block-email/component/Compose.tsx
index e636c76470..843c9996ed 100644
--- a/js/app/packages/block-email/component/Compose.tsx
+++ b/js/app/packages/block-email/component/Compose.tsx
@@ -243,7 +243,10 @@ export function EmailCompose() {
onSuccess: (data) => {
toast.success('Email sent');
if (data.message.thread_db_id) {
- replaceSplit({ type: 'email', id: data.message.thread_db_id }, true);
+ replaceSplit({
+ content: { type: 'email', id: data.message.thread_db_id },
+ mergeHistory: true,
+ });
}
},
onError: () => {
diff --git a/js/app/packages/block-email/component/EmailContext.tsx b/js/app/packages/block-email/component/EmailContext.tsx
index 1cc2e2693c..c2a4a9ccec 100644
--- a/js/app/packages/block-email/component/EmailContext.tsx
+++ b/js/app/packages/block-email/component/EmailContext.tsx
@@ -284,7 +284,7 @@ export function EmailProvider(props: FlowProps<{ threadID: string }>) {
};
const {
- unifiedListContext: {
+ soupContext: {
entitiesSignal: [entities],
actionRegistry,
},
diff --git a/js/app/packages/block-email/signal/threadNavigation.ts b/js/app/packages/block-email/signal/threadNavigation.ts
index 5d60bea79d..dc867e7242 100644
--- a/js/app/packages/block-email/signal/threadNavigation.ts
+++ b/js/app/packages/block-email/signal/threadNavigation.ts
@@ -5,7 +5,7 @@ import { useSplitLayout } from '../../app/component/split-layout/layout';
export function useThreadNavigation() {
const {
- unifiedListContext: {
+ soupContext: {
entitiesSignal: [entities],
selectedView,
setViewDataStore,
diff --git a/js/app/packages/block-project/component/Block.tsx b/js/app/packages/block-project/component/Block.tsx
index 9b9ffde71a..e70f7156f9 100644
--- a/js/app/packages/block-project/component/Block.tsx
+++ b/js/app/packages/block-project/component/Block.tsx
@@ -85,7 +85,7 @@ const Block: Component = () => {
const splitContext = useSplitPanelOrThrow();
const { selectedView, setSelectedView, setViewDataStore } =
- splitContext.unifiedListContext;
+ splitContext.soupContext;
createRenderEffect(() => {
const previousView = untrack(selectedView);
diff --git a/js/app/packages/block-project/component/ProjectCreateMenu.tsx b/js/app/packages/block-project/component/ProjectCreateMenu.tsx
index d87877f79f..df0d856651 100644
--- a/js/app/packages/block-project/component/ProjectCreateMenu.tsx
+++ b/js/app/packages/block-project/component/ProjectCreateMenu.tsx
@@ -70,11 +70,19 @@ function MenuContent(props: { projectId: string }) {
const block = { type: blockName, id };
- shouldInsert ? insertSplit(block) : replaceSplit(block);
+ shouldInsert
+ ? insertSplit(block, 'entity-actions-menu')
+ : replaceSplit({ content: block, referredFrom: 'entity-actions-menu' });
} else {
const split = shouldInsert
- ? insertSplit({ type: 'component', id: 'loading' })
- : replaceSplit({ type: 'component', id: 'loading' });
+ ? insertSplit(
+ { type: 'component', id: 'loading' },
+ 'entity-actions-menu'
+ )
+ : replaceSplit({
+ content: { type: 'component', id: 'loading' },
+ referredFrom: 'entity-actions-menu',
+ });
const id = await tryCreate();
if (!id) {
@@ -82,7 +90,12 @@ function MenuContent(props: { projectId: string }) {
return;
}
- if (split) split.replace({ type: blockName, id }, true);
+ if (split)
+ split.replace({
+ next: { type: blockName, id },
+ mergeHistory: true,
+ referredFrom: 'entity-actions-menu',
+ });
}
};
diff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsx
index 78a57afd64..d7c0ecc386 100644
--- a/js/app/packages/core/component/DocumentPreview.tsx
+++ b/js/app/packages/core/component/DocumentPreview.tsx
@@ -385,9 +385,12 @@ export function PopupPreview(props: {
const splitManager = globalSplitManager();
if (splitManager) {
splitManager.createNewSplit({
- type: props.documentInfo.type,
- id: props.documentInfo.id,
- params: props.documentInfo.params,
+ content: {
+ type: props.documentInfo.type,
+ id: props.documentInfo.id,
+ params: props.documentInfo.params,
+ },
+ referredFrom: null,
});
}
});
diff --git a/js/app/packages/core/util/channels.ts b/js/app/packages/core/util/channels.ts
index 2506c1b0a2..6341cff145 100644
--- a/js/app/packages/core/util/channels.ts
+++ b/js/app/packages/core/util/channels.ts
@@ -68,13 +68,13 @@ export function useSendMessageToPeople() {
refetchContacts();
const navigateToChannel = async () => {
- replaceSplit(
- {
+ replaceSplit({
+ content: {
type: 'channel',
id: channelId,
},
- navigate?.mergeHistory
- );
+ mergeHistory: navigate?.mergeHistory,
+ });
const handle = await orchestrator.getBlockHandle(channelId);
await handle?.goToLocationFromParams({
message_id: messageResponse.id,
diff --git a/js/app/packages/notifications/notification-navigation.ts b/js/app/packages/notifications/notification-navigation.ts
index d553f85bda..cca6ed1f49 100644
--- a/js/app/packages/notifications/notification-navigation.ts
+++ b/js/app/packages/notifications/notification-navigation.ts
@@ -41,8 +41,8 @@ function openSplitIfNotOpen(
if (!isSplitOpen) {
layoutManager.createNewSplit({
- type,
- id,
+ content: { type, id },
+ referredFrom: null,
});
}
}