Skip to content

Conversation

jdufresne
Copy link
Member

In my project, several STI models have the same label stored in their translation file. This is because, from the user's perspective, they represent the same abstract concept, even if the developers know differently.

This can sometimes be an issue when rendering the main navigation. As the labels are equal, the listed models can be displayed in either order. It would be better to always display models in a single consistent and deterministic order. This is especially an issue for my project as the end-to-end tests rely on this order to assert correct behavior.

In my project, several STI models have the same label stored in their
translation file. This is because, from the user's perspective, they
represent the same abstract concept, even if the developers know
differently.

This can sometimes be an issue when rendering the main navigation. As
the labels are equal, the listed models can be displayed in either
order. It would be better to always display models in a single
consistent and deterministic order. This is especially an issue for my
project as the end-to-end tests rely on this order to assert correct
behavior.
# for a deterministic ordering.
result = a.model.name.casecmp(b.model.name)
end
result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having something like this can be simpler?

      def visible_models(bindings)
        visible_models_with_bindings(bindings).sort_by do |model|
          [model.weight, model.label.downcase, model.model.name.downcase]
        end
      end

@mshibuya
Copy link
Member

mshibuya commented Mar 9, 2025

Could you add tests for this? 🙏

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

Successfully merging this pull request may close these issues.

2 participants