mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 00:26:51 +08:00
refactor(editor): do not create a tag column by default anymore (#9789)
close: BS-2423
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user