DataEditor Module Documentation¶
The DataEditor module is a configurable component within the SSB Dash Framework. It is designed for micro-level editing, validation, and metadata visualization of statistical survey data (e.g., Altinn questionnaires) within Statistics Norway (SSB) platforms like Dapla.
This document is a reference for the MicroLayout components and explains how the module is built. To learn how to set up a DataEditor in your app, with both YAML and Python, follow the guide Edit form data with the DataEditor.
Table of Contents¶
MicroLayout Components Reference¶
The key to customizing individual data views is MicroLayout. It arranges elements on a grid and binds input controls to data fields. In a MicroLayout definition, each item has a required "type" key.
A DataViewCustom layout itself may only contain row, col, microlayout and nested DataViewCustom nodes. All components below are used inside the layout of a microlayout node.
The microlayout node accepts these keys in addition to layout:
inputs: Variable selector fields that select the form, in the order refnr field, then time unit field. Defaults to the configuredrefnrand time unit.Any
EditorSettingskey, for examplefield_name_colorform_data_table. These override theDataEditorsettings for this microlayout only.
applies_to_forms and applies_to_tables belong on the DataViewCustom node, not on the microlayout node.
Below is an overview of all supported components:
Layout & Grid Containers¶
Container components arrange other elements into columns, rows, or tabular layouts. They contain a list of child configurations in their children key.
Type |
Key Properties |
Description |
Example |
|---|---|---|---|
|
|
Arranges all child elements horizontally in a single row. |
|
|
|
Arranges all child elements vertically in a column. |
|
|
|
Displays a tabbed header bar. The tabs shown are the |
|
|
|
Represents a single page or view category inside a |
|
Leaf & Value Components¶
Leaf components display static information, gather user input, show chart visualizers, or display auto-calculated numbers.
Component Type |
Properties |
Description |
Example Configuration |
|---|---|---|---|
|
|
Displays a static title or section header. |
|
|
|
Renders plain static helper text or instructions. |
|
|
|
Standard text box for reading and writing data values. Saves when the field loses focus or when the user presses Enter. |
|
|
|
Multiline input box. Best suited for comments, clarifications, or descriptive feedback. Saves when the field loses focus. |
|
|
|
Standard dropdown containing user-defined options of |
|
|
|
Checklist allowing users to toggle multiple criteria. |
|
|
|
SSB-specific! Connects directly with the SSB Klass Classification API. Fetches the classification code list (e.g. |
|
|
|
Similar to |
|
|
|
Runs client-side math calculations in real-time. |
|
|
|
Renders a trend line (sparkline graph) of specific variable values over a past number of periods for historical comparison. |
|
|
|
Generates a table of all fields matching a pattern, capturing repeating or dynamic field lists. The pattern is a SQL |
|
Advanced Architecture & Framework Integration¶
To understand how the DataEditor fits within the broader SSB Dash Framework, we need to inspect its internal division of responsibilities and flow.
+-----------------------------------------------------------------------+
| SSB Dash Application |
| |
| +---------------------------------------------------------------+ |
| | VariableSelector | |
| | - refnr (reference number) | |
| | - ident (organization identification) | |
| | - altinnskjema (selected form) | |
| | - iso_periode (selected statistical period) | |
| +-----------------------------------------------+---------------+ |
| | |
| v triggers callbacks|
| +---------------------------------------------------------------+ |
| | DataEditor Tab | |
| | | |
| | +---------------------------------------------------------+ | |
| | | Info Row | | |
| | | (Displays unit metadata: Orgnr, Name, active Form) | | |
| | +---------------------------------------------------------+ | |
| | | |
| | +------------+ +----------------------------------------+ | |
| | | Sidebar | | Helper Buttons Row | | |
| | | - Table | | - Editing History - Contact Info | | |
| | | Selector | +----------------------------------------+ | |
| | | - Status | +----------------------------------------+ | |
| | | Tracking | | Main View | | |
| | | - Comments | | (Switches layouts dynamically based | | |
| | +------------+ | on selected Table and Form ID) | | |
| | | | | |
| | | +------------------------------+ | | |
| | | | DataViewCustom (Form) | | | |
| | | | - Powered by MicroLayoutAIO| | | |
| | | +------------------------------+ | | |
| | +----------------------------------------+ | |
| +---------------------------------------+-----------------------+ |
| | |
| v reads/writes |
| +---------------------------------------+-----------------------+ |
| | StandardDataHandler | |
| | (Interacts with underlying Ibis/Postgres/Parquet backend) | |
| +---------------------------------------------------------------+ |
+-----------------------------------------------------------------------+
Structural Decomposition¶
An instantiated DataEditor is divided into four major UI panels:
Info Row (
DataEditorInfoRow):Placed at the very top. It displays read-only identity indicators (e.g. enterprise name, organizational code, active form schema) relevant to the current respondent.
It queries these variables dynamically from auxiliary metadata tables like
enhetsinfodepending on the current selections.
Sidebar Modules (
DataEditorHelperSidebar):Placed in the left column.
Table Selector (
DataEditorTableSelector): A dropdown that lets the user choose which table to inspect/edit (e.g.,skjemadata). Add it to thesidebarlist. The DataEditor uses its value to pick the data view to show.Editing Status (
DataEditorSidebarEditingStatus): Allows the statistician to mark a questionnaire as “Ubehandlet” (Unprocessed), “Under arbeid” (Under work/editing), or “Ferdig” (Finished/approved). Writes these flags directly back to theskjemamottaktracking table.Comment Field (
DataEditorSidebarComment): Allows writing and retrieving notes or comments regarding that specific submission.
Helper Buttons (
DataEditorHelperButton):Placed on the top-right card.
History Viewer (
DataEditorHistory): Shows the editing history of the form, as returned by the data handler’sget_history.Contact Information (
DataEditorContactInfo): Displays details of the person who submitted the form (e.g., name, phone number, email address) to enable easy verification and communication.Support Tables (
DataEditorSupportTables): Shows a collection of supporting reference tables in a window.
Main Data View (
DataEditorDataView):Placed on the bottom-right card.
Depending on settings, it switches between a full-width spreadsheet editor (
DataEditorTable) powered by AgGrid, or a customized, domain-specific questionnaire view (DataViewCustom) which parses yourmicrolayoutdefinitions.If there are multiple layouts, it registers them under a layout lookup mapping index
(table_name, form_id)and shows/hides them dynamically based on the current selection.
Decoupled Communication¶
Modules in the SSB Dash Framework do not call each other directly. Instead, they rely on the VariableSelector to manage active contextual state (such as the selected company ident, statistical period iso_periode, or active questionnaire identifier altinnskjema).
When a user switches units or periods in the global dropdowns:
The
VariableSelectorupdates its global reactive attributes.The
DataEditorcatches these changes through built-in Dash callbacks (e.g.,toggle_view_visibilityineditor.pylistening toVariableSelector.get_input("altinnskjema")).These callbacks fetch updated data from the backend, reset editing states, and re-render the appropriate custom micro-layouts for the matching questionnaire structure.
This decoupled architecture makes it extremely simple to plug different views or helper buttons in and out of the app without breaking core editor functionality.
The Data Access Layer¶
To keep database queries separate from UI layout logic, the DataEditor depends on a data handler inheriting from FetcherMeta. The default implementation is StandardDataHandler.
The handler performs several tasks:
Form Caching: Employs
FormGetterCachedto cache datasets from the backend on-the-fly, reducing database latency during navigation.Reading Values (
get_field): Queries targeted fields dynamically. For instance, filtering files/tables where the reference number (refnr) matches and where the field path (feltsti) matches the target variable path.Committing Changes (
update_field_value): Writes individual adjustments back to the database. Whenever a user changes a value in aninputortextareaand leaves the field (or presses Enter), an update signal triggers the handler, which updates the respective table (e.g., updating a cell’s string value or setting updated statuses in the tracking database).
The data handler is the only place the DataEditor reads or writes data, so any data can be used by writing a handler that inherits from FetcherMeta (or from StandardDataHandler). See Use your own data in the guide.
The MicroLayout Engine¶
How does a JSON/YAML configuration list get translated into functional Dash components without developer intervention?
Pydantic Validation: When custom views are parsed (via
DataViewCustom.from_yamlor when loadingAppConfig), each element in the layout list is parsed against the discriminated union defined inssb_dash_framework/modules/data_editor/modules/microlayout/microlayout_components/models.py. If a field is missing required parameters (such as a missingklass_codeinklass-dropdown), the application fails fast during validation, printing precise errors before launching the web server.All-In-One (AIO) Isolation: To prevent duplicate component ID conflicts when multiple micro-layouts are active simultaneously, the framework encapsulates forms inside the
MicroLayoutAIOlayout engine. Each form receives a randomized or structured UUID prefix (aio_id). Standard components inside utilize compound dictionary IDs:id={"comp_id": field_variable, "aio": options.aio_id}Auto-Wiring Callbacks: Inside
MicroLayoutAIO, the system loops through all validated leaf components. For every interactive node (likeInputFieldorTextarea):It instantiates a
FieldCallbackContainercontaining the specific field metadata.It registers a dynamic Dash callback listening to
valuechanges. Inputs and textareas are debounced, so they only send their value when the field loses focus or the user presses Enter.When triggered, these callbacks feed changes directly into the
StandardDataHandlerwhich commits them, completing the end-to-end data flow seamlessly.
Internal Architecture & UML Diagram¶
To provide a complete map of how the classes, data wrappers, and dynamic layouts coordinate internally, we have authored a detailed D2 UML Diagram in data_editor.d2.
Architectural Relationships Map¶
The D2 diagram outlines several critical layers:
The Core Orchestration Module (
DataEditor): Houses configurations, manages sub-layouts, and connects to the globalVariableSelectorto trigger updates on active context adjustments (such as switching target organizations or periods).Sub-Modules and Helper Panels: Holds the layout and callback behavior for contextual widgets like metadata cards (
DataEditorInfoRow), comments management (DataEditorSidebarComment), status toggles (DataEditorSidebarEditingStatus), and helper modals (DataEditorContactInfo,DataEditorHistory,DataEditorSupportTables).The Data Views Grid (
DataEditorTable&DataViewCustom): Standard spreadsheet mode coordinates edits directly via SQL wrappers, while custom layouts read tree-like configurations to draw questionnaire interfaces.The MicroLayout Form Engine (
MicroLayoutAIO): The heart of config-driven layouts. It validates shapes using Pydantic, generates isolatedaio_idnamespaces, auto-wires Javascript-based math callbacks, and dynamically binds value-change listeners.The Persistence/Database Access Layer (
StandardDataHandler): ImplementsFetcherMetato wrap all database execution. IntegratesFormGetterCachedto cache datasets on-the-fly and processesUpdateSkjemadatamodels.
Rendering the UML Diagram¶
To compile this D2 specification into a visual SVG or PNG diagram, run:
d2 docs/modules/dataeditor/data_editor.d2 docs/modules/dataeditor/data_editor.svg
Or you can paste the contents of data_editor.d2 into any D2 playground/viewer (e.g., https://play.d2lang.com/).