-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add download modal to dataset view actions (#6283)
* some download modal refactoring * add python modal visibility action * add pythonClientModal to dataset actions * prettyfication * make modal lazy * make share modal lazy * Update frontend/javascripts/oxalis/view/action-bar/view_dataset_actions_view.tsx * also suggest open_remote in export dialog; update changelog * small visual tweaks Co-authored-by: Philipp Otto <[email protected]> Co-authored-by: Philipp Otto <[email protected]>
- Loading branch information
1 parent
7710e36
commit 8cac67e
Showing
10 changed files
with
189 additions
and
18 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
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
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
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
116 changes: 116 additions & 0 deletions
116
frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx
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,116 @@ | ||
import { Divider, Modal, Row, Typography } from "antd"; | ||
import React from "react"; | ||
import { useFetch, makeComponentLazy } from "libs/react_helpers"; | ||
import Toast from "libs/toast"; | ||
import messages from "messages"; | ||
import { getAuthToken } from "admin/admin_rest_api"; | ||
import { useSelector } from "react-redux"; | ||
import type { OxalisState } from "oxalis/store"; | ||
import { CopyableCodeSnippet, MoreInfoHint } from "./download_modal_view"; | ||
const { Paragraph, Text } = Typography; | ||
type Props = { | ||
isVisible: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
function _PythonClientModalView(props: Props): JSX.Element { | ||
const { isVisible, onClose } = props; | ||
const activeUser = useSelector((state: OxalisState) => state.activeUser); | ||
const dataset = useSelector((state: OxalisState) => state.dataset); | ||
|
||
const maybeShowWarning = () => ( | ||
<Row> | ||
<Text | ||
style={{ | ||
margin: "0 6px 12px", | ||
}} | ||
type="warning" | ||
> | ||
{activeUser != null | ||
? messages["annotation.python_do_not_share"] | ||
: messages["annotation.register_for_token"]} | ||
</Text> | ||
</Row> | ||
); | ||
|
||
const authToken = useFetch( | ||
async () => { | ||
if (activeUser != null) { | ||
return getAuthToken(); | ||
} | ||
return null; | ||
}, | ||
"loading...", | ||
[activeUser], | ||
); | ||
const wkInitSnippet = `import webknossos as wk | ||
with wk.webknossos_context(token="${authToken || "<insert token here>"}"): | ||
# Download the dataset. | ||
dataset = wk.Dataset.download( | ||
url="${window.location.origin}", | ||
dataset="${dataset.name}" | ||
organization_id="${dataset.owningOrganization}", | ||
) | ||
# Alternatively, directly open the dataset. Image data will be | ||
# streamed when being accessed. | ||
remote_dataset = wk.Dataset.open_remote( | ||
url="${window.location.origin}", | ||
dataset="${dataset.name}" | ||
organization_id="${dataset.owningOrganization}", | ||
) | ||
`; | ||
|
||
const alertTokenIsPrivate = () => { | ||
Toast.warning( | ||
"The clipboard contains private data. Do not share this information with anyone you do not trust!", | ||
); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
title="Python Client" | ||
visible={isVisible} | ||
width={800} | ||
footer={null} | ||
onCancel={onClose} | ||
style={{ overflow: "visible" }} | ||
> | ||
<Row> | ||
<Text | ||
style={{ | ||
margin: "0 6px 12px", | ||
}} | ||
> | ||
The following code snippets are suggestions to get you started quickly with the{" "} | ||
<a href="https://docs.webknossos.org/webknossos-py/" target="_blank" rel="noreferrer"> | ||
webKnossos Python API | ||
</a> | ||
. To download and use this dataset in your Python project, simply copy and paste the code | ||
snippets to your script. | ||
</Text> | ||
</Row> | ||
<Divider | ||
style={{ | ||
margin: "18px 0", | ||
}} | ||
> | ||
Code Snippets | ||
</Divider> | ||
{maybeShowWarning()} | ||
<Paragraph> | ||
<CopyableCodeSnippet code="pip install webknossos" /> | ||
<CopyableCodeSnippet code={wkInitSnippet} onCopy={alertTokenIsPrivate} /> | ||
</Paragraph> | ||
<Divider | ||
style={{ | ||
margin: "18px 0", | ||
}} | ||
/> | ||
<MoreInfoHint /> | ||
</Modal> | ||
); | ||
} | ||
|
||
const PythonClientModalView = makeComponentLazy(_PythonClientModalView); | ||
export default PythonClientModalView; |
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
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