mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 12:39:02 +08:00
fix: relative time param from the url not respected (#5545)
* fix: relative time param from the url not respected * chore: added code comments and the priorities of the params * fix: added validity checks for the relativeTime in the url
This commit is contained in:
parent
d60daef171
commit
05bd6d52f1
@ -23,7 +23,7 @@ import NewExplorerCTA from 'container/NewExplorerCTA';
|
|||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
||||||
import useUrlQuery from 'hooks/useUrlQuery';
|
import useUrlQuery from 'hooks/useUrlQuery';
|
||||||
import GetMinMax from 'lib/getMinMax';
|
import GetMinMax, { isValidTimeFormat } from 'lib/getMinMax';
|
||||||
import getTimeString from 'lib/getTimeString';
|
import getTimeString from 'lib/getTimeString';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import { isObject } from 'lodash-es';
|
import { isObject } from 'lodash-es';
|
||||||
@ -73,6 +73,7 @@ function DateTimeSelection({
|
|||||||
const urlQuery = useUrlQuery();
|
const urlQuery = useUrlQuery();
|
||||||
const searchStartTime = urlQuery.get('startTime');
|
const searchStartTime = urlQuery.get('startTime');
|
||||||
const searchEndTime = urlQuery.get('endTime');
|
const searchEndTime = urlQuery.get('endTime');
|
||||||
|
const relativeTimeFromUrl = urlQuery.get(QueryParams.relativeTime);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [enableAbsoluteTime, setEnableAbsoluteTime] = useState(false);
|
const [enableAbsoluteTime, setEnableAbsoluteTime] = useState(false);
|
||||||
const [isValidteRelativeTime, setIsValidteRelativeTime] = useState(false);
|
const [isValidteRelativeTime, setIsValidteRelativeTime] = useState(false);
|
||||||
@ -404,9 +405,18 @@ function DateTimeSelection({
|
|||||||
time: Time,
|
time: Time,
|
||||||
currentRoute: string,
|
currentRoute: string,
|
||||||
): Time | CustomTimeType => {
|
): Time | CustomTimeType => {
|
||||||
|
// if the relativeTime param is present in the url give top most preference to the same
|
||||||
|
// if the relativeTime param is not valid then move to next preference
|
||||||
|
if (relativeTimeFromUrl != null && isValidTimeFormat(relativeTimeFromUrl)) {
|
||||||
|
return relativeTimeFromUrl as Time;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the startTime and endTime params are present in the url give next preference to the them.
|
||||||
if (searchEndTime !== null && searchStartTime !== null) {
|
if (searchEndTime !== null && searchStartTime !== null) {
|
||||||
return 'custom';
|
return 'custom';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if nothing is present in the url for time range then rely on the local storage values
|
||||||
if (
|
if (
|
||||||
(localstorageEndTime === null || localstorageStartTime === null) &&
|
(localstorageEndTime === null || localstorageStartTime === null) &&
|
||||||
time === 'custom'
|
time === 'custom'
|
||||||
@ -414,6 +424,7 @@ function DateTimeSelection({
|
|||||||
return getDefaultOption(currentRoute);
|
return getDefaultOption(currentRoute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if not present in the local storage as well then rely on the defaults set for the page
|
||||||
if (OLD_RELATIVE_TIME_VALUES.indexOf(time) > -1) {
|
if (OLD_RELATIVE_TIME_VALUES.indexOf(time) > -1) {
|
||||||
return convertOldTimeToNewValidCustomTimeFormat(time);
|
return convertOldTimeToNewValidCustomTimeFormat(time);
|
||||||
}
|
}
|
||||||
@ -448,7 +459,11 @@ function DateTimeSelection({
|
|||||||
|
|
||||||
setRefreshButtonHidden(updatedTime === 'custom');
|
setRefreshButtonHidden(updatedTime === 'custom');
|
||||||
|
|
||||||
|
if (updatedTime !== 'custom') {
|
||||||
|
updateTimeInterval(updatedTime);
|
||||||
|
} else {
|
||||||
updateTimeInterval(updatedTime, [preStartTime, preEndTime]);
|
updateTimeInterval(updatedTime, [preStartTime, preEndTime]);
|
||||||
|
}
|
||||||
|
|
||||||
if (updatedTime !== 'custom') {
|
if (updatedTime !== 'custom') {
|
||||||
urlQuery.delete('startTime');
|
urlQuery.delete('startTime');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user