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:
@@ -11,6 +11,15 @@ const DefaultDisplayPreference: ExplorerDisplayPreference = {
|
|||||||
'system:createdBy',
|
'system:createdBy',
|
||||||
'system:tags',
|
'system:tags',
|
||||||
],
|
],
|
||||||
|
orderBy: {
|
||||||
|
type: 'system',
|
||||||
|
key: 'updatedAt',
|
||||||
|
desc: true,
|
||||||
|
},
|
||||||
|
groupBy: {
|
||||||
|
type: 'system',
|
||||||
|
key: 'updatedAt',
|
||||||
|
},
|
||||||
showDocIcon: true,
|
showDocIcon: true,
|
||||||
showDocPreview: true,
|
showDocPreview: true,
|
||||||
quickFavorite: true,
|
quickFavorite: true,
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ export const SelectPage = memo(function SelectPage({
|
|||||||
quickFavorite: true,
|
quickFavorite: true,
|
||||||
showMoreOperation: false,
|
showMoreOperation: false,
|
||||||
showDragHandle: false,
|
showDragHandle: false,
|
||||||
|
groupBy: undefined,
|
||||||
|
orderBy: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,6 +134,11 @@ export const SelectPage = memo(function SelectPage({
|
|||||||
value: 'false',
|
value: 'false',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
orderBy: {
|
||||||
|
type: 'system',
|
||||||
|
key: 'updatedAt',
|
||||||
|
desc: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.subscribe(result => {
|
.subscribe(result => {
|
||||||
docExplorerContextValue.groups$.next(result.groups);
|
docExplorerContextValue.groups$.next(result.groups);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const toRelativeDate = (time: string | number) => {
|
|||||||
return i18nTime(time, {
|
return i18nTime(time, {
|
||||||
relative: {
|
relative: {
|
||||||
max: [1, 'day'],
|
max: [1, 'day'],
|
||||||
|
accuracy: 'day',
|
||||||
},
|
},
|
||||||
absolute: {
|
absolute: {
|
||||||
accuracy: 'day',
|
accuracy: 'day',
|
||||||
@@ -54,12 +55,39 @@ export const UpdatedAtValue = MetaDateValueFactory({
|
|||||||
type: 'updatedDate',
|
type: 'updatedDate',
|
||||||
});
|
});
|
||||||
|
|
||||||
export const CreatedAtGroupHeader = (props: GroupHeaderProps) => {
|
export const CreatedAtGroupHeader = ({
|
||||||
return <PlainTextDocGroupHeader {...props} />;
|
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) => {
|
export const UpdatedAtGroupHeader = ({
|
||||||
return <PlainTextDocGroupHeader {...props} />;
|
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 }) => {
|
export const CreateAtDocListProperty = ({ doc }: { doc: DocRecord }) => {
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ export const RulesMode = ({
|
|||||||
showDragHandle: false,
|
showDragHandle: false,
|
||||||
showMoreOperation: false,
|
showMoreOperation: false,
|
||||||
quickFavorite: true,
|
quickFavorite: true,
|
||||||
|
groupBy: undefined,
|
||||||
|
orderBy: undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -76,6 +78,11 @@ export const RulesMode = ({
|
|||||||
value: 'false',
|
value: 'false',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
orderBy: {
|
||||||
|
type: 'system',
|
||||||
|
key: 'updatedAt',
|
||||||
|
desc: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.subscribe(rules => {
|
.subscribe(rules => {
|
||||||
setRulesPageIds(rules.groups.flatMap(group => group.items));
|
setRulesPageIds(rules.groups.flatMap(group => group.items));
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ export const TrashPage = () => {
|
|||||||
quickFavorite: false,
|
quickFavorite: false,
|
||||||
quickDeletePermanently: true,
|
quickDeletePermanently: true,
|
||||||
quickRestore: true,
|
quickRestore: true,
|
||||||
|
groupBy: undefined,
|
||||||
|
orderBy: undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ const AllDocs = () => {
|
|||||||
displayProperties: ['createdAt', 'updatedAt', 'tags'],
|
displayProperties: ['createdAt', 'updatedAt', 'tags'],
|
||||||
view: 'masonry',
|
view: 'masonry',
|
||||||
showDragHandle: false,
|
showDragHandle: false,
|
||||||
|
groupBy: undefined,
|
||||||
|
orderBy: undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const collectionRulesService = useService(CollectionRulesService);
|
const collectionRulesService = useService(CollectionRulesService);
|
||||||
@@ -43,8 +45,8 @@ const AllDocs = () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
orderBy: {
|
orderBy: {
|
||||||
type: 'property',
|
type: 'system',
|
||||||
key: 'createdAt',
|
key: 'updatedAt',
|
||||||
desc: true,
|
desc: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ const CollectionDocs = ({ collection }: { collection: Collection }) => {
|
|||||||
displayProperties: ['createdAt', 'updatedAt', 'tags'],
|
displayProperties: ['createdAt', 'updatedAt', 'tags'],
|
||||||
view: 'masonry',
|
view: 'masonry',
|
||||||
showDragHandle: false,
|
showDragHandle: false,
|
||||||
|
groupBy: undefined,
|
||||||
|
orderBy: undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const groups = useLiveData(explorerContextValue.groups$);
|
const groups = useLiveData(explorerContextValue.groups$);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ const TagDocs = ({ tag }: { tag: Tag }) => {
|
|||||||
displayProperties: ['createdAt', 'updatedAt', 'tags'],
|
displayProperties: ['createdAt', 'updatedAt', 'tags'],
|
||||||
view: 'masonry',
|
view: 'masonry',
|
||||||
showDragHandle: false,
|
showDragHandle: false,
|
||||||
|
groupBy: undefined,
|
||||||
|
orderBy: undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const collectionRulesService = useService(CollectionRulesService);
|
const collectionRulesService = useService(CollectionRulesService);
|
||||||
@@ -50,8 +52,8 @@ const TagDocs = ({ tag }: { tag: Tag }) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
orderBy: {
|
orderBy: {
|
||||||
type: 'property',
|
type: 'system',
|
||||||
key: 'createdAt',
|
key: 'updatedAt',
|
||||||
desc: true,
|
desc: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ export class DocsService extends Service {
|
|||||||
middleware.afterCreate?.(docRecord, options);
|
middleware.afterCreate?.(docRecord, options);
|
||||||
}
|
}
|
||||||
docRecord.setCreatedAt(Date.now());
|
docRecord.setCreatedAt(Date.now());
|
||||||
|
docRecord.setUpdatedAt(Date.now());
|
||||||
this.eventBus.emit(DocCreated, {
|
this.eventBus.emit(DocCreated, {
|
||||||
doc: docRecord,
|
doc: docRecord,
|
||||||
docCreateOptions: options,
|
docCreateOptions: options,
|
||||||
|
|||||||
@@ -7144,6 +7144,10 @@ export function useAFFiNEI18N(): {
|
|||||||
* `Unchecked`
|
* `Unchecked`
|
||||||
*/
|
*/
|
||||||
["com.affine.all-docs.group.is-not-checked"](): string;
|
["com.affine.all-docs.group.is-not-checked"](): string;
|
||||||
|
/**
|
||||||
|
* `Never updated`
|
||||||
|
*/
|
||||||
|
["com.affine.all-docs.group.updated-at.never-updated"](): string;
|
||||||
/**
|
/**
|
||||||
* `core`
|
* `core`
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1782,6 +1782,7 @@
|
|||||||
"com.affine.all-docs.group.is-not-journal": "Not Journal",
|
"com.affine.all-docs.group.is-not-journal": "Not Journal",
|
||||||
"com.affine.all-docs.group.is-checked": "Checked",
|
"com.affine.all-docs.group.is-checked": "Checked",
|
||||||
"com.affine.all-docs.group.is-not-checked": "Unchecked",
|
"com.affine.all-docs.group.is-not-checked": "Unchecked",
|
||||||
|
"com.affine.all-docs.group.updated-at.never-updated": "Never updated",
|
||||||
"core": "core",
|
"core": "core",
|
||||||
"dark": "Dark",
|
"dark": "Dark",
|
||||||
"invited you to join": "invited you to join",
|
"invited you to join": "invited you to join",
|
||||||
|
|||||||
Reference in New Issue
Block a user