mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 09:21:24 +08:00
fix(core): should display date as original title of journal (#11375)
Closes: [BS-2991](https://linear.app/affine-design/issue/BS-2991/linked-journal添加alias后,toolbar上获取不到标题)
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
} from '@blocksuite/affine-shared/consts';
|
} from '@blocksuite/affine-shared/consts';
|
||||||
import {
|
import {
|
||||||
ActionPlacement,
|
ActionPlacement,
|
||||||
|
DocDisplayMetaProvider,
|
||||||
type LinkEventType,
|
type LinkEventType,
|
||||||
type OpenDocMode,
|
type OpenDocMode,
|
||||||
type ToolbarAction,
|
type ToolbarAction,
|
||||||
@@ -76,11 +77,13 @@ const docTitleAction = {
|
|||||||
if (!model.props.title) return null;
|
if (!model.props.title) return null;
|
||||||
|
|
||||||
const originalTitle =
|
const originalTitle =
|
||||||
ctx.workspace.getDoc(model.props.pageId)?.meta?.title || 'Untitled';
|
ctx.std.get(DocDisplayMetaProvider).title(model.props.pageId).value ||
|
||||||
|
'Untitled';
|
||||||
|
const open = (event: MouseEvent) => block.open({ event });
|
||||||
|
|
||||||
return html`<affine-linked-doc-title
|
return html`<affine-linked-doc-title
|
||||||
.title=${originalTitle}
|
.title=${originalTitle}
|
||||||
.open=${(event: MouseEvent) => block.open({ event })}
|
.open=${open}
|
||||||
></affine-linked-doc-title>`;
|
></affine-linked-doc-title>`;
|
||||||
},
|
},
|
||||||
} as const satisfies ToolbarAction;
|
} as const satisfies ToolbarAction;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { notifyLinkedDocSwitchedToEmbed } from '@blocksuite/affine-components/notification';
|
import { notifyLinkedDocSwitchedToEmbed } from '@blocksuite/affine-components/notification';
|
||||||
import {
|
import {
|
||||||
ActionPlacement,
|
ActionPlacement,
|
||||||
|
DocDisplayMetaProvider,
|
||||||
type ToolbarAction,
|
type ToolbarAction,
|
||||||
type ToolbarActionGroup,
|
type ToolbarActionGroup,
|
||||||
type ToolbarModuleConfig,
|
type ToolbarModuleConfig,
|
||||||
@@ -34,9 +35,14 @@ export const builtinInlineReferenceToolbarConfig = {
|
|||||||
if (!(target instanceof AffineReference)) return null;
|
if (!(target instanceof AffineReference)) return null;
|
||||||
if (!target.referenceInfo.title) return null;
|
if (!target.referenceInfo.title) return null;
|
||||||
|
|
||||||
|
const originalTitle =
|
||||||
|
ctx.std.get(DocDisplayMetaProvider).title(target.referenceInfo.pageId)
|
||||||
|
.value || 'Untitled';
|
||||||
|
const open = (event: MouseEvent) => target.open({ event });
|
||||||
|
|
||||||
return html`<affine-linked-doc-title
|
return html`<affine-linked-doc-title
|
||||||
.title=${target.docTitle}
|
.title=${originalTitle}
|
||||||
.open=${(event: MouseEvent) => target.open({ event })}
|
.open=${open}
|
||||||
></affine-linked-doc-title>`;
|
></affine-linked-doc-title>`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ import {
|
|||||||
} from '@blocksuite/icons/lit';
|
} from '@blocksuite/icons/lit';
|
||||||
import { LifeCycleWatcher, StdIdentifier } from '@blocksuite/std';
|
import { LifeCycleWatcher, StdIdentifier } from '@blocksuite/std';
|
||||||
import type { Store } from '@blocksuite/store';
|
import type { Store } from '@blocksuite/store';
|
||||||
import { computed, type Signal, signal } from '@preact/signals-core';
|
import {
|
||||||
|
computed,
|
||||||
|
type ReadonlySignal,
|
||||||
|
type Signal,
|
||||||
|
signal,
|
||||||
|
} from '@preact/signals-core';
|
||||||
import type { TemplateResult } from 'lit';
|
import type { TemplateResult } from 'lit';
|
||||||
|
|
||||||
import { referenceToNode } from '../utils/reference.js';
|
import { referenceToNode } from '../utils/reference.js';
|
||||||
@@ -44,11 +49,11 @@ export interface DocDisplayMetaExtension {
|
|||||||
icon: (
|
icon: (
|
||||||
docId: string,
|
docId: string,
|
||||||
referenceInfo?: DocDisplayMetaParams
|
referenceInfo?: DocDisplayMetaParams
|
||||||
) => Signal<TemplateResult>;
|
) => ReadonlySignal<TemplateResult>;
|
||||||
title: (
|
title: (
|
||||||
docId: string,
|
docId: string,
|
||||||
referenceInfo?: DocDisplayMetaParams
|
referenceInfo?: DocDisplayMetaParams
|
||||||
) => Signal<string>;
|
) => ReadonlySignal<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DocDisplayMetaProvider = createIdentifier<DocDisplayMetaExtension>(
|
export const DocDisplayMetaProvider = createIdentifier<DocDisplayMetaExtension>(
|
||||||
@@ -93,11 +98,11 @@ export class DocDisplayMetaService
|
|||||||
icon(
|
icon(
|
||||||
pageId: string,
|
pageId: string,
|
||||||
{ params, title, referenced }: DocDisplayMetaParams = {}
|
{ params, title, referenced }: DocDisplayMetaParams = {}
|
||||||
): Signal<TemplateResult> {
|
): ReadonlySignal<TemplateResult> {
|
||||||
const doc = this.std.workspace.getDoc(pageId);
|
const doc = this.std.workspace.getDoc(pageId);
|
||||||
|
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return signal(DocDisplayMetaService.icons.deleted);
|
return computed(() => DocDisplayMetaService.icons.deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
const store = doc.getStore();
|
const store = doc.getStore();
|
||||||
@@ -160,11 +165,14 @@ export class DocDisplayMetaService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
title(pageId: string, { title }: DocDisplayMetaParams = {}): Signal<string> {
|
title(
|
||||||
|
pageId: string,
|
||||||
|
{ title }: DocDisplayMetaParams = {}
|
||||||
|
): ReadonlySignal<string> {
|
||||||
const doc = this.std.workspace.getDoc(pageId);
|
const doc = this.std.workspace.getDoc(pageId);
|
||||||
|
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return signal(title || 'Deleted doc');
|
return computed(() => title || 'Deleted doc');
|
||||||
}
|
}
|
||||||
|
|
||||||
const store = doc.getStore();
|
const store = doc.getStore();
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import { DocDisplayMetaProvider } from '@blocksuite/affine/shared/services';
|
|||||||
import {
|
import {
|
||||||
createSignalFromObservable,
|
createSignalFromObservable,
|
||||||
referenceToNode,
|
referenceToNode,
|
||||||
type Signal,
|
|
||||||
} from '@blocksuite/affine/shared/utils';
|
} from '@blocksuite/affine/shared/utils';
|
||||||
import { LifeCycleWatcher, StdIdentifier } from '@blocksuite/affine/std';
|
import { LifeCycleWatcher, StdIdentifier } from '@blocksuite/affine/std';
|
||||||
import { LinkedPageIcon, PageIcon } from '@blocksuite/icons/lit';
|
import { LinkedPageIcon, PageIcon } from '@blocksuite/icons/lit';
|
||||||
|
import { computed, type ReadonlySignal } from '@preact/signals-core';
|
||||||
import { type FrameworkProvider } from '@toeverything/infra';
|
import { type FrameworkProvider } from '@toeverything/infra';
|
||||||
import type { TemplateResult } from 'lit';
|
import type { TemplateResult } from 'lit';
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ export function buildDocDisplayMetaExtension(framework: FrameworkProvider) {
|
|||||||
icon(
|
icon(
|
||||||
docId: string,
|
docId: string,
|
||||||
{ params, title, referenced }: DocDisplayMetaParams = {}
|
{ params, title, referenced }: DocDisplayMetaParams = {}
|
||||||
): Signal<TemplateResult> {
|
): ReadonlySignal<TemplateResult> {
|
||||||
const icon$ = docDisplayMetaService
|
const icon$ = docDisplayMetaService
|
||||||
.icon$(docId, {
|
.icon$(docId, {
|
||||||
type: 'lit',
|
type: 'lit',
|
||||||
@@ -69,13 +69,13 @@ export function buildDocDisplayMetaExtension(framework: FrameworkProvider) {
|
|||||||
|
|
||||||
this.disposables.push(cleanup);
|
this.disposables.push(cleanup);
|
||||||
|
|
||||||
return iconSignal;
|
return computed(() => iconSignal.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
title(
|
title(
|
||||||
docId: string,
|
docId: string,
|
||||||
{ title, referenced }: DocDisplayMetaParams = {}
|
{ title, referenced }: DocDisplayMetaParams = {}
|
||||||
): Signal<string> {
|
): ReadonlySignal<string> {
|
||||||
const title$ = docDisplayMetaService.title$(docId, {
|
const title$ = docDisplayMetaService.title$(docId, {
|
||||||
title,
|
title,
|
||||||
reference: referenced,
|
reference: referenced,
|
||||||
@@ -86,7 +86,7 @@ export function buildDocDisplayMetaExtension(framework: FrameworkProvider) {
|
|||||||
|
|
||||||
this.disposables.push(cleanup);
|
this.disposables.push(cleanup);
|
||||||
|
|
||||||
return titleSignal;
|
return computed(() => titleSignal.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
override unmounted() {
|
override unmounted() {
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
createLinkedPage,
|
createLinkedPage,
|
||||||
createTodayPage,
|
createTodayPage,
|
||||||
getBlockSuiteEditorTitle,
|
getBlockSuiteEditorTitle,
|
||||||
waitForEditorLoad,
|
|
||||||
waitForEmptyEditor,
|
waitForEmptyEditor,
|
||||||
} from '@affine-test/kit/utils/page-logic';
|
} from '@affine-test/kit/utils/page-logic';
|
||||||
import {
|
import {
|
||||||
@@ -980,7 +979,6 @@ test.describe('Customize linked doc title and description', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should show emoji doc icon in normal document', async ({ page }) => {
|
test('should show emoji doc icon in normal document', async ({ page }) => {
|
||||||
await waitForEditorLoad(page);
|
|
||||||
await enableEmojiDocIcon(page);
|
await enableEmojiDocIcon(page);
|
||||||
|
|
||||||
await clickNewPageButton(page);
|
await clickNewPageButton(page);
|
||||||
@@ -1010,7 +1008,6 @@ test.describe('Customize linked doc title and description', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should show emoji doc icon in journal document', async ({ page }) => {
|
test('should show emoji doc icon in journal document', async ({ page }) => {
|
||||||
await waitForEditorLoad(page);
|
|
||||||
await enableEmojiDocIcon(page);
|
await enableEmojiDocIcon(page);
|
||||||
|
|
||||||
await clickNewPageButton(page);
|
await clickNewPageButton(page);
|
||||||
@@ -1042,7 +1039,6 @@ test.describe('Customize linked doc title and description', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should save open doc mode of internal links', async ({ page }) => {
|
test('should save open doc mode of internal links', async ({ page }) => {
|
||||||
await waitForEditorLoad(page);
|
|
||||||
await enableEmojiDocIcon(page);
|
await enableEmojiDocIcon(page);
|
||||||
|
|
||||||
await clickNewPageButton(page);
|
await clickNewPageButton(page);
|
||||||
@@ -1223,3 +1219,67 @@ test('should reach target block when clicking affine-link multiple times', async
|
|||||||
|
|
||||||
expect(refreshKey0).not.toEqual(refreshKey1);
|
expect(refreshKey0).not.toEqual(refreshKey1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should display date as the original title of journal', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
await createTodayPage(page);
|
||||||
|
|
||||||
|
const { toolbar, switchViewBtn, cardViewBtn } = toolbarButtons(page);
|
||||||
|
|
||||||
|
const linkedDocTitle = toolbar.locator('affine-linked-doc-title .label');
|
||||||
|
|
||||||
|
const inlineLink = page.locator('affine-reference');
|
||||||
|
await inlineLink.hover();
|
||||||
|
|
||||||
|
await expect(toolbar).toBeVisible();
|
||||||
|
await expect(linkedDocTitle).toBeHidden();
|
||||||
|
|
||||||
|
// Edits title & description
|
||||||
|
await toolbar.getByRole('button', { name: 'Edit' }).click();
|
||||||
|
|
||||||
|
await expect(toolbar).toBeHidden();
|
||||||
|
|
||||||
|
const popover = page.locator('reference-popup');
|
||||||
|
|
||||||
|
// Title alias
|
||||||
|
await page.keyboard.type('Test Page Alias Again');
|
||||||
|
await page.keyboard.press('Tab');
|
||||||
|
// Description alias
|
||||||
|
await page.keyboard.type('This is a new description');
|
||||||
|
|
||||||
|
await popover.getByLabel('Save').click();
|
||||||
|
|
||||||
|
await inlineLink.hover();
|
||||||
|
await expect(toolbar).toBeVisible();
|
||||||
|
await expect(linkedDocTitle).toBeVisible();
|
||||||
|
const inlineTitleText = (await linkedDocTitle.textContent())?.trim() ?? '';
|
||||||
|
|
||||||
|
const year = String(new Date().getFullYear());
|
||||||
|
expect(inlineTitleText).toContain(year);
|
||||||
|
|
||||||
|
await switchViewBtn.click();
|
||||||
|
await cardViewBtn.click();
|
||||||
|
|
||||||
|
const cardLink = page.locator('affine-embed-linked-doc-block');
|
||||||
|
await expect(cardLink).toBeVisible();
|
||||||
|
|
||||||
|
await expect(toolbar).toBeVisible();
|
||||||
|
await expect(linkedDocTitle).toBeVisible();
|
||||||
|
const cardViewTitleText = (await linkedDocTitle.textContent())?.trim() ?? '';
|
||||||
|
|
||||||
|
expect(cardViewTitleText).toBe(inlineTitleText);
|
||||||
|
|
||||||
|
// Edits title & description
|
||||||
|
await toolbar.getByRole('button', { name: 'Edit' }).click();
|
||||||
|
|
||||||
|
await expect(toolbar).toBeHidden();
|
||||||
|
|
||||||
|
const cardEditPopup = page.locator('embed-card-edit-modal');
|
||||||
|
// Resets
|
||||||
|
await cardEditPopup.getByRole('button', { name: 'Reset' }).click();
|
||||||
|
|
||||||
|
await expect(toolbar).toBeVisible();
|
||||||
|
await expect(linkedDocTitle).toBeHidden();
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user