From dbf985c1920457918f15950d4714d54b93c8ced5 Mon Sep 17 00:00:00 2001 From: Devansh Date: Sun, 23 Feb 2025 15:39:50 +0530 Subject: [PATCH 1/2] Fix validation error --- src/handlers/ExecuteBlockActionHandler.ts | 7 ++---- src/lib/NotionSDK.ts | 25 ++++++++++++++----- src/modals/common/DropDownComponent.ts | 22 ++++++++-------- src/modals/common/searchPageComponent.ts | 22 +++++++++------- .../common/searchPageOrDatabaseComponent.ts | 23 +++++++++-------- 5 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/handlers/ExecuteBlockActionHandler.ts b/src/handlers/ExecuteBlockActionHandler.ts index 01bfec3..e0ffd87 100644 --- a/src/handlers/ExecuteBlockActionHandler.ts +++ b/src/handlers/ExecuteBlockActionHandler.ts @@ -260,11 +260,8 @@ export class ExecuteBlockActionHandler { oAuth2Storage: OAuth2Storage, roomInteractionStorage: RoomInteractionStorage ) { - const { user } = this.context.getInteractionData(); const PropertyName = `${DatabaseModal.PROPERTY_NAME_ACTION}-${uuid()}`; - const PropertyType = `${ - DatabaseModal.PROPERTY_TYPE_SELECT_ACTION - }-${uuid()}`; + const PropertyType = `${DatabaseModal.PROPERTY_TYPE_SELECT_ACTION}-${uuid()}`; await modalInteraction.storeInteractionActionId({ PropertyType, @@ -911,7 +908,7 @@ export class ExecuteBlockActionHandler { .getInteractionResponder() .updateModalViewResponse(modal); } - + // update the modal if database is selected const database = Object as IDatabase; diff --git a/src/lib/NotionSDK.ts b/src/lib/NotionSDK.ts index 5b76ce0..72afb93 100644 --- a/src/lib/NotionSDK.ts +++ b/src/lib/NotionSDK.ts @@ -97,14 +97,23 @@ export class NotionSDK implements INotionSDK { cursor?: string ): Promise | Error> { try { - const data = { + const data: { + filter: { + value: any, + property: any, + }; + start_cursor?: string | undefined, + } = { filter: { - value: NotionObjectTypes.PAGE, + value: NotionObjectTypes.DATABASE, property: NotionObjectTypes.PROPERTY, }, - start_cursor: cursor, }; + if (cursor !== undefined) { + data.start_cursor = cursor; + } + const response = await this.http.post(NotionApi.SEARCH, { data, headers: this.getNotionApiHeaders(token), @@ -507,9 +516,13 @@ export class NotionSDK implements INotionSDK { cursor?: string ): Promise | Error> { try { - const data = { - start_cursor: cursor, - }; + const data: { + start_cursor?: string; + } = {}; + + if (cursor !== undefined) { + data.start_cursor = cursor; + } const response = await this.http.post(NotionApi.SEARCH, { data, diff --git a/src/modals/common/DropDownComponent.ts b/src/modals/common/DropDownComponent.ts index f34e39e..d1ec096 100644 --- a/src/modals/common/DropDownComponent.ts +++ b/src/modals/common/DropDownComponent.ts @@ -37,18 +37,20 @@ export function DropDownComponent( dispatchActionConfig.push(Modals.dispatchActionConfigOnInput); } - const dropDown = elementBuilder.addDropDown( - { - placeholder, + const inputBlock = blockBuilder.createInputBlock({ + text: text, + element: { + type: 'static_select', + blockId: blockId, options: dropDownOption, - dispatchActionConfig, - initialValue + appId: app.getID(), + actionId: actionId, + placeholder: { + type: 'plain_text', + text: placeholder, + }, + dispatchActionConfig: [Modals.dispatchActionConfigOnSelect] }, - { blockId, actionId } - ); - const inputBlock = blockBuilder.createInputBlock({ - text, - element: dropDown, optional: false, }); diff --git a/src/modals/common/searchPageComponent.ts b/src/modals/common/searchPageComponent.ts index 6f5b5a7..9d425e3 100644 --- a/src/modals/common/searchPageComponent.ts +++ b/src/modals/common/searchPageComponent.ts @@ -39,19 +39,23 @@ export async function searchPageComponent( }; }); const dropDownOption = elementBuilder.createDropDownOptions(options); - const dropDown = elementBuilder.addDropDown( - { - placeholder: SearchPage.PLACEHOLDER, - options: dropDownOption, - dispatchActionConfig: [Modals.dispatchActionConfigOnSelect], - }, - { blockId: SearchPage.BLOCK_ID, actionId } - ); const inputBlock = blockBuilder.createInputBlock({ text: SearchPage.LABEL, - element: dropDown, + element: { + type: 'static_select', + blockId: SearchPage.BLOCK_ID, + options: dropDownOption, + appId: app.getID(), + actionId: actionId, + placeholder: { + type: 'plain_text', + text: SearchPage.PLACEHOLDER, + }, + dispatchActionConfig: [Modals.dispatchActionConfigOnSelect] + }, optional: false, }); + return inputBlock; } diff --git a/src/modals/common/searchPageOrDatabaseComponent.ts b/src/modals/common/searchPageOrDatabaseComponent.ts index 64daa30..1d180d6 100644 --- a/src/modals/common/searchPageOrDatabaseComponent.ts +++ b/src/modals/common/searchPageOrDatabaseComponent.ts @@ -36,7 +36,7 @@ export async function searchPageOrDatabaseComponent( const options: StaticSelectOptionsParam = accesiblePagesAndDatabase.map( (item) => { - + const info = NotionObjectTypes.INFO.toString(); const name = NotionObjectTypes.NAME.toString(); @@ -51,17 +51,20 @@ export async function searchPageOrDatabaseComponent( ); const dropDownOption = elementBuilder.createDropDownOptions(options); - const dropDown = elementBuilder.addDropDown( - { - placeholder: SearchPageAndDatabase.PLACEHOLDER, - options: dropDownOption, - dispatchActionConfig: [Modals.dispatchActionConfigOnSelect], - }, - { blockId: SearchPageAndDatabase.BLOCK_ID, actionId } - ); const inputBlock = blockBuilder.createInputBlock({ text: SearchPageAndDatabase.LABEL, - element: dropDown, + element: { + type: 'static_select', + blockId: SearchPageAndDatabase.BLOCK_ID, + options: dropDownOption, + appId: app.getID(), + actionId: actionId, + placeholder: { + type: 'plain_text', + text: SearchPageAndDatabase.PLACEHOLDER, + }, + dispatchActionConfig: [Modals.dispatchActionConfigOnSelect] + }, optional: false, }); From 72c80bbcb1b34845fc99896c3e7790c5ced52d3f Mon Sep 17 00:00:00 2001 From: Devansh Date: Sun, 23 Feb 2025 16:25:36 +0530 Subject: [PATCH 2/2] Ensured that the pages get listed in searchPageComponent --- src/lib/NotionSDK.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/lib/NotionSDK.ts b/src/lib/NotionSDK.ts index 72afb93..993f9a0 100644 --- a/src/lib/NotionSDK.ts +++ b/src/lib/NotionSDK.ts @@ -98,20 +98,16 @@ export class NotionSDK implements INotionSDK { ): Promise | Error> { try { const data: { - filter: { - value: any, - property: any, - }; - start_cursor?: string | undefined, - } = { - filter: { - value: NotionObjectTypes.DATABASE, - property: NotionObjectTypes.PROPERTY, - }, - }; + filter?: any; + start_cursor?: string | undefined; + } = {}; if (cursor !== undefined) { data.start_cursor = cursor; + data.filter = { + value: NotionObjectTypes.DATABASE, + property: NotionObjectTypes.PROPERTY, + } } const response = await this.http.post(NotionApi.SEARCH, {