From 8931e1b8465e11a6427a99550fcbbf0fcc8698c1 Mon Sep 17 00:00:00 2001 From: Jorgen-5 Date: Wed, 13 Mar 2024 16:28:02 +0100 Subject: [PATCH 1/4] Correct categorisation of dataset fields (#221) * Made multiple dataset fields obligatory * Fixed progress bar test --------- Co-authored-by: rlj --- src/datadoc/frontend/fields/display_dataset.py | 5 +++++ tests/backend/test_datadoc_metadata.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/datadoc/frontend/fields/display_dataset.py b/src/datadoc/frontend/fields/display_dataset.py index 7a12b030..e4b36982 100644 --- a/src/datadoc/frontend/fields/display_dataset.py +++ b/src/datadoc/frontend/fields/display_dataset.py @@ -135,6 +135,7 @@ class DatasetIdentifiers(str, Enum): get_enum_options_for_language, enums.DataSetStatus, ), + obligatory=True, ), DatasetIdentifiers.DATASET_STATE: DisplayDatasetMetadataDropdown( identifier=DatasetIdentifiers.DATASET_STATE.value, @@ -185,6 +186,7 @@ class DatasetIdentifiers(str, Enum): display_name="Versjonsbeskrivelse", description="Årsak/grunnlag for denne versjonen av datasettet i form av beskrivende tekst.", multiple_language_support=True, + obligatory=True, ), DatasetIdentifiers.UNIT_TYPE: DisplayDatasetMetadataDropdown( identifier=DatasetIdentifiers.UNIT_TYPE.value, @@ -192,6 +194,7 @@ class DatasetIdentifiers(str, Enum): description="Primær enhetstype for datafil, datatabell eller datasett. Se Vi jobber med en avklaring av behov for flere enhetstyper her.", multiple_language_support=False, options_getter=get_unit_type_options, + obligatory=True, ), DatasetIdentifiers.TEMPORALITY_TYPE: DisplayDatasetMetadataDropdown( identifier=DatasetIdentifiers.TEMPORALITY_TYPE.value, @@ -201,12 +204,14 @@ class DatasetIdentifiers(str, Enum): get_enum_options_for_language, enums.TemporalityTypeType, ), + obligatory=True, ), DatasetIdentifiers.DESCRIPTION: DisplayDatasetMetadata( identifier=DatasetIdentifiers.DESCRIPTION.value, display_name="Beskrivelse", description="Beskrivelse av datasettet", multiple_language_support=True, + obligatory=True, ), DatasetIdentifiers.SUBJECT_FIELD: DisplayDatasetMetadataDropdown( identifier=DatasetIdentifiers.SUBJECT_FIELD.value, diff --git a/tests/backend/test_datadoc_metadata.py b/tests/backend/test_datadoc_metadata.py index ebd23484..2034e7cc 100644 --- a/tests/backend/test_datadoc_metadata.py +++ b/tests/backend/test_datadoc_metadata.py @@ -77,7 +77,7 @@ def test_metadata_document_percent_complete(metadata: DataDocMetadata): metadata.dataset = document.dataset # type: ignore [assignment] metadata.variables = document.variables # type: ignore [assignment] - assert metadata.percent_complete == 16 # noqa: PLR2004 + assert metadata.percent_complete == 12 # noqa: PLR2004 def test_write_metadata_document( From ab3871c5336f9455e53813989cac1a11b49a0718 Mon Sep 17 00:00:00 2001 From: tilen1976 <68303562+tilen1976@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:29:08 +0100 Subject: [PATCH 2/4] build edit section --- src/datadoc/frontend/components/builders.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/datadoc/frontend/components/builders.py b/src/datadoc/frontend/components/builders.py index d1ee188e..9813ac1b 100644 --- a/src/datadoc/frontend/components/builders.py +++ b/src/datadoc/frontend/components/builders.py @@ -151,6 +151,17 @@ def build_edit_section( ) +def build_dataset_edit_section(title: str) -> html.Section: + """Create edit section for dataset.""" + return html.Section( + id={"type": "dataset-edit-section", "title": title}, + children=[ + ssb.Title(title, size=3, className="input-section-title"), + ], + className="dataset-edit-section", + ) + + def build_ssb_accordion( header: str, key: dict, From 15cc786f72b2eef40482e18362e46419623f7e00 Mon Sep 17 00:00:00 2001 From: tilen1976 <68303562+tilen1976@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:42:18 +0100 Subject: [PATCH 3/4] New dataset tab ok --- src/datadoc/app.py | 2 ++ .../frontend/callbacks/register_callbacks.py | 15 +++++++++++++++ src/datadoc/frontend/components/dataset_tab.py | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/datadoc/app.py b/src/datadoc/app.py index 67adfa13..a962ec14 100644 --- a/src/datadoc/app.py +++ b/src/datadoc/app.py @@ -29,6 +29,7 @@ from datadoc.frontend.components.control_bars import header from datadoc.frontend.components.control_bars import progress_bar from datadoc.frontend.components.dataset_tab import build_dataset_tab +from datadoc.frontend.components.dataset_tab import build_new_dataset_tab from datadoc.frontend.components.variables_tab import build_variables_tab from datadoc.logging.logging_config import configure_logging from datadoc.utils import get_app_version @@ -44,6 +45,7 @@ def build_app(app: type[Dash]) -> Dash: tabs_children = [ build_dataset_tab(), build_variables_tab(), + build_new_dataset_tab(), ] app.layout = dbc.Container( diff --git a/src/datadoc/frontend/callbacks/register_callbacks.py b/src/datadoc/frontend/callbacks/register_callbacks.py index f13aae85..e41bd5c4 100644 --- a/src/datadoc/frontend/callbacks/register_callbacks.py +++ b/src/datadoc/frontend/callbacks/register_callbacks.py @@ -25,9 +25,11 @@ from datadoc.frontend.callbacks.utils import update_global_language_state from datadoc.frontend.callbacks.variables import accept_variable_metadata_date_input from datadoc.frontend.callbacks.variables import accept_variable_metadata_input +from datadoc.frontend.components.builders import build_dataset_edit_section from datadoc.frontend.components.builders import build_edit_section 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 SECTION_WRAPPER_ID 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 @@ -209,6 +211,19 @@ def callback_populate_variables_workspace( for variable in list(state.metadata.variables) ] + @app.callback( + Output(SECTION_WRAPPER_ID, "children"), + Input("language-dropdown", "value"), + prevent_initial_call=True, + ) + def callback_populate_dataset_workspace(language: str) -> list: + """Create dataset workspace with sections.""" + update_global_language_state(SupportedLanguages(language)) + logger.info("Populating new dataset workspace") + return [ + build_dataset_edit_section("Obligatorisk"), + ] + @app.callback( Output( { diff --git a/src/datadoc/frontend/components/dataset_tab.py b/src/datadoc/frontend/components/dataset_tab.py index 51952f2b..099a02c0 100644 --- a/src/datadoc/frontend/components/dataset_tab.py +++ b/src/datadoc/frontend/components/dataset_tab.py @@ -96,7 +96,7 @@ def build_dataset_tab() -> dbc.Tab: def build_new_dataset_tab() -> dbc.Tab: """Build the Dataset metadata tab.""" return build_ssb_styled_tab( - "Datasett", + "Ny Datasett", html.Article( [ html.Header( From 562542c8ecdb22eb64b529da2749ac570c43aaff Mon Sep 17 00:00:00 2001 From: tilen1976 <68303562+tilen1976@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:48:27 +0100 Subject: [PATCH 4/4] Add edit_sections --- src/datadoc/frontend/callbacks/register_callbacks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/datadoc/frontend/callbacks/register_callbacks.py b/src/datadoc/frontend/callbacks/register_callbacks.py index e41bd5c4..5efeab3d 100644 --- a/src/datadoc/frontend/callbacks/register_callbacks.py +++ b/src/datadoc/frontend/callbacks/register_callbacks.py @@ -211,6 +211,7 @@ def callback_populate_variables_workspace( for variable in list(state.metadata.variables) ] + # Work in progress... @app.callback( Output(SECTION_WRAPPER_ID, "children"), Input("language-dropdown", "value"), @@ -222,6 +223,8 @@ def callback_populate_dataset_workspace(language: str) -> list: logger.info("Populating new dataset workspace") return [ build_dataset_edit_section("Obligatorisk"), + build_dataset_edit_section("Anbefalt"), + build_dataset_edit_section("Maskingenerert"), ] @app.callback(