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

feat: sort labels by name,asc in shopping lists #4253

Merged
merged 8 commits into from
Sep 24, 2024
Merged

feat: sort labels by name,asc in shopping lists #4253

merged 8 commits into from
Sep 24, 2024

Conversation

seamuslowry
Copy link
Contributor

@seamuslowry seamuslowry commented Sep 22, 2024

What type of PR is this?

  • feature

What this PR does / why we need it:

This is an initial (partial) implementation of the request in this discussion: #3297.

In controller_labels.py it extends the PaginationQuery class to override the default values for order_by and order_direction so that call to this endpoint will use those as the default, rather than using nothing.

Update frontend/pages/shopping-lists/_id.vue to pass orderBy: "name" and orderDirection: "asc" on label refreshes

Which issue(s) this PR fixes:

No issues reference this specifically. This is intended as an initial step towards the feature requested in This is an initial implementation of the request in this discussion: #3297.

Special notes for your reviewer:

I am not experienced with FastAPI or Mealie conventions. I am happy to apply the same pattern to the paginated GET requests of the other listed models, but I wanted to get some input on the pattern and implementation before copying the pattern around.

Testing

  • in Swagger UI, I tested passing other values for order_by and order_direction to verify they were used over the new defaults. Similarly, tested with other pre-existing values like per_page to ensure they were still respected.
  • in the UI, I validated that the request to get labels when adding a new item to a shopping list (which wasn't specifying order_by and order_direction is now specifying name and asc

@seamuslowry seamuslowry changed the title feat: sort labels by name,desc by default feat: sort labels by name,asc by default Sep 22, 2024
@michael-genson
Copy link
Collaborator

I don't think this is something we want to do on the backend; is there somewhere in particular on the frontend you labels aren't sorted alphabetically? If so, we should address it there

@seamuslowry
Copy link
Contributor Author

seamuslowry commented Sep 24, 2024

I've only noted seeing it when trying to add an item to a shopping list

image

I thought it would make sense to change the defaults for the endpoint, get it for free everywhere that doesn't specify. But I'm happy to make it in that one spot on the frontend instead

@seamuslowry seamuslowry changed the title feat: sort labels by name,asc by default feat: sort labels by name,asc in shopping lists Sep 24, 2024
@michael-genson
Copy link
Collaborator

michael-genson commented Sep 24, 2024

Ah okay, that makes sense. Is it possible to use the label store here instead of using userApi? The store defaults to name ascending, and it would save us an API call (we're already using the label store in that same file). Something like:

const { store: allLabels, actions: labelActions } = useLabelStore();  // this already partially exists on line 605

And then we can just call actions.refresh() and get rid of refreshLabels (and allLabels will automatically be updated).

@seamuslowry
Copy link
Contributor Author

seamuslowry commented Sep 24, 2024

Updated. But I used labelActions.getAll rather than labelActions.refresh

The refresh call seems to call the api directly without specifying any defaults: https://github.com/mealie-recipes/mealie/blob/mealie-next/frontend/composables/partials/use-actions-factory.ts#L106. So it does not resolve the issue.

Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping with this one!

@michael-genson michael-genson enabled auto-merge (squash) September 24, 2024 21:26
@michael-genson michael-genson merged commit 2053f29 into mealie-recipes:mealie-next Sep 24, 2024
13 checks passed
boc-the-git pushed a commit to boc-the-git/mealie that referenced this pull request Sep 28, 2024
boc-the-git pushed a commit to boc-the-git/mealie that referenced this pull request Sep 28, 2024
Choromanski pushed a commit to Choromanski/mealie that referenced this pull request Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants