Skip to content

Commit cab65d8

Browse files
authored
Merge pull request #8477 from sagemathinc/frontend-explorer-breadcrumb-improve-nav
frontend/explorer: enhance breadcrumb nav
2 parents 8898a9c + cd00ed6 commit cab65d8

File tree

2 files changed

+63
-17
lines changed

2 files changed

+63
-17
lines changed

src/packages/frontend/_projects.sass

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
// the particular place we are using this.
8888
.cc-path-navigator
8989
flex: 5 1 auto
90-
margin-bottom: 15px !important
9190
max-width: 50vw
9291
padding: 5px 10px !important
9392

src/packages/frontend/project/explorer/path-navigator.tsx

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
*/
55

66
import { HomeOutlined } from "@ant-design/icons";
7-
import { Breadcrumb } from "antd";
7+
import { Breadcrumb, Button, Flex, Tooltip } from "antd";
88

99
import {
10+
CSS,
1011
React,
1112
useActions,
1213
useTypedRedux,
1314
} from "@cocalc/frontend/app-framework";
15+
import { Icon } from "@cocalc/frontend/components";
1416
import { trunc_middle } from "@cocalc/util/misc";
1517
import { createPathSegmentLink } from "./path-segment-link";
1618

@@ -30,36 +32,53 @@ export const PathNavigator: React.FC<Props> = React.memo(
3032
className = "cc-path-navigator",
3133
mode = "files",
3234
} = 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");
3537
const actions = useActions({ project_id });
3638

3739
function make_path() {
3840
const v: any[] = [];
3941

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+
);
4461

4562
v.push(
4663
createPathSegmentLink({
4764
path: "",
48-
display: <HomeOutlined style={{ fontSize: style?.fontSize }} />,
65+
display: (
66+
<Tooltip title="Go to home directory">{homeDisplay}</Tooltip>
67+
),
4968
full_name: "",
5069
key: 0,
5170
on_click: () => actions?.open_directory("", true, false),
52-
active: current_path_depth === -1,
71+
active: currentPathDepth === -1,
5372
}),
5473
);
5574

56-
const pathLen = current_path_depth;
75+
const pathLen = currentPathDepth;
5776
const condense = mode === "flyout";
5877

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;
6382

6483
// don't show too much in flyout mode
6584
const hide =
@@ -70,7 +89,7 @@ export const PathNavigator: React.FC<Props> = React.memo(
7089
v.push(
7190
// yes, must be called as a normal function.
7291
createPathSegmentLink({
73-
path: history_segments.slice(0, i + 1 || undefined).join("/"),
92+
path: historySegments.slice(0, i + 1 || undefined).join("/"),
7493
display: hide ? <>&bull;</> : trunc_middle(segment, 15),
7594
full_name: segment,
7695
key: i + 1,
@@ -83,10 +102,38 @@ export const PathNavigator: React.FC<Props> = React.memo(
83102
return v;
84103
}
85104

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+
86125
// Background color is set via .cc-project-files-path-nav > nav
87126
// so that things look good even for multiline long paths.
88-
return (
127+
const bc = (
89128
<Breadcrumb style={style} className={className} items={make_path()} />
90129
);
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+
);
91138
},
92139
);

0 commit comments

Comments
 (0)