mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 14:28:51 +08:00
feat(editor): add date grouping configurations (#12679)
https://github.com/user-attachments/assets/d5578060-2c8c-47a5-ba65-ef2e9430518b This PR adds the ability to group-by date with configuration which an example is shown in the image below:  <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Date-based grouping modes (relative, day, week Sun/Mon, month, year), a date group renderer, and quick lookup for group-by configs by name. * **Improvements** * Enhanced group settings: date sub‑modes, week‑start, per‑group visibility, Hide All/Show All, date sort order, improved drag/drop and reorder. * Consistent popup placement/middleware, nested popup positioning, per‑item close-on-select, and enforced minimum menu heights. * UI: empty groups now display "No <property>"; views defensively handle null/hidden groups. * **Tests** * Added unit tests for date-key sorting and comparison. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Norkz <richardlora557@gmail.com> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { compareDateKeys } from '../core/group-by/compare-date-keys.js';
|
||||
|
||||
describe('compareDateKeys', () => {
|
||||
it('sorts relative keys ascending', () => {
|
||||
const cmp = compareDateKeys('date-relative', true);
|
||||
const keys = ['today', 'last7', 'yesterday', 'last30'];
|
||||
const sorted = [...keys].sort(cmp);
|
||||
expect(sorted).toEqual(['last30', 'last7', 'yesterday', 'today']);
|
||||
});
|
||||
|
||||
it('sorts relative keys descending', () => {
|
||||
const cmp = compareDateKeys('date-relative', false);
|
||||
const keys = ['today', 'last7', 'yesterday', 'last30'];
|
||||
const sorted = [...keys].sort(cmp);
|
||||
expect(sorted).toEqual(['today', 'yesterday', 'last7', 'last30']);
|
||||
});
|
||||
|
||||
it('sorts numeric keys correctly', () => {
|
||||
const asc = compareDateKeys('date-day', true);
|
||||
const desc = compareDateKeys('date-day', false);
|
||||
const keys = ['3', '1', '2'];
|
||||
expect([...keys].sort(asc)).toEqual(['1', '2', '3']);
|
||||
expect([...keys].sort(desc)).toEqual(['3', '2', '1']);
|
||||
});
|
||||
|
||||
it('handles mixed relative and numeric keys', () => {
|
||||
const cmp = compareDateKeys('date-relative', true);
|
||||
const keys = ['today', '1', 'yesterday', '2'];
|
||||
const sorted = [...keys].sort(cmp);
|
||||
expect(sorted[0]).toBe('1');
|
||||
expect(sorted[sorted.length - 1]).toBe('today');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user