Skip to content

Commit

Permalink
Merge pull request #448 from apjanusz/main
Browse files Browse the repository at this point in the history
add possibility to hide share button and change some frontend(#406)
  • Loading branch information
pplonski authored May 10, 2024
2 parents c3d6919 + c4d103a commit 3d692ab
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 29 deletions.
3 changes: 3 additions & 0 deletions frontend/src/components/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type SideBarProps = {
continuousUpdate: boolean;
staticNotebook: boolean;
allowDownload: boolean;
allowShare: boolean;
};

export default function SideBar({
Expand All @@ -90,6 +91,7 @@ export default function SideBar({
continuousUpdate,
staticNotebook,
allowDownload,
allowShare,
}: SideBarProps) {
const dispatch = useDispatch();
const widgetsValues: Record<string, WidgetValueType> = useSelector(
Expand Down Expand Up @@ -516,6 +518,7 @@ export default function SideBar({
notebookTitle={notebookTitle}
staticNotebook={staticNotebook}
allowDownload={allowDownload}
allowShare={allowShare}
waiting={waiting}
continuousUpdate={continuousUpdate}
runDownloadHTML={runDownloadHTML}
Expand Down
64 changes: 35 additions & 29 deletions frontend/src/components/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { setShowShareDialog } from "../slices/appSlice";

type Props = {
allowDownload: boolean;
allowShare: boolean;
waiting: boolean;
continuousUpdate: boolean;
staticNotebook: boolean;
Expand All @@ -27,6 +28,7 @@ type Props = {

export default function StatusBar({
allowDownload,
allowShare,
waiting,
continuousUpdate,
staticNotebook,
Expand Down Expand Up @@ -121,11 +123,13 @@ export default function StatusBar({
{allowDownload && (
<div
className="dropdown mx-2 btn-group"
style={{
//display: "inline",
// width: "47%",
// float: continuousUpdate ? "left" : "right",
}}
style={
{
//display: "inline",
// width: "47%",
// float: continuousUpdate ? "left" : "right",
}
}
>
<button
className="btn btn-sm btn-primary dropdown-toggle"
Expand Down Expand Up @@ -199,31 +203,33 @@ export default function StatusBar({
</ul>
</div>
)}
<button
className="btn btn-sm btn-primary"
onClick={() => dispatch(setShowShareDialog(true))}
disabled={waiting}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="14"
height="14"
viewBox="0 0 24 24"
strokeWidth="2"
stroke="currentColor"
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
{allowShare && (
<button
className="btn btn-sm btn-primary"
onClick={() => dispatch(setShowShareDialog(true))}
disabled={waiting}
>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
<path d="M18 6m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
<path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
<path d="M8.7 10.7l6.6 -3.4"></path>
<path d="M8.7 13.3l6.6 3.4"></path>
</svg>{" "}
Share
</button>
<svg
xmlns="http://www.w3.org/2000/svg"
width="14"
height="14"
viewBox="0 0 24 24"
strokeWidth="2"
stroke="currentColor"
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
<path d="M18 6m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
<path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
<path d="M8.7 10.7l6.6 -3.4"></path>
<path d="M8.7 13.3l6.6 3.4"></path>
</svg>{" "}
Share
</button>
)}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/slices/notebooksSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface INotebookParams {
show_sidebar: boolean;
full_screen: boolean;
allow_download: boolean;
allow_share: boolean;
}

export interface INotebook {
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/views/AppView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ function App({ isSingleApp, notebookSlug, displayEmbed }: AppProps) {
return true;
};

const doAllowShare = () => {
if (notebook !== undefined && notebook !== null) {
return notebook?.params?.allow_share !== undefined &&
notebook?.params?.allow_share !== null
? notebook.params.allow_share
: true;
}
return true;
}

useEffect(() => {
if (logoFilename === "") {
setLogoSrc(DefaultLogoSrc);
Expand Down Expand Up @@ -243,6 +253,7 @@ function App({ isSingleApp, notebookSlug, displayEmbed }: AppProps) {
continuousUpdate={notebook?.params?.continuous_update}
staticNotebook={notebook?.params?.static_notebook}
allowDownload={doAllowDownload()}
allowShare={doAllowShare()}
/>
)}

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/views/HomeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ export default function HomeView() {
title={`Open ${notebook.title}`}
>
<i className="fa fa-chevron-right" aria-hidden="true" />
<i className="fa fa-chevron-right" aria-hidden="true" />
</button>
)}

</Link>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions mercury/apps/nbworker/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def update_notebook(self, new_params):
"show_sidebar",
"full_screen",
"allow_download",
"allow_share",
"stop_on_error",
]:
if new_params.get(property) is not None and nb_params.get(
Expand Down
3 changes: 3 additions & 0 deletions mercury/apps/ws/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def parse_params(nb, params={}):
"show_sidebar",
"full_screen",
"allow_download",
"allow_share",
"stop_on_error",
]:
if view.get(property) is not None:
Expand All @@ -159,6 +160,8 @@ def parse_params(nb, params={}):
params["full_screen"] = True
if params.get("allow_download") is None:
params["allow_download"] = True
if params.get("allow_share") is None:
params["allow_share"] = True
if params.get("stop_on_error") is None:
params["stop_on_error"] = False

Expand Down
1 change: 1 addition & 0 deletions mercury/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ cryptography
pyopenssl>=23.1.1
bleach>=6.0.0
itables>=2.0.0

7 changes: 7 additions & 0 deletions mercury/widgets/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class App:
If True (the default), a Download button is available to export results as
a PDF or HTML file. Set to False to hide the Download button.
allow_share : bool, default True
If True (the default), a Share button is available to export results as a
URL. Set to False to hide the Share button.
stop_on_error : bool, default False
If True, the notebook will stop execution when an error occurs in a cell.
The default is False, meaning the notebook will execute all cells even with
Expand Down Expand Up @@ -100,6 +104,7 @@ def __init__(
show_sidebar=True,
full_screen=True,
allow_download=True,
allow_share=True,
stop_on_error=False,
):
self.code_uid = WidgetsManager.get_code_uid("App")
Expand All @@ -115,6 +120,7 @@ def __init__(
self.show_sidebar = show_sidebar
self.full_screen = full_screen
self.allow_download = allow_download
self.allow_share = allow_share
self.stop_on_error = stop_on_error
display(self)

Expand All @@ -141,6 +147,7 @@ def _repr_mimebundle_(self, **kwargs):
"show_sidebar": self.show_sidebar,
"full_screen": self.full_screen,
"allow_download": self.allow_download,
"allow_share": self.allow_share,
"stop_on_error": self.stop_on_error,
"model_id": "mercury-app",
"code_uid": self.code_uid,
Expand Down

0 comments on commit 3d692ab

Please sign in to comment.