Skip to content

Commit

Permalink
Wizard: clear compliance data when switching between types
Browse files Browse the repository at this point in the history
When switching between openscap and insights compliance, clear the data
so the profile information isn't showing anymore.
  • Loading branch information
croissanne authored and regexowl committed Sep 25, 2024
1 parent 4c6d277 commit cbb9598
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/Components/CreateImageWizard/steps/Oscap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ import {
} from '../../../../constants';
import { imageBuilderApi } from '../../../../store/enhancedImageBuilderApi';
import { useAppDispatch, useAppSelector } from '../../../../store/hooks';
import { useGetOscapCustomizationsQuery } from '../../../../store/imageBuilderApi';
import {
ComplianceType,
selectComplianceProfileID,
changeCompliance,
changeComplianceType,
changeEnabledServices,
changeMaskedServices,
changeDisabledServices,
removePackage,
changeFileSystemConfigurationType,
changeKernelAppend,
selectDistribution,
selectComplianceType,
} from '../../../../store/wizardSlice';
Expand All @@ -32,12 +41,21 @@ const OscapStep = () => {
const dispatch = useAppDispatch();
const complianceEnabled = useFlag('image-builder.compliance.enabled');
const complianceType = useAppSelector(selectComplianceType);
const profileID = useAppSelector(selectComplianceProfileID);
const prefetchOscapProfile = imageBuilderApi.usePrefetch(
'getOscapProfiles',
{}
);
const { isProd } = useGetEnvironment();
const release = useAppSelector(selectDistribution);
const { data: currentProfileData } = useGetOscapCustomizationsQuery(
{
distribution: release,
// @ts-ignore if openScapProfile is undefined the query is going to get skipped
profile: profileID,
},
{ skip: !profileID }
);

useEffect(() => {
prefetchOscapProfile({ distribution: release });
Expand All @@ -46,6 +64,29 @@ const OscapStep = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handleTypeChange = (complianceType: string) => {
dispatch(changeComplianceType(complianceType as ComplianceType));

// Avoid showing profile information when switching between types by
// clearing the compliance data.
dispatch(
changeCompliance({
profileID: undefined,
policyID: undefined,
policyTitle: undefined,
})
);
const pkgs = currentProfileData?.packages || [];
for (const pkg of pkgs) {
dispatch(removePackage(pkg));
}
dispatch(changeFileSystemConfigurationType('automatic'));
dispatch(changeEnabledServices([]));
dispatch(changeMaskedServices([]));
dispatch(changeDisabledServices([]));
dispatch(changeKernelAppend(''));
};

return (
<Form>
<Title headingLevel="h1" size="xl">
Expand All @@ -58,18 +99,14 @@ const OscapStep = () => {
label="OpenSCAP"
name="oscap-radio-openscap"
isChecked={complianceType === 'openscap'}
onChange={() =>
dispatch(changeComplianceType('openscap' as ComplianceType))
}
onChange={() => handleTypeChange('openscap')}
/>
<Radio
id="openscap radio compliance type"
label="Insights compliance"
name="oscap-radio-compliance"
isChecked={complianceType === 'compliance'}
onChange={() =>
dispatch(changeComplianceType('compliance' as ComplianceType))
}
onChange={() => handleTypeChange('compliance')}
/>
</FormGroup>
)}
Expand Down

0 comments on commit cbb9598

Please sign in to comment.