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: front end optimize search response handling (#1723)
gbirman84471b6ac84f
diff --git a/js/app/packages/core/util/searchHighlight.ts b/js/app/packages/core/util/searchHighlight.tsxsimilarity index 81%rename from js/app/packages/core/util/searchHighlight.tsrename to js/app/packages/core/util/searchHighlight.tsxindex c6b534f264..4a1f06dd9d 100644--- a/js/app/packages/core/util/searchHighlight.ts+++ b/js/app/packages/core/util/searchHighlight.tsx@@ -2,9 +2,12 @@* Utilities for extracting information from search highlight content* that contains <macro_em> tags marking matched terms.*/+import { Index } from 'solid-js';const INVISIBLE_CHARS_RE =/(?:[\u200B-\u200F\u2028-\u202F\u2060-\u206F\uFEFF\u00AD\u2800-\u28FF]|\u034F)+/g;+const MACRO_EM_SPLIT_RE = /(<macro_em>.*?<\/macro_em>)/gs;+const MACRO_EM_UNWRAP_RE = /^<macro_em>(.*)<\/macro_em>$/s;/** Collapses newlines, extra whitespace, and invisible Unicode characters into a clean single line. */function stripInvisibleChars(text: string): string {@@ -147,3 +150,40 @@ export function windowSearchMatch(text: string, chars: number = 200): string {return line;}++/**+ * Parses text containing `<macro_em>` tags into an array of segments.+ * Each segment is either plain text or a highlighted match.+ */+export function parseSearchHighlightSegments(+ text: string+): Array<{ text: string; highlight: boolean }> {+ const parts = text.split(MACRO_EM_SPLIT_RE);+ const segments: Array<{ text: string; highlight: boolean }> = [];+ for (const part of parts) {+ if (!part) continue;+ const match = MACRO_EM_UNWRAP_RE.exec(part);+ if (match) {+ segments.push({ text: match[1], highlight: true });+ } else {+ segments.push({ text: part, highlight: false });+ }+ }+ return segments;+}++export function HighlightRender(props: { text: string }) {+ return (+ <span>+ <Index each={parseSearchHighlightSegments(props.text)}>+ {(segment) =>+ segment().highlight ? (+ <span class="md-mark search-match">{segment().text}</span>+ ) : (+ segment().text+ )+ }+ </Index>+ </span>+ );+}diff --git a/js/app/packages/entity/src/composed/ListEntity.tsx b/js/app/packages/entity/src/composed/ListEntity.tsxindex cf75578ba5..75778352cb 100644--- a/js/app/packages/entity/src/composed/ListEntity.tsx+++ b/js/app/packages/entity/src/composed/ListEntity.tsx@@ -1,5 +1,9 @@import type { DateValue } from '@core/util/date';-import { visibleLength, windowSearchMatch } from '@core/util/searchHighlight';+import {+ visibleLength,+ windowSearchMatch,+ HighlightRender,+} from '@core/util/searchHighlight';import { Entity } from '../entity';import type { StreamEvent } from '@service-connection/generated/schemas';import {@@ -12,7 +16,15 @@ import {type EntityData,isTaskEntity,} from '../types/entity';-import { Match, Show, Switch, type Ref } from 'solid-js';+import {+ createSignal,+ Match,+ onCleanup,+ onMount,+ Show,+ Switch,+ type Ref,+} from 'solid-js';import {getStreamState,subscribeToStreamState,@@ -41,6 +53,8 @@ import {import { useSplitPanel } from '@app/component/split-layout/layoutUtils';import { mergeRefs } from '@solid-primitives/refs';+const WIDE_BREAKPOINT = 512; // @lg container query = 32rem+const hasSearchContentHits = (entity: EntityData) =>isSearchEntity(entity) && !!entity.search.contentHitData?.length;@@ -128,13 +142,7 @@ function EmailSnippet(props: {when={props.showContentHits && getBestContentHitContent(props.entity)}fallback={props.entity.snippet}>- {(content) => (- <StaticMarkdown- markdown={windowSearchMatch(content())}- theme={unifiedListMarkdownTheme}- singleLine- />- )}+ {(content) => <HighlightRender text={windowSearchMatch(content())} />}</Show>);}@@ -167,7 +175,7 @@ function ChannelMessage(props: {function NarrowLayout(props: LayoutProps) {return (<Entity.Layout- class="w-full gap-x-2 items-center text-sm pl-0 px-2 grid @lg/entity:hidden"+ class="w-full gap-x-2 items-center text-sm pl-0 px-2 grid"style={{'grid-template-columns': 'auto 1fr 8ch','grid-template-rows': '2.5rem auto',@@ -269,8 +277,7 @@ function WideLayout(props: LayoutProps) {class={cn('w-full min-h-[inherit] items-center text-sm px-2','gap-2 grid grid-cols-[1rem_1fr_auto_8ch] grid-rows-[1fr]',- '[--title-width:clamp(6rem,20%,16rem)]',- 'hidden @lg/entity:grid'+ '[--title-width:clamp(6rem,20%,16rem)]')}style={{'grid-template-areas': '"indicator content meta timestamp"',@@ -407,6 +414,17 @@ export function ListEntity(props: ListEntityProps) {splitId: useSplitPanel()?.handle?.id,});+ let rootEl!: HTMLElement;+ const [isWide, setIsWide] = createSignal(true);++ onMount(() => {+ const observer = new ResizeObserver((entries) => {+ setIsWide((entries[0]?.contentRect.width ?? 0) >= WIDE_BREAKPOINT);+ });+ observer.observe(rootEl);+ onCleanup(() => observer.disconnect());+ });+return (<Entity.Rootentity={props.entity}@@ -417,7 +435,9 @@ export function ListEntity(props: ListEntityProps) {}props.onClick?.(e);}}- ref={mergeRefs(props.ref, draggable)}+ ref={mergeRefs(props.ref, draggable, (el) => {+ rootEl = el;+ })}class={cn('@container/entity w-full min-h-10 relative group/narrow', {'bg-accent/5': props.checked,'hover:bg-hover/30':@@ -434,8 +454,9 @@ export function ListEntity(props: ListEntityProps) {})}/>- <NarrowLayout {...layoutProps()} />- <WideLayout {...layoutProps()} />+ <Show when={isWide()} fallback={<NarrowLayout {...layoutProps()} />}>+ <WideLayout {...layoutProps()} />+ </Show><Show when={hasNotifications()}><div class="flex gap-2 w-full h-full items-center text-sm px-2 pb-1 -mt-2 min-w-0 overflow-hidden">