Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] View Notion Table inside RC #28

Merged
merged 24 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1d2dd41
feat: create record
Nabhag8848 Jul 24, 2023
91c5819
feat: create record improved Version
Nabhag8848 Aug 2, 2023
e089eec
fix: Required Property Closing Modal onSubmit with ViewErrors
Nabhag8848 Aug 21, 2023
7fe1082
fix: variable naming to missingPropObject
Nabhag8848 Aug 22, 2023
5a51803
feat: share page
Nabhag8848 Jul 28, 2023
cce0216
fix: Sharing page without selecting with ViewErrors
Nabhag8848 Aug 2, 2023
5055660
feat: register send to page message action
Nabhag8848 Aug 8, 2023
59a596c
feat: Write Message While Creation of Notion Record
Nabhag8848 Aug 8, 2023
bb031ec
fix: message attachment to have a quote instead of text
Nabhag8848 Aug 8, 2023
98f8747
feat: Write Message while Creating Page
Nabhag8848 Aug 8, 2023
9311a85
feat: appendCodeBlock while Creating Message text in Page
Nabhag8848 Aug 8, 2023
1c94a11
feat: appendCallOutBlock on Preserving Message
Nabhag8848 Aug 8, 2023
40c0989
fix: actionbutton to send-to-new-page instead of send-to-page
Nabhag8848 Aug 10, 2023
4e10882
fix: share page to get new created pages
Nabhag8848 Aug 10, 2023
09ec9fc
feat: created sendMessagePageModal()
Nabhag8848 Aug 10, 2023
87d8bfe
feat: handled sendToNotionPage Action
Nabhag8848 Aug 10, 2023
e75a0eb
feat: handled sendToNotionPage Submit Action
Nabhag8848 Aug 10, 2023
fbeb93c
feat: created searchDatabases() method in NotionSDK
Nabhag8848 Aug 10, 2023
592f386
feat: created searchDatabaseComponent()
Nabhag8848 Aug 10, 2023
fa2b46b
feat: created viewNotionTableModal()
Nabhag8848 Aug 10, 2023
212096a
feat: created queryDatabasePages() in NotionSDK
Nabhag8848 Aug 10, 2023
9164165
feat: handled viewNotionTable with View command Param
Nabhag8848 Aug 10, 2023
11d8e3e
fix: handled required elements with view errors
Nabhag8848 Aug 10, 2023
fd6c6a1
feat: handled submit action of viewTable
Nabhag8848 Aug 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion NotionApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ILogger,
IModify,
IPersistence,
IRead
IRead,
} from "@rocket.chat/apps-engine/definition/accessors";
import { App } from "@rocket.chat/apps-engine/definition/App";
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata";
Expand Down Expand Up @@ -80,7 +80,21 @@ export class NotionApp extends App {
context: UIActionButtonContext.MESSAGE_BOX_ACTION,
};

const sendToPageButton: IUIActionButtonDescriptor = {
actionId: ActionButton.SEND_TO_PAGE_MESSAGE_ACTION,
labelI18n: ActionButton.SEND_TO_PAGE_MESSAGE_ACTION_LABEL,
context: UIActionButtonContext.MESSAGE_ACTION,
};

const sendToNewPageButton: IUIActionButtonDescriptor = {
actionId: ActionButton.SEND_TO_NEW_PAGE_MESSAGE_ACTION,
labelI18n: ActionButton.SEND_TO_NEW_PAGE_MESSAGE_ACTION_LABEL,
context: UIActionButtonContext.MESSAGE_ACTION,
};

configurationExtend.ui.registerButton(commentOnPagesButton);
configurationExtend.ui.registerButton(sendToPageButton);
configurationExtend.ui.registerButton(sendToNewPageButton);
}

