feat: filter out used networks in network selector WD-34762#1885
Open
omarelkashef wants to merge 1 commit intocanonical:mainfrom
Open
feat: filter out used networks in network selector WD-34762#1885omarelkashef wants to merge 1 commit intocanonical:mainfrom
omarelkashef wants to merge 1 commit intocanonical:mainfrom
Conversation
Signed-off-by: Omar Elkashef <omarelkashef01@gmail.com>
edlerd
reviewed
Mar 20, 2026
Comment on lines
+191
to
+196
| const appliedProfiles = getAppliedProfiles(values, profiles); | ||
| for (const profile of appliedProfiles) { | ||
| Object.values(profile.devices).map((item) => { | ||
| existingNetworksNames.push((item as LxdNicDevice).network); | ||
| }); | ||
| } |
Collaborator
There was a problem hiding this comment.
We need to be more careful here. Some of those inherited devices can be overridden by other profiles or by instance networks. Maybe better to use the getInheritedNetworks helper. Which we actually already call in NetworkDevicePanel, so perhaps we can pass those into this function instead of calculating them afresh.
Comment on lines
+88
to
+104
| const isEditing = panelParams.panel === panels.editNetworkDevice; | ||
| const isEditingNetwork = (network: LxdNetwork) => { | ||
| return isEditing && device?.network === network.name; | ||
| }; | ||
| const canAttachNetworkAgain = (network: LxdNetwork) => { | ||
| return ( | ||
| parentFormik.values.entityType === "profile" || | ||
| !existingNetworks.includes(network.name) || | ||
| network.config["dns.mode"] === "none" | ||
| ); | ||
| }; | ||
|
|
||
| const managedNetworks = networks.filter((network) => network.managed); | ||
| const managedNetworks = networks.filter( | ||
| (network) => | ||
| network.managed && | ||
| (isEditingNetwork(network) || canAttachNetworkAgain(network)), | ||
| ); |
Collaborator
There was a problem hiding this comment.
Suggested change
| const isEditing = panelParams.panel === panels.editNetworkDevice; | |
| const isEditingNetwork = (network: LxdNetwork) => { | |
| return isEditing && device?.network === network.name; | |
| }; | |
| const canAttachNetworkAgain = (network: LxdNetwork) => { | |
| return ( | |
| parentFormik.values.entityType === "profile" || | |
| !existingNetworks.includes(network.name) || | |
| network.config["dns.mode"] === "none" | |
| ); | |
| }; | |
| const managedNetworks = networks.filter((network) => network.managed); | |
| const managedNetworks = networks.filter( | |
| (network) => | |
| network.managed && | |
| (isEditingNetwork(network) || canAttachNetworkAgain(network)), | |
| ); | |
| const isAvailable = (network: LxdNetwork) => { | |
| if (network.managed) { | |
| return false; | |
| } | |
| const isSelectedNetwork = isEditing && device?.network === network.name; | |
| const isUnused = !existingNetworks.includes(network.name); | |
| const allowsDuplicateAttachment = network.config["dns.mode"] === "none"; | |
| return isSelectedNetwork || isUnused || allowsDuplicateAttachment; | |
| }; | |
| const networkOptions = networks.filter(isAvailable); |
Suggesting to slightly restructure the filter logic here. Wdyt?
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Done
NOTE: it is possible now to create a profile attached to a network twice. This will cause an error when starting an instance with that profile. This can be fixed in another PR.