diff --git a/src/datadoc/app.py b/src/datadoc/app.py index 67adfa13..99153878 100644 --- a/src/datadoc/app.py +++ b/src/datadoc/app.py @@ -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_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 @@ -42,8 +42,9 @@ 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( diff --git a/src/datadoc/frontend/callbacks/register_callbacks.py b/src/datadoc/frontend/callbacks/register_callbacks.py index f13aae85..2badabb7 100644 --- a/src/datadoc/frontend/callbacks/register_callbacks.py +++ b/src/datadoc/frontend/callbacks/register_callbacks.py @@ -15,7 +15,6 @@ 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 @@ -25,15 +24,19 @@ 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 build_dataset_metadata_accordion +from datadoc.frontend.components.dataset_tab import SECTION_WRAPPER_ID 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 @@ -147,20 +150,19 @@ def callback_open_dataset( """ return open_dataset_handling(n_clicks, dataset_path) - @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. + # @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. - 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 + # 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 @app.callback( Output(VARIABLES_INFORMATION_ID, "children"), @@ -209,6 +211,34 @@ 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( { diff --git a/src/datadoc/frontend/components/builders.py b/src/datadoc/frontend/components/builders.py index d1ee188e..fe4b46f9 100644 --- a/src/datadoc/frontend/components/builders.py +++ b/src/datadoc/frontend/components/builders.py @@ -13,11 +13,14 @@ 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.""" @@ -134,6 +137,29 @@ 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, @@ -151,6 +177,22 @@ 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, diff --git a/src/datadoc/frontend/components/dataset_tab.py b/src/datadoc/frontend/components/dataset_tab.py index fbbe41b8..b0b13793 100644 --- a/src/datadoc/frontend/components/dataset_tab.py +++ b/src/datadoc/frontend/components/dataset_tab.py @@ -2,90 +2,41 @@ 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 - ], - ) +if TYPE_CHECKING: + import dash_bootstrap_components as dbc -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] +DATASET_METADATA_INPUT = "dataset-metadata-input" +SECTION_WRAPPER_ID = "section-wrapper-id" -def build_dataset_tab() -> dbc.Tab: +def build_new_dataset_tab() -> dbc.Tab: """Build the Dataset metadata tab.""" return build_ssb_styled_tab( - "Datasett", - dbc.Container( + "Ny Datasett", + 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", + ), + html.Article( + id=SECTION_WRAPPER_ID, + className="main-content", ), ], + className="dataset-page-wrapper", ), ) diff --git a/src/datadoc/frontend/fields/display_base.py b/src/datadoc/frontend/fields/display_base.py index aa7198f8..75de459f 100644 --- a/src/datadoc/frontend/fields/display_base.py +++ b/src/datadoc/frontend/fields/display_base.py @@ -130,6 +130,63 @@ class DisplayDatasetMetadata(DisplayMetadata): value_getter: Callable[[BaseModel, str], Any] = get_metadata_and_stringify +@dataclass +class DatasetInputField(DisplayMetadata): + """Controls for how a given metadata field should be displayed. + + Specific to dataset fields. + """ + + extra_kwargs: dict[str, Any] = field(default_factory=input_kwargs_factory) + value_getter: Callable[[BaseModel, str], Any] = get_metadata_and_stringify + type: str = "text" + + def render( + self, + dataset_id: dict, + language: str, # noqa: ARG002 + # dataset: model.Dataset, + ) -> ssb.Input: + """Build input component.""" + # value = self.value_getter(dataset, self.identifier) # noqa: ERA001 + return ssb.Input( + label=self.display_name, + id=dataset_id, + debounce=True, + type=self.type, + disabled=not self.editable, + # value=value, # noqa: ERA001 + className="variable-input", + ) + + +@dataclass +class DatasetDropdownField(DisplayMetadata): + """Control how a Dropdown should be displayed.""" + + extra_kwargs: dict[str, Any] = field(default_factory=empty_kwargs_factory) + value_getter: Callable[[BaseModel, str], Any] = get_metadata_and_stringify + # fmt: off + options_getter: Callable[[SupportedLanguages], list[dict[str, str]]] = lambda _: [] # noqa: E731 + # fmt: on + + def render( + self, + variable_id: dict, + language: str, + # variable: model.Variable, + ) -> ssb.Dropdown: + """Build Dropdown component.""" + # value = self.value_getter(variable, self.identifier) # noqa: ERA001 + return ssb.Dropdown( + header=self.display_name, + id=variable_id, + items=self.options_getter(SupportedLanguages(language)), + # value=value, # noqa: ERA001 + className="dataset-dropdown", + ) + + @dataclass class DisplayDatasetMetadataDropdown(DisplayDatasetMetadata): """Include the possible options which a user may choose from.""" @@ -173,7 +230,7 @@ def render( @dataclass class VariablesPeriodField(DisplayMetadata): - """Control how fields which define a time period are displayed. + """Control how fields which define a time period are displayed for variables. These are a special case since two fields have a relationship to one another.> """ @@ -202,6 +259,37 @@ def render( ) +@dataclass +class DatasetPeriodField(DisplayMetadata): + """Control how fields which define a time period are displayed for Dataset. + + These are a special case since two fields have a relationship to one another.> + """ + + extra_kwargs: dict[str, Any] = field(default_factory=empty_kwargs_factory) + value_getter: Callable[[BaseModel, str], Any] = get_metadata_and_stringify + type: str = "date" + + def render( + self, + dataset_id: dict, + language: str, # noqa: ARG002 + # variable: model.Variable, + ) -> ssb.Input: + """Build Input date component.""" + # value = self.value_getter(variable, self.identifier) # noqa: ERA001 + # variable_id["type"] = VARIABLES_METADATA_DATE_INPUT # noqa: ERA001 + return ssb.Input( + label=self.display_name, + id=dataset_id, + debounce=False, + type=self.type, + disabled=not self.editable, + # value=value, # noqa: ERA001 + className="variable-input", + ) + + @dataclass class VariablesDropdownField(DisplayMetadata): """Control how a Dropdown should be displayed.""" @@ -260,3 +348,5 @@ def render( | VariablesCheckboxField | VariablesPeriodField ) + +DatasetFieldTypes = DatasetInputField | DatasetDropdownField | DatasetPeriodField diff --git a/src/datadoc/frontend/fields/display_dataset.py b/src/datadoc/frontend/fields/display_dataset.py index e4b36982..75c648dc 100644 --- a/src/datadoc/frontend/fields/display_dataset.py +++ b/src/datadoc/frontend/fields/display_dataset.py @@ -7,15 +7,16 @@ from enum import Enum from typing import TYPE_CHECKING -from dash import dcc - from datadoc import enums from datadoc import state -from datadoc.frontend.callbacks.utils import get_language_strings_enum from datadoc.frontend.fields.display_base import INPUT_KWARGS -from datadoc.frontend.fields.display_base import DisplayDatasetMetadata +from datadoc.frontend.fields.display_base import DatasetDropdownField +from datadoc.frontend.fields.display_base import DatasetFieldTypes +from datadoc.frontend.fields.display_base import DatasetInputField +from datadoc.frontend.fields.display_base import DatasetPeriodField from datadoc.frontend.fields.display_base import DisplayDatasetMetadataDropdown from datadoc.frontend.fields.display_base import get_comma_separated_string +from datadoc.frontend.fields.display_base import get_enum_options_for_language from datadoc.frontend.fields.display_base import get_metadata_and_stringify from datadoc.frontend.fields.display_base import get_multi_language_metadata @@ -25,28 +26,14 @@ logger = logging.getLogger(__name__) -def get_enum_options_for_language( - enum: Enum, - language: SupportedLanguages, -) -> list[dict[str, str]]: - """Generate the list of options based on the currently chosen language.""" - return [ - { - "label": i.get_value_for_language(language), - "value": i.name, - } - for i in get_language_strings_enum(enum) # type: ignore [attr-defined] - ] - - def get_statistical_subject_options( language: SupportedLanguages, ) -> list[dict[str, str]]: """Collect the statistical subject options for the given language.""" return [ { - "label": f"{primary.get_title(language)} - {secondary.get_title(language)}", - "value": secondary.subject_code, + "title": f"{primary.get_title(language)} - {secondary.get_title(language)}", + "id": secondary.subject_code, } for primary in state.statistic_subject_mapping.primary_subjects for secondary in primary.secondary_subjects @@ -59,8 +46,8 @@ def get_unit_type_options( """Collect the unit type options for the given language.""" return [ { - "label": unit_type.get_title(language), - "value": unit_type.code, + "title": unit_type.get_title(language), + "id": unit_type.code, } for unit_type in state.unit_types.classifications ] @@ -72,8 +59,8 @@ def get_owner_options( """Collect the owner options for the given language.""" return [ { - "label": f"{option.code} - {option.get_title(language)}", - "value": option.code, + "title": f"{option.code} - {option.get_title(language)}", + "id": option.code, } for option in state.organisational_units.classifications ] @@ -109,16 +96,18 @@ class DatasetIdentifiers(str, Enum): CONTAINS_DATA_UNTIL = "contains_data_until" -DISPLAY_DATASET: dict[DatasetIdentifiers, DisplayDatasetMetadata] = { - DatasetIdentifiers.SHORT_NAME: DisplayDatasetMetadata( +DISPLAY_DATASET: dict[ + DatasetIdentifiers, + DatasetFieldTypes, +] = { + DatasetIdentifiers.SHORT_NAME: DatasetInputField( identifier=DatasetIdentifiers.SHORT_NAME.value, display_name="Kortnavn", description="Navn på (fysisk) datafil, datatabell eller datasett", - component=dcc.Input, obligatory=True, editable=False, ), - DatasetIdentifiers.ASSESSMENT: DisplayDatasetMetadataDropdown( + DatasetIdentifiers.ASSESSMENT: DatasetDropdownField( identifier=DatasetIdentifiers.ASSESSMENT.value, display_name="Verdivurdering", description="Verdivurdering (sensitivitetsklassifisering) for datasettet.", @@ -127,7 +116,7 @@ class DatasetIdentifiers(str, Enum): enums.Assessment, ), ), - DatasetIdentifiers.DATASET_STATUS: DisplayDatasetMetadataDropdown( + DatasetIdentifiers.DATASET_STATUS: DatasetDropdownField( identifier=DatasetIdentifiers.DATASET_STATUS.value, display_name="Status", description="Livssyklus for datasettet", @@ -137,7 +126,7 @@ class DatasetIdentifiers(str, Enum): ), obligatory=True, ), - DatasetIdentifiers.DATASET_STATE: DisplayDatasetMetadataDropdown( + DatasetIdentifiers.DATASET_STATE: DatasetDropdownField( identifier=DatasetIdentifiers.DATASET_STATE.value, display_name="Datatilstand", description="Datatilstand. Se Intern dokument 2021- 17 Datatilstander i SSB", @@ -147,48 +136,50 @@ class DatasetIdentifiers(str, Enum): enums.DataSetState, ), ), - DatasetIdentifiers.NAME: DisplayDatasetMetadata( + DatasetIdentifiers.NAME: DatasetInputField( identifier=DatasetIdentifiers.NAME.value, display_name="Navn", description="Datasettnavn", obligatory=True, multiple_language_support=True, ), - DatasetIdentifiers.DATA_SOURCE: DisplayDatasetMetadata( + DatasetIdentifiers.DATA_SOURCE: DatasetInputField( identifier=DatasetIdentifiers.DATA_SOURCE.value, display_name="Datakilde", description="Datakilde. Settes enten for datasettet eller variabelforekomst.", obligatory=True, multiple_language_support=True, ), - DatasetIdentifiers.REGISTER_URI: DisplayDatasetMetadata( + DatasetIdentifiers.REGISTER_URI: DatasetInputField( identifier=DatasetIdentifiers.REGISTER_URI.value, display_name="Register URI", description="Lenke (URI) til register i registeroversikt (oversikt over alle registre meldt Datatilsynet (oppdatering foretas av sikkerhetsrådgiver))", multiple_language_support=True, + url=True, + type="url", ), - DatasetIdentifiers.POPULATION_DESCRIPTION: DisplayDatasetMetadata( + DatasetIdentifiers.POPULATION_DESCRIPTION: DatasetInputField( identifier=DatasetIdentifiers.POPULATION_DESCRIPTION.value, display_name="Populasjon", description="Populasjonen datasettet dekker. Populasjonsbeskrivelsen inkluderer enhetstype, geografisk dekningsområde og tidsperiode.", obligatory=True, multiple_language_support=True, ), - DatasetIdentifiers.VERSION: DisplayDatasetMetadata( + DatasetIdentifiers.VERSION: DatasetInputField( identifier=DatasetIdentifiers.VERSION.value, display_name="Versjon", description="Versjon", extra_kwargs=dict(type="number", min=1, **INPUT_KWARGS), obligatory=True, ), - DatasetIdentifiers.VERSION_DESCRIPTION: DisplayDatasetMetadata( + DatasetIdentifiers.VERSION_DESCRIPTION: DatasetInputField( identifier=DatasetIdentifiers.VERSION_DESCRIPTION.value, 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( + DatasetIdentifiers.UNIT_TYPE: DatasetDropdownField( 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.", @@ -196,7 +187,7 @@ class DatasetIdentifiers(str, Enum): options_getter=get_unit_type_options, obligatory=True, ), - DatasetIdentifiers.TEMPORALITY_TYPE: DisplayDatasetMetadataDropdown( + DatasetIdentifiers.TEMPORALITY_TYPE: DatasetDropdownField( identifier=DatasetIdentifiers.TEMPORALITY_TYPE.value, display_name="Temporalitetstype", description="Temporalitetstype. Settes enten for variabelforekomst eller datasett. Se Temporalitet, hendelser og forløp.", @@ -206,14 +197,14 @@ class DatasetIdentifiers(str, Enum): ), obligatory=True, ), - DatasetIdentifiers.DESCRIPTION: DisplayDatasetMetadata( + DatasetIdentifiers.DESCRIPTION: DatasetInputField( identifier=DatasetIdentifiers.DESCRIPTION.value, display_name="Beskrivelse", description="Beskrivelse av datasettet", multiple_language_support=True, obligatory=True, ), - DatasetIdentifiers.SUBJECT_FIELD: DisplayDatasetMetadataDropdown( + DatasetIdentifiers.SUBJECT_FIELD: DatasetDropdownField( identifier=DatasetIdentifiers.SUBJECT_FIELD.value, display_name="Statistikkområde", description="Primær statistikkområdet som datasettet inngår i", @@ -223,19 +214,19 @@ class DatasetIdentifiers(str, Enum): multiple_language_support=True, options_getter=get_statistical_subject_options, ), - DatasetIdentifiers.KEYWORD: DisplayDatasetMetadata( + DatasetIdentifiers.KEYWORD: DatasetInputField( identifier=DatasetIdentifiers.KEYWORD.value, display_name="Nøkkelord", description="En kommaseparert liste med søkbare nøkkelord som kan bidra til utvikling av effektive filtrerings- og søketjeneste.", value_getter=get_comma_separated_string, ), - DatasetIdentifiers.SPATIAL_COVERAGE_DESCRIPTION: DisplayDatasetMetadata( + DatasetIdentifiers.SPATIAL_COVERAGE_DESCRIPTION: DatasetInputField( identifier=DatasetIdentifiers.SPATIAL_COVERAGE_DESCRIPTION.value, display_name="Geografisk dekningsområde", description="Beskrivelse av datasettets geografiske dekningsområde. Målet er på sikt at dette skal hentes fra Klass, men fritekst vil også kunne brukes.", multiple_language_support=True, ), - DatasetIdentifiers.ID: DisplayDatasetMetadata( + DatasetIdentifiers.ID: DatasetInputField( identifier=DatasetIdentifiers.ID.value, display_name="ID", description="Unik SSB-identifikator for datasettet (løpenummer)", @@ -243,7 +234,7 @@ class DatasetIdentifiers(str, Enum): editable=False, value_getter=get_metadata_and_stringify, ), - DatasetIdentifiers.OWNER: DisplayDatasetMetadataDropdown( + DatasetIdentifiers.OWNER: DatasetDropdownField( identifier=DatasetIdentifiers.OWNER.value, display_name="Eier", description="Maskingenerert seksjonstilhørighet til den som oppretter metadata om datasettet, men kan korrigeres manuelt", @@ -252,49 +243,49 @@ class DatasetIdentifiers(str, Enum): multiple_language_support=False, options_getter=get_owner_options, ), - DatasetIdentifiers.FILE_PATH: DisplayDatasetMetadata( + DatasetIdentifiers.FILE_PATH: DatasetInputField( identifier=DatasetIdentifiers.FILE_PATH.value, display_name="Filsti", description="Filstien inneholder datasettets navn og stien til hvor det er lagret.", obligatory=True, editable=False, ), - DatasetIdentifiers.METADATA_CREATED_DATE: DisplayDatasetMetadata( + DatasetIdentifiers.METADATA_CREATED_DATE: DatasetInputField( identifier=DatasetIdentifiers.METADATA_CREATED_DATE.value, display_name="Dato opprettet", description="Opprettet dato for metadata om datasettet", obligatory=True, editable=False, ), - DatasetIdentifiers.METADATA_CREATED_BY: DisplayDatasetMetadata( + DatasetIdentifiers.METADATA_CREATED_BY: DatasetInputField( identifier=DatasetIdentifiers.METADATA_CREATED_BY.value, display_name="Opprettet av", description="Opprettet av person. Kun til bruk i SSB.", obligatory=True, editable=False, ), - DatasetIdentifiers.METADATA_LAST_UPDATED_DATE: DisplayDatasetMetadata( + DatasetIdentifiers.METADATA_LAST_UPDATED_DATE: DatasetInputField( identifier=DatasetIdentifiers.METADATA_LAST_UPDATED_DATE.value, display_name="Dato oppdatert", description="Sist oppdatert dato for metadata om datasettet", obligatory=True, editable=False, ), - DatasetIdentifiers.METADATA_LAST_UPDATED_BY: DisplayDatasetMetadata( + DatasetIdentifiers.METADATA_LAST_UPDATED_BY: DatasetInputField( identifier=DatasetIdentifiers.METADATA_LAST_UPDATED_BY.value, display_name="Oppdatert av", description="Siste endring utført av person. Kun til bruk i SSB.", obligatory=True, editable=False, ), - DatasetIdentifiers.CONTAINS_DATA_FROM: DisplayDatasetMetadata( + DatasetIdentifiers.CONTAINS_DATA_FROM: DatasetPeriodField( identifier=DatasetIdentifiers.CONTAINS_DATA_FROM.value, display_name="Inneholder data f.o.m.", description="ÅÅÅÅ-MM-DD", obligatory=True, editable=True, ), - DatasetIdentifiers.CONTAINS_DATA_UNTIL: DisplayDatasetMetadata( + DatasetIdentifiers.CONTAINS_DATA_UNTIL: DatasetPeriodField( identifier=DatasetIdentifiers.CONTAINS_DATA_UNTIL.value, display_name="Inneholder data t.o.m.", description="ÅÅÅÅ-MM-DD", @@ -312,7 +303,10 @@ class DatasetIdentifiers(str, Enum): ] OBLIGATORY_EDITABLE_DATASET_METADATA = [ - m for m in DISPLAY_DATASET.values() if m.obligatory and m.editable + m + for m in DISPLAY_DATASET.values() + if m.obligatory and m.editable + # DISPLAY_DATASET[DatasetIdentifiers.NAME], # noqa: ERA001 ] OPTIONAL_DATASET_METADATA = [ @@ -323,7 +317,7 @@ class DatasetIdentifiers(str, Enum): # The order of this list MUST match the order of display components, as defined in DatasetTab.py -DISPLAYED_DATASET_METADATA: list[DisplayDatasetMetadata] = ( +DISPLAYED_DATASET_METADATA: list[DatasetFieldTypes] = ( OBLIGATORY_EDITABLE_DATASET_METADATA + OPTIONAL_DATASET_METADATA + NON_EDITABLE_DATASET_METADATA diff --git a/tests/frontend/fields/test_display_dataset.py b/tests/frontend/fields/test_display_dataset.py index 99888e3f..1886e2ec 100644 --- a/tests/frontend/fields/test_display_dataset.py +++ b/tests/frontend/fields/test_display_dataset.py @@ -19,10 +19,10 @@ / STATISTICAL_SUBJECT_STRUCTURE_DIR / "extract_secondary_subject.xml", [ - {"label": "aa norwegian - aa00 norwegian", "value": "aa00"}, - {"label": "aa norwegian - aa01 norwegian", "value": "aa01"}, - {"label": "ab norwegian - ab00 norwegian", "value": "ab00"}, - {"label": "ab norwegian - ab01 norwegian", "value": "ab01"}, + {"title": "aa norwegian - aa00 norwegian", "id": "aa00"}, + {"title": "aa norwegian - aa01 norwegian", "id": "aa01"}, + {"title": "ab norwegian - ab00 norwegian", "id": "ab00"}, + {"title": "ab norwegian - ab01 norwegian", "id": "ab01"}, ], ), ( @@ -30,10 +30,10 @@ / STATISTICAL_SUBJECT_STRUCTURE_DIR / "missing_language.xml", [ - {"label": " - aa00 norwegian", "value": "aa00"}, - {"label": " - aa01 norwegian", "value": "aa01"}, - {"label": " - ab00 norwegian", "value": "ab00"}, - {"label": " - ", "value": "ab01"}, + {"title": " - aa00 norwegian", "id": "aa00"}, + {"title": " - aa01 norwegian", "id": "aa01"}, + {"title": " - ab00 norwegian", "id": "ab00"}, + {"title": " - ", "id": "ab01"}, ], ), ], @@ -53,9 +53,9 @@ def test_get_statistical_subject_options( ( TEST_RESOURCES_DIRECTORY / CODE_LIST_DIR / "code_list_nb.csv", [ - {"label": "Adresse", "value": "01"}, - {"label": "Arbeidsulykke", "value": "02"}, - {"label": "Bolig", "value": "03"}, + {"title": "Adresse", "id": "01"}, + {"title": "Arbeidsulykke", "id": "02"}, + {"title": "Bolig", "id": "03"}, ], ), ],