-
Notifications
You must be signed in to change notification settings - Fork 1
/
variables_tab.py
76 lines (71 loc) · 3.17 KB
/
variables_tab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Components and layout for the Variables metadata tab."""
from __future__ import annotations
import dash_bootstrap_components as dbc
from dash import dash_table, html
from datadoc import state
from datadoc.frontend.components.builders import build_ssb_styled_tab
from datadoc.frontend.fields.display_variables import (
DISPLAY_VARIABLES,
VariableIdentifiers,
)
from datadoc.utils import get_display_values
def build_variables_tab() -> dbc.Tab:
"""Build the Variables metadata tab."""
return build_ssb_styled_tab(
"Variabler",
dbc.Container(
children=[
dbc.Row(html.H2("Variabel detaljer", className="ssb-title")),
dbc.Row(
dash_table.DataTable(
id="variables-table",
# Populate fields with known values
data=[
get_display_values(v, state.current_metadata_language)
for v in state.metadata.meta.variables
],
# Define columns based on the information in DISPLAY_VARIABLES
columns=[
{
"name": variable.display_name,
"id": variable.identifier,
"editable": variable.editable,
"presentation": variable.presentation,
"hideable": variable.editable,
}
for variable in DISPLAY_VARIABLES.values()
if variable.identifier
!= VariableIdentifiers.IDENTIFIER.value # Should be removed from the model, for now we hide it
],
# Non-obligatory variables are hidden by default
hidden_columns=[
v.identifier
for v in DISPLAY_VARIABLES.values()
if v.obligatory is False
],
# Include tooltips for all columns
tooltip_header={
v.identifier: v.description
for v in DISPLAY_VARIABLES.values()
},
editable=True,
# Exclude short_name column from scrolling
fixed_columns={"headers": True, "data": 1},
# Enable sorting and pagination
sort_action="native",
page_action="native",
page_size=20,
# Enable filtering
filter_action="native",
filter_options={"case": "insensitive"},
# Use horizontal scroll, keep full width
style_table={
"overflowX": "auto",
"minWidth": "100%",
"accentColor": "black",
},
),
),
],
),
)