new enum instead of string in proto

This commit is contained in:
Priec
2026-09-07 09:54:32 +02:00
parent 6dc20bf7ad
commit e4364e1c44
16 changed files with 122 additions and 40 deletions

View File

@@ -112,12 +112,13 @@ pub(crate) async fn load_page(
// The profile's ledger accounts are not a link target of their own: an
// ACCOUNTING column is how a row is posted to one.
.filter(|table| table.name != crate::schema::LEDGER_ACCOUNTS_TABLE)
.map(|table| RelationTableOption {
.map(|table| Ok(RelationTableOption {
name: table.name,
global: table.global,
system: table.table_kind == "system",
})
.collect::<Vec<_>>();
system: table_scope::table_kind(table.table_kind).map_err(LoadError::Backend)?
== crate::definitions::table_definition::ManagedTableKind::System,
}))
.collect::<Result<Vec<_>, LoadError>>()?;
// Every table the new one would sit beside holds its name — including the
// shared ones, which exist in every profile, and including in a profile

View File

@@ -101,7 +101,7 @@ pub(crate) async fn load_admin_page(
.map(|tables| {
tables
.into_iter()
.map(|table| TableView {
.map(|table| Ok(TableView {
name: table.name,
// One entry per link, named by the column carrying it, so a
// table pointing at one target twice reads as two links.
@@ -113,10 +113,11 @@ pub(crate) async fn load_admin_page(
})
.collect(),
row_display_columns: table.row_display_columns,
table_kind: table.table_kind,
})
.collect::<Vec<_>>()
table_kind: table_scope::table_kind(table.table_kind).map_err(LoadError::Backend)?,
}))
.collect::<Result<Vec<_>, LoadError>>()
})
.transpose()?
.unwrap_or_default();
let selected_table = (!selection.table.is_empty()).then_some(selection.table);

View File

@@ -84,14 +84,14 @@ pub(crate) struct TableView {
pub name: String,
pub depends_on: Vec<String>,
pub row_display_columns: Vec<String>,
pub table_kind: String,
pub table_kind: crate::definitions::table_definition::ManagedTableKind,
}
impl TableView {
/// System tables are backend-managed: the server refuses every structural
/// write on them, so the pane offers none of the action links for one.
pub(crate) fn is_system(&self) -> bool {
self.table_kind == "system"
self.table_kind == crate::definitions::table_definition::ManagedTableKind::System
}
}

View File

@@ -155,7 +155,7 @@ mod tests {
name: "invoice".to_string(),
depends_on: Vec::new(),
row_display_columns: vec!["number".to_string()],
table_kind: "dynamic".to_string(),
table_kind: crate::definitions::table_definition::ManagedTableKind::Dynamic,
}],
selected_table: Some("invoice".to_string()),
columns: Vec::new(),
@@ -195,7 +195,7 @@ mod tests {
name: "currencies".to_string(),
depends_on: Vec::new(),
row_display_columns: vec!["code".to_string()],
table_kind: "dynamic".to_string(),
table_kind: crate::definitions::table_definition::ManagedTableKind::Dynamic,
}],
selected_table: Some("currencies".to_string()),
columns: Vec::new(),

View File

@@ -146,9 +146,9 @@ pub(crate) async fn load_page(
} else {
table_scope::linkable_tables(&tree.profiles, &catalog_tables, &inputs.selection.profile)
};
let summary = |table: crate::definitions::table_definition::profile_tree_response::Table| TableSummary {
let summary = |table: crate::definitions::table_definition::profile_tree_response::Table| -> Result<TableSummary, LoadError> { Ok(TableSummary {
name: table.name,
table_kind: table.table_kind,
table_kind: table_scope::table_kind(table.table_kind).map_err(LoadError::Backend)?,
global: table.global,
// One entry per link, named by the column carrying it, so a table
// pointing at one target twice reads as two links.
@@ -157,9 +157,9 @@ pub(crate) async fn load_page(
.into_iter()
.map(|dependency| format!("{} ({})", dependency.table_name, dependency.column_name))
.collect(),
};
let tables = selected_tables.into_iter().map(summary).collect::<Vec<_>>();
let link_targets = link_targets.into_iter().map(summary).collect::<Vec<_>>();
}) };
let tables = selected_tables.into_iter().map(summary).collect::<Result<Vec<_>, _>>()?;
let link_targets = link_targets.into_iter().map(summary).collect::<Result<Vec<_>, _>>()?;
// A table the scope does not hold is dropped rather than acted on. It is
// said out loud, though: dropping it in silence is what left the panel

View File

@@ -67,7 +67,7 @@ impl Selection {
#[derive(Clone, Debug)]
pub(crate) struct TableSummary {
pub name: String,
pub table_kind: String,
pub table_kind: crate::definitions::table_definition::ManagedTableKind,
pub global: bool,
pub depends_on: Vec<String>,
}
@@ -76,7 +76,7 @@ impl TableSummary {
/// System tables are backend-managed: the server refuses every write below
/// on them, so the workspace does not offer the panels either.
pub(crate) fn is_system(&self) -> bool {
self.table_kind == "system"
self.table_kind == crate::definitions::table_definition::ManagedTableKind::System
}
}

View File

@@ -247,10 +247,10 @@ mod tests {
schema::ColumnDraft,
};
fn table(name: &str, kind: &str) -> TableSummary {
fn table(name: &str, kind: crate::definitions::table_definition::ManagedTableKind) -> TableSummary {
TableSummary {
name: name.to_string(),
table_kind: kind.to_string(),
table_kind: kind,
global: false,
depends_on: Vec::new(),
}
@@ -268,8 +268,8 @@ mod tests {
profile: "billing".to_string(),
table: "invoice".to_string(),
},
tables: vec![table("invoice", "dynamic"), table("ledger_accounts", "system")],
link_targets: vec![table("invoice", "dynamic"), table("ledger_accounts", "system")],
tables: vec![table("invoice", crate::definitions::table_definition::ManagedTableKind::Dynamic), table("ledger_accounts", crate::definitions::table_definition::ManagedTableKind::System)],
link_targets: vec![table("invoice", crate::definitions::table_definition::ManagedTableKind::Dynamic), table("ledger_accounts", crate::definitions::table_definition::ManagedTableKind::System)],
detail: Some(TableDetailView {
id: 7,
row_version: 1,
@@ -364,7 +364,7 @@ mod tests {
};
state.tables = vec![TableSummary {
name: "currencies".to_string(),
table_kind: "dynamic".to_string(),
table_kind: crate::definitions::table_definition::ManagedTableKind::Dynamic,
global: true,
depends_on: Vec::new(),
}];
@@ -598,12 +598,12 @@ mod tests {
state.columns.type_input = "link".to_string();
// The link targets are their own list: a profile's table may point at
// a shared one, which is not among the profile's own tables.
state.link_targets.push(table("customer", "dynamic"));
state.link_targets.push(table("customer", crate::definitions::table_definition::ManagedTableKind::Dynamic));
state.link_targets.push(TableSummary {
global: true,
..table("currencies", "dynamic")
..table("currencies", crate::definitions::table_definition::ManagedTableKind::Dynamic)
});
state.link_targets.push(table("audit_log", "system"));
state.link_targets.push(table("audit_log", crate::definitions::table_definition::ManagedTableKind::System));
let html = render_column_panel(&state);

View File

@@ -13,6 +13,14 @@
//! profile's own tables are the tree's. Neither is derived from the other.
use crate::definitions::table_definition::profile_tree_response::{Profile, Table};
use crate::definitions::table_definition::ManagedTableKind;
pub(crate) fn table_kind(value: i32) -> Result<ManagedTableKind, String> {
match ManagedTableKind::try_from(value) {
Ok(kind @ (ManagedTableKind::Dynamic | ManagedTableKind::System)) => Ok(kind),
_ => Err(format!("Invalid managed table kind: {value}")),
}
}
/// The tables of the global scope: the catalog for `profile_name: None`, which
/// is every shared table in the deployment, whether or not any profile exists
@@ -74,7 +82,7 @@ pub(crate) mod tests {
name: name.to_string(),
depends_on: Vec::new(),
row_display_columns: Vec::new(),
table_kind: "dynamic".to_string(),
table_kind: ManagedTableKind::Dynamic.into(),
global,
profile_name: if global {
SHARED_PROFILE.to_string()