mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(core): refactor collection to use new filter system (#12228)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new Collection entity and store with reactive management and real-time updates. - Added reactive favorite and shared filters with expanded filtering options. - **Refactor** - Overhauled collection and filtering logic for better performance and maintainability. - Replaced legacy filtering UI and logic with a streamlined, service-driven rules system. - Updated collection components to use reactive data streams and simplified props. - Simplified collection creation by delegating ID generation and instantiation to the service layer. - Removed deprecated hooks and replaced state-based filtering with observable-driven filtering. - **Bug Fixes** - Improved accuracy and consistency of tag and favorite filtering in collections. - **Chores** - Removed deprecated and unused filter-related files, types, components, and styles to reduce complexity. - Cleaned up imports and removed unused code across multiple components. - **Documentation** - Corrected inline documentation for improved clarity. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,43 +1,4 @@
|
||||
import type { Locator, Page } from '@playwright/test';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { clickNewPageButton, getBlockSuiteEditorTitle } from './page-logic';
|
||||
|
||||
const monthNames = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec',
|
||||
];
|
||||
|
||||
export const createFirstFilter = async (page: Page, name: string) => {
|
||||
await page.locator('[data-testid="create-first-filter"]').click();
|
||||
await page
|
||||
.locator('[data-testid="variable-select-item"]', { hasText: name })
|
||||
.click();
|
||||
await page.keyboard.press('Escape');
|
||||
};
|
||||
|
||||
export const checkFilterName = async (page: Page, name: string) => {
|
||||
const filterName = await page
|
||||
.locator('[data-testid="filter-name"]')
|
||||
.textContent();
|
||||
expect(filterName).toBe(name);
|
||||
};
|
||||
|
||||
const dateFormat = (date: Date) => {
|
||||
const month = monthNames[date.getMonth()];
|
||||
const day = date.getDate().toString().padStart(2, '0');
|
||||
return `${month} ${day}`;
|
||||
};
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
// fixme: there could be multiple page lists in the Page
|
||||
export const getPagesCount = async (page: Page) => {
|
||||
@@ -54,97 +15,6 @@ export const getPagesCount = async (page: Page) => {
|
||||
return count ? parseInt(count) : 0;
|
||||
};
|
||||
|
||||
export const checkDatePicker = async (page: Page, date: Date) => {
|
||||
expect(
|
||||
await page
|
||||
.locator('[data-testid="filter-arg"]')
|
||||
.locator('input')
|
||||
.inputValue()
|
||||
).toBe(dateFormat(date));
|
||||
};
|
||||
|
||||
export const clickDatePicker = async (page: Page) => {
|
||||
await page.locator('[data-testid="filter-arg"]').locator('input').click();
|
||||
};
|
||||
|
||||
const clickMonthPicker = async (page: Page | Locator) => {
|
||||
await page.locator('[data-testid="month-picker-button"]').click();
|
||||
};
|
||||
|
||||
export const fillDatePicker = async (page: Page, date: Date) => {
|
||||
await page
|
||||
.locator('[data-testid="filter-arg"]')
|
||||
.locator('input')
|
||||
.fill(dateFormat(date));
|
||||
};
|
||||
|
||||
export const selectMonthFromMonthPicker = async (
|
||||
page: Page | Locator,
|
||||
date: Date
|
||||
) => {
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||
const year = date.getFullYear();
|
||||
// Open the month picker popup
|
||||
await clickMonthPicker(page);
|
||||
const selectMonth = async (): Promise<void> => {
|
||||
const selectedYear = +(await page
|
||||
.getByTestId('month-picker-current-year')
|
||||
.innerText());
|
||||
if (selectedYear > year) {
|
||||
await page.locator('[data-testid="date-picker-nav-prev"]').click();
|
||||
return await selectMonth();
|
||||
} else if (selectedYear < year) {
|
||||
await page.locator('[data-testid="date-picker-nav-next"]').click();
|
||||
return await selectMonth();
|
||||
}
|
||||
// Click on the day cell
|
||||
const monthCell = page.locator(
|
||||
`[data-is-month-cell][aria-label="${year}-${month}"]`
|
||||
);
|
||||
await monthCell.click();
|
||||
};
|
||||
await selectMonth();
|
||||
};
|
||||
|
||||
export const checkDatePickerMonth = async (
|
||||
page: Page | Locator,
|
||||
date: Date
|
||||
) => {
|
||||
expect(
|
||||
await page.getByTestId('month-picker-button').evaluate(e => e.dataset.month)
|
||||
).toBe(date.getMonth().toString());
|
||||
};
|
||||
|
||||
const createTag = async (page: Page, name: string) => {
|
||||
await page.keyboard.type(name);
|
||||
await page.keyboard.press('ArrowUp');
|
||||
await page.keyboard.press('Enter');
|
||||
};
|
||||
|
||||
export const createPageWithTag = async (
|
||||
page: Page,
|
||||
options: {
|
||||
title: string;
|
||||
tags: string[];
|
||||
}
|
||||
) => {
|
||||
await page.getByTestId('all-pages').click();
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('test page');
|
||||
await page.getByTestId('page-info-collapse').click();
|
||||
await page.locator('[data-testid="property-tags-value"]').click();
|
||||
for (const name of options.tags) {
|
||||
await createTag(page, name);
|
||||
}
|
||||
await page.keyboard.press('Escape');
|
||||
};
|
||||
|
||||
export const changeFilter = async (page: Page, to: string) => {
|
||||
await page.getByTestId('filter-name').click();
|
||||
await page.getByTestId(`filler-tag-${to}`).click();
|
||||
};
|
||||
|
||||
export async function selectTag(page: Page, name: string | RegExp) {
|
||||
await page.getByTestId('filter-arg').click();
|
||||
await page.getByTestId(`multi-select-${name}`).click();
|
||||
|
||||
@@ -30,10 +30,13 @@ export async function waitForEditorLoad(page: Page) {
|
||||
}
|
||||
|
||||
export async function waitForAllPagesLoad(page: Page) {
|
||||
// if filters tag is rendered, we believe all_pages is ready
|
||||
await page.waitForSelector('[data-testid="create-first-filter"]', {
|
||||
timeout: 20000,
|
||||
});
|
||||
// if page-list-header-selection-checkbox is rendered, we believe all_pages is ready
|
||||
await page.waitForSelector(
|
||||
'[data-testid="page-list-header-selection-checkbox"]',
|
||||
{
|
||||
timeout: 20000,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function clickNewPageButton(page: Page, title?: string) {
|
||||
|
||||
Reference in New Issue
Block a user