mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 18:46:19 +08:00
fix(core): dedicated link config for comments (#13003)
#### PR Dependency Tree * **PR #13003** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced enhanced member mention functionality in the comment editor, including improved search, highlighting, and avatar display for mentioning users. * **Refactor** * Simplified configuration options for linked widgets and menu groups, removing the ability to selectively include menu groups. * Updated internal logic to streamline menu group handling and improve performance during member searches. * **Bug Fixes** * Prevented unnecessary member search calls on empty queries for better efficiency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -62,13 +62,6 @@ const RESERVED_ITEM_KEYS = {
|
||||
datePicker: 'date-picker',
|
||||
};
|
||||
|
||||
export enum LinkedMenuGroupType {
|
||||
LinkToDoc = 'link-to-doc',
|
||||
Mention = 'mention',
|
||||
Journal = 'journal',
|
||||
NewDoc = 'new-doc',
|
||||
}
|
||||
|
||||
export class AtMenuConfigService extends Service {
|
||||
constructor(
|
||||
private readonly journalService: JournalService,
|
||||
@@ -86,11 +79,9 @@ export class AtMenuConfigService extends Service {
|
||||
|
||||
// todo(@peng17): maybe refactor the config using entity, so that each config
|
||||
// can be reactive to the query, instead of recreating the whole config?
|
||||
getConfig(
|
||||
includedGroups?: LinkedMenuGroupType[]
|
||||
): Partial<LinkedWidgetConfig> {
|
||||
getConfig(): Partial<LinkedWidgetConfig> {
|
||||
return {
|
||||
getMenus: this.getMenusFn(includedGroups),
|
||||
getMenus: this.getMenusFn(),
|
||||
mobile: this.getMobileConfig(),
|
||||
autoFocusedItemKey: this.autoFocusedItemKey,
|
||||
};
|
||||
@@ -111,14 +102,14 @@ export class AtMenuConfigService extends Service {
|
||||
return null;
|
||||
}
|
||||
|
||||
const linkToDocGroup = menus.at(0);
|
||||
const memberGroup = menus.at(1);
|
||||
const linkToDocGroup = menus[0];
|
||||
const memberGroup = menus[1];
|
||||
|
||||
if (memberGroup && resolveSignal(memberGroup.items).length > 1) {
|
||||
if (resolveSignal(memberGroup.items).length > 1) {
|
||||
return resolveSignal(memberGroup.items)[0]?.key;
|
||||
}
|
||||
|
||||
if (linkToDocGroup && resolveSignal(linkToDocGroup.items).length > 0) {
|
||||
if (resolveSignal(linkToDocGroup.items).length > 0) {
|
||||
return resolveSignal(linkToDocGroup.items)[0]?.key;
|
||||
}
|
||||
|
||||
@@ -644,7 +635,9 @@ export class AtMenuConfigService extends Service {
|
||||
return query.length > 0 && !loading && members.length === 0;
|
||||
});
|
||||
|
||||
this.memberSearchService.search(query);
|
||||
if (query.length > 0) {
|
||||
this.memberSearchService.search(query);
|
||||
}
|
||||
|
||||
return {
|
||||
name: I18n.t('com.affine.editor.at-menu.mention-members'),
|
||||
@@ -662,28 +655,13 @@ export class AtMenuConfigService extends Service {
|
||||
};
|
||||
}
|
||||
|
||||
private getMenusFn(
|
||||
includedGroups: LinkedMenuGroupType[] = [
|
||||
LinkedMenuGroupType.LinkToDoc,
|
||||
LinkedMenuGroupType.Mention,
|
||||
LinkedMenuGroupType.Journal,
|
||||
LinkedMenuGroupType.NewDoc,
|
||||
]
|
||||
): LinkedWidgetConfig['getMenus'] {
|
||||
private getMenusFn(): LinkedWidgetConfig['getMenus'] {
|
||||
return (query, close, editorHost, inlineEditor, abortSignal) => {
|
||||
return [
|
||||
...(includedGroups?.includes(LinkedMenuGroupType.LinkToDoc)
|
||||
? [this.linkToDocGroup(query, close, inlineEditor, abortSignal)]
|
||||
: []),
|
||||
...(includedGroups?.includes(LinkedMenuGroupType.Mention)
|
||||
? [this.memberGroup(query, close, inlineEditor, abortSignal)]
|
||||
: []),
|
||||
...(includedGroups?.includes(LinkedMenuGroupType.Journal)
|
||||
? [this.journalGroup(query, close, inlineEditor)]
|
||||
: []),
|
||||
...(includedGroups?.includes(LinkedMenuGroupType.NewDoc)
|
||||
? [this.newDocMenuGroup(query, close, editorHost, inlineEditor)]
|
||||
: []),
|
||||
this.linkToDocGroup(query, close, inlineEditor, abortSignal),
|
||||
this.memberGroup(query, close, inlineEditor, abortSignal),
|
||||
this.journalGroup(query, close, inlineEditor),
|
||||
this.newDocMenuGroup(query, close, editorHost, inlineEditor),
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user