-
Notifications
You must be signed in to change notification settings - Fork 5k
Add chat history feature #1988
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
Merged
Merged
Add chat history feature #1988
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f59fce4
Add chat history feature
fujita-h f4b0182
Add translations for chat history in Spanish and French
fujita-h afc8d1b
Update e2e test
pamelafox 063b64c
Refactor chat history configuration variables
fujita-h c6fd15c
Refactor session state handling
fujita-h 99474e8
Add support for chat history feature to bicep
fujita-h 88d4d59
Update workflows, docs, typing
pamelafox 88c1df4
Apply suggestions from code review
pamelafox bc22f15
Revert e2e test change
pamelafox e3caa07
Merge branch 'feat-chat-history' of https://github.com/fujita-h/azure…
pamelafox 291943e
Merge branch 'main' into feat-chat-history
pamelafox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a reasonable addition according to packagephobia and snyk:
https://packagephobia.com/result?p=idb
https://snyk.io/advisor/npm-package/idb