Skip to content

Commit 5159136

Browse files
committed
fix(url-state): clear log tab on all close paths + trim KB search
1 parent 65082c1 commit 5159136

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ export function KnowledgeBase({
298298
// doesn't refetch on every keystroke. Changing the search resets pagination.
299299
const handleSearchChange = useCallback(
300300
(newQuery: string) => {
301-
const next = newQuery.length > 0 ? newQuery : null
301+
const trimmed = newQuery.trim()
302+
const next = trimmed.length > 0 ? trimmed : null
302303
setDocumentFilters(
303304
{ q: next },
304305
next === null ? undefined : { limitUrlUpdates: debounce(300) }

apps/sim/app/workspace/[workspaceId]/logs/logs.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,24 @@ export default function Logs() {
422422
const handleCloseSidebar = useCallback(() => {
423423
dispatch({ type: 'CLOSE_SIDEBAR' })
424424
activeLogTabRef.current = 'overview'
425-
// Strip `tab` from the URL (back to the default) so reopening another log
426-
// starts on the overview tab instead of inheriting the closed log's tab.
427-
setLogDetailsTab(null)
428-
}, [setLogDetailsTab])
425+
}, [])
426+
427+
/**
428+
* Strip the `tab` param whenever the detail panel transitions from open to
429+
* closed — by the X button, toggling the same row, or the keyboard — so
430+
* reopening another log starts on overview rather than inheriting the closed
431+
* log's tab. Guarded on a prior-open ref so an initial deep-linked `?tab=` is
432+
* preserved (the panel isn't open yet on first mount).
433+
*/
434+
const wasSidebarOpenRef = useRef(false)
435+
useEffect(() => {
436+
if (isSidebarOpen) {
437+
wasSidebarOpenRef.current = true
438+
} else if (wasSidebarOpenRef.current) {
439+
wasSidebarOpenRef.current = false
440+
setLogDetailsTab(null)
441+
}
442+
}, [isSidebarOpen, setLogDetailsTab])
429443

430444
const handleActiveTabChange = useCallback((tab: string) => {
431445
activeLogTabRef.current = tab

0 commit comments

Comments
 (0)