debian-image-builder-frontend/src/Components/CreateImageWizard/steps/Kernel/components/KernelArguments.tsx
regexowl 47b5eb8392 Wizard: Turn required category name into LabelInput prop
This swaps hardcoded value of the required `categoryName` in `LabelInput` for a prop, allowing to customize text for the reuired category independently on the component.
2025-03-31 19:46:52 -05:00

60 lines
1.9 KiB
TypeScript

import React from 'react';
import { FormGroup } from '@patternfly/react-core';
import { useAppSelector } from '../../../../../store/hooks';
import { useGetOscapCustomizationsQuery } from '../../../../../store/imageBuilderApi';
import {
addKernelArg,
removeKernelArg,
selectComplianceProfileID,
selectDistribution,
selectKernel,
} from '../../../../../store/wizardSlice';
import LabelInput from '../../../LabelInput';
import { useKernelValidation } from '../../../utilities/useValidation';
import { isKernelArgumentValid } from '../../../validators';
const KernelArguments = () => {
const kernelAppend = useAppSelector(selectKernel).append;
const stepValidation = useKernelValidation();
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 requiredByOpenSCAP = kernelAppend.filter((arg) =>
oscapProfileInfo?.kernel?.append?.split(' ').includes(arg)
);
return (
<FormGroup isRequired={false} label="Append">
<LabelInput
ariaLabel="Add kernel argument"
placeholder="Add kernel argument"
validator={isKernelArgumentValid}
list={kernelAppend.filter((arg) => !requiredByOpenSCAP.includes(arg))}
requiredList={requiredByOpenSCAP}
requiredCategoryName="Required by OpenSCAP"
item="Kernel argument"
addAction={addKernelArg}
removeAction={removeKernelArg}
stepValidation={stepValidation}
fieldName="kernelAppend"
/>
</FormGroup>
);
};
export default KernelArguments;