- For listing members in a group, the backend code accepts
order
andasc
parameters to order by a specific field in ascending/descending order. When theasc
parameter is present and non-blank, it is the ascending order, otherwise descending. - The frontend code of the group members page also seems to be able to parse query parameters and pass to the backend.
asc
istrue
by default on the frontend.
When I navigate to this link: https://try.discourse.org/g/trust_level_2?order=added_at&asc=, I expect this to be a direct link to show me TL2 members ordered by Added time in descending order, without having to manually click on the table header to toggle ordering.
However the actual behavior is that: it shows TL2 members ordered by Added time in ascending order, yet with a “chevron-down” icon (suggesting that it should have shown in descending order instead):
Looking at the Network tab in DevTools, the page issued a request of https://try.discourse.org/groups/trust_level_2/members.json?offset=0&order=added_at&asc=false&filter=, instead of https://try.discourse.org/groups/trust_level_2/members.json?offset=0&order=added_at&asc=&filter=.
As all URL parameters are strings, asc=false
will be considered as non-blank by the params[:asc] && params[:asc].present?
logic, thus returning ascending result. Perhaps the frontend code should convert the Boolean false
value of asc
to an empty string in the URL parameter?