17229: Add webshell to workbench2
[arvados-workbench2.git] / src / views / virtual-machine-panel / virtual-machine-user-panel.tsx
index b5f7d5f55f57b9a5ae1d8e06e6b739a805689e44..44631ce32bee12ebe3ac50db534ce77be802994f 100644 (file)
@@ -61,7 +61,8 @@ const mapStateToProps = (state: RootState) => {
         userUuid: state.auth.user!.uuid,
         helpText: state.auth.config.clusterConfig.Workbench.SSHHelpPageHTML,
         hostSuffix: state.auth.config.clusterConfig.Workbench.SSHHelpHostSuffix || "",
-        webShell: state.auth.config.clusterConfig.Services.Workbench1.ExternalURL,
+        token: state.auth.extraApiToken || state.auth.apiToken || '',
+        webshellUrl: state.auth.config.clusterConfig.Services.WebShell.ExternalURL,
         ...state.virtualMachines
     };
 };
@@ -78,7 +79,8 @@ interface VirtualMachinesPanelDataProps {
     links: ListResults<any>;
     helpText: string;
     hostSuffix: string;
-    webShell: string;
+    token: string;
+    webshellUrl: string;
 }
 
 interface VirtualMachinesPanelActionProps {
@@ -134,7 +136,7 @@ const CardContentWithVirtualMachines = (props: VirtualMachineProps) =>
                         {virtualMachineSendRequest(props)}
                     </div>
                     <div className={props.classes.icon}>
-                        <a href="https://doc.arvados.org/user/getting_started/vm-login-with-webshell.html" target="_blank" className={props.classes.linkIcon}>
+                        <a href="https://doc.arvados.org/user/getting_started/vm-login-with-webshell.html" target="_blank" rel="noopener noreferrer" className={props.classes.linkIcon}>
                             <Tooltip title="Access VM using webshell">
                                 <HelpIcon />
                             </Tooltip>
@@ -165,7 +167,7 @@ const virtualMachinesTable = (props: VirtualMachineProps) =>
                 <TableCell>Host name</TableCell>
                 <TableCell>Login name</TableCell>
                 <TableCell>Command line</TableCell>
-                {props.webShell !== "" && <TableCell>Web shell</TableCell>}
+                <TableCell>Web shell</TableCell>
             </TableRow>
         </TableHead>
         <TableBody>
@@ -180,14 +182,14 @@ const virtualMachinesTable = (props: VirtualMachineProps) =>
                             <TableCell>
                                 {command}
                             </TableCell>
-                            {props.webShell !== "" && <TableCell>
-                                <a href={`${props.webShell}${it.href}/webshell/${username}`} target="_blank" className={props.classes.link}>
+                            <TableCell>
+                                <a href={`/webshell/?host=${encodeURIComponent(props.webshellUrl + '/' + it.hostname)}&login=${username}&token=${encodeURIComponent(props.token)}`} target="_blank" rel="noopener noreferrer" className={props.classes.link}>
                                     Log in as {username}
                                 </a>
-                            </TableCell>}
+                            </TableCell>
                         </TableRow>;
                     }
-                    return;
+                    return null;
                 }
                 ))}
         </TableBody>