From 6fdec4b79fde18daacbec75725130661f9b3236b Mon Sep 17 00:00:00 2001 From: Harish Mohan Raj Date: Tue, 23 Apr 2024 15:01:09 +0530 Subject: [PATCH] Do not show daily analysis chat unless the user loads the application with its uuid in the query parameter --- app/main.wasp | 1 + .../migration.sql | 2 + .../migration.sql | 2 + app/src/client/app/ChatPage.tsx | 16 +++- app/src/client/components/ChatSidebar.tsx | 75 ++++++++++--------- app/src/client/tests/chatUtils.test.ts | 58 +++++++++++++- app/src/client/utils/chatUtils.ts | 6 +- 7 files changed, 121 insertions(+), 39 deletions(-) create mode 100644 app/migrations/20240423082334_add_a_field_to_chat_model_to_decide_whether_to_show_the_daily_analysis_chat/migration.sql create mode 100644 app/migrations/20240423082642_set_the_should_show_chat_value_for_existing_daily_analysis_chats/migration.sql diff --git a/app/main.wasp b/app/main.wasp index fba8738..41f8353 100644 --- a/app/main.wasp +++ b/app/main.wasp @@ -125,6 +125,7 @@ entity Chat {=psl team_name String? team_status String? chatType String? + shouldShowChat Boolean @default(false) proposedUserAction String[] @default([]) userRespondedWithNextAction Boolean @default(false) emailContent String? diff --git a/app/migrations/20240423082334_add_a_field_to_chat_model_to_decide_whether_to_show_the_daily_analysis_chat/migration.sql b/app/migrations/20240423082334_add_a_field_to_chat_model_to_decide_whether_to_show_the_daily_analysis_chat/migration.sql new file mode 100644 index 0000000..9e705bf --- /dev/null +++ b/app/migrations/20240423082334_add_a_field_to_chat_model_to_decide_whether_to_show_the_daily_analysis_chat/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Chat" ADD COLUMN "shouldShowChat" BOOLEAN NOT NULL DEFAULT false; diff --git a/app/migrations/20240423082642_set_the_should_show_chat_value_for_existing_daily_analysis_chats/migration.sql b/app/migrations/20240423082642_set_the_should_show_chat_value_for_existing_daily_analysis_chats/migration.sql new file mode 100644 index 0000000..5e7bb81 --- /dev/null +++ b/app/migrations/20240423082642_set_the_should_show_chat_value_for_existing_daily_analysis_chats/migration.sql @@ -0,0 +1,2 @@ +-- This migration sets the shouldShowChat value to true for all existing daily analysis chats. +UPDATE "Chat" SET "shouldShowChat" = TRUE WHERE "chatType" = 'daily_analysis'; \ No newline at end of file diff --git a/app/src/client/app/ChatPage.tsx b/app/src/client/app/ChatPage.tsx index 6bb7f57..a3a7d06 100644 --- a/app/src/client/app/ChatPage.tsx +++ b/app/src/client/app/ChatPage.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useSocket, useSocketListener } from 'wasp/client/webSocket'; import { type User } from 'wasp/entities'; @@ -54,6 +54,20 @@ const ChatPage = ({ user }: { user: User }) => { { enabled: !!activeChatId } ); + useEffect(() => { + if ( + currentChatDetails && + currentChatDetails.chatType === 'daily_analysis' + ) { + updateCurrentChat({ + id: activeChatId, + data: { + shouldShowChat: true, + }, + }); + } + }, [activeChatUUId, currentChatDetails]); + useSocketListener('smartSuggestionsAddedToDB', updateState); useSocketListener('streamFromTeamFinished', updateState); diff --git a/app/src/client/components/ChatSidebar.tsx b/app/src/client/components/ChatSidebar.tsx index 85e6eb8..23db1b3 100644 --- a/app/src/client/components/ChatSidebar.tsx +++ b/app/src/client/components/ChatSidebar.tsx @@ -5,7 +5,7 @@ import { Link, useHistory } from 'react-router-dom'; import { NavLink, useLocation } from 'react-router-dom'; import Logo from '../static/logo-for-dark-bg.png'; import EditableChatName from './EditableChatName'; - +import { shouldRenderChat } from '../utils/chatUtils'; import { updateCurrentChat } from 'wasp/client/operations'; interface ChatSidebarProps { @@ -189,41 +189,44 @@ const ChatSidebar = ({ {/* */}
  • {chats && - chats.map((chat: Chat, idx) => ( - - - - - - - - - ))} + chats.map( + (chat: Chat, idx) => + shouldRenderChat(chat) && ( + + + + + + + + + ) + )}
  • diff --git a/app/src/client/tests/chatUtils.test.ts b/app/src/client/tests/chatUtils.test.ts index 7c6b22e..2f49d26 100644 --- a/app/src/client/tests/chatUtils.test.ts +++ b/app/src/client/tests/chatUtils.test.ts @@ -1,4 +1,4 @@ -import { test, expect, vi, describe } from 'vitest'; +import { test, expect, vi, describe, it } from 'vitest'; import * as operations from 'wasp/client/operations'; import { type Conversation } from 'wasp/entities'; @@ -12,7 +12,9 @@ import { handleAgentResponse, handleChatError, exceptionMessage, + shouldRenderChat, } from '../utils/chatUtils'; +import { type Chat } from 'wasp/entities'; vi.mock('wasp/client/operations', async (importOriginal) => { const mod = await importOriginal(); @@ -486,3 +488,57 @@ describe('chatUtils', () => { }); }); }); + +const patialTestChatFields = { + id: 0, + uuid: null, + createdAt: new Date(), + updatedAt: new Date(), + team_id: null, + team_name: null, + team_status: null, + proposedUserAction: [], + userRespondedWithNextAction: false, + emailContent: null, + agentChatHistory: null, + isExceptionOccured: false, + showLoader: false, + smartSuggestions: null, + streamAgentResponse: false, + customerBrief: null, + userId: null, + name: null, + isChatNameUpdated: false, +}; + +describe('shouldRenderChat', () => { + it('should return true if chatType is "daily_analysis" and shouldShowChat is true', () => { + const chat: Chat = { + chatType: 'daily_analysis', + shouldShowChat: true, + ...patialTestChatFields, + }; + + expect(shouldRenderChat(chat)).toBe(true); + }); + + it('should return true if chatType is not "daily_analysis"', () => { + const chat = { + chatType: 'other_type', + shouldShowChat: false, + ...patialTestChatFields, + }; + + expect(shouldRenderChat(chat)).toBe(true); + }); + + it('should return false if shouldShowChat is false', () => { + const chat = { + chatType: 'daily_analysis', + shouldShowChat: false, + ...patialTestChatFields, + }; + + expect(shouldRenderChat(chat)).toBe(false); + }); +}); diff --git a/app/src/client/utils/chatUtils.ts b/app/src/client/utils/chatUtils.ts index 59cf045..75912d8 100644 --- a/app/src/client/utils/chatUtils.ts +++ b/app/src/client/utils/chatUtils.ts @@ -7,7 +7,7 @@ import { deleteLastConversationInChat, } from 'wasp/client/operations'; -import { type Conversation } from 'wasp/entities'; +import { type Conversation, type Chat } from 'wasp/entities'; export const exceptionMessage = "Ahoy, mate! It seems our voyage hit an unexpected squall. Let's trim the sails and set a new course. Cast off once more by clicking the button below."; @@ -236,3 +236,7 @@ export const handleChatError = async ( }); } }; + +export const shouldRenderChat = (chat: Chat): boolean => { + return chat.chatType !== 'daily_analysis' || chat.shouldShowChat; +};