Skip to content

Commit

Permalink
Merge pull request #274 from notion-dotnet/226-add-table-block-support
Browse files Browse the repository at this point in the history
Add support for Table and TableRow block ✨
  • Loading branch information
KoditkarVedant authored Jul 16, 2022
2 parents 5de4799 + f739b99 commit 07d09c4
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class TableRowUpdateBlock : UpdateBlock, IUpdateBlock
{
[JsonProperty("table_row")]
public Info TableRow { get; set; }

public class Info
{
[JsonProperty("cells")]
public IEnumerable<IEnumerable<RichTextTextInput>> Cells { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class TableUpdateBlock : UpdateBlock, IUpdateBlock
{
[JsonProperty("table")]
public Info Table { get; set; }

public class Info
{
[JsonProperty("has_column_header")]
public bool HasColumnHeader { get; set; }

[JsonProperty("has_row_header")]
public bool HasRowHeader { get; set; }
}
}
}
6 changes: 6 additions & 0 deletions Src/Notion.Client/Models/Blocks/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public enum BlockType
[EnumMember(Value = "synced_block")]
SyncedBlock,

[EnumMember(Value = "table")]
Table,

[EnumMember(Value = "table_row")]
TableRow,

[EnumMember(Value = "unsupported")]
Unsupported
}
Expand Down
2 changes: 2 additions & 0 deletions Src/Notion.Client/Models/Blocks/IBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace Notion.Client
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
[JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)]
[JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)]
[JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)]
[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)]
[JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)]
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
Expand Down
27 changes: 27 additions & 0 deletions Src/Notion.Client/Models/Blocks/TableBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;

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

[JsonProperty("table")]
public TableInfo Table { get; set; }

public class TableInfo
{
[JsonProperty("table_width")]
public int TableWidth { get; set; }

[JsonProperty("has_column_header")]
public bool HasColumnHeader { get; set; }

[JsonProperty("has_row_header")]
public bool HasRowHeader { get; set; }

[JsonProperty("children")]
public TableRowBlock Children { get; set; }
}
}
}
19 changes: 19 additions & 0 deletions Src/Notion.Client/Models/Blocks/TableRowBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using Newtonsoft.Json;

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

[JsonProperty("table_row")]
public Info TableRow { get; set; }

public class Info
{
[JsonProperty("cells")]
public IEnumerable<IEnumerable<RichTextText>> Cells { get; set; }
}
}
}

0 comments on commit 07d09c4

Please sign in to comment.