Skip to content

Commit f309683

Browse files
Merge branch 'main' into notion-version-2022-02-22
2 parents 331819d + 07d09c4 commit f309683

File tree

10 files changed

+175
-6
lines changed

10 files changed

+175
-6
lines changed

Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public class Info
1515

1616
[JsonProperty("language")]
1717
public string Language { get; set; }
18+
19+
[JsonProperty("caption")]
20+
public IEnumerable<RichTextBaseInput> Caption { get; set; }
1821
}
1922
}
2023
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class TableRowUpdateBlock : UpdateBlock, IUpdateBlock
7+
{
8+
[JsonProperty("table_row")]
9+
public Info TableRow { get; set; }
10+
11+
public class Info
12+
{
13+
[JsonProperty("cells")]
14+
public IEnumerable<IEnumerable<RichTextTextInput>> Cells { get; set; }
15+
}
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class TableUpdateBlock : UpdateBlock, IUpdateBlock
6+
{
7+
[JsonProperty("table")]
8+
public Info Table { get; set; }
9+
10+
public class Info
11+
{
12+
[JsonProperty("has_column_header")]
13+
public bool HasColumnHeader { get; set; }
14+
15+
[JsonProperty("has_row_header")]
16+
public bool HasRowHeader { get; set; }
17+
}
18+
}
19+
}

Src/Notion.Client/Models/Blocks/BlockType.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public enum BlockType
9191
[EnumMember(Value = "synced_block")]
9292
SyncedBlock,
9393

94+
[EnumMember(Value = "table")]
95+
Table,
96+
97+
[EnumMember(Value = "table_row")]
98+
TableRow,
99+
94100
[EnumMember(Value = "unsupported")]
95101
Unsupported
96102
}

Src/Notion.Client/Models/Blocks/CodeBlock.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class Info
1717

1818
[JsonProperty("language")]
1919
public string Language { get; set; }
20+
21+
[JsonProperty("caption")]
22+
public IEnumerable<RichTextBase> Caption { get; set; }
2023
}
2124
}
2225
}

Src/Notion.Client/Models/Blocks/IBlock.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace Notion.Client
2828
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
2929
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
3030
[JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)]
31+
[JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)]
32+
[JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)]
3133
[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)]
3234
[JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)]
3335
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock
6+
{
7+
public override BlockType Type => BlockType.Table;
8+
9+
[JsonProperty("table")]
10+
public TableInfo Table { get; set; }
11+
12+
public class TableInfo
13+
{
14+
[JsonProperty("table_width")]
15+
public int TableWidth { get; set; }
16+
17+
[JsonProperty("has_column_header")]
18+
public bool HasColumnHeader { get; set; }
19+
20+
[JsonProperty("has_row_header")]
21+
public bool HasRowHeader { get; set; }
22+
23+
[JsonProperty("children")]
24+
public TableRowBlock Children { get; set; }
25+
}
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock
7+
{
8+
public override BlockType Type => BlockType.TableRow;
9+
10+
[JsonProperty("table_row")]
11+
public Info TableRow { get; set; }
12+
13+
public class Info
14+
{
15+
[JsonProperty("cells")]
16+
public IEnumerable<IEnumerable<RichTextText>> Cells { get; set; }
17+
}
18+
}
19+
}

Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class DatePropertyValue : PropertyValue
1313
/// <summary>
1414
/// Date
1515
/// </summary>
16-
[JsonProperty("date")]
16+
[JsonProperty("date", NullValueHandling = NullValueHandling.Include)]
1717
public Date Date { get; set; }
1818
}
1919

@@ -33,5 +33,11 @@ public class Date
3333
/// </summary>
3434
[JsonProperty("end")]
3535
public DateTime? End { get; set; }
36+
37+
/// <summary>
38+
/// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are based on the time zones from Moment.js.
39+
/// </summary>
40+
[JsonProperty("time_zone")]
41+
public string TimeZone { get; set; }
3642
}
3743
}

Test/Notion.IntegrationTests/IPageClientTests.cs

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Notion.IntegrationTests
1111
public class IPageClientTests
1212
{
1313
private readonly INotionClient _client;
14+
private readonly string _databaseId;
1415

1516
public IPageClientTests()
1617
{
@@ -20,14 +21,15 @@ public IPageClientTests()
2021
};
2122

2223
_client = NotionClientFactory.Create(options);
24+
_databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb";
2325
}
2426

