From 9a009acb3ba51bebb47e1a61671635368b477ec0 Mon Sep 17 00:00:00 2001 From: tilen1976 <68303562+tilen1976@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:28:49 +0100 Subject: [PATCH 1/4] Semantic structure dataset tab --- src/datadoc/frontend/components/dataset_tab.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/datadoc/frontend/components/dataset_tab.py b/src/datadoc/frontend/components/dataset_tab.py index fbbe41b8..08f7b9a0 100644 --- a/src/datadoc/frontend/components/dataset_tab.py +++ b/src/datadoc/frontend/components/dataset_tab.py @@ -3,6 +3,7 @@ from __future__ import annotations import dash_bootstrap_components as dbc +import ssb_dash_components as ssb from dash import html from datadoc.frontend.components.builders import build_ssb_styled_tab @@ -78,14 +79,19 @@ def build_dataset_tab() -> dbc.Tab: """Build the Dataset metadata tab.""" return build_ssb_styled_tab( "Datasett", - dbc.Container( + html.Article( [ - dbc.Row(html.H2("Datasett detaljer", className="ssb-title")), - dbc.Accordion( - id="dataset-accordion", - always_open=True, - children=build_dataset_metadata_accordion(), + html.Header( + [ + ssb.Title( + "Datasett detaljer", + size=2, + className="dataset-title", + ), + ], + className="dataset-header", ), ], + className="page-wrapper", ), ) From f2b889969a259f83e282614538639b7c4b32cc4a Mon Sep 17 00:00:00 2001 From: tilen1976 <68303562+tilen1976@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:10:58 +0100 Subject: [PATCH 2/4] Update dataset tab --- .../frontend/components/dataset_tab.py | 79 +++---------------- 1 file changed, 12 insertions(+), 67 deletions(-) diff --git a/src/datadoc/frontend/components/dataset_tab.py b/src/datadoc/frontend/components/dataset_tab.py index 08f7b9a0..78963bfd 100644 --- a/src/datadoc/frontend/components/dataset_tab.py +++ b/src/datadoc/frontend/components/dataset_tab.py @@ -2,80 +2,21 @@ from __future__ import annotations -import dash_bootstrap_components as dbc +from typing import TYPE_CHECKING + import ssb_dash_components as ssb from dash import html from datadoc.frontend.components.builders import build_ssb_styled_tab -from datadoc.frontend.fields.display_dataset import NON_EDITABLE_DATASET_METADATA -from datadoc.frontend.fields.display_dataset import OBLIGATORY_EDITABLE_DATASET_METADATA -from datadoc.frontend.fields.display_dataset import OPTIONAL_DATASET_METADATA -from datadoc.frontend.fields.display_dataset import DisplayDatasetMetadata - -DATASET_METADATA_INPUT = "dataset-metadata-input" - - -def build_dataset_metadata_accordion_item( - title: str, - metadata_inputs: list[DisplayDatasetMetadata], - accordion_item_id: str, -) -> dbc.AccordionItem: - """Build a Dash AccordionItem for the given Metadata inputs with a unique ID. - - Typically used to categorize metadata fields. - """ - return dbc.AccordionItem( - title=title, - id=accordion_item_id, - children=[ - dbc.Row( - [ - dbc.Col(html.Label(i.display_name)), - dbc.Col( - i.component( - placeholder=i.description, - disabled=not i.editable, - id={ - "type": DATASET_METADATA_INPUT, - "id": i.identifier, - }, - **i.extra_kwargs, - ), - width=5, - ), - dbc.Col(width=4), - ], - ) - for i in metadata_inputs - ], - ) - -def build_dataset_metadata_accordion(n_clicks: int = 0) -> list[dbc.AccordionItem]: - """Build the accordion on Dataset metadata tab. +if TYPE_CHECKING: + import dash_bootstrap_components as dbc - n_clicks parameter is appended to the accordions' items id - to avoid browser caching and refresh the values - """ - obligatory = build_dataset_metadata_accordion_item( - "Obligatorisk", - OBLIGATORY_EDITABLE_DATASET_METADATA, - accordion_item_id=f"obligatory-metadata-accordion-item-{n_clicks}", - ) - optional = build_dataset_metadata_accordion_item( - "Anbefalt", - OPTIONAL_DATASET_METADATA, - accordion_item_id=f"optional-metadata-accordion-item-{n_clicks}", - ) - non_editable = build_dataset_metadata_accordion_item( - "Maskingenerert", - NON_EDITABLE_DATASET_METADATA, - accordion_item_id=f"non-editable-metadata-accordion-item-{n_clicks}", - ) - return [obligatory, optional, non_editable] +DATASET_METADATA_INPUT = "dataset-metadata-input" +SECTION_WRAPPER_ID = "section-wrapper" -def build_dataset_tab() -> dbc.Tab: +def build_new_dataset_tab() -> dbc.Tab: """Build the Dataset metadata tab.""" return build_ssb_styled_tab( "Datasett", @@ -91,7 +32,11 @@ def build_dataset_tab() -> dbc.Tab: ], className="dataset-header", ), + html.Article( + id="dataset-section-wrapper", + className="main-content", + ), ], - className="page-wrapper", + className="dataset-page-wrapper", ), ) From 36d58d2504751e4a3c836a2287ec07a36253b643 Mon Sep 17 00:00:00 2001 From: tilen1976 <68303562+tilen1976@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:29:57 +0100 Subject: [PATCH 3/4] Set const id for wrapper for all dataset sections - use in callback to build layout --- src/datadoc/frontend/components/dataset_tab.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/datadoc/frontend/components/dataset_tab.py b/src/datadoc/frontend/components/dataset_tab.py index 78963bfd..aaed3893 100644 --- a/src/datadoc/frontend/components/dataset_tab.py +++ b/src/datadoc/frontend/components/dataset_tab.py @@ -13,7 +13,7 @@ import dash_bootstrap_components as dbc DATASET_METADATA_INPUT = "dataset-metadata-input" -SECTION_WRAPPER_ID = "section-wrapper" +SECTION_WRAPPER_ID = "section-wrapper-id" def build_new_dataset_tab() -> dbc.Tab: @@ -33,7 +33,7 @@ def build_new_dataset_tab() -> dbc.Tab: className="dataset-header", ), html.Article( - id="dataset-section-wrapper", + id=SECTION_WRAPPER_ID, className="main-content", ), ], From 742264275935acce24ea45caeaba8887020217ee Mon Sep 17 00:00:00 2001 From: tilen1976 <68303562+tilen1976@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:42:57 +0100 Subject: [PATCH 4/4] Undelete dataset tab code --- .../frontend/components/dataset_tab.py | 87 +++++++++++++++++-- 1 file changed, 82 insertions(+), 5 deletions(-) diff --git a/src/datadoc/frontend/components/dataset_tab.py b/src/datadoc/frontend/components/dataset_tab.py index aaed3893..51952f2b 100644 --- a/src/datadoc/frontend/components/dataset_tab.py +++ b/src/datadoc/frontend/components/dataset_tab.py @@ -2,20 +2,97 @@ from __future__ import annotations -from typing import TYPE_CHECKING - +import dash_bootstrap_components as dbc import ssb_dash_components as ssb from dash import html from datadoc.frontend.components.builders import build_ssb_styled_tab - -if TYPE_CHECKING: - import dash_bootstrap_components as dbc +from datadoc.frontend.fields.display_dataset import NON_EDITABLE_DATASET_METADATA +from datadoc.frontend.fields.display_dataset import OBLIGATORY_EDITABLE_DATASET_METADATA +from datadoc.frontend.fields.display_dataset import OPTIONAL_DATASET_METADATA +from datadoc.frontend.fields.display_dataset import DisplayDatasetMetadata DATASET_METADATA_INPUT = "dataset-metadata-input" SECTION_WRAPPER_ID = "section-wrapper-id" +def build_dataset_metadata_accordion_item( + title: str, + metadata_inputs: list[DisplayDatasetMetadata], + accordion_item_id: str, +) -> dbc.AccordionItem: + """Build a Dash AccordionItem for the given Metadata inputs with a unique ID. + + Typically used to categorize metadata fields. + """ + return dbc.AccordionItem( + title=title, + id=accordion_item_id, + children=[ + dbc.Row( + [ + dbc.Col(html.Label(i.display_name)), + dbc.Col( + i.component( + placeholder=i.description, + disabled=not i.editable, + id={ + "type": DATASET_METADATA_INPUT, + "id": i.identifier, + }, + **i.extra_kwargs, + ), + width=5, + ), + dbc.Col(width=4), + ], + ) + for i in metadata_inputs + ], + ) + + +def build_dataset_metadata_accordion(n_clicks: int = 0) -> list[dbc.AccordionItem]: + """Build the accordion on Dataset metadata tab. + + n_clicks parameter is appended to the accordions' items id + to avoid browser caching and refresh the values + """ + obligatory = build_dataset_metadata_accordion_item( + "Obligatorisk", + OBLIGATORY_EDITABLE_DATASET_METADATA, + accordion_item_id=f"obligatory-metadata-accordion-item-{n_clicks}", + ) + optional = build_dataset_metadata_accordion_item( + "Anbefalt", + OPTIONAL_DATASET_METADATA, + accordion_item_id=f"optional-metadata-accordion-item-{n_clicks}", + ) + non_editable = build_dataset_metadata_accordion_item( + "Maskingenerert", + NON_EDITABLE_DATASET_METADATA, + accordion_item_id=f"non-editable-metadata-accordion-item-{n_clicks}", + ) + return [obligatory, optional, non_editable] + + +def build_dataset_tab() -> dbc.Tab: + """Build the Dataset metadata tab.""" + return build_ssb_styled_tab( + "Datasett", + dbc.Container( + [ + dbc.Row(html.H2("Datasett detaljer", className="ssb-title")), + dbc.Accordion( + id="dataset-accordion", + always_open=True, + children=build_dataset_metadata_accordion(), + ), + ], + ), + ) + + def build_new_dataset_tab() -> dbc.Tab: """Build the Dataset metadata tab.""" return build_ssb_styled_tab(