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

Advanced View List Header Labels #16

Open
jordanstephens opened this issue Feb 1, 2021 · 1 comment
Open

Advanced View List Header Labels #16

jordanstephens opened this issue Feb 1, 2021 · 1 comment

Comments

@jordanstephens
Copy link

Hello!

I'm investigating adding support for specifying the label to display in the advanced view list's collapsible header. For example, in the image below, I might like to replace "SKILL - 1" with "Ruby."

advanced_view_object

I'm planning to open a PR with the changes I make, so I want to try to make a change that you might merge upstream.

While investigating how I might add support for this, I noticed in this file app/views/fields/jsonb/_hash.html.erb:

<% structure.each do |sk, sv| %>
  <% if sv.is_a?(Hash) %>
    <dt class='attribute-label administrate-field-jsonb-accordion'><%= sk.to_s.titleize %></dt>
    <dd class='administrate-field-jsonb-panel'>
      <dl class='administrate-field-jsonb-box'>
        <% if data[sk].is_a?(Array) %> <% # <------------------ when is this branch triggered? %>
          <%= render field.to_partial_path('array'),
            field: field, structure: structure[sk], data: data[sk], label: sk.to_s.singularize.titleize %>
        <% else %>
          <% # ... %>
        <% end %>
      <dl>
    </dd>
  <% else %>
    <% # ... %>
  <% end %>
<% end %>

While iterating over the hash attributes, you check if sv.is_a?(Hash), then later in that same block you check if data[sk].is_a?(Array). It's not clear to me how this branch of code gets executed.

I don't see any examples in the README that have a hash value in the structure, and I don't see any tests at all. Would it be possible for you to provide an example configuration which would exercise this branch?

If I extend the API to support array header labels, I want to try my best to do it in a backwards compatible way. 👍

Thank you!

@volkov-sergey
Copy link
Member

Hi @jordanstephens, thanks for your interest in this gem!

About your question:

Let's start from the root file app/views/fields/jsonb/_show.html.erb, since both

{
  "foo": "bar"
}

and

["foo", "bar"]

are valid JSONs we need the first check.

Also JSON can have such structure

{
  "foo": ["one", "two"]
}

or

{
  "foo": [
    {
      "bar": 1
    }
  ]
}

In this case first check (app/views/fields/jsonb/_show.html.erb) will forward us to _hash.html.erb and this line _hash.html.erb#L6 will be something like: { "foo": ["one", "two"] }["foo"].is_a?(Array)

Hope this makes sense. Thanks!

Do you already have an idea about implementation your feature?

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

No branches or pull requests

2 participants