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.

chg(ui): restyle references (#3340)

teo58e3a8796cbd
diff --git a/js/app/packages/core/component/References.tsx b/js/app/packages/core/component/References.tsx
index 6d6fd3c6a3..ff894cdb6d 100644
--- a/js/app/packages/core/component/References.tsx
+++ b/js/app/packages/core/component/References.tsx
@@ -4,10 +4,11 @@ import { getChannelParams } from '@block-channel/utils/link';
import type { BlockAlias, BlockName } from '@core/block';
import { toast } from '@core/component/Toast/Toast';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { tryMacroId, useDisplayNameParts } from '@core/user';
import { compareDateDesc, type DateValue } from '@core/util/date';
import { isErr } from '@core/util/maybeResult';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
+import { formatRelativeTimestamp } from '@entity';
import {
isAccessiblePreviewItem,
type PreviewItem,
@@ -17,9 +18,10 @@ import { commsServiceClient } from '@service-comms/client';
import type { EntityReference } from '@service-comms/generated/models/entityReference';
import type { GenericReference } from '@service-comms/generated/models/genericReference';
import type { ItemType } from '@service-storage/client';
-import { createMemo, createResource, For, Show } from 'solid-js';
+import { createMemo, createResource, For, type JSX, Show } from 'solid-js';
import { InlineItemPreview } from './ItemPreview';
import { StaticMarkdown } from './LexicalMarkdown/component/core/StaticMarkdown';
+import { twoLineClampMarkdownTheme } from './LexicalMarkdown/theme';
import { UserIcon } from './UserIcon';
export type ReferenceProps = {
@@ -27,14 +29,19 @@ export type ReferenceProps = {
entityType?: ItemType;
};
-function isChannelReference(ref: EntityReference): ref is EntityReference & {
+type ChannelRef = EntityReference & {
channel_id: string;
message_id: string;
thread_id?: string;
sender_id: string;
attachment_created_at: string;
message_content?: string;
-} {
+};
+
+type GenericRef = EntityReference &
+ GenericReference & { reference_type: 'generic' };
+
+function isChannelReference(ref: EntityReference): ref is ChannelRef {
return (
'channel_id' in ref &&
'message_id' in ref &&
@@ -43,9 +50,7 @@ function isChannelReference(ref: EntityReference): ref is EntityReference & {
);
}
-function isGenericReference(
- ref: EntityReference
-): ref is EntityReference & GenericReference & { reference_type: 'generic' } {
+function isGenericReference(ref: EntityReference): ref is GenericRef {
return (
'reference_type' in ref &&
(ref as any).reference_type === 'generic' &&
@@ -63,6 +68,155 @@ const getReferenceCreatedAt = (ref: EntityReference) => {
}
};
+interface ReferenceRowProps {
+ source: JSX.Element;
+ senderAvatar?: JSX.Element;
+ senderName?: string;
+ timestamp: DateValue;
+ body?: JSX.Element;
+ onClick?: (e: KeyboardEvent | MouseEvent) => void;
+}
+
+function ReferenceRow(props: ReferenceRowProps) {
+ const navHandlers = useSplitNavigationHandler<HTMLDivElement>((e) => {
+ props.onClick?.(e);
+ });
+
+ return (
+ <div
+ role="button"
+ tabIndex={0}
+ class="group/ref-row flex flex-col px-3 py-2 hover:bg-ink-muted/6 min-w-0 overflow-hidden cursor-pointer"
+ onMouseDown={navHandlers.onMouseDown}
+ onClick={navHandlers.onClick}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ e.preventDefault();
+ props.onClick?.(e);
+ }
+ }}
+ >
+ <div class="flex items-center gap-2 min-w-0 text-xs leading-5">
+ <Show when={props.senderAvatar}>{props.senderAvatar}</Show>
+ <div class="min-w-0 flex items-center gap-1.5 overflow-hidden">
+ <Show when={props.senderName}>
+ <span class="ph-no-capture shrink-0 font-medium text-ink truncate max-w-[8rem]">
+ {props.senderName}
+ </span>
+ <span class="shrink-0 text-ink-muted/70">in</span>
+ </Show>
+ <div class="min-w-0 flex items-center overflow-hidden text-ink-muted">
+ {props.source}
+ </div>
+ </div>
+ <span class="shrink-0 ml-auto text-ink-extra-muted tabular-nums">
+ {formatRelativeTimestamp(props.timestamp)}
+ </span>
+ </div>
+
+ <Show when={props.body}>
+ <div class="ph-no-capture min-w-0 mt-1.5 ml-1 pl-2.5 border-l-2 border-ink-muted/12 text-xs text-ink-muted/65">
+ {props.body}
+ </div>
+ </Show>
+ </div>
+ );
+}
+
+function ReferencesCard(props: { children: JSX.Element }) {
+ return (
+ <div class="rounded-lg border border-ink-muted/8 bg-ink-muted/2.5 overflow-hidden">
+ <div class="divide-y divide-ink-muted/8">{props.children}</div>
+ </div>
+ );
+}
+
+// A message that is only mention tags adds no info — the row's source chip
+// already links to the same target.
+const MENTION_TAG_RE = /<m-\w+-mention>[\s\S]*?<\/m-\w+-mention>/g;
+function isOnlyMentions(markdown: string): boolean {
+ return markdown.replace(MENTION_TAG_RE, '').trim().length === 0;
+}
+
+function ChannelReferenceRow(props: {
+ reference: ChannelRef;
+ onOpen: (e: KeyboardEvent | MouseEvent) => void;
+}) {
+ const { firstName, fullName } = useDisplayNameParts(
+ tryMacroId(props.reference.sender_id)
+ );
+ const senderName = () => firstName() || fullName();
+ const hasContent = () => {
+ const content = props.reference.message_content?.trim();
+ if (!content) return false;
+ return !isOnlyMentions(content);
+ };
+
+ return (
+ <ReferenceRow
+ source={
+ <InlineItemPreview id={props.reference.channel_id} type="channel" />
+ }
+ senderAvatar={
+ <UserIcon
+ id={props.reference.sender_id}
+ size="sm"
+ isDeleted={false}
+ suppressClick
+ showTooltip={false}
+ />
+ }
+ senderName={senderName()}
+ timestamp={props.reference.attachment_created_at}
+ onClick={props.onOpen}
+ body={
+ hasContent() ? (
+ <StaticMarkdown
+ markdown={props.reference.message_content || ''}
+ theme={twoLineClampMarkdownTheme}
+ />
+ ) : undefined
+ }
+ />
+ );
+}
+
+function GenericReferenceRow(props: {
+ reference: GenericRef;
+ onOpen: (item: PreviewItem, e?: KeyboardEvent | MouseEvent) => void;
+}) {
+ const userId = props.reference.user_id!;
+ const { firstName, fullName } = useDisplayNameParts(tryMacroId(userId));
+ const senderName = () => firstName() || fullName();
+ const [item] = useItemPreview(() => ({
+ id: props.reference.source_entity_id,
+ type: props.reference.source_entity_type as ItemType,
+ }));
+
+ return (
+ <ReferenceRow
+ source={
+ <InlineItemPreview
+ id={props.reference.source_entity_id}
+ type={props.reference.source_entity_type as ItemType}
+ />
+ }
+ senderAvatar={
+ <UserIcon
+ id={userId}
+ size="sm"
+ isDeleted={false}
+ suppressClick
+ showTooltip={false}
+ />
+ }
+ senderName={senderName()}
+ timestamp={props.reference.created_at}
+ onClick={(e) => props.onOpen(item(), e)}
+ />
+ );
+}
+
export function References(props: ReferenceProps) {
const [references] = createResource(async () => {
const entityType = props.entityType ?? 'document';
@@ -150,126 +304,49 @@ export function References(props: ReferenceProps) {
);
});
- const formatTimestamp = (input: DateValue) => {
- const timestamp = input instanceof Date ? input : new Date(input);
- const datePart = timestamp
- .toLocaleDateString('en-US', {
- month: 'numeric',
- day: 'numeric',
- year: 'numeric',
- })
- .replaceAll('/', '-');
-
- const timePart = timestamp.toLocaleTimeString('en-US', {
- hour: 'numeric',
- minute: 'numeric',
- });
-
- return `${datePart} @ ${timePart}`;
- };
-
return (
- <div class="flex flex-col">
- <Show
- when={sortedReferences().length > 0}
- fallback={
- <div class="py-8 text-ink-muted text-sm text-center">
- No references found
- </div>
- }
- >
+ <Show
+ when={sortedReferences().length > 0}
+ fallback={
+ <div class="py-8 text-ink-muted text-sm text-center">
+ No references found
+ </div>
+ }
+ >
+ <ReferencesCard>
<For each={sortedReferences()}>
{(ref) => {
if (isChannelReference(ref)) {
- const [userName] = useDisplayName(tryMacroId(ref.sender_id));
- const hasMessageContent =
- ref.message_content && ref.message_content.trim().length > 0;
-
- const navHandlers = useSplitNavigationHandler((e) =>
- navigateToMessage({
- event: e,
- channelId: ref.channel_id,
- messageId: ref.message_id,
- threadId: ref.thread_id,
- })
- );
-
return (
- <button
- class="bg-surface hover:bg-hover p-2 pb-3 border-edge-muted border-b w-full text-left"
- {...navHandlers}
- >
- <div class="flex justify-start items-center gap-2 mb-4 font-mono text-ink-muted text-xs uppercase">
- <div class="bg-ink-extra-muted size-2" />
- <div>{hasMessageContent ? 'REFERENCE' : 'ATTACHMENT'}</div>
- <div class="grow" />
- <div>{formatTimestamp(ref.attachment_created_at)}</div>
- </div>
-
- <span class="inline-flex items-center gap-2 pl-4 text-sm">
- <UserIcon id={ref.sender_id} size="sm" isDeleted={false} />
- <span class="font-medium text-ink">{userName()}</span>
- <span class="text-ink-extra-muted">
- {hasMessageContent ? 'referenced in' : 'attached in'}
- </span>
- <InlineItemPreview id={ref.channel_id} type="channel" />
- </span>
- <Show when={hasMessageContent}>
- <div class="pl-4 text-ink-muted text-xs">
- <StaticMarkdown markdown={ref.message_content || ''} />
- </div>
- </Show>
- </button>
+ <ChannelReferenceRow
+ reference={ref}
+ onOpen={(e) =>
+ navigateToMessage({
+ event: e,
+ channelId: ref.channel_id,
+ messageId: ref.message_id,
+ threadId: ref.thread_id,
+ })
+ }
+ />
);
}
-
if (isGenericReference(ref)) {
- const userId = ref.user_id!;
- const [userName] = useDisplayName(tryMacroId(userId));
- const [item] = useItemPreview(() => ({
- id: ref.source_entity_id,
- type: ref.source_entity_type as ItemType,
- }));
-
- const navHandlers = useSplitNavigationHandler((e) =>
- navigateToGenericReference(item(), e)
- );
-
return (
- <button
- class="bg-surface hover:bg-hover p-2 pb-3 border-edge-muted border-b w-full text-left"
- {...navHandlers}
- >
- <div class="flex justify-start items-center gap-2 mb-4 font-mono text-ink-muted text-xs uppercase">
- <div class="bg-ink-extra-muted size-2" />
- <div>MENTION</div>
- <div class="grow" />
- <div>{formatTimestamp(ref.created_at)}</div>
- </div>
-
- <span class="inline-flex items-center gap-1 text-sm pl-4">
- <UserIcon id={userId} size="sm" isDeleted={false} />
- <span class="font-medium text-ink">{userName()}</span>
- <span class="text-ink-extra-muted">mentioned in</span>
- <InlineItemPreview
- id={ref.source_entity_id}
- type={ref.source_entity_type as ItemType}
- />
- </span>
- </button>
+ <GenericReferenceRow
+ reference={ref}
+ onOpen={navigateToGenericReference}
+ />
);
}
-
return (
- <div class="flex justify-between items-center bg-failure-bg px-4 py-2 border-edge border-b w-full">
- <div class="text-failure text-xs">
- Unknown reference type: {JSON.stringify(ref, null, 2)}
- </div>
+ <div class="px-3 py-2 text-xs text-failure">
+ Unknown reference type
</div>
);
}}
</For>
- </Show>
- </div>
+ </ReferencesCard>
+ </Show>
);
}