fix: back btn navigation on first load (#4405)

* fix: back btn navigation on first load

* fix: remove console logs

* chore: refactor the logic to a function and added code comments
This commit is contained in:
Vikrant Gupta 2024-01-22 14:47:25 +05:30 committed by GitHub
parent 00e97fa401
commit 255b3dd3b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 1 deletions

View File

@ -279,6 +279,18 @@ function DateTimeSelection({
setRefreshButtonHidden(updatedTime === 'custom');
updateTimeInterval(updatedTime, [preStartTime, preEndTime]);
if (updatedTime !== 'custom') {
const { minTime, maxTime } = GetMinMax(updatedTime);
urlQuery.set(QueryParams.startTime, minTime.toString());
urlQuery.set(QueryParams.endTime, maxTime.toString());
} else {
urlQuery.set(QueryParams.startTime, preStartTime.toString());
urlQuery.set(QueryParams.endTime, preEndTime.toString());
}
const generatedUrl = `${location.pathname}?${urlQuery.toString()}`;
history.replace(generatedUrl);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [location.pathname, updateTimeInterval, globalTimeLoading]);

View File

@ -25,6 +25,7 @@ import {
parseQueryIntoPageSize,
parseQueryIntoSelectedTags,
parseSelectedFilter,
stripTimestampsFromQuery,
} from './util';
export const GetInitialTraceFilter = (
@ -113,8 +114,11 @@ export const GetInitialTraceFilter = (
);
if (response.payload && !isSelectionSkipped.currentValue) {
/** this is required as now we have timestamps updated in date time selection component
* so for initial filters we need to strip timestamps and check for initial load
*/
const diff =
query.length === 0
stripTimestampsFromQuery(query).length === 0
? traces.filterToFetchData
: xor(traces.filterToFetchData, getFilterToFetchData.currentValue);

View File

@ -86,3 +86,6 @@ export const getFilter = (data: GetFilterPayload): TraceReducer['filter'] => {
return filter;
};
export const stripTimestampsFromQuery = (query: string): string =>
query.replace(/(\?|&)startTime=\d+/, '').replace(/&endTime=\d+/, '');