[PE-93] refactor: editor mentions extension (#6178)
* refactor: editor mentions * fix: build errors * fix: build errors * chore: add cycle status to search endpoint response * fix: build errors * fix: dynamic mention content in markdown * chore: update entity search endpoint * style: user mention popover * chore: edition specific mention content handler * chore: show deactivated user for old mentions * chore: update search entity keys * refactor: use editor mention hook
This commit is contained in:
parent
c10b875e2a
commit
119d343d5f
78 changed files with 1491 additions and 992 deletions
76
web/core/hooks/use-editor-mention.tsx
Normal file
76
web/core/hooks/use-editor-mention.tsx
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import { useCallback } from "react";
|
||||
// plane editor
|
||||
import { TMentionSection, TMentionSuggestion } from "@plane/editor";
|
||||
// plane types
|
||||
import { TSearchEntities, TSearchEntityRequestPayload, TSearchResponse, TUserSearchResponse } from "@plane/types";
|
||||
// plane ui
|
||||
import { Avatar } from "@plane/ui";
|
||||
// helpers
|
||||
import { getFileURL } from "@/helpers/file.helper";
|
||||
// plane web constants
|
||||
import { EDITOR_MENTION_TYPES } from "@/plane-web/constants/editor";
|
||||
// plane web hooks
|
||||
import { useAdditionalEditorMention } from "@/plane-web/hooks/use-additional-editor-mention";
|
||||
|
||||
type TArgs = {
|
||||
searchEntity: (payload: TSearchEntityRequestPayload) => Promise<TSearchResponse>;
|
||||
};
|
||||
|
||||
export const useEditorMention = (args: TArgs) => {
|
||||
const { searchEntity } = args;
|
||||
// additional mentions
|
||||
const { updateAdditionalSections } = useAdditionalEditorMention();
|
||||
// fetch mentions handler
|
||||
const fetchMentions = useCallback(
|
||||
async (query: string): Promise<TMentionSection[]> => {
|
||||
try {
|
||||
const res = await searchEntity({
|
||||
count: 5,
|
||||
query_type: EDITOR_MENTION_TYPES,
|
||||
query,
|
||||
});
|
||||
const suggestionSections: TMentionSection[] = [];
|
||||
if (!res) {
|
||||
throw new Error("No response found");
|
||||
}
|
||||
Object.keys(res).map((key) => {
|
||||
const responseKey = key as TSearchEntities;
|
||||
const response = res[responseKey];
|
||||
if (responseKey === "user_mention" && response && response.length > 0) {
|
||||
const items: TMentionSuggestion[] = (response as TUserSearchResponse[]).map((user) => ({
|
||||
icon: (
|
||||
<Avatar
|
||||
className="flex-shrink-0"
|
||||
src={getFileURL(user.member__avatar_url)}
|
||||
name={user.member__display_name}
|
||||
/>
|
||||
),
|
||||
id: user.member__id,
|
||||
entity_identifier: user.member__id,
|
||||
entity_name: "user_mention",
|
||||
title: user.member__display_name,
|
||||
}));
|
||||
suggestionSections.push({
|
||||
key: "users",
|
||||
title: "Users",
|
||||
items,
|
||||
});
|
||||
}
|
||||
});
|
||||
updateAdditionalSections({
|
||||
response: res,
|
||||
sections: suggestionSections,
|
||||
});
|
||||
return suggestionSections;
|
||||
} catch (error) {
|
||||
console.error("Error in fetching mentions for project pages:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
[searchEntity, updateAdditionalSections]
|
||||
);
|
||||
|
||||
return {
|
||||
fetchMentions,
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue