1- import React , { useRef , useState } from 'react' ;
2-
1+ import React , { FormEvent , useRef , useState } from 'react' ;
32import { view } from '@risingstack/react-easy-state' ;
3+
44import appStore from 'webviews/store/appStore' ;
55import persistDataHook from 'webviews/hooks/persistDataHook' ;
66import Activities from 'webviews/components/Activities' ;
77import Reviewers from 'webviews/components/Reviewers' ;
88import messageTransferHook from 'webviews/hooks/messageTransferHook' ;
9+ import EditButton from 'webviews/components/EditButton' ;
10+ import { requestUpdateMRContent } from 'webviews/service/mrService' ;
11+
912import {
1013 EmptyWrapper ,
1114 TitleWrapper ,
@@ -17,13 +20,17 @@ import {
1720 Empty ,
1821 BranchName ,
1922 EditBtn ,
20- } from 'webviews/styles/MROverview' ;
23+ OperationBtn ,
24+ SectionTitle ,
25+ } from 'webviews/app.styles' ;
2126
2227function App ( ) {
23- const { currentMR, updateMRTitle } = appStore ;
24- const [ isEditing , setEditing ] = useState ( false ) ;
28+ const { currentMR, updateMRTitle, toggleUpdatingDesc } = appStore ;
29+ const [ isEditingTitle , setEditingTitle ] = useState ( false ) ;
2530 const [ title , setTitle ] = useState ( currentMR ?. data ?. merge_request ?. title ) ;
2631 const inputRef = useRef < HTMLInputElement | null > ( null ) ;
32+ const [ desc , setDesc ] = useState ( `` ) ;
33+
2734 const { repoInfo, data } = currentMR ;
2835 const { merge_request : mergeRequest } = data || { } ;
2936
@@ -33,7 +40,7 @@ function App() {
3340 const handleKeyDown = async ( event : any ) => {
3441 if ( event . key === 'Enter' ) {
3542 await updateMRTitle ( title ) ;
36- setEditing ( false ) ;
43+ setEditingTitle ( false ) ;
3744 }
3845 } ;
3946
@@ -47,10 +54,23 @@ function App() {
4754 } ;
4855
4956 const handleEdit = ( ) => {
50- setEditing ( true ) ;
57+ setEditingTitle ( true ) ;
5158 inputRef . current ?. focus ( ) ;
5259 } ;
5360
61+ const onEditDesc = ( ) => {
62+ toggleUpdatingDesc ( ) ;
63+ setDesc ( currentMR . data . merge_request . body_plan ) ;
64+ } ;
65+
66+ const onChangeDesc = ( ev : FormEvent < HTMLTextAreaElement > ) => {
67+ setDesc ( ev . currentTarget . value ) ;
68+ } ;
69+
70+ const onSaveDesc = async ( ) => {
71+ await requestUpdateMRContent ( currentMR . iid , desc ) ;
72+ } ;
73+
5474 if ( ! currentMR . iid ) {
5575 return < EmptyWrapper > Please select an merge request first.</ EmptyWrapper > ;
5676 }
@@ -62,13 +82,13 @@ function App() {
6282 return (
6383 < div >
6484 < TitleWrapper >
65- { isEditing ? (
85+ { isEditingTitle ? (
6686 < input
6787 type = 'text'
6888 value = { title }
6989 ref = { ( ref ) => ( inputRef . current = ref ) }
70- onBlur = { ( ) => setEditing ( false ) }
71- onFocus = { ( ) => setEditing ( true ) }
90+ onBlur = { ( ) => setEditingTitle ( false ) }
91+ onFocus = { ( ) => setEditingTitle ( true ) }
7292 onKeyDown = { handleKeyDown }
7393 onChange = { handleTitleChange }
7494 />
@@ -91,14 +111,39 @@ function App() {
91111 </ Row >
92112 < BodyWrap >
93113 < Body >
94- < h3 > Description</ h3 >
95- < Desc >
96- { mergeRequest ?. body ? (
97- < div dangerouslySetInnerHTML = { { __html : mergeRequest ?. body } } />
98- ) : (
99- < Empty > Empty</ Empty >
114+ < SectionTitle >
115+ Description
116+ { ! currentMR . data . editingDesc && < EditButton onClick = { onEditDesc } /> }
117+ { currentMR . data . editingDesc && (
118+ < >
119+ < OperationBtn className = { `colored` } onClick = { onSaveDesc } >
120+ Save
121+ </ OperationBtn >
122+ < OperationBtn className = { `colored secondary` } onClick = { ( ) => toggleUpdatingDesc ( ) } >
123+ Cancel
124+ </ OperationBtn >
125+ </ >
100126 ) }
101- </ Desc >
127+ </ SectionTitle >
128+ { ! currentMR . data . editingDesc && (
129+ < Desc >
130+ { mergeRequest ?. body ? (
131+ < div dangerouslySetInnerHTML = { { __html : mergeRequest ?. body } } />
132+ ) : (
133+ < Empty > This MR has no description.</ Empty >
134+ ) }
135+ </ Desc >
136+ ) }
137+ { currentMR . data . editingDesc && (
138+ < textarea
139+ name = 'desc'
140+ id = 'mr-desc'
141+ cols = { 30 }
142+ rows = { 20 }
143+ value = { desc }
144+ onChange = { onChangeDesc }
145+ />
146+ ) }
102147 < h3 > Activities</ h3 >
103148 < Activities />
104149 </ Body >
0 commit comments