1
+ import * as React from 'react' ;
1
2
import { Dialog , showDialog , UseSignal } from '@jupyterlab/apputils' ;
2
3
import { PathExt } from '@jupyterlab/coreutils' ;
3
- import { FileDialog , FileBrowserModel } from '@jupyterlab/filebrowser' ;
4
+ import { FileBrowserModel , FileDialog } from '@jupyterlab/filebrowser' ;
4
5
import { DefaultIconReact } from '@jupyterlab/ui-components' ;
5
- import * as React from 'react' ;
6
6
import { classes } from 'typestyle' ;
7
7
import {
8
8
gitPullStyle ,
9
9
gitPushStyle ,
10
+ noRepoPathStyle ,
10
11
pinIconStyle ,
11
12
repoPathStyle ,
13
+ repoPinStyle ,
12
14
repoRefreshStyle ,
13
15
repoStyle ,
14
- repoPinStyle ,
15
- repoPinnedStyle
16
+ separatorStyle ,
17
+ toolBarStyle
16
18
} from '../style/PathHeaderStyle' ;
19
+ import { IGitExtension } from '../tokens' ;
17
20
import { GitCredentialsForm } from '../widgets/CredentialsBox' ;
18
21
import { GitPullPushDialog , Operation } from '../widgets/gitPushPull' ;
19
- import { IGitExtension } from '../tokens' ;
20
22
23
+ /**
24
+ * Properties of the PathHeader React component
25
+ */
21
26
export interface IPathHeaderProps {
27
+ /**
28
+ * Git extension model
29
+ */
22
30
model : IGitExtension ;
31
+ /**
32
+ * File browser model
33
+ */
23
34
fileBrowserModel : FileBrowserModel ;
35
+ /**
36
+ * Refresh UI callback
37
+ */
24
38
refresh : ( ) => Promise < void > ;
25
39
}
26
40
27
41
/**
28
42
* Displays the error dialog when the Git Push/Pull operation fails.
43
+ *
29
44
* @param title the title of the error dialog
30
45
* @param body the message to be shown in the body of the modal.
31
46
*/
@@ -86,7 +101,8 @@ async function selectGitRepository(
86
101
model . pathRepository = folder . path ;
87
102
} else if ( fileModel . path !== folder . path ) {
88
103
// Change current filebrowser path
89
- fileModel . cd ( '/' + folder . path ) ;
104
+ // => will be propagated to path repository
105
+ fileModel . cd ( `/${ folder . path } ` ) ;
90
106
}
91
107
}
92
108
}
@@ -107,14 +123,9 @@ export const PathHeader: React.FunctionComponent<IPathHeaderProps> = (
107
123
} ) ;
108
124
} ) ;
109
125
110
- const pinStyles = [ repoPinStyle , 'jp-Icon-16' ] ;
111
- if ( pin ) {
112
- pinStyles . push ( repoPinnedStyle ) ;
113
- }
114
-
115
126
return (
116
- < div >
117
- < div className = { repoStyle } >
127
+ < React . Fragment >
128
+ < div className = { toolBarStyle } >
118
129
< button
119
130
className = { classes ( gitPullStyle , 'jp-Icon-16' ) }
120
131
title = { 'Pull latest changes' }
@@ -143,58 +154,61 @@ export const PathHeader: React.FunctionComponent<IPathHeaderProps> = (
143
154
onClick = { ( ) => props . refresh ( ) }
144
155
/>
145
156
</ div >
146
- < div >
147
- < UseSignal
148
- signal = { props . model . repositoryChanged }
149
- initialArgs = { {
150
- name : 'pathRepository' ,
151
- oldValue : null ,
152
- newValue : props . model . pathRepository
153
- } }
154
- >
155
- { ( _ , change ) => {
156
- const pathStyles = [ repoPathStyle ] ;
157
- let pinTitle = 'the repository path' ;
158
- if ( props . model . repositoryPinned ) {
159
- pinTitle = 'Unpin ' + pinTitle ;
160
- } else {
161
- pinTitle = 'Pin ' + pinTitle ;
162
- }
157
+ < UseSignal
158
+ signal = { props . model . repositoryChanged }
159
+ initialArgs = { {
160
+ name : 'pathRepository' ,
161
+ oldValue : null ,
162
+ newValue : props . model . pathRepository
163
+ } }
164
+ >
165
+ { ( _ , change ) => {
166
+ const pathStyles = [ repoPathStyle ] ;
167
+ if ( ! change . newValue ) {
168
+ pathStyles . push ( noRepoPathStyle ) ;
169
+ }
163
170
164
- return (
165
- < React . Fragment >
166
- < label className = { repoPinStyle } title = { pinTitle } >
167
- < input
168
- type = "checkbox"
169
- checked = { props . model . repositoryPinned }
170
- onChange = { ( ) => {
171
- props . model . repositoryPinned = ! props . model
172
- . repositoryPinned ;
173
- setPin ( props . model . repositoryPinned ) ;
174
- } }
175
- />
176
- < DefaultIconReact
177
- className = { pinIconStyle }
178
- tag = "span"
179
- name = "git-pin"
180
- />
181
- </ label >
182
- < span
183
- className = { classes ( ...pathStyles ) }
184
- title = { change . newValue }
185
- onClick = { ( ) => {
186
- selectGitRepository ( props . model , props . fileBrowserModel ) ;
171
+ let pinTitle = 'the repository path' ;
172
+ if ( pin ) {
173
+ pinTitle = 'Unpin ' + pinTitle ;
174
+ } else {
175
+ pinTitle = 'Pin ' + pinTitle ;
176
+ }
177
+
178
+ return (
179
+ < div className = { repoStyle } >
180
+ < label className = { repoPinStyle } title = { pinTitle } >
181
+ < input
182
+ type = "checkbox"
183
+ checked = { pin }
184
+ onChange = { ( ) => {
185
+ props . model . repositoryPinned = ! props . model
186
+ . repositoryPinned ;
187
+ setPin ( props . model . repositoryPinned ) ;
187
188
} }
188
- >
189
- { PathExt . basename (
190
- change . newValue || 'Click to select a Git repository.'
191
- ) }
192
- </ span >
193
- </ React . Fragment >
194
- ) ;
195
- } }
196
- </ UseSignal >
197
- </ div >
198
- </ div >
189
+ />
190
+ < DefaultIconReact
191
+ className = { pinIconStyle }
192
+ tag = "span"
193
+ name = "git-pin"
194
+ />
195
+ </ label >
196
+ < span
197
+ className = { classes ( ...pathStyles ) }
198
+ title = { change . newValue }
199
+ onClick = { ( ) => {
200
+ selectGitRepository ( props . model , props . fileBrowserModel ) ;
201
+ } }
202
+ >
203
+ { change . newValue
204
+ ? PathExt . basename ( change . newValue )
205
+ : 'Click to select a Git repository.' }
206
+ </ span >
207
+ </ div >
208
+ ) ;
209
+ } }
210
+ </ UseSignal >
211
+ < div className = { separatorStyle } />
212
+ </ React . Fragment >
199
213
) ;
200
214
} ;
0 commit comments