Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Add spec_url display/filter support #383

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sideshowbarker
Copy link

@sideshowbarker sideshowbarker commented Jan 6, 2020

For any BCD feature that has a spec_url value: this change adds support for displaying, in the same section of the Web UI where any existing "MDN" link is displayed, a link to the relevant spec.

This change also adds support for filtering feature searches based on the presence of a spec URL.


Note: It’s (unfortunately) possible for a BCD feature to be associated with multiple specs; so the spec_url value in BCD can be either a string or an array of strings.

Therefore, to handle the possible cases, the patch in this pull request does this:

<% if feature.spec_url %>
  <% if feature.spec_url.start_with?('[') %>
    <span class="card-link">Spec:</span>
    <% specURLs = feature.spec_url.tr('[]""','').split(',') %>
    <% specURLs.each_with_index { |specURL, index| %>
      <%= link_to (index + 1).to_s, specURL.strip, class: "card-link spec-link" %>
    <% } %>
  <% else %>
    <%= link_to "Spec", feature.spec_url, class: "card-link spec-link" %>
  <% end %>
<% end %>

…which isn’t pretty — but the alternative of making the code handle it otherwise is bit beyond my rudimentary Rails and Postgres skills; specifically, I don’t really know how to:

  1. deal with reading the spec_url value properly from the BCD data to begin with given fact that the value in BCD can be either a string or an array
  2. store the spec_url value in the database with the right datatype (always store it as an array?) or datatypes (sometimes as a string, sometimes as an array?), and
  3. read the spec_url value back from the database in the right way

But all that said, if what the existing patch is doing is just too ugly, and if I could get some guidance on how to do it better, I’d be happy to put some more time into refining this.

For any BCD feature that has a spec_url value: this change adds support
for displaying, in the same section of the Web UI where any existing
"MDN" link is displayed, a link to the relevant specification.

This change also adds support for filtering feature searches based on
the presence of a spec URL.
This is still a kludge, but it’s at least better than an ad-hoc
.tr() + .split hack...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant