1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
4
- import Panel from '../atom/panel' ;
5
4
import InitDialog from '../views/init-dialog' ;
6
5
import CloneDialog from '../views/clone-dialog' ;
7
6
import CredentialDialog from '../views/credential-dialog' ;
8
7
import OpenIssueishDialog from '../views/open-issueish-dialog' ;
9
8
import OpenCommitDialog from '../views/open-commit-dialog' ;
10
9
10
+ const DIALOG_COMPONENTS = {
11
+ null : NullDialog ,
12
+ init : InitDialog ,
13
+ clone : CloneDialog ,
14
+ credential : CredentialDialog ,
15
+ issueish : OpenIssueishDialog ,
16
+ commit : OpenCommitDialog ,
17
+ } ;
18
+
11
19
export default class DialogsController extends React . Component {
12
20
static propTypes = {
13
21
// Model
@@ -22,58 +30,16 @@ export default class DialogsController extends React.Component {
22
30
config : PropTypes . object . isRequired ,
23
31
} ;
24
32
25
- constructor ( props ) {
26
- super ( props ) ;
27
-
28
- this . dialogRenderFns = {
29
- null : ( ) => null ,
30
- init : this . renderInitDialog ,
31
- clone : this . renderCloneDialog ,
32
- credential : this . renderCredentialDialog ,
33
- issueish : this . renderIssueishDialog ,
34
- commit : this . renderCommitDialog ,
35
- } ;
36
-
37
- this . state = {
38
- requestInProgress : null ,
39
- requestError : [ null , null ] ,
40
- } ;
33
+ state = {
34
+ requestInProgress : null ,
35
+ requestError : [ null , null ] ,
41
36
}
42
37
43
38
render ( ) {
44
- return this . dialogRenderFns [ this . props . request . identifier ] ( ) ;
39
+ const DialogComponent = DIALOG_COMPONENTS [ this . props . request . identifier ] ;
40
+ return < DialogComponent { ...this . getCommonProps ( ) } /> ;
45
41
}
46
42
47
- renderInitDialog = ( ) => (
48
- < Panel workspace = { this . props . workspace } location = "modal" >
49
- < InitDialog { ...this . getCommonProps ( ) } />
50
- </ Panel >
51
- )
52
-
53
- renderCloneDialog = ( ) => (
54
- < Panel workspace = { this . props . workspace } location = "modal" >
55
- < CloneDialog config = { this . props . config } { ...this . getCommonProps ( ) } />
56
- </ Panel >
57
- )
58
-
59
- renderCredentialDialog = ( ) => (
60
- < Panel workspace = { this . props . workspace } location = "modal" >
61
- < CredentialDialog { ...this . getCommonProps ( ) } />
62
- </ Panel >
63
- )
64
-
65
- renderIssueishDialog = ( ) => (
66
- < Panel workspace = { this . props . workspace } location = "modal" >
67
- < OpenIssueishDialog { ...this . getCommonProps ( ) } />
68
- </ Panel >
69
- )
70
-
71
- renderCommitDialog = ( ) => (
72
- < Panel workspace = { this . props . workspace } location = "modal" >
73
- < OpenCommitDialog { ...this . getCommonProps ( ) } />
74
- </ Panel >
75
- )
76
-
77
43
getCommonProps ( ) {
78
44
const { request} = this . props ;
79
45
const accept = request . isProgressing
@@ -99,14 +65,20 @@ export default class DialogsController extends React.Component {
99
65
const wrapped = wrapDialogRequest ( request , { accept} ) ;
100
66
101
67
return {
68
+ config : this . props . config ,
102
69
commands : this . props . commands ,
70
+ workspace : this . props . workspace ,
103
71
inProgress : this . state . requestInProgress === request ,
104
72
error : this . state . requestError [ 0 ] === request ? this . state . requestError [ 1 ] : null ,
105
73
request : wrapped ,
106
74
} ;
107
75
}
108
76
}
109
77
78
+ function NullDialog ( ) {
79
+ return null ;
80
+ }
81
+
110
82
class DialogRequest {
111
83
constructor ( identifier , params = { } ) {
112
84
this . identifier = identifier ;
@@ -135,7 +107,7 @@ class DialogRequest {
135
107
}
136
108
137
109
function wrapDialogRequest ( original , { accept} ) {
138
- const dup = new DialogRequest ( original . identifier , original . getParams ( ) ) ;
110
+ const dup = new DialogRequest ( original . identifier , original . params ) ;
139
111
dup . isProgressing = original . isProgressing ;
140
112
dup . onAccept ( accept ) ;
141
113
dup . onCancel ( original . cancel ) ;
0 commit comments