web add table fix in naming

This commit is contained in:
Priec
2026-08-13 22:48:29 +02:00
parent 2b68560359
commit df145c14f7
5 changed files with 89 additions and 21 deletions

View File

@@ -60,21 +60,26 @@ pub(crate) async fn load_page(
.into_inner();
let effective_profile = draft.effective_profile_name();
// A global table belongs to every profile, so it is a link target from
// every scope. It is listed under each profile in the tree, so it is
// collected once here and deduplicated by name.
let global_tables = tree
.profiles
.iter()
.flat_map(|profile| profile.tables.iter())
.filter(|table| table.global)
.map(|table| (table.name.clone(), table.table_kind.clone()))
.collect::<std::collections::BTreeMap<_, _>>()
.into_iter()
.map(|(name, table_kind)| RelationTableOption {
name,
global: true,
system: table_kind == "system",
})
.collect::<Vec<_>>();
if draft.global {
let global_tables = tree
.profiles
.iter()
.flat_map(|profile| profile.tables.iter())
.filter(|table| table.global)
.map(|table| (table.name.clone(), table.table_kind.clone()))
.collect::<std::collections::BTreeMap<_, _>>()
.into_iter()
.map(|(name, table_kind)| RelationTableOption {
name,
global: true,
system: table_kind == "system",
})
.collect::<Vec<_>>();
draft.existing_profile_tables = tree
.profiles
.iter()
@@ -92,7 +97,7 @@ pub(crate) async fn load_page(
// An existing profile: its tables are the link targets, and their
// names are reserved against duplicate table creation.
Some(profile) => {
let table_options = profile
let mut table_options = profile
.tables
.iter()
.filter(|table| table.name != "accounts")
@@ -102,17 +107,28 @@ pub(crate) async fn load_page(
system: table.table_kind == "system",
})
.collect::<Vec<_>>();
// The shared tables belong here whether or not the tree repeated
// them under this profile.
for global in &global_tables {
if !table_options.iter().any(|table| table.name == global.name) {
table_options.push(global.clone());
}
}
draft.existing_profile_tables = table_options
.iter()
.map(|table| table.name.clone())
.collect();
draft.set_available_relation_table_options(table_options);
}
// A brand-new (or not-yet-named) profile has nothing to link to.
// A brand-new (or not-yet-named) profile has no tables of its own,
// but the shared ones are there to link to — and their names are
// taken, so the new table may not reuse one either.
None => {
draft.existing_profile_tables.clear();
draft.relation_tables.clear();
draft.relation_table_options.clear();
draft.existing_profile_tables = global_tables
.iter()
.map(|table| table.name.clone())
.collect();
draft.set_available_relation_table_options(global_tables);
}
}}