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: task type chat attachment + use item preview directly in chat attachment (#1443)
gbirman7d558dd361e9
diff --git a/js/app/packages/core/component/AI/component/input/Attachment.tsx b/js/app/packages/core/component/AI/component/input/Attachment.tsxindex 728ec85512..f2b065acda 100644--- a/js/app/packages/core/component/AI/component/input/Attachment.tsx+++ b/js/app/packages/core/component/AI/component/input/Attachment.tsx@@ -1,4 +1,3 @@-import { useSplitLayout } from '@app/component/split-layout/layout';import type { Attachment, AttachmentPreview } from '@core/component/AI/types';import {isDssImage,@@ -6,25 +5,13 @@ import {} from '@core/component/AI/util/attachment';import { EntityIcon } from '@core/component/EntityIcon';import { ImagePreview } from '@core/component/ImagePreview';-import { useItemPreviewData } from '@core/component/ItemPreview';+import { ItemPreview } from '@core/component/ItemPreview';import { toast } from '@core/component/Toast/Toast';-import { itemToBlockName } from '@core/constant/allBlocks';-import { openInNewSplitForMention } from '@core/util/openInNewSplit';-import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';import XIcon from '@icon/regular/x.svg';import Spinner from '@phosphor-icons/core/bold/spinner-gap-bold.svg?component-solid';-import Envelope from '@phosphor-icons/core/regular/envelope.svg';import Close from '@phosphor-icons/core/regular/x.svg?component-solid';import type { Accessor } from 'solid-js';-import {- createMemo,- createSignal,- For,- Match,- Show,- Suspense,- Switch,-} from 'solid-js';+import { createSignal, For, Match, Show, Suspense, Switch } from 'solid-js';type AttachmentListProps = {removeAttachment: (id: string) => void;@@ -108,51 +95,6 @@ function ChatAttachment(props: {attachment: Attachment;onRemove: () => void;}) {- const { insertSplit, replaceOrInsertSplit } = useSplitLayout();-- const name = createMemo(() => {- const attachment = props.attachment;- if (!attachment.metadata) return '';-- if (attachment.metadata.type === 'email') {- return attachment.metadata.email_subject;- } else if (attachment.metadata.type === 'image') {- return attachment.metadata.image_name;- }-- const entity = {- id: attachment.attachmentId,- type: attachment.metadata.type,- };- const { name } = useItemPreviewData(() => entity);- return name();- });-- const block = createMemo(() => {- const attachment = props.attachment;- if (!attachment.metadata) return;- const type = attachment.metadata.type;- if (type === 'image') return;- return itemToBlockName({- type,- fileType:- type === 'document' ? attachment.metadata.document_type : undefined,- });- });-- const onClick = (e: MouseEvent) => {- const attachment = props.attachment;- if (isImageAttachment(attachment)) return;- const block_ = block();- if (!block_) return;- const inNewSplit = openInNewSplitForMention(e.shiftKey, true);- const open = inNewSplit ? insertSplit : replaceOrInsertSplit;- open({- id: attachment.attachmentId,- type: block_,- })?.activate?.();- };- const navHandlers = useSplitNavigationHandler<HTMLDivElement>(onClick);return (<Switch><Match when={isImageAttachment(props.attachment)}>@@ -161,69 +103,38 @@ function ChatAttachment(props: {onRemove={props.onRemove}/></Match>- <Match when={true}>- <div- class={`- flex items-center p-1 space-x-2- hover:bg-hover hover-transition-bg cursor-default- text-sm- `}- {...navHandlers}- >- <Switch>- <Match- when={- props.attachment.metadata?.type === 'channel' &&- props.attachment.metadata- }- >- {(a) => (- <div class="flex gap-1 items-center">- <EntityIcon targetType={a().channel_type || 'channel'} />- <div> {name()}</div>- </div>- )}- </Match>- <Match- when={- props.attachment.metadata?.type === 'document' &&- props.attachment.metadata- }- >- {(a) => (- <div class="flex gap-1 items-center">- <EntityIcon targetType={a().document_type} />- <div>{name()}</div>- </div>- )}- </Match>- <Match when={props.attachment.attachmentType === 'email'}>- <div class="flex gap-1 items-center">- <Envelope class="w-4" />- <div> {name()}</div>- </div>- </Match>- <Match when={props.attachment.attachmentType === 'project'}>- <div class="flex gap-1 items-center">- <EntityIcon targetType="project" />- <div> {name()}</div>- </div>- </Match>- </Switch>- <div- class="hover:bg-hover hover-transition-bg rounded-md p-1 items-center flex"- onClick={(e) => {- e.stopPropagation();- props.onRemove?.();- }}- >- <Close- width={12}- height={12}- class="text-ink-muted group-hover:text-failure"+ <Match+ when={+ props.attachment.metadata?.type !== 'image' &&+ props.attachment.metadata+ }+ >+ {(metadata) => (+ <div class="flex items-center p-1 space-x-2 hover:bg-hover hover-transition-bg cursor-default text-sm">+ <ItemPreview+ id={props.attachment.attachmentId}+ type={metadata().type}+ class="flex items-center gap-1 text-sm"+ iconClass=""+ textClass="truncate"+ iconSize="xs"+ disableHoverCard/>+ <div+ class="hover:bg-hover hover-transition-bg rounded-md p-1 items-center flex"+ onClick={(e) => {+ e.stopPropagation();+ props.onRemove?.();+ }}+ >+ <Close+ width={12}+ height={12}+ class="text-ink-muted group-hover:text-failure"+ />+ </div></div>- </div>+ )}</Match></Switch>);diff --git a/js/app/packages/core/component/ItemPreview.tsx b/js/app/packages/core/component/ItemPreview.tsxindex 14bc3d2be9..858d579b2e 100644--- a/js/app/packages/core/component/ItemPreview.tsx+++ b/js/app/packages/core/component/ItemPreview.tsx@@ -27,7 +27,11 @@ import { PopupPreview } from './DocumentPreview';import { HoverCard } from './HoverCard';import { useSplitLayout } from '../../app/component/split-layout/layout';import { DeprecatedTextButton } from './DeprecatedTextButton';-import { EntityIcon, getPreviewItemIconType } from './EntityIcon';+import {+ EntityIcon,+ type EntityIconProps,+ getPreviewItemIconType,+} from './EntityIcon';export function useItemPreviewData(entity: Accessor<ItemEntity>) {const [item] = useItemPreview(entity);@@ -170,7 +174,22 @@ function InlineLoading() {);}-export function ItemPreview(props: ItemEntity) {+export type ItemPreviewProps = ItemEntity & {+ /** Custom class for the button wrapper */+ class?: string;+ /** Custom class for the icon container */+ iconClass?: string;+ /** Custom class for the text/name */+ textClass?: string;+ /** Disable hover card popup */+ disableHoverCard?: boolean;+ /** Max length for text truncation */+ maxLength?: number;+ /** Icon size (defaults to 'fill') */+ iconSize?: EntityIconProps['size'];+};++export function ItemPreview(props: ItemPreviewProps) {return (<Suspense><ItemPreviewInner {...props} />@@ -178,10 +197,20 @@ export function ItemPreview(props: ItemEntity) {);}-function ItemPreviewInner(props: ItemEntity) {+function ItemPreviewInner(props: ItemPreviewProps) {const { item, name, onPreviewClick, targetType, ItemEntityIcon } =useItemPreviewData(() => props);+ const maxLength = () => props.maxLength ?? 80;+ const iconSize = () => props.iconSize ?? 'fill';+ const buttonClass = () =>+ props.class ??+ 'text-ink-base text-sm ring-1 ring-edge-muted rounded-xs hover:bg-panel-hover flex flex-row h-6 px-2 justify-center items-center';+ const iconClass = () =>+ props.iconClass ?? 'flex justify-start items-center h-3.5 mr-2';+ const textClass = () =>+ props.textClass ?? 'flex-1 text-left leading-5 min-w-0 truncate';+return (<Switch><Match when={item().loading}>@@ -197,6 +226,7 @@ function ItemPreviewInner(props: ItemEntity) {const itemType = accessibleItem().type;return fileTypeToBlockName(type ?? itemType);};+const navHandlers =useSplitNavigationHandler<HTMLButtonElement>((e) => {const item = accessibleItem();@@ -208,19 +238,19 @@ function ItemPreviewInner(props: ItemEntity) {e.shiftKey);});+return (<HoverCard- disabled={isTouchDevice() || !blockName()}+ disabled={+ props.disableHoverCard || isTouchDevice() || !blockName()+ }trigger={- <button- class="text-ink-base text-sm ring-1 ring-edge-muted rounded-xs hover:bg-panel-hover flex flex-row h-6 px-2 justify-center items-center"- {...navHandlers}- >- <div class="flex justify-start items-center h-3.5 mr-2">- <ItemEntityIcon size="fill" />+ <button class={buttonClass()} {...navHandlers}>+ <div class={iconClass()}>+ <ItemEntityIcon size={iconSize()} /></div>- <div class="flex-1 text-left leading-5 min-w-0 truncate">- {truncateString(name(), 80)}+ <div class={textClass()}>+ {truncateString(name(), maxLength())}</div></button>}