debian-image-builder-frontend/src/Components/CreateImageWizard/steps/ImageOutput/ArchSelect.tsx
regexowl 4fb37c187e src: Rename "V2" folders to just Wizard
This replaces all occurences of "CreateImageWizardV2" with just "CreateImageWizard" as it is the only version now.
2024-07-17 11:17:06 +02:00

60 lines
1.4 KiB
TypeScript

import React, { ReactElement, useState } from 'react';
import { FormGroup } from '@patternfly/react-core';
import {
Select,
SelectOption,
SelectVariant,
} from '@patternfly/react-core/deprecated';
import { ARCHS } from '../../../../constants';
import { useAppDispatch, useAppSelector } from '../../../../store/hooks';
import { ImageRequest } from '../../../../store/imageBuilderApi';
import {
changeArchitecture,
selectArchitecture,
} from '../../../../store/wizardSlice';
const ArchSelect = () => {
const arch = useAppSelector(selectArchitecture);
const dispatch = useAppDispatch();
const [isOpen, setIsOpen] = useState(false);
const setArch = (
_event: React.MouseEvent,
selection: ImageRequest['architecture']
) => {
dispatch(changeArchitecture(selection));
setIsOpen(false);
};
const setSelectOptions = () => {
const options: ReactElement[] = [];
ARCHS.forEach((arch) => {
options.push(
<SelectOption key={arch} value={arch}>
{arch}
</SelectOption>
);
});
return options;
};
return (
<FormGroup isRequired={true} label="Architecture">
<Select
ouiaId="arch_select"
variant={SelectVariant.single}
onToggle={() => setIsOpen(!isOpen)}
onSelect={setArch}
selections={arch}
isOpen={isOpen}
>
{setSelectOptions()}
</Select>
</FormGroup>
);
};
export default ArchSelect;