Skip to content

Commit

Permalink
Adding multi-select block elements
Browse files Browse the repository at this point in the history
  • Loading branch information
soxtoby committed Jan 2, 2020
1 parent 206ed8a commit c922655
Show file tree
Hide file tree
Showing 23 changed files with 250 additions and 151 deletions.
24 changes: 24 additions & 0 deletions SlackNet/Blocks/ActionElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace SlackNet.Blocks
{
public interface IActionElement
{
string Type { get; }
string ActionId { get; set; }
}

public abstract class ActionElement : BlockElement, IActionElement
{
protected ActionElement(string type) : base(type) { }

/// <summary>
/// An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action.
/// Should be unique among all other <see cref="ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }

/// <summary>
/// Defines an optional confirmation dialog that appears after the element is activated.
/// </summary>
public ConfirmationDialog Confirm { get; set; }
}
}
13 changes: 1 addition & 12 deletions SlackNet/Blocks/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// An interactive element that inserts a button. The button can be a trigger for anything from opening a simple link to starting a complex workflow.
/// </summary>
[SlackType("button")]
public class Button : BlockElement, IActionElement
public class Button : ActionElement
{
public Button() : base("button") { }

Expand All @@ -30,17 +30,6 @@ public Button() : base("button") { }
/// </summary>
[IgnoreIfDefault]
public ButtonStyle Style { get; set; }

/// <summary>
/// Defines an optional confirmation dialog after the button is clicked.
/// </summary>
public ConfirmationDialog Confirm { get; set; }

/// <summary>
/// An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action.
/// Should be unique among all other <see cref="ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }
}

public enum ButtonStyle
Expand Down
10 changes: 10 additions & 0 deletions SlackNet/Blocks/ChannelMultiSelectAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace SlackNet.Blocks
{
[SlackType("multi_channels_select")]
public class ChannelMultiSelectAction
{
public IList<string> SelectedChannels { get; set; } = new List<string>();
}
}
23 changes: 23 additions & 0 deletions SlackNet/Blocks/ChannelMultiSelectMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;

namespace SlackNet.Blocks
{
/// <summary>
/// This multi-select menu will populate its options with a list of public channels visible to the current user in the active workspace.
/// </summary>
[SlackType("multi_channels_select")]
public class ChannelMultiSelectMenu : SelectMenuBase
{
public ChannelMultiSelectMenu() : base("multi_channels_select") { }

/// <summary>
/// A list of one or more IDs of any valid public channel to be pre-selected when the menu loads.
/// </summary>
public IList<string> InitialChannels { get; set; } = new List<string>();

/// <summary>
/// Specifies the maximum number of items that can be selected in the menu. Minimum number is 1.
/// </summary>
public int? MaxSelectedItems { get; set; }
}
}
18 changes: 1 addition & 17 deletions SlackNet/Blocks/ChannelSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,13 @@
/// This select menu will populate its options with a list of public channels visible to the current user in the active workspace.
/// </summary>
[SlackType("channels_select")]
public class ChannelSelectMenu : BlockElement, IActionElement
public class ChannelSelectMenu : SelectMenuBase
{
public ChannelSelectMenu() : base("channels_select") { }

/// <summary>
/// A plain text object that defines the placeholder text shown on the menu.
/// </summary>
public PlainText Placeholder { get; set; }

/// <summary>
/// The ID of any valid public channel to be pre-selected when the menu loads.
/// </summary>
public string InitialChannel { get; set; }

/// <summary>
/// Defines an optional confirmation dialog that appears after a menu item is selected.
/// </summary>
public ConfirmationDialog Confirm { get; set; }

/// <summary>
/// An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action.
/// Should be unique among all other <see cref="ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }
}
}
10 changes: 10 additions & 0 deletions SlackNet/Blocks/ConversationMultiSelectAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace SlackNet.Blocks
{
[SlackType("multi_conversations_select")]
public class ConversationMultiSelectAction
{
public IList<string> SelectedConversations { get; set; } = new List<string>();
}
}
23 changes: 23 additions & 0 deletions SlackNet/Blocks/ConversationMultiSelectMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;

namespace SlackNet.Blocks
{
/// <summary>
/// This multi-select menu will populate its options with a list of public and private channels, DMs, and MPIMs visible to the current user in the active workspace.
/// </summary>
[SlackType("multi_conversations_select")]
public class ConversationMultiSelectMenu : SelectMenuBase
{
public ConversationMultiSelectMenu() : base("multi_conversations_select") { }

/// <summary>
/// A list of one or more IDs of any valid conversations to be pre-selected when the menu loads.
/// </summary>
public IList<string> InitialConversations { get; set; } = new List<string>();

/// <summary>
/// Specifies the maximum number of items that can be selected in the menu. Minimum number is 1.
/// </summary>
public int? MaxSelectedItems { get; set; }
}
}
18 changes: 1 addition & 17 deletions SlackNet/Blocks/ConversationSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,13 @@
/// This select menu will populate its options with a list of public and private channels, DMs, and MPIMs visible to the current user in the active workspace.
/// </summary>
[SlackType("conversations_select")]
public class ConversationSelectMenu : BlockElement, IActionElement
public class ConversationSelectMenu : SelectMenuBase
{
public ConversationSelectMenu() : base("conversations_select") { }

/// <summary>
/// A plain text object that defines the placeholder text shown on the menu.
/// </summary>
public PlainText Placeholder { get; set; }

/// <summary>
/// The ID of any valid conversation to be pre-selected when the menu loads.
/// </summary>
public string InitialConversation { get; set; }

/// <summary>
/// Defines an optional confirmation dialog that appears after a menu item is selected.
/// </summary>
public ConfirmationDialog Confirm { get; set; }

/// <summary>
/// An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action.
/// Should be unique among all other <see cref="ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }
}
}
13 changes: 1 addition & 12 deletions SlackNet/Blocks/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SlackNet.Blocks
/// Date picker elements can be used inside of section and actions blocks.
/// </summary>
[SlackType("datepicker")]
public class DatePicker : BlockElement, IActionElement
public class DatePicker : ActionElement
{
public DatePicker() : base("datepicker") { }

Expand All @@ -20,16 +20,5 @@ public DatePicker() : base("datepicker") { }
/// The initial date that is selected when the element is loaded.
/// </summary>
public DateTime? InitialDate { get; set; }

/// <summary>
/// Defines an optional confirmation dialog that appears after a menu item is selected.
/// </summary>
public ConfirmationDialog Confirm { get; set; }

/// <summary>
/// An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action.
/// Should be unique among all other <see cref="ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }
}
}
10 changes: 10 additions & 0 deletions SlackNet/Blocks/ExternalMultiSelectAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace SlackNet.Blocks
{
[SlackType("multi_external_select")]
public class ExternalMultiSelectAction
{
public IList<Option> SelectedOptions { get; set; } = new List<Option>();
}
}
26 changes: 26 additions & 0 deletions SlackNet/Blocks/ExternalMultiSelectMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using SlackNet.Interaction;

