global table content
This commit is contained in:
@@ -26,7 +26,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use super::state::{
|
||||
DetailColumn, LoadError, PageInputs, RenameEntry, ScriptView, TableDefinitionPageState,
|
||||
DetailColumn, GLOBAL_SCOPE, LoadError, PageInputs, RenameEntry, ScriptView, TableDefinitionPageState,
|
||||
TableDetailView, TablePermissionAction, TableRolePermissions, TableSummary,
|
||||
};
|
||||
|
||||
@@ -96,19 +96,24 @@ pub(crate) async fn load_page(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// A profile that no longer exists takes the table selection with it.
|
||||
if !profiles.contains(&inputs.selection.profile) {
|
||||
if inputs.selection.profile != GLOBAL_SCOPE && !profiles.contains(&inputs.selection.profile) {
|
||||
inputs.selection.profile.clear();
|
||||
inputs.selection.table.clear();
|
||||
}
|
||||
|
||||
let tables = tree
|
||||
.profiles
|
||||
.iter()
|
||||
.find(|profile| profile.name == inputs.selection.profile)
|
||||
.map(|profile| {
|
||||
profile
|
||||
.tables
|
||||
let selected_tables = if inputs.selection.is_global() {
|
||||
tree.profiles.first().map(|profile| profile.tables.as_slice())
|
||||
} else {
|
||||
tree.profiles
|
||||
.iter()
|
||||
.find(|profile| profile.name == inputs.selection.profile)
|
||||
.map(|profile| profile.tables.as_slice())
|
||||
};
|
||||
let tables = selected_tables
|
||||
.map(|tables| {
|
||||
tables
|
||||
.iter()
|
||||
.filter(|table| table.global == inputs.selection.is_global())
|
||||
.map(|table| TableSummary {
|
||||
name: table.name.clone(),
|
||||
table_kind: table.table_kind.clone(),
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
use crate::schema::{ColumnCatalog, ColumnDraft};
|
||||
|
||||
pub(crate) const GLOBAL_SCOPE: &str = "__global";
|
||||
|
||||
/// The profile and table the workspace is pointed at. Arrives as a query
|
||||
/// string on the selector and on the column-panel endpoints, and as hidden
|
||||
/// fields on the panels that write.
|
||||
@@ -27,6 +29,10 @@ impl Selection {
|
||||
!self.table.is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn is_global(&self) -> bool {
|
||||
self.profile == GLOBAL_SCOPE
|
||||
}
|
||||
|
||||
/// The query string the column panel posts back to, so the panel's own
|
||||
/// form does not have to carry the selection among its column fields.
|
||||
pub(crate) fn query(&self) -> String {
|
||||
|
||||
@@ -113,6 +113,20 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_tables_have_their_own_scope() {
|
||||
let mut state = page();
|
||||
state.selection.profile = "__global".to_string();
|
||||
|
||||
let html = render_workspace(&state);
|
||||
|
||||
assert!(html.contains(r#"value="__global" selected"#));
|
||||
assert!(html.contains("Global — all profiles"));
|
||||
assert!(html.contains("/admin/tables/new?global=true"));
|
||||
assert!(!html.contains("Copy <code>__global</code>"));
|
||||
assert!(!html.contains("Create tables from an invoice template"));
|
||||
}
|
||||
|
||||
fn page() -> TableDefinitionPageState {
|
||||
TableDefinitionPageState {
|
||||
nav: Nav::default(),
|
||||
@@ -254,7 +268,7 @@ mod tests {
|
||||
state.tables.clear();
|
||||
let html = render_workspace(&state);
|
||||
assert!(!html.contains("/admin/table-definition/copy"));
|
||||
assert!(html.contains("Choose a profile"));
|
||||
assert!(html.contains("Choose a scope"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user