Some validations
This commit is contained in:
parent
a1d7e14984
commit
10bda7bb9c
@ -7,6 +7,7 @@ use crate::components::styled_date_time_input::*;
|
|||||||
use crate::components::styled_input::*;
|
use crate::components::styled_input::*;
|
||||||
use crate::components::styled_select::*;
|
use crate::components::styled_select::*;
|
||||||
use crate::model::IssueModal;
|
use crate::model::IssueModal;
|
||||||
|
use crate::shared::validate::*;
|
||||||
use crate::{FieldId, Msg};
|
use crate::{FieldId, Msg};
|
||||||
|
|
||||||
#[derive(Copy, Clone, EnumPrimitive, EnumIter)]
|
#[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 struct Model {
|
||||||
pub priority: IssuePriority,
|
pub priority: IssuePriority,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
@ -65,6 +68,8 @@ pub struct Model {
|
|||||||
|
|
||||||
// modal fields
|
// modal fields
|
||||||
pub title_state: StyledInputState,
|
pub title_state: StyledInputState,
|
||||||
|
pub title_validator: TitleValidator,
|
||||||
|
|
||||||
pub type_state: StyledSelectState,
|
pub type_state: StyledSelectState,
|
||||||
pub reporter_state: StyledSelectState,
|
pub reporter_state: StyledSelectState,
|
||||||
pub assignees_state: StyledSelectState,
|
pub assignees_state: StyledSelectState,
|
||||||
@ -90,7 +95,10 @@ impl Default for Model {
|
|||||||
reporter_id: Default::default(),
|
reporter_id: Default::default(),
|
||||||
issue_status_id: Default::default(),
|
issue_status_id: Default::default(),
|
||||||
epic_id: Default::default(),
|
epic_id: Default::default(),
|
||||||
|
|
||||||
title_state: StyledInputState::new(FieldId::AddIssueModal(IssueFieldId::Title), ""),
|
title_state: StyledInputState::new(FieldId::AddIssueModal(IssueFieldId::Title), ""),
|
||||||
|
title_validator: TitleValidator::default(),
|
||||||
|
|
||||||
type_state: StyledSelectState::new(FieldId::AddIssueModal(IssueFieldId::Type), vec![]),
|
type_state: StyledSelectState::new(FieldId::AddIssueModal(IssueFieldId::Type), vec![]),
|
||||||
reporter_state: StyledSelectState::new(
|
reporter_state: StyledSelectState::new(
|
||||||
FieldId::AddIssueModal(IssueFieldId::Reporter),
|
FieldId::AddIssueModal(IssueFieldId::Reporter),
|
||||||
|
@ -3,6 +3,7 @@ use seed::prelude::*;
|
|||||||
|
|
||||||
use crate::components::styled_select::StyledSelectChanged;
|
use crate::components::styled_select::StyledSelectChanged;
|
||||||
use crate::model::IssueModal;
|
use crate::model::IssueModal;
|
||||||
|
use crate::shared::validate::Validator;
|
||||||
use crate::ws::send_ws_msg;
|
use crate::ws::send_ws_msg;
|
||||||
use crate::{FieldId, Msg, OperationKind, ResourceKind};
|
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);
|
modal.update_states(msg, orders);
|
||||||
|
|
||||||
match msg {
|
match msg {
|
||||||
|
Msg::StrInputChanged(FieldId::AddIssueModal(IssueFieldId::Title), s) => {
|
||||||
|
modal.title_validator.validate(s);
|
||||||
|
}
|
||||||
Msg::AddEpic => {
|
Msg::AddEpic => {
|
||||||
send_ws_msg(
|
send_ws_msg(
|
||||||
WsMsg::EpicCreate(modal.title_state.value.clone(), None, None),
|
WsMsg::EpicCreate(modal.title_state.value.clone(), None, None),
|
||||||
|
@ -17,6 +17,7 @@ use crate::modals::epic_field;
|
|||||||
use crate::modals::issues_create::{Model as AddIssueModal, Type};
|
use crate::modals::issues_create::{Model as AddIssueModal, Type};
|
||||||
use crate::model::Model;
|
use crate::model::Model;
|
||||||
use crate::{FieldId, Msg};
|
use crate::{FieldId, Msg};
|
||||||
|
use crate::shared::validate::Validator;
|
||||||
|
|
||||||
pub fn view(model: &Model, modal: &AddIssueModal) -> Node<Msg> {
|
pub fn view(model: &Model, modal: &AddIssueModal) -> Node<Msg> {
|
||||||
let issue_type = modal
|
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> {
|
fn short_summary_field(modal: &AddIssueModal) -> Node<Msg> {
|
||||||
let short_summary = StyledInput {
|
let short_summary = StyledInput {
|
||||||
value: modal.title_state.value.as_str(),
|
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)),
|
id: Some(FieldId::AddIssueModal(IssueFieldId::Title)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,8 @@ macro_rules! match_modal {
|
|||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! match_modal_mut {
|
macro_rules! match_modal_mut {
|
||||||
($model: ident, $ty: ident) => {
|
($model: ident, $field: ident) => {
|
||||||
match $model.modals.iter_mut().find_map(|modal| {
|
match $model.modals.$field {
|
||||||
if let crate::model::ModalType::$ty(modal) = modal {
|
|
||||||
Some(modal)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
Some(modal) => modal,
|
Some(modal) => modal,
|
||||||
_ => return,
|
_ => return,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user