feat(Notion Node): Add icon support for page and database page creation (#5468)

This commit is contained in:
Jonathan Bennetts 2023-02-16 09:00:54 +00:00 committed by GitHub
parent a9f08fc5ba
commit 71cba06b7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 120 additions and 1 deletions

View file

@ -534,6 +534,47 @@ export const databasePageFields: INodeProperties[] = [
],
},
...blocks('databasePage', 'create'),
{
displayName: 'Options',
name: 'options',
type: 'collection',
displayOptions: {
show: {
resource: ['databasePage'],
operation: ['create'],
},
},
default: {},
placeholder: 'Add Option',
options: [
{
displayName: 'Icon Type',
name: 'iconType',
type: 'options',
options: [
{
name: 'Emoji',
value: 'emoji',
description: 'Use an Emoji for the icon',
},
{
name: 'File',
value: 'file',
description: 'Use a file for the icon',
},
],
default: 'emoji',
description: 'The icon type for the database page, Either a URL or an Emoji',
},
{
displayName: 'Icon',
name: 'icon',
type: 'string',
default: '',
description: 'Emoji or File URL to use as the icon',
},
],
},
/* -------------------------------------------------------------------------- */
/* databasePage:update */
/* -------------------------------------------------------------------------- */

View file

@ -237,6 +237,47 @@ export const pageFields: INodeProperties[] = [
description: 'Whether to return a simplified version of the response instead of the raw data',
},
...blocks('page', 'create'),
{
displayName: 'Options',
name: 'options',
type: 'collection',
displayOptions: {
show: {
resource: ['page'],
operation: ['create'],
},
},
default: {},
placeholder: 'Add Option',
options: [
{
displayName: 'Icon Type',
name: 'iconType',
type: 'options',
options: [
{
name: 'Emoji',
value: 'emoji',
description: 'Use an Emoji for the icon',
},
{
name: 'File',
value: 'file',
description: 'Use a file for the icon',
},
],
default: 'emoji',
description: 'The icon type for the page, Either a URL or an Emoji',
},
{
displayName: 'Icon',
name: 'icon',
type: 'string',
default: '',
description: 'Emoji or File URL to use as the icon',
},
],
},
/* -------------------------------------------------------------------------- */
/* page:get */
/* -------------------------------------------------------------------------- */

View file

@ -369,6 +369,15 @@ export class NotionV1 implements INodeType {
responseData = simplifyObjects(responseData, false, 1);
}
const options = this.getNodeParameter('options', i);
if (options.icon) {
if (options.iconType && options.iconType === 'file') {
body.icon = { external: { url: options.icon } };
} else {
body.icon = { emoji: options.icon };
}
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
@ -530,6 +539,15 @@ export class NotionV1 implements INodeType {
responseData = simplifyObjects(responseData, false, 1);
}
const options = this.getNodeParameter('options', i);
if (options.icon) {
if (options.iconType && options.iconType === 'file') {
body.icon = { external: { url: options.icon } };
} else {
body.icon = { emoji: options.icon };
}
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },

View file

@ -463,6 +463,16 @@ export class NotionV2 implements INodeType {
const blockValues = this.getNodeParameter('blockUi.blockValues', i, []) as IDataObject[];
extractDatabaseMentionRLC(blockValues);
body.children = formatBlocks(blockValues);
const options = this.getNodeParameter('options', i);
if (options.icon) {
if (options.iconType && options.iconType === 'file') {
body.icon = { external: { url: options.icon } };
} else {
body.icon = { emoji: options.icon };
}
}
responseData = await notionApiRequest.call(this, 'POST', '/pages', body);
if (simple) {
responseData = simplifyObjects(responseData);
@ -663,7 +673,6 @@ export class NotionV2 implements INodeType {
if (operation === 'create') {
for (let i = 0; i < length; i++) {
const simple = this.getNodeParameter('simple', i) as boolean;
const body: { [key: string]: any } = {
parent: {},
properties: {},
@ -675,6 +684,16 @@ export class NotionV2 implements INodeType {
const blockValues = this.getNodeParameter('blockUi.blockValues', i, []) as IDataObject[];
extractDatabaseMentionRLC(blockValues);
body.children = formatBlocks(blockValues);
const options = this.getNodeParameter('options', i);
if (options.icon) {
if (options.iconType && options.iconType === 'file') {
body.icon = { external: { url: options.icon } };
} else {
body.icon = { emoji: options.icon };
}
}
responseData = await notionApiRequest.call(this, 'POST', '/pages', body);
if (simple) {
responseData = simplifyObjects(responseData, download);