Skip to content

Commit

Permalink
Remove variables datatable interface (#207)
Browse files Browse the repository at this point in the history
* Remove variables table code

* Add a comment

* Remove config function

* Don't change test resource

* Fix test

* Fix checkbox styling

* Release v0.7.0
  • Loading branch information
mmwinther authored Mar 8, 2024
1 parent 4880f21 commit 70d0222
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 925 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-datadoc"
version = "0.6.0"
version = "0.7.0"
description = "Document dataset metadata. For use in Statistics Norway's metadata system."
authors = ["Statistics Norway <stat-dev@ssb.no>"]
license = "MIT"
Expand Down Expand Up @@ -107,6 +107,7 @@ exclude = ["docs/conf.py", "noxfile.py", "gunicorn.conf.py"]
module = [
"dash.*",
"dash_bootstrap_components",
"ssb_dash_components",
"flask_healthz",
"dapla",
"gcsfs",
Expand Down
17 changes: 0 additions & 17 deletions src/datadoc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
from datadoc.backend.unit_types import UnitTypes
from datadoc.enums import SupportedLanguages
from datadoc.frontend.callbacks.register_callbacks import register_callbacks
from datadoc.frontend.callbacks.register_callbacks import (
register_new_variables_tab_callbacks,
)
from datadoc.frontend.components.alerts import dataset_validation_error
from datadoc.frontend.components.alerts import opened_dataset_error
from datadoc.frontend.components.alerts import opened_dataset_success
Expand All @@ -32,7 +29,6 @@
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.new_variables_tab import build_new_variables_tab
from datadoc.frontend.components.variables_tab import build_variables_tab
from datadoc.utils import get_app_version
from datadoc.utils import pick_random_port
Expand All @@ -49,14 +45,6 @@ def build_app(app: type[Dash]) -> Dash:
build_variables_tab(),
]

# TODO @mmwinther: Remove this when new variables workspace is ready for production.
# https://statistics-norway.atlassian.net/browse/DPMETA-14
if config.get_toggle_new_variables_workspace():
tabs_children.append(build_new_variables_tab())
logger.warning(
"New variables workspace is enabled, not yet ready for production!",
)

app.layout = dbc.Container(
style={"padding": "4px"},
children=[
Expand Down Expand Up @@ -84,11 +72,6 @@ def build_app(app: type[Dash]) -> Dash:

register_callbacks(app)

# TODO @mmwinther: Remove this when new variables workspace is ready for production.
# https://statistics-norway.atlassian.net/browse/DPMETA-14
if config.get_toggle_new_variables_workspace():
register_new_variables_tab_callbacks(app)

return app


Expand Down
2 changes: 1 addition & 1 deletion src/datadoc/assets/variables_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
width: 100%;
}

.form-check.variable-checkbox{
.form-check.ssb-checkbox{
align-self: center;
}

Expand Down
8 changes: 5 additions & 3 deletions src/datadoc/backend/datadoc_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from datadoc.frontend.fields.display_dataset import (
OBLIGATORY_DATASET_METADATA_IDENTIFIERS,
)
from datadoc.frontend.fields.display_variables import OBLIGATORY_VARIABLES_METADATA
from datadoc.frontend.fields.display_variables import (
OBLIGATORY_VARIABLES_METADATA_IDENTIFIERS,
)
from datadoc.utils import METADATA_DOCUMENT_FILE_SUFFIX
from datadoc.utils import calculate_percentage
from datadoc.utils import get_timestamp_now
Expand Down Expand Up @@ -276,12 +278,12 @@ def percent_complete(self) -> int:
],
)
for variable in self.variables:
num_all_fields += len(OBLIGATORY_VARIABLES_METADATA)
num_all_fields += len(OBLIGATORY_VARIABLES_METADATA_IDENTIFIERS)
num_set_fields += len(
[
k
for k, v in variable.model_dump().items()
if k in OBLIGATORY_VARIABLES_METADATA and v is not None
if k in OBLIGATORY_VARIABLES_METADATA_IDENTIFIERS and v is not None
],
)
return calculate_percentage(num_set_fields, num_all_fields)
5 changes: 0 additions & 5 deletions src/datadoc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ def get_dash_development_mode() -> bool:
return _get_config_item("DATADOC_DASH_DEVELOPMENT_MODE") == "True"


def get_toggle_new_variables_workspace() -> bool:
"""Toggle on the new variables workspace."""
return _get_config_item("DATADOC_TOGGLE_NEW_VARIABLE_WORKSPACE") == "True"


def get_jupyterhub_service_prefix() -> str | None:
"""Get the JupyterHub service prefix."""
return _get_config_item("JUPYTERHUB_SERVICE_PREFIX")
Expand Down
83 changes: 14 additions & 69 deletions src/datadoc/frontend/callbacks/register_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,15 @@
from datadoc.frontend.callbacks.dataset import change_language_dataset_metadata
from datadoc.frontend.callbacks.dataset import open_dataset_handling
from datadoc.frontend.callbacks.utils import update_global_language_state
from datadoc.frontend.callbacks.variables import (
accept_variable_datatable_metadata_input,
)
from datadoc.frontend.callbacks.variables import accept_variable_metadata_input
from datadoc.frontend.callbacks.variables import (
update_variable_table_dropdown_options_for_language,
)
from datadoc.frontend.callbacks.variables import update_variable_table_language
from datadoc.frontend.components.builders import VARIABLES_METADATA_INPUT
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.resources_test_new_variables import (
VARIABLES_METADATA_INPUT,
)
from datadoc.frontend.components.resources_test_new_variables import build_edit_section
from datadoc.frontend.components.resources_test_new_variables import build_ssb_accordion
from datadoc.frontend.fields.display_dataset import DISPLAYED_DROPDOWN_DATASET_METADATA
from datadoc.frontend.fields.display_new_variables import OBLIGATORY_VARIABLES_METADATA
from datadoc.frontend.fields.display_new_variables import OPTIONAL_VARIABLES_METADATA
from datadoc.frontend.fields.display_variables import OBLIGATORY_VARIABLES_METADATA
from datadoc.frontend.fields.display_variables import OPTIONAL_VARIABLES_METADATA

if TYPE_CHECKING:
import dash_bootstrap_components as dbc
Expand All @@ -57,7 +48,14 @@ def register_callbacks(app: Dash) -> None:
Output("progress-bar", "value"),
Output("progress-bar", "label"),
Input({"type": DATASET_METADATA_INPUT, "id": ALL}, "value"),
Input("variables-table", "data"),
Input(
{
"type": VARIABLES_METADATA_INPUT,
"variable_short_name": ALL,
"id": ALL,
},
"value",
),
)
def callback_update_progress(
value: MetadataInputTypes, # noqa: ARG001 argument required by Dash
Expand Down Expand Up @@ -122,50 +120,6 @@ def callback_accept_dataset_metadata_input(
ctx.triggered_id["id"],
)

@app.callback(
Output("variables-table", "data"),
Output("variables-validation-error", "is_open"),
Output("variables-validation-explanation", "children"),
State("variables-table", "active_cell"),
Input("variables-table", "data"),
State("variables-table", "data_previous"),
Input("language-dropdown", "value"),
prevent_initial_call=True,
)
def callback_variable_table(
active_cell: dict,
data: list[dict],
data_previous: list[dict],
language: str,
) -> tuple[list[dict], bool, str]:
"""Update data in the variable table.
Triggered upon:
- New data enetered in the variable table.
- Change of language.
Will display an alert if validation fails.
"""
if ctx.triggered_id == "language-dropdown":
return update_variable_table_language(SupportedLanguages(language))

return accept_variable_datatable_metadata_input(
data,
active_cell,
data_previous,
)

@app.callback(
Output("variables-table", "dropdown"),
Input("language-dropdown", "value"),
)
def callback_variable_table_dropdown_options(
language: str,
) -> dict[str, dict[str, object]]:
"""Update the options in variable table dropdowns when the language changes."""
language = SupportedLanguages(language)
return update_variable_table_dropdown_options_for_language(language)

@app.callback(
Output("opened-dataset-success", "is_open"),
Output("opened-dataset-error", "is_open"),
Expand Down Expand Up @@ -203,15 +157,6 @@ def callback_clear_accordion_values(n_clicks: int) -> list[dbc.AccordionItem]:
return build_dataset_metadata_accordion(n_clicks)
return no_update


def register_new_variables_tab_callbacks(app: Dash) -> None:
"""Define and register callbacks for the new variables tab.
This may be included in the main register_callbacks function once it's
ready for production.
"""
logger.info("Registering callbacks for the new variable tab for %s", app.title)

@app.callback(
Output("accordion-wrapper", "children"),
Input("language-dropdown", "value"),
Expand All @@ -228,7 +173,7 @@ def callback_populate_new_variables_workspace(
variable.short_name,
{
"type": "variables-accordion",
"id": f"{variable.short_name}-{language}",
"id": f"{variable.short_name}-{language}", # Insert language into the ID to invalidate browser caches
},
variable.short_name,
children=[
Expand Down
Loading

0 comments on commit 70d0222

Please sign in to comment.