mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
d511799f31
* feat: created custom mention component * feat: added mention suggestions and suggestion highlights * feat: created mention suggestion list for displaying mention suggestions * feat: created custom mention text component, for handling click event * feat: exposed mention component * feat: integrated and exposed `mentions` componenet with `editor-core` * feat: integrated mentions extension with the core editor package * feat: exposed suggestion types from mentions * feat: added `mention-suggestion` parameters in `r-t-e` and `l-t-e` * feat: added `IssueMention` model in apiserver models * chore: updated activities background job and added bs4 in requirements * feat: added mention removal logic in issue_activity * chore: exposed mention types from `r-t-e` and `l-t-e` * feat: integrated mentions in side peek view description form * feat: added mentions in issue modal form * feat: created custom react-hook for editor suggestions * feat: integrated mention suggestions block in RichTextEditor * feat: added `mentions` integration in `lite-text-editor` instances * fix: tailwind loading nodemodules from packages * feat: added styles for the mention suggestion list * fix: update module import to resolve build failure * feat: added mentions as an issue filter * feat: added UI Changes to Implement `mention` filters * feat: added `mentions` as a filter option in the header * feat: added mentions in the filter list options * feat: added mentions in default display filter options * feat: added filters in applied and issue params in store * feat: modified types for adding mentions as a filter option * feat: modified `notification-card` to display message when it exists in object * feat: rewrote user mention management upon the changes made in develop * chore: merged debounce PR with the current PR for tracing changes * fix: mentions_filters updated with the new setup * feat: updated requirements for bs4 * feat: modified `mentions-filter` to remove many to many dependency * feat: implemented list manipulation instead of for loop * feat: added readonly functionality in `read-only` editor core * feat: added UI Changes for read-only mode * feat: added mentions store in web Root Store * chore: renamed `use-editor-suggestions` hook * feat: UI Improvements for conditional highlights w.r.t readonly in mentionNode * fix: removed mentions from `filter_set` parameters * fix: minor merge fixes * fix: package lock updates --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
113 lines
3.4 KiB
TypeScript
113 lines
3.4 KiB
TypeScript
import React from "react";
|
|
import { useRouter } from "next/router";
|
|
import { useForm, Controller } from "react-hook-form";
|
|
|
|
// services
|
|
import { FileService } from "services/file.service";
|
|
// components
|
|
import { LiteTextEditorWithRef } from "@plane/lite-text-editor";
|
|
// ui
|
|
import { Button } from "@plane/ui";
|
|
import { Globe2, Lock } from "lucide-react";
|
|
|
|
// types
|
|
import type { IIssueComment } from "types";
|
|
import useEditorSuggestions from "hooks/use-editor-suggestions";
|
|
|
|
const defaultValues: Partial<IIssueComment> = {
|
|
access: "INTERNAL",
|
|
comment_html: "",
|
|
};
|
|
|
|
type Props = {
|
|
disabled?: boolean;
|
|
onSubmit: (data: IIssueComment) => Promise<void>;
|
|
showAccessSpecifier?: boolean;
|
|
};
|
|
|
|
type commentAccessType = {
|
|
icon: any;
|
|
key: string;
|
|
label: "Private" | "Public";
|
|
};
|
|
const commentAccess: commentAccessType[] = [
|
|
{
|
|
icon: Lock,
|
|
key: "INTERNAL",
|
|
label: "Private",
|
|
},
|
|
{
|
|
icon: Globe2,
|
|
key: "EXTERNAL",
|
|
label: "Public",
|
|
},
|
|
];
|
|
|
|
// services
|
|
const fileService = new FileService();
|
|
|
|
export const AddComment: React.FC<Props> = ({ disabled = false, onSubmit, showAccessSpecifier = false }) => {
|
|
const editorRef = React.useRef<any>(null);
|
|
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
const editorSuggestions = useEditorSuggestions(workspaceSlug as string | undefined, projectId as string | undefined)
|
|
|
|
const {
|
|
control,
|
|
formState: { isSubmitting },
|
|
handleSubmit,
|
|
reset,
|
|
} = useForm<IIssueComment>({ defaultValues });
|
|
|
|
const handleAddComment = async (formData: IIssueComment) => {
|
|
if (!formData.comment_html || isSubmitting) return;
|
|
|
|
await onSubmit(formData).then(() => {
|
|
reset(defaultValues);
|
|
editorRef.current?.clearEditor();
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<form onSubmit={handleSubmit(handleAddComment)}>
|
|
<div>
|
|
<div className="relative">
|
|
<Controller
|
|
name="access"
|
|
control={control}
|
|
render={({ field: { onChange: onAccessChange, value: accessValue } }) => (
|
|
<Controller
|
|
name="comment_html"
|
|
control={control}
|
|
render={({ field: { onChange: onCommentChange, value: commentValue } }) => (
|
|
<LiteTextEditorWithRef
|
|
onEnterKeyPress={handleSubmit(handleAddComment)}
|
|
uploadFile={fileService.getUploadFileFunction(workspaceSlug as string)}
|
|
deleteFile={fileService.deleteImage}
|
|
ref={editorRef}
|
|
value={!commentValue || commentValue === "" ? "<p></p>" : commentValue}
|
|
customClassName="p-3 min-h-[100px] shadow-sm"
|
|
debouncedUpdatesEnabled={false}
|
|
onChange={(comment_json: Object, comment_html: string) => onCommentChange(comment_html)}
|
|
commentAccessSpecifier={{ accessValue, onAccessChange, showAccessSpecifier, commentAccess }}
|
|
mentionSuggestions={editorSuggestions.mentionSuggestions}
|
|
mentionHighlights={editorSuggestions.mentionHighlights}
|
|
/>
|
|
)}
|
|
/>
|
|
)}
|
|
/>
|
|
</div>
|
|
|
|
<Button variant="neutral-primary" type="submit" disabled={isSubmitting || disabled}>
|
|
{isSubmitting ? "Adding..." : "Comment"}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
);
|
|
};
|