Compliance: refactor clearPackage duplicate
This commit is contained in:
parent
d5877b256c
commit
c026102dd3
3 changed files with 26 additions and 17 deletions
|
|
@ -9,6 +9,8 @@ import {
|
|||
} from '@patternfly/react-core';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { useSelectorHandlers } from './useSelectorHandlers';
|
||||
|
||||
import {
|
||||
PolicyRead,
|
||||
usePoliciesQuery,
|
||||
|
|
@ -91,6 +93,7 @@ const PolicySelector = () => {
|
|||
const hasWslTargetOnly = useHasSpecificTargetOnly('wsl');
|
||||
const dispatch = useAppDispatch();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const { clearCompliancePackages } = useSelectorHandlers();
|
||||
|
||||
const {
|
||||
data: policies,
|
||||
|
|
@ -143,7 +146,7 @@ const PolicySelector = () => {
|
|||
policyTitle: undefined,
|
||||
})
|
||||
);
|
||||
clearOscapPackages(currentProfileData?.packages || []);
|
||||
clearCompliancePackages(currentProfileData?.packages || []);
|
||||
dispatch(changeFileSystemConfigurationType('automatic'));
|
||||
handleServices(undefined);
|
||||
dispatch(clearKernelAppend());
|
||||
|
|
@ -153,7 +156,7 @@ const PolicySelector = () => {
|
|||
oldOscapPackages: string[],
|
||||
newOscapPackages: string[]
|
||||
) => {
|
||||
clearOscapPackages(oldOscapPackages);
|
||||
clearCompliancePackages(oldOscapPackages);
|
||||
|
||||
for (const pkg of newOscapPackages) {
|
||||
dispatch(
|
||||
|
|
@ -166,12 +169,6 @@ const PolicySelector = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const clearOscapPackages = (oscapPackages: string[]) => {
|
||||
for (const pkg of oscapPackages) {
|
||||
dispatch(removePackage(pkg));
|
||||
}
|
||||
};
|
||||
|
||||
const handlePartitions = (oscapPartitions: Filesystem[]) => {
|
||||
dispatch(clearPartitions());
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import {
|
|||
import { TimesIcon } from '@patternfly/react-icons';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { useSelectorHandlers } from './useSelectorHandlers';
|
||||
|
||||
import {
|
||||
useBackendPrefetch,
|
||||
useGetOscapCustomizationsQuery,
|
||||
|
|
@ -42,7 +44,6 @@ import {
|
|||
changeMaskedServices,
|
||||
clearKernelAppend,
|
||||
clearPartitions,
|
||||
removePackage,
|
||||
selectComplianceProfileID,
|
||||
selectComplianceType,
|
||||
selectDistribution,
|
||||
|
|
@ -81,6 +82,7 @@ const ProfileSelector = () => {
|
|||
>([]);
|
||||
const complianceType = useAppSelector(selectComplianceType);
|
||||
const prefetchProfile = useBackendPrefetch('getOscapCustomizations');
|
||||
const { clearCompliancePackages } = useSelectorHandlers();
|
||||
|
||||
const {
|
||||
data: profiles,
|
||||
|
|
@ -181,7 +183,7 @@ const ProfileSelector = () => {
|
|||
policyTitle: undefined,
|
||||
})
|
||||
);
|
||||
clearOscapPackages(currentProfileData?.packages || []);
|
||||
clearCompliancePackages(currentProfileData?.packages || []);
|
||||
dispatch(changeFileSystemConfigurationType('automatic'));
|
||||
handleServices(undefined);
|
||||
dispatch(clearKernelAppend());
|
||||
|
|
@ -193,7 +195,7 @@ const ProfileSelector = () => {
|
|||
oldOscapPackages: string[],
|
||||
newOscapPackages: string[]
|
||||
) => {
|
||||
clearOscapPackages(oldOscapPackages);
|
||||
clearCompliancePackages(oldOscapPackages);
|
||||
|
||||
for (const pkg of newOscapPackages) {
|
||||
dispatch(
|
||||
|
|
@ -206,12 +208,6 @@ const ProfileSelector = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const clearOscapPackages = (oscapPackages: string[]) => {
|
||||
for (const pkg of oscapPackages) {
|
||||
dispatch(removePackage(pkg));
|
||||
}
|
||||
};
|
||||
|
||||
const handlePartitions = (oscapPartitions: Filesystem[]) => {
|
||||
dispatch(clearPartitions());
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
import { useAppDispatch } from '../../../../../store/hooks';
|
||||
import { removePackage } from '../../../../../store/wizardSlice';
|
||||
|
||||
export const useSelectorHandlers = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const clearCompliancePackages = (oscapPackages: string[]) => {
|
||||
for (const pkg of oscapPackages) {
|
||||
dispatch(removePackage(pkg));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
clearCompliancePackages,
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue