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

Filter Models [enhancement] #455

Closed
pete-the-pete opened this issue Aug 21, 2015 · 19 comments
Closed

Filter Models [enhancement] #455

pete-the-pete opened this issue Aug 21, 2015 · 19 comments

Comments

@pete-the-pete
Copy link
Contributor

i'd like to be able to filter models:

  • hide empty models
  • only show models used by the current route

I'm assuming hiding empty is an easier task. I'm more than happy to do the work, but any tips on how to approach it are appreciated.

@pete-the-pete pete-the-pete changed the title Filter Models Filter Models [enhancement] Aug 21, 2015
@teddyzeenny
Copy link
Contributor

Can you say more about what you mean by empty models? Model types that don't have any records in the store?

@pete-the-pete
Copy link
Contributor Author

Exactly. Just a simple filter so that only models with records in the store are displayed. I started looking into it a little, I think I could get something to play with early next week.

@vvscode
Copy link
Contributor

vvscode commented Aug 28, 2015

Can you describe how can I filter models which used at current route? I want to help, but I can't find idea how to implement that filter. Thx

@teddyzeenny
Copy link
Contributor

Can you clarify what you mean by "used at current route"? Has a record that is rendered in the template? Has a record set as currentModel in an active route? Has a record inside an object/array currentModel?
Are you suggesting a filter for the "active" model classes or for the records themselves?

@vvscode
Copy link
Contributor

vvscode commented Aug 31, 2015

It was a quote from start message

"only show models used by the current route"

So the question is for @pete-the-pete I suppose

@pete-the-pete
Copy link
Contributor Author

I was suggesting the 'active' model classes, not necessarily the records themselves. I was thinking something similar to the View Tree filter options. So, yes to "Has a record set as currentModel in an active route? Has a record inside an object/array currentModel", but no to "Has a record that is rendered in the template?"

@stefanpenner
Copy link
Member

seems like this would be a better explored via the route explorer then no?

@pete-the-pete
Copy link
Contributor Author

My request is coming from personal experience; when I wanted to explore the data/models, the Data explorer of ember inspector is pretty noisy (we have too many models in our project). I was thinking of how I could add some additional filtering within that tab to make exploring the models easier.

Adding something to the Route explorer is an interesting idea, I like that it would tie everything together. , Maybe another column that lists all the models, or a link to the filtered list of models in the Data explorer.

@vvscode
Copy link
Contributor

vvscode commented Sep 1, 2015

@pete-the-pete can you explain how can I filter models which are used by current scope of routes?

@teddyzeenny
Copy link
Contributor

@pete-the-pete would adding a model type search field help solve the problem of many models?

@pete-the-pete
Copy link
Contributor Author

@teddyzeenny it could. The more I think about it, the more I think I'd want the Data explorer to have relative parity with the View explorer, which would include search. The View and Route explorers have the topbar with subnav/filter controls that make sense for that type of module, I'd like to have the data explorer have something similar.

@vvscode, I'm not sure yet, I'm starting to look into the code. Maybe I can use modelFor to find the route's current models, and then filter other models based on the relationships they have.

@teddyzeenny
Copy link
Contributor

I'm not convinced yet with the "used by current route" feature yet as it is not very clear which models it really filters.

  • Should we take relationships into account?
  • What if a model is being used but not set as the route's currentModel? Why not include it?
  • What if the model returned an object containing several models?
  • What if the model returned an array that contains different models?
  • Why only filter model types and not filter the records themselves?

I feel like adding search can help reduce noise without any of the complications.

@pete-the-pete
Copy link
Contributor Author

@teddyzeenny, I agree the 'used by current route' needs more clarity. How do you feel about the nonEmpty filter? I started looking into that as its own feature, and to get familiar with the code.

If you're ok with that feature, maybe we could treat it as a first pass, and sort out what other enhancements to add as separate/follow up efforts; search, current route, showing the models in the Routes explorer as @stefanpenner mentioned.

@vvscode
Copy link
Contributor

vvscode commented Sep 2, 2015

@pete-the-pete 'Hide empty models' already merged into ( see above )

@vvscode
Copy link
Contributor

vvscode commented Sep 2, 2015

@pete-the-pete @teddyzeenny What about adding search box to model-type topbar ( enter json and get filtered models with container.store.all(modelType).filter(.... ) ) ?

@pete-the-pete
Copy link
Contributor Author

Ha, I should have been watching the PRs too...oh, well, I got some more exposure to the code.

@vvscode search could be good. My project has way too many models, so search could help a developer get exposed to the many different types much easier than browsing. I also like that it makes the different explorers (Data, Routes, Views) consistent. @teddyzeenny what do you think?

@vvscode let me know how I can help with the actual coding.

@pete-the-pete
Copy link
Contributor Author

the filter works great by the way, thanks for getting that in

@pete-the-pete
Copy link
Contributor Author

I've been thinking about how to define this better, and have come up with the following:

ModelTypes for Current Route:

Add an option to filter models used by the current route (similar to View Tree filter), similar to the new 'Hide Empty Models' filter.

The 'non empty' filter should apply to the routes filtered for the current model. This is tricky
for a couple reasons, at least 3 are:

  1. Routes can return a model in different forms (Object, Array, Map):
  2. Relationships: how deep do you go?
  3. Records: the same model could have multiple records used across routes, do they need to get filtered as well?

I think first pass could provide a solution for 1 and 2, while a more robust solution, and addressing 3 could come later.

First Pass:

Solving 1 is the base case, there are different ways a route can return from a model hook, but not infinitely many. I think it would be possible to pull out the models from currentModel. A default fallback could be used to avoid explicit errors (showing no models for ex):

  • This would enable the 'Model Column in Routes explorer' idea @stefanpenner brought up.
  • These models would be the only ones shown in the 'Model Types' list. Additional models would be added to the list as the user drilled down into the relationships.
  • Records would not be filtered by route, all records for a given model type would still be loaded.

Ideally the list of models by type would be maintained, so that switching between routes, or toggling the filter wouldn't be too costly. This gets into other issues/questions about how store and maintain this list in EmberInspector:

  • should it even be stored?
  • how would it be stored (should be fast and light)
  • build it onload of the data route (regardless of filter)
  • build it when the filter is enabled
  • build it when the route changes

Later:

Assuming a data structure was used to store the models by route, the relationships could be added to the filtered list programmatically, before the user drills down. Traversing the model relationships, starting from those found in currentModel, should give the relevant records. They wouldn't necessarily be the records used exclusively by the current route, but that's fine, and desirable.

Models in routes explorer:

  • show model types use in a route's model hook
    • should be per route, so parent models do not show in child route
  • show in the far right column
  • link to Data explorer, with model selected

@RobbieTheWagner
Copy link
Member

Since this was merged in a long time ago, closing this issue.

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

No branches or pull requests

5 participants