SOLVED! I'm using my own github fork of Avo and I...
# avo-2
b
SOLVED! I'm using my own github fork of Avo and I needed to
rake app:avo:build-assets
there to get the updated CSS in my app.
l
Hey man, I wonder what can I do to convince you to bring your updates into Avo and use the same version from rubygems 😅
I'm curious what modifications you made. Maybe more people would benefit from them
b
Prepare to be underwhelmed! This is the only commit I have in my fork: https://github.com/coderifous/avo/commit/e2ed2ef0ce3d49c85dce59d5c4edc3bd9a52812b
It addressed an issue that I imagine is either very rare, or the result of doing something ill-advised. The commit message attempts to explain it completely - but it's a one line change and ... with great shame ... no test update.
l
haha
got it
I wonder if that should be in the main branch
I also see some counters on the sidebar items
I think those got my attention
b
Oh! I accomplished this by adding this module in my project at `app/concerns/navigation_label_with_count.rb`:
Copy code
module NavigationLabelWithCount

  def navigation_label
    <<-HTML
    <div class="w-full flex justify-between pr-3">
      <div>#{plural_name}</div>
      <div>#{resource_count_html}</div>
    </div>
    HTML
    .html_safe
  end

  private

  def resource_count_html
    c = resource_count
    return if c == 0
    <<-HTML
    <span class="#{resource_count_tailwind_classes(c)}">
      #{resource_count}
    </span>
    HTML
  end

  def resource_count
    resolve_query_scope.call(model_class: model_class).count
  end

  def resource_count_tailwind_classes(c)
    classes = %w(
      text-white
      px-2
      py-0.5
      text-xs
      rounded-full
    )
    if c == 0
      classes << "bg-gray-300"
    else
      classes << "bg-blue-500"
    end
    classes.join(" ")
  end

end
Then I just include that module on the resources I want to show a count in the sidebar:
include NavigationLabelWithCount
l
no way!
that's so cool
you didn't even have to override the view component
you're so smart!
b
I'm actually a bit ignorant when it comes to View Components! I haven't used them in past projects, but I've read about them and thought "I should really bring that into my tool kit". So, Adrian... 🧐 was that your very gentle and kind way of hinting that a more elegant and less surprising approach to this would be to override the view component? 🤣
l
I would actually say that your solution is more elegant
instead of overriding a whole component, you gently "nudged" the
navigation_label
to do what you need it to do
it's more verbose doing it your way, but it's more resiliant in future Avo updates
but yes, if you want to, you can override the view component inside your parent app
Rails will pick that up and use your version
b
It's been a while since I implemented that - I wonder how brittle it is - e.g. what if
navigation_label
changes/goes away in the future. I don't remember whether it was a documented method or whether I just looked through the Avo source code and said "ah, I can override that method and have the outcome I need". I appreciate the kind appraisal! I think you're doing a great job of running Avo and you present such a positive and welcoming attitude, and Avo just keeps getting better. I'm at the outset of a significant project build for a client, and I'm trying to leverage Avo for nearly all of the "business user" functionality. I'll be getting into the really custom needs in the next week or two, and expect I'll be getting deep into Custom Tools and Resource Tools. I'll keep an eye out for any types of needs that aren't immediately or easily met by the available customization options, and maybe they'll be good material for feedback. When my work load becomes a bit less intense, I'd love to contribute back to Avo with some code.
l
> I don't remember whether it was a documented method or whether I just looked through the Avo source code I can answer that. You probably digged through the code. I purposely don't "officially" document internal methods because they change a lot over time. That will happen for a while as Avo gets more and more stable and we figure out all the proper abstractions.
> I think you're doing a great job of running Avo and you present such a positive and welcoming attitude, and Avo just keeps getting better. I'm at the outset of a significant project build for a client, and I'm trying to leverage Avo for nearly all of the "business user" functionality Can I use this on our website as a testmonial?
and thank you for saying that 🙏
> and maybe they'll be good material for feedback Yes. please come back with feedback. good and bad. This is how we make Avo better
> I'd love to contribute back to Avo with some code. Do that too please 🙂
we're quite friendly on the GitHub repo
we merge quite a few commits from external contributors over the last year