wip: allow updating field spec
This commit is contained in:
parent
d4de42365d
commit
395a547b94
2 changed files with 10 additions and 65 deletions
|
|
@ -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<bool>,
|
||||
|
|
@ -43,9 +43,7 @@ pub(super) struct FormBody {
|
|||
timestamp_format: Option<String>,
|
||||
}
|
||||
|
||||
/// 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<Presentation, AppError> {
|
||||
// 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!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,13 @@
|
|||
style:position-anchor={anchor_name}
|
||||
>
|
||||
<form method="post" action="update-field">
|
||||
<FieldDetails bind:name_value bind:label_value name_input_disabled />
|
||||
<FieldDetails
|
||||
bind:name_value
|
||||
bind:label_value
|
||||
name_input_disabled
|
||||
presentation={field.field.presentation}
|
||||
/>
|
||||
<input type="hidden" name="field_id" value={field.field.id} />
|
||||
<button class="button--primary" type="submit">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue