Skip to content

Commit 7ba6c73

Browse files
authored
[Fleet] Default Integration Policy Configuration section is only shown if no UI extension is registered (#84534)
* Do not render out-of-box integration policy configuration step if a custom UI extension is registered * Remove endpoint specific logic from fleet and move it to UI extension
1 parent 69845cc commit 7ba6c73

File tree

5 files changed

+52
-42
lines changed

5 files changed

+52
-42
lines changed

x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/index.tsx

+14-9
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
7878
const [isLoadingSecondStep, setIsLoadingSecondStep] = useState<boolean>(false);
7979

8080
// Retrieve agent count
81-
const agentPolicyId = useMemo(() => agentPolicy?.id, [agentPolicy?.id]);
81+
const agentPolicyId = agentPolicy?.id;
8282
useEffect(() => {
8383
const getAgentCount = async () => {
8484
const { data } = await sendGetAgentStatus({ policyId: agentPolicyId });
@@ -331,15 +331,20 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
331331
updatePackagePolicy={updatePackagePolicy}
332332
validationResults={validationResults!}
333333
/>
334-
<StepConfigurePackagePolicy
335-
packageInfo={packageInfo}
336-
packagePolicy={packagePolicy}
337-
updatePackagePolicy={updatePackagePolicy}
338-
validationResults={validationResults!}
339-
submitAttempted={formState === 'INVALID'}
340-
/>
334+
335+
{/* Only show the out-of-box configuration step if a UI extension is NOT registered */}
336+
{!ExtensionView && (
337+
<StepConfigurePackagePolicy
338+
packageInfo={packageInfo}
339+
packagePolicy={packagePolicy}
340+
updatePackagePolicy={updatePackagePolicy}
341+
validationResults={validationResults!}
342+
submitAttempted={formState === 'INVALID'}
343+
/>
344+
)}
345+
341346
{/* If an Agent Policy and a package has been selected, then show UI extension (if any) */}
342-
{packagePolicy.policy_id && packagePolicy.package?.name && ExtensionView && (
347+
{ExtensionView && packagePolicy.policy_id && packagePolicy.package?.name && (
343348
<ExtensionWrapper>
344349
<ExtensionView newPolicy={packagePolicy} onChange={handleExtensionViewOnChange} />
345350
</ExtensionWrapper>

x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/step_configure_package.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { Loading } from '../../../components';
2222
import { PackagePolicyValidationResults } from './services';
2323
import { PackagePolicyInputPanel } from './components';
2424
import { CreatePackagePolicyFrom } from './types';
25-
import { useUIExtension } from '../../../hooks/use_ui_extension';
2625

2726
const findStreamsForInputType = (
2827
inputType: string,
@@ -63,12 +62,6 @@ export const StepConfigurePackagePolicy: React.FunctionComponent<{
6362
validationResults,
6463
submitAttempted,
6564
}) => {
66-
const hasUiExtension =
67-
useUIExtension(
68-
packageInfo.name,
69-
from === 'edit' ? 'package-policy-edit' : 'package-policy-create'
70-
) !== undefined;
71-
7265
// Configure inputs (and their streams)
7366
// Assume packages only export one config template for now
7467
const renderConfigureInputs = () =>
@@ -112,7 +105,7 @@ export const StepConfigurePackagePolicy: React.FunctionComponent<{
112105
})}
113106
</EuiFlexGroup>
114107
</>
115-
) : hasUiExtension ? null : (
108+
) : (
116109
<EuiEmptyPrompt
117110
iconType="checkInCircleFilled"
118111
iconColor="secondary"

x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/step_define_package_policy.tsx

+6-11
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,12 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
4747
.sort();
4848

4949
updatePackagePolicy({
50-
name:
51-
// For Endpoint packages, the user must fill in the name, thus we don't attempt to generate
52-
// a default one here.
53-
// FIXME: Improve package policies name uniqueness - https://github.com/elastic/kibana/issues/72948
54-
packageInfo.name !== 'endpoint'
55-
? `${packageInfo.name}-${
56-
pkgPoliciesWithMatchingNames.length
57-
? pkgPoliciesWithMatchingNames[pkgPoliciesWithMatchingNames.length - 1] + 1
58-
: 1
59-
}`
60-
: '',
50+
// FIXME: Improve package policies name uniqueness - https://github.com/elastic/kibana/issues/72948
51+
name: `${packageInfo.name}-${
52+
pkgPoliciesWithMatchingNames.length
53+
? pkgPoliciesWithMatchingNames[pkgPoliciesWithMatchingNames.length - 1] + 1
54+
: 1
55+
}`,
6156
package: {
6257
name: packageInfo.name,
6358
title: packageInfo.title,

x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx

+15-12
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,23 @@ export const EditPackagePolicyPage: React.FunctionComponent = () => {
305305
validationResults={validationResults!}
306306
/>
307307

308-
<StepConfigurePackagePolicy
309-
from={'edit'}
310-
packageInfo={packageInfo}
311-
packagePolicy={packagePolicy}
312-
packagePolicyId={packagePolicyId}
313-
updatePackagePolicy={updatePackagePolicy}
314-
validationResults={validationResults!}
315-
submitAttempted={formState === 'INVALID'}
316-
/>
308+
{/* Only show the out-of-box configuration step if a UI extension is NOT registered */}
309+
{!ExtensionView && (
310+
<StepConfigurePackagePolicy
311+
from={'edit'}
312+
packageInfo={packageInfo}
313+
packagePolicy={packagePolicy}
314+
packagePolicyId={packagePolicyId}
315+
updatePackagePolicy={updatePackagePolicy}
316+
validationResults={validationResults!}
317+
submitAttempted={formState === 'INVALID'}
318+
/>
319+
)}
317320

318-
{packagePolicy.policy_id &&
321+
{ExtensionView &&
322+
packagePolicy.policy_id &&
319323
packagePolicy.package?.name &&
320-
originalPackagePolicy &&
321-
ExtensionView && (
324+
originalPackagePolicy && (
322325
<ExtensionWrapper>
323326
<ExtensionView
324327
policy={originalPackagePolicy}

x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_policy_create_extension.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { memo } from 'react';
7+
import React, { memo, useEffect } from 'react';
88
import { EuiCallOut, EuiSpacer, EuiText } from '@elastic/eui';
99
import { FormattedMessage } from '@kbn/i18n/react';
1010
import { PackagePolicyCreateExtensionComponentProps } from '../../../../../../../fleet/public';
@@ -14,7 +14,21 @@ import { PackagePolicyCreateExtensionComponentProps } from '../../../../../../..
1414
* for use in the Ingest app create / edit package policy
1515
*/
1616
export const EndpointPolicyCreateExtension = memo<PackagePolicyCreateExtensionComponentProps>(
17-
() => {
17+
({ newPolicy, onChange }) => {
18+
// Fleet will initialize the create form with a default name for the integratin policy, however,
19+
// for endpoint security, we want the user to explicitely type in a name, so we blank it out
20+
// only during 1st component render (thus why the eslint disabled rule below).
21+
useEffect(() => {
22+
onChange({
23+
isValid: false,
24+
updatedPolicy: {
25+
...newPolicy,
26+
name: '',
27+
},
28+
});
29+
// eslint-disable-next-line react-hooks/exhaustive-deps
30+
}, []);
31+
1832
return (
1933
<>
2034
<EuiSpacer size="m" />

0 commit comments

Comments
 (0)