Skip to content

Commit

Permalink
fix: rich text issue description editor
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryan610 committed Dec 27, 2024
1 parent 5e98bf6 commit 0e4d713
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IssueWidget } from "@/extensions";
// helpers
import { getEditorClassNames } from "@/helpers/common";
// hooks
import { useCollaborativeEditor } from "@/hooks/use-collaborative-editor";
import { useCollaborativeDocumentEditor } from "@/hooks/use-collaborative-document-editor";
// types
import { EditorRefApi, ICollaborativeDocumentEditor } from "@/types";

Expand Down Expand Up @@ -44,7 +44,7 @@ const CollaborativeDocumentEditor = (props: ICollaborativeDocumentEditor) => {
}

// use document editor
const { editor, hasServerConnectionFailed, hasServerSynced } = useCollaborativeEditor({
const { editor, hasServerConnectionFailed, hasServerSynced } = useCollaborativeDocumentEditor({
disabledExtensions,
editable,
editorClassName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CollaborativeRichTextEditor = (props: ICollaborativeRichTextEditor) => {
const { editor } = useCollaborativeRichTextEditor({
disabledExtensions,
editorClassName,
editable: true,
fileHandler,
forwardedRef,
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { useEditor } from "@/hooks/use-editor";
// plane editor extensions
import { DocumentEditorAdditionalExtensions } from "@/plane-editor/extensions";
// types
import { TCollaborativeEditorProps } from "@/types";
import { TCollaborativeDocumentEditorHookProps } from "@/types";

export const useCollaborativeEditor = (props: TCollaborativeEditorProps) => {
export const useCollaborativeDocumentEditor = (props: TCollaborativeDocumentEditorHookProps) => {
const {
onTransaction,
disabledExtensions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TCollaborativeRichTextEditorHookProps } from "@/types";
export const useCollaborativeRichTextEditor = (props: TCollaborativeRichTextEditorHookProps) => {
const {
disabledExtensions,
editable,
editorClassName,
editorProps = {},
extensions,
Expand Down Expand Up @@ -51,6 +52,7 @@ export const useCollaborativeRichTextEditor = (props: TCollaborativeRichTextEdit
const editor = useEditor({
id,
disabledExtensions,
editable,
editorProps,
editorClassName,
enableHistory: false,
Expand Down
25 changes: 8 additions & 17 deletions packages/editor/src/core/types/collaboration-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ type TCollaborativeEditorHookCommonProps = {
extensions?: Extensions;
handleEditorReady?: (value: boolean) => void;
id: string;
realtimeConfig: TRealtimeConfig;
serverHandler?: TServerHandler;
user: TUserDetails;
};

type TCollaborativeEditorHookProps = TCollaborativeEditorHookCommonProps & {
onTransaction?: () => void;
embedHandler?: TEmbedConfig;
fileHandler: TFileHandler;
forwardedRef?: React.MutableRefObject<EditorRefApi | null>;
Expand All @@ -48,24 +44,19 @@ type TCollaborativeReadOnlyEditorHookProps = TCollaborativeEditorHookCommonProps
mentionHandler: TReadOnlyMentionHandler;
};

export type TCollaborativeRichTextEditorHookProps = TCollaborativeEditorHookProps & {
onChange: (updatedDescription: Uint8Array) => void;
value: Uint8Array;
};

export type TCollaborativeRichTextReadOnlyEditorHookProps = TCollaborativeReadOnlyEditorHookProps & {
value: Uint8Array;
};

export type TCollaborativeDocumentEditorHookProps = TCollaborativeEditorHookProps & {
onTransaction?: () => void;
embedHandler?: TEmbedConfig;
realtimeConfig: TRealtimeConfig;
serverHandler?: TServerHandler;
user: TUserDetails;
};

export type TCollaborativeDocumentReadOnlyEditorHookProps = TCollaborativeReadOnlyEditorHookProps & {
realtimeConfig: TRealtimeConfig;
serverHandler?: TServerHandler;
user: TUserDetails;
export type TCollaborativeRichTextEditorHookProps = TCollaborativeEditorHookProps & {
onChange: (updatedDescription: Uint8Array) => void;
value: Uint8Array;
};

export type TCollaborativeRichTextReadOnlyEditorHookProps = TCollaborativeReadOnlyEditorHookProps & {
value: Uint8Array;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,35 @@ import React, { forwardRef } from "react";
// editor
import { CollaborativeRichTextEditorWithRef, EditorRefApi, ICollaborativeRichTextEditor } from "@plane/editor";
// types
import { IUserLite } from "@plane/types";
import { TSearchEntityRequestPayload, TSearchResponse } from "@plane/types";
// components
import { EditorMentionsRoot } from "@/components/editor";
// helpers
import { cn } from "@/helpers/common.helper";
import { getEditorFileHandlers } from "@/helpers/editor.helper";
// hooks
import { useMember, useMention, useUser } from "@/hooks/store";
import { useEditorMention } from "@/hooks/use-editor-mention";
// plane web hooks
import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging";
import { useFileSize } from "@/plane-web/hooks/use-file-size";

interface Props extends Omit<ICollaborativeRichTextEditor, "disabledExtensions" | "fileHandler" | "mentionHandler"> {
key: string;
projectId: string;
searchMentionCallback: (payload: TSearchEntityRequestPayload) => Promise<TSearchResponse>;
uploadFile: (file: File) => Promise<string>;
workspaceId: string;
workspaceSlug: string;
}

export const CollaborativeRichTextEditor = forwardRef<EditorRefApi, Props>((props, ref) => {
const { containerClassName, workspaceSlug, workspaceId, projectId, uploadFile, ...rest } = props;
// store hooks
const { data: currentUser } = useUser();
const {
getUserDetails,
project: { getProjectMemberIds },
} = useMember();
const { containerClassName, workspaceSlug, workspaceId, projectId, searchMentionCallback, uploadFile, ...rest } =
props;
// editor flaggings
const { richTextEditor: disabledExtensions } = useEditorFlagging(workspaceSlug?.toString());
// derived values
const projectMemberIds = getProjectMemberIds(projectId);
const projectMemberDetails = projectMemberIds?.map((id) => getUserDetails(id) as IUserLite);
// use-mention
const { mentionHighlights, mentionSuggestions } = useMention({
workspaceSlug,
projectId,
members: projectMemberDetails,
user: currentUser,
// use editor mention
const { fetchMentions } = useEditorMention({
searchEntity: async (payload) => await searchMentionCallback(payload),
});
// file size
const { maxFileSize } = useFileSize();
Expand All @@ -55,8 +47,12 @@ export const CollaborativeRichTextEditor = forwardRef<EditorRefApi, Props>((prop
workspaceSlug,
})}
mentionHandler={{
highlights: mentionHighlights,
suggestions: mentionSuggestions,
searchCallback: async (query) => {
const res = await fetchMentions(query);
if (!res) throw new Error("Failed in fetching mentions");
return res;
},
renderComponent: (props) => <EditorMentionsRoot {...props} />,
}}
{...rest}
containerClassName={cn("relative pl-3", containerClassName)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {
} from "@plane/editor";
// plane ui
import { Loader } from "@plane/ui";
// components
import { EditorMentionsRoot } from "@/components/editor";
// helpers
import { cn } from "@/helpers/common.helper";
import { getReadOnlyEditorFileHandlers } from "@/helpers/editor.helper";
// hooks
import { useMention } from "@/hooks/store";
import { useIssueDescription } from "@/hooks/use-issue-description";
// plane web hooks
import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging";
Expand All @@ -30,8 +31,6 @@ export const CollaborativeRichTextReadOnlyEditor = React.forwardRef<
EditorReadOnlyRefApi,
RichTextReadOnlyEditorWrapperProps
>(({ descriptionBinary: savedDescriptionBinary, descriptionHTML, projectId, workspaceSlug, ...props }, ref) => {
// store hooks
const { mentionHighlights } = useMention({});
// editor flaggings
const { richTextEditor: disabledExtensions } = useEditorFlagging(workspaceSlug?.toString());

Expand All @@ -57,7 +56,7 @@ export const CollaborativeRichTextReadOnlyEditor = React.forwardRef<
workspaceSlug,
})}
mentionHandler={{
highlights: mentionHighlights,
renderComponent: (props) => <EditorMentionsRoot {...props} />,
}}
{...props}
// overriding the containerClassName to add relative class passed
Expand Down
9 changes: 9 additions & 0 deletions web/core/components/issues/description-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import { getDescriptionPlaceholder } from "@/helpers/issue.helper";
// hooks
import { useWorkspace } from "@/hooks/store";
import { useIssueDescription } from "@/hooks/use-issue-description";
// plane web services
import { WorkspaceService } from "@/plane-web/services";
// services
import { FileService } from "@/services/file.service";
const workspaceService = new WorkspaceService();
const fileService = new FileService();

export type IssueDescriptionInputProps = {
Expand Down Expand Up @@ -109,6 +112,12 @@ export const IssueDescriptionInput: FC<IssueDescriptionInputProps> = observer((p
placeholder={placeholder ? placeholder : (isFocused, value) => getDescriptionPlaceholder(isFocused, value)}
projectId={projectId}
ref={editorRef}
searchMentionCallback={async (payload) =>
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
...payload,
project_id: projectId?.toString() ?? "",
})
}
uploadFile={async (file) => {
try {
const { asset_id } = await fileService.uploadProjectAsset(
Expand Down

0 comments on commit 0e4d713

Please sign in to comment.