Skip to content

Commit

Permalink
Merge pull request #216 from notion-dotnet/209-add-support-for-link-t…
Browse files Browse the repository at this point in the history
…o-page-block-type

Add support for link_to_page block type ✨
  • Loading branch information
KoditkarVedant authored Dec 31, 2021
2 parents 492fb02 + 20ed709 commit cb6b5c7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class LinkToPageUpdateBlock : UpdateBlock, IUpdateBlock
{
[JsonProperty("link_to_page")]
public IPageParentInput LinkToPage { get; set; }
}
}
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/Blocks/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public enum BlockType
[EnumMember(Value = "template")]
Template,

[EnumMember(Value = "link_to_page")]
LinkToPage,

[EnumMember(Value = "unsupported")]
Unsupported
}
Expand Down
1 change: 1 addition & 0 deletions Src/Notion.Client/Models/Blocks/IBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Notion.Client
[JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)]
[JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)]
[JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)]
[JsonSubtypes.KnownSubType(typeof(LinkToPageBlock), BlockType.LinkToPage)]
[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)]
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
Expand Down
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class LinkToPageBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.LinkToPage;

[JsonProperty("link_to_page")]
public IPageParent LinkToPage { get; set; }
}
}
29 changes: 29 additions & 0 deletions Test/Notion.IntegrationTests/IBlocksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,35 @@ private static IEnumerable<object[]> BlockData()
Assert.Null(templateBlock.Template.Children);
Assert.Equal("Test Template 2", templateBlock.Template.Text.OfType<RichTextText>().First().Text.Content);
})
},
new object[]
{
new LinkToPageBlock()
{
LinkToPage = new PageParent
{
Type = ParentType.PageId,
PageId = "533578e3edf14c0a91a9da6b09bac3ee"
}
},
new LinkToPageUpdateBlock()
{
LinkToPage = new ParentPageInput
{
PageId = "3c357473a28149a488c010d2b245a589"
}
},
new Action<IBlock>(block =>
{
Assert.NotNull(block);
var linkToPageBlock = Assert.IsType<LinkToPageBlock>(block);

var pageParent = Assert.IsType<PageParent>(linkToPageBlock.LinkToPage);

// TODO: Currently the api doesn't allow to update the link_to_page block type
// This will change to updated ID once api start to support
Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId));
})
}
};
}
Expand Down

0 comments on commit cb6b5c7

Please sign in to comment.