Namespacing des dcc.Location pour éviter les conflits entre pages

This commit is contained in:
Colin Maudry
2026-01-24 14:35:12 +01:00
parent 937e8be356
commit bd64c397dc
3 changed files with 10 additions and 9 deletions
+2 -2
View File
@@ -25,7 +25,7 @@ register_page(
layout = [ layout = [
dcc.Store(id="marche_data"), dcc.Store(id="marche_data"),
dcc.Store(id="titulaires_data"), dcc.Store(id="titulaires_data"),
dcc.Location(id="url", refresh="callback-nav"), dcc.Location(id="marche_url", refresh="callback-nav"),
dbc.Container( dbc.Container(
className="marche_infos", className="marche_infos",
children=[ children=[
@@ -73,7 +73,7 @@ layout = [
@callback( @callback(
Output("marche_data", "data"), Output("marche_data", "data"),
Output("titulaires_data", "data"), Output("titulaires_data", "data"),
Input(component_id="url", component_property="pathname"), Input(component_id="marche_url", component_property="pathname"),
) )
def get_marche_data(url) -> tuple[dict, list]: def get_marche_data(url) -> tuple[dict, list]:
marche_uid = url.split("/")[-1] marche_uid = url.split("/")[-1]
+5 -4
View File
@@ -47,7 +47,7 @@ datatable = html.Div(
) )
layout = [ layout = [
dcc.Location(id="url", refresh=False), dcc.Location(id="tableau_url", refresh=False),
html.Div( html.Div(
html.Details( html.Details(
children=[ children=[
@@ -190,8 +190,8 @@ def download_data(n_clicks, filter_query, sort_by, hidden_columns: list = None):
Output("table", "filter_query"), Output("table", "filter_query"),
Output("table", "sort_by"), Output("table", "sort_by"),
Output("table", "hidden_columns"), Output("table", "hidden_columns"),
Output("url", "search", allow_duplicate=True), Output("tableau_url", "search", allow_duplicate=True),
Input("url", "search"), Input("tableau_url", "search"),
prevent_initial_call=True, prevent_initial_call=True,
) )
def restore_view_from_url(search): def restore_view_from_url(search):
@@ -228,7 +228,8 @@ def restore_view_from_url(search):
Input("table", "filter_query"), Input("table", "filter_query"),
Input("table", "sort_by"), Input("table", "sort_by"),
Input("table", "hidden_columns"), Input("table", "hidden_columns"),
State("url", "href"), State("tableau_url", "href"),
prevent_initial_call=True,
) )
def sync_url_and_reset_button(filter_query, sort_by, hidden_columns, href): def sync_url_and_reset_button(filter_query, sort_by, hidden_columns, href):
if not href: if not href:
+3 -3
View File
@@ -47,7 +47,7 @@ datatable = html.Div(
layout = [ layout = [
dcc.Store(id="titulaire_data", storage_type="memory"), dcc.Store(id="titulaire_data", storage_type="memory"),
dcc.Location(id="url", refresh="callback-nav"), dcc.Location(id="titulaire_url", refresh="callback-nav"),
html.Div( html.Div(
children=[ children=[
html.Div( html.Div(
@@ -152,7 +152,7 @@ layout = [
Output(component_id="titulaire_departement", component_property="children"), Output(component_id="titulaire_departement", component_property="children"),
Output(component_id="titulaire_region", component_property="children"), Output(component_id="titulaire_region", component_property="children"),
Output(component_id="titulaire_lien_annuaire", component_property="href"), Output(component_id="titulaire_lien_annuaire", component_property="href"),
Input(component_id="url", component_property="pathname"), Input(component_id="titulaire_url", component_property="pathname"),
) )
def update_titulaire_infos(url): def update_titulaire_infos(url):
titulaire_siret = url.split("/")[-1] titulaire_siret = url.split("/")[-1]
@@ -219,7 +219,7 @@ def update_titulaire_stats(data):
Output("btn-download-data-titulaire", "disabled"), Output("btn-download-data-titulaire", "disabled"),
Output("btn-download-data-titulaire", "children"), Output("btn-download-data-titulaire", "children"),
Output("btn-download-data-titulaire", "title"), Output("btn-download-data-titulaire", "title"),
Input(component_id="url", component_property="pathname"), Input(component_id="titulaire_url", component_property="pathname"),
Input(component_id="titulaire_year", component_property="value"), Input(component_id="titulaire_year", component_property="value"),
) )
def get_titulaire_marches_data(url, titulaire_year: str) -> tuple: def get_titulaire_marches_data(url, titulaire_year: str) -> tuple: