talbe definition web

This commit is contained in:
Priec
2026-08-06 17:47:53 +02:00
parent f13def52c1
commit 5f4b026624
14 changed files with 870 additions and 273 deletions

View File

@@ -15,7 +15,7 @@ use crate::{
definitions::table_definition::{
PostTableDefinitionRequest, TableLink as ProtoTableLink,
},
schema::{ColumnDraft, proto_columns, validate_identifier},
schema::{ColumnCatalog, ColumnDraft, proto_columns, validate_identifier},
};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -102,11 +102,13 @@ pub(crate) struct TableDraft {
}
impl TableDraft {
/// A draft for a brand-new page load, matching the client's defaults.
/// A draft for a brand-new page load, matching the client's defaults. The
/// column panel's vocabulary is filled in by the loader, which is the only
/// thing that knows it.
pub(crate) fn new() -> Self {
Self {
accounting_currency: "EUR".to_string(),
columns: ColumnDraft::new(),
columns: ColumnDraft::new(ColumnCatalog::default()),
..Self::default()
}
}
@@ -148,6 +150,11 @@ impl TableDraft {
self.row_display_columns.clear();
return;
}
// A compound column leaves no column of its own name behind, so it can
// never identify a row; `row_display_candidates` does not offer one.
if !self.columns.is_indexable(index - 1) {
return;
}
let Some(column) = self
.columns
.added
@@ -354,6 +361,9 @@ mod tests {
fn draft_with_column(name: &str, data_type: &str) -> TableDraft {
let mut draft = TableDraft::new();
// The loader fills this in from the backend; a draft under test gets
// the same vocabulary directly.
draft.columns.catalog = crate::schema::tests::catalog();
draft.profile_name = "billing".to_string();
draft.table_name = "invoice".to_string();
draft.columns.added.push(ColumnDefinition {
@@ -471,6 +481,26 @@ mod tests {
assert!(draft.row_display_columns.is_empty());
}
/// A compound column expands into schema-managed companions, so there is
/// no column of that name for a row to be identified by — the builder does
/// not offer it, and a crafted post cannot choose it either.
#[test]
fn a_compound_column_never_identifies_a_row() {
let mut draft = draft_with_column("number", "text");
draft.columns.added.push(ColumnDefinition {
name: "accounting".to_string(),
data_type: "accounting".to_string(),
indexed: false,
quantity_ledger: false,
money_mode: MoneyMode::Exact,
currency: "EUR".to_string(),
});
draft.toggle_row_display_candidate(2);
assert!(draft.row_display_columns.is_empty());
}
#[test]
fn removing_a_column_drops_it_from_the_display_columns() {
let mut draft = draft_with_column("number", "text");