Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(soup): make g->d hotkey work (#4082)

Seamusc6a86a074e10
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.tsx b/js/app/packages/app/component/app-sidebar/sidebar.tsx
index 8ffed4626b..2a76ba743c 100644
--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx
+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx
@@ -12,6 +12,7 @@ import {
import { CommandState } from '@app/component/command';
import { InteractiveOnboardingModal } from '@app/component/interactive-onboarding/InteractiveOnboardingModal';
import { createMenuOpen, setCreateMenuOpen } from '@app/component/Launcher';
+import { getDocumentsFilterSplit } from '@app/component/next-soup/soup-view/documents-filter-controllers';
import {
getInboxFilterSplit,
INBOX_FILTER_ENTRY_KEY,
@@ -102,12 +103,14 @@ interface SidebarItem {
id: ListView | (string & {});
label: string;
href: string;
+ params?: Record<string, unknown>;
icon?: Component<
JSX.SvgSVGAttributes<SVGSVGElement> | { triggerAnimation?: boolean }
>;
hotkey: ValidHotkey;
hotkeyToken: HotkeyToken;
standaloneHotkey?: boolean;
+ hiddenFromSidebar?: boolean;
}
const SIDEBAR_LINKS = [
@@ -152,6 +155,22 @@ const SIDEBAR_LINKS = [
hotkey: 'f',
hotkeyToken: TOKENS.sidebar.goTo.documents,
},
+ {
+ id: 'documents',
+ label: 'Documents',
+ href: LIST_VIEW_PATHS.documents,
+ params: {
+ initialFilters: { include: { fileAssoc: ['assoc:md'] } },
+ initialClientFilters: {
+ and: ['document-or-file'],
+ or: ['doc-markdown'],
+ },
+ },
+ icon: AnimatedFileMdIcon,
+ hotkey: 'd',
+ hotkeyToken: TOKENS.sidebar.goTo.markdownDocuments,
+ hiddenFromSidebar: true,
+ },
{
id: 'tasks',
label: 'Tasks',
@@ -284,6 +303,16 @@ const isComponentEntry =
(entry: SplitContent): boolean =>
entry.type === 'component' && entry.id === id;
+const isMarkdownDocumentsParams = (
+ params: SidebarItem['params'] | undefined
+): boolean => {
+ const initialClientFilters = params?.initialClientFilters as
+ | { or?: readonly unknown[] }
+ | undefined;
+
+ return initialClientFilters?.or?.includes('doc-markdown') ?? false;
+};
+
/**
* Navigate to a sidebar view, preserving prior state when possible.
*
@@ -294,19 +323,41 @@ const isComponentEntry =
*/
function navigateToSidebarView(args: {
viewId: SidebarItem['id'];
+ params?: SidebarItem['params'];
shiftKey: boolean;
activeSplit: SplitHandle | undefined;
openWithSplit: OpenWithSplitFn;
referredFrom?: ReferredFrom;
}): SplitHandle | undefined {
- const { viewId, shiftKey, activeSplit, openWithSplit, referredFrom } = args;
+ const { viewId, params, shiftKey, activeSplit, openWithSplit, referredFrom } =
+ args;
+
+ const activeContent = activeSplit?.content();
+ if (
+ !shiftKey &&
+ isMarkdownDocumentsParams(params) &&
+ activeContent?.type === 'component' &&
+ activeContent.id === 'documents'
+ ) {
+ const controller = activeSplit
+ ? getDocumentsFilterSplit(activeSplit.id)
+ : undefined;
+ if (controller) {
+ controller.toggleMarkdownFilter();
+ return activeSplit;
+ }
+ }
- if (!shiftKey && activeSplit?.goToEntry(isComponentEntry(viewId))) {
+ if (
+ !params &&
+ !shiftKey &&
+ activeSplit?.goToEntry(isComponentEntry(viewId))
+ ) {
return activeSplit;
}
return openWithSplit(
- { type: 'component', id: viewId },
+ { type: 'component', id: viewId, params },
{
preferNewSplit: shiftKey,
mergeHistory: false,
@@ -428,6 +479,7 @@ const registerSidebarHotkeys = ({
const handle = navigateToSidebarView({
viewId: link.id,
+ params: link.params,
shiftKey: !!e?.shiftKey,
activeSplit: globalSplitManager()?.activeSplit(),
openWithSplit,
@@ -744,6 +796,21 @@ export const AppSidebar = (props: AppSidebarProps) => {
links = [...links.slice(0, idx + 1), CALLS_LINK, ...links.slice(idx + 1)];
}
+ return links.filter((link) => !link.hiddenFromSidebar);
+ });
+
+ const hotkeyLinks = createMemo((): SidebarItem[] => {
+ let links: SidebarItem[] = [...SIDEBAR_LINKS];
+
+ if (homeViewEnabled().enabled) {
+ links = [DASHBOARD_LINK, ...links];
+ }
+
+ if (ENABLE_CALLS()) {
+ const idx = links.findIndex((l) => l.id === 'channels');
+ links = [...links.slice(0, idx + 1), CALLS_LINK, ...links.slice(idx + 1)];
+ }
+
return links;
});
@@ -824,7 +891,7 @@ export const AppSidebar = (props: AppSidebarProps) => {
});
registerSidebarHotkeys({
- links: visibleLinks,
+ links: hotkeyLinks,
hotkeyVisible,
setHotkeyVisible,
resetHotkeysState,
@@ -1087,6 +1154,7 @@ const SidebarLink = (props: SidebarLinkProps) => {
({
type: 'component',
id: props.id,
+ params: props.params,
}) as const;
const canOpenInNewSplit = () =>
@@ -1157,6 +1225,7 @@ const SidebarLink = (props: SidebarLinkProps) => {
if (!isSameContent || e.shiftKey) {
currentContentHandle = navigateToSidebarView({
viewId: props.id,
+ params: props.params,
shiftKey: e.shiftKey,
activeSplit: currentContentHandle,
openWithSplit: layout.openWithSplit,
diff --git a/js/app/packages/app/component/next-soup/soup-view/documents-filter-controllers.ts b/js/app/packages/app/component/next-soup/soup-view/documents-filter-controllers.ts
new file mode 100644
index 0000000000..eac0471db2
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/documents-filter-controllers.ts
@@ -0,0 +1,23 @@
+import type { SplitId } from '@app/component/split-layout/layoutManager';
+
+type DocumentsFilterController = {
+ toggleMarkdownFilter: () => void;
+};
+
+const registry = new Map<SplitId, DocumentsFilterController>();
+
+export function registerDocumentsFilterSplit(
+ splitId: SplitId,
+ controller: DocumentsFilterController
+): () => void {
+ registry.set(splitId, controller);
+ return () => {
+ if (registry.get(splitId) === controller) registry.delete(splitId);
+ };
+}
+
+export function getDocumentsFilterSplit(
+ splitId: SplitId
+): DocumentsFilterController | undefined {
+ return registry.get(splitId);
+}
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.tsx
index b3834af65f..02db1c5574 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
@@ -19,6 +19,7 @@ import type {
} from '@app/component/next-soup/filters/filter-store';
import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';
import { useSoup } from '@app/component/next-soup/soup-context';
+import { registerDocumentsFilterSplit } from '@app/component/next-soup/soup-view/documents-filter-controllers';
import { EmptyState } from '@app/component/next-soup/soup-view/empty-states';
import { InboxSelector } from '@app/component/next-soup/soup-view/filters-bar/inbox-selector';
import { SoupFiltersBar } from '@app/component/next-soup/soup-view/filters-bar/soup-filters-bar';
@@ -122,6 +123,7 @@ import {
Match,
on,
onCleanup,
+ onMount,
Show,
Suspense,
Switch,
@@ -457,6 +459,32 @@ export const SoupView = (props: SoupViewProps) => {
});
});
+ onMount(() => {
+ if (contentId !== 'documents') return;
+
+ const markdownQuery: Query = { include: { fileAssoc: ['assoc:md'] } };
+ const dispose = registerDocumentsFilterSplit(panel.handle.id, {
+ toggleMarkdownFilter: () => {
+ if (soup.predicates.isActive('doc-markdown')) {
+ soupView.queryFilters.remove(markdownQuery);
+ soup.predicates.set(({ andIds, orIds }) => ({
+ and: andIds,
+ or: orIds.filter((id) => id !== 'doc-markdown'),
+ }));
+ return;
+ }
+
+ soupView.queryFilters.add(markdownQuery);
+ soup.predicates.set(({ andIds, orIds }) => ({
+ and: andIds,
+ or: [...new Set([...orIds, 'doc-markdown'])],
+ }));
+ },
+ });
+
+ onCleanup(dispose);
+ });
+
createEffect(() => {
panel.handle.setDisplayName(props.viewName);
});
diff --git a/js/app/packages/app/component/split-layout/componentRegistry.tsx b/js/app/packages/app/component/split-layout/componentRegistry.tsx
index 15c3e689f6..16b7484f36 100644
--- a/js/app/packages/app/component/split-layout/componentRegistry.tsx
+++ b/js/app/packages/app/component/split-layout/componentRegistry.tsx
@@ -1,7 +1,9 @@
import { useAnalytics } from '@app/component/analytics-context';
import { getViewPreset } from '@app/component/app-sidebar/soup-filter-presets';
import { Home } from '@app/component/home';
+import { queryStateFrom } from '@app/component/next-soup/filters/filter-store';
import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';
+import { mergeQuery } from '@app/component/next-soup/filters/filter-store/query-store';
import type { Query } from '@app/component/next-soup/filters/filter-store/types';
import { SoupView } from '@app/component/next-soup/soup-view/soup-view';
import { ChannelCompose } from '@block-channel/component/Compose';
@@ -46,6 +48,24 @@ const withAuth = <P extends object>(Comp: Component<P>): Component<P> => {
type ComponentFactory = (params?: Record<string, any>) => JSXElement;
+type DocumentsComponentParams = {
+ initialFilters?: Query;
+ initialClientFilters?: SetPredicatesInput<string>;
+};
+
+function mergeClientFilters(
+ base?: SetPredicatesInput<string>,
+ refinement?: SetPredicatesInput<string>
+): SetPredicatesInput<string> | undefined {
+ if (!base) return refinement;
+ if (!refinement) return base;
+
+ return {
+ and: [...new Set([...(base.and ?? []), ...(refinement.and ?? [])])],
+ or: [...new Set([...(base.or ?? []), ...(refinement.or ?? [])])],
+ };
+}
+
export type UnifiedListMeta = {
kind: 'unified-list';
viewId: ViewId;
@@ -172,7 +192,7 @@ registerComponent(
registerComponent(
'documents',
- withAuth(() => {
+ withAuth((params: DocumentsComponentParams = {}) => {
usePageViewTracking('documents');
const user = useUserContext();
const preset = getViewPreset('documents', undefined, {
@@ -180,11 +200,19 @@ registerComponent(
email: user.email(),
isTeamAdmin: false,
});
+ const initialFilters =
+ preset?.filters && params.initialFilters
+ ? mergeQuery(queryStateFrom(preset.filters), params.initialFilters)
+ : (params.initialFilters ?? preset?.filters);
+ const initialClientFilters = mergeClientFilters(
+ preset?.clientFilters,
+ params.initialClientFilters
+ );
return (
<SoupView
viewName="Files"
- initialFilters={preset?.filters}
- initialClientFilters={preset?.clientFilters}
+ initialFilters={initialFilters}
+ initialClientFilters={initialClientFilters}
initialGroupBy={preset?.groupBy}
/>
);
diff --git a/js/app/packages/core/hotkey/tokens.ts b/js/app/packages/core/hotkey/tokens.ts
index dfbeb1a8bb..48f40430fb 100644
--- a/js/app/packages/core/hotkey/tokens.ts
+++ b/js/app/packages/core/hotkey/tokens.ts
@@ -92,6 +92,7 @@ export const TOKENS = {
agents: 'sidebar.goTo.agents',
mail: 'sidebar.goTo.mail',
documents: 'sidebar.goTo.documents',
+ markdownDocuments: 'sidebar.goTo.markdownDocuments',
tasks: 'sidebar.goTo.tasks',
channels: 'sidebar.goTo.channels',
calls: 'sidebar.goTo.calls',