-
Notifications
You must be signed in to change notification settings - Fork 400
change: [M3-9881] - Improve behavior of VLANSelect component when creating a new VLAN #12380
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
Changes from 9 commits
4208f3b
3410a24
3f41829
d1aaa4c
205b362
79a3809
4128b4b
fd7cda8
86dd2fc
ff00e37
cf6a2b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@linode/manager": Changed | ||
| --- | ||
|
|
||
| Improve VLANSelect component behavior when creating a new VLAN ([#12380](https://github.com/linode/manager/pull/12380)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@linode/manager": Upcoming Features | ||
| --- | ||
|
|
||
| Add region filtering for VLANSelect in AddInterface form ([#12380](https://github.com/linode/manager/pull/12380)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,9 @@ export const VLANSelect = (props: Props) => { | |
| // If the value gets cleared, make sure the TextField's value also gets cleared. | ||
| setInputValue(''); | ||
| } | ||
| if (value && !inputValue) { | ||
| setInputValue(value); | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [value]); | ||
|
|
||
|
|
@@ -108,27 +111,31 @@ export const VLANSelect = (props: Props) => { | |
| option === newVlanPlaceholder ? `Create "${inputValue}"` : option.label | ||
| } | ||
| helperText={helperText} | ||
| inputValue={selectedVLAN ? selectedVLAN.label : inputValue} | ||
| isOptionEqualToValue={(option1, options2) => | ||
| option1.label === options2.label | ||
| inputValue={selectedVLAN && !open ? selectedVLAN.label : inputValue} | ||
| isOptionEqualToValue={(option1, option2) => | ||
| option1.label === option2.label | ||
| } | ||
| label="VLAN" | ||
| ListboxProps={{ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| onScroll: (event: React.SyntheticEvent) => { | ||
| const listboxNode = event.currentTarget; | ||
| if ( | ||
| listboxNode.scrollTop + listboxNode.clientHeight >= | ||
| listboxNode.scrollHeight && | ||
| hasNextPage | ||
| ) { | ||
| fetchNextPage(); | ||
| } | ||
| }, | ||
| }} | ||
| loading={isFetching} | ||
| noMarginTop | ||
| noOptionsText="You have no VLANs in this region. Type to create one." | ||
| onBlur={onBlur} | ||
| onBlur={() => { | ||
| if (inputValue !== value) { | ||
| if (vlans.length === 1 && onChange) { | ||
|
||
| // if input value has changed and there is only one option, select that input value | ||
| // this handles the case where users expect the new VLAN to be selected onBlur if the only option that exists is to create it | ||
| onChange(inputValue); | ||
| } else { | ||
| // otherwise, if there are multiple options: if we didn't explicitly select the new input value, keep the old value | ||
| // if there is no pre-existing value selected, this clears the textfield | ||
| setInputValue(value ?? ''); | ||
| } | ||
| } | ||
|
|
||
| if (onBlur) { | ||
| onBlur(); | ||
| } | ||
| }} | ||
| onChange={(event, value) => { | ||
| if (onChange) { | ||
| onChange(value?.label ?? null); | ||
|
|
@@ -151,6 +158,20 @@ export const VLANSelect = (props: Props) => { | |
| open={open} | ||
| options={vlans} | ||
| placeholder="Create or select a VLAN" | ||
| slotProps={{ | ||
| listbox: { | ||
| onScroll: (event: React.SyntheticEvent) => { | ||
| const listboxNode = event.currentTarget; | ||
| if ( | ||
| listboxNode.scrollTop + listboxNode.clientHeight >= | ||
| listboxNode.scrollHeight && | ||
| hasNextPage | ||
| ) { | ||
| fetchNextPage(); | ||
| } | ||
| }, | ||
| }, | ||
| }} | ||
| sx={sx} | ||
| value={selectedVLAN} | ||
| /> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.