Skip to content

Commit

Permalink
Remove post-installation redirect for integrations (#103179) (#103473)
Browse files Browse the repository at this point in the history
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 <[email protected]>

Co-authored-by: Kyle Pollich <[email protected]>
  • Loading branch information
kibanamachine and kpollich authored Jun 28, 2021
1 parent 61dd3db commit dfda99b
Showing 1 changed file with 5 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,24 +31,15 @@ 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,
useLink,
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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit dfda99b

Please sign in to comment.