Compliance: refactor handleServices duplicate

This commit is contained in:
Anna Vítová 2025-06-05 15:03:20 +02:00 committed by Gianluca Zuccarelli
parent 128abcb98f
commit 9da490ad52
3 changed files with 19 additions and 25 deletions

View file

@ -18,7 +18,6 @@ import {
import { useAppDispatch, useAppSelector } from '../../../../../store/hooks';
import {
Filesystem,
Services,
useGetOscapCustomizationsForPolicyQuery,
useLazyGetOscapCustomizationsForPolicyQuery,
} from '../../../../../store/imageBuilderApi';
@ -26,13 +25,9 @@ import {
addKernelArg,
addPartition,
changeCompliance,
changeDisabledServices,
changeEnabledServices,
changeFileSystemConfigurationType,
changeMaskedServices,
clearKernelAppend,
clearPartitions,
removePackage,
selectCompliancePolicyID,
selectCompliancePolicyTitle,
selectDistribution,
@ -92,7 +87,8 @@ const PolicySelector = () => {
const hasWslTargetOnly = useHasSpecificTargetOnly('wsl');
const dispatch = useAppDispatch();
const [isOpen, setIsOpen] = useState(false);
const { clearCompliancePackages, handlePackages } = useSelectorHandlers();
const { clearCompliancePackages, handlePackages, handleServices } =
useSelectorHandlers();
const {
data: policies,
@ -173,12 +169,6 @@ const PolicySelector = () => {
}
};
const handleServices = (services: Services | undefined) => {
dispatch(changeEnabledServices(services?.enabled || []));
dispatch(changeMaskedServices(services?.masked || []));
dispatch(changeDisabledServices(services?.disabled || []));
};
const handleKernelAppend = (kernelAppend: string | undefined) => {
dispatch(clearKernelAppend());

View file

@ -31,17 +31,12 @@ import {
Filesystem,
OpenScap,
OpenScapProfile,
Services,
} from '../../../../../store/imageBuilderApi';
import {
addKernelArg,
addPackage,
addPartition,
changeCompliance,
changeDisabledServices,
changeEnabledServices,
changeFileSystemConfigurationType,
changeMaskedServices,
clearKernelAppend,
clearPartitions,
selectComplianceProfileID,
@ -82,7 +77,8 @@ const ProfileSelector = () => {
>([]);
const complianceType = useAppSelector(selectComplianceType);
const prefetchProfile = useBackendPrefetch('getOscapCustomizations');
const { clearCompliancePackages, handlePackages } = useSelectorHandlers();
const { clearCompliancePackages, handlePackages, handleServices } =
useSelectorHandlers();
const {
data: profiles,
@ -213,12 +209,6 @@ const ProfileSelector = () => {
}
};
const handleServices = (services: Services | undefined) => {
dispatch(changeEnabledServices(services?.enabled || []));
dispatch(changeMaskedServices(services?.masked || []));
dispatch(changeDisabledServices(services?.disabled || []));
};
const handleKernelAppend = (kernelAppend: string | undefined) => {
dispatch(clearKernelAppend());

View file

@ -1,5 +1,12 @@
import { useAppDispatch } from '../../../../../store/hooks';
import { addPackage, removePackage } from '../../../../../store/wizardSlice';
import { Services } from '../../../../../store/imageBuilderApi';
import {
addPackage,
changeDisabledServices,
changeEnabledServices,
changeMaskedServices,
removePackage,
} from '../../../../../store/wizardSlice';
export const useSelectorHandlers = () => {
const dispatch = useAppDispatch();
@ -28,8 +35,15 @@ export const useSelectorHandlers = () => {
}
};
const handleServices = (services: Services | undefined) => {
dispatch(changeEnabledServices(services?.enabled || []));
dispatch(changeMaskedServices(services?.masked || []));
dispatch(changeDisabledServices(services?.disabled || []));
};
return {
clearCompliancePackages,
handlePackages,
handleServices,
};
};