Skip to content

Commit 41bc31c

Browse files
authored
Notion Update Page Dynamic Fields (#15002)
* dynamic properties * pnpm-lock.yaml * update properties description * improve parsing properties
1 parent 2d96a02 commit 41bc31c

File tree

7 files changed

+57
-18
lines changed

7 files changed

+57
-18
lines changed

components/notion/actions/append-block/append-block.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "notion-append-block",
77
name: "Append Block to Parent",
88
description: "Creates and appends blocks to the specified parent. [See the documentation](https://developers.notion.com/reference/patch-block-children)",
9-
version: "0.2.16",
9+
version: "0.2.17",
1010
type: "action",
1111
props: {
1212
notion,

components/notion/actions/common/base-page-builder.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ export default {
7979
*/
8080
_filterProps(properties = {}) {
8181
return Object.keys(properties)
82-
.filter((property) => this[property] != null)
82+
.filter((property) => this[property] != null
83+
|| (this.properties && this.properties[property]))
8384
.map((property) => ({
8485
type: properties[property]?.type ?? property,
8586
label: property,
86-
value: this[property],
87+
value: this[property] || this.properties[property],
8788
}));
8889
},
8990
/**

components/notion/actions/create-page-from-database/create-page-from-database.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default {
66
...base,
77
key: "notion-create-page-from-database",
88
name: "Create Page from Database",
9-
description: "Creates a page from a database. [See the docs](https://developers.notion.com/reference/post-page)",
10-
version: "0.1.14",
9+
description: "Creates a page from a database. [See the documentation](https://developers.notion.com/reference/post-page)",
10+
version: "0.1.15",
1111
type: "action",
1212
props: {
1313
notion,

components/notion/actions/create-page/create-page.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "notion-create-page",
88
name: "Create Page",
99
description: "Creates a page from a parent page. The only valid property is *title*. [See the documentation](https://developers.notion.com/reference/post-page)",
10-
version: "0.2.12",
10+
version: "0.2.13",
1111
type: "action",
1212
props: {
1313
notion,

components/notion/actions/duplicate-page/duplicate-page.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default {
66
...base,
77
key: "notion-duplicate-page",
88
name: "Duplicate Page",
9-
description: "Creates a new page copied from an existing page block. [See the docs](https://developers.notion.com/reference/post-page)",
10-
version: "0.0.8",
9+
description: "Creates a new page copied from an existing page block. [See the documentation](https://developers.notion.com/reference/post-page)",
10+
version: "0.0.9",
1111
type: "action",
1212
props: {
1313
notion,

components/notion/actions/update-page/update-page.mjs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default {
66
...base,
77
key: "notion-update-page",
88
name: "Update Page",
9-
description: "Updates page property values for the specified page. Properties that are not set will remain unchanged. To append page content, use the *append block* action. [See the docs](https://developers.notion.com/reference/patch-page)",
10-
version: "1.1.2",
9+
description: "Updates page property values for the specified page. Properties that are not set will remain unchanged. To append page content, use the *append block* action. [See the documentation](https://developers.notion.com/reference/patch-page)",
10+
version: "1.1.3",
1111
type: "action",
1212
props: {
1313
notion,
@@ -54,13 +54,23 @@ export default {
5454
},
5555
},
5656
async additionalProps() {
57-
const { properties } = await this.notion.retrieveDatabase(this.parent);
58-
const selectedProperties = pick(properties, this.propertyTypes);
57+
try {
58+
const { properties } = await this.notion.retrieveDatabase(this.parent);
59+
const selectedProperties = pick(properties, this.propertyTypes);
5960

60-
return this.buildAdditionalProps({
61-
properties: selectedProperties,
62-
meta: this.metaTypes,
63-
});
61+
return this.buildAdditionalProps({
62+
properties: selectedProperties,
63+
meta: this.metaTypes,
64+
});
65+
} catch {
66+
return {
67+
properties: {
68+
type: "object",
69+
label: "Properties",
70+
description: "The property values to update for the page. The keys are the names or IDs of the property and the values are property values. If a page property ID is not included, then it is not changed. Example: `{ \"Name\": \"Tuscan Kale\", \"Description\": \"A dark green leafy vegetable\" }`",
71+
},
72+
};
73+
}
6474
},
6575
methods: {
6676
...base.methods,
@@ -77,16 +87,44 @@ export default {
7787
properties,
7888
};
7989
},
90+
parseProperties(properties) {
91+
if (!properties) {
92+
return undefined;
93+
}
94+
if (typeof properties === "string") {
95+
try {
96+
return JSON.parse(properties);
97+
} catch {
98+
throw new Error("Could not parse properties as JSON object");
99+
}
100+
}
101+
const parsedProperties = {};
102+
for (const [
103+
key,
104+
value,
105+
] of Object.entries(properties)) {
106+
try {
107+
parsedProperties[key] = typeof value === "string"
108+
? JSON.parse(value)
109+
: value;
110+
} catch {
111+
parsedProperties[key] = value;
112+
}
113+
}
114+
return parsedProperties;
115+
},
80116
},
81117
async run({ $ }) {
82118
try {
119+
this.properties = this.parseProperties(this.properties);
120+
83121
const currentPage = await this.notion.retrievePage(this.pageId);
84122
const page = this.buildPage(currentPage);
85123
const response = await this.notion.updatePage(this.pageId, page);
86124
$.export("$summary", "Updated page successfully");
87125
return response;
88126
} catch (error) {
89-
throw new Error(error.body);
127+
throw new Error(error.body || error);
90128
}
91129
},
92130
};

components/notion/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notion",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"description": "Pipedream Notion Components",
55
"main": "notion.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)