From 2e18ae59e38a57e8113db7e8445aa898be8a9001 Mon Sep 17 00:00:00 2001 From: zzj3720 <17165520+zzj3720@users.noreply.github.com> Date: Mon, 20 Jan 2025 06:59:09 +0000 Subject: [PATCH] refactor(editor): do not create a tag column by default anymore (#9789) close: BS-2423 --- .../affine/block-database/src/data-source.ts | 47 ++----------------- blocksuite/tests-legacy/slash-menu.spec.ts | 6 +-- .../e2e/blocksuite/database/clipboard.spec.ts | 4 ++ .../e2e/blocksuite/database/utils.ts | 14 ++++-- .../affine-local/e2e/page-properties.spec.ts | 3 ++ 5 files changed, 23 insertions(+), 51 deletions(-) diff --git a/blocksuite/affine/block-database/src/data-source.ts b/blocksuite/affine/block-database/src/data-source.ts index 82c2b1c27..29d3f9554 100644 --- a/blocksuite/affine/block-database/src/data-source.ts +++ b/blocksuite/affine/block-database/src/data-source.ts @@ -13,7 +13,6 @@ import { type DatabaseFlags, DataSourceBase, type DataViewDataType, - getTagColor, type PropertyMetaConfig, type TypeInstance, type ViewManager, @@ -23,7 +22,7 @@ import { import { propertyPresets } from '@blocksuite/data-view/property-presets'; import { IS_MOBILE } from '@blocksuite/global/env'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; -import { type BlockModel, nanoid, Text } from '@blocksuite/store'; +import { type BlockModel } from '@blocksuite/store'; import { computed, type ReadonlySignal } from '@preact/signals-core'; import { getIcon } from './block-icons.js'; @@ -512,49 +511,9 @@ export const databaseViewInitTemplate = ( datasource: DatabaseBlockDataSource, viewType: string ) => { - const ids = [nanoid(), nanoid(), nanoid()] as const; - const titleId = datasource.properties$.value[0]; - const statusId = datasource.propertyAdd( - 'end', - propertyPresets.selectPropertyConfig.type - ); - datasource.propertyNameSet(statusId, 'Status'); - datasource.propertyDataSet(statusId, { - options: [ - { - id: ids[0], - color: getTagColor(), - value: 'TODO', - }, - { - id: ids[1], - color: getTagColor(), - value: 'In Progress', - }, - { - id: ids[2], - color: getTagColor(), - value: 'Done', - }, - ], + Array.from({ length: 3 }).forEach(() => { + datasource.rowAdd('end'); }); - for (let i = 0; i < 4; i++) { - const rowId = datasource.rowAdd('end'); - if (titleId) { - const text = datasource.cellValueGet(rowId, titleId); - if (text instanceof Text) { - text.replace(0, text.length, `Task ${i + 1}`); - } - } - datasource.cellValueChange(rowId, statusId, ids[i]); - // const rowId = model.doc.addBlock( - // 'affine:paragraph', - // { - // text: new Text(`Task ${i + 1}`), - // }, - // model.id - // ); - } datasource.viewManager.viewAdd(viewType); }; export const convertToDatabase = (host: EditorHost, viewType: string) => { diff --git a/blocksuite/tests-legacy/slash-menu.spec.ts b/blocksuite/tests-legacy/slash-menu.spec.ts index 1f11918dd..43cc8b3b1 100644 --- a/blocksuite/tests-legacy/slash-menu.spec.ts +++ b/blocksuite/tests-legacy/slash-menu.spec.ts @@ -751,10 +751,10 @@ test('should insert database', async ({ page }) => { const database = page.locator('affine-database'); await expect(database).toBeVisible(); - const tagColumn = page.locator('.affine-database-column').nth(1); - expect(await tagColumn.innerText()).toBe('Status'); + const titleColumn = page.locator('.affine-database-column').nth(0); + expect(await titleColumn.innerText()).toBe('Title'); const defaultRows = page.locator('.affine-database-block-row'); - expect(await defaultRows.count()).toBe(4); + expect(await defaultRows.count()).toBe(3); }); test.describe('slash menu with customize menu', () => { diff --git a/tests/affine-local/e2e/blocksuite/database/clipboard.spec.ts b/tests/affine-local/e2e/blocksuite/database/clipboard.spec.ts index 4f45c1e40..2656a5a36 100644 --- a/tests/affine-local/e2e/blocksuite/database/clipboard.spec.ts +++ b/tests/affine-local/e2e/blocksuite/database/clipboard.spec.ts @@ -1,6 +1,7 @@ import { test } from '@affine-test/kit/playwright'; import { + addColumn, addRows, initDatabaseByOneStep, pasteString, @@ -14,6 +15,7 @@ test.describe('Database Clipboard Operations', () => { }) => { // Open the home page and wait for the editor to load await initDatabaseByOneStep(page); + await addColumn(page, 'multi-select'); // Create a database block with two rows await addRows(page, 2); @@ -36,6 +38,7 @@ test.describe('Database Clipboard Operations', () => { }) => { // Open the home page and wait for the editor to load await initDatabaseByOneStep(page); + await addColumn(page, 'multi-select'); // Create a database block with two rows await addRows(page, 2); @@ -51,6 +54,7 @@ test.describe('Database Clipboard Operations', () => { test('handle pasting data larger than selected area', async ({ page }) => { // Open the home page and wait for the editor to load await initDatabaseByOneStep(page); + await addColumn(page, 'multi-select'); // Create a database block with one row await addRows(page, 1); diff --git a/tests/affine-local/e2e/blocksuite/database/utils.ts b/tests/affine-local/e2e/blocksuite/database/utils.ts index 0f49fe135..8a4deb0b1 100644 --- a/tests/affine-local/e2e/blocksuite/database/utils.ts +++ b/tests/affine-local/e2e/blocksuite/database/utils.ts @@ -71,22 +71,28 @@ export async function verifyCellContents( } } -export async function selectColumnType(page: Page, columnType: string) { +export async function selectColumnType( + page: Page, + columnType: string, + nth: number = 1 +) { const typeMenu = page.locator('affine-menu').getByText('Type'); await page.waitForTimeout(100); await typeMenu.hover(); await page.waitForTimeout(100); await page.keyboard.type(columnType); await page.waitForTimeout(100); - await page.keyboard.press('ArrowDown'); + for (let i = 0; i < nth; i++) { + await page.keyboard.press('ArrowDown'); + } await page.waitForTimeout(100); await page.keyboard.press('Enter'); await page.waitForTimeout(100); } -export async function addColumn(page: Page, type: string) { +export async function addColumn(page: Page, type: string, nth: number = 1) { await clickAddColumnButton(page); - await selectColumnType(page, type); + await selectColumnType(page, type, nth); } export async function clickAddColumnButton(page: Page) { diff --git a/tests/affine-local/e2e/page-properties.spec.ts b/tests/affine-local/e2e/page-properties.spec.ts index 20e495f6c..08ffeec1f 100644 --- a/tests/affine-local/e2e/page-properties.spec.ts +++ b/tests/affine-local/e2e/page-properties.spec.ts @@ -28,6 +28,8 @@ import { } from '@affine-test/kit/utils/properties'; import { expect } from '@playwright/test'; +import { addColumn } from './blocksuite/database/utils'; + test.beforeEach(async ({ page }) => { await openHomePage(page); await clickNewPageButton(page); @@ -298,6 +300,7 @@ test('can show database backlink info', async ({ page }) => { const databaseTitle = 'some database title'; await addDatabase(page, databaseTitle); + await addColumn(page, 'select', 2); await expect(page.locator('affine-database-title')).toContainText( databaseTitle