Skip to content

Commit 3d692ab

Browse files
authored
Merge pull request #448 from apjanusz/main
add possibility to hide share button and change some frontend(#406)
2 parents c3d6919 + c4d103a commit 3d692ab

9 files changed

Lines changed: 64 additions & 29 deletions

File tree

frontend/src/components/SideBar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type SideBarProps = {
7171
continuousUpdate: boolean;
7272
staticNotebook: boolean;
7373
allowDownload: boolean;
74+
allowShare: boolean;
7475
};
7576

7677
export default function SideBar({
@@ -90,6 +91,7 @@ export default function SideBar({
9091
continuousUpdate,
9192
staticNotebook,
9293
allowDownload,
94+
allowShare,
9395
}: SideBarProps) {
9496
const dispatch = useDispatch();
9597
const widgetsValues: Record<string, WidgetValueType> = useSelector(
@@ -516,6 +518,7 @@ export default function SideBar({
516518
notebookTitle={notebookTitle}
517519
staticNotebook={staticNotebook}
518520
allowDownload={allowDownload}
521+
allowShare={allowShare}
519522
waiting={waiting}
520523
continuousUpdate={continuousUpdate}
521524
runDownloadHTML={runDownloadHTML}

frontend/src/components/StatusBar.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { setShowShareDialog } from "../slices/appSlice";
1515

1616
type Props = {
1717
allowDownload: boolean;
18+
allowShare: boolean;
1819
waiting: boolean;
1920
continuousUpdate: boolean;
2021
staticNotebook: boolean;
@@ -27,6 +28,7 @@ type Props = {
2728

2829
export default function StatusBar({
2930
allowDownload,
31+
allowShare,
3032
waiting,
3133
continuousUpdate,
3234
staticNotebook,
@@ -121,11 +123,13 @@ export default function StatusBar({
121123
{allowDownload && (
122124
<div
123125
className="dropdown mx-2 btn-group"
124-
style={{
125-
//display: "inline",
126-
// width: "47%",
127-
// float: continuousUpdate ? "left" : "right",
128-
}}
126+
style={
127+
{
128+
//display: "inline",
129+
// width: "47%",
130+
// float: continuousUpdate ? "left" : "right",
131+
}
132+
}
129133
>
130134
<button
131135
className="btn btn-sm btn-primary dropdown-toggle"
@@ -199,31 +203,33 @@ export default function StatusBar({
199203
</ul>
200204
</div>
201205
)}
202-
<button
203-
className="btn btn-sm btn-primary"
204-
onClick={() => dispatch(setShowShareDialog(true))}
205-
disabled={waiting}
206-
>
207-
<svg
208-
xmlns="http://www.w3.org/2000/svg"
209-
width="14"
210-
height="14"
211-
viewBox="0 0 24 24"
212-
strokeWidth="2"
213-
stroke="currentColor"
214-
fill="none"
215-
strokeLinecap="round"
216-
strokeLinejoin="round"
206+
{allowShare && (
207+
<button
208+
className="btn btn-sm btn-primary"
209+
onClick={() => dispatch(setShowShareDialog(true))}
210+
disabled={waiting}
217211
>
218-
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
219-
<path d="M6 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
220-
<path d="M18 6m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
221-
<path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
222-
<path d="M8.7 10.7l6.6 -3.4"></path>
223-
<path d="M8.7 13.3l6.6 3.4"></path>
224-
</svg>{" "}
225-
Share
226-
</button>
212+
<svg
213+
xmlns="http://www.w3.org/2000/svg"
214+
width="14"
215+
height="14"
216+
viewBox="0 0 24 24"
217+
strokeWidth="2"
218+
stroke="currentColor"
219+
fill="none"
220+
strokeLinecap="round"
221+
strokeLinejoin="round"
222+
>
223+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
224+
<path d="M6 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
225+
<path d="M18 6m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
226+
<path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
227+
<path d="M8.7 10.7l6.6 -3.4"></path>
228+
<path d="M8.7 13.3l6.6 3.4"></path>
229+
</svg>{" "}
230+
Share
231+
</button>
232+
)}
227233
</div>
228234
</div>
229235
);

frontend/src/slices/notebooksSlice.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface INotebookParams {
4141
show_sidebar: boolean;
4242
full_screen: boolean;
4343
allow_download: boolean;
44+
allow_share: boolean;
4445
}
4546

4647
export interface INotebook {

frontend/src/views/AppView.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ function App({ isSingleApp, notebookSlug, displayEmbed }: AppProps) {
189189
return true;
190190
};
191191

192+
const doAllowShare = () => {
193+
if (notebook !== undefined && notebook !== null) {
194+
return notebook?.params?.allow_share !== undefined &&
195+
notebook?.params?.allow_share !== null
196+
? notebook.params.allow_share
197+
: true;
198+
}
199+
return true;
200+
}
201+
192202
useEffect(() => {
193203
if (logoFilename === "") {
194204
setLogoSrc(DefaultLogoSrc);
@@ -243,6 +253,7 @@ function App({ isSingleApp, notebookSlug, displayEmbed }: AppProps) {
243253
continuousUpdate={notebook?.params?.continuous_update}
244254
staticNotebook={notebook?.params?.static_notebook}
245255
allowDownload={doAllowDownload()}
256+
allowShare={doAllowShare()}
246257
/>
247258
)}
248259

frontend/src/views/HomeView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ export default function HomeView() {
183183
title={`Open ${notebook.title}`}
184184
>
185185
<i className="fa fa-chevron-right" aria-hidden="true" />
186+
<i className="fa fa-chevron-right" aria-hidden="true" />
186187
</button>
187188
)}
189+
188190
</Link>
189191
</div>
190192
</div>

mercury/apps/nbworker/rest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def update_notebook(self, new_params):
8585
"show_sidebar",
8686
"full_screen",
8787
"allow_download",
88+
"allow_share",
8889
"stop_on_error",
8990
]:
9091
if new_params.get(property) is not None and nb_params.get(

mercury/apps/ws/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def parse_params(nb, params={}):
133133
"show_sidebar",
134134
"full_screen",
135135
"allow_download",
136+
"allow_share",
136137
"stop_on_error",
137138
]:
138139
if view.get(property) is not None:
@@ -159,6 +160,8 @@ def parse_params(nb, params={}):
159160
params["full_screen"] = True
160161
if params.get("allow_download") is None:
161162
params["allow_download"] = True
163+
if params.get("allow_share") is None:
164+
params["allow_share"] = True
162165
if params.get("stop_on_error") is None:
163166
params["stop_on_error"] = False
164167

mercury/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ cryptography
2626
pyopenssl>=23.1.1
2727
bleach>=6.0.0
2828
itables>=2.0.0
29+

mercury/widgets/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class App:
6969
If True (the default), a Download button is available to export results as
7070
a PDF or HTML file. Set to False to hide the Download button.
7171
72+
allow_share : bool, default True
73+
If True (the default), a Share button is available to export results as a
74+
URL. Set to False to hide the Share button.
75+
7276
stop_on_error : bool, default False
7377
If True, the notebook will stop execution when an error occurs in a cell.
7478
The default is False, meaning the notebook will execute all cells even with
@@ -100,6 +104,7 @@ def __init__(
100104
show_sidebar=True,
101105
full_screen=True,
102106
allow_download=True,
107+
allow_share=True,
103108
stop_on_error=False,
104109
):
105110
self.code_uid = WidgetsManager.get_code_uid("App")
@@ -115,6 +120,7 @@ def __init__(
115120
self.show_sidebar = show_sidebar
116121
self.full_screen = full_screen
117122
self.allow_download = allow_download
123+
self.allow_share = allow_share
118124
self.stop_on_error = stop_on_error
119125
display(self)
120126

@@ -141,6 +147,7 @@ def _repr_mimebundle_(self, **kwargs):
141147
"show_sidebar": self.show_sidebar,
142148
"full_screen": self.full_screen,
143149
"allow_download": self.allow_download,
150+
"allow_share": self.allow_share,
144151
"stop_on_error": self.stop_on_error,
145152
"model_id": "mercury-app",
146153
"code_uid": self.code_uid,

0 commit comments

Comments
 (0)