Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [M3-8696] - Autocomplete renderOption prop console warning #11140

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11140-fixed-1729625688555.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

Autocomplete renderOption prop console warning ([#11140](https://github.com/linode/manager/pull/11140))
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ export const PlacementGroupsSelect = (props: PlacementGroupsSelectProps) => {
handlePlacementGroupChange(selectedOption ?? null);
}}
renderOption={(props, option, { selected }) => {
const { key, ...rest } = props;

return (
<PlacementGroupSelectOption
disabled={isDisabledPlacementGroup(option, selectedRegion)}
key={option.id}
key={key}
label={option.label}
props={props}
props={rest}
selected={selected}
value={option}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,22 @@ export const RegionMultiSelect = React.memo((props: RegionMultiSelectProps) => {
onChange(selectedOptions?.map((region) => region.id) ?? [])
}
renderOption={(props, option, { selected }) => {
const { key, ...rest } = props;
if (!option.site_type) {
// Render options like "Select All / Deselect All"
return <StyledListItem {...props}>{option.label}</StyledListItem>;
return (
<StyledListItem {...rest} key={key}>
{option.label}
</StyledListItem>
);
}

// Render regular options
return (
<RegionOption
disabledOptions={disabledRegions[option.id]}
key={option.id}
props={props}
key={key}
props={rest}
region={option}
selected={selected}
/>
Expand Down
20 changes: 12 additions & 8 deletions packages/manager/src/components/RegionSelect/RegionSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,18 @@ export const RegionSelect = <
getOptionLabel={(region) =>
isGeckoLAEnabled ? region.label : `${region.label} (${region.id})`
}
renderOption={(props, region) => (
<RegionOption
disabledOptions={disabledRegions[region.id]}
key={region.id}
props={props}
region={region}
/>
)}
renderOption={(props, region) => {
const { key, ...rest } = props;

return (
<RegionOption
disabledOptions={disabledRegions[region.id]}
key={key}
props={rest}
region={region}
/>
);
}}
sx={(theme) => ({
[theme.breakpoints.up('md')]: {
width: '416px',
Expand Down
12 changes: 9 additions & 3 deletions packages/manager/src/components/TagCell/AddTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ export const AddTag = (props: AddTagProps) => {
handleAddTag(typeof value == 'string' ? value : value.label);
}
}}
renderOption={(props, option) => (
<li {...props}>{option.displayLabel ?? option.label}</li>
)}
renderOption={(props, option) => {
const { key, ...rest } = props;

return (
<li {...rest} key={key}>
{option.displayLabel ?? option.label}
</li>
);
}}
disableClearable
forcePopupIcon
label={'Create or Select a Tag'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,14 @@ export const DatabaseBackups = (props: Props) => {
onChange={(_, newTime) => setSelectedTime(newTime)}
options={TIME_OPTIONS}
placeholder="Choose a time"
renderOption={(props, option) => (
<li {...props} key={option.value}>
{option.label}
</li>
)}
renderOption={(props, option) => {
const { key, ...rest } = props;
return (
<li {...rest} key={key}>
{option.label}
</li>
);
}}
textFieldProps={{
dataAttrs: {
'data-qa-time-select': true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export const KernelSelect = React.memo((props: KernelSelectProps) => {
return (
<Autocomplete
renderOption={(props, kernel) => {
const { key, ...rest } = props;
return (
<li {...props} data-testid="kernel-option">
<li {...rest} data-testid="kernel-option" key={key}>
{kernel.label}
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ export const LinodeOrIPSelect = (props: Props) => {
}
}}
renderOption={(props, option, state) => {
const { key, ...rest } = props;
const region =
regions?.find((r) => r.id === option.region)?.label ?? option.region;

const isCustomIp = option === customIpPlaceholder;

return (
<li {...props}>
<li {...rest} key={key}>
<Stack flexGrow={1}>
<Box>
<b>{isCustomIp ? 'Custom IP' : option.label}</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,32 @@ export const ConfigNodeIPSelect = React.memo((props: Props) => {

return (
<Autocomplete
renderOption={(props, option, { selected }) => (
<li {...props} key={props.key}>
<Box
alignItems="center"
display="flex"
flexDirection="row"
gap={1}
justifyContent="space-between"
width="100%"
>
<Stack>
<Typography
color="inherit"
fontFamily={(theme) => theme.font.bold}
>
{option.label}
</Typography>
<Typography color="inherit">{option.linode.label}</Typography>
</Stack>
{selected && <SelectedIcon visible />}
</Box>
</li>
)}
renderOption={(props, option, { selected }) => {
const { key, ...rest } = props;
return (
<li {...rest} key={key}>
<Box
alignItems="center"
display="flex"
flexDirection="row"
gap={1}
justifyContent="space-between"
width="100%"
>
<Stack>
<Typography
color="inherit"
fontFamily={(theme) => theme.font.bold}
>
{option.label}
</Typography>
<Typography color="inherit">{option.linode.label}</Typography>
</Stack>
{selected && <SelectedIcon visible />}
</Box>
</li>
);
}}
disabled={disabled}
errorText={errorText ?? error?.[0].reason}
id={inputId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ export const NodeBalancerSelect = (
renderOption={
renderOption
? (props, option, { selected }) => {
const { key, ...rest } = props;
return (
<li {...props} data-qa-linode-option>
<li {...rest} data-qa-linode-option key={key}>
{renderOption(option, selected)}
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const PlacementGroupTypeSelect = (props: Props) => {
setFieldValue('placement_group_type', value?.value ?? '');
}}
renderOption={(props, option) => {
const { key, ...rest } = props;
const isDisabledMenuItem = option.value === 'affinity:local';

return (
Expand All @@ -49,10 +50,10 @@ export const PlacementGroupTypeSelect = (props: Props) => {
enterDelay={200}
enterNextDelay={200}
enterTouchDelay={200}
key={option.value}
key={key}
>
<ListItem
{...props}
{...rest}
className={
isDisabledMenuItem
? `${props.className} Mui-disabled`
Expand Down
5 changes: 5 additions & 0 deletions packages/ui/src/foundations/themes/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ export const darkTheme: ThemeOptions = {
'.MuiChip-deleteIcon': { color: primaryColors.text },
backgroundColor: customDarkModeOptions.bg.lightBlue1,
},
input: {
'&::selection': {
backgroundColor: customDarkModeOptions.bg.appBar,
},
},
},
},
MuiBackdrop: {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/foundations/themes/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export const lightTheme: ThemeOptions = {
opacity: 1,
},
'&::selection': {
backgroundColor: color.grey7,
backgroundColor: color.grey10,
},
},
inputRoot: {
Expand Down