better UX/UI

This commit is contained in:
Priec
2026-08-17 21:35:59 +02:00
parent e13447e3d6
commit 9b2b429dc6
12 changed files with 282 additions and 83 deletions

View File

@@ -375,12 +375,12 @@ pub(crate) async fn set_column_alias(
.await
}
/// POST /admin/tables/presentation/order — SetColumnPresentation, moving one
/// column past its neighbour.
/// POST /admin/tables/presentation/order — SetColumnPresentation, saving the
/// order staged by the browser.
///
/// Every alias in the request is the name the backend just reported, so this
/// write cannot rename a column even when the browser's copy of the table is
/// stale. Only the order it sends comes from the form.
/// write cannot rename a column. The ids from the browser must be an exact
/// permutation of the current columns before their order is accepted.
pub(crate) async fn set_column_order(
State(state): State<AppState>,
headers: HeaderMap,
@@ -399,33 +399,38 @@ pub(crate) async fn set_column_order(
Ok(columns) => columns,
Err(response) => return response,
};
let Some(index) = columns
let current_ids = columns
.iter()
.position(|column| column.column_id == form.column_id)
else {
let message = tr!(Locale::from_headers(&headers), "td-err-unknown-column");
.map(|column| column.column_id)
.collect::<std::collections::HashSet<_>>();
let submitted_ids = form
.column_ids
.iter()
.copied()
.collect::<std::collections::HashSet<_>>();
if form.column_ids.len() != columns.len()
|| submitted_ids.len() != form.column_ids.len()
|| submitted_ids != current_ids
{
let message = tr!(Locale::from_headers(&headers), "td-err-invalid-order");
return refuse(state, headers, inputs, Page::Presentation, message).await;
};
// A column at the end of the table has nowhere further to go, and the
// button that says so is disabled; a request that asks anyway is answered
// with the table as it is.
let swap_with = match form.direction.as_str() {
"up" => index.checked_sub(1),
"down" if index + 1 < columns.len() => Some(index + 1),
_ => None,
};
let Some(swap_with) = swap_with else {
return respond(state, headers, inputs, Page::Presentation, StatusCode::OK).await;
};
}
let mut presentation = columns
let columns_by_id = columns
.iter()
.map(|column| ColumnPresentation {
column_id: column.column_id,
alias: column.name.clone(),
.map(|column| (column.column_id, column))
.collect::<std::collections::HashMap<_, _>>();
let presentation = form
.column_ids
.iter()
.map(|column_id| {
let column = columns_by_id[column_id];
ColumnPresentation {
column_id: *column_id,
alias: column.name.clone(),
}
})
.collect::<Vec<_>>();
presentation.swap(index, swap_with);
.collect();
apply_presentation(
state,