remove hash router related code (#115733)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
9d81fff7e8
commit
e578bf1f68
2 changed files with 9 additions and 49 deletions
|
@ -71,20 +71,6 @@ describe('when on the package policy create page', () => {
|
|||
expect(cancelLink.href).toBe(expectedRouteState.onCancelUrl);
|
||||
expect(cancelButton.href).toBe(expectedRouteState.onCancelUrl);
|
||||
});
|
||||
|
||||
it('should redirect via history when cancel link is clicked', () => {
|
||||
act(() => {
|
||||
cancelLink.click();
|
||||
});
|
||||
expect(testRenderer.mountHistory.location.pathname).toBe('/cancel/url/here');
|
||||
});
|
||||
|
||||
it('should redirect via history when cancel Button (button bar) is clicked', () => {
|
||||
act(() => {
|
||||
cancelButton.click();
|
||||
});
|
||||
expect(testRenderer.mountHistory.location.pathname).toBe('/cancel/url/here');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -22,7 +22,6 @@ import {
|
|||
EuiErrorBoundary,
|
||||
} from '@elastic/eui';
|
||||
import type { EuiStepProps } from '@elastic/eui/src/components/steps/step';
|
||||
import type { ApplicationStart } from 'kibana/public';
|
||||
import { safeLoad } from 'js-yaml';
|
||||
|
||||
import type {
|
||||
|
@ -46,7 +45,6 @@ import { ConfirmDeployAgentPolicyModal } from '../components';
|
|||
import { useIntraAppState, useUIExtension } from '../../../hooks';
|
||||
import { ExtensionWrapper } from '../../../components';
|
||||
import type { PackagePolicyEditExtensionComponentProps } from '../../../types';
|
||||
import { PLUGIN_ID } from '../../../../../../common/constants';
|
||||
import { pkgKeyFromPackageInfo } from '../../../services';
|
||||
|
||||
import { CreatePackagePolicyPageLayout, PostInstallAddAgentModal } from './components';
|
||||
|
@ -76,14 +74,16 @@ interface AddToPolicyParams {
|
|||
}
|
||||
|
||||
export const CreatePackagePolicyPage: React.FunctionComponent = () => {
|
||||
const { notifications } = useStartServices();
|
||||
const {
|
||||
application: { navigateToApp },
|
||||
notifications,
|
||||
} = useStartServices();
|
||||
const {
|
||||
agents: { enabled: isFleetEnabled },
|
||||
} = useConfig();
|
||||
const { params } = useRouteMatch<AddToPolicyParams>();
|
||||
const { getHref, getPath } = useLink();
|
||||
const history = useHistory();
|
||||
const handleNavigateTo = useNavigateToCallback();
|
||||
const routeState = useIntraAppState<CreatePackagePolicyRouteState>();
|
||||
|
||||
const { search } = useLocation();
|
||||
|
@ -254,10 +254,10 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
|
|||
(ev) => {
|
||||
if (routeState && routeState.onCancelNavigateTo) {
|
||||
ev.preventDefault();
|
||||
handleNavigateTo(routeState.onCancelNavigateTo);
|
||||
navigateToApp(...routeState.onCancelNavigateTo);
|
||||
}
|
||||
},
|
||||
[routeState, handleNavigateTo]
|
||||
[routeState, navigateToApp]
|
||||
);
|
||||
|
||||
// Save package policy
|
||||
|
@ -298,15 +298,15 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
|
|||
mappingOptions: routeState.onSaveQueryParams,
|
||||
paramsToApply,
|
||||
});
|
||||
handleNavigateTo([appId, { ...options, path: pathWithQueryString }]);
|
||||
navigateToApp(appId, { ...options, path: pathWithQueryString });
|
||||
} else {
|
||||
handleNavigateTo(routeState.onSaveNavigateTo);
|
||||
navigateToApp(...routeState.onSaveNavigateTo);
|
||||
}
|
||||
} else {
|
||||
history.push(getPath('policy_details', { policyId: agentPolicy!.id }));
|
||||
}
|
||||
},
|
||||
[agentPolicy, getPath, handleNavigateTo, history, routeState]
|
||||
[agentPolicy, getPath, navigateToApp, history, routeState]
|
||||
);
|
||||
|
||||
const onSubmit = useCallback(async () => {
|
||||
|
@ -578,29 +578,3 @@ const IntegrationBreadcrumb: React.FunctionComponent<{
|
|||
});
|
||||
return null;
|
||||
};
|
||||
|
||||
const useNavigateToCallback = () => {
|
||||
const history = useHistory();
|
||||
const {
|
||||
application: { navigateToApp },
|
||||
} = useStartServices();
|
||||
|
||||
return useCallback(
|
||||
(navigateToProps: Parameters<ApplicationStart['navigateToApp']>) => {
|
||||
// If navigateTo appID is `fleet`, then don't use Kibana's navigateTo method, because that
|
||||
// uses BrowserHistory but within fleet, we are using HashHistory.
|
||||
// This temporary workaround hook can be removed once this issue is addressed:
|
||||
// https://github.com/elastic/kibana/issues/70358
|
||||
if (navigateToProps[0] === PLUGIN_ID) {
|
||||
const { path = '', state } = navigateToProps[1] || {};
|
||||
history.push({
|
||||
pathname: path.charAt(0) === '#' ? path.substr(1) : path,
|
||||
state,
|
||||
});
|
||||
}
|
||||
|
||||
return navigateToApp(...navigateToProps);
|
||||
},
|
||||
[history, navigateToApp]
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue