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

Allow sorting of Tree like model list views #4811

Closed
itdependsnetworks opened this issue Nov 15, 2023 · 9 comments
Closed

Allow sorting of Tree like model list views #4811

itdependsnetworks opened this issue Nov 15, 2023 · 9 comments
Assignees
Labels
type: feature Introduction of new or enhanced functionality to the application
Milestone

Comments

@itdependsnetworks
Copy link
Contributor

Environment

  • Nautobot version (Docker tag too if applicable): 2.0
  • Python version: 3.11
  • Database platform, version: psql
  • Middleware(s): N/A

Steps to Reproduce

  1. Go to https://demo.nautobot.com/ipam/prefixes/
  2. Click on headers

Expected Behavior

To sort based on the column header you created

Observed Behavior

No sorting

@itdependsnetworks itdependsnetworks added type: bug Something isn't working as expected triage This issue is new and has not been reviewed. labels Nov 15, 2023
@itdependsnetworks
Copy link
Contributor Author

Seems like we just need to remove this

orderable = False
, but not sure why it was there to begin with?

@glennmatthews
Copy link
Contributor

Given that prefixes are hierarchical, I'm not sure sorting makes a lot of sense (similar to #1854). Can you give an example of the type of sorting you'd expect to be able to do here?

@lampwins
Copy link
Member

IIRC in #1854 we chose at the time to disable sorting on tree models primarily due to the odd visual representation of nested data and because we did not have the cycles in 2.0 to properly solve that.

Let's use this issue to build a good story around the presentation and interaction with the Prefix hierarchy alone. I'm sure some of it will meaningfully carry over to other tree models like location, but there will be different use cases.

To start, I can see two primary views into the prefix data.

  1. A collapsable, navigable tree. Filtering and sorting here, would only effect top level nodes in the tree.
  2. A flat view that ignores the tree relationships in which all traditional filtering and sorting works.

As a user I would want a simple toggle between these two options in the list view.

I'm certain we can get more advanced from there.

In the first case, I care primary about drilling down into the data. In the second case, I care more about filtering and sorting, such as filtering by a location and then sorting by the role.

@itdependsnetworks
Copy link
Contributor Author

2 would be what I was looking for, I asked chatgpt for some starter code to describe what I think makes sense

class MyTable(tables.Table):
    my_column = tables.TemplateColumn(template_name='my_column_template.html')

    def __init__(self, *args, **kwargs):
        super(MyTable, self).__init__(*args, **kwargs)
        
        # Check if there's an explicit sorting
        is_sorting = any(value for key, value in self.order_by_field.items() if value)

        # Add context to all columns (or you can target a specific column)
        for column in self.columns:
            column.extra_context.update({'is_sorting': is_sorting})

Within the PREFIX_LINK variable have something like

PREFIX_LINK = """
{% load helpers %}
{% if not is_sorting %}
{% for i in record.ancestors.count|as_range %}
    <i class="mdi mdi-circle-small"></i>
{% endfor %}
{% endif %}

@lampwins lampwins added type: feature Introduction of new or enhanced functionality to the application and removed type: bug Something isn't working as expected triage This issue is new and has not been reviewed. labels Nov 17, 2023
@lampwins
Copy link
Member

For now, we will allow the sorting and when a user actually does sort, we will dynamically remove the hierarchy indentation.

@lampwins lampwins changed the title IPAM Prefix Sort Not Available Allow sorting of IPAM Prefix list view Dec 4, 2023
@joewesch
Copy link
Contributor

joewesch commented Jan 5, 2024

We had a request today regarding sorting in Locations, and I'm assuming it's missing due to the same reason. @lampwins do you want me to create a parallel issue?

@lampwins
Copy link
Member

lampwins commented Jan 5, 2024

I don't think so. We would support sorting any column that it should be, in this model.

@lampwins lampwins changed the title Allow sorting of IPAM Prefix list view Allow sorting of Tree like model list views Jan 29, 2024
@timizuoebideri1 timizuoebideri1 self-assigned this Jan 31, 2024
@gsnider2195
Copy link
Contributor

Reopening this issue, needs to be implemented on the Prefix list view, and needs to be implemented when filtering a tree list view as well as sorting

@glennmatthews
Copy link
Contributor

#5452 added sortability to the Prefix table. Remaining work now is to remove the indentation of entries whenever a filter is applied to any tree table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Introduction of new or enhanced functionality to the application
Projects
No open projects
Status: To Groom
Development

No branches or pull requests

6 participants