2527
[Fact]
2628
public async Task CreateAsync_CreatesANewPage()
2729
{
2830
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
2931
{
30-
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
32+
DatabaseId = _databaseId
3133
})
3234
.AddProperty("Name", new TitlePropertyValue
3335
{
@@ -48,7 +50,7 @@ public async Task CreateAsync_CreatesANewPage()
4850

4951
page.Should().NotBeNull();
5052
page.Parent.Should().BeOfType<DatabaseParent>().Which
51-
.DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb");
53+
.DatabaseId.Should().Be(_databaseId);
5254

5355
page.Properties.Should().ContainKey("Name");
5456
page.Properties["Name"].Should().BeOfType<TitlePropertyValue>().Which
@@ -65,7 +67,7 @@ public async Task Bug_unable_to_create_page_with_select_property()
6567
{
6668
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
6769
{
68-
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
70+
DatabaseId = _databaseId
6971
})
7072
.AddProperty("Name", new TitlePropertyValue
7173
{
@@ -93,7 +95,7 @@ public async Task Bug_unable_to_create_page_with_select_property()
9395

9496
page.Should().NotBeNull();
9597
page.Parent.Should().BeOfType<DatabaseParent>().Which
96-
.DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb");
98+
.DatabaseId.Should().Be(_databaseId);
9799

98100
page.Properties.Should().ContainKey("Name");
99101
page.Properties["Name"].Should().BeOfType<TitlePropertyValue>().Which
@@ -110,7 +112,7 @@ public async Task Test_RetrievePagePropertyItemAsync()
110112
{
111113
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
112114
{
113-
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
115+
DatabaseId = _databaseId
114116
})
115117
.AddProperty("Name", new TitlePropertyValue
116118
{
@@ -155,5 +157,70 @@ public async Task Test_RetrievePagePropertyItemAsync()
155157
Archived = true
156158
});
157159
}
160+
161+
[Fact]
162+
public async Task Test_UpdatePageProperty_with_date_as_null()
163+
{
164+
// setup - add property to db and create a page with the property having a date
165+
166+
string datePropertyName = "Test Date Property";
167+
var updateDatabaseParameters = new DatabasesUpdateParameters();
168+
updateDatabaseParameters.Properties = new Dictionary<string, IUpdatePropertySchema>
169+
{
170+
{ "Name", new TitleUpdatePropertySchema { Title = new Dictionary<string, object>() } },
171+
{ "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary<string, object>() } }
172+
};
173+
174+
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
175+
{
176+
DatabaseId = _databaseId
177+
})
178+
.AddProperty("Name", new TitlePropertyValue
179+
{
180+
Title = new List<RichTextBase>
181+
{
182+
new RichTextText
183+
{
184+
Text = new Text
185+
{
186+
Content = "Test Page Title"
187+
}
188+
}
189+
}
190+
})
191+
.AddProperty(datePropertyName, new DatePropertyValue
192+
{
193+
Date = new Date()
194+
{
195+
Start = Convert.ToDateTime("2020-12-08T12:00:00Z"),
196+
End = Convert.ToDateTime("2025-12-08T12:00:00Z")
197+
}
198+
})
199+
.Build();
200+
201+
var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters);
202+
203+
var page = await _client.Pages.CreateAsync(pagesCreateParameters);
204+
205+
var setDate = page.Properties[datePropertyName] as DatePropertyValue;
206+
207+
setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z"));
208+
209+
// verify
210+
IDictionary<string, PropertyValue> testProps = new Dictionary<string, PropertyValue>();
211+
testProps.Add(datePropertyName, new DatePropertyValue() { Date = null });
212+
213+
var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
214+
{
215+
Properties = testProps
216+
});
217+
218+
var verifyDate = updatedPage.Properties[datePropertyName] as DatePropertyValue;
219+
220+
verifyDate?.Date.Should().BeNull();
221+
222+
//cleanup
223+
await _client.Blocks.DeleteAsync(page.Id);
224+
}
158225
}
159226
}

0 commit comments

Comments
 (0)