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