organization of incoming data
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::{
|
||||
services::authenticated_request,
|
||||
};
|
||||
|
||||
use super::{draft::TableDraft, state::AddTablePageState};
|
||||
use super::{draft::{RelationTableOption, TableDraft}, state::AddTablePageState};
|
||||
|
||||
/// Loads everything the builder needs around the draft: the column-type
|
||||
/// vocabulary, the profiles that can be picked, and — for whichever profile the
|
||||
@@ -66,9 +66,14 @@ pub(crate) async fn load_page(
|
||||
.iter()
|
||||
.flat_map(|profile| profile.tables.iter())
|
||||
.filter(|table| table.global)
|
||||
.map(|table| table.name.clone())
|
||||
.collect::<std::collections::BTreeSet<_>>()
|
||||
.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
|
||||
@@ -78,7 +83,7 @@ pub(crate) async fn load_page(
|
||||
.collect::<std::collections::BTreeSet<_>>()
|
||||
.into_iter()
|
||||
.collect();
|
||||
draft.set_available_relation_tables(global_tables);
|
||||
draft.set_available_relation_table_options(global_tables);
|
||||
} else { match tree
|
||||
.profiles
|
||||
.iter()
|
||||
@@ -87,19 +92,27 @@ 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_names = profile
|
||||
let table_options = profile
|
||||
.tables
|
||||
.iter()
|
||||
.filter(|table| table.name != "accounts")
|
||||
.map(|table| table.name.clone())
|
||||
.map(|table| RelationTableOption {
|
||||
name: table.name.clone(),
|
||||
global: table.global,
|
||||
system: table.table_kind == "system",
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
draft.existing_profile_tables = table_names.clone();
|
||||
draft.set_available_relation_tables(table_names);
|
||||
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.
|
||||
None => {
|
||||
draft.existing_profile_tables.clear();
|
||||
draft.relation_tables.clear();
|
||||
draft.relation_table_options.clear();
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user