Remove post-installation redirect for integrations (#103179)

When installation integrations via the browse -> add integration flow in
the integrations UI, we will no longer redirect the user back to the
integration details page.

Closes #100978

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Kyle Pollich 2021-06-28 08:13:41 -04:00 committed by GitHub
parent bfadab6324
commit 96c4350289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@
*/
import type { ReactEventHandler } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Redirect, Route, Switch, useLocation, useParams, useHistory } from 'react-router-dom';
import { Redirect, Route, Switch, useLocation, useParams } from 'react-router-dom';
import styled from 'styled-components';
import {
EuiBetaBadge,
@ -31,12 +31,7 @@ import {
useBreadcrumbs,
useStartServices,
} from '../../../../hooks';
import {
PLUGIN_ID,
INTEGRATIONS_PLUGIN_ID,
INTEGRATIONS_ROUTING_PATHS,
pagePathGetters,
} from '../../../../constants';
import { PLUGIN_ID, INTEGRATIONS_ROUTING_PATHS, pagePathGetters } from '../../../../constants';
import {
useCapabilities,
useGetPackageInfoByKey,
@ -44,11 +39,7 @@ import {
useAgentPolicyContext,
} from '../../../../hooks';
import { pkgKeyFromPackageInfo } from '../../../../services';
import type {
CreatePackagePolicyRouteState,
DetailViewPanelName,
PackageInfo,
} from '../../../../types';
import type { DetailViewPanelName, PackageInfo } from '../../../../types';
import { InstallStatus } from '../../../../types';
import { Error, Loading } from '../../../../components';
import type { WithHeaderLayoutProps } from '../../../../layouts';
@ -89,8 +80,7 @@ export function Detail() {
const { pkgkey, panel } = useParams<DetailParams>();
const { getHref } = useLink();
const hasWriteCapabilites = useCapabilities().write;
const history = useHistory();
const { pathname, search, hash } = useLocation();
const { search } = useLocation();
const queryParams = useMemo(() => new URLSearchParams(search), [search]);
const integration = useMemo(() => queryParams.get('integration'), [queryParams]);
const services = useStartServices();
@ -212,66 +202,19 @@ export function Detail() {
(ev) => {
ev.preventDefault();
// The object below, given to `createHref` is explicitly accessing keys of `location` in order
// to ensure that dependencies to this `useCallback` is set correctly (because `location` is mutable)
const currentPath = history.createHref({
pathname,
search,
hash,
});
const path = pagePathGetters.add_integration_to_policy({
pkgkey,
...(integration ? { integration } : {}),
...(agentPolicyIdFromContext ? { agentPolicyId: agentPolicyIdFromContext } : {}),
})[1];
let redirectToPath: CreatePackagePolicyRouteState['onSaveNavigateTo'] &
CreatePackagePolicyRouteState['onCancelNavigateTo'];
if (agentPolicyIdFromContext) {
redirectToPath = [
PLUGIN_ID,
{
path: `#${
pagePathGetters.policy_details({
policyId: agentPolicyIdFromContext,
})[1]
}`,
},
];
} else {
redirectToPath = [
INTEGRATIONS_PLUGIN_ID,
{
path: currentPath,
},
];
}
const redirectBackRouteState: CreatePackagePolicyRouteState = {
onSaveNavigateTo: redirectToPath,
onCancelNavigateTo: redirectToPath,
onCancelUrl: currentPath,
};
services.application.navigateToApp(PLUGIN_ID, {
// Necessary because of Fleet's HashRouter. Can be changed when
// https://github.com/elastic/kibana/issues/96134 is resolved
path: `#${path}`,
state: redirectBackRouteState,
});
},
[
history,
hash,
pathname,
search,
pkgkey,
integration,
services.application,
agentPolicyIdFromContext,
]
[pkgkey, integration, services.application, agentPolicyIdFromContext]
);
const headerRightContent = useMemo(