Skip to content

Commit

Permalink
[Fleet] Fix uncorrect override of cspm inputs (#208562)
Browse files Browse the repository at this point in the history
## Summary
Fixes a bug introduced with
#206074

When a user selected a single account and switched the deployment method
to `agentless`, it reverted to the organization selection. This PR
removes[ the
code](https://github.com/elastic/kibana/pull/206074/files#diff-a169e222e1116859e05821170ab592903c2943613dfe0035c32a4b9d42e5634fR330)
that was causing the bug.


https://github.com/user-attachments/assets/9007c35b-8454-4f7f-8811-bd39ba7ac99e


⚠️ **Important** ⚠️
One side effect of this change is that when we switch back from
agentless to agent-based, the inputs that were previously hidden and
disabled are now visible but they are disabled. This is not ideal but
offers the user the option to re enable them, but at least doesn't try
to forcefully switch them to initial state, that was the cause of the
current bug.



https://github.com/user-attachments/assets/520e361b-2789-4081-bb91-c75db88d5431


### Checklist
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
criamico and elasticmachine authored Jan 29, 2025
1 parent da41b8b commit e758f32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function validateAgentlessInputs(
supportsAgentless?: boolean | null
) {
if (Array.isArray(packagePolicyInputs)) {
return packagePolicyInputs.forEach((input) => {
packagePolicyInputs.forEach((input) => {
throwIfInputNotAllowed(input.type, input.enabled, supportsAgentless);
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ export function useOnSubmit({
// Used to initialize the package policy once
const isInitializedRef = useRef(false);

// only used to save the initial value of the package policy
const [initialPackagePolicy, setInitialPackagePolicy] = useState<NewPackagePolicy>({
...DEFAULT_PACKAGE_POLICY,
});

const [agentPolicies, setAgentPolicies] = useState<AgentPolicy[]>([]);
// New package policy state
const [packagePolicy, setPackagePolicy] = useState<NewPackagePolicy>({
Expand Down Expand Up @@ -276,19 +271,11 @@ export function useOnSubmit({
DEFAULT_PACKAGE_POLICY.description,
integrationToEnable
);
setInitialPackagePolicy(basePackagePolicy);
updatePackagePolicy(basePackagePolicy);
setIsInitialized(true);
}
init();
}, [
packageInfo,
agentPolicies,
updatePackagePolicy,
integrationToEnable,
isInitialized,
initialPackagePolicy,
]);
}, [packageInfo, agentPolicies, updatePackagePolicy, integrationToEnable, isInitialized]);

useEffect(() => {
if (
Expand Down Expand Up @@ -328,9 +315,9 @@ export function useOnSubmit({
if (isAgentlessSelected && AGENTLESS_DISABLED_INPUTS.includes(input.type)) {
return { ...input, enabled: false };
}
return initialPackagePolicy.inputs[i];
return packagePolicy.inputs[i];
});
}, [initialPackagePolicy?.inputs, isAgentlessSelected, packagePolicy.inputs]);
}, [packagePolicy.inputs, isAgentlessSelected]);

useEffect(() => {
if (prevSetupTechnology !== selectedSetupTechnology) {
Expand Down

0 comments on commit e758f32

Please sign in to comment.