Skip to content

Commit 6c5c0ab

Browse files
Notion usability improvements (#15813)
* pnpm * App prop description updates * pnpm * "Append Block" significant improvements * Search and Create Page improvements * Description and summary improvements * Description updates and alert props * Source updates * Version bumps * Removing unused dependencies * pnpm * Update components/notion/actions/retrieve-page/retrieve-page.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Improvements * Label adjustment --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 5d08bf7 commit 6c5c0ab

File tree

25 files changed

+222
-205
lines changed

25 files changed

+222
-205
lines changed

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

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ export default {
55
...base,
66
key: "notion-append-block",
77
name: "Append Block to Parent",
8-
description: "Creates and appends blocks to the specified parent. [See the documentation](https://developers.notion.com/reference/patch-block-children)",
9-
version: "0.2.17",
8+
description:
9+
"Append new and/or existing blocks to the specified parent. [See the documentation](https://developers.notion.com/reference/patch-block-children)",
10+
version: "0.3.0",
1011
type: "action",
1112
props: {
1213
notion,
@@ -16,37 +17,65 @@ export default {
1617
"pageId",
1718
],
1819
label: "Parent Block ID",
19-
description: "The identifier for the parent block",
20+
description: "Select a parent block/page or provide its ID",
2021
},
21-
blockObjects: {
22+
blockTypes: {
2223
type: "string[]",
23-
label: "Block Objects",
24-
description: "This prop accepts an array of block objects to be appended. Using a custom expression in this prop is recommended.",
25-
optional: true,
24+
label: "Block Type(s)",
25+
description: "Select which type(s) of block you'd like to append",
26+
reloadProps: true,
27+
options: [
28+
{
29+
label: "Append existing blocks",
30+
value: "blockIds",
31+
},
32+
{
33+
label: "Provide Markdown content to create new blocks with",
34+
value: "markdownContents",
35+
},
36+
{
37+
label: "Provide Image URLs to create new image blocks",
38+
value: "imageUrls",
39+
},
40+
],
2641
},
2742
blockIds: {
2843
propDefinition: [
2944
notion,
3045
"pageId",
3146
],
3247
type: "string[]",
33-
label: "Block IDs",
34-
description: "Contents of selected blocks will be appended",
35-
optional: true,
48+
label: "Existing Block IDs",
49+
description: "Select one or more block(s) or page(s) to append (selecting a page appends its children). You can also provide block or page IDs.",
50+
hidden: true,
3651
},
37-
markupContents: {
52+
markdownContents: {
3853
type: "string[]",
39-
label: "Markup Contents",
40-
description: "Content of new blocks to append. You must use Markdown syntax [See docs](https://www.notion.so/help/writing-and-editing-basics#markdown-&-shortcuts)",
41-
optional: true,
54+
label: "Markdown Contents",
55+
description:
56+
"Each entry is the content of a new block to append, using Markdown syntax. [See the documentation](https://www.notion.com/help/writing-and-editing-basics#markdown-and-shortcuts) for more information",
57+
hidden: true,
4258
},
4359
imageUrls: {
4460
type: "string[]",
4561
label: "Image URLs",
46-
description: "List of URLs to append as image blocks",
47-
optional: true,
62+
description: "One or more Image URLs to append new image blocks with. [See the documentation](https://www.notion.com/help/images-files-and-media#media-block-types) for more information",
63+
hidden: true,
4864
},
4965
},
66+
additionalProps(currentProps) {
67+
const { blockTypes } = this;
68+
69+
for (let prop of [
70+
"blockIds",
71+
"markdownContents",
72+
"imageUrls",
73+
]) {
74+
currentProps[prop].hidden = !blockTypes.includes(prop);
75+
}
76+
77+
return {};
78+
},
5079
methods: {
5180
...base.methods,
5281
chunkArray(array, chunkSize = 100) {
@@ -58,19 +87,11 @@ export default {
5887
},
5988
},
6089
async run({ $ }) {
90+
const { blockTypes } = this;
6191
const children = [];
62-
// add blocks from blockObjects
63-
if (this.blockObjects?.length > 0) {
64-
for (const obj of this.blockObjects) {
65-
const child = (typeof obj === "string")
66-
? JSON.parse(obj)
67-
: obj;
68-
children.push(child);
69-
}
70-
}
7192

7293
// add blocks from blockIds
73-
if (this.blockIds?.length > 0) {
94+
if (blockTypes.includes("blockIds") && this.blockIds?.length > 0) {
7495
for (const id of this.blockIds) {
7596
const block = await this.notion.retrieveBlock(id);
7697
block.children = await this.notion.retrieveBlockChildren(block);
@@ -80,15 +101,15 @@ export default {
80101
}
81102

82103
// add blocks from markup
83-
if (this.markupContents?.length > 0) {
84-
for (const content of this.markupContents) {
104+
if (blockTypes.includes("markdownContents") && this.markdownContents?.length > 0) {
105+
for (const content of this.markdownContents) {
85106
const block = this.createBlocks(content);
86107
children.push(...block);
87108
}
88109
}
89110

90111
// add image blocks
91-
if (this.imageUrls?.length) {
112+
if (blockTypes.includes("imageUrls") && this.imageUrls?.length) {
92113
for (const url of this.imageUrls) {
93114
children.push({
94115
type: "image",
@@ -111,7 +132,10 @@ export default {
111132
const chunks = this.chunkArray(children);
112133

113134
for (const chunk of chunks) {
114-
const { results: payload } = await this.notion.appendBlock(this.pageId, chunk);
135+
const { results: payload } = await this.notion.appendBlock(
136+
this.pageId,
137+
chunk,
138+
);
115139
results.push(payload);
116140
}
117141

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default {
3939
*/
4040
_buildPropDescription(type, example) {
4141
const typeName = type.replace(/_/g, "-");
42-
const description = `The type of this property is \`${type}\`. [See ${type} type docs here](https://developers.notion.com/reference/property-object#${typeName}).`;
42+
const description = `The type of this property is \`${type}\`. [See ${type} type documentation here](https://developers.notion.com/reference/property-object#${typeName}).`;
4343
const descriptionExample = example
4444
? `e.g. ${example}.`
4545
: "";

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@ import { ConfigurationError } from "@pipedream/platform";
44
export default {
55
key: "notion-create-comment",
66
name: "Create Comment",
7-
description: "Creates a comment in a page or existing discussion thread. [See the documentation](https://developers.notion.com/reference/create-a-comment)",
8-
version: "0.0.1",
7+
description: "Create a comment in a page or existing discussion thread. [See the documentation](https://developers.notion.com/reference/create-a-comment)",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
notion,
12+
infoLabel: {
13+
type: "alert",
14+
alertType: "info",
15+
content: "Provide either a Page ID or a Discussion ID to create the comment under.",
16+
},
1217
pageId: {
1318
propDefinition: [
1419
notion,
1520
"pageId",
1621
],
17-
description: "Unique identifier of a page. Either this or a Discussion ID is required (not both)",
1822
optional: true,
1923
},
2024
discussionId: {
2125
type: "string",
2226
label: "Discussion ID",
23-
description: "A UUID identifier for a discussion thread. Either this or a Page ID is required (not both)",
27+
description: "The ID of a discussion thread. [See the documentation](https://developers.notion.com/docs/working-with-comments#retrieving-a-discussion-id) for more information",
2428
optional: true,
2529
},
2630
comment: {
@@ -31,7 +35,7 @@ export default {
3135
},
3236
async run({ $ }) {
3337
if ((this.pageId && this.discussionId) || (!this.pageId && !this.discussionId)) {
34-
throw new ConfigurationError("Either a Page ID or a Discussion ID is required (not both)");
38+
throw new ConfigurationError("Provide either a page ID or a discussion thread ID to create the comment under");
3539
}
3640

3741
const response = await this.notion._getNotionClient().comments.create({
@@ -47,7 +51,7 @@ export default {
4751
},
4852
],
4953
});
50-
$.export("$summary", `Successfully added comment with ID: ${response.id}`);
54+
$.export("$summary", `Successfully created comment (ID: ${response.id})`);
5155
return response;
5256
},
5357
};

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

Lines changed: 8 additions & 8 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 documentation](https://developers.notion.com/reference/post-page)",
10-
version: "0.1.15",
9+
description: "Create a page from a database. [See the documentation](https://developers.notion.com/reference/post-page)",
10+
version: "0.1.16",
1111
type: "action",
1212
props: {
1313
notion,
@@ -17,7 +17,7 @@ export default {
1717
"databaseId",
1818
],
1919
label: "Parent Database ID",
20-
description: "The identifier for a Notion parent page",
20+
description: "Select a parent database or provide a database ID",
2121
reloadProps: true,
2222
},
2323
metaTypes: {
@@ -40,13 +40,13 @@ export default {
4040
alert: {
4141
type: "alert",
4242
alertType: "info",
43-
content: "This action will create an empty page by default. To add content, use the `pageContent` prop below.",
43+
content: "This action will create an empty page by default. To add content, use the `Page Content` prop below.",
4444
},
4545
pageContent: {
46-
type: "string",
47-
label: "Page Content",
48-
description: "Content of the page. You can use Markdown syntax [See docs](https://www.notion.so/help/writing-and-editing-basics#markdown-&-shortcuts)",
49-
optional: true,
46+
propDefinition: [
47+
notion,
48+
"pageContent",
49+
],
5050
},
5151
},
5252
async additionalProps() {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default {
66
...base,
77
key: "notion-create-page",
88
name: "Create Page",
9-
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.13",
9+
description: "Create a page from a parent page. [See the documentation](https://developers.notion.com/reference/post-page)",
10+
version: "0.2.14",
1111
type: "action",
1212
props: {
1313
notion,
@@ -17,7 +17,7 @@ export default {
1717
"pageId",
1818
],
1919
label: "Parent Page ID",
20-
description: "The identifier for a Notion parent page",
20+
description: "Select a parent page or provide a page ID",
2121
reloadProps: true,
2222
},
2323
title: {
@@ -33,10 +33,10 @@ export default {
3333
],
3434
},
3535
pageContent: {
36-
type: "string",
37-
label: "Page Content",
38-
description: "Content of the page. You can use Markdown syntax [See docs](https://www.notion.so/help/writing-and-editing-basics#markdown-&-shortcuts)",
39-
optional: true,
36+
propDefinition: [
37+
notion,
38+
"pageContent",
39+
],
4040
},
4141
},
4242
async additionalProps() {

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

Lines changed: 5 additions & 5 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 documentation](https://developers.notion.com/reference/post-page)",
10-
version: "0.0.9",
9+
description: "Create a new page copied from an existing page block. [See the documentation](https://developers.notion.com/reference/post-page)",
10+
version: "0.0.10",
1111
type: "action",
1212
props: {
1313
notion,
@@ -16,7 +16,7 @@ export default {
1616
notion,
1717
"pageId",
1818
],
19-
description: "The page to copy",
19+
description: "Select a page to copy or provide a page ID",
2020
},
2121
title: {
2222
propDefinition: [
@@ -31,7 +31,7 @@ export default {
3131
"pageId",
3232
],
3333
label: "Parent Page ID",
34-
description: "The parent page of the new page being created",
34+
description: "Select a parent page for the new page being created, or provide the ID of a parent page",
3535
},
3636
},
3737
async run({ $ }) {
@@ -65,7 +65,7 @@ export default {
6565

6666
const results = await this.notion.createPage(page);
6767
const pageName = this.notion.extractPageTitle(results);
68-
$.export("$summary", `Successfully created the new page, "[${pageName}](${results.url})"`);
68+
$.export("$summary", `Successfully created page "[${pageName}](${results.url})"`);
6969
return results;
7070
},
7171
};

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

Lines changed: 0 additions & 22 deletions
This file was deleted.

components/notion/actions/query-database/query-database.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import utils from "../../common/utils.mjs";
44
export default {
55
key: "notion-query-database",
66
name: "Query Database",
7-
description: "Query a database. [See the docs](https://developers.notion.com/reference/post-database-query)",
8-
version: "0.0.8",
7+
description: "Query a database with a specified filter. [See the documentation](https://developers.notion.com/reference/post-database-query)",
8+
version: "0.0.9",
99
type: "action",
1010
props: {
1111
notion,
@@ -16,8 +16,8 @@ export default {
1616
],
1717
},
1818
filter: {
19-
label: "Filter",
20-
description: "The filter to query. [See how filters work here](https://developers.notion.com/reference/post-database-query-filter). E.g. { \"property\": \"Email\", \"rich_text\": { \"contains\": \"gmail.com\" } }",
19+
label: "Filter (query)",
20+
description: "The filter to apply, as a JSON-stringified object. [See the documentation for available filters](https://developers.notion.com/reference/post-database-query-filter). Example: `{ \"property\": \"Name\", \"title\": { \"contains\": \"title to search for\" } }`",
2121
type: "string",
2222
},
2323
},
@@ -28,7 +28,11 @@ export default {
2828
filter: utils.parseStringToJSON(filter),
2929
});
3030

31-
$.export("$summary", "Retrieved database query result");
31+
const length = response?.results?.length;
32+
33+
$.export("$summary", `Retrieved ${length} result${length === 1
34+
? ""
35+
: "s"}`);
3236

3337
return response;
3438
},

0 commit comments

Comments
 (0)