Skip to content

Commit 220531e

Browse files
Dashboard: Add documentation sidebar (#836)
* Add sidebar for documentation Instead of opening a new tab to the documentation when users click on the info button on a section header, the documentation is integrated onto the dashboard and is shown through a drawer style ui * update documentation still may be wrong link * remove unused styling * fix importing issues * move function to GeneralFunctions Future pr needs to split up generalFunctions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7b22e71 commit 220531e

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

src/python/impactx/dashboard/Input/components.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
server, state, ctrl = setup_server()
88

9+
state.documentation_drawer_open = False
10+
state.documentation_url = ""
11+
912

1013
class CardComponents:
1114
"""
@@ -41,7 +44,7 @@ def documentation_icon(section_name: str) -> vuetify.VIcon:
4144
return vuetify.VIcon(
4245
"mdi-information",
4346
style="color: #00313C;",
44-
click=lambda: generalFunctions.documentation(section_name),
47+
click=lambda: generalFunctions.open_documentation(section_name),
4548
)
4649

4750
@staticmethod
@@ -187,3 +190,21 @@ def create_dialog_tabs(name: str, num_tabs: int, tab_names: list[str]) -> None:
187190
for tab_name in tab_names:
188191
vuetify.VTab(tab_name)
189192
vuetify.VDivider()
193+
194+
@staticmethod
195+
def create_documentation_drawer():
196+
with vuetify.VNavigationDrawer(
197+
v_model=("documentation_drawer_open",),
198+
absolute=True,
199+
right=True,
200+
hide_overlay=True,
201+
style="width: 30vw; top: 64px !important; position: fixed;",
202+
):
203+
with vuetify.VContainer(
204+
fluid=True,
205+
classes="pa-0 fill-height",
206+
):
207+
html.Iframe(
208+
src=("documentation_url",),
209+
style="width: 100%; height: 100%; border: none;",
210+
)

src/python/impactx/dashboard/Input/defaults.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ class DashboardDefaults:
119119
"emitt": "m",
120120
}
121121

122+
DOCUMENTATION = {
123+
"input_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#impactx.ImpactX",
124+
"lattice_configuration": "https://impactx.readthedocs.io/en/latest/usage/python.html#lattice-elements",
125+
"distribution_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#initial-beam-distributions",
126+
"space_charge": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#space-charge",
127+
"csr": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#coherent-synchrotron-radiation-csr",
128+
}
129+
122130

123131
class TooltipDefaults:
124132
"""

src/python/impactx/dashboard/Input/generalFunctions.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
"""
88

99
import inspect
10-
import os
1110
import re
12-
import subprocess
13-
import webbrowser
1411

1512
from .. import setup_server
1613
from .defaults import DashboardDefaults
@@ -24,27 +21,20 @@
2421

2522
class generalFunctions:
2623
@staticmethod
27-
def documentation(section_name):
24+
def open_documentation(section_name):
2825
"""
29-
Opens a tab to the specified section link in the documentation.
30-
:param section_name (str): The name of the documentation section to open.
26+
Retrieves the documentation link with the provided section_name
27+
and opens the documentation sidebar on the dashoard.
28+
29+
:param section_name: The name for the input section.
3130
"""
32-
url_dict = {
33-
"input_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#general",
34-
"lattice_configuration": "https://impactx.readthedocs.io/en/latest/usage/python.html#lattice-elements",
35-
"distribution_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#initial-beam-distributions",
36-
"space_charge": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#space-charge",
37-
"csr": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#coherent-synchrotron-radiation-csr",
38-
}
39-
40-
url = url_dict.get(section_name)
41-
if url is None:
42-
raise ValueError(f"Invalid section name: {section_name}")
43-
44-
if "WSL_DISTRO_NAME" in os.environ:
45-
subprocess.run(["explorer.exe", url])
31+
32+
new_url = DashboardDefaults.DOCUMENTATION.get(section_name)
33+
if state.documentation_drawer_open and state.documentation_url == new_url:
34+
state.documentation_drawer_open = False
4635
else:
47-
webbrowser.open_new_tab(url)
36+
state.documentation_url = new_url
37+
state.documentation_drawer_open = True
4838

4939
@staticmethod
5040
def get_default(parameter, type):

src/python/impactx/dashboard/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"html",
2323
"JupyterApp",
2424
"setup_server",
25+
"html",
2526
"vuetify",
2627
"AnalyzeSimulation",
2728
"NavigationComponents",

src/python/impactx/dashboard/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def application():
9090
NavigationComponents.create_route("Analyze", "mdi-chart-box-multiple")
9191

9292
with layout.content:
93+
NavigationComponents.create_documentation_drawer()
9394
router.RouterView()
9495
init_terminal()
9596
return layout

0 commit comments

Comments
 (0)