namespace SlackNet.Blocks
{
/// <summary>
/// This menu will load its options from an external data source, allowing for a dynamic list of options.
/// </summary>
[SlackType("multi_external_select")]
public class ExternalMultiSelectMenu : ExternalSelectMenuBase
{
public ExternalMultiSelectMenu() : base("multi_external_select") { }

/// <summary>
/// A list of <see cref="Option"/>s that exactly match one or more of the options within the <see cref="BlockOptionsResponse.Options"/>
/// or <see cref="BlockOptionsResponse.OptionGroups"/> loaded from the external data source.
/// These options will be selected when the menu initially loads.
/// </summary>
public IList<Option> InitialOptions { get; set; } = new List<Option>();

/// <summary>
/// Specifies the maximum number of items that can be selected in the menu. Minimum number is 1.
/// </summary>
public int? MaxSelectedItems { get; set; }
}
}
24 changes: 1 addition & 23 deletions SlackNet/Blocks/ExternalSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,15 @@ namespace SlackNet.Blocks
/// This select menu will load its options from an external data source, allowing for a dynamic list of options.
/// </summary>
[SlackType("external_select")]
public class ExternalSelectMenu : BlockElement, IActionElement
public class ExternalSelectMenu : ExternalSelectMenuBase
{
public ExternalSelectMenu() : base("external_select") { }

/// <summary>
/// A plain text object that defines the placeholder text shown on the menu.
/// </summary>
public PlainText Placeholder { get; set; }

/// <summary>
/// A single <see cref="Option"/> that exactly matches one of the options within the <see cref="BlockOptionsResponse.Options"/>
/// or <see cref="BlockOptionsResponse.OptionGroups"/> loaded from the external data source.
/// This option will be selected when the menu initially loads.
/// </summary>
public Option InitialOption { get; set; }

/// <summary>
/// When the typeahead field is used, a request will be sent on every character change.
/// If you prefer fewer requests or more fully ideated queries, use this to tell Slack the fewest number of typed characters required before dispatch.
/// </summary>
public int? MinQueryLength { get; set; }

/// <summary>
/// Defines an optional confirmation dialog that appears after a menu item is selected.
/// </summary>
public ConfirmationDialog Confirm { get; set; }

/// <summary>
/// An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action.
/// Should be unique among all other <see cref="ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }
}
}
13 changes: 13 additions & 0 deletions SlackNet/Blocks/ExternalSelectMenuBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SlackNet.Blocks
{
public abstract class ExternalSelectMenuBase : SelectMenuBase
{
protected ExternalSelectMenuBase(string type) : base(type) { }

/// <summary>
/// When the typeahead field is used, a request will be sent on every character change.
/// If you prefer fewer requests or more fully ideated queries, use this to tell Slack the fewest number of typed characters required before dispatch.
/// </summary>
public int? MinQueryLength { get; set; }
}
}
8 changes: 0 additions & 8 deletions SlackNet/Blocks/IActionElement.cs

This file was deleted.

13 changes: 1 addition & 12 deletions SlackNet/Blocks/OverflowMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,13 @@ namespace SlackNet.Blocks
/// You can also specify simple URL links as overflow menu options, instead of actions.
/// </summary>
[SlackType("overflow")]
public class OverflowMenu : BlockElement, IActionElement
public class OverflowMenu : ActionElement
{
public OverflowMenu() : base("overflow") { }

/// <summary>
/// A list of option objects to display in the menu.
/// </summary>
public IList<OverflowOption> Options { get; set; } = new List<OverflowOption>();

/// <summary>
/// Defines an optional confirmation dialog that appears after a menu item is selected.
/// </summary>
public ConfirmationDialog Confirm { get; set; }

/// <summary>
/// An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action.
/// Should be unique among all other <see cref="ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }
}
}
12 changes: 12 additions & 0 deletions SlackNet/Blocks/SelectMenuBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SlackNet.Blocks
{
public abstract class SelectMenuBase : ActionElement
{
protected SelectMenuBase(string type) : base(type) { }

/// <summary>
/// A plain text object that defines the placeholder text shown on the menu.
/// </summary>
public PlainText Placeholder { get; set; }
}
}
10 changes: 10 additions & 0 deletions SlackNet/Blocks/StaticMultiSelectAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace SlackNet.Blocks
{
[SlackType("multi_static_select")]
public class StaticMultiSelectAction : BlockAction
{
public IList<Option> SelectedOptions { get; set; } = new List<Option>();
}
}
Loading

0 comments on commit c922655

Please sign in to comment.