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

Add PRs #315 and #317 #318

Merged
merged 2 commits into from
Apr 23, 2024
Merged
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
1 change: 1 addition & 0 deletions app/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Chat" ADD COLUMN "shouldShowChat" BOOLEAN NOT NULL DEFAULT false;
Original file line number Diff line number Diff line change
@@ -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';
10 changes: 9 additions & 1 deletion app/src/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,15 @@ export default function App({ children }: { children: ReactNode }) {
<Footer />
<div className='flex items-center h-20 '>
<p className='text-center w-full text-sm text-captn-dark-blue opacity-50'>
© 2024 airt. All rights reserved.
© 2024{' '}
<a
href='https://airt.ai'
className='text-sm leading-6 hover:text-captn-light-blue text-captn-dark-blue underline'
target='_blank'
>
airt
</a>
. All rights reserved.
</p>
</div>
</div>
Expand Down
16 changes: 15 additions & 1 deletion app/src/client/app/ChatPage.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);

Expand Down
75 changes: 39 additions & 36 deletions app/src/client/components/ChatSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -189,41 +189,44 @@ const ChatSidebar = ({
{/* <!-- Menu Item Dashboard --> */}
<li>
{chats &&
chats.map((chat: Chat, idx) => (
<NavLink
key={chat.id}
to={`/chat/${chat.uuid}?`}
className={`chat-link relative no-underline group relative flex items-center gap-2.5 rounded-sm py-2 px-4 font-medium text-bodydark1 duration-300 ease-in-out ${
pathname === '/' && 'bg-gray-700 dark:bg-meta-4'
} ${
chat.uuid === activeChat
? 'bg-captn-light-cream text-captn-dark-blue hover:bg-captn-light-blue hover:text-captn-dark-blue'
: 'text-captn-light-cream hover:bg-captn-light-blue hover:text-captn-dark-blue'
}`}
>
<svg
stroke='currentColor'
fill='none'
strokeWidth='2'
viewBox='0 0 24 24'
strokeLinecap='round'
strokeLinejoin='round'
className='icon-sm'
height='1em'
width='1em'
xmlns='http://www.w3.org/2000/svg'
>
<path d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'></path>
</svg>
<span>
<EditableChatName
chatId={chat.id}
chatName={chat.name ? chat.name : ''}
onValueChange={handlechatNameChange}
/>
</span>
</NavLink>
))}
chats.map(
(chat: Chat, idx) =>
shouldRenderChat(chat) && (
<NavLink
key={chat.id}
to={`/chat/${chat.uuid}?`}
className={`chat-link relative no-underline group relative flex items-center gap-2.5 rounded-sm py-2 px-4 font-medium text-bodydark1 duration-300 ease-in-out ${
pathname === '/' && 'bg-gray-700 dark:bg-meta-4'
} ${
chat.uuid === activeChat
? 'bg-captn-light-cream text-captn-dark-blue hover:bg-captn-light-blue hover:text-captn-dark-blue'
: 'text-captn-light-cream hover:bg-captn-light-blue hover:text-captn-dark-blue'
}`}
>
<svg
stroke='currentColor'
fill='none'
strokeWidth='2'
viewBox='0 0 24 24'
strokeLinecap='round'
strokeLinejoin='round'
className='icon-sm'
height='1em'
width='1em'
xmlns='http://www.w3.org/2000/svg'
>
<path d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'></path>
</svg>
<span>
<EditableChatName
chatId={chat.id}
chatName={chat.name ? chat.name : ''}
onValueChange={handlechatNameChange}
/>
</span>
</NavLink>
)
)}
</li>
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/src/client/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const Footer = () => {
>
<div className='flex items-start justify-end mt-10 gap-20 mx-auto max-w-7xl sm:px-6 lg:px-8'>
<div>
<h3 className='text-sm font-semibold leading-6 text-captn-dark-blue dark:text-captn-light-cream'>
{/* <h3 className='text-sm font-semibold leading-6 text-captn-dark-blue dark:text-captn-light-cream'>
Company
</h3>
</h3> */}
<ul role='list' className='mt-6 space-y-4'>
{footerNavigation.company.map((item) => (
<li key={item.name}>
Expand Down
5 changes: 2 additions & 3 deletions app/src/client/landing-page/contentSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ export const footerNavigation = {
{ name: 'Blog', href: BLOG_URL },
],
company: [
{ name: 'airt', href: 'https://airt.ai/' },
{ name: 'Privacy', href: '/privacy' },
{ name: 'Terms of Service', href: '/toc' },
{ name: 'Privacy Policy', href: '/privacy' },
{ name: 'Terms & Conditions', href: '/toc' },
],
};
58 changes: 57 additions & 1 deletion app/src/client/tests/chatUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<typeof import('wasp/client/operations')>();
Expand Down Expand Up @@ -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);
});
});
6 changes: 5 additions & 1 deletion app/src/client/utils/chatUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down Expand Up @@ -236,3 +236,7 @@ export const handleChatError = async (
});
}
};

export const shouldRenderChat = (chat: Chat): boolean => {
return chat.chatType !== 'daily_analysis' || chat.shouldShowChat;
};
Loading