1414 * limitations under the License.
1515 */
1616
17- import { useMemo , useState } from 'react'
17+ import { useEffect , useMemo , useState } from 'react'
1818import MDEditor , { commands , MDEditorProps } from '@uiw/react-md-editor'
1919
20- import { ReactComponent as BoldIcon } from '@Icons/ic-bold.svg'
21- import { ReactComponent as CheckedListIcon } from '@Icons/ic-checked-list.svg'
22- import { ReactComponent as CodeIcon } from '@Icons/ic-code.svg'
23- import { ReactComponent as HeaderIcon } from '@Icons/ic-header.svg'
24- import { ReactComponent as ImageIcon } from '@Icons/ic-image.svg'
25- import { ReactComponent as ItalicIcon } from '@Icons/ic-italic.svg'
26- import { ReactComponent as LinkIcon } from '@Icons/ic-link.svg'
27- import { ReactComponent as OrderedListIcon } from '@Icons/ic-ordered-list.svg'
2820import { ReactComponent as Edit } from '@Icons/ic-pencil.svg'
29- import { ReactComponent as QuoteIcon } from '@Icons/ic-quote.svg'
30- import { ReactComponent as StrikethroughIcon } from '@Icons/ic-strikethrough.svg'
3121import { ReactComponent as UnorderedListIcon } from '@Icons/ic-unordered-list.svg'
3222
3323import {
@@ -41,59 +31,12 @@ import {
4131} from '../../Shared'
4232import Markdown from '../Markdown/MarkDown'
4333import { showError , Tooltip } from '..'
44- import { DESCRIPTION_EMPTY_ERROR_MSG , DESCRIPTION_UNSAVED_CHANGES_MSG } from './constant'
34+ import { DESCRIPTION_EMPTY_ERROR_MSG , DESCRIPTION_UNSAVED_CHANGES_MSG , TOOLBAR_SECONDARY_COMMANDS } from './constant'
4535import { GenericDescriptionProps } from './types'
4636import { getParsedUpdatedOnDate } from './utils'
4737
4838import './genericDescription.scss'
4939
50- const extraCommands = [
51- {
52- ...commands . bold ,
53- icon : < BoldIcon className = "icon-dim-16 flex" /> ,
54- } ,
55- {
56- ...commands . italic ,
57- icon : < ItalicIcon className = "icon-dim-16 flex" /> ,
58- } ,
59- {
60- ...commands . strikethrough ,
61- icon : < StrikethroughIcon className = "icon-dim-16 flex" /> ,
62- } ,
63- {
64- ...commands . heading ,
65- icon : < HeaderIcon className = "icon-dim-16 flex" /> ,
66- } ,
67- {
68- ...commands . quote ,
69- icon : < QuoteIcon className = "icon-dim-16 flex" /> ,
70- } ,
71- {
72- ...commands . code ,
73- icon : < CodeIcon className = "icon-dim-16 flex" /> ,
74- } ,
75- {
76- ...commands . link ,
77- icon : < LinkIcon className = "icon-dim-16 flex" /> ,
78- } ,
79- {
80- ...commands . image ,
81- icon : < ImageIcon className = "icon-dim-16 flex" /> ,
82- } ,
83- {
84- ...commands . orderedListCommand ,
85- icon : < OrderedListIcon className = "icon-dim-16 flex" /> ,
86- } ,
87- {
88- ...commands . unorderedListCommand ,
89- icon : < UnorderedListIcon className = "icon-dim-16 flex" /> ,
90- } ,
91- {
92- ...commands . checkedListCommand ,
93- icon : < CheckedListIcon className = "icon-dim-16 flex" /> ,
94- } ,
95- ]
96-
9740const GenericDescription = ( {
9841 text,
9942 updatedBy,
@@ -102,15 +45,22 @@ const GenericDescription = ({
10245 title,
10346 emptyStateConfig,
10447} : GenericDescriptionProps ) => {
48+ const parsedText = text || ''
49+
10550 const [ isLoading , setIsLoading ] = useState ( false )
106- const [ modifiedValue , setModifiedValue ] = useState ( text || '' )
51+ const [ modifiedValue , setModifiedValue ] = useState ( parsedText )
10752 const [ isEditView , setIsEditView ] = useState ( false )
10853
10954 const [ editorViewState , setEditorViewState ] = useState < 'write' | 'preview' > ( 'write' )
11055
11156 const _date = getParsedUpdatedOnDate ( updatedOn )
11257
113- const myCommands = useMemo (
58+ useEffect ( ( ) => {
59+ setModifiedValue ( parsedText )
60+ setIsEditView ( false )
61+ } , [ parsedText ] )
62+
63+ const toolbarPrimaryCommands = useMemo (
11464 ( ) => [
11565 {
11666 ...commands . codeEdit ,
@@ -133,7 +83,7 @@ const GenericDescription = ({
13383 )
13484
13585 const handleCancel = ( ) => {
136- const isDescriptionModified = modifiedValue . trim ( ) !== ( text || '' ) . trim ( )
86+ const isDescriptionModified = modifiedValue . trim ( ) !== parsedText . trim ( )
13787 let isConfirmed = true
13888
13989 if ( isDescriptionModified ) {
@@ -142,7 +92,7 @@ const GenericDescription = ({
14292 }
14393
14494 if ( isConfirmed ) {
145- setModifiedValue ( text )
95+ setModifiedValue ( parsedText )
14696 setIsEditView ( false )
14797 }
14898 }
@@ -171,7 +121,7 @@ const GenericDescription = ({
171121 setIsEditView ( true )
172122 }
173123
174- if ( ! text && ! isEditView ) {
124+ if ( ! parsedText && ! isEditView ) {
175125 const { img, subtitle } = emptyStateConfig || { }
176126 return (
177127 < div className = "flexbox w-100 bg__primary br-8 dc__border-dashed--n3" >
@@ -265,15 +215,15 @@ const GenericDescription = ({
265215 </ button >
266216 </ div >
267217
268- { renderMarkdown ( text ) }
218+ { renderMarkdown ( parsedText ) }
269219 </ div >
270220 ) : (
271221 < >
272222 < MDEditor
273223 value = { modifiedValue }
274224 onChange = { setModifiedValue }
275- commands = { myCommands }
276- extraCommands = { extraCommands }
225+ commands = { toolbarPrimaryCommands }
226+ extraCommands = { TOOLBAR_SECONDARY_COMMANDS }
277227 preview = { editorViewState === 'preview' ? 'preview' : 'edit' }
278228 components = { {
279229 preview : renderMarkdown ,
0 commit comments