web interface for table_definition improved

This commit is contained in:
Priec
2026-08-04 17:20:58 +02:00
parent c2002c7da3
commit 803207b1af
20 changed files with 2989 additions and 612 deletions

View File

@@ -1,12 +1,12 @@
use askama::Template;
use crate::ui::{Alert, Nav, render};
use super::{
draft::{COLUMN_TYPES, CURRENCY_CODES, GTIN_TYPES, TEMPORAL_TYPES},
state::AddTablePageState,
use crate::{
schema::{CURRENCY_CODES, GTIN_TYPES, TEMPORAL_TYPES},
ui::{Alert, Nav, render},
};
use super::state::AddTablePageState;
/// GET /admin/tables/new — the page shell around the builder.
#[derive(Template)]
#[template(path = "pages/add_table/add_table.html")]
@@ -34,7 +34,7 @@ pub(crate) fn render_page(page: &AddTablePageState) -> String {
render(&AddTablePage {
nav: page.nav.clone(),
page,
column_types: COLUMN_TYPES,
column_types: page.draft.columns.offered_types(),
temporal_types: TEMPORAL_TYPES,
gtin_types: GTIN_TYPES,
currency_codes: CURRENCY_CODES,
@@ -44,7 +44,7 @@ pub(crate) fn render_page(page: &AddTablePageState) -> String {
pub(crate) fn render_builder(page: &AddTablePageState) -> String {
render(&BuilderFragment {
page,
column_types: COLUMN_TYPES,
column_types: page.draft.columns.offered_types(),
temporal_types: TEMPORAL_TYPES,
gtin_types: GTIN_TYPES,
})
@@ -60,13 +60,16 @@ pub(crate) fn render_submission_error(message: &str) -> String {
#[cfg(test)]
mod tests {
use super::*;
use crate::pages::add_table::draft::{ColumnDefinition, LinkMode, MoneyMode, TableDraft};
use crate::{
pages::add_table::draft::{LinkMode, TableDraft},
schema::{ColumnDefinition, MoneyMode},
};
fn page() -> AddTablePageState {
let mut draft = TableDraft::new();
draft.profile_name = "billing".to_string();
draft.table_name = "invoice".to_string();
draft.columns.push(ColumnDefinition {
draft.columns.added.push(ColumnDefinition {
name: "number".to_string(),
data_type: "text".to_string(),
indexed: true,
@@ -116,21 +119,41 @@ mod tests {
assert!(html.contains(r#"<option value="EUR">"#));
}
/// Every type the server accepts has to be reachable from the picker, or
/// the web UI silently offers less than the backend does.
#[test]
fn the_type_picker_offers_the_parameterised_and_interval_types() {
let html = render_builder(&page());
for column_type in ["decimal", "duration", "period", "accounting"] {
assert!(
html.contains(&format!(r#"<option value="{column_type}""#)),
"the type picker is missing {column_type}"
);
}
}
#[test]
fn conditional_fields_follow_the_pending_column_type() {
let mut state = page();
assert!(!render_builder(&state).contains(r#"name="temporal_type_input""#));
state.draft.column_type_input = "temporal".to_string();
state.draft.columns.type_input = "temporal".to_string();
let html = render_builder(&state);
assert!(html.contains(r#"name="temporal_type_input""#));
assert!(!html.contains(r#"name="gtin_type_input""#));
state.draft.column_type_input = "gtin".to_string();
state.draft.columns.type_input = "gtin".to_string();
assert!(render_builder(&state).contains(r#"name="gtin_type_input""#));
// Decimal reveals its precision and scale.
state.draft.columns.type_input = "decimal".to_string();
let html = render_builder(&state);
assert!(html.contains(r#"name="decimal_precision_input""#));
assert!(html.contains(r#"name="decimal_scale_input""#));
// Money reveals its currency and rounding inputs.
state.draft.column_type_input = "money".to_string();
state.draft.columns.type_input = "money".to_string();
let html = render_builder(&state);
assert!(html.contains(r#"name="column_rounding_input""#));
assert!(html.contains(r#"list="currency-codes""#));