//! The Askama entry point for a described "delete this version" button.
//!
//! Shape 3 step 4 (`108557ec`), the step the plan calls the clean tail: the one
//! part of `static/item-upload.js` that retires with no host remnant. It waited
//! on `27d5e5b8` (a described act inside an Askama page) and on `35756077` (the
//! unlayered `button` rule taking the tone off every described act). Both are
//! settled, so it converts.
//!
//! # What the description says that the markup did not
//!
//! Everything, in this case. There was no markup: the button carried a class
//! and a `data-version-id`, and the whole act lived in a click handler in
//! `item-upload.js` — a `confirm()` string, a `fetch` with CSRF headers, and a
//! `btn.closest('tr').remove()` on success. None of that is legible to anything
//! but a browser. As an [`Act`] it is one sentence: what it is called, where it
//! goes, what it replaces, that it is destructive, and what to ask first.
//!
//! # Why the row id is a parameter, and why the row grew one
//!
//! `DELETE /api/items/{item}/versions/{version}` is a plain API route the
//! description layer does not serve; it answers `200` with an empty body, so it
//! cannot name what it changed and the control has to. See
//! [`Action::replaces`].
//!
//! The blog pair ([`super::blog_delete_act`]) converted because its templates
//! already gave each row a real id. This one's `
` did not, and the handler
//! it replaces reached the row through `closest('tr')`. So the template grew
//! `id="version-row-{id}"` in the same change. That is worth telling apart from
//! the two rows that are still hand-written: `partials/link_row.html` and
//! `partials/tag.html` target `closest .` on rows whose identity is a
//! CSS class and nothing else, and inventing an id for them would be describing
//! a fact the page does not have. A version row has an id in the database and
//! the template was simply not writing it down.
//!
//! # The download button beside it is not here, and that is measured
//!
//! Wiki [[mnw-shape-conversion-plans]] Shape 3 step 4 says
//! `download-version-btn` is `Action::get`. It is not.
//! `GET /api/versions/{id}/download` (`routes::storage::downloads`) answers
//! **JSON carrying a presigned URL**, and the handler then navigates to it, so
//! a described `Action::get` would send the reader to a JSON body. Making it
//! sayable is a route change — answer a redirect, or serve the route through
//! the description layer so it can answer `Outcome::Goto` with a
//! `Destination::External` — rather than a control change, so the handler
//! stays.
use makeover_layout::Tone;
use quasi_router::screen::Act;
use quasi_router::{Action, Node};
/// The delete button for one version's row.
///
/// Both ids are needed and they are not the same fact: the route is addressed
/// by item and version together, and the row is named by the version alone.
#[must_use]
pub fn act(item_id: &str, version_id: &str) -> Node {
Node::Act(
Act::new(
"Delete",
Action::delete(format!("/api/items/{item_id}/versions/{version_id}"))
.replacing(format!("version-row-{version_id}")),
)
.tone(Tone::Danger)
.confirm("Delete this version?"),
)
}
/// The same act as a fragment, for the Askama call site.
#[must_use]
pub fn html(item_id: &str, version_id: &str) -> String {
use quasi_axum::Serves as _;
quasi_webview::Webview::new().fragment(&act(item_id, version_id))
}
#[cfg(test)]
mod tests {
/// What the click handler said in four places, said once: where it goes,
/// what it replaces, and what to ask first.
#[test]
fn a_delete_names_its_route_its_row_and_its_prompt() {
let html = super::html("7", "42");
assert!(
html.contains(r#"hx-delete="/api/items/7/versions/42""#),
"{html}"
);
assert!(html.contains(r##"hx-target="#version-row-42""##), "{html}");
assert!(
html.contains(r#"hx-confirm="Delete this version?""#),
"{html}"
);
}
/// The tone. The template said nothing at all here -- the button was
/// `btn-secondary`, so the page did not mark the destructive act even to
/// the stylesheet.
#[test]
fn a_delete_says_it_is_dangerous_in_a_word_every_renderer_reads() {
let html = super::html("7", "42");
assert!(html.contains(r#"data-tone="danger""#), "{html}");
}
/// The negative half, as `export_act` asserts it: the dispatcher is gone
/// from this control, not merely bypassed.
#[test]
fn nothing_here_goes_through_the_dispatcher() {
let html = super::html("7", "42");
assert!(!html.contains("data-action"), "{html}");
assert!(!html.contains("delete-version-btn"), "{html}");
}
}