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: support multi hit content matches in front end search (#543)
gbirmand61daaad62cb
diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsxindex 29a2fa97a2..257a3b3f73 100644--- a/js/app/packages/app/component/UnifiedListView.tsx+++ b/js/app/packages/app/component/UnifiedListView.tsx@@ -51,7 +51,6 @@ import {type EntityFilter,type ExpandedEntityType,importantFilterFn,- isSearchEntity,isTaskEntity,notDoneFilterFn,type SortOption,@@ -893,6 +892,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {}if (onlyHas(typeFilter, 'channel')) return true;+ if (isSearchActive() && onlyHas(typeFilter, 'email')) return true;return false;});@@ -1036,7 +1036,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {const documentEntityClickHandler: EntityClickHandler<DocumentEntity | WithSearch<DocumentEntity>- > = async (entity, event) => {+ > = async (entity, event, location) => {const { id, fileType, subType } = entity;const blockName = fileTypeToBlockName(subType ?? fileType);const handle = event.altKey@@ -1045,9 +1045,6 @@ export function UnifiedListView(props: UnifiedListViewProps) {handle?.activate();- if (!isSearchEntity(entity)) return;-- const location = entity.search.contentHitData?.at(0)?.location;if (!location) return;const blockHandle = await blockOrchestrator.getBlockHandle(id);@@ -1073,6 +1070,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {const entityClickHandler: EntityClickHandler<EntityData> = async (entity,event,+ location,options) => {if (preview() && !options?.ignorePreview) {@@ -1081,7 +1079,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {}if (entity.type === 'document')- return documentEntityClickHandler(entity, event);+ return documentEntityClickHandler(entity, event, location);const handle = event.altKey? insertSplit({ type: entity.type, id: entity.id })@@ -1089,9 +1087,6 @@ export function UnifiedListView(props: UnifiedListViewProps) {handle?.activate();- if (!isSearchEntity(entity)) return;-- const location = entity.search.contentHitData?.at(0)?.location;if (!location) return;switch (location.type) {diff --git a/js/app/packages/core/constant/allBlocks.ts b/js/app/packages/core/constant/allBlocks.tsindex d67f35983e..51a109769d 100644--- a/js/app/packages/core/constant/allBlocks.ts+++ b/js/app/packages/core/constant/allBlocks.ts@@ -191,7 +191,7 @@ export function fileTypeToResolvedBlockName(/*** Get the default display name for an unnamed file of a particular block.*/-export function blockNameToDefaultFile(block?: BlockName | string) {+export function blockNameToDefaultFile(block?: BlockName | string | null) {if (!block) return DefaultFilename;if (block in blockNameToDefaultFilename) {return (diff --git a/js/app/packages/macro-entity/src/components/Entity.tsx b/js/app/packages/macro-entity/src/components/Entity.tsxindex 964bb60efc..f62a939247 100644--- a/js/app/packages/macro-entity/src/components/Entity.tsx+++ b/js/app/packages/macro-entity/src/components/Entity.tsx@@ -6,6 +6,7 @@ import { children, createMemo, Show, Suspense } from 'solid-js';import { Dynamic } from 'solid-js/web';import { createProfilePictureQuery } from '../queries/auth';import type { EntityData } from '../types/entity';+import type { SearchLocation } from '../types/search';export type EntityClickEvent = Parameters<JSX.EventHandler<HTMLDivElement, MouseEvent>@@ -13,6 +14,7 @@ export type EntityClickEvent = Parameters<export type EntityClickHandler<T extends EntityData> = (entity: T,event: EntityClickEvent,+ location?: SearchLocation,options?: { ignorePreview?: boolean }) => void;interface EntityProps<T extends EntityData> extends ParentProps {diff --git a/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx b/js/app/packages/macro-entity/src/components/EntityWithEverything.tsxindex f6d0b85a85..e950f5dc8a 100644--- a/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx+++ b/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx@@ -44,6 +44,7 @@ import type { Notification, WithNotification } from '../types/notification';import type {ChannelContentHitData,ContentHitData,+ SearchLocation,WithSearch,} from '../types/search';import type { EntityClickEvent, EntityClickHandler } from './Entity';@@ -118,6 +119,215 @@ function ChannelMessageContentHit(props: { data: ChannelContentHitData }) {);}+function ThreadBorder() {+ return (+ <div+ class="absolute left-[calc(0.5rem+1px)] w-[1px] border-l border-edge-muted -top-0.75"+ style={{ height: '6px' }}+ />+ );+}++function CollapsibleListRow(+ props: ParentProps<{+ onClick?: (e: EntityClickEvent) => void;+ classList?: Record<string, boolean>;+ enableHover?: boolean;+ showThreadBorder?: boolean;+ blockNavigation?: boolean;+ }>+) {+ return (+ <div+ class="relative flex gap-1 items-center min-w-0 h-8 transition-all"+ classList={{+ 'hover:bg-hover/50 hover:opacity-85':+ props.enableHover ?? !!props.onClick,+ ...props.classList,+ }}+ onClick={(e) => {+ if (props.onClick) {+ if (props.blockNavigation) {+ e.stopPropagation();+ }+ props.onClick(e);+ }+ }}+ data-blocks-navigation={props.blockNavigation}+ >+ <Show when={props.showThreadBorder}>+ <ThreadBorder />+ </Show>+ {props.children}+ </div>+ );+}++function CollapsibleList<T>(props: {+ items: T[];+ visibleCount?: number;+ children: (item: T) => any;+ threadBorder?: boolean;+}) {+ const [showAll, setShowAll] = createSignal(false);+ const visibleCount = () => props.visibleCount ?? 3;++ const visibleItems = () => {+ if (props.items.length <= visibleCount() || showAll()) {+ return props.items;+ }+ return props.items.slice(0, visibleCount());+ };++ const hasMore = () => props.items.length > visibleCount();++ return (+ <>+ <For each={visibleItems()}>{props.children}</For>+ <Show when={hasMore()}>+ <div class="relative h-5">+ <Show when={props.threadBorder}>+ <ThreadBorder />+ </Show>+ <button+ class="block w-fit px-2 py-0.5 text-[10px] border border-edge uppercase font-mono hover:font-medium"+ onClick={(e) => {+ e.stopPropagation();+ setShowAll((prev) => !prev);+ }}+ data-blocks-navigation+ >+ <Show when={!showAll()} fallback={<>Collapse</>}>+ + {props.items.length - visibleCount()} More+ </Show>+ </button>+ </div>+ </Show>+ </>+ );+}++function NotificationRow(props: {+ notification: Notification;+ onClick?: NotificationClickHandler;+ entity: EntityData;+}) {+ const [userName] = useDisplayName(props.notification.senderId);+ const formattedDate = createFormattedDate(props.notification.createdAt);++ const ActionContent = () => {+ if (+ props.notification.notificationEventType === 'document_mention' ||+ props.notification.notificationEventType === 'channel_message_document'+ ) {+ return 'shared';+ }++ const metadata = tryToTypedNotification(+ props.notification+ )?.notificationMetadata;+ if (!metadata || !('messageContent' in metadata)) return '';++ return 'message';+ };++ const MessageContent = () => {+ if (+ props.notification.notificationEventType === 'document_mention' ||+ props.notification.notificationEventType === 'channel_message_document'+ ) {+ return '';+ }++ const metadata = tryToTypedNotification(+ props.notification+ )?.notificationMetadata;+ if (+ !metadata ||+ !('messageContent' in metadata) ||+ !metadata.messageContent+ )+ return '';++ return (+ <Show+ when={metadata.messageContent.trim()}+ fallback={<span class="italic text-ink-disabled">Attached items</span>}+ >+ {(content) => (+ <StaticMarkdown+ markdown={content()}+ theme={unifiedListMarkdownTheme}+ singleLine={true}+ />+ )}+ </Show>+ );+ };++ return (+ <CollapsibleListRow+ showThreadBorder+ onClick={+ props.onClick+ ? (e) => {+ props.onClick?.(+ {+ ...props.entity,+ notification: props.notification,+ },+ e+ );+ }+ : undefined+ }+ classList={{+ 'opacity-70': props.notification.viewedAt !== null,+ }}+ >+ <div class="flex size-5 shrink-0 items-center justify-center mr-1">+ <NotificationUserIcon id={props.notification.senderId!} />+ </div>+ <div class="flex gap-2 text-sm w-full min-w-0 overflow-hidden items-baseline">+ <div class="text-sm w-[20cqw] shrink-0 truncate min-w-0">+ {userName()}{' '}+ <span class="opacity-70 uppercase font-mono text-[0.625rem] mx-2">+ {ActionContent()}+ </span>+ </div>+ <MessageContent />+ </div>+ <div class="shrink-0 font-mono text-xs uppercase text-ink-extra-muted ml-2">+ {formattedDate()}+ </div>+ </CollapsibleListRow>+ );+}++function ContentHitRow(props: {+ data: ContentHitData;+ onClick: (e: EntityClickEvent, location?: SearchLocation) => void;+}) {+ return (+ <CollapsibleListRow+ blockNavigation+ onClick={(e) => props.onClick(e, props.data.location)}+ >+ <Show+ when={props.data.type === 'channel' && props.data}+ fallback={+ <div class="flex gap-2 items-center min-w-0 w-full">+ <div class="flex size-5 shrink-0 items-center justify-center opacity-0" />+ <GenericContentHit data={props.data} />+ </div>+ }+ >+ {(data) => <ChannelMessageContentHit data={data()} />}+ </Show>+ </CollapsibleListRow>+ );+}+// function ImportantBadge(props: { active?: boolean }) {// return (// <Show when={props.active}>@@ -128,6 +338,10 @@ function ChannelMessageContentHit(props: { data: ChannelContentHitData }) {// </Show>// );// }+//++type NotificationClickHandler<T extends EntityData = EntityData> =+ EntityClickHandler<T & { notification: Notification }>;interface EntityProps<T extends WithNotification<EntityData>>extends ParentProps {@@ -136,7 +350,7 @@ interface EntityProps<T extends WithNotification<EntityData>>timestamp?: number;onClick?: EntityClickHandler<T>;onClickRowAction?: (entity: T, type: 'done') => void;- onClickNotification?: EntityClickHandler<T & { notification: Notification }>;+ onClickNotification?: NotificationClickHandler<T>;onMouseOver?: () => void;onMouseLeave?: () => void;onFocusIn?: () => void;@@ -164,8 +378,6 @@ export function EntityWithEverything(const [entityDivRef, setEntityDivRef] = createSignal<HTMLDivElement | null>(null);- const [showRestOfNotifications, setShowRestOfNotifications] =- createSignal(false);const { keydownDataDuringTask } = trackKeydownDuringTask();const userEmail = useEmail();@@ -197,22 +409,9 @@ export function EntityWithEverything(const hasNotifications = () =>!!props.entity.notifications && props.entity.notifications().length > 0;- const threadGap = 6;- const ThreadBorder = () => (- <div- class="absolute left-[calc(0.5rem+1px)] w-[1px] border-l border-edge-muted -top-0.75"- style={{ height: `${threadGap}px` }}- />- );-const notDoneNotifications = () => {- let notifications = props.entity.notifications?.();+ const notifications = props.entity.notifications?.();if (!notifications) return [];-- if (!showRestOfNotifications()) {- notifications = notifications.slice(0, 3);- }-return notifications.filter(({ done }) => !done);};@@ -617,17 +816,17 @@ export function EntityWithEverything(</div>{/* Content Hits from Search */}<Show when={contentHitData().length > 0}>- <div class="relative row-2 grid gap-2 col-2 col-end-4 pb-2">- <For each={contentHitData()}>+ <div class="relative row-2 col-2 col-end-4 pb-2">+ <CollapsibleList items={contentHitData()} threadBorder>{(data) => (- <Show- when={data.type === 'channel' && data}- fallback={<GenericContentHit data={data} />}- >- {(data) => <ChannelMessageContentHit data={data()} />}- </Show>+ <ContentHitRow+ data={data}+ onClick={(e, location) => {+ props.onClick?.(props.entity, e, location);+ }}+ />)}- </For>+ </CollapsibleList></div></Show>{/* Notifications */}@@ -638,148 +837,16 @@ export function EntityWithEverything(contentHitData().length === 0}>- <div class="relative col-2 col-end-4 200 pb-2 gap-2">- <For each={notDoneNotifications()}>- {(notification) => {- const [userName] = useDisplayName(notification.senderId);-- const formattedDate = createFormattedDate(- notification.createdAt- );-- const ActionContent = () => {- if (- notification.notificationEventType === 'document_mention' ||- notification.notificationEventType ===- 'channel_message_document'- ) {- return 'shared';- }-- const metadata =- tryToTypedNotification(notification)?.notificationMetadata;- if (!metadata || !('messageContent' in metadata)) return '';-- return 'message';- };-- const MessageContent = () => {- if (- notification.notificationEventType === 'document_mention' ||- notification.notificationEventType ===- 'channel_message_document'- ) {- return '';- }-- const metadata =- tryToTypedNotification(notification)?.notificationMetadata;- if (- !metadata ||- !('messageContent' in metadata) ||- !metadata.messageContent- )- return '';-- // TODO (seamus): Notifs endpoint does not return any information- // about attachments. If we have an empty message, assume it's attachments.- return (- <Show- when={metadata.messageContent.trim()}- fallback={- <span class="italic text-ink-disabled">- Attached items- </span>- }- >- {(content) => (- <StaticMarkdown- markdown={content()}- theme={unifiedListMarkdownTheme}- singleLine={true}- />- )}- </Show>- );- };-- return (- <div- class="relative flex gap-1 items-center min-w-0 h-8"- classList={{- 'hover:bg-hover/20 hover:opacity-70':- !!props.onClickNotification,- 'opacity-70': notification.viewedAt !== null,- }}- onClick={- props.onClickNotification- ? [- props.onClickNotification,- {- ...props.entity,- notification,- },- ]- : undefined- }- >- <ThreadBorder />- <div class="flex size-5 shrink-0 items-center justify-center mr-1">- <NotificationUserIcon id={notification.senderId!} />- </div>- <div class="flex gap-2 text-sm w-full min-w-0 overflow-hidden items-baseline">- <div class="text-sm w-[20cqw] shrink-0 truncate min-w-0">- {userName()}{' '}- <span class="opacity-70 uppercase font-mono text-[0.625rem] mx-2">- {ActionContent()}- </span>- </div>- {/*<ImportantBadge- active={- notification.viewedAt === null &&- notification.isImportantV0- }- />*/}- <MessageContent />- </div>- <div class="shrink-0 font-mono text-xs uppercase text-ink-extra-muted ml-2">- {formattedDate()}- </div>- </div>- );- }}- </For>- <Show- when={- hasNotifications() &&- (props.entity.notifications?.().length ?? 0) > 3- }- >- <div class="relative h-5">- <ThreadBorder />- <button- class="block w-fit px-2 py-0.5 text-[10px] border border-edge uppercase font-mono hover:font-medium"- onClick={(e) => {- e.stopPropagation();- setShowRestOfNotifications((prev) => !prev);- }}- data-blocks-navigation- >- <Show- when={!showRestOfNotifications()}- fallback={<>Collapse</>}- >- + {(props.entity.notifications?.().length ?? 0) - 3} More- </Show>- </button>- </div>- </Show>- {/* <div class="relative h-4">- <ThreadBorder />- <button class="block p-1 py-0 text-[10px] h-4 border border-edge uppercase font-mono">- + 6 more- </button>- </div> */}+ <div class="relative col-2 col-end-4 pb-2">+ <CollapsibleList items={notDoneNotifications()} threadBorder>+ {(notification) => (+ <NotificationRow+ notification={notification}+ onClick={props.onClickNotification}+ entity={props.entity}+ />+ )}+ </CollapsibleList></div></Show></div>@@ -905,7 +972,7 @@ function EntityProject(props: {ownerId: data.owner,updatedAt: data.updatedAt,};- click(projectEntity, e, { ignorePreview: true });+ click(projectEntity, e, undefined, { ignorePreview: true });};projectIconRef.classList.add('hover:text-accent');diff --git a/js/app/packages/macro-entity/src/queries/search.ts b/js/app/packages/macro-entity/src/queries/search.tsindex 78bdf95542..5b765356a3 100644--- a/js/app/packages/macro-entity/src/queries/search.ts+++ b/js/app/packages/macro-entity/src/queries/search.ts@@ -1,4 +1,5 @@import { useChannelsContext } from '@core/component/ChannelsProvider';+import { blockNameToDefaultFile } from '@core/constant/allBlocks';import { ENABLE_SEARCH_SERVICE } from '@core/constant/featureFlags';import { idToDisplayName } from '@core/user';import { isErr } from '@core/util/maybeResult';@@ -172,7 +173,7 @@ const useMapSearchResponseItem = () => {return {type: 'document',id: result.document_id,- name: result.document_name,+ name: result.name || blockNameToDefaultFile(result.file_type),ownerId: result.owner_id,createdAt: result.metadata?.created_at,updatedAt: result.metadata?.updated_at,@@ -188,13 +189,20 @@ const useMapSearchResponseItem = () => {type: 'email',});- // Email thread subject match- // TODO: make sure this looks/feels right in the unified list+ const name = result.name ?? blockNameToDefaultFile('email');++ const senderName =+ emailResult?.sender ||+ result.email_message_search_results.at(1)?.sender ||+ idToDisplayName(result.user_id);++ // NOTE: this shouldn't happen unless it's a name only match that doesn't produce a name highlight for some reason+ // including this as a fallback for nowif (!emailResult) {return {type: 'email',id: result.thread_id,- name: result.name ?? '',+ name,ownerId: result.owner_id,createdAt: result.created_at,updatedAt: result.updated_at,@@ -202,7 +210,7 @@ const useMapSearchResponseItem = () => {isRead: false,isImportant: false,done: false,- senderName: idToDisplayName(result.user_id),+ senderName,search,};}@@ -210,7 +218,7 @@ const useMapSearchResponseItem = () => {return {type: 'email',id: result.thread_id,- name: result.name ?? '',+ name,ownerId: result.owner_id,createdAt: emailResult.sent_at ?? result.updated_at,updatedAt: emailResult.sent_at ?? result.updated_at,@@ -218,7 +226,7 @@ const useMapSearchResponseItem = () => {isRead: !emailResult.labels.includes('UNREAD'),isImportant: emailResult.labels.includes('IMPORTANT'),done: !emailResult.labels.includes('INBOX'),- senderName: emailResult.sender!,+ senderName,search,};}@@ -228,7 +236,7 @@ const useMapSearchResponseItem = () => {results: result.chat_search_results,});let name = result.name;- if (!name || name === 'New Chat') {+ if (!name || name === blockNameToDefaultFile('chat')) {const chat = history().find((item) => item.id === result.chat_id);if (chat) {name = chat.name;@@ -258,7 +266,7 @@ const useMapSearchResponseItem = () => {return {type: 'channel',id: result.channel_id,- name: channelWithLatest?.name ?? '',+ name: channelWithLatest?.name ?? blockNameToDefaultFile('channel'),ownerId: result.owner_id ?? '',createdAt: result.metadata?.created_at,updatedAt: result.metadata?.updated_at,