From 395a547b94679b9f73348c84b6b4eca17d5399b4 Mon Sep 17 00:00:00 2001 From: Brent Schroeter Date: Tue, 14 Oct 2025 05:17:41 +0000 Subject: [PATCH] wip: allow updating field spec --- .../relations_single/update_field_handler.rs | 67 +------------------ svelte/src/field-header.svelte | 8 ++- 2 files changed, 10 insertions(+), 65 deletions(-) diff --git a/interim-server/src/routes/relations_single/update_field_handler.rs b/interim-server/src/routes/relations_single/update_field_handler.rs index 9bedce1..2e27c79 100644 --- a/interim-server/src/routes/relations_single/update_field_handler.rs +++ b/interim-server/src/routes/relations_single/update_field_handler.rs @@ -35,7 +35,7 @@ pub(super) struct PathParams { #[derive(Debug, Deserialize)] pub(super) struct FormBody { - name: String, + field_id: Uuid, label: String, presentation_tag: String, dropdown_allow_custom: Option, @@ -43,9 +43,7 @@ pub(super) struct FormBody { timestamp_format: Option, } -/// HTTP POST handler for adding a [`Field`] to a [`Portal`]. If the field name -/// does not match a column in the backing database, a new column is created -/// with a compatible type. +/// HTTP POST handler for updating an existing [`Field`]. /// /// This handler expects 3 path parameters with the structure described by /// [`PathParams`]. @@ -83,64 +81,5 @@ pub(super) async fn post( .acquire_for(workspace.id, RoleAssignment::User(user.id)) .await?; - let class = PgClass::with_oid(portal.class_oid) - .fetch_one(&mut workspace_client) - .await?; - - let presentation = try_presentation_from_form(&form)?; - - query(&format!( - "alter table {ident} add column if not exists {col} {typ}", - ident = class.get_identifier(), - col = escape_identifier(&form.name), - typ = presentation.attr_data_type_fragment(), - )) - .execute(workspace_client.get_conn()) - .await?; - - Field::insert() - .portal_id(portal.id) - .name(form.name) - .table_label(if form.label.is_empty() { - None - } else { - Some(form.label) - }) - .presentation(presentation) - .build()? - .insert(&mut app_db) - .await?; - - Ok(navigator - .portal_page() - .workspace_id(workspace_id) - .rel_oid(Oid(rel_oid)) - .portal_id(portal_id) - .build()? - .redirect_to()) -} - -fn try_presentation_from_form(form: &FormBody) -> Result { - // Parses the presentation tag into the correct enum variant, but without - // meaningful inner value(s). Match arms should all use the - // `MyVariant { .. }` pattern to pay attention to only the tag. - let presentation_default = Presentation::try_from(form.presentation_tag.as_str())?; - Ok(match presentation_default { - Presentation::Dropdown { .. } => Presentation::Dropdown { allow_custom: true }, - Presentation::Text { .. } => Presentation::Text { - input_mode: form - .text_input_mode - .clone() - .map(|value| TextInputMode::try_from(value.as_str())) - .transpose()? - .unwrap_or_default(), - }, - Presentation::Timestamp { .. } => Presentation::Timestamp { - format: form - .timestamp_format - .clone() - .unwrap_or(RFC_3339_S.to_owned()), - }, - Presentation::Uuid { .. } => Presentation::Uuid {}, - }) + todo!(); } diff --git a/svelte/src/field-header.svelte b/svelte/src/field-header.svelte index a2c3fa2..35f65f4 100644 --- a/svelte/src/field-header.svelte +++ b/svelte/src/field-header.svelte @@ -80,7 +80,13 @@ style:position-anchor={anchor_name} >
- + +