mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-01 17:50:50 +08:00
fix(editor): transcript note will create useless docs (#14976)
fix #13520 #### PR Dependency Tree * **PR #14976** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added comprehensive test coverage for markdown insertion functionality to verify that existing document metadata remains unchanged when importing markdown content into workspace documents. * **Chores** * Optimized internal markdown-to-snapshot conversion process to use a more direct and efficient conversion approach. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/toeverything/AFFiNE/pull/14976) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { getStoreManager } from '@affine/core/blocksuite/manager/store';
|
||||
import { Text } from '@blocksuite/affine/store';
|
||||
import { TestWorkspace } from '@blocksuite/affine/store/test';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { insertFromMarkdown } from './markdown-utils';
|
||||
|
||||
const extensions = getStoreManager().config.init().value.get('store');
|
||||
|
||||
describe('markdown-utils', () => {
|
||||
test('insertFromMarkdown does not create docs in the target workspace', async () => {
|
||||
const collection = new TestWorkspace({ id: 'test' });
|
||||
collection.meta.initialize();
|
||||
|
||||
const store = collection.createDoc('page0').getStore({ extensions });
|
||||
store.load();
|
||||
const rootId = store.addBlock('affine:page', {
|
||||
title: new Text(''),
|
||||
});
|
||||
const noteId = store.addBlock('affine:note', {}, rootId);
|
||||
|
||||
await insertFromMarkdown(
|
||||
undefined,
|
||||
['- Summary item', '## Decisions', '- Ship it'].join('\n'),
|
||||
store,
|
||||
noteId,
|
||||
0
|
||||
);
|
||||
|
||||
expect(collection.meta.docMetas.map(meta => meta.id)).toEqual(['page0']);
|
||||
});
|
||||
});
|
||||
@@ -153,31 +153,10 @@ export const markdownToSnapshot = async (
|
||||
pageId: store.id,
|
||||
};
|
||||
|
||||
const page = await markdownAdapter.toDoc(payload);
|
||||
|
||||
if (page) {
|
||||
const pageSnapshot = transformer.docToSnapshot(page);
|
||||
if (pageSnapshot) {
|
||||
const snapshot: SliceSnapshot = {
|
||||
type: 'slice',
|
||||
content: [
|
||||
pageSnapshot.blocks.children.find(
|
||||
b => b.flavour === 'affine:note'
|
||||
) as BlockSnapshot,
|
||||
],
|
||||
workspaceId: payload.workspaceId,
|
||||
pageId: payload.pageId,
|
||||
};
|
||||
|
||||
return {
|
||||
snapshot,
|
||||
transformer,
|
||||
};
|
||||
}
|
||||
}
|
||||
const snapshot = await markdownAdapter.toSliceSnapshot(payload);
|
||||
|
||||
return {
|
||||
snapshot: null,
|
||||
snapshot,
|
||||
transformer,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user