Jelajahi Sumber

Fix tree handling and routed signal.

Afshin Darian 7 tahun lalu
induk
melakukan
693b2c3a75

+ 3 - 9
packages/application-extension/src/index.ts

@@ -48,9 +48,6 @@ namespace CommandIDs {
 
   export
   const tree: string = 'router:tree';
-
-  export
-  const url: string = 'router:tree-url';
 }
 
 
@@ -172,13 +169,13 @@ const router: JupyterLabPlugin<IRouter> = {
       PageConfig.getBaseUrl(),
       PageConfig.getOption('pageUrl')
     );
-    const tree = PageConfig.getTreeUrl();
     const router = new Router({ base, commands });
+    const pattern = /^\/tree\/(.*)/;
 
     commands.addCommand(CommandIDs.tree, {
       execute: (args: IRouter.ICommandArgs) => {
         return app.restored.then(() => {
-          const path = (args.path as string).replace('/tree', '');
+          const path = decodeURIComponent((args.path.match(pattern)[1]));
 
           // Change the URL back to the base application URL.
           window.history.replaceState({ }, '', base);
@@ -188,10 +185,7 @@ const router: JupyterLabPlugin<IRouter> = {
       }
     });
 
-    commands.addCommand(CommandIDs.url, {
-      execute: args => URLExt.join(tree, (args.path as string))
-    });
-    router.register({ command: CommandIDs.tree, pattern: /^\/tree\/.+/ });
+    router.register({ command: CommandIDs.tree, pattern });
     app.started.then(() => { router.route(window.location.href); });
 
     return router;

+ 9 - 8
packages/application/src/router.ts

@@ -189,14 +189,15 @@ class Router implements IRouter {
       }
     });
 
-    // Order the rules by rank and collect the promises their commands return.
-    const promises = matches.sort((a, b) => a.rank - b.rank)
-      .map(rule => this.commands.execute(rule.command, args));
-
-    // After all the promises (if any) resolve, emit the routed signal.
-    Promise.all(promises)
-      .catch(reason => { console.warn(`Routing ${url} failed:`, reason); })
-      .then(() => { this._routed.emit(args); });
+    // Order the matching rules by rank and execute them.
+    matches.sort((a, b) => a.rank - b.rank).forEach(rule => {
+      // Ignore the results of each executed promise.
+      this.commands.execute(rule.command, args).catch(reason => {
+        console.warn(`Routing ${url} using ${rule.command} failed:`, reason);
+      });
+    });
+
+    this._routed.emit(args);
   }
 
   private _routed = new Signal<this, IRouter.ICommandArgs>(this);

+ 2 - 2
packages/filebrowser-extension/src/index.ts

@@ -380,10 +380,10 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
 
   commands.addCommand(CommandIDs.share, {
     execute: () => {
-      const path = browser.selectedItems().next().path;
+      const path = encodeURIComponent(browser.selectedItems().next().path);
       const tree = PageConfig.getTreeUrl();
 
-      Clipboard.copyToSystem(URLExt.join(tree, (path as string)));
+      Clipboard.copyToSystem(URLExt.join(tree, path));
     },
     isVisible: () => toArray(browser.selectedItems()).length === 1,
     iconClass: 'jp-MaterialIcon jp-LinkIcon',