From 27349f43377a0ec02487d31f012ae5f7fa08e120 Mon Sep 17 00:00:00 2001 From: Ren0v Date: Thu, 8 Feb 2024 09:00:52 +0100 Subject: [PATCH 1/3] Allowing to add an id when creating an empty property. --- src/Pages/Properties/Date.php | 4 ++-- src/Pages/Properties/Email.php | 4 ++-- src/Pages/Properties/Number.php | 4 ++-- src/Pages/Properties/PhoneNumber.php | 4 ++-- src/Pages/Properties/RichTextProperty.php | 4 ++-- src/Pages/Properties/Select.php | 4 ++-- src/Pages/Properties/Url.php | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Pages/Properties/Date.php b/src/Pages/Properties/Date.php index b66cfff2..99ecd933 100644 --- a/src/Pages/Properties/Date.php +++ b/src/Pages/Properties/Date.php @@ -39,9 +39,9 @@ public static function createRange(DateTimeImmutable $start, DateTimeImmutable $ return new self($property, CommonDate::createRange($start, $end)); } - public static function createEmpty(): self + public static function createEmpty(string $id = null): self { - $metadata = PropertyMetadata::create("", PropertyType::Date); + $metadata = PropertyMetadata::create($id ?? "", PropertyType::Date); return new self($metadata, null); } diff --git a/src/Pages/Properties/Email.php b/src/Pages/Properties/Email.php index 1be81c36..fbb6af8c 100644 --- a/src/Pages/Properties/Email.php +++ b/src/Pages/Properties/Email.php @@ -26,9 +26,9 @@ public static function create(string $email): self return new self($property, $email); } - public static function createEmpty(): self + public static function createEmpty(string $id = null): self { - $property = PropertyMetadata::create("", PropertyType::Email); + $property = PropertyMetadata::create($id ?? "", PropertyType::Email); return new self($property, null); } diff --git a/src/Pages/Properties/Number.php b/src/Pages/Properties/Number.php index 21e9d4cc..2ae8fb31 100644 --- a/src/Pages/Properties/Number.php +++ b/src/Pages/Properties/Number.php @@ -26,9 +26,9 @@ public static function create(int|float $number): self return new self($property, $number); } - public static function createEmpty(): self + public static function createEmpty(string $id = null): self { - $property = PropertyMetadata::create("", PropertyType::Number); + $property = PropertyMetadata::create($id ?? "", PropertyType::Number); return new self($property, null); } diff --git a/src/Pages/Properties/PhoneNumber.php b/src/Pages/Properties/PhoneNumber.php index 9065f51a..2bc10294 100644 --- a/src/Pages/Properties/PhoneNumber.php +++ b/src/Pages/Properties/PhoneNumber.php @@ -26,9 +26,9 @@ public static function create(string $phone): self return new self($property, $phone); } - public static function createEmpty(): self + public static function createEmpty(string $id = null): self { - $property = PropertyMetadata::create("", PropertyType::PhoneNumber); + $property = PropertyMetadata::create($id ?? "", PropertyType::PhoneNumber); return new self($property, null); } diff --git a/src/Pages/Properties/RichTextProperty.php b/src/Pages/Properties/RichTextProperty.php index b102f62c..212ca9b6 100644 --- a/src/Pages/Properties/RichTextProperty.php +++ b/src/Pages/Properties/RichTextProperty.php @@ -39,9 +39,9 @@ public static function fromString(string $text): self return new self($metadata, $texts); } - public static function createEmpty(): self + public static function createEmpty(string $id = null): self { - $metadata = PropertyMetadata::create("", PropertyType::RichText); + $metadata = PropertyMetadata::create($id ?? "", PropertyType::RichText); return new self($metadata, []); } diff --git a/src/Pages/Properties/Select.php b/src/Pages/Properties/Select.php index 4a95e4b8..82ca9ac5 100644 --- a/src/Pages/Properties/Select.php +++ b/src/Pages/Properties/Select.php @@ -44,9 +44,9 @@ public static function fromOption(SelectOption $option): self return new self($metadata, $option); } - public static function createEmpty(): self + public static function createEmpty(string $id = null): self { - $metadata = PropertyMetadata::create("", PropertyType::Select); + $metadata = PropertyMetadata::create($id ?? "", PropertyType::Select); return new self($metadata, null); } diff --git a/src/Pages/Properties/Url.php b/src/Pages/Properties/Url.php index f0926407..c2c21e29 100644 --- a/src/Pages/Properties/Url.php +++ b/src/Pages/Properties/Url.php @@ -26,9 +26,9 @@ public static function create(string $url): self return new self($metadata, $url); } - public static function createEmpty(): self + public static function createEmpty(string $id = null): self { - $metadata = PropertyMetadata::create("", PropertyType::Url); + $metadata = PropertyMetadata::create($id ?? "", PropertyType::Url); return new self($metadata, null); } From 673fdc266fead742ca814d73e819a0b4ee40b94b Mon Sep 17 00:00:00 2001 From: Ren0v Date: Thu, 8 Feb 2024 09:10:55 +0100 Subject: [PATCH 2/3] Adding missing createEmpty method to all editable properties. --- src/Pages/Properties/Checkbox.php | 7 +++++++ src/Pages/Properties/Files.php | 7 +++++++ src/Pages/Properties/MultiSelect.php | 7 +++++++ src/Pages/Properties/People.php | 7 +++++++ src/Pages/Properties/Relation.php | 7 +++++++ src/Pages/Properties/Status.php | 9 ++++++++- src/Pages/Properties/Title.php | 7 +++++++ 7 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Pages/Properties/Checkbox.php b/src/Pages/Properties/Checkbox.php index aa16df1f..1ef979fc 100644 --- a/src/Pages/Properties/Checkbox.php +++ b/src/Pages/Properties/Checkbox.php @@ -33,6 +33,13 @@ public static function createUnchecked(): self return new self($property, false); } + public static function createEmpty(string $id = null): self + { + $property = PropertyMetadata::create($id ?? "", PropertyType::Checkbox); + + return new self($property, false); + } + public static function fromArray(array $array): self { /** @psalm-var CheckboxJson $array */ diff --git a/src/Pages/Properties/Files.php b/src/Pages/Properties/Files.php index 407fe430..3ec95d7f 100644 --- a/src/Pages/Properties/Files.php +++ b/src/Pages/Properties/Files.php @@ -39,6 +39,13 @@ public static function create(File ...$files): self return new self($property, $files); } + public static function createEmpty(string $id = null): self + { + $property = PropertyMetadata::create($id ?? "", PropertyType::Files); + + return new self($property, []); + } + public static function fromArray(array $array): self { /** @psalm-var FilesJson $array */ diff --git a/src/Pages/Properties/MultiSelect.php b/src/Pages/Properties/MultiSelect.php index 9606a445..1f1a8154 100644 --- a/src/Pages/Properties/MultiSelect.php +++ b/src/Pages/Properties/MultiSelect.php @@ -24,6 +24,13 @@ private function __construct( ) { } + public static function createEmpty(string $id = null): self + { + $property = PropertyMetadata::create($id ?? "", PropertyType::MultiSelect); + + return new self($property, []); + } + public static function fromIds(string ...$ids): self { $metadata = PropertyMetadata::create("", PropertyType::MultiSelect); diff --git a/src/Pages/Properties/People.php b/src/Pages/Properties/People.php index eb4fb635..ea17d1a5 100644 --- a/src/Pages/Properties/People.php +++ b/src/Pages/Properties/People.php @@ -31,6 +31,13 @@ public static function create(User ...$users): self return new self($property, $users); } + public static function createEmpty(string $id = null): self + { + $property = PropertyMetadata::create($id ?? "", PropertyType::People); + + return new self($property, []); + } + public static function fromArray(array $array): self { /** @psalm-var PeopleJson $array */ diff --git a/src/Pages/Properties/Relation.php b/src/Pages/Properties/Relation.php index 0d4e41e7..69af0e90 100644 --- a/src/Pages/Properties/Relation.php +++ b/src/Pages/Properties/Relation.php @@ -27,6 +27,13 @@ public static function create(string ...$pageIds): self return new self($property, $pageIds); } + public static function createEmpty(string $id = null): self + { + $property = PropertyMetadata::create($id ?? "", PropertyType::Relation); + + return new self($property, []); + } + public static function fromArray(array $array): self { /** @psalm-var RelationJson $array */ diff --git a/src/Pages/Properties/Status.php b/src/Pages/Properties/Status.php index cff115b2..993f1182 100644 --- a/src/Pages/Properties/Status.php +++ b/src/Pages/Properties/Status.php @@ -18,10 +18,17 @@ class Status implements PropertyInterface { private function __construct( private readonly PropertyMetadata $metadata, - public readonly StatusOption $option, + public readonly StatusOption|null $option, ) { } + public static function createEmpty(string $id = null): self + { + $property = PropertyMetadata::create($id ?? "", PropertyType::Status); + + return new self($property, null); + } + public static function fromId(string $id): self { $metadata = PropertyMetadata::create("", PropertyType::Status); diff --git a/src/Pages/Properties/Title.php b/src/Pages/Properties/Title.php index 32c7c840..84993686 100644 --- a/src/Pages/Properties/Title.php +++ b/src/Pages/Properties/Title.php @@ -26,6 +26,13 @@ private function __construct( ) { } + public static function createEmpty(): self + { + $property = PropertyMetadata::create("title", PropertyType::Title); + + return new self($property, []); + } + /** @psalm-mutation-free */ public static function fromText(RichText ...$title): self { From df2cc796668c8fff1449ac03fc82971084c04a55 Mon Sep 17 00:00:00 2001 From: ren0v <48944413+ren0v@users.noreply.github.com> Date: Sun, 25 Feb 2024 15:32:58 +0100 Subject: [PATCH 3/3] StatusOption cannot be null Remove null type for StatusOption in Pages\Properties\Status. --- src/Pages/Properties/Status.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pages/Properties/Status.php b/src/Pages/Properties/Status.php index 993f1182..e4a73b60 100644 --- a/src/Pages/Properties/Status.php +++ b/src/Pages/Properties/Status.php @@ -18,7 +18,7 @@ class Status implements PropertyInterface { private function __construct( private readonly PropertyMetadata $metadata, - public readonly StatusOption|null $option, + public readonly StatusOption $option, ) { }