Skip to content

Commit

Permalink
Refactor MetricTimespanProvider to accept location prop for improved …
Browse files Browse the repository at this point in the history
…URL handling
  • Loading branch information
hervedombya committed Dec 11, 2024
1 parent 62aef0b commit f956f92
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/lib/components/linetemporalchart/MetricTimespanProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import React from 'react';
import { useEffect, useState, createContext, useContext } from 'react';
import { useLocation } from 'react-router-dom';
import { QueryTimeSpan } from '../constants';
import { queryTimeSpansCodes } from '../constants';
import { createContext, useContext, useEffect, useState } from 'react';
import { QueryTimeSpan, queryTimeSpansCodes } from '../constants';
export const MetricsTimeSpanContext = createContext<QueryTimeSpan | null>(null);
export const MetricsTimeSpanProvider = ({
children,
location,
}: {
children: JSX.Element;
location?: Location;
}) => {
// the default timespan is the last 24h
const [queryTimeSpanCode, setQueryTimeSpanCode] = useState(
queryTimeSpansCodes[1],
);
const urlSearchParams = new URLSearchParams(useLocation().search);
const urlSearchParams = new URLSearchParams(location?.search);
const queryTimeSpan = urlSearchParams.get('from');
// Sync url timespan to local timespan
useEffect(() => {
Expand Down

0 comments on commit f956f92

Please sign in to comment.