4
4
*/
5
5
6
6
import { HomeOutlined } from "@ant-design/icons" ;
7
- import { Breadcrumb } from "antd" ;
7
+ import { Breadcrumb , Button , Flex , Tooltip } from "antd" ;
8
8
9
9
import {
10
+ CSS ,
10
11
React ,
11
12
useActions ,
12
13
useTypedRedux ,
13
14
} from "@cocalc/frontend/app-framework" ;
15
+ import { Icon } from "@cocalc/frontend/components" ;
14
16
import { trunc_middle } from "@cocalc/util/misc" ;
15
17
import { createPathSegmentLink } from "./path-segment-link" ;
16
18
@@ -30,36 +32,53 @@ export const PathNavigator: React.FC<Props> = React.memo(
30
32
className = "cc-path-navigator" ,
31
33
mode = "files" ,
32
34
} = props ;
33
- const current_path = useTypedRedux ( { project_id } , "current_path" ) ;
34
- const history_path = useTypedRedux ( { project_id } , "history_path" ) ;
35
+ const currentPath = useTypedRedux ( { project_id } , "current_path" ) ;
36
+ const historyPath = useTypedRedux ( { project_id } , "history_path" ) ;
35
37
const actions = useActions ( { project_id } ) ;
36
38
37
39
function make_path ( ) {
38
40
const v : any [ ] = [ ] ;
39
41
40
- const current_path_depth =
41
- ( current_path == "" ? 0 : current_path . split ( "/" ) . length ) - 1 ;
42
- const history_segments = history_path . split ( "/" ) ;
43
- const is_root = current_path [ 0 ] === "/" ;
42
+ const currentPathDepth =
43
+ ( currentPath == "" ? 0 : currentPath . split ( "/" ) . length ) - 1 ;
44
+ const historySegments = historyPath . split ( "/" ) ;
45
+ const isRoot = currentPath [ 0 ] === "/" ;
46
+
47
+ const homeStyle : CSS = {
48
+ fontSize : style ?. fontSize ,
49
+ fontWeight : "bold" ,
50
+ } as const ;
51
+
52
+ const homeDisplay =
53
+ mode === "files" ? (
54
+ < >
55
+ < HomeOutlined style = { homeStyle } /> { " " }
56
+ < span style = { homeStyle } > Home</ span >
57
+ </ >
58
+ ) : (
59
+ < HomeOutlined style = { homeStyle } />
60
+ ) ;
44
61
45
62
v . push (
46
63
createPathSegmentLink ( {
47
64
path : "" ,
48
- display : < HomeOutlined style = { { fontSize : style ?. fontSize } } /> ,
65
+ display : (
66
+ < Tooltip title = "Go to home directory" > { homeDisplay } </ Tooltip >
67
+ ) ,
49
68
full_name : "" ,
50
69
key : 0 ,
51
70
on_click : ( ) => actions ?. open_directory ( "" , true , false ) ,
52
- active : current_path_depth === - 1 ,
71
+ active : currentPathDepth === - 1 ,
53
72
} ) ,
54
73
) ;
55
74
56
- const pathLen = current_path_depth ;
75
+ const pathLen = currentPathDepth ;
57
76
const condense = mode === "flyout" ;
58
77
59
- history_segments . forEach ( ( segment , i ) => {
60
- if ( is_root && i === 0 ) return ;
61
- const is_current = i === current_path_depth ;
62
- const is_history = i > current_path_depth ;
78
+ historySegments . forEach ( ( segment , i ) => {
79
+ if ( isRoot && i === 0 ) return ;
80
+ const is_current = i === currentPathDepth ;
81
+ const is_history = i > currentPathDepth ;
63
82
64
83
// don't show too much in flyout mode
65
84
const hide =
@@ -70,7 +89,7 @@ export const PathNavigator: React.FC<Props> = React.memo(
70
89
v . push (
71
90
// yes, must be called as a normal function.
72
91
createPathSegmentLink ( {
73
- path : history_segments . slice ( 0 , i + 1 || undefined ) . join ( "/" ) ,
92
+ path : historySegments . slice ( 0 , i + 1 || undefined ) . join ( "/" ) ,
74
93
display : hide ? < > •</ > : trunc_middle ( segment , 15 ) ,
75
94
full_name : segment ,
76
95
key : i + 1 ,
@@ -83,10 +102,38 @@ export const PathNavigator: React.FC<Props> = React.memo(
83
102
return v ;
84
103
}
85
104
105
+ function renderUP ( ) {
106
+ const canGoUp = currentPath !== "" ;
107
+
108
+ return (
109
+ < Button
110
+ icon = { < Icon name = "arrow-circle-up" /> }
111
+ type = "text"
112
+ onClick = { ( ) => {
113
+ if ( ! canGoUp ) return ;
114
+ const pathSegments = currentPath . split ( "/" ) ;
115
+ pathSegments . pop ( ) ;
116
+ const parentPath = pathSegments . join ( "/" ) ;
117
+ actions ?. open_directory ( parentPath , true , false ) ;
118
+ } }
119
+ disabled = { ! canGoUp }
120
+ title = { canGoUp ? "Go up one directory" : "Already at home directory" }
121
+ />
122
+ ) ;
123
+ }
124
+
86
125
// Background color is set via .cc-project-files-path-nav > nav
87
126
// so that things look good even for multiline long paths.
88
- return (
127
+ const bc = (
89
128
< Breadcrumb style = { style } className = { className } items = { make_path ( ) } />
90
129
) ;
130
+ return mode === "files" ? (
131
+ < Flex justify = "space-between" align = "center" style = { { width : "100%" } } >
132
+ < div style = { { flex : 1 , minWidth : 0 } } > { bc } </ div >
133
+ { renderUP ( ) }
134
+ </ Flex >
135
+ ) : (
136
+ bc
137
+ ) ;
91
138
} ,
92
139
) ;
0 commit comments