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(md): fix reactive rename on empty md title (#1344)

Seamusfdcbf7d881a0
diff --git a/js/app/packages/block-md/component/TitleEditor.tsx b/js/app/packages/block-md/component/TitleEditor.tsx
index f2926330a7..6cd38a40ab 100644
--- a/js/app/packages/block-md/component/TitleEditor.tsx
+++ b/js/app/packages/block-md/component/TitleEditor.tsx
@@ -145,7 +145,8 @@ export function TitleEditor(props: { autoFocusOnMount?: boolean } = {}) {
const debouncedRename = debounce(() => {
const name = state();
- if (canEdit()) renameMarkdownDocument(name);
+ const prevName = untrack(mdDocumentName);
+ if (canEdit()) renameMarkdownDocument(name, prevName);
}, 500);
const [state, setState] = createSignal('');
diff --git a/js/app/packages/block-md/signal/save.ts b/js/app/packages/block-md/signal/save.ts
index fd6060b1a8..f3ab17a180 100644
--- a/js/app/packages/block-md/signal/save.ts
+++ b/js/app/packages/block-md/signal/save.ts
@@ -4,7 +4,6 @@ import {
editorStateAsMarkdown,
getSaveState,
} from '@core/component/LexicalMarkdown/utils';
-import { renameItem } from '@core/component/FileList/itemOperations';
import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';
import { isErr } from '@core/util/maybeResult';
import { utf8Encode } from '@core/util/string';
@@ -13,6 +12,7 @@ import { refetchHistory } from '@queries/history/history';
import { createCallback } from '@solid-primitives/rootless';
import { createMemo } from 'solid-js';
import { mdStore } from './markdownBlockData';
+import { createRenameDssEntityMutation } from '../../macro-entity/src/queries/rename';
export const useBlockSave = () => {
const pendingComment = createMemo(() => activeCommentThreadSignal() === -1);
@@ -45,14 +45,18 @@ export function useSaveMarkdownDocument() {
export function useRenameMarkdownDocument() {
const documentId = useBlockId();
-
- return createCallback(async (documentName: string) => {
- await renameItem({
- itemType: 'document',
- id: documentId,
- newName: documentName,
+ const renameMutation = createRenameDssEntityMutation();
+
+ return async (newName: string, oldName: string) => {
+ await renameMutation.mutateAsync({
+ entity: {
+ type: 'document',
+ name: oldName,
+ id: documentId,
+ },
+ newName,
});
- });
+ };
}
export function useDownloadDocumentAsMarkdownText() {
diff --git a/js/app/packages/macro-entity/src/queries/rename.ts b/js/app/packages/macro-entity/src/queries/rename.ts
index a0590468ba..d93fba2501 100644
--- a/js/app/packages/macro-entity/src/queries/rename.ts
+++ b/js/app/packages/macro-entity/src/queries/rename.ts
@@ -15,10 +15,11 @@ import type { SoupPage } from '@service-storage/generated/schemas';
import { setPreviewData } from '@queries/preview';
import { setHistoryItemData } from '@queries/history/history';
-type EntityWithName = EntityData & { name: string };
+type RenamableEntity = Pick<EntityData, 'id' | 'type' | 'name'> &
+ Partial<EntityData>;
type EntityRenameOperation = {
- entity: EntityWithName;
+ entity: RenamableEntity;
newName: string;
};
diff --git a/js/app/packages/queries/history/history.ts b/js/app/packages/queries/history/history.ts
index 8f25757ee7..3a8fd0b4f1 100644
--- a/js/app/packages/queries/history/history.ts
+++ b/js/app/packages/queries/history/history.ts
@@ -236,13 +236,27 @@ export async function removeHistoryItem(
/**
* Hook to get the updated name of a DSS item from history.
+ * Returns the raw name without transform (preserves empty strings).
*/
export function useUpdatedDssItemName(itemId: string | Accessor<string>) {
- const historyQuery = useHistoryQuery();
+ const instructionsMdIdQuery = useInstructionsMdIdQuery();
+
+ const rawHistoryQuery = useQuery(() => {
+ const instructionsId = instructionsMdIdQuery.isSuccess
+ ? instructionsMdIdQuery.data
+ : null;
+
+ return {
+ ...historyQueryOptions(),
+ select: (data: HistoryQueryResponse): HistoryItem[] => {
+ return transformHistoryResponse(data, instructionsId, true);
+ },
+ };
+ });
return () => {
- if (historyQuery.isLoading) return undefined;
- const history = historyQuery.data;
+ if (rawHistoryQuery.isLoading) return undefined;
+ const history = rawHistoryQuery.data;
if (!history) return undefined;
const itemIdValue = typeof itemId === 'function' ? itemId() : itemId;
diff --git a/js/app/packages/queries/history/transforms.ts b/js/app/packages/queries/history/transforms.ts
index 339cb4b69c..8e63ec6402 100644
--- a/js/app/packages/queries/history/transforms.ts
+++ b/js/app/packages/queries/history/transforms.ts
@@ -12,10 +12,13 @@ export type HistoryQueryResponse = {
data: Item[];
};
-export function transformHistoryItem(item: Item): HistoryItem {
+export function transformHistoryItem(
+ item: Item,
+ rawName?: boolean
+): HistoryItem {
return {
...item,
- name: itemToSafeName(item),
+ name: rawName ? item.name : itemToSafeName(item),
viewedAt: (item as ItemWithViewedAt).viewedAt,
};
}
@@ -30,10 +33,11 @@ export function filterInstructionsMd(
export function transformHistoryResponse(
data: HistoryQueryResponse,
- instructionsId: string | null | undefined
+ instructionsId: string | null | undefined,
+ rawName?: boolean
): HistoryItem[] {
- return filterInstructionsMd(data.data, instructionsId).map(
- transformHistoryItem
+ return filterInstructionsMd(data.data, instructionsId).map((item) =>
+ transformHistoryItem(item, rawName)
);
}