2021-10-16 14:31:03 +00:00
|
|
|
import {faFlask} from "@fortawesome/free-solid-svg-icons"
|
2021-10-20 18:21:49 +00:00
|
|
|
import {Button} from "@steffo/bluelib-react"
|
2021-10-16 14:31:03 +00:00
|
|
|
import * as React from "react"
|
|
|
|
import {useAuthorizationContext} from "../../contexts/authorization"
|
|
|
|
import {useNotebookContext} from "../../contexts/notebook"
|
|
|
|
import {IconText} from "../elements/IconText"
|
|
|
|
|
|
|
|
|
|
|
|
export function NotebookLabButton(): JSX.Element | null {
|
|
|
|
const authorization = useAuthorizationContext()
|
|
|
|
const notebook = useNotebookContext()
|
|
|
|
|
|
|
|
const canOpen =
|
|
|
|
React.useMemo(
|
|
|
|
() => authorization &&
|
|
|
|
notebook &&
|
|
|
|
(
|
|
|
|
notebook.value.locked_by === null || notebook.value.locked_by === authorization?.state.user?.id
|
|
|
|
),
|
|
|
|
[notebook, authorization],
|
|
|
|
)
|
|
|
|
|
|
|
|
if(!notebook) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
if(!notebook.value.lab_url) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-10-20 18:21:49 +00:00
|
|
|
<Button onClick={() => window.open(notebook.value.lab_url!)} disabled={!canOpen}>
|
2021-10-16 14:31:03 +00:00
|
|
|
<IconText icon={faFlask}>
|
|
|
|
Open JupyterLab
|
|
|
|
</IconText>
|
2021-10-20 18:21:49 +00:00
|
|
|
</Button>
|
2021-10-16 14:31:03 +00:00
|
|
|
)
|
|
|
|
}
|