From 74217f16a5e3c88a4eef966aca21578759dba717 Mon Sep 17 00:00:00 2001 From: regexowl Date: Tue, 14 Jan 2025 09:36:39 +0100 Subject: [PATCH] Wizard: Properly sort arguments required by OpenSCAP This updates the way the arguments are sorted by whether they're required by a selected OpenSCAP profile. --- .../Kernel/components/KernelArguments.tsx | 81 ++++++++++++------- .../CreateImageWizard/steps/Oscap/Oscap.tsx | 1 - .../utilities/requestMapper.ts | 2 +- src/store/wizardSlice.ts | 15 +--- 4 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/Components/CreateImageWizard/steps/Kernel/components/KernelArguments.tsx b/src/Components/CreateImageWizard/steps/Kernel/components/KernelArguments.tsx index 57a35c156..34b97f089 100644 --- a/src/Components/CreateImageWizard/steps/Kernel/components/KernelArguments.tsx +++ b/src/Components/CreateImageWizard/steps/Kernel/components/KernelArguments.tsx @@ -14,9 +14,12 @@ import { import { PlusCircleIcon, TimesIcon } from '@patternfly/react-icons'; import { useAppDispatch, useAppSelector } from '../../../../../store/hooks'; +import { useGetOscapCustomizationsQuery } from '../../../../../store/imageBuilderApi'; import { addKernelArg, removeKernelArg, + selectComplianceProfileID, + selectDistribution, selectKernel, } from '../../../../../store/wizardSlice'; import { isKernelArgumentValid } from '../../../validators'; @@ -25,9 +28,30 @@ const KernelArguments = () => { const dispatch = useAppDispatch(); const kernelAppend = useAppSelector(selectKernel).append; + const release = useAppSelector(selectDistribution); + const complianceProfileID = useAppSelector(selectComplianceProfileID); + + const { data: oscapProfileInfo } = useGetOscapCustomizationsQuery( + { + distribution: release, + // @ts-ignore if complianceProfileID is undefined the query is going to get skipped, so it's safe here to ignore the linter here + profile: complianceProfileID, + }, + { + skip: !complianceProfileID, + } + ); + const [inputValue, setInputValue] = useState(''); const [errorText, setErrorText] = useState(''); + const requiredByOpenSCAP = kernelAppend.filter((arg) => + oscapProfileInfo?.kernel?.append?.split(' ').includes(arg.name) + ); + const notRequiredByOpenSCAP = kernelAppend.filter( + (arg) => !oscapProfileInfo?.kernel?.append?.split(' ').includes(arg.name) + ); + const onTextInputChange = ( _event: React.FormEvent, value: string @@ -43,7 +67,7 @@ const KernelArguments = () => { isKernelArgumentValid(value) && !kernelAppend.some((arg) => arg.name === value) ) { - dispatch(addKernelArg({ name: value, isRequiredByOpenSCAP: false })); + dispatch(addKernelArg({ name: value })); setInputValue(''); setErrorText(''); } @@ -59,7 +83,7 @@ const KernelArguments = () => { }; const handleAddItem = (e: React.MouseEvent, value: string) => { - dispatch(addKernelArg({ name: value, isRequiredByOpenSCAP: false })); + dispatch(addKernelArg({ name: value })); setInputValue(''); }; return ( @@ -95,36 +119,31 @@ const KernelArguments = () => { {errorText} )} - {kernelAppend.some((arg) => arg.isRequiredByOpenSCAP) && ( - - {kernelAppend - .filter((arg) => arg.isRequiredByOpenSCAP) - .map((arg) => ( - dispatch(removeKernelArg(arg.name))} - isReadOnly - > - {arg.name} - - ))} - - )} + + {requiredByOpenSCAP.map((arg) => ( + dispatch(removeKernelArg(arg.name))} + isReadOnly + > + {arg.name} + + ))} + + - {kernelAppend - .filter((arg) => !arg.isRequiredByOpenSCAP) - .map((arg) => ( - dispatch(removeKernelArg(arg.name))} - > - {arg.name} - - ))} + {notRequiredByOpenSCAP.map((arg) => ( + dispatch(removeKernelArg(arg.name))} + > + {arg.name} + + ))} ); diff --git a/src/Components/CreateImageWizard/steps/Oscap/Oscap.tsx b/src/Components/CreateImageWizard/steps/Oscap/Oscap.tsx index de4e37999..ab36e01de 100644 --- a/src/Components/CreateImageWizard/steps/Oscap/Oscap.tsx +++ b/src/Components/CreateImageWizard/steps/Oscap/Oscap.tsx @@ -238,7 +238,6 @@ const ProfileSelector = () => { dispatch( addKernelArg({ name: kernelArgsArray[arg], - isRequiredByOpenSCAP: true, }) ); } diff --git a/src/Components/CreateImageWizard/utilities/requestMapper.ts b/src/Components/CreateImageWizard/utilities/requestMapper.ts index 923b62a76..08ef497b3 100644 --- a/src/Components/CreateImageWizard/utilities/requestMapper.ts +++ b/src/Components/CreateImageWizard/utilities/requestMapper.ts @@ -320,7 +320,7 @@ function commonRequestToState( append: request.customizations?.kernel?.append ?.split(' ') - .map((arg) => ({ name: arg, isRequiredByOpenSCAP: false })) || [], + .map((arg) => ({ name: arg })) || [], }, timezone: { timezone: request.customizations.timezone?.timezone || '', diff --git a/src/store/wizardSlice.ts b/src/store/wizardSlice.ts index 1241ce2fd..3c7fc0397 100644 --- a/src/store/wizardSlice.ts +++ b/src/store/wizardSlice.ts @@ -63,9 +63,8 @@ type UserSshKeyPayload = { sshKey: string; }; -export type KernelAppendWithAdditionalInfo = { +export type KernelArgument = { name: string; - isRequiredByOpenSCAP: boolean; }; export type wizardState = { @@ -132,7 +131,7 @@ export type wizardState = { disabled: string[]; }; kernel: { - append: KernelAppendWithAdditionalInfo[]; + append: KernelArgument[]; }; locale: Locale; details: { @@ -795,10 +794,7 @@ export const wizardSlice = createSlice({ changeDisabledServices: (state, action: PayloadAction) => { state.services.disabled = action.payload; }, - addKernelArg: ( - state, - action: PayloadAction - ) => { + addKernelArg: (state, action: PayloadAction) => { const existingArgIndex = state.kernel.append.findIndex( (arg) => arg.name === action.payload.name ); @@ -809,10 +805,7 @@ export const wizardSlice = createSlice({ state.kernel.append.push(action.payload); } }, - removeKernelArg: ( - state, - action: PayloadAction - ) => { + removeKernelArg: (state, action: PayloadAction) => { state.kernel.append.splice( state.kernel.append.findIndex((arg) => arg.name === action.payload), 1