From e7f6f98c638094beba2cd68b1ae7e329714e7830 Mon Sep 17 00:00:00 2001 From: Brendan O'Connell Date: Fri, 31 May 2024 17:10:57 +0200 Subject: [PATCH] Reordered WorkStatus enum in mod.rs, made publication_date and withdrawn_date required in View for relevant work_status, fixed Thoth error message for work_active_publication_date_check --- thoth-api/src/model/work/mod.rs | 6 +++--- thoth-app/src/component/new_work.rs | 16 +++++++++------- thoth-app/src/component/work.rs | 18 +++++++++++------- thoth-errors/src/database_errors.rs | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/thoth-api/src/model/work/mod.rs b/thoth-api/src/model/work/mod.rs index c349fc4da..63ef3d4d3 100644 --- a/thoth-api/src/model/work/mod.rs +++ b/thoth-api/src/model/work/mod.rs @@ -54,15 +54,15 @@ pub enum WorkType { #[serde(rename_all = "SCREAMING_SNAKE_CASE")] #[strum(serialize_all = "title_case")] pub enum WorkStatus { - Cancelled, #[default] Forthcoming, - #[cfg_attr(feature = "backend", db_rename = "postponed-indefinitely")] - PostponedIndefinitely, Active, #[cfg_attr(feature = "backend", db_rename = "withdrawn-from-sale")] WithdrawnFromSale, Superseded, + #[cfg_attr(feature = "backend", db_rename = "postponed-indefinitely")] + PostponedIndefinitely, + Cancelled, } #[cfg_attr( diff --git a/thoth-app/src/component/new_work.rs b/thoth-app/src/component/new_work.rs index 61e68fa4a..95fa674a5 100644 --- a/thoth-app/src/component/new_work.rs +++ b/thoth-app/src/component/new_work.rs @@ -290,7 +290,7 @@ impl Component for NewWorkComponent { self.work.page_interval = None; } if self.work.work_status != WorkStatus::WithdrawnFromSale && - self.work.work_status != WorkStatus::WithdrawnFromSale + self.work.work_status != WorkStatus::Superseded { self.work.withdrawn_date = None; } @@ -458,10 +458,12 @@ impl Component for NewWorkComponent { // Grey out chapter-specific or "book"-specific fields // based on currently selected work type. let is_chapter = self.work.work_type == WorkType::BookChapter; - let is_not_withdrawn = self.work.work_status - != WorkStatus::WithdrawnFromSale; - let is_active = self.work.work_status - == WorkStatus::Active; + let is_not_withdrawn_or_superseded = self.work.work_status + != WorkStatus::WithdrawnFromSale && self.work.work_status != WorkStatus::Superseded; + let is_active_withdrawn_or_superseded = self.work.work_status + == WorkStatus::Active || + self.work.work_status == WorkStatus::WithdrawnFromSale || + self.work.work_status == WorkStatus::Superseded; html! { <>