public getOAuth2Client(): OAuth2Client {
Expand Down
3 changes: 3 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
},
{
"name": "room.write"
},
{
"name": "message.read"
}
]
}
1 change: 1 addition & 0 deletions definition/handlers/IHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IHandler extends Omit<ICommandUtilityParams, "params"> {
commentOnPages(): Promise<void>;
createNotionPageOrRecord(): Promise<void>;
changeNotionWorkspace(): Promise<void>;
shareNotionPage(): Promise<void>;
}

export type IHanderParams = Omit<ICommandUtilityParams, "params">;
72 changes: 71 additions & 1 deletion definition/lib/INotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { INotionUser, ITokenInfo } from "../authorization/IOAuth2Storage";
import { ClientError, Error } from "../../errors/Error";
import { NotionObjectTypes, NotionOwnerType } from "../../enum/Notion";
import { RichText } from "@tryfabric/martian/build/src/notion";
import { RecordPropertyType } from "../../enum/modals/common/NotionProperties";
import { Modals } from "../../enum/modals/common/Modals";
import { IMessageAttachmentField } from "@rocket.chat/apps-engine/definition/messages";

export interface INotion {
baseUrl: string;
Expand Down Expand Up @@ -46,7 +49,37 @@ export interface INotionSDK extends INotion {
token: string,
page: IPage,
prop: IPageProperties
): Promise<INotionPage | Error>;
): Promise<(INotionPage & { pageId: string }) | Error>;
retrieveDatabase(
token: string,
database_id: string
): Promise<object | Error>;
createRecord(
token: string,
database: IDatabase,
properties: object
): Promise<
| {
fields: Array<IMessageAttachmentField>;
url: string;
pageId: string;
}
| Error
>;
retrievePage(
token: string,
pageId: string
): Promise<(IPage & { url: string }) | Error>;
appendMessageBlock(
token: string,
message: string,
blockId: string
): Promise<boolean | Error>;
searchDatabases(token: string): Promise<Array<IDatabase> | Error>;
queryDatabasePages(
token: string,
databaseId: string
): Promise<Array<Array<string>> | Error>;
}

export interface IParentPage {
Expand Down Expand Up @@ -114,3 +147,40 @@ export interface IPageProperties {
export interface INotionPage extends INotionDatabase {
title: string;
}

export interface IDatabaseProperties {
title: IDatabaseTitle;
additionalProperties?: IDatabaseAddProperties;
}

export interface IDatabaseTitle {
id: string;
type: NotionObjectTypes.TITLE;
name: string;
}

export interface IDatabaseAddProperties {
[key: string]: {
id: string;
name: string;
type: RecordPropertyType;
config?: IDatabasePropertiesConfig;
};
}

interface IDatabasePropertiesConfig {
[Modals.OPTIONS]?: Array<{
id: string;
color: string;
name: string;
}>;

[Modals.GROUPS]?: Array<{
id: string;
color: string;
name: string;
options_ids: Array<string>;
}>;

[NotionObjectTypes.EXPRESSION]?: string;
}
6 changes: 6 additions & 0 deletions definition/ui-kit/Element/IDatePickerElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DatePickerElement } from "@rocket.chat/ui-kit";

export type DatePickerElementParam = Omit<
DatePickerElement,
"type" | "placeholder" | "appId" | "blockId" | "actionId"
> & { text?: string };
13 changes: 12 additions & 1 deletion definition/ui-kit/Element/IElementBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ButtonStyle } from "@rocket.chat/apps-engine/definition/uikit";
import {
ButtonElement,
ImageElement,
StaticSelectElement,
PlainTextInputElement,
OverflowElement,
Option,
DatePickerElement,
MultiStaticSelectElement,
} from "@rocket.chat/ui-kit";
import { ButtonParam } from "./IButtonElement";
import { ImageParam } from "./IImageElement";
Expand All @@ -15,6 +16,8 @@ import {
} from "./IStaticSelectElement";
import { PlainTextInputParam } from "./IPlainTextInputElement";
import { OverflowElementParam } from "./IOverflowElement";
import { DatePickerElementParam } from "./IDatePickerElement";
import { MultiStaticSelectElementParam } from "./IMultiStaticSelectElement";

