Skip to content

Improve flexibility for options on collection_order_toggle_indicator component #13

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

Open
aaron-contreras opened this issue Apr 16, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@aaron-contreras
Copy link
Member

Currently, the way to provide what we render for default, ascending and descending sort options for the collection_order_toggle_indicator component is only via a "text" option. Also, options for asc and desc are rendered as "unescaped", while the default option gets rendered as plaintext. I can see the why behind this (perhaps to provide some unicode characters as the ascending and descending arrows and wanting those to be unescaped).

I feel a bit limited by the current behavior. Instead, I'd like to use arrow bs_icons for example on matestack-ui-bootstrap for these or provide my own rendering or template for what these should render. I propose using slots somewhat similar to the interface as we have in bs_card on matestack-ui-bootstrap, where you can provide a body via a text option or define a method that provides the rendering for body and add it as a slot.

Also, I'd like default, asc, and desc as text to all render as plaintext and not some plaintext and some unescaped. If we want unescaped text for asc and desc we could have the text be unescaped from the caller's side. This is more flexible in my opinion and doesn't hide the fact that whatever string/text is passed in as an argument is unescaped.

An example of the desired API would look something like this:

# EXAMPLE 1
# all rendered as plaintext

collection_order_toggle_indicator(
  key: :title,
  default: "unsorted",
  asc: "asc",
  desc: "desc"
)

# EXAMPLE 2
# or some as custom provided slots

collection_order_toggle_indicator(
  key: :title,
  default: "unsorted",
  slots: {
    asc: method(:asc_partial)
  }
  desc: "desc"
)

def asc_partial
  span do
     plain "I came from a method"
  end
end

# EXAMPLE 3
# or all as custom provided slots

collection_order_toggle_indicator(
  key: :title,
  slots: {
    default: method(:default_partial),
    asc: method(:asc_partial),
    desc: method(:desc_partial)
  }
)

def default_partial
  plain "We all came from a method"
end

def asc_partial
  plain "We all came from a method"
end

def desc_partial
  plain "We all came from a method"
end
@aaron-contreras aaron-contreras added the enhancement New feature or request label Apr 16, 2023
@aaron-contreras aaron-contreras changed the title Flexibility for default, asc, and desc options on collection_order_toggle_indicator component Improve flexibility for options on collection_order_toggle_indicator component Apr 16, 2023
@aaron-contreras
Copy link
Member Author

aaron-contreras commented Apr 16, 2023

Experimented and cooked something up to demonstrate what I wanted to achieve on the dummy app for matestack-ui-bootstrap. Let me know your thoughts 😉 @jonasjabari . This is using sort-up and sort-down bootstrap icons and the code snippet looks like this:

NOTE:
In case you're wondering where this sorting capability on the smart collection component is coming from, this is provided by some other features I'm building on it to allow for this. It's not a current feature on main or develop.

def table_head
  #...
  collection_order_toggle_indicator key: key,
                                    slots: {
                                      asc: method(:asc_partial),
                                      desc: method(:desc_partial)
                                    }
  #...
end

def asc_partial
  bs_icon name: 'sort-up'
end

def desc_partial
  bs_icon name: 'sort-down'
end

Screenshot 2023-04-15 at 23 08 03

@jonasjabari
Copy link
Member

@aaron-contreras I like this idea! Feel free to work on this improvement!
Thinking about sorting - just as a note - I feel like a dropdown which enables the user to select a column which should be used for sorting could be a nice and generic way to enable sorting as well. A second dropdown for asc/desc would be required then as well. This approach of sorting would also work with a non-table way of display the collection content (e.g. in cards like seen here: https://dummy.matestack.io/dummy/products) (I guess this is just another improvement we can tackle afterwards)

@aaron-contreras
Copy link
Member Author

@jonasjabari Nice. I had a similar thought. My idea of it was that I could provide in the collection_config

{
  sorting: true # or sortable?
  columns: {
    # columns defined here
  }
}

and this would enable sorting on all columns being the standard case.

However, if I wanted to provide a custom sorting slot that would be used like you indicated in a non-table way or in any other scenario, I could do something like this which would generate the corresponding dropdowns you talked about:

{
  sorting: {
    some_column_name: {
      text: "Sort by some_column_name",
      default: :asc
    },
    # all columns I would like to provide the dropdowns for sorting
  }
}

or if I want to provide my own sorting rendering

{
  slots: {
    collection_rendering: method(:my_collection_rendering),
    sort_rendering: method(:my_sort_rendering)
  }
}

@aaron-contreras aaron-contreras self-assigned this May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants