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

Enhance Tab Functionality for URL Query-Based Field Filtering #811

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ehco1996
Copy link

@Ehco1996 Ehco1996 commented Oct 18, 2024

Summary:

This PR introduces improvements to the tab functionality, allowing tabs to serve as quick filters for field data based on URL query parameters. The current logic does not handle this scenario correctly, leading to incorrect filtering results.

Example:

Currently, the tabs are structured as follows:

tabs = [
    {
        "models": [
            "group1",
        ],
        "items": [
            {"title": "group-1", "link": "/admin/app_name/group/"},
            {"title": "group--2", "link": "/admin/app_name/group/?lable=online"},
        ],
    },
]

This PR addresses the issue by implementing a more robust logic to correctly interpret and apply the URL query parameters for filtering.

@lukasvinclav
Copy link
Contributor

Would you mind to upload a short video what does this functionality do?

@Ehco1996
Copy link
Author

Ehco1996 commented Oct 20, 2024

20241020-194617

Please find the GIF attached. Please note that all tabs correspond to the same model, but with different filter parameters, as mentioned in the PR description.

code looks like

[
    {
        "models": [
            "proxy.proxynode",
        ],
        "items": [
            {"title": "所有", "link": "/admin/proxy/proxynode/"},
            {"title": "美国", "link": "/admin/proxy/proxynode/?country__exact=US"},
            {"title": "日本", "link": "/admin/proxy/proxynode/?country__exact=JP"},
            {"title": "香港", "link": "/admin/proxy/proxynode/?country__exact=HK"},
        ],
    }
]

@pnost
Copy link

pnost commented Oct 22, 2024

Nice. I used it for a link in settings.py -> SIDEBAR -> navigation:
"link": lambda request: reverse_lazy("admin:rezeptor_prescriptionsync_changelist") + "?kassenrezept=true&status__exact=processing
which now does not collapse anymore but stays open & active.
Now I don't need to create a proxy for Model.
Thank you

@lukasvinclav
Copy link
Contributor

I think, the @pnost solution is correct. You don't need to change any business logic to get tabs with filters.

@pnost
Copy link

pnost commented Oct 22, 2024

@lukasvinclav it's not only about having tabs with filters but having them hightlighted as active tab.
Links in tabs and navigation are not highlighted as active until now if you use the same model but add a filter to the url. @Ehco1996 commit changes this.

@Ehco1996
Copy link
Author

@lukasvinclav ptal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants