feat(core): add default group and order (#12526)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added default sorting and grouping by "Last Updated" for document views.
  - Introduced clearer group headers for documents grouped by creation or update date, displaying relative dates or appropriate fallback text.

- **Improvements**
  - Enhanced date grouping headers with capitalized, user-friendly text and improved handling of missing dates.
  - Added a new localization for "Never updated" to improve clarity in document groupings.
  - Initialized document update timestamps at creation to improve date accuracy.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
EYHN
2025-05-27 04:08:56 +00:00
parent ed8e50bca6
commit 3676f3b769
11 changed files with 73 additions and 8 deletions

View File

@@ -11,6 +11,15 @@ const DefaultDisplayPreference: ExplorerDisplayPreference = {
'system:createdBy',
'system:tags',
],
orderBy: {
type: 'system',
key: 'updatedAt',
desc: true,
},
groupBy: {
type: 'system',
key: 'updatedAt',
},
showDocIcon: true,
showDocPreview: true,
quickFavorite: true,

View File

@@ -49,6 +49,8 @@ export const SelectPage = memo(function SelectPage({
quickFavorite: true,
showMoreOperation: false,
showDragHandle: false,
groupBy: undefined,
orderBy: undefined,
});
});
@@ -132,6 +134,11 @@ export const SelectPage = memo(function SelectPage({
value: 'false',
},
],
orderBy: {
type: 'system',
key: 'updatedAt',
desc: true,
},
})
.subscribe(result => {
docExplorerContextValue.groups$.next(result.groups);

View File

@@ -11,6 +11,7 @@ const toRelativeDate = (time: string | number) => {
return i18nTime(time, {
relative: {
max: [1, 'day'],
accuracy: 'day',
},
absolute: {
accuracy: 'day',
@@ -54,12 +55,39 @@ export const UpdatedAtValue = MetaDateValueFactory({
type: 'updatedDate',
});
export const CreatedAtGroupHeader = (props: GroupHeaderProps) => {
return <PlainTextDocGroupHeader {...props} />;
export const CreatedAtGroupHeader = ({
groupId,
docCount,
}: GroupHeaderProps) => {
const date = groupId ? toRelativeDate(groupId) : 'No Date';
return (
<PlainTextDocGroupHeader
style={{ textTransform: 'capitalize' }}
groupId={groupId}
docCount={docCount}
>
{date}
</PlainTextDocGroupHeader>
);
};
export const UpdatedAtGroupHeader = (props: GroupHeaderProps) => {
return <PlainTextDocGroupHeader {...props} />;
export const UpdatedAtGroupHeader = ({
groupId,
docCount,
}: GroupHeaderProps) => {
const t = useI18n();
const date = groupId
? toRelativeDate(groupId)
: t['com.affine.all-docs.group.updated-at.never-updated']();
return (
<PlainTextDocGroupHeader
style={{ textTransform: 'capitalize' }}
groupId={groupId}
docCount={docCount}
>
{date}
</PlainTextDocGroupHeader>
);
};
export const CreateAtDocListProperty = ({ doc }: { doc: DocRecord }) => {

View File

@@ -55,6 +55,8 @@ export const RulesMode = ({
showDragHandle: false,
showMoreOperation: false,
quickFavorite: true,
groupBy: undefined,
orderBy: undefined,
})
);
@@ -76,6 +78,11 @@ export const RulesMode = ({
value: 'false',
},
],
orderBy: {
type: 'system',
key: 'updatedAt',
desc: true,
},
})
.subscribe(rules => {
setRulesPageIds(rules.groups.flatMap(group => group.items));

View File

@@ -60,6 +60,8 @@ export const TrashPage = () => {
quickFavorite: false,
quickDeletePermanently: true,
quickRestore: true,
groupBy: undefined,
orderBy: undefined,
})
);

View File

@@ -19,6 +19,8 @@ const AllDocs = () => {
displayProperties: ['createdAt', 'updatedAt', 'tags'],
view: 'masonry',
showDragHandle: false,
groupBy: undefined,
orderBy: undefined,
})
);
const collectionRulesService = useService(CollectionRulesService);
@@ -43,8 +45,8 @@ const AllDocs = () => {
},
],
orderBy: {
type: 'property',
key: 'createdAt',
type: 'system',
key: 'updatedAt',
desc: true,
},
})

View File

@@ -36,6 +36,8 @@ const CollectionDocs = ({ collection }: { collection: Collection }) => {
displayProperties: ['createdAt', 'updatedAt', 'tags'],
view: 'masonry',
showDragHandle: false,
groupBy: undefined,
orderBy: undefined,
})
);
const groups = useLiveData(explorerContextValue.groups$);

View File

@@ -20,6 +20,8 @@ const TagDocs = ({ tag }: { tag: Tag }) => {
displayProperties: ['createdAt', 'updatedAt', 'tags'],
view: 'masonry',
showDragHandle: false,
groupBy: undefined,
orderBy: undefined,
})
);
const collectionRulesService = useService(CollectionRulesService);
@@ -50,8 +52,8 @@ const TagDocs = ({ tag }: { tag: Tag }) => {
},
],
orderBy: {
type: 'property',
key: 'createdAt',
type: 'system',
key: 'updatedAt',
desc: true,
},
})

View File

@@ -164,6 +164,7 @@ export class DocsService extends Service {
middleware.afterCreate?.(docRecord, options);
}
docRecord.setCreatedAt(Date.now());
docRecord.setUpdatedAt(Date.now());
this.eventBus.emit(DocCreated, {
doc: docRecord,
docCreateOptions: options,