Skip to content

Commit

Permalink
Adding specific types for ViewInfo element values plus some missing B…
Browse files Browse the repository at this point in the history
…lockAction types
  • Loading branch information
Simon Oxtoby committed Mar 29, 2020
1 parent 13ebce3 commit 4565348
Show file tree
Hide file tree
Showing 33 changed files with 288 additions and 124 deletions.
70 changes: 69 additions & 1 deletion SlackNet.EventsExample/AppHome.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using SlackNet.Blocks;
using SlackNet.Events;
Expand All @@ -10,6 +12,7 @@ namespace SlackNet.EventsExample
public class AppHome : IEventHandler<AppHomeOpened>, IBlockActionHandler<ButtonAction>, IViewSubmissionHandler
{
private const string OpenModal = "open_modal";
private const string InlineCheckboxes = "checkboxes";
private const string InputBlockId = "input_block";
private const string InputActionId = "text_input";
public static readonly string ModalCallbackId = "home_modal";
Expand Down Expand Up @@ -58,19 +61,84 @@ public async Task Handle(ButtonAction action, BlockActionRequest request)
ActionId = InputActionId,
Placeholder = "Enter some text"
}
},
new InputBlock
{
Label = "Single-select",
BlockId = "single_select_block",
Element = new StaticSelectMenu
{
ActionId = "single_select",
Options = ExampleOptions()
}
},
new InputBlock
{
Label = "Multi-select",
BlockId = "multi_select_block",
Element = new StaticMultiSelectMenu
{
ActionId = "multi_select",
Options = ExampleOptions()
}
},
new InputBlock
{
Label = "Date",
BlockId = "date_block",
Element = new DatePicker { ActionId = "date_picker" }
},
new InputBlock
{
Label = "Radio options",
BlockId = "radio_block",
Element = new RadioButtonGroup
{
ActionId = "radio",
Options = ExampleOptions()
}
},
new InputBlock
{
Label = "Checkbox options",
BlockId = "checkbox_block",
Element = new CheckboxGroup
{
ActionId = "checkbox",
Options = ExampleOptions()
}
},
new InputBlock
{
Label = "Single user select",
BlockId = "single_user_block",
Element = new UserSelectMenu
{
ActionId = "single_user"
}
}
},
Submit = "Submit",
NotifyOnClose = true
}).ConfigureAwait(false);
}

private IList<Blocks.Option> ExampleOptions()
{
return new List<Blocks.Option>
{
new Blocks.Option { Text = "One", Value = "1" },
new Blocks.Option { Text = "Two", Value = "2" },
new Blocks.Option { Text = "Three", Value = "3" }
};
}

public async Task<ViewSubmissionResponse> Handle(ViewSubmission viewSubmission)
{
await _slack.Chat.PostMessage(new Message
{
Channel = await UserIm(viewSubmission.User).ConfigureAwait(false),
Text = $"You entered: {viewSubmission.View.State.Values[InputBlockId][InputActionId].Value}"
Text = $"You entered: {viewSubmission.View.State.GetValue<PlainTextInputValue>(InputActionId).Value}"
}).ConfigureAwait(false);

return ViewSubmissionResponse.Null;
Expand Down
6 changes: 6 additions & 0 deletions SlackNet.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FBuiltInTypes/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FElsewhere/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FSimpleTypes/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">NEXT_LINE_SHIFTED_2</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseVar</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVar</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseVar</s:String>
<s:String x:Key="/Default/Environment/Hierarchy/PsiConfigurationSettingsKey/CustomLocation/@EntryValue">C:\Users\Simon\AppData\Local\JetBrains\Transient\ReSharperPlatformVs15\v08_a19e333b\SolutionCaches</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=authed/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Endtime/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Filetype/@EntryIndexedValue">True</s:Boolean>
Expand Down
7 changes: 7 additions & 0 deletions SlackNet/Blocks/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ public enum ButtonStyle
/// </summary>
Danger
}

[SlackType("button")]
public class ButtonAction : BlockAction
{
public TextObject Text { get; set; }
public string Value { get; set; }
}
}
9 changes: 0 additions & 9 deletions SlackNet/Blocks/ButtonAction.cs

This file was deleted.

10 changes: 0 additions & 10 deletions SlackNet/Blocks/ChannelMultiSelectAction.cs

This file was deleted.

12 changes: 12 additions & 0 deletions SlackNet/Blocks/ChannelMultiSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ public ChannelMultiSelectMenu() : base("multi_channels_select") { }
/// </summary>
public int? MaxSelectedItems { get; set; }
}

[SlackType("multi_channels_select")]
public class ChannelMultiSelectAction : BlockAction
{
public IList<string> SelectedChannels { get; set; } = new List<string>();
}

[SlackType("multi_channels_select")]
public class ChannelMultiSelectValue : ElementValue
{
public IList<string> SelectedChannels { get; set; } = new List<string>();
}
}
8 changes: 0 additions & 8 deletions SlackNet/Blocks/ChannelSelectAction.cs

