troessner/transitions

available_state available_events should list states or events in the order they are defined

Closed this issue · 4 comments

itkin commented

Hello,

Would be nice if available_states and availabe_events would not sort states/events but display them in the order they are defined.

Would allow to use these methods to quickly build buttons groups where the order often matters

Is there any reason you did otherwise ?

Sincerely

Would be nice if available_states and availabe_events would not sort states/events but display them in the order they are defined.

But the order in which states were defined does not convey any valuable information. You can group them however you want in the source code, but at runtime the initial order is irrelevant.

Would allow to use these methods to quickly build buttons groups where the order often matters

Even if transitions would support this you'd still have to "know" where one group starts and ends since there is no "grouping" concept for states yet, or am I missing something?

itkin commented

hi! You're right about the absence of "grouping" concept and I do agree with you for complex state machine it's irrelevant, but for simple ones where states flow reprensents a kind of linear progression it may make more sense...

For example :

state_machine auto_scopes: true do
  state :unactive
  state :pending_validation
  state :active
  state :terminated
end

I was coding an admin backend using ActiveAdmin and wanted to implement scope filters buttons (to filter my list of offers by their state). That's how it could be done :

Offer.available_states.each do |state|
  scope state
end

Note that in this case my users expect to have the buttons displayed from the unactive state to the terminated one

Well this is not the feature of the year, but i think one would "naively" expect states/events to be listed in the order they have been defined, and since you store (at least the states) in an array and since it doesn't have any purpose to list them alphabetically, why not simply "not sort" :-)

Thanks for your nice gem !

Well this is not the feature of the year, but i think one would "naively" expect states/events to be listed in the order they have been defined, and since you store (at least the states) in an array and since it doesn't have any purpose to list them alphabetically, why not simply "not sort" :-)

I agree with you. I can see how this is more intuitive towards the user expects.
Actually that should be almost trivial to change.
If you'd come up with a pull request I'd be happy to merge this one ;)

itkin commented

deal ! :-)