Skip to content

Commit

Permalink
Revert "Change field type for dates"
Browse files Browse the repository at this point in the history
  • Loading branch information
JanhSander authored Mar 15, 2024
1 parent a54e831 commit 667767c
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 263 deletions.
5 changes: 2 additions & 3 deletions src/datadoc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from datadoc.frontend.components.control_bars import build_language_dropdown
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_new_dataset_tab
from datadoc.frontend.components.dataset_tab import build_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 @@ -42,9 +42,8 @@
def build_app(app: type[Dash]) -> Dash:
"""Define the layout, register callbacks."""
tabs_children = [
# build_dataset_tab(),
build_dataset_tab(),
build_variables_tab(),
build_new_dataset_tab(),
]

app.layout = dbc.Container(
Expand Down
60 changes: 15 additions & 45 deletions src/datadoc/frontend/callbacks/register_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from dash import Output
from dash import State
from dash import ctx
from dash import no_update

from datadoc import state
from datadoc.enums import SupportedLanguages
Expand All @@ -24,19 +25,15 @@
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
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
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_variables import OBLIGATORY_VARIABLES_METADATA
from datadoc.frontend.fields.display_variables import OPTIONAL_VARIABLES_METADATA
from datadoc.frontend.fields.display_variables import VariableIdentifiers
Expand Down Expand Up @@ -150,19 +147,20 @@ def callback_open_dataset(
"""
return open_dataset_handling(n_clicks, dataset_path)

# @app.callback(
# Output("dataset-accordion", "children"), # noqa: ERA001
# Input("open-button", "n_clicks"), # noqa: ERA001
# prevent_initial_call=True, # noqa: ERA001)
# def callback_clear_accordion_values(n_clicks: int) -> list[dbc.AccordionItem]:
# """Recreate accordion items with unique IDs.
@app.callback(
Output("dataset-accordion", "children"),
Input("open-button", "n_clicks"),
prevent_initial_call=True,
)
def callback_clear_accordion_values(n_clicks: int) -> list[dbc.AccordionItem]:
"""Recreate accordion items with unique IDs.
# The purpose is to avoid browser caching and clear the values of all
# components inside the dataset accordion when new file is opened
# """
# if n_clicks and n_clicks > 0:
# return build_dataset_metadata_accordion(n_clicks) # noqa: ERA001
# return no_update # noqa: ERA001
The purpose is to avoid browser caching and clear the values of all
components inside the dataset accordion when new file is opened
"""
if n_clicks and n_clicks > 0:
return build_dataset_metadata_accordion(n_clicks)
return no_update

@app.callback(
Output(VARIABLES_INFORMATION_ID, "children"),
Expand Down Expand Up @@ -211,34 +209,6 @@ 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",
OBLIGATORY_EDITABLE_DATASET_METADATA,
language,
),
build_dataset_edit_section(
"Anbefalt",
OPTIONAL_DATASET_METADATA,
language,
),
build_dataset_edit_section(
"Maskingenerert",
NON_EDITABLE_DATASET_METADATA,
language,
),
]

@app.callback(
Output(
{
Expand Down
42 changes: 0 additions & 42 deletions src/datadoc/frontend/components/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
from dash import html

from datadoc.frontend.fields.display_base import VARIABLES_METADATA_INPUT
from datadoc.frontend.fields.display_base import DatasetFieldTypes
from datadoc.frontend.fields.display_base import VariablesFieldTypes

if TYPE_CHECKING:
from datadoc_model import model

DATASET_METADATA_INPUT = "dataset-metadata-input"


class AlertTypes(Enum):
"""Types of alerts."""
Expand Down Expand Up @@ -137,29 +134,6 @@ def build_input_field_section(
)


def build_dataset_input_field_section(
metadata_fields: list[DatasetFieldTypes],
language: str,
) -> dbc.Form:
"""Create input fields for dataset."""
return dbc.Form(
[
i.render(
{
"type": "NEW_DATASET",
# "type": DATASET_METADATA_INPUT, # noqa: ERA001
"id": i.identifier,
},
language,
)
for i in metadata_fields
# for i in OBLIGATORY_EDITABLE_DATASET_METADATA
],
id="new-dataset-form",
className="dataset-input-group",
)


def build_edit_section(
metadata_inputs: list,
title: str,
Expand All @@ -177,22 +151,6 @@ def build_edit_section(
)


def build_dataset_edit_section(
title: str,
metadata_inputs: list,
language: 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"),
build_dataset_input_field_section(metadata_inputs, language),
],
className="dataset-edit-section",
)


def build_ssb_accordion(
header: str,
key: dict,
Expand Down
97 changes: 73 additions & 24 deletions src/datadoc/frontend/components/dataset_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,90 @@

from __future__ import annotations

from typing import TYPE_CHECKING

import ssb_dash_components as ssb
import dash_bootstrap_components as dbc
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_new_dataset_tab() -> dbc.Tab:
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(
"Ny Datasett",
html.Article(
"Datasett",
dbc.Container(
[
html.Header(
[
ssb.Title(
"Datasett detaljer",
size=2,
className="dataset-title",
),
],
className="dataset-header",
),
html.Article(
id=SECTION_WRAPPER_ID,
className="main-content",
dbc.Row(html.H2("Datasett detaljer", className="ssb-title")),
dbc.Accordion(
id="dataset-accordion",
always_open=True,
children=build_dataset_metadata_accordion(),
),
],
className="dataset-page-wrapper",
),
)
Loading

0 comments on commit 667767c

Please sign in to comment.