-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: add way to open, list and close interactive sessions
closes #77
- Loading branch information
Showing
18 changed files
with
421 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
-*- coding: utf-8 -*- | ||
This file is part of REANA. | ||
Copyright (C) 2020 CERN. | ||
REANA is free software; you can redistribute it and/or modify it | ||
under the terms of the MIT License; see LICENSE file for more details. | ||
*/ | ||
|
||
import React, { useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Icon, Menu, Popup } from "semantic-ui-react"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
import { workflowShape } from "~/props"; | ||
import { | ||
deleteWorkflow, | ||
openInteractiveSession, | ||
closeInteractiveSession, | ||
openDeleteWorkflowModal, | ||
triggerNotification, | ||
} from "~/actions"; | ||
|
||
import { JupyterNotebookIcon } from "~/components"; | ||
|
||
import styles from "./WorkflowActionsPopup.module.scss"; | ||
|
||
const JupyterIcon = <JupyterNotebookIcon className={styles["jupyter-icon"]} />; | ||
|
||
export default function WorkflowActionsPopup({ workflow, className }) { | ||
const dispatch = useDispatch(); | ||
const [open, setOpen] = useState(false); | ||
const { id, size, status, session_status: sessionStatus } = workflow; | ||
const isDeleted = status === "deleted"; | ||
const isDeletedUsingWorkspace = isDeleted && size !== "0K"; | ||
const isSessionOpen = sessionStatus === "created"; | ||
|
||
let menuItems = []; | ||
|
||
if (isSessionOpen) { | ||
menuItems.push({ | ||
key: "closeNotebook", | ||
content: "Close Jupyter Notebook", | ||
icon: JupyterIcon, | ||
onClick: (e) => { | ||
dispatch(closeInteractiveSession(id)); | ||
setOpen(false); | ||
e.stopPropagation(); | ||
}, | ||
}); | ||
} else { | ||
menuItems.push({ | ||
key: "openNotebook", | ||
content: "Open Jupyter Notebook", | ||
icon: JupyterIcon, | ||
onClick: (e) => { | ||
dispatch(openInteractiveSession(id)).then(() => { | ||
dispatch( | ||
triggerNotification( | ||
"Success!", | ||
"The interactive session has been created. However, it could take several minutes to start the Jupyter Notebook." | ||
) | ||
); | ||
}); | ||
setOpen(false); | ||
e.stopPropagation(); | ||
}, | ||
}); | ||
} | ||
|
||
if (isDeleted) { | ||
if (isDeletedUsingWorkspace) { | ||
menuItems.push({ | ||
key: "freeup", | ||
content: "Free up disk", | ||
icon: "hdd", | ||
onClick: (e) => { | ||
dispatch(deleteWorkflow(id, true)); | ||
setOpen(false); | ||
e.stopPropagation(); | ||
}, | ||
}); | ||
} | ||
} else { | ||
menuItems.push({ | ||
key: "delete", | ||
content: "Delete workflow", | ||
icon: "trash", | ||
onClick: (e) => { | ||
dispatch(openDeleteWorkflowModal(workflow)); | ||
setOpen(false); | ||
e.stopPropagation(); | ||
}, | ||
}); | ||
} | ||
|
||
return ( | ||
<div className={className || styles.container}> | ||
{(!isDeleted || isDeletedUsingWorkspace) && ( | ||
<Popup | ||
basic | ||
trigger={ | ||
<Icon | ||
name="ellipsis vertical" | ||
className={styles.icon} | ||
onClick={(e) => { | ||
setOpen(true); | ||
e.stopPropagation(); | ||
}} | ||
/> | ||
} | ||
position="bottom left" | ||
on="click" | ||
open={open} | ||
onClose={() => setOpen(false)} | ||
> | ||
<Menu items={menuItems} secondary vertical /> | ||
</Popup> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
WorkflowActionsPopup.defaultProps = { | ||
className: "", | ||
}; | ||
|
||
WorkflowActionsPopup.propTypes = { | ||
workflow: workflowShape.isRequired, | ||
className: PropTypes.string, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
-*- coding: utf-8 -*- | ||
This file is part of REANA. | ||
Copyright (C) 2020 CERN. | ||
REANA is free software; you can redistribute it and/or modify it | ||
under the terms of the MIT License; see LICENSE file for more details. | ||
*/ | ||
|
||
@import "@palette"; | ||
|
||
:global(.icon).icon { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
} | ||
|
||
.container { | ||
cursor: pointer; | ||
min-width: 22px; | ||
margin-left: 2em; | ||
|
||
&:hover { | ||
color: darken($sepia, 30%); | ||
} | ||
} | ||
|
||
.jupyter-icon { | ||
width: 1.18em; | ||
float: right; | ||
margin: -0.2em 0em 0em 0.5em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.