@@ -34,19 +34,6 @@ export interface ICommitBoxProps {
3434 */
3535 trans : TranslationBundle ;
3636
37- /**
38- * Callback to invoke in order to commit changes.
39- *
40- * @param msg - commit message
41- * @returns a promise which commits changes
42- */
43- onCommit : ( msg : string ) => Promise < void > ;
44- }
45-
46- /**
47- * Interface describing component state.
48- */
49- export interface ICommitBoxState {
5037 /**
5138 * Commit message summary.
5239 */
@@ -56,15 +43,33 @@ export interface ICommitBoxState {
5643 * Commit message description.
5744 */
5845 description : string ;
46+
47+ /**
48+ * Updates the commit message summary.
49+ *
50+ * @param summary - commit message summary
51+ */
52+ setSummary : ( summary : string ) => void ;
53+
54+ /**
55+ * Updates the commit message description.
56+ *
57+ * @param description - commit message description
58+ */
59+ setDescription : ( description : string ) => void ;
60+
61+ /**
62+ * Callback to invoke in order to commit changes.
63+ *
64+ * @returns a promise which commits changes
65+ */
66+ onCommit : ( ) => Promise < void > ;
5967}
6068
6169/**
6270 * React component for entering a commit message.
6371 */
64- export class CommitBox extends React . Component <
65- ICommitBoxProps ,
66- ICommitBoxState
67- > {
72+ export class CommitBox extends React . Component < ICommitBoxProps > {
6873 /**
6974 * Returns a React component for entering a commit message.
7075 *
@@ -73,10 +78,6 @@ export class CommitBox extends React.Component<
7378 */
7479 constructor ( props : ICommitBoxProps ) {
7580 super ( props ) ;
76- this . state = {
77- summary : '' ,
78- description : ''
79- } ;
8081 }
8182
8283 componentDidMount ( ) : void {
@@ -96,7 +97,7 @@ export class CommitBox extends React.Component<
9697 const disabled = ! this . _canCommit ( ) ;
9798 const title = ! this . props . hasFiles
9899 ? this . props . trans . __ ( 'Disabled: No files are staged for commit' )
99- : ! this . state . summary
100+ : ! this . props . summary
100101 ? this . props . trans . __ ( 'Disabled: No commit message summary' )
101102 : this . props . label ;
102103
@@ -116,7 +117,7 @@ export class CommitBox extends React.Component<
116117 title = { this . props . trans . __ (
117118 'Enter a commit message summary (a single line, preferably less than 50 characters)'
118119 ) }
119- value = { this . state . summary }
120+ value = { this . props . summary }
120121 onChange = { this . _onSummaryChange }
121122 onKeyPress = { this . _onSummaryKeyPress }
122123 />
@@ -125,7 +126,7 @@ export class CommitBox extends React.Component<
125126 minRows = { 5 }
126127 placeholder = { this . props . trans . __ ( 'Description (optional)' ) }
127128 title = { this . props . trans . __ ( 'Enter a commit message description' ) }
128- value = { this . state . description }
129+ value = { this . props . description }
129130 onChange = { this . _onDescriptionChange }
130131 />
131132 < input
@@ -134,7 +135,7 @@ export class CommitBox extends React.Component<
134135 title = { title }
135136 value = { this . props . label }
136137 disabled = { disabled }
137- onClick = { this . _onCommitSubmit }
138+ onClick = { this . props . onCommit }
138139 />
139140 </ form >
140141 ) ;
@@ -144,7 +145,7 @@ export class CommitBox extends React.Component<
144145 * Whether a commit can be performed (files are staged and summary is not empty).
145146 */
146147 private _canCommit ( ) : boolean {
147- return ! ! ( this . props . hasFiles && this . state . summary ) ;
148+ return ! ! ( this . props . hasFiles && this . props . summary ) ;
148149 }
149150
150151 /**
@@ -157,26 +158,13 @@ export class CommitBox extends React.Component<
157158 return binding . keys . join ( ' ' ) ;
158159 } ;
159160
160- /**
161- * Callback invoked upon clicking a commit message submit button or otherwise submitting the form.
162- */
163- private _onCommitSubmit = ( ) : void => {
164- const msg = this . state . summary + '\n\n' + this . state . description + '\n' ;
165- this . props . onCommit ( msg ) ;
166-
167- // NOTE: we assume here that committing changes always works and we can safely clear component state
168- this . _reset ( ) ;
169- } ;
170-
171161 /**
172162 * Callback invoked upon updating a commit message description.
173163 *
174164 * @param event - event object
175165 */
176166 private _onDescriptionChange = ( event : any ) : void => {
177- this . setState ( {
178- description : event . target . value
179- } ) ;
167+ this . props . setDescription ( event . target . value ) ;
180168 } ;
181169
182170 /**
@@ -185,9 +173,7 @@ export class CommitBox extends React.Component<
185173 * @param event - event object
186174 */
187175 private _onSummaryChange = ( event : any ) : void => {
188- this . setState ( {
189- summary : event . target . value
190- } ) ;
176+ this . props . setSummary ( event . target . value ) ;
191177 } ;
192178
193179 /**
@@ -218,17 +204,7 @@ export class CommitBox extends React.Component<
218204 commandArgs : CommandRegistry . ICommandExecutedArgs
219205 ) : void => {
220206 if ( commandArgs . id === CommandIDs . gitSubmitCommand && this . _canCommit ( ) ) {
221- this . _onCommitSubmit ( ) ;
207+ this . props . onCommit ( ) ;
222208 }
223209 } ;
224-
225- /**
226- * Resets component state (e.g., in order to re-initialize the commit message input box).
227- */
228- private _reset ( ) : void {
229- this . setState ( {
230- summary : '' ,
231- description : ''
232- } ) ;
233- }
234210}
0 commit comments