Skip to content

Commit

Permalink
manage no update case (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
MateoLostanlen authored Jan 24, 2024
1 parent 58e9692 commit e728935
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/callbacks/data_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def login_callback(n_clicks, username, password, user_headers):
[
Output("store_api_events_data", "data"),
Output("store_api_alerts_data", "data"),
Output("trigger_no_events", "data"),
],
[Input("main_api_fetch_interval", "n_intervals")],
[
Expand Down Expand Up @@ -117,6 +118,8 @@ def api_watcher(n_intervals, local_events, local_alerts, user_headers, user_cred
# Fetch events
api_events = pd.DataFrame(call_api(api_client.get_unacknowledged_events, user_credentials)())
api_events = past_ndays_api_events(api_events, n_days=1) # keep only events from today
if api_events.empty:
return dash.no_update, dash.no_update, True
api_events = api_events[::-1] # Display the last alert first

if event_data_loaded:
Expand Down Expand Up @@ -179,6 +182,7 @@ def api_watcher(n_intervals, local_events, local_alerts, user_headers, user_cred
return [
json.dumps({"data": local_events.to_json(orient="split"), "data_loaded": True}),
json.dumps({"data": local_alerts.to_json(orient="split"), "data_loaded": True}),
dash.no_update,
]


Expand Down
6 changes: 4 additions & 2 deletions app/callbacks/display_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
# Loading initial data
@app.callback(
Output("modal-loading", "is_open"),
[Input("media_url", "data"), Input("user_headers", "data")],
[Input("media_url", "data"), Input("user_headers", "data"), Input("trigger_no_events", "data")],
State("store_api_alerts_data", "data"),
prevent_initial_call=True,
)
def toggle_modal(media_url, user_headers, local_alerts):
def toggle_modal(media_url, user_headers, local_alerts, trigger_no_events):
"""
Toggles the visibility of the loading modal waiting for the load of media_url
Expand All @@ -36,6 +36,8 @@ def toggle_modal(media_url, user_headers, local_alerts):
Returns:
- bool: True to show the modal, False to hide it.
"""
if trigger_no_events:
return False
if user_headers is None:
raise PreventUpdate
local_alerts, alerts_data_loaded = read_stored_DataFrame(local_alerts)
Expand Down
1 change: 1 addition & 0 deletions app/layouts/main_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ def get_main_layout():
# [TEMPORARY FIX] Storing the user's credentials to refresh the token when needed
dcc.Store(id="user_credentials", storage_type="session", data=user_credentials),
dcc.Store(id="to_acknowledge", data=0),
dcc.Store(id="trigger_no_events", data=False),
]
)

0 comments on commit e728935

Please sign in to comment.