organization of incoming data

This commit is contained in:
Priec
2026-08-12 17:46:58 +02:00
parent 08af99e334
commit 719bae0cd2
10 changed files with 184 additions and 24 deletions

View File

@@ -117,6 +117,7 @@ pub(crate) async fn load_page(
.map(|table| TableSummary {
name: table.name.clone(),
table_kind: table.table_kind.clone(),
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.
depends_on: table

View File

@@ -45,6 +45,7 @@ impl Selection {
pub(crate) struct TableSummary {
pub name: String,
pub table_kind: String,
pub global: bool,
pub depends_on: Vec<String>,
pub row_display_columns: Vec<String>,
}
@@ -277,10 +278,34 @@ pub(crate) struct TablePermissionAction {
}
impl TableDefinitionPageState {
pub(crate) fn link_target_tables(&self) -> Vec<&str> {
fn eligible_link_target(&self, table: &TableSummary) -> bool {
table.name != self.selection.table && table.name != "accounts"
}
pub(crate) fn global_link_target_tables(&self) -> Vec<&str> {
self.tables
.iter()
.filter(|table| table.name != self.selection.table && table.name != "accounts")
.filter(|table| self.eligible_link_target(table) && table.global)
.map(|table| table.name.as_str())
.collect()
}
pub(crate) fn user_link_target_tables(&self) -> Vec<&str> {
self.tables
.iter()
.filter(|table| {
self.eligible_link_target(table) && !table.global && !table.is_system()
})
.map(|table| table.name.as_str())
.collect()
}
pub(crate) fn system_link_target_tables(&self) -> Vec<&str> {
self.tables
.iter()
.filter(|table| {
self.eligible_link_target(table) && !table.global && table.is_system()
})
.map(|table| table.name.as_str())
.collect()
}

View File

@@ -108,6 +108,7 @@ mod tests {
TableSummary {
name: name.to_string(),
table_kind: kind.to_string(),
global: false,
depends_on: Vec::new(),
row_display_columns: vec!["number".to_string()],
}
@@ -234,12 +235,21 @@ mod tests {
let mut state = page();
state.columns.type_input = "link".to_string();
state.tables.push(table("customer", "dynamic"));
state.tables.push(TableSummary {
global: true,
..table("currencies", "dynamic")
});
state.tables.push(table("audit_log", "system"));
let html = render_column_panel(&state);
assert!(html.contains(r#">FKlink</option>"#));
assert!(html.contains("Link alias"));
assert!(html.contains(r#"name="link_table_input""#));
assert!(html.contains(r#"<option value="customer""#));
assert!(html.contains(r#"<optgroup label="Global">"#));
assert!(html.contains(r#"<optgroup label="User-created">"#));
assert!(html.contains(r#"<optgroup label="System-created">"#));
assert!(!html.contains(r#"<option value="invoice""#));
}