-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add chat history feature This commit adds the following new files: - HistoryItem: A new component for displaying chat history items. - HistoryPanel: A new component for displaying the chat history panel. - HistoryButton: A new component for opening the chat history. - HistoryProviders: A new module containing history provider classes. These changes include functionality to support future enhancements to the chat history feature. * Add translations for chat history in Spanish and French * Update e2e test * Refactor chat history configuration variables Changed variable names to make their functions clearer. * Refactor session state handling Changed to generate session state on the server side. * Add support for chat history feature to bicep * Update workflows, docs, typing * Apply suggestions from code review Co-authored-by: Wassim Chegham <[email protected]> * Revert e2e test change --------- Co-authored-by: Pamela Fox <[email protected]> Co-authored-by: Wassim Chegham <[email protected]> Co-authored-by: Pamela Fox <[email protected]>
- Loading branch information
1 parent
f4f6896
commit be26d31
Showing
33 changed files
with
708 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import uuid | ||
from typing import Union | ||
|
||
|
||
def create_session_id(config_chat_history_browser_enabled: bool) -> Union[str, None]: | ||
if config_chat_history_browser_enabled: | ||
return str(uuid.uuid4()) | ||
return None |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
7 changes: 7 additions & 0 deletions
7
app/frontend/src/components/HistoryButton/HistoryButton.module.css
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,7 @@ | ||
.container { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.375em; | ||
cursor: pointer; | ||
padding: 0.5rem; | ||
} |
22 changes: 22 additions & 0 deletions
22
app/frontend/src/components/HistoryButton/HistoryButton.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,22 @@ | ||
import { History24Regular } from "@fluentui/react-icons"; | ||
import { Button } from "@fluentui/react-components"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import styles from "./HistoryButton.module.css"; | ||
|
||
interface Props { | ||
className?: string; | ||
onClick: () => void; | ||
disabled?: boolean; | ||
} | ||
|
||
export const HistoryButton = ({ className, disabled, onClick }: Props) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<div className={`${styles.container} ${className ?? ""}`}> | ||
<Button icon={<History24Regular />} disabled={disabled} onClick={onClick}> | ||
{t("history.openChatHistory")} | ||
</Button> | ||
</div> | ||
); | ||
}; |
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 @@ | ||
export * from "./HistoryButton"; |
120 changes: 120 additions & 0 deletions
120
app/frontend/src/components/HistoryItem/HistoryItem.module.css
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,120 @@ | ||
.historyItem { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 4px 8px; | ||
border-radius: 6px; | ||
transition: background-color 0.2s; | ||
} | ||
|
||
.historyItem:hover { | ||
background-color: #f3f4f6; | ||
} | ||
|
||
.historyItemButton { | ||
flex-grow: 1; | ||
text-align: left; | ||
padding: 0; | ||
margin-right: 4px; | ||
background: none; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
|
||
.historyItemTitle { | ||
font-size: 1rem; | ||
} | ||
|
||
.deleteIcon { | ||
width: 20px; | ||
height: 20px; | ||
} | ||
|
||
.deleteButton { | ||
opacity: 0; | ||
transition: opacity 0.2s; | ||
background: none; | ||
border: none; | ||
cursor: pointer; | ||
padding: 4px; | ||
border-radius: 9999px; | ||
color: #6b7280; | ||
} | ||
|
||
.historyItem:hover .deleteButton, | ||
.deleteButton:focus { | ||
opacity: 1; | ||
} | ||
|
||
.deleteButton:hover { | ||
color: #111827; | ||
} | ||
|
||
.modalOverlay { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
z-index: 50; | ||
} | ||
|
||
.modalContent { | ||
background-color: white; | ||
padding: 24px; | ||
border-radius: 8px; | ||
box-shadow: | ||
0 4px 6px -1px rgba(0, 0, 0, 0.1), | ||
0 2px 4px -1px rgba(0, 0, 0, 0.06); | ||
max-width: 400px; | ||
width: 100%; | ||
} | ||
|
||
.modalTitle { | ||
font-size: 20px; | ||
font-weight: 600; | ||
margin-top: 0px; | ||
margin-bottom: 16px; | ||
} | ||
|
||
.modalDescription { | ||
margin-top: 0px; | ||
margin-bottom: 16px; | ||
} | ||
|
||
.modalActions { | ||
display: flex; | ||
justify-content: flex-end; | ||
gap: 16px; | ||
} | ||
|
||
.modalCancelButton, | ||
.modalConfirmButton { | ||
padding: 8px 16px; | ||
border-radius: 4px; | ||
font-size: 14px; | ||
font-weight: 500; | ||
cursor: pointer; | ||
} | ||
|
||
.modalCancelButton { | ||
background-color: #f3f4f6; | ||
color: #374151; | ||
} | ||
|
||
.modalConfirmButton { | ||
background-color: #ef4444; | ||
color: white; | ||
} | ||
|
||
.modalCancelButton:hover { | ||
background-color: #e5e7eb; | ||
} | ||
|
||
.modalConfirmButton:hover { | ||
background-color: #dc2626; | ||
} |
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,59 @@ | ||
import { useState, useCallback } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import styles from "./HistoryItem.module.css"; | ||
import { DefaultButton } from "@fluentui/react"; | ||
import { Delete24Regular } from "@fluentui/react-icons"; | ||
|
||
export interface HistoryData { | ||
id: string; | ||
title: string; | ||
timestamp: number; | ||
} | ||
|
||
interface HistoryItemProps { | ||
item: HistoryData; | ||
onSelect: (id: string) => void; | ||
onDelete: (id: string) => void; | ||
} | ||
|
||
export function HistoryItem({ item, onSelect, onDelete }: HistoryItemProps) { | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
|
||
const handleDelete = useCallback(() => { | ||
setIsModalOpen(false); | ||
onDelete(item.id); | ||
}, [item.id, onDelete]); | ||
|
||
return ( | ||
<div className={styles.historyItem}> | ||
<button onClick={() => onSelect(item.id)} className={styles.historyItemButton}> | ||
<div className={styles.historyItemTitle}>{item.title}</div> | ||
</button> | ||
<button onClick={() => setIsModalOpen(true)} className={styles.deleteButton} aria-label="delete this chat history"> | ||
<Delete24Regular className={styles.deleteIcon} /> | ||
</button> | ||
<DeleteHistoryModal isOpen={isModalOpen} onClose={() => setIsModalOpen(false)} onConfirm={handleDelete} /> | ||
</div> | ||
); | ||
} | ||
|
||
function DeleteHistoryModal({ isOpen, onClose, onConfirm }: { isOpen: boolean; onClose: () => void; onConfirm: () => void }) { | ||
if (!isOpen) return null; | ||
const { t } = useTranslation(); | ||
return ( | ||
<div className={styles.modalOverlay}> | ||
<div className={styles.modalContent}> | ||
<h2 className={styles.modalTitle}>{t("history.deleteModalTitle")}</h2> | ||
<p className={styles.modalDescription}>{t("history.deleteModalDescription")}</p> | ||
<div className={styles.modalActions}> | ||
<DefaultButton onClick={onClose} className={styles.modalCancelButton}> | ||
{t("history.cancelLabel")} | ||
</DefaultButton> | ||
<DefaultButton onClick={onConfirm} className={styles.modalConfirmButton}> | ||
{t("history.deleteLabel")} | ||
</DefaultButton> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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 @@ | ||
export * from "./HistoryItem"; |
14 changes: 14 additions & 0 deletions
14
app/frontend/src/components/HistoryPanel/HistoryPanel.module.css
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,14 @@ | ||
.group { | ||
margin-top: 1rem; | ||
} | ||
.groupLabel { | ||
font-size: 0.9rem; | ||
font-weight: bold; | ||
margin-top: 0.5rem; | ||
margin-bottom: 0.2rem; | ||
} | ||
|
||
.footer { | ||
display: flex; | ||
justify-content: space-between; | ||
} |
Oops, something went wrong.