@@ -34,19 +34,6 @@ export interface ICommitBoxProps {
34
34
*/
35
35
trans : TranslationBundle ;
36
36
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 {
50
37
/**
51
38
* Commit message summary.
52
39
*/
@@ -56,15 +43,33 @@ export interface ICommitBoxState {
56
43
* Commit message description.
57
44
*/
58
45
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 > ;
59
67
}
60
68
61
69
/**
62
70
* React component for entering a commit message.
63
71
*/
64
- export class CommitBox extends React . Component <
65
- ICommitBoxProps ,
66
- ICommitBoxState
67
- > {
72
+ export class CommitBox extends React . Component < ICommitBoxProps > {
68
73
/**
69
74
* Returns a React component for entering a commit message.
70
75
*
@@ -73,10 +78,6 @@ export class CommitBox extends React.Component<
73
78
*/
74
79
constructor ( props : ICommitBoxProps ) {
75
80
super ( props ) ;
76
- this . state = {
77
- summary : '' ,
78
- description : ''
79
- } ;
80
81
}
81
82
82
83
componentDidMount ( ) : void {
@@ -96,7 +97,7 @@ export class CommitBox extends React.Component<
96
97
const disabled = ! this . _canCommit ( ) ;
97
98
const title = ! this . props . hasFiles
98
99
? this . props . trans . __ ( 'Disabled: No files are staged for commit' )
99
- : ! this . state . summary
100
+ : ! this . props . summary
100
101
? this . props . trans . __ ( 'Disabled: No commit message summary' )
101
102
: this . props . label ;
102
103
@@ -116,7 +117,7 @@ export class CommitBox extends React.Component<
116
117
title = { this . props . trans . __ (
117
118
'Enter a commit message summary (a single line, preferably less than 50 characters)'
118
119
) }
119
- value = { this . state . summary }
120
+ value = { this . props . summary }
120
121
onChange = { this . _onSummaryChange }
121
122
onKeyPress = { this . _onSummaryKeyPress }
122
123
/>
@@ -125,7 +126,7 @@ export class CommitBox extends React.Component<
125
126
minRows = { 5 }
126
127
placeholder = { this . props . trans . __ ( 'Description (optional)' ) }
127
128
title = { this . props . trans . __ ( 'Enter a commit message description' ) }
128
- value = { this . state . description }
129
+ value = { this . props . description }
129
130
onChange = { this . _onDescriptionChange }
130
131
/>
131
132
< input
@@ -134,7 +135,7 @@ export class CommitBox extends React.Component<
134
135
title = { title }
135
136
value = { this . props . label }
136
137
disabled = { disabled }
137
- onClick = { this . _onCommitSubmit }
138
+ onClick = { this . props . onCommit }
138
139
/>
139
140
</ form >
140
141
) ;
@@ -144,7 +145,7 @@ export class CommitBox extends React.Component<
144
145
* Whether a commit can be performed (files are staged and summary is not empty).
145
146
*/
146
147
private _canCommit ( ) : boolean {
147
- return ! ! ( this . props . hasFiles && this . state . summary ) ;
148
+ return ! ! ( this . props . hasFiles && this . props . summary ) ;
148
149
}
149
150
150
151
/**
@@ -157,26 +158,13 @@ export class CommitBox extends React.Component<
157
158
return binding . keys . join ( ' ' ) ;
158
159
} ;
159
160
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
-
171
161
/**
172
162
* Callback invoked upon updating a commit message description.
173
163
*
174
164
* @param event - event object
175
165
*/
176
166
private _onDescriptionChange = ( event : any ) : void => {
177
- this . setState ( {
178
- description : event . target . value
179
- } ) ;
167
+ this . props . setDescription ( event . target . value ) ;
180
168
} ;
181
169
182
170
/**
@@ -185,9 +173,7 @@ export class CommitBox extends React.Component<
185
173
* @param event - event object
186
174
*/
187
175
private _onSummaryChange = ( event : any ) : void => {
188
- this . setState ( {
189
- summary : event . target . value
190
- } ) ;
176
+ this . props . setSummary ( event . target . value ) ;
191
177
} ;
192
178
193
179
/**
@@ -218,17 +204,7 @@ export class CommitBox extends React.Component<
218
204
commandArgs : CommandRegistry . ICommandExecutedArgs
219
205
) : void => {
220
206
if ( commandArgs . id === CommandIDs . gitSubmitCommand && this . _canCommit ( ) ) {
221
- this . _onCommitSubmit ( ) ;
207
+ this . props . onCommit ( ) ;
222
208
}
223
209
} ;
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
- }
234
210
}
0 commit comments