-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update markdown component + create avatar component + refactor (…
…#36832) /ok-to-test tags="@tag.Anvil" <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced the `Avatar` component for displaying user avatars. - Added the `Markdown` component for rendering Markdown content with GitHub Flavored Markdown support. - Enhanced `AIChat` component with a new modular input system and improved message display. - **Bug Fixes** - Updated CSS for better styling consistency across components. - **Refactor** - Removed outdated components (`ChatDescriptionModal` and `ThreadMessage`) to streamline the codebase. - Simplified the structure of `AIChat` by incorporating new components. - **Documentation** - Updated Storybook stories for `AIChat`, `Avatar`, and `Markdown` components to showcase new features. <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11320929997> > Commit: db2bc5c > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11320929997&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Anvil` > Spec: > <hr>Mon, 14 Oct 2024 04:42:54 UTC <!-- end of auto-generated comment: Cypress test results -->
- Loading branch information
Showing
52 changed files
with
1,011 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
...gn-system/widgets/src/components/AIChat/src/ChatDescriptionModal/ChatDescriptionModal.tsx
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
...nt/packages/design-system/widgets/src/components/AIChat/src/ChatDescriptionModal/index.ts
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...nt/packages/design-system/widgets/src/components/AIChat/src/ChatDescriptionModal/types.ts
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
app/client/packages/design-system/widgets/src/components/AIChat/src/ChatHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useState } from "react"; | ||
import { | ||
Avatar, | ||
Button, | ||
Flex, | ||
Modal, | ||
ModalBody, | ||
ModalContent, | ||
ModalHeader, | ||
Text, | ||
} from "@appsmith/wds"; | ||
|
||
import styles from "./styles.module.css"; | ||
|
||
// this value might come from props in future. So keeping a temporary value here. | ||
const LOGO = | ||
"https://app.appsmith.com/static/media/appsmith_logo_square.3867b1959653dabff8dc.png"; | ||
|
||
export const ChatHeader: React.FC<{ | ||
chatTitle?: string; | ||
username: string; | ||
chatDescription?: string; | ||
}> = ({ chatDescription, chatTitle, username }) => { | ||
const [isChatDescriptionModalOpen, setIsChatDescriptionModalOpen] = | ||
useState(false); | ||
|
||
return ( | ||
<> | ||
<div className={styles.header}> | ||
<Flex alignItems="center" gap="spacing-2"> | ||
<Flex alignItems="center" gap="spacing-3"> | ||
<Avatar label="Appsmith AI" size="large" src={LOGO} /> | ||
<Text fontWeight={600} size="subtitle"> | ||
{chatTitle} | ||
</Text> | ||
</Flex> | ||
<Button | ||
icon="info-square-rounded" | ||
onPress={() => setIsChatDescriptionModalOpen(true)} | ||
variant="ghost" | ||
/> | ||
</Flex> | ||
<Flex alignItems="center" gap="spacing-2"> | ||
<Avatar label={username} /> | ||
<Text data-testid="t--aichat-username" size="body"> | ||
{username} | ||
</Text> | ||
</Flex> | ||
</div> | ||
|
||
<Modal | ||
isOpen={isChatDescriptionModalOpen} | ||
setOpen={setIsChatDescriptionModalOpen} | ||
> | ||
<ModalContent> | ||
<ModalHeader title="Information about the bot" /> | ||
<ModalBody>{chatDescription}</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
}; |
48 changes: 48 additions & 0 deletions
48
app/client/packages/design-system/widgets/src/components/AIChat/src/ChatInputSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from "react"; | ||
import { Flex, ChatInput, Icon, Text } from "@appsmith/wds"; | ||
|
||
const MIN_PROMPT_LENGTH = 3; | ||
|
||
export const ChatInputSection: React.FC<{ | ||
isWaitingForResponse: boolean; | ||
prompt: string; | ||
promptInputPlaceholder?: string; | ||
onPromptChange: (value: string) => void; | ||
onSubmit?: () => void; | ||
}> = ({ | ||
isWaitingForResponse, | ||
onPromptChange, | ||
onSubmit, | ||
prompt, | ||
promptInputPlaceholder, | ||
}) => ( | ||
<Flex | ||
direction="column" | ||
gap="spacing-3" | ||
paddingBottom="spacing-4" | ||
paddingLeft="spacing-6" | ||
paddingRight="spacing-6" | ||
paddingTop="spacing-4" | ||
> | ||
<ChatInput | ||
isLoading={isWaitingForResponse} | ||
isSubmitDisabled={prompt.length < MIN_PROMPT_LENGTH} | ||
onChange={onPromptChange} | ||
onSubmit={onSubmit} | ||
placeholder={promptInputPlaceholder} | ||
value={prompt} | ||
/> | ||
<Flex | ||
alignItems="center" | ||
flexGrow={1} | ||
gap="spacing-1" | ||
justifyContent="center" | ||
> | ||
<Icon name="alert-circle" size="small" /> | ||
<Text color="neutral" size="caption" textAlign="center"> | ||
LLM assistant can make mistakes. Answers should be verified before they | ||
are trusted. | ||
</Text> | ||
</Flex> | ||
</Flex> | ||
); |
53 changes: 53 additions & 0 deletions
53
app/client/packages/design-system/widgets/src/components/AIChat/src/ChatThread.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from "react"; | ||
import { Avatar, Flex, Markdown } from "@appsmith/wds"; | ||
|
||
import styles from "./styles.module.css"; | ||
import type { ChatMessage } from "./types"; | ||
import { AssistantSuggestionButton } from "./AssistantSuggestionButton"; | ||
|
||
export const ChatThread: React.FC<{ | ||
thread: ChatMessage[]; | ||
onApplyAssistantSuggestion?: (suggestion: string) => void; | ||
username: string; | ||
}> = ({ onApplyAssistantSuggestion, thread, username }) => ( | ||
<Flex direction="column" gap="spacing-3" padding="spacing-6"> | ||
{thread.map((message: ChatMessage) => { | ||
const { content, isAssistant, promptSuggestions = [] } = message; | ||
|
||
return ( | ||
<Flex direction={isAssistant ? "row" : "row-reverse"} key={message.id}> | ||
{isAssistant && ( | ||
<div> | ||
<Markdown>{content}</Markdown> | ||
|
||
{promptSuggestions.length > 0 && ( | ||
<Flex | ||
className={styles.suggestions} | ||
gap="spacing-5" | ||
paddingTop="spacing-4" | ||
wrap="wrap" | ||
> | ||
{promptSuggestions.map((suggestion) => ( | ||
<AssistantSuggestionButton | ||
key={suggestion} | ||
// eslint-disable-next-line react-perf/jsx-no-new-function-as-prop | ||
onPress={() => onApplyAssistantSuggestion?.(suggestion)} | ||
> | ||
{suggestion} | ||
</AssistantSuggestionButton> | ||
))} | ||
</Flex> | ||
)} | ||
</div> | ||
)} | ||
{!isAssistant && ( | ||
<Flex direction="row-reverse" gap="spacing-3"> | ||
<Avatar label={username} /> | ||
<div>{content}</div> | ||
</Flex> | ||
)} | ||
</Flex> | ||
); | ||
})} | ||
</Flex> | ||
); |
17 changes: 0 additions & 17 deletions
17
app/client/packages/design-system/widgets/src/components/AIChat/src/ChatTitle/ChatTitle.tsx
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
app/client/packages/design-system/widgets/src/components/AIChat/src/ChatTitle/index.ts
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...ient/packages/design-system/widgets/src/components/AIChat/src/ChatTitle/styles.module.css
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/client/packages/design-system/widgets/src/components/AIChat/src/ChatTitle/types.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.