-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataFilesDropdown.jsx
More file actions
152 lines (140 loc) · 4.96 KB
/
DataFilesDropdown.jsx
File metadata and controls
152 lines (140 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Link, useLocation } from 'react-router-dom';
import { Button } from '_common';
import {
Dropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
} from 'reactstrap';
import { useSystemDisplayName, useSystems } from 'hooks/datafiles';
import '../DataFilesBreadcrumbs/DataFilesBreadcrumbs.scss';
const BreadcrumbsDropdown = ({
api,
scheme,
system,
path,
_section,
isPublic,
}) => {
const paths = [];
const [dropdownOpen, setDropdownOpen] = useState(false);
const toggleDropdown = () => setDropdownOpen(!dropdownOpen);
const location = useLocation();
const pathParts = location.pathname.split('/');
const projectId = pathParts.includes('projects')
? pathParts[pathParts.indexOf('projects') + 1]
: null;
const handleNavigation = (targetPath) => {
const basePath = isPublic ? '/public-data' : '/workbench/data';
let url;
if (scheme === 'projects' && targetPath === systemName) {
url = `${basePath}/${api}/projects/${projectId}/`;
} else if (scheme === 'projects' && !targetPath) {
url = `${basePath}/${api}/projects/`;
} else if (api === 'googledrive' && !targetPath) {
url = `${basePath}/${api}/${scheme}/${system}/`;
} else if (api === 'tapis' && scheme !== 'projects' && !targetPath) {
url = `${basePath}/${api}/${scheme}/${system}/`;
} else {
url = `${basePath}/${api}/${scheme}/${system}${targetPath}/`;
}
return url;
};
const { fetchSelectedSystem } = useSystems();
const selectedSystem = fetchSelectedSystem({ scheme, system, path });
const systemName = useSystemDisplayName({ scheme, system, path });
const homeDir = selectedSystem?.homeDir;
const isSystemRootPath = !path
.replace(/^\/+/, '')
.startsWith(homeDir?.replace(/^\/+/, ''));
const startingPath = isSystemRootPath ? '' : homeDir;
const pathComponents = path.split('/').filter((x) => !!x);
const startingPathComponents = startingPath.split('/').filter((x) => !!x);
const overlapIndex = pathComponents.findIndex(
(component, index) => startingPathComponents[index] !== component
);
let currentPath = startingPath;
pathComponents.slice(overlapIndex).forEach((component) => {
currentPath = `${currentPath}/${component}`;
paths.push(currentPath);
});
const fullPath = paths.reverse();
const displayPaths =
scheme === 'projects' ? [...fullPath, systemName] : fullPath;
const sliceStart = scheme === 'projects' && systemName ? 0 : 1;
return (
<div id="path-button-wrapper">
<Dropdown
isOpen={dropdownOpen}
toggle={toggleDropdown}
className="go-to-button-dropdown"
>
<DropdownToggle tag={Button}>Go to ...</DropdownToggle>
<DropdownMenu>
{displayPaths
.slice(sliceStart, displayPaths.length)
.map((path, index) => {
const folderName = path.split('/').pop();
return (
<Link
className="link-hover"
key={index}
to={handleNavigation(path)}
>
<DropdownItem
className={
scheme === 'projects' && path === systemName
? 'complex-dropdown-item-project'
: ''
}
>
<i className="icon-folder" />
<span
className={
scheme === 'projects' && path === systemName
? 'multiline-menu-item-wrapper'
: ''
}
>
{folderName.length > 20
? folderName.substring(0, 20)
: folderName}
{scheme === 'projects' && path === systemName && (
<small> Project Name </small>
)}
</span>
</DropdownItem>
</Link>
);
})}
<DropdownItem divider />
<Link className="link-hover" to={handleNavigation(homeDir)}>
<DropdownItem className="complex-dropdown-item-root">
<i className="icon-my-data" />
<span className="multiline-menu-item-wrapper">
{scheme === 'projects'
? 'Shared Workspaces'
: systemName || 'Shared Workspaces'}
{homeDir ? <small>Root</small> : null}
</span>
</DropdownItem>
</Link>
</DropdownMenu>
</Dropdown>
</div>
);
};
BreadcrumbsDropdown.propTypes = {
api: PropTypes.string.isRequired,
scheme: PropTypes.string.isRequired,
system: PropTypes.string.isRequired,
path: PropTypes.string.isRequired,
section: PropTypes.string,
isPublic: PropTypes.bool,
};
BreadcrumbsDropdown.defaultProps = {
isPublic: false,
};
export default BreadcrumbsDropdown;