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/#75 input values settings #78

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions whiteboard/WhiteboardApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
IPersistence,
IRead,
IAppInstallationContext,
IPersistenceRead,
} 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 @@ -53,13 +54,15 @@ export class WhiteboardApp extends App implements IUIKitInteractionHandler {
read: IRead,
http: IHttp,
persistence: IPersistence,
// persisenceRead: IPersistenceRead,
modify: IModify
): Promise<IUIKitResponse> {
const handler = new ExecuteBlockActionHandler(
this,
read,
http,
persistence,
// persisenceRead,
modify,
context
);
Expand Down
25 changes: 24 additions & 1 deletion whiteboard/handlers/ExecuteBlockActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { UtilityEnum } from "../enum/uitlityEnum";
import { SettingsModal } from "../modals/SettingsModal";
import { DeleteModal } from "../modals/DeleteModal";
import { IUser } from "@rocket.chat/apps-engine/definition/users";
import { getCurrentBoardName, getCurrentBoardLabel } from '../persistence/boardInteraction';

// ExecuteBlockActionHandler is used to handle the block actions
export class ExecuteBlockActionHandler {
Expand All @@ -25,13 +26,32 @@ export class ExecuteBlockActionHandler {
private readonly modify: IModify,
private readonly context: UIKitBlockInteractionContext
) {}
// Add a method to get the current board name
private async getCurrentBoardName(): Promise<string> {
// Assuming you have a method to get the messageId from the context
const messageId = this.context.getInteractionData().message?.id;

// Call the helper function to get the current board name
return getCurrentBoardName(this.read.getPersistenceReader(), messageId);
}

// Add a method to get the current board label
private async getCurrentBoardLabel(): Promise<string> {
// Assuming you have a method to get the messageId from the context
const messageId = this.context.getInteractionData().message?.id;

// Call the helper function to get the current board name
return getCurrentBoardLabel(this.read.getPersistenceReader(), messageId);
}

public async run(): Promise<IUIKitResponse> {
const data = this.context.getInteractionData();
try {
const {
actionId,
triggerId,
user,
// messageId,
room,
value,
message,
Expand All @@ -49,7 +69,10 @@ export class ExecuteBlockActionHandler {
// handleSettingsButtonAction is used to handle the settings button action
case UtilityEnum.SETTINGS_BUTTON_ACTION_ID:
if (messageId) {
const modal = await SettingsModal(appId, messageId);
// Call the method to get the current board name
const currentBoardName = await this.getCurrentBoardName();
const currentBoardLabel = await this.getCurrentBoardLabel();
const modal = await SettingsModal(appId, messageId, currentBoardName, currentBoardLabel);
await Promise.all([
this.modify.getUiController().openSurfaceView(
modal,
Expand Down
6 changes: 6 additions & 0 deletions whiteboard/lib/commandUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ export class CommandUtility implements ExecutorProps {
const boardEndpoint = endpoints[0];
const appId = app.getID();
const params = this.context.getArguments();
console.log("Params: " + params);


// the name specified in command "/whiteboard new"
let createBoardName =
params.length > 1 ? params.slice(1).join(" ") : "";
console.log(createBoardName);


const repeatBoardName = await checkBoardNameByRoomId(
this.read.getPersistenceReader(),
Expand Down Expand Up @@ -304,6 +308,8 @@ export class CommandUtility implements ExecutorProps {
}

public async resolveCommand(context: WhiteboardSlashCommandContext) {
console.log(this.command);

switch (this.command[0]) {
case "new":
await this.handleNewBoardCommand(context);
Expand Down
14 changes: 11 additions & 3 deletions whiteboard/modals/SettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import {
getSectionBlock,
getStaticSelectElement,
} from "../helpers/blockBuilder";
import { getBoardRecordByRoomId } from '../persistence/boardInteraction';

export async function SettingsModal(
appId: string,
messageId: string
messageId: string,
boardName: string,
boardLabel: string,
): Promise<IUIKitSurfaceViewParam> {
const block: Block[] = [];

// Call the modified function to get the board name
// const boardRecords = await getBoardRecordByRoomId(persistenceRead, roomId);

/* For Settings Text block */
let settingsTextBlock = getSectionBlock(UtilityEnum.SETTINGS_LABEL);
block.push(settingsTextBlock);
Expand All @@ -28,7 +34,8 @@ export async function SettingsModal(
UtilityEnum.BOARD_INPUT_PLACEHOLDER,
UtilityEnum.BOARD_INPUT_BLOCK_ID,
UtilityEnum.BOARD_INPUT_ACTION_ID,
appId
appId,
boardName,
);
block.push(boardInputBlock);

Expand All @@ -55,7 +62,8 @@ export async function SettingsModal(
options,
appId,
UtilityEnum.BOARD_SELECT_BLOCK_ID,
UtilityEnum.BOARD_SELECT_ACTION_ID
UtilityEnum.BOARD_SELECT_ACTION_ID,
boardLabel,
);

// Event handling for dropdown selection
Expand Down
32 changes: 30 additions & 2 deletions whiteboard/persistence/boardInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
RocketChatAssociationModel,
RocketChatAssociationRecord,
} from "@rocket.chat/apps-engine/definition/metadata";
import { UtilityEnum } from '../enum/uitlityEnum';

//functions needed to persist board data while modal and other UI interactions
// Messages can be retrieved by using the messageId, privateMessageId and boardId
Expand Down Expand Up @@ -75,7 +76,7 @@ export const storeBoardRecord = async (
// query all records within the "scope" - room
export const getBoardRecordByRoomId = async (
persistenceRead: IPersistenceRead,
roomId: string
roomId: string | undefined,
): Promise<any> => {
const association = new RocketChatAssociationRecord(
RocketChatAssociationModel.ROOM,
Expand Down Expand Up @@ -110,6 +111,8 @@ export const checkBoardNameByRoomId = async (
boardName: string
): Promise<any> => {
const boardData = await getBoardRecordByRoomId(persistenceRead, roomId);
console.log(boardData);

if (boardName == "") return false;

for (const board of boardData) {
Expand Down Expand Up @@ -166,6 +169,30 @@ export const getBoardName = async (
return newName;
};

// function to get the current board name
export const getCurrentBoardName = async (
persistenceRead: IPersistenceRead,
messageId: string | undefined,
): Promise<string> => {
// Retrieve the board record based on the messageId
const boardRecord = await getBoardRecordByMessageId(persistenceRead, messageId);

// Return the board name if found, otherwise a default name
return boardRecord ? boardRecord.title : 'Untitled Board';
};

// function to get the current board name
export const getCurrentBoardLabel = async (
persistenceRead: IPersistenceRead,
messageId: string | undefined,
): Promise<string> => {
// Retrieve the board record based on the messageId
const boardRecord = await getBoardRecordByMessageId(persistenceRead, messageId);

// Return the board name if found, otherwise a default name
return boardRecord ? boardRecord.status : UtilityEnum.PUBLIC;
};

export const getBoardRecord = async (
persistenceRead: IPersistenceRead,
boardId: string
Expand All @@ -182,7 +209,7 @@ export const getBoardRecord = async (

export const getBoardRecordByMessageId = async (
persistenceRead: IPersistenceRead,
messageId: string
messageId: string | undefined,
): Promise<any> => {
const association = new RocketChatAssociationRecord(
RocketChatAssociationModel.MESSAGE,
Expand All @@ -192,6 +219,7 @@ export const getBoardRecordByMessageId = async (
association
)) as Array<any>;
return result && result.length ? result[0] : null;

};

export const updateBoardnameByMessageId = async (
Expand Down