Skip to content

feat:(model-manager) add sorting capabilities for models#9024

Open
skunkworxdark wants to merge 13 commits intoinvoke-ai:mainfrom
skunkworxdark:model-manager-sort
Open

feat:(model-manager) add sorting capabilities for models#9024
skunkworxdark wants to merge 13 commits intoinvoke-ai:mainfrom
skunkworxdark:model-manager-sort

Conversation

@skunkworxdark
Copy link
Copy Markdown
Contributor

Summary

This PR introduces robust sorting capabilities to the Model Manager, allowing users to organize their installed models by several attributes in both ascending and descending order. This improves usability for users with large model libraries.

Related Issues / Discussions

#5885

Changes Made

  • Backend (``invokeai/app/ & `tests/`):

    • Expanded the ModelRecordOrderBy enum to include Size, DateAdded, DateModified, and Path.
    • Added an order_by and direction query parameter to list_models and search_by_attr in model_records_base.py and model_manager.py.
    • Implemented SQL-based sorting in model_records_sql.py, notably using COLLATE NOCASE for string attributes (Name, Base) and json_extract to sort by file_size nested inside the config JSON.
    • Corrected the Default sort implementation to ensure the selected sort direction is correctly applied to all fallback columns (type, base, and name), rather than just the final column (format).
    • Added robust test coverage in test_model_records_sql.py to ensure proper ascending and descending functionality across different attributes.
  • Frontend (``invokeai/frontend/web/):

    • State Management: Updated the modelManagerV2Slice to track orderBy and sortDirection globally.
    • API Integration: Passed the sorting arguments into the useGetModelConfigsQuery. Removed the client-side sortComparer from modelConfigsAdapter so the UI properly respects the server-provided order.
    • UI/UX: Added a new <ModelSortControl /> component to the ModelListNavigation panel.
    • i18n: Added full English localization strings for all sort options.

QA Instructions

  1. Navigate to the Model Manager tab.
  2. Ensure you have multiple models installed with varying bases, sizes, and names.
  3. Locate the new Sort control in the top navigation bar of the Model Manager.
  4. Try sorting by different parameters (Name, Base, Size, Date Added, etc.) and toggle between Ascending/Descending.
  5. Change the sort mode back to Default and toggle the direction to verify that the list properly reverses the fallback groupings (Type, then Base, then Name).
  6. Verify that the list updates correctly based on your selection and that the UI state persists across component unmounts.

Merge Plan

Standard merge. No Special instructions.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

dded the ability to sort models in the Model Manager by various attributes
including Name, Base, Type, Format, Size, Date Added, and Date Modified.
Supports both ascending and descending order.

- Backend: Added `order_by` and `direction` query parameters to the
  ``/api/v1/models`/` listing endpoint. Implemented case-insensitive
  sorting in the SQLite model records service.
- Frontend: Introduced `<ModelSortControl />` UI, updated Redux slices
  to manage sort state, removed client-side entity adapter sorting to
  respect server-side ordering, and added i18n localization keys.
- Tests: Added test coverage for SQL-based sorting on size and name.
dded the ability to sort models in the Model Manager by various attributes
including Name, Base, Type, Format, Size, Date Added, and Date Modified.
Supports both ascending and descending order.

- Backend: Added `order_by` and `direction` query parameters to the
  ``/api/v1/models`/` listing endpoint. Implemented case-insensitive
  sorting in the SQLite model records service.
- Frontend: Introduced `<ModelSortControl />` UI, updated Redux slices
  to manage sort state, removed client-side entity adapter sorting to
  respect server-side ordering, and added i18n localization keys.
- Tests: Added test coverage for SQL-based sorting on size and name.
@github-actions github-actions bot added api python PRs that change python files services PRs that change app services frontend PRs that change frontend files python-tests PRs that change python tests labels Apr 5, 2026
@joshistoast
Copy link
Copy Markdown
Collaborator

joshistoast commented Apr 8, 2026

I'm still of the opinion personally that since the client has already fetched all the models, that it would be less intensive, faster and cleaner to sort on the client. But I digress.

The model search widget is starting too feel dense with the new direction toggle and sort by dropdown, they all have very different styles. Maybe we can get this all condensed into a unified filter dropdown each with submenus to select the desired filtering.

image

@skunkworxdark
Copy link
Copy Markdown
Contributor Author

I'm still of the opinion personally that since the client has already fetched all the models, that it would be less intensive, faster and cleaner to sort on the client. But I digress.

The model search widget is starting too feel dense with the new direction toggle and sort by dropdown, they all have very different styles. Maybe we can get this all condensed into a unified filter dropdown each with submenus to select the desired filtering.

image

I'm not great with the frontend stuff, but I will take a quick look and see if I can do something without breaking everything. If not, maybe someone else, who is far more skilled than I, could do a UI PR for it later.

But I will take a stab at it first.

@skunkworxdark
Copy link
Copy Markdown
Contributor Author

skunkworxdark commented Apr 8, 2026

@joshistoast, what do you think of this?
If you think that is ok, I will commit it.

image image image

@joshistoast
Copy link
Copy Markdown
Collaborator

Yeah that looks much better @skunkworxdark. Small nitpick on the UI, maybe preserve the checkmark space on the left of non-selected item labels.

@ufuksarp
Copy link
Copy Markdown
Contributor

ufuksarp commented Apr 9, 2026

Another important UX improvement would be for the drop-down menu to stay open (if not already), only closing when clicked outside or on the Filtering button.

@skunkworxdark
Copy link
Copy Markdown
Contributor Author

@joshistoast indentation sorted. I think this is what you requested?

image

@ufuksarp, I am not exactly sure what you mean or what the point of your request would be. Can you expand on what you mean, or better still, provide an example of another menu in Invoke that behaves the way you are requesting?

…ed menu

-  Replaced separate `ModelSortControl` and `ModelTypeFilter` components with a single, unified "Filtering" dropdown menu.
- Organised filtering options into categorised submenus in the following order: Direction, Sort By, and Model Type.
- Enhanced submenu labels to display the currently active selection inline for quick reference.
- Improved visual alignment within menus by using hidden checkmarks on unselected items, ensuring consistent indentation across all options.
- Resolved styling and linting issues (unused variables, JSX bind warnings) within the new component.
@ufuksarp
Copy link
Copy Markdown
Contributor

ufuksarp commented Apr 9, 2026

@skunkworxdark Ah, I thought the model selection was a multi-select with the checkmarks and all just seeing the images. My bad. Testing the PR now locally, all seems fine.

@skunkworxdark
Copy link
Copy Markdown
Contributor Author

skunkworxdark commented Apr 9, 2026

@skunkworxdark Ah, I thought the model selection was a multi-select with the checkmarks and all just seeing the images. My bad. Testing the PR now locally, all seems fine.

The model type filter selection hasn't been changed; it has only been rolled into a single dropdown menu along with the sort by and direction options to keep the header section clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api frontend PRs that change frontend files python PRs that change python files python-tests PRs that change python tests services PRs that change app services v6.13.x

Projects

Status: 6.13.x Theme: MODELS

Development

Successfully merging this pull request may close these issues.

5 participants