Skip to content

Commit

Permalink
feat: multi select channels (#140)
Browse files Browse the repository at this point in the history
* feat: public channels multi-select

* fix multi-select validation comments

* fix tests
  • Loading branch information
cakekindel authored May 24, 2021
1 parent cce7397 commit ba6307a
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 21 deletions.
9 changes: 5 additions & 4 deletions src/block_elements/select/multi/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ impl<'a> Conversation<'a> {
/// ```
/// use slack_blocks::block_elements::select;
///
/// let select = select::Conversation::from_placeholder_and_action_id(
/// r#"Hey I really would appreciate it if you chose
/// let select = select::multi::Conversation::builder().placeholder(
/// r#"Hey I really would appreciate it if you chose
/// a channel relatively soon, so that we can figure out
/// where we need to send this poll, ok? it's kind of
/// important that you specify where this poll should be
/// sent, in case we haven't made that super clear.
/// If you understand, could you pick a channel, already??"#,
/// "ABC123"
/// );
/// )
/// .action_id("ABC123")
/// .build();
///
/// assert!(matches!(select.validate(), Err(_)))
/// ```
Expand Down
11 changes: 6 additions & 5 deletions src/block_elements/select/multi/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ impl<'a> External<'a> {
/// ```
/// use slack_blocks::block_elements::select;
///
/// let select = select::External::from_placeholder_and_action_id(
/// r#"Hey I really would appreciate it if you chose
/// let placeholder = r#"Hey I really would appreciate it if you chose
/// a channel relatively soon, so that we can figure out
/// where we need to send this poll, ok? it's kind of
/// important that you specify where this poll should be
/// sent, in case we haven't made that super clear.
/// If you understand, could you pick a channel, already??"#,
/// "ABC123"
/// );
/// If you understand, could you pick a channel, already??"#;
///
/// let select = select::multi::External::builder().placeholder(placeholder)
/// .action_id("ABC123")
/// .build();
///
/// assert!(matches!(select.validate(), Err(_)))
/// ```
Expand Down
7 changes: 3 additions & 4 deletions src/block_elements/select/multi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
//! [select menus 🔗]: https://api.slack.com/reference/block-kit/block-elements#select
//! [guide to enabling interactivity 🔗]: https://api.slack.com/interactivity/handling

// mod builder;
pub mod conversation;
pub mod external;
// pub mod public_channel;
pub mod public_channel;
pub mod static_;
pub mod user;

#[doc(inline)]
pub use conversation::Conversation;
#[doc(inline)]
pub use external::External;
// #[doc(inline)]
// pub use public_channel::PublicChannel;
#[doc(inline)]
pub use public_channel::PublicChannel;
#[doc(inline)]
pub use static_::Static;
#[doc(inline)]
Expand Down
75 changes: 75 additions & 0 deletions src/block_elements/select/multi/public_channel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::borrow::Cow;

use serde::{Deserialize, Serialize};
use validator::Validate;

use crate::{compose::Confirm,
elems::select::public_channel::build,
text,
val_helpr::ValidationResult};

/// # Public Channel Select
/// [slack api docs 🔗](https://api.slack.com/reference/block-kit/block-elements#channel_select)
///
/// This select menu will populate its options with a list of
/// public channels visible to the current user in the active workspace.
#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize, Validate)]
pub struct PublicChannel<'a> {
#[validate(custom = "crate::elems::select::validate::placeholder")]
pub(in crate::elems::select) placeholder: text::Text,

#[validate(length(max = 255))]
pub(in crate::elems::select) action_id: Cow<'a, str>,

#[serde(skip_serializing_if = "Option::is_none")]
#[validate]
pub(in crate::elems::select) confirm: Option<Confirm>,

#[serde(skip_serializing_if = "Option::is_none")]
pub(in crate::elems::select) initial_channels: Option<Cow<'a, [String]>>,

#[validate(range(min = 1))]
pub(in crate::elems::select) max_selected_items: Option<u32>,
}

impl<'a> PublicChannel<'a> {
/// Build a new conversation multi-select element
///
/// # Examples
/// ```
/// // TODO(#130)
/// ```
pub fn builder() -> build::MultiPublicChannelBuilderInit<'a> {
build::MultiPublicChannelBuilderInit::new()
}

/// Validate that this Public Channel Select element
/// agrees with Slack's model requirements
///
/// # Errors
/// - If `from_placeholder_and_action_id` was called with
/// `placeholder` longer than 150 chars
/// - If `from_placeholder_and_action_id` was called with
/// `action_id` longer than 255 chars
///
/// # Example
/// ```
/// use slack_blocks::block_elements::select;
///
/// let select = select::multi::PublicChannel::builder().placeholder(
/// r#"Hey I really would appreciate it if you chose
/// a channel relatively soon, so that we can figure out
/// where we need to send this poll, ok? it's kind of
/// important that you specify where this poll should be
/// sent, in case we haven't made that super clear.
/// If you understand, could you pick a channel, already??"#,
/// )
/// .action_id("ABC123")
/// .build();
///
/// assert!(matches!(select.validate(), Err(_)))
/// ```
pub fn validate(&self) -> ValidationResult {
Validate::validate(&self)
}
}
8 changes: 4 additions & 4 deletions src/block_elements/select/multi/static_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ impl<'a> Static<'a> {
/// sent, in case we haven't made that super clear.
/// If you understand, could you pick a channel, already??"#;
///
/// let select = select::Static::builder().placeholder(placeholder)
/// .action_id("abc123")
/// .options(std::iter::empty())
/// .build();
/// let select = select::multi::Static::builder().placeholder(placeholder)
/// .action_id("abc123")
/// .options(std::iter::empty())
/// .build();
///
/// assert!(matches!(select.validate(), Err(_)))
/// ```
Expand Down
9 changes: 5 additions & 4 deletions src/block_elements/select/multi/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ impl<'a> User<'a> {
/// ```
/// use slack_blocks::elems::select;
///
/// let select = select::User::from_placeholder_and_action_id(
/// r#"Hey I really would appreciate it if you chose
/// let select = select::multi::User::builder().placeholder(
/// r#"Hey I really would appreciate it if you chose
/// a channel relatively soon, so that we can figure out
/// where we need to send this poll, ok? it's kind of
/// important that you specify where this poll should be
/// sent, in case we haven't made that super clear.
/// If you understand, could you pick a channel, already??"#,
/// "ABC123"
/// );
/// )
/// .action_id("ABC123")
/// .build();
///
/// assert!(matches!(select.validate(), Err(_)))
/// ```
Expand Down
Loading

0 comments on commit ba6307a

Please sign in to comment.