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,
|
type DatabaseFlags,
|
||||||
DataSourceBase,
|
DataSourceBase,
|
||||||
type DataViewDataType,
|
type DataViewDataType,
|
||||||
getTagColor,
|
|
||||||
type PropertyMetaConfig,
|
type PropertyMetaConfig,
|
||||||
type TypeInstance,
|
type TypeInstance,
|
||||||
type ViewManager,
|
type ViewManager,
|
||||||
@@ -23,7 +22,7 @@ import {
|
|||||||
import { propertyPresets } from '@blocksuite/data-view/property-presets';
|
import { propertyPresets } from '@blocksuite/data-view/property-presets';
|
||||||
import { IS_MOBILE } from '@blocksuite/global/env';
|
import { IS_MOBILE } from '@blocksuite/global/env';
|
||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
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 { computed, type ReadonlySignal } from '@preact/signals-core';
|
||||||
|
|
||||||
import { getIcon } from './block-icons.js';
|
import { getIcon } from './block-icons.js';
|
||||||
@@ -512,49 +511,9 @@ export const databaseViewInitTemplate = (
|
|||||||
datasource: DatabaseBlockDataSource,
|
datasource: DatabaseBlockDataSource,
|
||||||
viewType: string
|
viewType: string
|
||||||
) => {
|
) => {
|
||||||
const ids = [nanoid(), nanoid(), nanoid()] as const;
|
Array.from({ length: 3 }).forEach(() => {
|
||||||
const titleId = datasource.properties$.value[0];
|
datasource.rowAdd('end');
|
||||||
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',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
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);
|
datasource.viewManager.viewAdd(viewType);
|
||||||
};
|
};
|
||||||
export const convertToDatabase = (host: EditorHost, viewType: string) => {
|
export const convertToDatabase = (host: EditorHost, viewType: string) => {
|
||||||
|
|||||||
@@ -751,10 +751,10 @@ test('should insert database', async ({ page }) => {
|
|||||||
|
|
||||||
const database = page.locator('affine-database');
|
const database = page.locator('affine-database');
|
||||||
await expect(database).toBeVisible();
|
await expect(database).toBeVisible();
|
||||||
const tagColumn = page.locator('.affine-database-column').nth(1);
|
const titleColumn = page.locator('.affine-database-column').nth(0);
|
||||||
expect(await tagColumn.innerText()).toBe('Status');
|
expect(await titleColumn.innerText()).toBe('Title');
|
||||||
const defaultRows = page.locator('.affine-database-block-row');
|
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', () => {
|
test.describe('slash menu with customize menu', () => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { test } from '@affine-test/kit/playwright';
|
import { test } from '@affine-test/kit/playwright';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
addColumn,
|
||||||
addRows,
|
addRows,
|
||||||
initDatabaseByOneStep,
|
initDatabaseByOneStep,
|
||||||
pasteString,
|
pasteString,
|
||||||
@@ -14,6 +15,7 @@ test.describe('Database Clipboard Operations', () => {
|
|||||||
}) => {
|
}) => {
|
||||||
// Open the home page and wait for the editor to load
|
// Open the home page and wait for the editor to load
|
||||||
await initDatabaseByOneStep(page);
|
await initDatabaseByOneStep(page);
|
||||||
|
await addColumn(page, 'multi-select');
|
||||||
// Create a database block with two rows
|
// Create a database block with two rows
|
||||||
await addRows(page, 2);
|
await addRows(page, 2);
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ test.describe('Database Clipboard Operations', () => {
|
|||||||
}) => {
|
}) => {
|
||||||
// Open the home page and wait for the editor to load
|
// Open the home page and wait for the editor to load
|
||||||
await initDatabaseByOneStep(page);
|
await initDatabaseByOneStep(page);
|
||||||
|
await addColumn(page, 'multi-select');
|
||||||
// Create a database block with two rows
|
// Create a database block with two rows
|
||||||
await addRows(page, 2);
|
await addRows(page, 2);
|
||||||
|
|
||||||
@@ -51,6 +54,7 @@ test.describe('Database Clipboard Operations', () => {
|
|||||||
test('handle pasting data larger than selected area', async ({ page }) => {
|
test('handle pasting data larger than selected area', async ({ page }) => {
|
||||||
// Open the home page and wait for the editor to load
|
// Open the home page and wait for the editor to load
|
||||||
await initDatabaseByOneStep(page);
|
await initDatabaseByOneStep(page);
|
||||||
|
await addColumn(page, 'multi-select');
|
||||||
// Create a database block with one row
|
// Create a database block with one row
|
||||||
await addRows(page, 1);
|
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');
|
const typeMenu = page.locator('affine-menu').getByText('Type');
|
||||||
await page.waitForTimeout(100);
|
await page.waitForTimeout(100);
|
||||||
await typeMenu.hover();
|
await typeMenu.hover();
|
||||||
await page.waitForTimeout(100);
|
await page.waitForTimeout(100);
|
||||||
await page.keyboard.type(columnType);
|
await page.keyboard.type(columnType);
|
||||||
await page.waitForTimeout(100);
|
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.waitForTimeout(100);
|
||||||
await page.keyboard.press('Enter');
|
await page.keyboard.press('Enter');
|
||||||
await page.waitForTimeout(100);
|
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 clickAddColumnButton(page);
|
||||||
await selectColumnType(page, type);
|
await selectColumnType(page, type, nth);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function clickAddColumnButton(page: Page) {
|
export async function clickAddColumnButton(page: Page) {
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import {
|
|||||||
} from '@affine-test/kit/utils/properties';
|
} from '@affine-test/kit/utils/properties';
|
||||||
import { expect } from '@playwright/test';
|
import { expect } from '@playwright/test';
|
||||||
|
|
||||||
|
import { addColumn } from './blocksuite/database/utils';
|
||||||
|
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await openHomePage(page);
|
await openHomePage(page);
|
||||||
await clickNewPageButton(page);
|
await clickNewPageButton(page);
|
||||||
@@ -298,6 +300,7 @@ test('can show database backlink info', async ({ page }) => {
|
|||||||
|
|
||||||
const databaseTitle = 'some database title';
|
const databaseTitle = 'some database title';
|
||||||
await addDatabase(page, databaseTitle);
|
await addDatabase(page, databaseTitle);
|
||||||
|
await addColumn(page, 'select', 2);
|
||||||
|
|
||||||
await expect(page.locator('affine-database-title')).toContainText(
|
await expect(page.locator('affine-database-title')).toContainText(
|
||||||
databaseTitle
|
databaseTitle
|
||||||
|
|||||||
Reference in New Issue
Block a user