Some validations

This commit is contained in:
eraden 2021-04-29 23:36:05 +02:00
parent a1d7e14984
commit 10bda7bb9c
4 changed files with 18 additions and 10 deletions

View File

@ -7,6 +7,7 @@ use crate::components::styled_date_time_input::*;
use crate::components::styled_input::*;
use crate::components::styled_select::*;
use crate::model::IssueModal;
use crate::shared::validate::*;
use crate::{FieldId, Msg};
#[derive(Copy, Clone, EnumPrimitive, EnumIter)]
@ -49,7 +50,9 @@ impl Type {
}
}
#[derive(Clone, Debug, PartialOrd, PartialEq)]
pub type TitleValidator = Touched<Between<4, 60>>;
#[derive(Debug)]
pub struct Model {
pub priority: IssuePriority,
pub description: Option<String>,
@ -65,6 +68,8 @@ pub struct Model {
// modal fields
pub title_state: StyledInputState,
pub title_validator: TitleValidator,
pub type_state: StyledSelectState,
pub reporter_state: StyledSelectState,
pub assignees_state: StyledSelectState,
@ -90,7 +95,10 @@ impl Default for Model {
reporter_id: Default::default(),
issue_status_id: Default::default(),
epic_id: Default::default(),
title_state: StyledInputState::new(FieldId::AddIssueModal(IssueFieldId::Title), ""),
title_validator: TitleValidator::default(),
type_state: StyledSelectState::new(FieldId::AddIssueModal(IssueFieldId::Type), vec![]),
reporter_state: StyledSelectState::new(
FieldId::AddIssueModal(IssueFieldId::Reporter),

View File

@ -3,6 +3,7 @@ use seed::prelude::*;
use crate::components::styled_select::StyledSelectChanged;
use crate::model::IssueModal;
use crate::shared::validate::Validator;
use crate::ws::send_ws_msg;
use crate::{FieldId, Msg, OperationKind, ResourceKind};
@ -18,6 +19,9 @@ pub fn update(msg: &Msg, model: &mut crate::model::Model, orders: &mut impl Orde
modal.update_states(msg, orders);
match msg {
Msg::StrInputChanged(FieldId::AddIssueModal(IssueFieldId::Title), s) => {
modal.title_validator.validate(s);
}
Msg::AddEpic => {
send_ws_msg(
WsMsg::EpicCreate(modal.title_state.value.clone(), None, None),

View File

@ -17,6 +17,7 @@ use crate::modals::epic_field;
use crate::modals::issues_create::{Model as AddIssueModal, Type};
use crate::model::Model;
use crate::{FieldId, Msg};
use crate::shared::validate::Validator;
pub fn view(model: &Model, modal: &AddIssueModal) -> Node<Msg> {
let issue_type = modal
@ -190,7 +191,8 @@ fn type_select_option<'l>(t: Type) -> StyledSelectOption<'l> {
fn short_summary_field(modal: &AddIssueModal) -> Node<Msg> {
let short_summary = StyledInput {
value: modal.title_state.value.as_str(),
valid: modal.title_state.is_valid(),
valid: modal.title_validator.is_valid(),
err_msg: modal.title_validator.message(),
id: Some(FieldId::AddIssueModal(IssueFieldId::Title)),
..Default::default()
}

View File

@ -35,14 +35,8 @@ macro_rules! match_modal {
#[macro_export]
macro_rules! match_modal_mut {
($model: ident, $ty: ident) => {
match $model.modals.iter_mut().find_map(|modal| {
if let crate::model::ModalType::$ty(modal) = modal {
Some(modal)
} else {
None
}
}) {
($model: ident, $field: ident) => {
match $model.modals.$field {
Some(modal) => modal,
_ => return,
}