Skip to content

Commit

Permalink
DownloadImageDialog: Update Version dropdown styling to match the UI's
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
myarmolinsky committed Oct 24, 2024
1 parent 2d6dddd commit e451cac
Showing 1 changed file with 64 additions and 50 deletions.
114 changes: 64 additions & 50 deletions src/components/DownloadImageDialog/ImageForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
Typography,
IconButton,
Autocomplete,
useTheme,
Stack,
} from '@mui/material';
import HelpIcon from '@mui/icons-material/Help';
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
Expand All @@ -40,6 +42,9 @@ import { DeviceType, Dictionary, OsVersionsByDeviceType } from './models';
import { Visibility, VisibilityOff } from '@mui/icons-material';
import { FALLBACK_LOGO_UNKNOWN_DEVICE } from './utils';
import { ChipProps } from '../Chip';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTriangleExclamation } from '@fortawesome/free-solid-svg-icons';
import { Callout } from '../Callout';

const POLL_INTERVAL_DOCS =
'https://www.balena.io/docs/reference/supervisor/bandwidth-reduction/#side-effects--warnings';
Expand Down Expand Up @@ -108,6 +113,8 @@ export const ImageForm: React.FC<ImageFormProps> = memo(
onSelectedDeviceTypeChange,
onChange,
}) => {
const theme = useTheme();

const [showAdvancedSettings, setShowAdvancedSettings] = useState(false);
const [showPassword, setShowPassword] = useState(false);
const [version, setVersion] = useState<
Expand Down Expand Up @@ -199,6 +206,12 @@ export const ImageForm: React.FC<ImageFormProps> = memo(
}
}, [version, variant, onChange, versionSelectionOpts]);

const selectedOSVersion = useMemo(
() =>
versionSelectionOpts.find((version) => version.value === model.version),
[model.version, versionSelectionOpts],
);

return (
<Box
action={downloadUrl}
Expand Down Expand Up @@ -300,33 +313,41 @@ export const ImageForm: React.FC<ImageFormProps> = memo(
>
Select version
</InputLabel>
<Select
<Autocomplete
fullWidth
id="e2e-download-image-versions-list"
value={model.version}
inputProps={{
name: 'version',
}}
onChange={(event) => {
const version = versionSelectionOpts.find(
(v) => v.value === event.target.value,
);
value={selectedOSVersion}
getOptionLabel={(option) => option.value}
options={versionSelectionOpts}
onChange={(_event, version) => {
setVersion(version);
onChange('version', version?.value);
}}
placeholder="Choose a version..."
renderValue={() => {
return <VersionSelectItem option={version} />;
}}
>
{versionSelectionOpts?.map((option, index) => {
return (
<MenuItem key={index} value={option.value}>
<VersionSelectItem option={option} />
</MenuItem>
);
})}
</Select>
renderOption={(props, option) => (
<Box component="li" {...props}>
<VersionSelectItem option={option} />
</Box>
)}
renderInput={({ InputProps, ...params }) => (
<TextField
{...params}
InputProps={{
...InputProps,
name: 'version',
endAdornment: !!selectedOSVersion?.knownIssueList && (
<Tooltip title={selectedOSVersion.knownIssueList}>
<FontAwesomeIcon
icon={faTriangleExclamation}
color={theme.palette.warning.main}
/>
</Tooltip>
),
}}
/>
)}
disableClearable
/>
</Box>
{showAllVersionsToggle && (
<Box
Expand Down Expand Up @@ -523,36 +544,29 @@ const DeviceTypeItem: React.FC<{ deviceType: DeviceType }> = ({
);
};

export const VersionSelectItem = ({ option }: any) => {
// TODO: We need a better way than just copying the styling. Consider creating a component to export
export const VersionSelectItem = ({
option,
}: {
option: {
title: string;
isRecommended?: boolean;
knownIssueList: string | null;
};
}) => {
return (
<Tooltip title={option.knownIssueList ?? undefined}>
<Box
display="flex"
alignItems="center"
gap={2}
flexWrap="nowrap"
maxWidth="100%"
>
<Box>{option.title}</Box>
{!!option.line && (
<Chip label={option.line} color={lineMap[option.line]} />
)}
{!!option.isRecommended && (
<Chip
label="recommended"
sx={{
height: 20,
backgroundColor: '#CAFECD',
}}
/>
<Stack direction="column" flexWrap="wrap" maxWidth="100%" rowGap={1}>
<Typography noWrap maxWidth="100%" variant="titleSm">
{option.title}
{option.isRecommended && (
<Chip sx={{ ml: 1 }} color="green" label="recommended" />
)}
{!!option.knownIssueList && (
<Box alignItems="center" flex={1} display="contents">
<WarningAmberIcon color="warning" />
<Typography noWrap>{option.knownIssueList}</Typography>
</Box>
)}
</Box>
</Tooltip>
</Typography>
{!!option.knownIssueList && (
<Callout severity="warning" size="sm">
{option.knownIssueList}
</Callout>
)}
</Stack>
);
};

0 comments on commit e451cac

Please sign in to comment.