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

In menus, qualify device names with site and/or tenant #13093

Closed
candlerb opened this issue Jul 5, 2023 · 18 comments
Closed

In menus, qualify device names with site and/or tenant #13093

candlerb opened this issue Jul 5, 2023 · 18 comments
Labels
pending closure Requires immediate attention to avoid being closed for inactivity type: feature Introduction of new functionality to the application

Comments

@candlerb
Copy link
Contributor

candlerb commented Jul 5, 2023

NetBox version

v3.5.4

Feature type

Change to existing functionality

Proposed functionality

Currently when you get a drop-down selection list of devices (e.g. when creating a cable), the list shows only the device name.

However, device names are only unique within a given site/tenant.

Therefore if you have 100 sites, each with a device named "PDU", you will see a drop-down menu with 100 entries all called "PDU" - it's impossible to distinguish one from another.

Proposal: the menu label for a device should show "device name - site - tenant". If the device has no name, then "device model - id - site - tenant".

Use case

In some contexts it is possible to filter this list down further - e.g. by opening the filter sub-window and filtering on site.

But in general, I think presenting a menu of identical-looking choices (when in fact they are significantly different, and choosing the wrong one could be a serious error) is a poor user experience.

Database changes

None

External dependencies

None

@candlerb candlerb added the type: feature Introduction of new functionality to the application label Jul 5, 2023
@DanSheps
Copy link
Member

DanSheps commented Jul 5, 2023

Tangentially related: #11478

This same problem pops up in the context of interfaces.

@opericgithub
Copy link

Why don't you include site and/or tenant column in a table view?

@candlerb
Copy link
Contributor Author

candlerb commented Jul 5, 2023

Additional point 1: it occurs to me that these menus need to be searchable efficiently using AJAX. This suggests that there should be a "display label" field which is cached in the database model - much in the same way as interfaces have a _name field for natural sorting.

(This could also have a unique constraint, which would guarantee that you can never accidentally have two indistinguishable items in a menu)

Additional point 2: another tangential issue. In custom scripts, I would like to do this:

    pop_site = ObjectVar(
        model=Site,
        label="POP Site",
        query_params={
            status="active",
        },
    })

However, this displays only the Site "Name" attribute. I need also to show (and be able to search on) a site code, which is held separately in custom_field_data['mdf_id'] - but ObjectVar doesn't allow customization of the display label.

My workaround (which is OK for now because the list of sites isn't too large) is to generate a materialized ChoiceVar instead:

    pop_site_id = ChoiceVar([
            (
                site.id,
                f"{site.name} - {site.custom_field_data['mdf_id']}" if site.custom_field_data.get('mdf_id')
                else site.name
            )
            for site in Site.objects.filter(status='active')
        ],
        label="POP Site",
    )

But in the long term, if Site also had a display _name attribute, whose contents could be overridden with a custom function, that would achieve the same goal in a cleaner way.

@candlerb
Copy link
Contributor Author

candlerb commented Jul 5, 2023

@DanSheps: a vaguely related case which doesn't involve VCs is when a cable endpoint has multiple terminations, and those are interfaces on different devices, then the interface names may become indistinguishable: #10841

image

@DanSheps
Copy link
Member

DanSheps commented Jul 5, 2023

@DanSheps: a vaguely related case which doesn't involve VCs is when a cable endpoint has multiple terminations, and those are interfaces on different devices, then the interface names may become indistinguishable: #10841

It is related in that all of this (this issue and the one I referenced) relates to the serializer's display_name field not including context data.

@martinum4
Copy link

Therefore if you have 100 sites, each with a device named "PDU", you will see a drop-down menu with 100 entries all called "PDU" - it's impossible to distinguish one from another.

That seem like the same problem OpenStreetMap-Contributors are facing, names are names, not descriptions etc.

If the device is distinguishable from others by type and role and it has no actual assigned name just leave the name empty…

@DanSheps
Copy link
Member

DanSheps commented Jul 6, 2023

I think the example was made overly generic, but take for example:

"CORE-SW-01", you might have one in Site A and Site B. If you search just "CORE-SW-01" it will bring in all. However if there is a display_name attribute that includes more name context data (such as "CORE-SW-01, Site A, Region B" vs "CORE-SW-01, Site B, Region B" you can pick the appropriate one.

@candlerb
Copy link
Contributor Author

candlerb commented Jul 6, 2023

Yes that's it exactly.

@ITJamie
Copy link
Contributor

ITJamie commented Jul 6, 2023

Screenshot 2023-06-28 at 22 54 27
I have also been thinking about this and playing with ideas how to implement a fix in a sane way across models.
I made develop...ITJamie:netbox:alt_display_name as a concept of how we could define an "additional" standardized model property that if exists would be used in selection/multiselection boxes where additional context would be useful.

@martinum4
Copy link

I personally thing the end-user-friendliest approach would be to allow comma to be used as "search character", eg you search for "sw-core-1, samplecity" it then searches for "sw-core-1" first and in the results for that it searches for "samplecity" in all the other linked attributes (racks, locations, sites, regions).

@jsenecal
Copy link
Contributor

jsenecal commented Jul 7, 2023

I personally thing the end-user-friendliest approach would be to allow comma to be used as "search character", eg you search for "sw-core-1, samplecity" it then searches for "sw-core-1" first and in the results for that it searches for "samplecity" in all the other linked attributes (racks, locations, sites, regions).

There are also limitations in the frontend library that netbox uses as it currently only allows to find/select results which have the string typed in the select box. Just more things to consider when thinking about "searching" from additional fields/relationships.

@DanSheps
Copy link
Member

DanSheps commented Jul 11, 2023

I have also been thinking about this and playing with ideas how to implement a fix in a sane way across models.
I made develop...ITJamie:netbox:alt_display_name as a concept of how we could define an "additional" standardized model property that if exists would be used in selection/multiselection boxes where additional context would be useful.

I am not against this approach, but I think if we are doing this it makes more sense to override in get_display() instead.

That said, one option that this got me thinking about more, is to perhaps have the widget allow you to define a list of fields to include in the display name and it combines them itself (this would only work for fields available via the nested serializer). Something like:

  display_field: '$name ($device.display)'

This way, you could override it on the form itself without changing the underlying get_display function. The ApiSelect function would need to handle tokenizing the fields and replacing them but it is less "disruptive" to the underlying API.

@candlerb
Copy link
Contributor Author

perhaps have the widget allow you to define a list of fields to include in the display name

How would this work with filter-as-you-type, when there are a large set of objects in the database? Does it currently use an indexed column (Name)?

@DanSheps
Copy link
Member

DanSheps commented Jul 11, 2023

I believe the filter-as-you-type (might be mistaken mind you) uses a async request to dcim/interfaces/?q=X, which wouldn't interfere with it, to my knowledge.

Take this with a grain of salt as I am not a typescript expert.

@candlerb
Copy link
Contributor Author

Yes you're right, for example it calls /api/dcim/devices/?brief=true&q=X when searching for a device to create a cable endpoint (seen via developer console)

The problem though will be that q may not match the strings being shown. For example, if the drop-down shows

core-sw-01 (site foo)
core-sw-02 (site bar)

and the user types 'bar', they would expect the list to contract to

core-sw-02 (site bar)

but I think it will just go to empty (testing seems to confirm this; if I type part of a site name, I don't see any devices)

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Oct 10, 2023
@ITJamie
Copy link
Contributor

ITJamie commented Oct 23, 2023

@DanSheps you mentioned in #13156 that you were looking at another way to do this. I have vague memory of another PR fixing something like this but am having trouble tracking it down to suggest something similar for this.

@jeremystretch
Copy link
Member

This would be addressed by #13283

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending closure Requires immediate attention to avoid being closed for inactivity type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

7 participants