Skip to content

Commit c106ace

Browse files
authored
fix(url): Expand search tab when query parameter changes (fixes y-scope#392). (y-scope#396)
1 parent 4ddd1f5 commit c106ace

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/components/AppController.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import {
2424
* Handles hash change events by updating the application state based on the URL hash parameters.
2525
*/
2626
const handleHashChange = () => {
27-
updateViewHashParams();
28-
if (updateQueryHashParams()) {
27+
const isViewQueryModified = updateViewHashParams();
28+
const isQueryParamsModified = updateQueryHashParams();
29+
30+
if (isQueryParamsModified || isViewQueryModified) {
2931
const {setActiveTabName} = useUiStore.getState();
3032
setActiveTabName(TAB_NAME.SEARCH);
3133
const {startQuery} = useQueryStore.getState();

src/utils/url/urlHash.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ const getCursorFromHashParams = ({isPrettified, logEventNum, timestamp}: {
103103
/**
104104
* Updates view-related states from URL hash parameters.
105105
* NOTE: this may modify the URL parameters.
106+
*
107+
* @return Whether any query-related parameters were modified.
106108
*/
107109
const updateViewHashParams = () => {
108110
const {isPrettified, logEventNum, query, timestamp} = getWindowUrlHashParams();
@@ -120,22 +122,26 @@ const updateViewHashParams = () => {
120122
filterLogs,
121123
} = useViewStore.getState();
122124

125+
let isQueryModified = false;
123126
if (query !== kqlFilter) {
124127
if (kqlFilter === kqlFilterInput) {
125128
setKqlFilterInput(query);
126129
}
127130
setKqlFilter(query);
128131
filterLogs();
132+
isQueryModified = true;
129133
}
130134

131135
const cursor = getCursorFromHashParams({isPrettified, logEventNum, timestamp});
132136
if (null === cursor) {
133137
// If no cursor was set, we can return early.
134-
return;
138+
return isQueryModified;
135139
}
136140

137141
const {loadPageByCursor} = useViewStore.getState();
138142
loadPageByCursor(cursor).catch(handleErrorWithNotification);
143+
144+
return isQueryModified;
139145
};
140146

141147
/**

0 commit comments

Comments
 (0)