-
Notifications
You must be signed in to change notification settings - Fork 5.2k
feat: add rich text description to modules #9502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Syed-Ali-Abbas-Zaidi
wants to merge
2
commits into
makeplane:preview
Choose a base branch
from
Syed-Ali-Abbas-Zaidi:feat/git-280-module-rich-description
base: preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
apps/web/core/components/modules/description-editor.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| * See the LICENSE file for details. | ||
| */ | ||
|
|
||
| import { observer } from "mobx-react"; | ||
| import type { Control } from "react-hook-form"; | ||
| import { Controller } from "react-hook-form"; | ||
| // plane imports | ||
| import { useTranslation } from "@plane/i18n"; | ||
| import type { IModule } from "@plane/types"; | ||
| import { EFileAssetType } from "@plane/types"; | ||
| import { getDescriptionPlaceholderI18n } from "@plane/utils"; | ||
| // components | ||
| import { RichTextEditor } from "@/components/editor/rich-text"; | ||
| // hooks | ||
| import { useEditorAsset } from "@/hooks/store/use-editor-asset"; | ||
| import { useWorkspace } from "@/hooks/store/use-workspace"; | ||
| // services | ||
| import { WorkspaceService } from "@/services/workspace.service"; | ||
|
|
||
| const workspaceService = new WorkspaceService(); | ||
|
|
||
| type Props = { | ||
| control: Control<IModule>; | ||
| initialValue: string; | ||
| moduleId: string | undefined; | ||
| projectId: string; | ||
| tabIndex?: number; | ||
| workspaceSlug: string; | ||
| }; | ||
|
|
||
| export const ModuleDescriptionEditor = observer(function ModuleDescriptionEditor(props: Props) { | ||
| const { control, initialValue, moduleId, projectId, tabIndex, workspaceSlug } = props; | ||
| // store hooks | ||
| const { getWorkspaceBySlug } = useWorkspace(); | ||
| const { uploadEditorAsset, duplicateEditorAsset } = useEditorAsset(); | ||
| // i18n | ||
| const { t } = useTranslation(); | ||
| // derived values | ||
| const workspaceId = getWorkspaceBySlug(workspaceSlug)?.id; | ||
|
|
||
| if (!workspaceId) return null; | ||
|
|
||
| return ( | ||
| <Controller | ||
| name="description_html" | ||
| control={control} | ||
| render={({ field: { onChange } }) => ( | ||
| <RichTextEditor | ||
| key={moduleId} | ||
| editable | ||
| id="module-modal-editor" | ||
| initialValue={initialValue} | ||
| workspaceSlug={workspaceSlug} | ||
| workspaceId={workspaceId} | ||
| projectId={projectId} | ||
| onChange={(_description, description_html) => onChange(description_html)} | ||
| tabIndex={tabIndex} | ||
| placeholder={(isFocused, description) => t(getDescriptionPlaceholderI18n(isFocused, description))} | ||
| searchMentionCallback={async (payload) => | ||
| await workspaceService.searchEntity(workspaceSlug, { | ||
| ...payload, | ||
| project_id: projectId, | ||
| }) | ||
| } | ||
| containerClassName="pt-3 min-h-[120px] border-[0.5px] border-subtle-1 rounded-lg" | ||
| uploadFile={async (blockId, file) => { | ||
| try { | ||
| const { asset_id } = await uploadEditorAsset({ | ||
| blockId, | ||
| data: { | ||
| entity_identifier: moduleId ?? "", | ||
| entity_type: EFileAssetType.MODULE_DESCRIPTION, | ||
| }, | ||
| file, | ||
| projectId, | ||
| workspaceSlug, | ||
| }); | ||
| return asset_id; | ||
| } catch (error) { | ||
| console.error("Error in uploading module description asset:", error); | ||
| throw new Error("Asset upload failed. Please try again later.", { cause: error }); | ||
| } | ||
| }} | ||
| duplicateFile={async (assetId: string) => { | ||
| try { | ||
| const { asset_id } = await duplicateEditorAsset({ | ||
| assetId, | ||
| entityId: moduleId, | ||
| entityType: EFileAssetType.MODULE_DESCRIPTION, | ||
| projectId, | ||
| workspaceSlug, | ||
| }); | ||
| return asset_id; | ||
| } catch (error) { | ||
| console.error("Error in duplicating module description asset:", error); | ||
| throw new Error("Asset duplication failed. Please try again later.", { cause: error }); | ||
| } | ||
| }} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| /> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| )} | ||
| /> | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.