From 43c24336298c7de2ba88af6d1c79e66e44eb7a36 Mon Sep 17 00:00:00 2001 From: Paul Tavares <56442535+paul-tavares@users.noreply.github.com> Date: Mon, 30 Nov 2020 16:11:08 -0500 Subject: [PATCH] [Fleet] Default Integration Policy Configuration section is only shown if no UI extension is registered (#84534) (#84573) * 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 --- .../create_package_policy_page/index.tsx | 23 +++++++++------- .../step_configure_package.tsx | 9 +------ .../step_define_package_policy.tsx | 17 +++++------- .../edit_package_policy_page/index.tsx | 27 ++++++++++--------- .../endpoint_policy_create_extension.tsx | 18 +++++++++++-- 5 files changed, 52 insertions(+), 42 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/index.tsx index a68dbe52555ffe..4b471e661d8806 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/index.tsx @@ -78,7 +78,7 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => { const [isLoadingSecondStep, setIsLoadingSecondStep] = useState(false); // Retrieve agent count - const agentPolicyId = useMemo(() => agentPolicy?.id, [agentPolicy?.id]); + const agentPolicyId = agentPolicy?.id; useEffect(() => { const getAgentCount = async () => { const { data } = await sendGetAgentStatus({ policyId: agentPolicyId }); @@ -331,15 +331,20 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => { updatePackagePolicy={updatePackagePolicy} validationResults={validationResults!} /> - + + {/* Only show the out-of-box configuration step if a UI extension is NOT registered */} + {!ExtensionView && ( + + )} + {/* If an Agent Policy and a package has been selected, then show UI extension (if any) */} - {packagePolicy.policy_id && packagePolicy.package?.name && ExtensionView && ( + {ExtensionView && packagePolicy.policy_id && packagePolicy.package?.name && ( diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/step_configure_package.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/step_configure_package.tsx index 671bc829af82a8..e8c1ef6469925c 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/step_configure_package.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/step_configure_package.tsx @@ -22,7 +22,6 @@ import { Loading } from '../../../components'; import { PackagePolicyValidationResults } from './services'; import { PackagePolicyInputPanel } from './components'; import { CreatePackagePolicyFrom } from './types'; -import { useUIExtension } from '../../../hooks/use_ui_extension'; const findStreamsForInputType = ( inputType: string, @@ -63,12 +62,6 @@ export const StepConfigurePackagePolicy: React.FunctionComponent<{ validationResults, submitAttempted, }) => { - const hasUiExtension = - useUIExtension( - packageInfo.name, - from === 'edit' ? 'package-policy-edit' : 'package-policy-create' - ) !== undefined; - // Configure inputs (and their streams) // Assume packages only export one config template for now const renderConfigureInputs = () => @@ -112,7 +105,7 @@ export const StepConfigurePackagePolicy: React.FunctionComponent<{ })} - ) : hasUiExtension ? null : ( + ) : ( { validationResults={validationResults!} /> - + {/* Only show the out-of-box configuration step if a UI extension is NOT registered */} + {!ExtensionView && ( + + )} - {packagePolicy.policy_id && + {ExtensionView && + packagePolicy.policy_id && packagePolicy.package?.name && - originalPackagePolicy && - ExtensionView && ( + originalPackagePolicy && ( ( - () => { + ({ newPolicy, onChange }) => { + // Fleet will initialize the create form with a default name for the integratin policy, however, + // for endpoint security, we want the user to explicitely type in a name, so we blank it out + // only during 1st component render (thus why the eslint disabled rule below). + useEffect(() => { + onChange({ + isValid: false, + updatedPolicy: { + ...newPolicy, + name: '', + }, + }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + return ( <>