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: item rename preview + add featuer flag auto tab attachments (#1395)

gbirman2b52658014ce
diff --git a/js/app/packages/core/component/AI/component/input/Attachment.tsx b/js/app/packages/core/component/AI/component/input/Attachment.tsx
index f0a458af9d..26ca730d20 100644
--- a/js/app/packages/core/component/AI/component/input/Attachment.tsx
+++ b/js/app/packages/core/component/AI/component/input/Attachment.tsx
@@ -6,10 +6,12 @@ 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 { toast } from '@core/component/Toast/Toast';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { openInNewSplitForMention } from '@core/util/openInNewSplit';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
+import type { ItemEntity } from '@queries/preview';
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';
@@ -98,18 +100,51 @@ function ChatAttachment(props: {
onRemove: () => void;
}) {
const { insertSplit, replaceOrInsertSplit } = useSplitLayout();
+
+ const itemEntity = createMemo((): ItemEntity | null => {
+ const attachment = props.attachment;
+ if (!attachment.metadata) return null;
+
+ if (
+ attachment.metadata.type === 'email' ||
+ attachment.metadata.type === 'image'
+ ) {
+ return null;
+ }
+
+ if (attachment.metadata.type === 'channel') {
+ return {
+ id: attachment.attachmentId,
+ type: 'channel',
+ };
+ }
+
+ return {
+ id: attachment.attachmentId,
+ type: attachment.metadata.type,
+ };
+ });
+
+ const previewData = createMemo(() => {
+ const entity = itemEntity();
+ if (!entity) return null;
+ return useItemPreviewData(() => entity);
+ });
+
const name = createMemo(() => {
const attachment = props.attachment;
if (!attachment.metadata) return '';
- return attachment.metadata.type === 'document'
- ? attachment.metadata.document_name
+
+ const preview = previewData();
+ if (preview) {
+ return preview.name();
+ }
+
+ return attachment.metadata.type === 'email'
+ ? attachment.metadata.email_subject
: attachment.metadata.type === 'image'
? attachment.metadata.image_name
- : attachment.metadata.type === 'channel'
- ? attachment.metadata.channel_name
- : attachment.metadata.type === 'project'
- ? attachment.metadata.project_name
- : attachment.metadata.email_subject;
+ : '';
});
const block = createMemo(() => {
diff --git a/js/app/packages/core/component/AI/component/input/useChatInput.tsx b/js/app/packages/core/component/AI/component/input/useChatInput.tsx
index 9dc3e92d6a..5dd4cda501 100644
--- a/js/app/packages/core/component/AI/component/input/useChatInput.tsx
+++ b/js/app/packages/core/component/AI/component/input/useChatInput.tsx
@@ -18,6 +18,7 @@ import { useUploadAttachment } from '@core/component/AI/util/uploadToChat';
import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';
import { Hotkey, modifierMap } from '@core/component/Hotkey';
import { Tooltip } from '@core/component/Tooltip';
+import { ENABLE_AI_AUTO_TAB_ATTACHMENTS } from '@core/constant/featureFlags';
import { pressedKeys } from '@core/hotkey/state';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import ArrowUp from '@icon/bold/arrow-up-bold.svg';
@@ -98,19 +99,21 @@ export function useChatInput(
});
const tabAttachments = useTabAttachments();
- createEffect(
- on(tabAttachments, (tabs, p) => {
- for (const prev of p ?? []) {
- // remove stuff from closed tabs
- if (!tabs.find((t) => t.attachmentId === prev.attachmentId)) {
- attachments.removeAttachment(prev.attachmentId);
+ if (ENABLE_AI_AUTO_TAB_ATTACHMENTS) {
+ createEffect(
+ on(tabAttachments, (tabs, p) => {
+ for (const prev of p ?? []) {
+ // remove stuff from closed tabs
+ if (!tabs.find((t) => t.attachmentId === prev.attachmentId)) {
+ attachments.removeAttachment(prev.attachmentId);
+ }
}
- }
- for (const tab of tabs) {
- attachments.addAttachment(tab);
- }
- })
- );
+ for (const tab of tabs) {
+ attachments.addAttachment(tab);
+ }
+ })
+ );
+ }
const ChatInputComponent = (innerProps: ChatInputProps) => (
<ChatInput
diff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsx
index 8f639e0a27..e42364baab 100644
--- a/js/app/packages/core/component/DocumentPreview.tsx
+++ b/js/app/packages/core/component/DocumentPreview.tsx
@@ -275,6 +275,7 @@ export function PopupPreview(props: {
};
documentInfo: {
id: string;
+ name?: string;
type: BlockName | BlockAlias;
params: Record<string, string>;
isOpenable?: boolean;
@@ -503,7 +504,7 @@ export function PopupPreview(props: {
return (
<>
<div class="text-sm font-semibold select-text">
- {accessibleItem.name}
+ {props.documentInfo.name || accessibleItem.name}
{accessories && (
<div class="relative text-[0.8em] text-current/60 rounded-md mt-1.5 select-none">
{`${accessories.note} `}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
index cece90610a..164804fb8d 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
@@ -191,6 +191,7 @@ function SnapshotInner(props: SnapshotDecoratorProps) {
delete={editor?.isEditable() ? deleteSnapshot : undefined}
documentInfo={{
id: props.documentId,
+ name: props.documentName,
type: verifyBlockName(props.blockName),
params: {},
isOpenable: currentBlockId !== props.documentId,
diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.ts
index b1923784fe..c3a9a5b50d 100644
--- a/js/app/packages/core/constant/featureFlags.ts
+++ b/js/app/packages/core/constant/featureFlags.ts
@@ -125,3 +125,5 @@ export const ENABLE_UNIFIED_LIST_AI_INPUT = true;
export const ENABLE_SNAPSHOT_NODE = true;
export const ENABLE_EMAIL_SCHEDULED_SEND = false;
+
+export const ENABLE_AI_AUTO_TAB_ATTACHMENTS = true;
diff --git a/js/app/packages/macro-entity/src/queries/rename.ts b/js/app/packages/macro-entity/src/queries/rename.ts
index a0825fbdea..7f754e4848 100644
--- a/js/app/packages/macro-entity/src/queries/rename.ts
+++ b/js/app/packages/macro-entity/src/queries/rename.ts
@@ -43,6 +43,8 @@ type EntityRenameData = {
newName: string;
};
+type EntityRenameOptimisticInfo = Omit<EntityRenameData, 'oldName'>;
+
type EntityIdToNameMap = Map<string, string>;
type RenameDssEntityMutationVariables = EntityRenameOperation;
@@ -107,7 +109,7 @@ function updateEntityNamesInDssQueryData(
case 'channel': {
const itemId = item.data.channel.id;
const newName = updates.get(itemId);
- if (!newName) return item;
+ if (newName === undefined) return item;
item.data.channel.name = newName;
break;
}
@@ -116,7 +118,7 @@ function updateEntityNamesInDssQueryData(
case 'project': {
const itemId = item.data.id;
const newName = updates.get(itemId);
- if (!newName) return item;
+ if (newName === undefined) return item;
item.data.name = newName;
break;
}
@@ -132,7 +134,7 @@ function updateEntityNamesInDssQueryData(
};
}
-const renameDssSetData = (entities: EntityRenameData[]) => {
+const renameDssSetData = (entities: EntityRenameOptimisticInfo[]) => {
const updates: EntityIdToNameMap = new Map(
entities.map((e) => [e.id, e.newName])
);
@@ -149,7 +151,7 @@ const renameDssSetData = (entities: EntityRenameData[]) => {
};
const renameChannelSetData = (
- entities: EntityRenameData[]
+ entities: EntityRenameOptimisticInfo[]
): ChannelRenameContexts => {
const contexts: ChannelRenameContexts = new Map();
@@ -168,7 +170,7 @@ const renameChannelSetData = (
return contexts;
};
-const renamePreviewSetData = (entities: EntityRenameData[]) => {
+const renamePreviewSetData = (entities: EntityRenameOptimisticInfo[]) => {
entities.forEach(({ id, newName, itemType }) => {
setPreviewName({
itemId: id,
@@ -178,14 +180,14 @@ const renamePreviewSetData = (entities: EntityRenameData[]) => {
});
};
-const renameHistorySetData = (entities: EntityRenameData[]) => {
+const renameHistorySetData = (entities: EntityRenameOptimisticInfo[]) => {
entities.forEach(({ id, newName }) => {
setHistoryItemName(id, newName);
});
};
function performOptimisticRenameUpdates(
- entities: EntityRenameData[]
+ entities: EntityRenameOptimisticInfo[]
): RenameRollbackContext {
renamePreviewSetData(entities);
renameHistorySetData(entities);
@@ -358,12 +360,9 @@ export function useWaitChatRename(chatId: string, noDispose?: boolean) {
const dispose = createCognitionWebsocketEffect('chat_renamed', (data) => {
if (data.chat_id !== chatId) return;
- setHistoryItemName(chatId, data.name);
- setPreviewName({
- itemId: chatId,
- name: data.name,
- itemType: 'chat',
- });
+ performOptimisticRenameUpdates([
+ { id: chatId, newName: data.name, itemType: 'chat' },
+ ]);
if (!noDispose) {
dispose();
}