Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build dataset layout #223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/datadoc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
18 changes: 18 additions & 0 deletions src/datadoc/frontend/callbacks/register_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -209,6 +211,22 @@ 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"),
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"),
build_dataset_edit_section("Anbefalt"),
build_dataset_edit_section("Maskingenerert"),
]

@app.callback(
Output(
{
Expand Down
11 changes: 11 additions & 0 deletions src/datadoc/frontend/components/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/datadoc/frontend/components/dataset_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions src/datadoc/frontend/fields/display_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -185,13 +186,15 @@ 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,
display_name="Enhetstype",
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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/backend/test_datadoc_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down