@@ -311,6 +311,10 @@ class SourcesTree extends Component<Props, State> {
311311 ) ;
312312 } ;
313313
314+ renderEmptyElement ( message ) {
315+ return < div className = "no-sources-message" > { message } </ div > ;
316+ }
317+
314318 render ( ) {
315319 const { expanded, projectRoot } = this . props ;
316320 const {
@@ -329,14 +333,22 @@ class SourcesTree extends Component<Props, State> {
329333 this . props . setExpandedState ( expandedState ) ;
330334 } ;
331335
336+ const isEmpty = sourceTree . contents . length === 0 ;
337+
332338 const isCustomRoot = projectRoot !== "" ;
333339 let roots = ( ) => sourceTree . contents ;
334340
335341 let clearProjectRootButton = null ;
336342
337343 // The "sourceTree.contents[0]" check ensures that there are contents
338344 // A custom root with no existing sources will be ignored
339- if ( isCustomRoot && sourceTree . contents [ 0 ] ) {
345+ if ( isCustomRoot ) {
346+ let rootLabel = projectRoot . split ( "/" ) . pop ( ) ;
347+ if ( sourceTree . contents [ 0 ] ) {
348+ rootLabel = sourceTree . contents [ 0 ] . name ;
349+ roots = ( ) => sourceTree . contents [ 0 ] . contents ;
350+ }
351+
340352 clearProjectRootButton = (
341353 < button
342354 className = "sources-clear-root"
@@ -345,15 +357,15 @@ class SourcesTree extends Component<Props, State> {
345357 >
346358 < Svg name = "home" />
347359 < Svg name = "breadcrumb" class />
348- < span className = "sources-clear-root-label" >
349- { sourceTree . contents [ 0 ] . name }
350- </ span >
360+ < span className = "sources-clear-root-label" > { rootLabel } </ span >
351361 </ button >
352362 ) ;
353- roots = ( ) => sourceTree . contents [ 0 ] . contents ;
354363 }
355364
356- const isEmpty = sourceTree . contents . length === 0 ;
365+ if ( isEmpty && ! isCustomRoot ) {
366+ return this . renderEmptyElement ( L10N . getStr ( "sources.noSourcesAvailable" ) ) ;
367+ }
368+
357369 const treeProps = {
358370 autoExpandAll : false ,
359371 autoExpandDepth : expanded ? 0 : 1 ,
@@ -374,14 +386,6 @@ class SourcesTree extends Component<Props, State> {
374386
375387 const tree = < ManagedTree { ...treeProps } /> ;
376388
377- if ( isEmpty ) {
378- return (
379- < div className = "no-sources-message" >
380- { L10N . getStr ( "sources.noSourcesAvailable" ) }
381- </ div >
382- ) ;
383- }
384-
385389 const onKeyDown = e => {
386390 if ( e . keyCode === 13 && focusedItem ) {
387391 this . selectItem ( focusedItem ) ;
@@ -399,9 +403,13 @@ class SourcesTree extends Component<Props, State> {
399403 { clearProjectRootButton }
400404 </ div >
401405 ) : null }
402- < div className = "sources-list" onKeyDown = { onKeyDown } >
403- { tree }
404- </ div >
406+ { isEmpty ? (
407+ this . renderEmptyElement ( L10N . getStr ( "sources.noSourcesAvailableRoot" ) )
408+ ) : (
409+ < div className = "sources-list" onKeyDown = { onKeyDown } >
410+ { tree }
411+ </ div >
412+ ) }
405413 </ div >
406414 ) ;
407415 }
0 commit comments