fix:remove name

This commit is contained in:
Philipinho
2026-05-07 23:15:40 +01:00
parent 94ecc98617
commit 6c966651b0
9 changed files with 32 additions and 47 deletions
@@ -17,13 +17,13 @@ describe('collectTransclusionsFromPmJson', () => {
expect(collectTransclusionsFromPmJson(doc)).toEqual([]); expect(collectTransclusionsFromPmJson(doc)).toEqual([]);
}); });
it('extracts a top-level transclusion with id, name and content', () => { it('extracts a top-level transclusion with id and content', () => {
const doc = { const doc = {
type: 'doc', type: 'doc',
content: [ content: [
{ {
type: 'transclusionSource', type: 'transclusionSource',
attrs: { id: 'abc123', name: 'Pricing' }, attrs: { id: 'abc123' },
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Body' }] }], content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Body' }] }],
}, },
], ],
@@ -31,7 +31,6 @@ describe('collectTransclusionsFromPmJson', () => {
const got = collectTransclusionsFromPmJson(doc); const got = collectTransclusionsFromPmJson(doc);
expect(got).toHaveLength(1); expect(got).toHaveLength(1);
expect(got[0].transclusionId).toBe('abc123'); expect(got[0].transclusionId).toBe('abc123');
expect(got[0].name).toBe('Pricing');
expect(got[0].content).toEqual({ expect(got[0].content).toEqual({
type: 'doc', type: 'doc',
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Body' }] }], content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Body' }] }],
@@ -53,7 +52,7 @@ describe('collectTransclusionsFromPmJson', () => {
type: 'doc', type: 'doc',
content: [ content: [
{ type: 'transclusionSource', attrs: { id: 'a' }, content: [{ type: 'paragraph' }] }, { type: 'transclusionSource', attrs: { id: 'a' }, content: [{ type: 'paragraph' }] },
{ type: 'transclusionSource', attrs: { id: 'b', name: 'Two' }, content: [{ type: 'paragraph' }] }, { type: 'transclusionSource', attrs: { id: 'b' }, content: [{ type: 'paragraph' }] },
], ],
}; };
const got = collectTransclusionsFromPmJson(doc); const got = collectTransclusionsFromPmJson(doc);
@@ -102,13 +101,24 @@ describe('collectTransclusionsFromPmJson', () => {
const doc = { const doc = {
type: 'doc', type: 'doc',
content: [ content: [
{ type: 'transclusionSource', attrs: { id: 'dup', name: 'first' }, content: [{ type: 'paragraph' }] }, {
{ type: 'transclusionSource', attrs: { id: 'dup', name: 'second' }, content: [{ type: 'paragraph' }] }, type: 'transclusionSource',
attrs: { id: 'dup' },
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'first' }] }],
},
{
type: 'transclusionSource',
attrs: { id: 'dup' },
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'second' }] }],
},
], ],
}; };
const got = collectTransclusionsFromPmJson(doc); const got = collectTransclusionsFromPmJson(doc);
expect(got).toHaveLength(1); expect(got).toHaveLength(1);
expect(got[0].name).toBe('second'); expect(got[0].content).toEqual({
type: 'doc',
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'second' }] }],
});
}); });
}); });
@@ -42,7 +42,7 @@ describe('TransclusionService.syncPageTransclusions', () => {
content: [ content: [
{ {
type: 'transclusionSource', type: 'transclusionSource',
attrs: { id: 'a', name: 'Hello' }, attrs: { id: 'a' },
content: [{ type: 'paragraph' }], content: [{ type: 'paragraph' }],
}, },
], ],
@@ -56,7 +56,6 @@ describe('TransclusionService.syncPageTransclusions', () => {
expect.objectContaining({ expect.objectContaining({
pageId, pageId,
transclusionId: 'a', transclusionId: 'a',
name: 'Hello',
}), }),
undefined, undefined,
); );
@@ -64,27 +63,30 @@ describe('TransclusionService.syncPageTransclusions', () => {
expect(repo.deleteByPageAndTransclusionIds).not.toHaveBeenCalled(); expect(repo.deleteByPageAndTransclusionIds).not.toHaveBeenCalled();
}); });
it('updates transclusions whose name or content changed', async () => { it('updates transclusions whose content changed', async () => {
repo.findByPageId.mockResolvedValue([ repo.findByPageId.mockResolvedValue([
{ {
id: 'row1', id: 'row1',
pageId, pageId,
transclusionId: 'a', transclusionId: 'a',
name: 'Old',
content: { type: 'doc', content: [{ type: 'paragraph' }] }, content: { type: 'doc', content: [{ type: 'paragraph' }] },
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
} as any, } as any,
]); ]);
const newContent = {
type: 'doc',
content: [
{ type: 'paragraph', content: [{ type: 'text', text: 'X' }] },
],
};
const pm = { const pm = {
type: 'doc', type: 'doc',
content: [ content: [
{ {
type: 'transclusionSource', type: 'transclusionSource',
attrs: { id: 'a', name: 'New' }, attrs: { id: 'a' },
content: [ content: newContent.content,
{ type: 'paragraph', content: [{ type: 'text', text: 'X' }] },
],
}, },
], ],
}; };
@@ -95,12 +97,12 @@ describe('TransclusionService.syncPageTransclusions', () => {
expect(repo.update).toHaveBeenCalledWith( expect(repo.update).toHaveBeenCalledWith(
pageId, pageId,
'a', 'a',
expect.objectContaining({ name: 'New' }), expect.objectContaining({ content: newContent }),
undefined, undefined,
); );
}); });
it('skips update when name and content are unchanged', async () => { it('skips update when content is unchanged', async () => {
const sameContent = { const sameContent = {
type: 'doc', type: 'doc',
content: [{ type: 'paragraph' }], content: [{ type: 'paragraph' }],
@@ -110,7 +112,6 @@ describe('TransclusionService.syncPageTransclusions', () => {
id: 'row1', id: 'row1',
pageId, pageId,
transclusionId: 'a', transclusionId: 'a',
name: 'Same',
content: sameContent, content: sameContent,
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
@@ -121,7 +122,7 @@ describe('TransclusionService.syncPageTransclusions', () => {
content: [ content: [
{ {
type: 'transclusionSource', type: 'transclusionSource',
attrs: { id: 'a', name: 'Same' }, attrs: { id: 'a' },
content: sameContent.content, content: sameContent.content,
}, },
], ],
@@ -139,7 +140,6 @@ describe('TransclusionService.syncPageTransclusions', () => {
id: 'r', id: 'r',
pageId, pageId,
transclusionId: 'gone', transclusionId: 'gone',
name: null,
content: { type: 'doc', content: [] }, content: { type: 'doc', content: [] },
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
@@ -65,7 +65,6 @@ export class TransclusionService {
{ {
pageId, pageId,
transclusionId: d.transclusionId, transclusionId: d.transclusionId,
name: d.name,
content: d.content as any, content: d.content as any,
}, },
trx, trx,
@@ -74,13 +73,12 @@ export class TransclusionService {
continue; continue;
} }
const nameChanged = prev.name !== d.name;
const contentChanged = !isDeepStrictEqual(prev.content, d.content); const contentChanged = !isDeepStrictEqual(prev.content, d.content);
if (nameChanged || contentChanged) { if (contentChanged) {
await this.pageTransclusionsRepo.update( await this.pageTransclusionsRepo.update(
pageId, pageId,
d.transclusionId, d.transclusionId,
{ name: d.name, content: d.content as any }, { content: d.content as any },
trx, trx,
); );
updated += 1; updated += 1;
@@ -226,7 +224,6 @@ export class TransclusionService {
rows.push({ rows.push({
pageId: page.id, pageId: page.id,
transclusionId: s.transclusionId, transclusionId: s.transclusionId,
name: s.name,
content: s.content as any, content: s.content as any,
}); });
} }
@@ -10,6 +10,5 @@ export type TransclusionLookup =
export type TransclusionNodeSnapshot = { export type TransclusionNodeSnapshot = {
transclusionId: string; transclusionId: string;
name: string | null;
content: unknown; content: unknown;
}; };
@@ -34,13 +34,8 @@ export function collectTransclusionsFromPmJson(
if (node.type === TRANSCLUSION_TYPE) { if (node.type === TRANSCLUSION_TYPE) {
const id = node.attrs?.id; const id = node.attrs?.id;
if (typeof id === 'string' && id.length > 0) { if (typeof id === 'string' && id.length > 0) {
const name =
typeof node.attrs?.name === 'string' && node.attrs.name.length > 0
? node.attrs.name
: null;
byId.set(id, { byId.set(id, {
transclusionId: id, transclusionId: id,
name,
content: { type: 'doc', content: node.content ?? [] }, content: { type: 'doc', content: node.content ?? [] },
}); });
} }
@@ -10,7 +10,6 @@ export async function up(db: Kysely<any>): Promise<void> {
col.notNull().references('pages.id').onDelete('cascade'), col.notNull().references('pages.id').onDelete('cascade'),
) )
.addColumn('transclusion_id', 'varchar', (col) => col.notNull()) .addColumn('transclusion_id', 'varchar', (col) => col.notNull())
.addColumn('name', 'text')
.addColumn('content', 'jsonb', (col) => col.notNull()) .addColumn('content', 'jsonb', (col) => col.notNull())
.addColumn('created_at', 'timestamptz', (col) => .addColumn('created_at', 'timestamptz', (col) =>
col.notNull().defaultTo(sql`now()`), col.notNull().defaultTo(sql`now()`),
@@ -7,7 +7,6 @@ import {
PageTransclusion, PageTransclusion,
UpdatablePageTransclusion, UpdatablePageTransclusion,
} from '@docmost/db/types/entity.types'; } from '@docmost/db/types/entity.types';
import { sql } from 'kysely';
@Injectable() @Injectable()
export class PageTransclusionsRepo { export class PageTransclusionsRepo {
@@ -21,7 +20,6 @@ export class PageTransclusionsRepo {
.selectFrom('pageTransclusions') .selectFrom('pageTransclusions')
.selectAll() .selectAll()
.where('pageId', '=', pageId) .where('pageId', '=', pageId)
.orderBy(sql`name asc nulls last`)
.orderBy('createdAt', 'asc') .orderBy('createdAt', 'asc')
.execute(); .execute();
} }
-1
View File
@@ -242,7 +242,6 @@ export interface PageTransclusions {
createdAt: Generated<Timestamp>; createdAt: Generated<Timestamp>;
transclusionId: string; transclusionId: string;
id: Generated<string>; id: Generated<string>;
name: string | null;
pageId: string; pageId: string;
updatedAt: Generated<Timestamp>; updatedAt: Generated<Timestamp>;
} }
@@ -9,7 +9,6 @@ export interface TransclusionSourceOptions {
export interface TransclusionSourceAttributes { export interface TransclusionSourceAttributes {
id?: string | null; id?: string | null;
name?: string | null;
} }
declare module "@tiptap/core" { declare module "@tiptap/core" {
@@ -18,7 +17,6 @@ declare module "@tiptap/core" {
insertTransclusionSource: ( insertTransclusionSource: (
attributes?: TransclusionSourceAttributes, attributes?: TransclusionSourceAttributes,
) => ReturnType; ) => ReturnType;
setTransclusionSourceName: (name: string | null) => ReturnType;
toggleTransclusionSource: () => ReturnType; toggleTransclusionSource: () => ReturnType;
unsyncTransclusionSource: () => ReturnType; unsyncTransclusionSource: () => ReturnType;
}; };
@@ -48,12 +46,6 @@ export const TransclusionSource = Node.create<TransclusionSourceOptions>({
renderHTML: (attrs) => renderHTML: (attrs) =>
attrs.id ? { "data-id": attrs.id } : {}, attrs.id ? { "data-id": attrs.id } : {},
}, },
name: {
default: null,
parseHTML: (el) => el.getAttribute("data-name"),
renderHTML: (attrs) =>
attrs.name ? { "data-name": attrs.name } : {},
},
}; };
}, },
@@ -104,10 +96,6 @@ export const TransclusionSource = Node.create<TransclusionSourceOptions>({
return commands.insertContent(node); return commands.insertContent(node);
}, },
setTransclusionSourceName:
(name) =>
({ commands }) =>
commands.updateAttributes(this.name, { name }),
toggleTransclusionSource: toggleTransclusionSource:
() => () =>
({ commands }) => ({ commands }) =>