Hey, all. I'm evaluating Avo for a larger producti...
# avo-2
c
Hey, all. I'm evaluating Avo for a larger production application with a high volume of records. In this case, I would like to be able to show nested resources in the traditional rails nested resource routing: Ie. /avo/resources/companies/123/employees. Is this something I can do in Avo?
l
I guess that's a
has_many
association. yes. it can handle that
it handles all Rails associations
c
I see how I can include it on the show page. Can I also create a 'drill down' page to see those associated items on their own page?
l
just like Rails, with Avo it's a good rule of thumb to lean into it rather than trying to build everything in one particular style
how do you mean "drill down"?
can you share an example?
c
Sure. From a company show page, I'd like to link to a page that shows the company's employees. That page would only show employees of the company, and any additional filtering or searching would be within that company scope.
l
yup. that's
has_many
I'll share an example
check out the "team members" somewhere at mid-page below
those are only members of that team
you can attach/detach them and create new ones that will automatically be attached to that team
those are actually
has_and_belongs_to_many
records
the memberships below are the pivot models
c
I love what I'm seeing for team members. But can I move that to its own page?
l
like what page?
c
/avo/resources/teams/4/team_members
l
hmmm. never thought about that
c
So instead of viewing the has_many on the show page, I'd like to have them separate.
l
and see only the association
c
Right
Dealing with hundreds or thousands of records, this would be much preferred.
l
those are turbo frames, so if you inspect the frame you should get the link to that page
c
I also have several associations. That makes for one HUGE show page for the central model.
l
you can group them into tabs
which are lazy-loaded
you're looking for this, right?
Yeah. That's it.
l
oh yeah
even better
without the frame
c
Now we're just missing a heading or breadcrumbs that shows us what company these team members belong to.
l
I think you're better off with a different resource
so instead of a
UserResource
, you create a new
TeamUserResource
on which you set the
self.model_class = "User"
and set a custom scope on that
Copy code
ruby
class TeamUserResource < Avo::BaseResource
  self.model_class = "User"
  self.resolve_query_scope = ->(model_class:) do
    model_class.where(team_id: params[:team_id])
  end
end
c
Oh. Ok.
l
and you go to
avo/resources/team_users?team_id=123
and you'll get less side-effects
c
Sure
l
the
resolve_query_scope
will apply that scope to the index query
c
Is there a similar approach for creating a model based dashboard? Using the company example, could I have a dashboard that's full of metrics scoped to a single company?
l
c
haha
l
that has to be dynamic, right?
I mean, you have 1 million companies, not 2-3
c
With potentially thousands of companies, yes.
l
you can with a param
same approach
you have access to
params
almost everywhere
so in cards, you check the
company_id
param and query the data that way
c
I could create a dashboard, hide it from the main nav, and then use params in each card. Ok.
l
yup👆
I know the feature you're looking for, and we don't have it yet
dashboard-wide scoping
in theory you can do it yourself
1. have the dashboard on the menu 2. when a use clicks it will not have the company_id param 3 you use that and ide the cards. display an "empty state" card with some copy 4. add some links/build a search that queries for companies 5. when a user clicks on the company, you redirect to the same dashboard with that param 6. when the param is present, all the "good" cards appear on the page
c
cool
Thanks, Adrian!
l
for sure!
anytime
c
Avo is a beautiful product. There's a need for it in the market.
The other tools do a great job getting you about 70% of the way there. But the remaining 30% is excruciating.
Avo is much more elegant.
l
I know the pain and we work constantly to not get to that 70/30 ratio
like any tool, it's difficult impossible to cover 100% of use-cases, but we'd like to get close to that
thanks for the kind words
4 Views