Skip to content

Commit

Permalink
Merge pull request #58 from unicef-drp/Dashboard_enhancements
Browse files Browse the repository at this point in the history
More URL fixes
  • Loading branch information
Amy-Reidy authored Jan 24, 2024
2 parents ac30600 + e3d1d16 commit 988230e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dash_service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def reroute_transmonee_root():

@server.route("/transmonee/<path:page>")
def reroute_transmonee(page):
return redirect(f"/{page}?prj=tm")
return redirect(f"/?prj=tm&page={page}")


app = Dash(
Expand Down
28 changes: 14 additions & 14 deletions dash_service/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,19 @@ def apply_update_indicator_dropdown_class(indicator):
@callback(
Output("themes", "children"),
[Input("domain-dropdown", "value"),
Input("url", "pathname")],
Input("url", "search")],
[State("initial-load", "data")],
prevent_initial_call=True
)
def apply_create_subdomain_buttons(domain_dropdown_value, url_pathname, initial_load_data):
def apply_create_subdomain_buttons(domain_dropdown_value, url_search, initial_load_data):
ctx = callback_context
trigger_id = ctx.triggered[0]['prop_id']

# Check if it's the initial load or domain-dropdown value change
initial_load = initial_load_data.get('is_first_load', True)
if initial_load or "domain-dropdown.value" in trigger_id:
# Create and return subdomain buttons
return create_subdomain_buttons(domain_dropdown_value, initial_load, url_pathname)
return create_subdomain_buttons(domain_dropdown_value, initial_load, url_search)

# If not triggered by the initial load or domain-dropdown change, do not update
return dash.no_update
Expand All @@ -280,23 +280,23 @@ def set_active_subdomain_button(button_clicks, buttons_id):

@callback(
Output('initial-load', 'data'),
Input('url', 'pathname'),
Input('url', 'search'),
prevent_initial_call=True
)
def set_initial_load_flag(pathname):
def set_initial_load_flag(search):
return {'is_first_load': False}

@callback(
Output("domain-dropdown", "value"),
Input('url', 'pathname'),
Input('url', 'search'),
Input('initial-load', 'data'),
#prevent_initial_call=True
)
def update_domain_dropdown_on_initial_load(pathname, load_data):
def update_domain_dropdown_on_initial_load(search, load_data):
if load_data['is_first_load']:
print("First load")
print(pathname)
subdomain_code = pathname.strip('/transmonee-dashboard/')
print(search)
subdomain_code = search.strip('?prj=tm&page=')
if not subdomain_code:
subdomain_code = 'DEM' # Set 'DEM' by default if subdomain_code is empty
domain_value = update_domain_with_url(subdomain_code) # Map subdomain to domain
Expand All @@ -305,7 +305,7 @@ def update_domain_dropdown_on_initial_load(pathname, load_data):

# Callback to update the URL based on the active button
@callback(
Output('url', 'pathname'),
Output('url', 'search'),
Input({"type": "subdomain_button", "index": ALL}, "active"),
Input({'type': "nav_buttons", 'index': "crm_view"}, 'active'),
State({"type": "subdomain_button", "index": ALL}, "id")
Expand All @@ -314,12 +314,12 @@ def update_url(active_buttons, crm_view, buttons_id):
if crm_view:
active_button_id = [button['index'] for button, is_active in zip(buttons_id, active_buttons) if is_active]
if active_button_id:
new_url = f'/transmonee-dashboard/{active_button_id[0]}'
print(f"active button: {new_url.lstrip('/')}")
return new_url
new_search = f'?prj=tm&page={active_button_id[0]}'
print(f"active button: {new_search.lstrip('?prj=tm&page=')}")
return new_search
else:
return dash.no_update
return "/transmonee-dashboard/"
return "?prj=tm"

@callback(
Output({"type": "button_group", "index": "AIO_AREA"}, "children"),
Expand Down
4 changes: 2 additions & 2 deletions dash_service/pages/transmonee.py
Original file line number Diff line number Diff line change
Expand Up @@ -2401,14 +2401,14 @@ def get_filters(years_slider, countries, country_group):
)
return (filter_dict, filter_countries, selected_years, country_text)

def create_subdomain_buttons(domain_dropdown_value, initial_load, url_pathname):
def create_subdomain_buttons(domain_dropdown_value, initial_load, url_search):
buttons = []
if domain_dropdown_value:
_, domain_page_path = domain_dropdown_value.split("|")
domain_info = merged_page_config.get(domain_page_path)

# Extract and strip the subdomain code from the URL
url_subdomain_code = url_pathname.strip('/transmonee-dashboard/') if url_pathname else ''
url_subdomain_code = url_search.strip('?prj=tm&page=') if url_search else ''

if domain_info:
page_prefix = domain_info.get('page_prefix')
Expand Down

0 comments on commit 988230e

Please sign in to comment.