diff --git a/frontend/src/components/App.tsx b/frontend/src/components/App.tsx
index 8fd699a346..bd21a5a93a 100644
--- a/frontend/src/components/App.tsx
+++ b/frontend/src/components/App.tsx
@@ -36,7 +36,7 @@ const ThemeSwitcherWrapper = styled.div`
display: flex;
justify-content: center;
margin-top: 20px;
-`
+`;
const App = () => {
// state = { collapsed: false, isDarkMode: true };
const { switcher, currentTheme, status, themes } = useThemeSwitcher();
@@ -67,7 +67,7 @@ const App = () => {
>
-
+
{
}
const _DateTimeSelector = (props: DateTimeSelectorProps) => {
+ const defaultTime = "15min";
const [customDTPickerVisible, setCustomDTPickerVisible] = useState(false);
- const [timeInterval, setTimeInterval] = useState("15min");
+ const [timeInterval, setTimeInterval] = useState(defaultTime);
const [refreshButtonHidden, setRefreshButtonHidden] = useState(false);
-
const [form_dtselector] = Form.useForm();
+ useEffect(() => {
+ const timeDurationInLocalStorage = localStorage.getItem(
+ LOCAL_STORAGE.METRICS_TIME_IN_DURATION,
+ );
+ const urlParams = new URLSearchParams(window.location.search);
+ const timeInQueryParam = urlParams.get(METRICS_PAGE_QUERY_PARAM.time);
+ if (timeInQueryParam) {
+ setMetricsTime(timeInQueryParam);
+ } else if (timeDurationInLocalStorage) {
+ setMetricsTime(timeDurationInLocalStorage);
+ }
+ }, []);
+
+ const setMetricsTime = (value: string) => {
+ props.history.push({
+ search: `?${METRICS_PAGE_QUERY_PARAM.time}=${value}`,
+ }); //pass time in URL query param for all choices except custom in datetime picker
+ props.updateTimeInterval(value);
+ setTimeInterval(value);
+ };
+
const handleOnSelect = (value: string) => {
if (value === "custom") {
setCustomDTPickerVisible(true);
} else {
- props.history.push({
- search: "?time=" + value,
- }); //pass time in URL query param for all choices except custom in datetime picker
- props.updateTimeInterval(value);
setTimeInterval(value);
setRefreshButtonHidden(false); // for normal intervals, show refresh button
}
@@ -86,8 +104,22 @@ const _DateTimeSelector = (props: DateTimeSelectorProps) => {
};
const handleRefresh = () => {
- props.updateTimeInterval(timeInterval);
+ window.localStorage.setItem(
+ LOCAL_STORAGE.METRICS_TIME_IN_DURATION,
+ timeInterval,
+ );
+ setMetricsTime(timeInterval);
};
+
+ const options = [
+ { value: "custom", label: "Custom" },
+ { value: "15min", label: "Last 15 min" },
+ { value: "30min", label: "Last 30 min" },
+ { value: "1hr", label: "Last 1 hour" },
+ { value: "6hr", label: "Last 6 hour" },
+ { value: "1day", label: "Last 1 day" },
+ { value: "1week", label: "Last 1 week" },
+ ];
if (props.location.pathname.startsWith("/usage-explorer")) {
return null;
} else {
@@ -100,17 +132,12 @@ const _DateTimeSelector = (props: DateTimeSelectorProps) => {
initialValues={{ interval: "15min" }}
style={{ marginTop: 10, marginBottom: 10 }}
>
-
-
-
+
+