-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLEET] New Integration Policy Details page for use in Integrations section #85355
Merged
paul-tavares
merged 12 commits into
elastic:master
from
paul-tavares:task/fleet-82494-integration-policy-detail-page
Dec 9, 2020
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
83a9dab
new UI route to show Edit Package Policy page
paul-tavares f91631a
Package policy List items point to new Integration Policy details page
paul-tavares 0b36a2c
Edit package policy redirects to proper section depending on where it…
paul-tavares f64c17b
Refactor to use common service to generate pkgKey
paul-tavares 2dc614a
add breadcrumb for edit policy under integrations
paul-tavares 73db874
adjust layout for Package Edit from integrations
paul-tavares d91dc79
tests for package policies integration name link
paul-tavares 9e6a08c
Merge remote-tracking branch 'upstream/master' into task/fleet-82494-…
paul-tavares ddb97c4
Throw instead of fake api call
paul-tavares 50cd6ad
Merge remote-tracking branch 'upstream/master' into task/fleet-82494-…
paul-tavares 65d3835
Throw instead of fake api call
paul-tavares e5f7a64
fix handling the API calls
paul-tavares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React, { useState, useEffect, useCallback, useMemo } from 'react'; | ||
import React, { useState, useEffect, useCallback, useMemo, memo } from 'react'; | ||
import { useRouteMatch, useHistory } from 'react-router-dom'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
@@ -45,15 +45,24 @@ import { useUIExtension } from '../../../hooks/use_ui_extension'; | |
import { ExtensionWrapper } from '../../../components/extension_wrapper'; | ||
import { GetOnePackagePolicyResponse } from '../../../../../../common/types/rest_spec'; | ||
import { PackagePolicyEditExtensionComponentProps } from '../../../types'; | ||
import { pkgKeyFromPackageInfo } from '../../../services/pkg_key_from_package_info'; | ||
|
||
export const EditPackagePolicyPage: React.FunctionComponent = () => { | ||
export const EditPackagePolicyPage = memo(() => { | ||
const { | ||
params: { packagePolicyId }, | ||
} = useRouteMatch<{ policyId: string; packagePolicyId: string }>(); | ||
|
||
return <EditPackagePolicyForm packagePolicyId={packagePolicyId} />; | ||
}); | ||
|
||
export const EditPackagePolicyForm = memo<{ | ||
packagePolicyId: string; | ||
from?: CreatePackagePolicyFrom; | ||
}>(({ packagePolicyId, from = 'edit' }) => { | ||
const { notifications } = useStartServices(); | ||
const { | ||
agents: { enabled: isFleetEnabled }, | ||
} = useConfig(); | ||
const { | ||
params: { policyId, packagePolicyId }, | ||
} = useRouteMatch<{ policyId: string; packagePolicyId: string }>(); | ||
const history = useHistory(); | ||
const { getHref, getPath } = useLink(); | ||
|
||
|
@@ -76,16 +85,31 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => { | |
GetOnePackagePolicyResponse['item'] | ||
>(); | ||
|
||
const policyId = agentPolicy?.id ?? ''; | ||
|
||
// Retrieve agent policy, package, and package policy info | ||
useEffect(() => { | ||
const getData = async () => { | ||
setIsLoadingData(true); | ||
setLoadingError(undefined); | ||
try { | ||
const [{ data: agentPolicyData }, { data: packagePolicyData }] = await Promise.all([ | ||
sendGetOneAgentPolicy(policyId), | ||
sendGetOnePackagePolicy(packagePolicyId), | ||
]); | ||
const { | ||
data: packagePolicyData, | ||
error: packagePolicyError, | ||
} = await sendGetOnePackagePolicy(packagePolicyId); | ||
|
||
if (packagePolicyError) { | ||
throw packagePolicyError; | ||
} | ||
|
||
const { data: agentPolicyData, error: agentPolicyError } = await sendGetOneAgentPolicy( | ||
packagePolicyData!.item.policy_id | ||
); | ||
|
||
if (agentPolicyError) { | ||
throw agentPolicyError; | ||
} | ||
|
||
if (agentPolicyData?.item) { | ||
setAgentPolicy(agentPolicyData.item); | ||
} | ||
|
@@ -123,7 +147,7 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => { | |
setPackagePolicy(newPackagePolicy); | ||
if (packagePolicyData.item.package) { | ||
const { data: packageData } = await sendGetPackageInfoByKey( | ||
`${packagePolicyData.item.package.name}-${packagePolicyData.item.package.version}` | ||
pkgKeyFromPackageInfo(packagePolicyData.item.package) | ||
); | ||
if (packageData?.response) { | ||
setPackageInfo(packageData.response); | ||
|
@@ -150,7 +174,7 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => { | |
} | ||
}; | ||
|
||
if (isFleetEnabled) { | ||
if (isFleetEnabled && policyId) { | ||
getAgentCount(); | ||
} | ||
}, [policyId, isFleetEnabled]); | ||
|
@@ -214,8 +238,32 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => { | |
[updatePackagePolicy] | ||
); | ||
|
||
// Cancel url | ||
const cancelUrl = getHref('policy_details', { policyId }); | ||
// Cancel url + Success redirect Path: | ||
// if `from === 'edit'` then it links back to Policy Details | ||
// if `from === 'package-edit'` then it links back to the Integration Policy List | ||
const cancelUrl = useMemo((): string => { | ||
if (packageInfo && policyId) { | ||
return from === 'package-edit' | ||
? getHref('integration_details', { | ||
pkgkey: pkgKeyFromPackageInfo(packageInfo!), | ||
panel: 'policies', | ||
}) | ||
: getHref('policy_details', { policyId }); | ||
} | ||
return '/'; | ||
}, [from, getHref, packageInfo, policyId]); | ||
|
||
const successRedirectPath = useMemo(() => { | ||
if (packageInfo && policyId) { | ||
return from === 'package-edit' | ||
? getPath('integration_details', { | ||
pkgkey: pkgKeyFromPackageInfo(packageInfo!), | ||
panel: 'policies', | ||
}) | ||
: getPath('policy_details', { policyId }); | ||
} | ||
return '/'; | ||
}, [from, getPath, packageInfo, policyId]); | ||
|
||
// Save package policy | ||
const [formState, setFormState] = useState<PackagePolicyFormState>('INVALID'); | ||
|
@@ -237,7 +285,7 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => { | |
} | ||
const { error } = await savePackagePolicy(); | ||
if (!error) { | ||
history.push(getPath('policy_details', { policyId })); | ||
history.push(successRedirectPath); | ||
notifications.toasts.addSuccess({ | ||
title: i18n.translate('xpack.fleet.editPackagePolicy.updatedNotificationTitle', { | ||
defaultMessage: `Successfully updated '{packagePolicyName}'`, | ||
|
@@ -287,7 +335,7 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => { | |
}; | ||
|
||
const layoutProps = { | ||
from: 'edit' as CreatePackagePolicyFrom, | ||
from, | ||
cancelUrl, | ||
agentPolicy, | ||
packageInfo, | ||
|
@@ -363,13 +411,21 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => { | |
error={ | ||
loadingError || | ||
i18n.translate('xpack.fleet.editPackagePolicy.errorLoadingDataMessage', { | ||
defaultMessage: 'There was an error loading this intergration information', | ||
defaultMessage: 'There was an error loading this integration information', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All credit goes to WebStorm 🎉 |
||
}) | ||
} | ||
/> | ||
) : ( | ||
<> | ||
<Breadcrumb policyName={agentPolicy.name} policyId={policyId} /> | ||
{from === 'package' || from === 'package-edit' ? ( | ||
<IntegrationsBreadcrumb | ||
pkgkey={pkgKeyFromPackageInfo(packageInfo)} | ||
pkgTitle={packageInfo.title} | ||
policyName={packagePolicy.name} | ||
/> | ||
) : ( | ||
<PoliciesBreadcrumb policyName={agentPolicy.name} policyId={policyId} /> | ||
)} | ||
{formState === 'CONFIRM' && ( | ||
<ConfirmDeployAgentPolicyModal | ||
agentCount={agentCount} | ||
|
@@ -424,12 +480,21 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => { | |
)} | ||
</CreatePackagePolicyPageLayout> | ||
); | ||
}; | ||
}); | ||
|
||
const Breadcrumb: React.FunctionComponent<{ policyName: string; policyId: string }> = ({ | ||
const PoliciesBreadcrumb: React.FunctionComponent<{ policyName: string; policyId: string }> = ({ | ||
policyName, | ||
policyId, | ||
}) => { | ||
useBreadcrumbs('edit_integration', { policyName, policyId }); | ||
return null; | ||
}; | ||
|
||
const IntegrationsBreadcrumb = memo<{ | ||
pkgTitle: string; | ||
policyName: string; | ||
pkgkey: string; | ||
}>(({ pkgTitle, policyName, pkgkey }) => { | ||
useBreadcrumbs('integration_policy_edit', { policyName, pkgTitle, pkgkey }); | ||
return null; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we expect this to expand to more pages, perhaps a
switch
here so we can be explicit about the default case (iffrom
is something unexpected, perhaps new places added down the road, where the PR forgot to add themselves here).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, agreed a switch will make sense if we add more types for
from
. I don't see that happening at this time and when I get around to introducing the layout that the mocks call for, I hope to revert this in favor of having props that specifically allow for setting things like thecancelUrl
that should be used in the form.