-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow selecting OpenShift version when creating infraEnv
- Loading branch information
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
libs/ui-lib/lib/cim/components/InfraEnv/OpenshiftVersionDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as React from 'react'; | ||
import { Dropdown, DropdownItem, DropdownToggle, FormGroup, Tooltip } from '@patternfly/react-core'; | ||
import { useField } from 'formik'; | ||
import { useTranslation } from '../../../common/hooks/use-translation-wrapper'; | ||
import { architectureData, getFieldId, SupportedCpuArchitecture } from '../../../common'; | ||
import { OsImage } from '../../types'; | ||
|
||
const OpenshiftVersionDropdown = ({ osImages }: { osImages: OsImage[] }) => { | ||
const { t } = useTranslation(); | ||
const [{ name, value }, , { setValue }] = useField<string>('osImageVersion'); | ||
const [{ value: cpuArchitecture }] = useField<string>('cpuArchitecture'); | ||
const [osImageOpen, setOsImageOpen] = React.useState(false); | ||
const fieldId = getFieldId(name, 'input'); | ||
|
||
const onOsImageSelect = (e?: React.SyntheticEvent<HTMLDivElement>) => { | ||
const val = e?.currentTarget.id || ''; | ||
setValue(val); | ||
setOsImageOpen(false); | ||
}; | ||
|
||
const filteredImages = React.useMemo( | ||
() => osImages.filter((image) => image.cpuArchitecture === cpuArchitecture), | ||
[osImages, cpuArchitecture], | ||
); | ||
|
||
React.useEffect(() => { | ||
if (filteredImages.length === 0 && value !== '') { | ||
setValue(''); | ||
} | ||
}, [filteredImages.length, setValue, t, value]); | ||
|
||
return ( | ||
<FormGroup isInline fieldId={fieldId} label={t('ai:OpenShift version')}> | ||
<Tooltip | ||
content={t( | ||
'ai:No OpenShift images available for selected CPU architecture {{cpuArchitecture}}.', | ||
architectureData[cpuArchitecture as SupportedCpuArchitecture].label, | ||
)} | ||
hidden={!!filteredImages.length} | ||
> | ||
<Dropdown | ||
toggle={ | ||
<DropdownToggle | ||
onToggle={() => setOsImageOpen(!osImageOpen)} | ||
className="pf-u-w-100" | ||
isDisabled={!filteredImages.length} | ||
> | ||
{value ? `OpenShift ${value}` : t('ai:No version selected')} | ||
</DropdownToggle> | ||
} | ||
name="osImageVersion" | ||
isOpen={osImageOpen} | ||
onSelect={onOsImageSelect} | ||
dropdownItems={[ | ||
<DropdownItem key={'NO_VALUE'} value={''}> | ||
{t('ai:No version selected')} | ||
</DropdownItem>, | ||
...filteredImages.map((image) => ( | ||
<DropdownItem key={image.openshiftVersion} id={image.openshiftVersion}> | ||
{`OpenShift ${image.openshiftVersion}`} | ||
</DropdownItem> | ||
)), | ||
]} | ||
className="pf-u-w-100" | ||
/> | ||
</Tooltip> | ||
</FormGroup> | ||
); | ||
}; | ||
|
||
export default OpenshiftVersionDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters