Changesets · Branches · Tags · Compare
| Changeset | a8d6112f1f8cb4bb21ebacd03d48fe35af633dc1782b4d101077b55a0b2147c7 |
|---|---|
| Author | amar nath gupta <ang.amarnathgupta@gmail.com> · 2025-07-07 20:23 +05:30 |
| Committer | amar nath gupta <ang.amarnathgupta@gmail.com> · 2025-07-07 20:23 +05:30 |
| Parents | f73f501f39d0 |
1 file changed
modified gui/src/components/History/index.tsx +109 −90
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { SessionMetadata } from "core"; |
| 2 | 2 | import MiniSearch from "minisearch"; |
| 3 | -import React, { | |
| 3 | +import { | |
| 4 | 4 | Fragment, |
| 5 | 5 | useContext, |
| 6 | 6 | useEffect, |
| @@ -10,7 +10,11 @@ | ||
| 10 | 10 | } from "react"; |
| 11 | 11 | import Shortcut from "../gui/Shortcut"; |
| 12 | 12 | |
| 13 | -import { XMarkIcon } from "@heroicons/react/24/solid"; | |
| 13 | +import { | |
| 14 | + ChevronLeftIcon, | |
| 15 | + ChevronRightIcon, | |
| 16 | + XMarkIcon, | |
| 17 | +} from "@heroicons/react/24/solid"; | |
| 14 | 18 | import { useNavigate } from "react-router-dom"; |
| 15 | 19 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 16 | 20 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| @@ -39,10 +43,11 @@ | ||
| 39 | 43 | export function History() { |
| 40 | 44 | const dispatch = useAppDispatch(); |
| 41 | 45 | const navigate = useNavigate(); |
| 42 | - const searchInputRef = React.useRef<HTMLInputElement>(null); | |
| 46 | + const searchInputRef = useRef<HTMLInputElement>(null); | |
| 43 | 47 | const ideMessenger = useContext(IdeMessengerContext); |
| 44 | 48 | |
| 45 | 49 | const [searchTerm, setSearchTerm] = useState(""); |
| 50 | + const [collapsed, setCollapsed] = useState(false); | |
| 46 | 51 | |
| 47 | 52 | const minisearch = useRef<MiniSearch>( |
| 48 | 53 | new MiniSearch({ |
| @@ -76,30 +81,25 @@ | ||
| 76 | 81 | const platform = useMemo(() => getPlatform(), []); |
| 77 | 82 | |
| 78 | 83 | const filteredAndSortedSessions: SessionMetadata[] = useMemo(() => { |
| 79 | - // 1. Exact phrase matching | |
| 80 | 84 | const exactResults = minisearch.search(searchTerm, { |
| 81 | 85 | fuzzy: false, |
| 82 | 86 | }); |
| 83 | 87 | |
| 84 | - // 2. Fuzzy matching with higher tolerance | |
| 85 | 88 | const fuzzyResults = minisearch.search(searchTerm, { |
| 86 | 89 | fuzzy: 0.3, |
| 87 | 90 | }); |
| 88 | 91 | |
| 89 | - // 3. Prefix matching for partial words | |
| 90 | 92 | const prefixResults = minisearch.search(searchTerm, { |
| 91 | 93 | prefix: true, |
| 92 | 94 | fuzzy: 0.2, |
| 93 | 95 | }); |
| 94 | 96 | |
| 95 | - // Combine results, with exact matches having higher priority | |
| 96 | 97 | const allResults = [ |
| 97 | 98 | ...exactResults.map((r) => ({ ...r, priority: 3 })), |
| 98 | 99 | ...fuzzyResults.map((r) => ({ ...r, priority: 2 })), |
| 99 | 100 | ...prefixResults.map((r) => ({ ...r, priority: 1 })), |
| 100 | 101 | ]; |
| 101 | 102 | |
| 102 | - // Remove duplicates while preserving highest priority | |
| 103 | 103 | const uniqueResultsMap = new Map<string, any>(); |
| 104 | 104 | allResults.forEach((result) => { |
| 105 | 105 | const existing = uniqueResultsMap.get(result.id); |
| @@ -107,16 +107,15 @@ | ||
| 107 | 107 | uniqueResultsMap.set(result.id, result); |
| 108 | 108 | } |
| 109 | 109 | }); |
| 110 | - const uniqueResults = Array.from(uniqueResultsMap.values()); | |
| 111 | 110 | |
| 112 | - const sessionIds = uniqueResults | |
| 111 | + const sessionIds = Array.from(uniqueResultsMap.values()) | |
| 113 | 112 | .sort((a, b) => b.priority - a.priority || b.score - a.score) |
| 114 | 113 | .map((result) => result.id); |
| 115 | 114 | |
| 116 | 115 | return allSessionMetadata |
| 117 | - .filter((session) => { | |
| 118 | - return searchTerm === "" || sessionIds.includes(session.sessionId); | |
| 119 | - }) | |
| 116 | + .filter( | |
| 117 | + (session) => searchTerm === "" || sessionIds.includes(session.sessionId), | |
| 118 | + ) | |
| 120 | 119 | .sort( |
| 121 | 120 | (a, b) => |
| 122 | 121 | parseDate(b.dateCreated).getTime() - |
| @@ -136,14 +135,9 @@ | ||
| 136 | 135 | title={`Clear sessions`} |
| 137 | 136 | text={`Are you sure you want to permanently delete all chat sessions, including the current chat session?`} |
| 138 | 137 | onConfirm={async () => { |
| 139 | - // optimistic update | |
| 140 | 138 | dispatch(setAllSessionMetadata([])); |
| 141 | - | |
| 142 | - // actual update + refresh | |
| 143 | 139 | await ideMessenger.request("history/clear", undefined); |
| 144 | 140 | void dispatch(refreshSessionMetadata({})); |
| 145 | - | |
| 146 | - // start a new session | |
| 147 | 141 | dispatch(newSession()); |
| 148 | 142 | navigate(ROUTES.HOME); |
| 149 | 143 | }} |
| @@ -156,11 +150,27 @@ | ||
| 156 | 150 | return ( |
| 157 | 151 | <div |
| 158 | 152 | style={{ fontSize: getFontSize() }} |
| 159 | - className="flex flex-1 flex-col overflow-auto px-1" | |
| 153 | + className={`flex flex-1 flex-col overflow-auto px-1 transition-all duration-300 ${ | |
| 154 | + collapsed ? "w-10" : "w-full" | |
| 155 | + }`} | |
| 160 | 156 | > |
| 161 | 157 | <div className="relative my-2 flex justify-center space-x-2"> |
| 158 | + {/* Collapse Button */} | |
| 159 | + <button | |
| 160 | + onClick={() => setCollapsed(!collapsed)} | |
| 161 | + className="absolute left-2 top-1/2 -translate-y-1/2 transform bg-vsc-background text-vsc-foreground hover:bg-vsc-editor-background p-1 rounded-md" | |
| 162 | + title={collapsed ? "Expand sidebar" : "Collapse sidebar"} | |
| 163 | + > | |
| 164 | + {collapsed ? ( | |
| 165 | + <ChevronRightIcon className="h-5 w-5" /> | |
| 166 | + ) : ( | |
| 167 | + <ChevronLeftIcon className="h-5 w-5" /> | |
| 168 | + )} | |
| 169 | + </button> | |
| 170 | + | |
| 171 | + {/* Search Input */} | |
| 162 | 172 | <input |
| 163 | - className="bg-vsc-input-background text-vsc-foreground flex-1 rounded-md border border-none py-1 pl-2 pr-8 text-base outline-none focus:outline-none" | |
| 173 | + className="bg-vsc-input-background text-vsc-foreground flex-1 rounded-md border border-none py-1 pl-8 pr-8 text-base outline-none focus:outline-none" | |
| 164 | 174 | ref={searchInputRef} |
| 165 | 175 | placeholder="Search past sessions" |
| 166 | 176 | type="text" |
| @@ -179,79 +189,88 @@ | ||
| 179 | 189 | /> |
| 180 | 190 | )} |
| 181 | 191 | </div> |
| 182 | - <div className="thin-scrollbar flex flex-1 flex-col overflow-y-auto pr-4"> | |
| 183 | - {filteredAndSortedSessions.length === 0 && ( | |
| 184 | - <div className="m-3 text-center"> | |
| 185 | - {isSessionMetadataLoading ? ( | |
| 186 | - "Loading Sessions..." | |
| 187 | - ) : ( | |
| 188 | - <> | |
| 189 | - No past sessions found. To start a new session, either click the | |
| 190 | - "+" button or use the keyboard shortcut:{" "} | |
| 191 | - <Shortcut>meta L</Shortcut> | |
| 192 | - </> | |
| 192 | + | |
| 193 | + {!collapsed && ( | |
| 194 | + <> | |
| 195 | + <div className="thin-scrollbar flex flex-1 flex-col overflow-y-auto pr-4"> | |
| 196 | + {filteredAndSortedSessions.length === 0 && ( | |
| 197 | + <div className="m-3 text-center"> | |
| 198 | + {isSessionMetadataLoading ? ( | |
| 199 | + "Loading Sessions..." | |
| 200 | + ) : ( | |
| 201 | + <> | |
| 202 | + No past sessions found. To start a new session, either click the | |
| 203 | + "+" button or use the keyboard shortcut: <Shortcut>meta L</Shortcut> | |
| 204 | + </> | |
| 205 | + )} | |
| 206 | + </div> | |
| 193 | 207 | )} |
| 208 | + | |
| 209 | + <table className="flex flex-1 flex-col"> | |
| 210 | + <tbody> | |
| 211 | + {filteredAndSortedSessions.map((session, index) => { | |
| 212 | + const prevDate = | |
| 213 | + index > 0 | |
| 214 | + ? parseDate(filteredAndSortedSessions[index - 1].dateCreated) | |
| 215 | + : earlier; | |
| 216 | + const date = parseDate(session.dateCreated); | |
| 217 | + | |
| 218 | + return ( | |
| 219 | + <Fragment key={index}> | |
| 220 | + {index === 0 && date > yesterday && ( | |
| 221 | + <tr className={HEADER_CLASS}> | |
| 222 | + <td colSpan={3}>Today</td> | |
| 223 | + </tr> | |
| 224 | + )} | |
| 225 | + {date < yesterday && | |
| 226 | + date > lastWeek && | |
| 227 | + prevDate > yesterday && ( | |
| 228 | + <tr className={HEADER_CLASS}> | |
| 229 | + <td colSpan={3}>This Week</td> | |
| 230 | + </tr> | |
| 231 | + )} | |
| 232 | + {date < lastWeek && | |
| 233 | + date > lastMonth && | |
| 234 | + prevDate > lastWeek && ( | |
| 235 | + <tr className={HEADER_CLASS}> | |
| 236 | + <td colSpan={3}>This Month</td> | |
| 237 | + </tr> | |
| 238 | + )} | |
| 239 | + {date < lastMonth && prevDate > lastMonth && ( | |
| 240 | + <tr className={HEADER_CLASS}> | |
| 241 | + <td colSpan={3}>Older</td> | |
| 242 | + </tr> | |
| 243 | + )} | |
| 244 | + | |
| 245 | + <HistoryTableRow | |
| 246 | + sessionMetadata={session} | |
| 247 | + date={date} | |
| 248 | + index={index} | |
| 249 | + /> | |
| 250 | + </Fragment> | |
| 251 | + ); | |
| 252 | + })} | |
| 253 | + </tbody> | |
| 254 | + </table> | |
| 194 | 255 | </div> |
| 195 | - )} | |
| 196 | 256 | |
| 197 | - <table className="flex flex-1 flex-col"> | |
| 198 | - <tbody className=""> | |
| 199 | - {filteredAndSortedSessions.map((session, index) => { | |
| 200 | - const prevDate = | |
| 201 | - index > 0 | |
| 202 | - ? parseDate(filteredAndSortedSessions[index - 1].dateCreated) | |
| 203 | - : earlier; | |
| 204 | - const date = parseDate(session.dateCreated); | |
| 205 | - return ( | |
| 206 | - <Fragment key={index}> | |
| 207 | - {index === 0 && date > yesterday && ( | |
| 208 | - <tr className={HEADER_CLASS}> | |
| 209 | - <td colSpan={3}>Today</td> | |
| 210 | - </tr> | |
| 211 | - )} | |
| 212 | - {date < yesterday && | |
| 213 | - date > lastWeek && | |
| 214 | - prevDate > yesterday && ( | |
| 215 | - <div className={HEADER_CLASS}> | |
| 216 | - <td colSpan={3}>This Week</td> | |
| 217 | - </div> | |
| 218 | - )} | |
| 219 | - {date < lastWeek && | |
| 220 | - date > lastMonth && | |
| 221 | - prevDate > lastWeek && ( | |
| 222 | - <div className={HEADER_CLASS}> | |
| 223 | - <td colSpan={3}>This Month</td> | |
| 224 | - </div> | |
| 225 | - )} | |
| 226 | - {date < lastMonth && prevDate > lastMonth && ( | |
| 227 | - <div className={HEADER_CLASS}> | |
| 228 | - <td colSpan={3}>Older</td> | |
| 229 | - </div> | |
| 230 | - )} | |
| 231 | - | |
| 232 | - <HistoryTableRow | |
| 233 | - sessionMetadata={session} | |
| 234 | - date={date} | |
| 235 | - index={index} | |
| 236 | - /> | |
| 237 | - </Fragment> | |
| 238 | - ); | |
| 239 | - })} | |
| 240 | - </tbody> | |
| 241 | - </table> | |
| 242 | - </div> | |
| 243 | - <div className="flex flex-col items-end justify-center border-0 border-t border-solid border-gray-400 px-2 py-1.5 text-sm"> | |
| 244 | - <i | |
| 245 | - className="" | |
| 246 | - data-testid="history-sessions-note" | |
| 247 | - >{`Data is saved in ${platform === "windows" ? "%USERPROFILE%/.continue" : "~/.continue/sessions"}`}</i> | |
| 248 | - <span | |
| 249 | - className="cursor-pointer text-xs text-gray-400 hover:underline" | |
| 250 | - onClick={showClearSessionsDialog} | |
| 251 | - > | |
| 252 | - Clear session history | |
| 253 | - </span> | |
| 254 | - </div> | |
| 257 | + <div className="flex flex-col items-end justify-center border-0 border-t border-solid border-gray-400 px-2 py-1.5 text-sm"> | |
| 258 | + <i data-testid="history-sessions-note"> | |
| 259 | + {`Data is saved in ${ | |
| 260 | + platform === "windows" | |
| 261 | + ? "%USERPROFILE%/.continue" | |
| 262 | + : "~/.continue/sessions" | |
| 263 | + }`} | |
| 264 | + </i> | |
| 265 | + <span | |
| 266 | + className="cursor-pointer text-xs text-gray-400 hover:underline" | |
| 267 | + onClick={showClearSessionsDialog} | |
| 268 | + > | |
| 269 | + Clear session history | |
| 270 | + </span> | |
| 271 | + </div> | |
| 272 | + </> | |
| 273 | + )} | |
| 255 | 274 | </div> |
| 256 | 275 | ); |
| 257 | 276 | } |