export interface IElementBuilder {
addButton(
Expand All @@ -35,6 +38,14 @@ export interface IElementBuilder {
param: OverflowElementParam,
interaction: ElementInteractionParam
): OverflowElement;
createDatePicker(
param: DatePickerElementParam,
interaction: ElementInteractionParam
): DatePickerElement;
createMultiStaticSelect(
param: MultiStaticSelectElementParam,
interaction: ElementInteractionParam
): MultiStaticSelectElement;
}

export type ElementInteractionParam = { blockId: string; actionId: string };
7 changes: 7 additions & 0 deletions definition/ui-kit/Element/IMultiStaticSelectElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { MultiStaticSelectElement } from "@rocket.chat/ui-kit";
export type MultiStaticSelectElementParam = Omit<
MultiStaticSelectElement,
"type" | "blockId" | "actionId" | "placeholder" | "appId"
> & {
text: string;
};
2 changes: 2 additions & 0 deletions enum/CommandParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export enum CommandParam {
COMMENT = "comment",
WORKSPACE = "workspace",
WS = "ws",
SHARE = "share",
VIEW = "view",
}

export enum SubCommandParam {
Expand Down
4 changes: 4 additions & 0 deletions enum/Notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum NotionApi {
COMMENTS = `https://api.notion.com/v1/comments`,
USERS = `https://api.notion.com/v1/users`,
PAGES = `https://api.notion.com/v1/pages`,
BLOCKS = `https://api.notion.com/v1/blocks`,
}

export enum Notion {
Expand All @@ -45,4 +46,7 @@ export enum NotionObjectTypes {
TITLE = "title",
INFO = "info",
NAME = "name",
PROPERTIES = "properties",
ID = "id",
DATABASE = "database",
}
3 changes: 2 additions & 1 deletion enum/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export enum Messages {
• use \`/notion comment\` to comment on notion page
• use \`/notion create\` to create page or record
• use \`/notion create db\` to create database
• use \`/notion workspace\` to change workspace
• use \`/notion workspace\` to change workspace
• use \`/notion share\` to share pages

`,
HELPER_TEXT = `:wave: Need some help with \`/notion\`?`,
Expand Down
4 changes: 1 addition & 3 deletions enum/modals/NotionPageOrRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ export enum NotionPageOrRecord {
TITLE_ACTION = "title-page-or-record-action-id",
CHANGE_DATABASE_TEXT = "Change Database",
CHANGE_DATABASE_ACTION = "create-page-or-record-change-database-action-id",
ADD_PROPERTY_ACTION = "add-property-create-page-or-record-action-id",
ADD_PROPERTY_BLOCK = "add-property-create-page-or-record-action-id",
ADD_PROPERTY_BUTTON_TEXT = "Add Property",
PROPERTY_SELECTED_BLOCK_ELEMENT = "property-selected-element-create-page-or-record-block-id",
}
11 changes: 11 additions & 0 deletions enum/modals/NotionTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum NotionTable {
VIEW_ID = "notion-view-table-view-id",
ACTION_ID = "notion-view-table-action-id",
VIEW_ACTION = "notion-view-table-view-action-id",
VIEW_BLOCK = "notion-view-table-view-block-id",
CANCEL_ACTION = "notion-view-table-cancel-action-id",
CANCEL_BLOCK = "notion-view-table-cancel-block-id",
VIEW = "View",
CANCEL = "Cancel",
TITLE = "View Notion Table",
}
11 changes: 11 additions & 0 deletions enum/modals/SendMessagePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum SendMessagePage {
VIEW_ID = "notion-send-message-page-view-id",
ACTION_ID = "notion-send-message-page-action-id",
SEND_ACTION = "notion-send-message-page-send-action-id",
SEND_BLOCK = "notion-send-message-page-send-block-id",
CANCEL_ACTION = "notion-send-message-page-cancel-action-id",
CANCEL_BLOCK = "notion-send-message-page-cancel-block-id",
SEND = "Send",
CANCEL = "Cancel",
TITLE = "Send To Notion Page",
}
11 changes: 11 additions & 0 deletions enum/modals/SharePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum SharePage {
VIEW_ID = "notion-share-page-view-id",
ACTION_ID = "notion-share-page-action-id",
SHARE_ACTION = "notion-share-page-share-action-id",
SHARE_BLOCK = "notion-share-page-share-block-id",
CLOSE_ACTION = "notion-share-page-close-action-id",
CLOSE_BLOCK = "notion-share-page-close-block-id",
SHARE = "Share",
CLOSE = "Close",
TITLE = "Share Notion Page",
}
4 changes: 4 additions & 0 deletions enum/modals/common/ActionButtons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export enum ActionButton {
COMMENT_ON_PAGES_MESSAGE_BOX_ACTION = "comment-on-pages-message-box-action",
COMMENT_ON_PAGES_MESSAGE_BOX_ACTION_LABEL = "CommentOnPagesLabel",
SEND_TO_PAGE_MESSAGE_ACTION = "send-to-page-message-action",
SEND_TO_PAGE_MESSAGE_ACTION_LABEL = "SendToPageLabel",
SEND_TO_NEW_PAGE_MESSAGE_ACTION = "send-to-new-page-message-action",
SEND_TO_NEW_PAGE_MESSAGE_ACTION_LABEL = "SendToNewPageLabel",
}
4 changes: 4 additions & 0 deletions enum/modals/common/Modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ export enum Modals {
MISSING = "missing",
VIEWERROR = "viewError",
DATA = "data",
ADDITIONAL_PROP = "additionalProperties",
GROUPS = "groups",
PROPERTY = "property",
VALUE = "value",
}
30 changes: 30 additions & 0 deletions enum/modals/common/NotionProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,33 @@ export enum MissingPropertyMessage {
EXPRESSION = "Expression is required",
OPTION_NAME = "Option Name is required",
}

export type RecordPropertyType = Exclude<
PropertyTypeValue,
| PropertyTypeValue.CREATED_TIME
| PropertyTypeValue.CREATED_BY
| PropertyTypeValue.LAST_EDITED_TIME
| PropertyTypeValue.LAST_EDITED_BY
>;

export enum NotSupportedPropertyType {
RELATION = "relation",
ROLLUP = "rollup",
}

export const NotSupportedPropertyTypes = [
PropertyTypeValue.CREATED_TIME.toString(),
PropertyTypeValue.CREATED_BY.toString(),
PropertyTypeValue.LAST_EDITED_TIME.toString(),
PropertyTypeValue.LAST_EDITED_BY.toString(),
NotSupportedPropertyType.RELATION.toString(),
NotSupportedPropertyType.ROLLUP.toString(),
PropertyTypeValue.FILES.toString(),
];

export enum CheckboxEnum {
TRUE = "true",
FALSE = "false",
YES = "Yes",
NO = "No",
}
6 changes: 6 additions & 0 deletions enum/modals/common/SearchDatabaseComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum SearchDatabaseComponent {
PLACEHOLDER = "Select Database",
BLOCK_ID = "search-database-component-block-id",
ACTION_ID = "search-database-component-action-id",
LABEL = "Database Name *",
}
4 changes: 3 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"CredentialsSettings": "Authorization Settings",
"NotionCommandParams": "connect | disconnect | workspace | create | schema | comment",
"NotionCommandDescription": "Create Notion pages and database from Rocket.Chat",
"CommentOnPagesLabel": "💬 Comment on Page"
"CommentOnPagesLabel": "💬 Comment on Page",
"SendToPageLabel": "📝 Send to Page",
"SendToNewPageLabel": "📢 Send to New Page"
}
Loading