From 8303467e31e78e1c32b29f09a1e9176f4c732845 Mon Sep 17 00:00:00 2001 From: Miles Mason Winther <42948872+mmwinther@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:14:39 +0100 Subject: [PATCH] Populate variables information text (#213) --- .../frontend/callbacks/register_callbacks.py | 16 ++++++++++++++-- src/datadoc/frontend/components/builders.py | 5 ----- src/datadoc/frontend/components/variables_tab.py | 9 +++++---- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/datadoc/frontend/callbacks/register_callbacks.py b/src/datadoc/frontend/callbacks/register_callbacks.py index 7fa8e8af..f13aae85 100644 --- a/src/datadoc/frontend/callbacks/register_callbacks.py +++ b/src/datadoc/frontend/callbacks/register_callbacks.py @@ -29,6 +29,8 @@ from datadoc.frontend.components.builders import build_ssb_accordion from datadoc.frontend.components.dataset_tab import DATASET_METADATA_INPUT from datadoc.frontend.components.dataset_tab import build_dataset_metadata_accordion +from datadoc.frontend.components.variables_tab import ACCORDION_WRAPPER_ID +from datadoc.frontend.components.variables_tab import VARIABLES_INFORMATION_ID from datadoc.frontend.fields.display_base import VARIABLES_METADATA_DATE_INPUT from datadoc.frontend.fields.display_base import VARIABLES_METADATA_INPUT from datadoc.frontend.fields.display_dataset import DISPLAYED_DROPDOWN_DATASET_METADATA @@ -161,11 +163,21 @@ def callback_clear_accordion_values(n_clicks: int) -> list[dbc.AccordionItem]: return no_update @app.callback( - Output("accordion-wrapper", "children"), + Output(VARIABLES_INFORMATION_ID, "children"), Input("language-dropdown", "value"), prevent_initial_call=True, ) - def callback_populate_new_variables_workspace( + def callback_populate_variables_info_section( + language: str, # noqa: ARG001 Dash requires arguments for all Inputs + ) -> str: + return f"Datasettet inneholder {len(state.metadata.variables)} variabler." + + @app.callback( + Output(ACCORDION_WRAPPER_ID, "children"), + Input("language-dropdown", "value"), + prevent_initial_call=True, + ) + def callback_populate_variables_workspace( language: str, ) -> list: """Create variable workspace with accordions for variables.""" diff --git a/src/datadoc/frontend/components/builders.py b/src/datadoc/frontend/components/builders.py index 4a8b6376..d1ee188e 100644 --- a/src/datadoc/frontend/components/builders.py +++ b/src/datadoc/frontend/components/builders.py @@ -110,11 +110,6 @@ def build_ssb_button(text: str, icon_class: str, button_id: str) -> dbc.Button: ) -info_section = ( - "Informasjon om hvordan jobbe i Datadoc, antall variabler i datasettet: osv.." -) - - def build_input_field_section( metadata_fields: list[VariablesFieldTypes], variable: model.Variable, diff --git a/src/datadoc/frontend/components/variables_tab.py b/src/datadoc/frontend/components/variables_tab.py index d5d411fe..11e738ba 100644 --- a/src/datadoc/frontend/components/variables_tab.py +++ b/src/datadoc/frontend/components/variables_tab.py @@ -7,7 +7,9 @@ from dash import html from datadoc.frontend.components.builders import build_ssb_styled_tab -from datadoc.frontend.components.builders import info_section + +VARIABLES_INFORMATION_ID = "variables-information" +ACCORDION_WRAPPER_ID = "accordion-wrapper" def build_variables_tab() -> dbc.Tab: @@ -24,8 +26,7 @@ def build_variables_tab() -> dbc.Tab: className="variables-title", ), ssb.Paragraph( - info_section, - id="variables-information", + id=VARIABLES_INFORMATION_ID, ), ssb.Input( label="Søk i variabler", @@ -40,7 +41,7 @@ def build_variables_tab() -> dbc.Tab: className="variables-header", ), html.Main( - id="accordion-wrapper", + id=ACCORDION_WRAPPER_ID, className="main-content", ), ],