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