Wizard: Remove redundant code, fix addItem

Removed redundant code and updated `addItem` to check for duplicate arguments in both required and non-required list.
This commit is contained in:
regexowl 2025-01-24 14:03:08 +01:00 committed by Klara Simickova
parent 1b21852518
commit 6a29f7f344
2 changed files with 8 additions and 12 deletions

View file

@ -50,19 +50,19 @@ const ChippingInput = ({
};
const addItem = (value: string) => {
if (validator(value) && !list?.includes(value)) {
dispatch(addAction(value));
setInputValue('');
setErrorText('');
}
if (list?.includes(value)) {
if (list?.includes(value) || requiredList?.includes(value)) {
setErrorText(`${item} already exists.`);
return;
}
if (!validator(value)) {
setErrorText('Invalid format.');
return;
}
dispatch(addAction(value));
setInputValue('');
setErrorText('');
};
const handleKeyDown = (e: React.KeyboardEvent, value: string) => {

View file

@ -35,17 +35,13 @@ const KernelArguments = () => {
oscapProfileInfo?.kernel?.append?.split(' ').includes(arg)
);
const notRequiredByOpenSCAP = kernelAppend.filter(
(arg) => !oscapProfileInfo?.kernel?.append?.split(' ').includes(arg)
);
return (
<FormGroup isRequired={false} label="Append">
<ChippingInput
ariaLabel="Add kernel argument"
placeholder="Add kernel argument"
validator={isKernelArgumentValid}
list={notRequiredByOpenSCAP}
list={kernelAppend.filter((arg) => !requiredByOpenSCAP.includes(arg))}
requiredList={requiredByOpenSCAP}
item="Kernel argument"
addAction={addKernelArg}