mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
Fix: Policies page: Browser back button doesn't work as expected (#43082)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #36643 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] QA'd all new/changed functionality manually
This commit is contained in:
parent
4f9c908102
commit
f465f47bbf
3 changed files with 24 additions and 4 deletions
1
changes/36643-fix-back-button-policies-reports
Normal file
1
changes/36643-fix-back-button-policies-reports
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Fixed browser back button requiring an extra click to leave the Policies and Reports pages.
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
// TODO: make 'queryParams', 'router', and 'tableQueryData' dependencies stable (aka, memoized)
|
||||
import React, { useCallback, useContext, useEffect, useState } from "react";
|
||||
import React, {
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useQuery, useQueryClient } from "react-query";
|
||||
import { InjectedRouter } from "react-router/lib/Router";
|
||||
import PATHS from "router/paths";
|
||||
|
|
@ -223,6 +229,8 @@ const ManagePolicyPage = ({
|
|||
: null;
|
||||
})();
|
||||
|
||||
const isFirstNavigation = useRef(true);
|
||||
|
||||
// Needs update on location change or table state might not match URL
|
||||
const [searchQuery, setSearchQuery] = useState(initialSearchQuery);
|
||||
const [
|
||||
|
|
@ -496,7 +504,12 @@ const ManagePolicyPage = ({
|
|||
queryParams: { ...queryParams, ...newQueryParams },
|
||||
});
|
||||
|
||||
router?.push(locationPath);
|
||||
if (isFirstNavigation.current) {
|
||||
isFirstNavigation.current = false;
|
||||
router?.replace(locationPath);
|
||||
} else {
|
||||
router?.push(locationPath);
|
||||
}
|
||||
},
|
||||
[
|
||||
isRouteOk,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* eslint-disable react/prop-types */
|
||||
import React, { useContext, useCallback, useMemo } from "react";
|
||||
import React, { useContext, useCallback, useMemo, useRef } from "react";
|
||||
import { InjectedRouter } from "react-router";
|
||||
import { Row } from "react-table";
|
||||
import { SingleValue } from "react-select-5";
|
||||
|
|
@ -97,6 +97,7 @@ const QueriesTable = ({
|
|||
isPremiumTier,
|
||||
}: IQueriesTableProps): JSX.Element | null => {
|
||||
const { currentUser, config } = useContext(AppContext);
|
||||
const isFirstNavigation = useRef(true);
|
||||
|
||||
// Functions to avoid race conditions
|
||||
// TODO - confirm these are still necessary
|
||||
|
|
@ -159,7 +160,12 @@ const QueriesTable = ({
|
|||
queryParams: { ...queryParams, ...newQueryParams },
|
||||
});
|
||||
|
||||
router?.push(locationPath);
|
||||
if (isFirstNavigation.current) {
|
||||
isFirstNavigation.current = false;
|
||||
router?.replace(locationPath);
|
||||
} else {
|
||||
router?.push(locationPath);
|
||||
}
|
||||
},
|
||||
[
|
||||
curTargetedPlatformFilter,
|
||||
|
|
|
|||
Loading…
Reference in a new issue