organization of incoming data
This commit is contained in:
@@ -27,6 +27,13 @@ pub(crate) struct PreviewRow {
|
||||
pub source: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct RelationTableOption {
|
||||
pub name: String,
|
||||
pub global: bool,
|
||||
pub system: bool,
|
||||
}
|
||||
|
||||
/// The whole Add-table page state, minus presentation.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(crate) struct TableDraft {
|
||||
@@ -46,6 +53,7 @@ pub(crate) struct TableDraft {
|
||||
/// Tables in the target profile, offered as `link(...)` targets by the
|
||||
/// column picker.
|
||||
pub relation_tables: Vec<String>,
|
||||
pub relation_table_options: Vec<RelationTableOption>,
|
||||
/// Columns identifying a row to users, in the order they are shown.
|
||||
/// Empty means rows are identified by their id alone.
|
||||
pub row_display_columns: Vec<String>,
|
||||
@@ -125,11 +133,57 @@ impl TableDraft {
|
||||
|
||||
/// Records the tables the target profile offers as link targets. A table
|
||||
/// cannot link to itself, so its own name is never among them.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn set_available_relation_tables(&mut self, table_names: Vec<String>) {
|
||||
self.relation_tables = table_names
|
||||
self.set_available_relation_table_options(
|
||||
table_names
|
||||
.into_iter()
|
||||
.map(|name| RelationTableOption {
|
||||
name,
|
||||
global: false,
|
||||
system: false,
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn set_available_relation_table_options(
|
||||
&mut self,
|
||||
options: Vec<RelationTableOption>,
|
||||
) {
|
||||
self.relation_table_options = options
|
||||
.into_iter()
|
||||
.filter(|table_name| table_name != &self.table_name)
|
||||
.filter(|option| option.name != self.table_name)
|
||||
.collect();
|
||||
self.relation_tables = self
|
||||
.relation_table_options
|
||||
.iter()
|
||||
.map(|option| option.name.clone())
|
||||
.collect();
|
||||
}
|
||||
|
||||
pub(crate) fn global_relation_tables(&self) -> Vec<&str> {
|
||||
self.relation_table_options
|
||||
.iter()
|
||||
.filter(|option| option.global)
|
||||
.map(|option| option.name.as_str())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn user_relation_tables(&self) -> Vec<&str> {
|
||||
self.relation_table_options
|
||||
.iter()
|
||||
.filter(|option| !option.global && !option.system)
|
||||
.map(|option| option.name.as_str())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn system_relation_tables(&self) -> Vec<&str> {
|
||||
self.relation_table_options
|
||||
.iter()
|
||||
.filter(|option| !option.global && option.system)
|
||||
.map(|option| option.name.as_str())
|
||||
.collect()
|
||||
}
|
||||
|
||||
// ---- derived state ---------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user