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

Sortable arrow/icon in all sort links #754

Closed
brunofacca opened this issue Jan 24, 2017 · 10 comments
Closed

Sortable arrow/icon in all sort links #754

brunofacca opened this issue Jan 24, 2017 · 10 comments

Comments

@brunofacca
Copy link

Inexperienced users may not realize that columns are sortable just because their header names contain links. I have monkey patched Ransack to include a bidirectional vertical arrow in all sort links to explicitly indicate that those columns are sortable. I'd like to open a pull request. Are you interested in adding this feature to Ransack?

The main change would be in Ransack::Helpers::FormHelper::SortLink

def order_indicator
  return if @hide_indicator
  if no_sort_direction_specified?
    initial_arrow
  elsif @current_dir == 'desc'.freeze
    up_arrow
  else
    down_arrow
  end
end

I have also modified Ransack::Configuration to allow customization of the bidirectional arrow.

@scarroll32
Copy link
Member

I think this could be a great optional feature, esp. if it allows passing an icon.

@scarroll32
Copy link
Member

Pull requests welcome

@brunofacca
Copy link
Author

Thanks. I will submit a PR.

Would you like this feature to be turned on or off by default?

I'm thinking about naming that character/icon "initial_arrow", "sortable_icon" or "sortable_indicator". What do you think?

I can think of two ways to make this feature optional:

  • Add a config option such as initial_arrow whose value can be an empty string to turn off the feature or an actual character/icon (e.g., ↕) to turn it on.
  • Add an option to the config (e.g., hide_sortable_icon or hide_initial_sort_arrow) to switch the feature on or off.

Which do you think its best?

@scarroll32
Copy link
Member

Just thinking about this again ... It is possible to add any markup already.

<%= sort_link(@q, :name) do %>
  <strong>Player Name</strong>
<% end %>

What about a version of the sort_link helper which more easily includes an icon. I think it is better to create a new helper and leave the existing one as-is.

Font Awesome are pretty much the main open source font library, we could use something like

sort_fa_icon_link and then pass the name of the Font Awesome icon.

What do you think?

@brunofacca
Copy link
Author

I was thinking about something like the following in Ransack::Helpers::FormHelper

def order_indicator
  return if @hide_indicator
  if no_sort_direction_specified?
    initial_arrow
  elsif @current_dir == 'desc'.freeze
    up_arrow
  else
    down_arrow
  end
end

Plus adding an option to allow customizing the "initial arrow" in the config and, of course, the corresponding tests.

@abali96
Copy link

abali96 commented Jun 13, 2017

Hey! Was this submitted? I would love to use this feature!

@brunofacca
Copy link
Author

Hey @abali96. This was not yet submitted.

@seanfcarroll, I had most of the code ready before we started discussing implementation details. If you still think the feature is useful and you're ok with it being implemented as I described in this comment, I can open a PR. If positive, your feedback about these design decisions would be valuable.

@scarroll32
Copy link
Member

@brunofacca sorry for the delay in responding. I'd vote for the config option

Add a config option such as initial_arrow whose value can be an empty string to turn off the feature or an actual character/icon (e.g., ↕) to turn it on.

@brunofacca
Copy link
Author

No problem @seanfcarroll. Unfortunately, I no longer have any free time to implement this. I suggest we close this issue and I will reopen it if/when the required time comes up.

@scarroll32
Copy link
Member

Closed.

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

3 participants