talbe definition web

This commit is contained in:
Priec
2026-08-06 17:47:53 +02:00
parent f13def52c1
commit 5f4b026624
14 changed files with 870 additions and 273 deletions

View File

@@ -1,13 +1,15 @@
//! Reads everything the workspace shows.
//!
//! Three calls, in this order: the profile tree names the profiles and their
//! tables, the profile details describe the selected table's columns and
//! scripts, and the rename history explains how those columns got their names.
//! Four calls, in this order: the column-type catalog is the vocabulary the
//! append panel offers, the profile tree names the profiles and their tables,
//! the profile details describe the selected table's columns and scripts, and
//! the rename history explains how those columns got their names.
//! Nothing here trusts the posted selection — a profile or table that is gone
//! is dropped from the selection rather than reported as an error, because the
//! commonest way to get here with a stale one is having just deleted it.
use axum::http::HeaderMap;
use tonic::transport::Channel;
use crate::{
AppState,
@@ -16,8 +18,10 @@ use crate::{
common::Empty,
table_definition::{
GetColumnAliasRenameHistoryRequest, GetProfileDetailsRequest, MoneyRounding,
table_definition_client::TableDefinitionClient,
},
},
schema::{ColumnCatalog, column_catalog},
services::authenticated_request,
};
@@ -26,6 +30,27 @@ use super::state::{
TableDetailView, TableSummary,
};
/// Reads the column-type vocabulary on its own.
///
/// The panel's handlers stage and validate a column before the rest of the
/// workspace is read, and they cannot do either without the vocabulary, so
/// they fetch it with this and hand it to [`load_page`] on the draft.
pub(crate) async fn load_column_catalog(
definitions: &mut TableDefinitionClient<Channel>,
headers: &HeaderMap,
) -> Result<ColumnCatalog, LoadError> {
let request =
authenticated_request(headers, Empty {}).map_err(|_| LoadError::Unauthenticated)?;
let response = definitions
.list_column_types(request)
.await
.map_err(|error| match error.code() {
tonic::Code::Unauthenticated => LoadError::Unauthenticated,
_ => LoadError::Backend(error.message().to_string()),
})?;
Ok(column_catalog(response.into_inner().column_types))
}
pub(crate) async fn load_page(
state: AppState,
headers: &HeaderMap,
@@ -47,6 +72,15 @@ pub(crate) async fn load_page(
}
let mut definitions = state.definitions;
// A handler that had to stage or validate a column before it got here has
// already read the vocabulary; anything else reads it now.
if !inputs.columns.catalog.is_loaded() {
inputs.columns.catalog = load_column_catalog(&mut definitions, headers).await?;
}
// Also what the definition below is read through: the catalog describes
// the server-generated companion types as well as the declarable ones.
let catalog = inputs.columns.catalog.clone();
let tree = definitions
.get_profile_tree(
authenticated_request(headers, Empty {}).map_err(|_| LoadError::Unauthenticated)?,
@@ -119,6 +153,7 @@ pub(crate) async fn load_page(
let behavior = table.column_behaviors.get(&column.name);
DetailColumn {
name: column.name.clone(),
sql_type: catalog.sql_type(&column.field_type),
field_type: column.field_type.clone(),
currency: column.currency.clone(),
quantity_ledger: column.quantity_ledger,