Skip to content

Commit e480082

Browse files
committed
make labpath opt-in
- old filepath urls still open classic UI - form produces new `?labpath=` arg when a file path is chosen lab is still 'default', but choice is frozen at link-creation time instead of at visit-time
1 parent f3109e0 commit e480082

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

binderhub/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,14 @@ async def get(self, provider_prefix, _unescaped_spec):
7070
nbviewer_url = 'https://nbviewer.jupyter.org/github'
7171
org, repo_name, ref = spec.split('/', 2)
7272
# NOTE: tornado unquotes query arguments too -> notebooks%2Findex.ipynb becomes notebooks/index.ipynb
73-
filepath = self.get_argument('filepath', '').lstrip('/')
73+
filepath = self.get_argument("labpath", "").lstrip("/")
74+
if not filepath:
75+
filepath = self.get_argument('filepath', '').lstrip('/')
76+
7477

7578
# Check if we have a JupyterLab + file path, if so then use it for the filepath
7679
urlpath = self.get_argument('urlpath', '').lstrip('/')
77-
if urlpath.startswith("lab") and "/tree/" in urlpath:
80+
if urlpath and "/tree/" in urlpath:
7881
filepath = urlpath.split('tree/', 1)[-1]
7982

8083
blob_or_tree = 'blob' if filepath else 'tree'

binderhub/static/js/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,14 @@ function loadingMain(providerSpec) {
346346
if (path) {
347347
pathType = 'url';
348348
} else {
349-
path = params.get('filepath');
349+
path = params.get('labpath');
350350
if (path) {
351-
pathType = 'file';
351+
pathType = 'lab';
352+
} else {
353+
path = params.get('filepath');
354+
if (path) {
355+
pathType = 'file';
356+
}
352357
}
353358
}
354359
build(providerSpec, log, fitAddon, path, pathType);

binderhub/static/js/src/image.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ export default class BinderImage {
4949
url = url.replace(/\/$/, "");
5050
// trim leading '/'
5151
path = path.replace(/(^\/)/g, "");
52-
if (pathType === "file") {
52+
if (pathType === "lab") {
5353
// trim trailing / on file paths
5454
path = path.replace(/(\/$)/g, "");
5555
// /doc/tree is safe because it allows redirect to files
5656
url = url + "/doc/tree/" + encodeURI(path);
57+
} else if (pathType === "file") {
58+
// trim trailing / on file paths
59+
path = path.replace(/(\/$)/g, "");
60+
// /tree is safe because it allows redirect to files
61+
url = url + "/tree/" + encodeURI(path);
5762
} else {
5863
// pathType === 'url'
5964
url = url + "/" + path;

binderhub/static/js/src/path.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
export function getPathType() {
22
// return path type. 'file' or 'url'
33
const element = document.getElementById("url-or-file-selected");
4-
return element.innerText.trim().toLowerCase();
4+
let pathType = element.innerText.trim().toLowerCase();
5+
if (pathType === "file") {
6+
// selecting a 'file' in the form opens with jupyterlab
7+
// avoids backward-incompatibility with old `filepath` urls,
8+
// which still open old UI
9+
pathType = "lab";
10+
}
11+
return pathType;
512
}
613

714
export function updatePathText() {

0 commit comments

Comments
 (0)