Skip to content

Commit

Permalink
Reordered WorkStatus enum in mod.rs, made publication_date and withdr…
Browse files Browse the repository at this point in the history
…awn_date required in View for relevant work_status, fixed Thoth error message for work_active_publication_date_check
  • Loading branch information
brendan-oconnell committed May 31, 2024
1 parent 3fae5a8 commit e7f6f98
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
6 changes: 3 additions & 3 deletions thoth-api/src/model/work/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 9 additions & 7 deletions thoth-app/src/component/new_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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! {
<>
<nav class="level">
Expand Down Expand Up @@ -528,14 +530,14 @@ impl Component for NewWorkComponent {
label = "Publication Date"
value={ self.work.publication_date.clone() }
oninput={ ctx.link().callback(|e: InputEvent| Msg::ChangeDate(e.to_value())) }
required={ is_active }
required={ is_active_withdrawn_or_superseded }
/>
<FormDateInput
label = "Withdrawn Date"
value={ self.work.withdrawn_date.clone() }
oninput={ ctx.link().callback(|e: InputEvent| Msg::ChangeWithdrawnDate(e.to_value())) }
required = true
deactivated={ is_not_withdrawn }
deactivated={ is_not_withdrawn_or_superseded }
/>
<FormTextInput
label = "Place of Publication"
Expand Down
18 changes: 11 additions & 7 deletions thoth-app/src/component/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ impl Component for WorkComponent {
self.work.last_page = None;
self.work.page_interval = None;
}
if self.work.work_status != WorkStatus::WithdrawnFromSale
if self.work.work_status != WorkStatus::WithdrawnFromSale &&
self.work.work_status != WorkStatus::Superseded
{
self.work.withdrawn_date = None;
}
Expand Down Expand Up @@ -577,10 +578,13 @@ impl Component for WorkComponent {
// 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! {
<>
<nav class="level">
Expand Down Expand Up @@ -655,14 +659,14 @@ impl Component for WorkComponent {
label = "Publication Date"
value={ self.work.publication_date.clone() }
oninput={ ctx.link().callback(|e: InputEvent| Msg::ChangeDate(e.to_value())) }
required = { is_active }
required = { is_active_withdrawn_or_superseded }
/>
<FormDateInput
label = "Withdrawn Date"
value={ self.work.withdrawn_date.clone() }
oninput={ ctx.link().callback(|e: InputEvent| Msg::ChangeWithdrawnDate(e.to_value())) }
required = true
deactivated={ is_not_withdrawn }
deactivated={ is_not_withdrawn_or_superseded }
/>
<FormTextInput
label = "Place of Publication"
Expand Down
2 changes: 1 addition & 1 deletion thoth-errors/src/database_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static DATABASE_CONSTRAINT_ERRORS: Map<&'static str, &'static str> = phf_map! {
"subject_subject_code_check" => "Subject codes must not be an empty string.",
"subject_subject_ordinal_check" => "A subject ordinal number must be greater than 0.",
"work_active_withdrawn_date_check" => "Withdrawn Date can only be set for a withdrawn from sale or superseded Work.",
"work_active_publication_date_check" => "Active works must have a publication date.",
"work_active_publication_date_check" => "Active, superseded and withdrawn from sale works must have a publication date.",
"work_audio_count_check" => "An audio count must be greater than 0.",
"work_bibliography_note_check" => "Bibliography note must not be an empty string.",
"work_chapter_no_edition" => "Chapters must not have an edition number.",
Expand Down

0 comments on commit e7f6f98

Please sign in to comment.