This file was deleted.

12 changes: 12 additions & 0 deletions SlackNet/Blocks/ChannelSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ public ChannelSelectMenu() : base("channels_select") { }
/// </summary>
public string InitialChannel { get; set; }
}

[SlackType("channels_select")]
public class ChannelSelectAction : BlockAction
{
public string SelectedChannel { get; set; }
}

[SlackType("channels_select")]
public class ChannelSelectValue : ElementValue
{
public string SelectedChannel { get; set; }
}
}
12 changes: 12 additions & 0 deletions SlackNet/Blocks/CheckboxGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ public CheckboxGroup() : base("checkboxes") { }
[IgnoreIfEmpty]
public IList<Option> InitialOptions { get; set; } = new List<Option>();
}

[SlackType("checkboxes")]
public class CheckboxGroupAction : BlockAction
{
public IList<Option> SelectedOptions { get; set; } = new List<Option>();
}

[SlackType("checkboxes")]
public class CheckboxGroupValue : ElementValue
{
public IList<Option> SelectedOptions { get; set; } = new List<Option>();
}
}
10 changes: 0 additions & 10 deletions SlackNet/Blocks/ConversationMultiSelectAction.cs

This file was deleted.

12 changes: 12 additions & 0 deletions SlackNet/Blocks/ConversationMultiSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ public ConversationMultiSelectMenu() : base("multi_conversations_select") { }
/// </summary>
public int? MaxSelectedItems { get; set; }
}

[SlackType("multi_conversations_select")]
public class ConversationMultiSelectAction : BlockAction
{
public IList<string> SelectedConversations { get; set; } = new List<string>();
}

[SlackType("multi_conversations_select")]
public class ConversationMultiSelectValue : ElementValue
{
public IList<string> SelectedConversations { get; set; } = new List<string>();
}
}
8 changes: 0 additions & 8 deletions SlackNet/Blocks/ConversationSelectAction.cs

This file was deleted.

12 changes: 12 additions & 0 deletions SlackNet/Blocks/ConversationSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ public ConversationSelectMenu() : base("conversations_select") { }
/// </summary>
public string InitialConversation { get; set; }
}

[SlackType("conversations_select")]
public class ConversationSelectAction : BlockAction
{
public string SelectedConversation { get; set; }
}

[SlackType("conversations_select")]
public class ConversationSelectValue : ElementValue
{
public string SelectedConversation { get; set; }
}
}
12 changes: 12 additions & 0 deletions SlackNet/Blocks/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ public DatePicker() : base("datepicker") { }
/// </summary>
public DateTime? InitialDate { get; set; }
}

[SlackType("datepicker")]
public class DatePickerAction : BlockAction
{
public DateTime SelectedDate { get; set; }
}

[SlackType("datepicker")]
public class DatePickerValue : ElementValue
{
public DateTime SelectedDate { get; set; }
}
}
10 changes: 0 additions & 10 deletions SlackNet/Blocks/DatePickerAction.cs

This file was deleted.

10 changes: 0 additions & 10 deletions SlackNet/Blocks/ExternalMultiSelectAction.cs

This file was deleted.

12 changes: 12 additions & 0 deletions SlackNet/Blocks/ExternalMultiSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ public ExternalMultiSelectMenu() : base("multi_external_select") { }
/// </summary>
public int? MaxSelectedItems { get; set; }
}

[SlackType("multi_external_select")]
public class ExternalMultiSelectAction
{
public IList<Option> SelectedOptions { get; set; } = new List<Option>();
}

[SlackType("multi_external_select")]
public class ExternalMultiSelectValue
{
public IList<Option> SelectedOptions { get; set; } = new List<Option>();
}
}
9 changes: 0 additions & 9 deletions SlackNet/Blocks/ExternalSelectAction.cs

This file was deleted.

12 changes: 12 additions & 0 deletions SlackNet/Blocks/ExternalSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ public ExternalSelectMenu() : base("external_select") { }
/// </summary>
public Option InitialOption { get; set; }
}

[SlackType("external_select")]
public class ExternalSelectAction : BlockAction
{
public Option SelectedOption { get; set; }
}

[SlackType("external_select")]
public class ExternalSelectValue : ElementValue
{
public Option SelectedOption { get; set; }
}
}
8 changes: 0 additions & 8 deletions SlackNet/Blocks/OverflowAction.cs

This file was deleted.

12 changes: 12 additions & 0 deletions SlackNet/Blocks/OverflowMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ public OverflowMenu() : base("overflow") { }
/// </summary>
public IList<OverflowOption> Options { get; set; } = new List<OverflowOption>();
}

[SlackType("overflow")]
public class OverflowAction : BlockAction
{
public Option SelectedOption { get; set; }
}

[SlackType("overflow")]
public class OverflowValue : ElementValue
{
public Option SelectedOption { get; set; }
}
}
Loading

0 comments on commit 4565348

Please sign in to comment.