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

Add ability to sort comments #16133

Open
ludwiczakpawel opened this issue Jan 17, 2022 · 19 comments
Open

Add ability to sort comments #16133

ludwiczakpawel opened this issue Jan 17, 2022 · 19 comments
Assignees
Labels
area: comments & notifications area concerning interactions or notifications with user changelog: rollup Items that will be communicated in our monthly rollup changelogs tech: fullstack changes will heavily involve both frontend and backend technologies

Comments

@ludwiczakpawel
Copy link
Contributor

ludwiczakpawel commented Jan 17, 2022

This piggy-backs #3001.


Description

  • As a user I want to be able to sort comments.
  • [Stretch goal] As an admin I want to define default sorting option for discussions on my Forem.

1. Admin: community-level

Admin of a community should have a setting somewhere in /admin to set default sorting for their community discussions.

2. User-level

User should be able to set/overwrite default sorting for comments. Something like:

image

3. User, post-level

User should be able to overwrite global settings and his own preference for particular post only.

image

Importance, order of work:

Above I ordered it from the most global (community-level) to the most granular type of settings (user- & post-level). But implementation wise I think we should build it in the opposite order (post-level first, then user-level and finally community-level) because this feature seems like something that would be the most useful for users in general rather than admins.

Caveats

  • For the scope of this project, I don't think we need to consider anything but top-level comments.
@github-actions
Copy link
Contributor

Thanks for the issue, we will take it into consideration! Our team of engineers is busy working on many types of features, please give us time to get back to you.

Feature requests that require more discussion may be closed. Read more about our feature request process on forem.dev.

To our amazing contributors: issues labeled type: bug are always up for grabs, but for feature requests, please wait until we add a ready for dev before starting to work on it.

To claim an issue to work on, please leave a comment. If you've claimed the issue and need help, please ping @forem/oss. The OSS Community Manager or the engineers on OSS rotation will follow up.

For full info on how to contribute, please check out our contributors guide.

@amywtlin
Copy link

@jeremyf out of all 3, 3 would be a good candidate for CE pod to tackle if anyone has time or would like to change things up a little!

@nickytonline nickytonline added area: comments & notifications area concerning interactions or notifications with user tech: fullstack changes will heavily involve both frontend and backend technologies labels Jan 18, 2022
@vishaldeepak
Copy link
Contributor

any chance this issue is open for dev ?

@jeremyf
Copy link
Contributor

jeremyf commented Jan 27, 2022

@vishaldeepak as in you'd be up for tackling this? If so, I'd love to hear your approach.

@vishaldeepak
Copy link
Contributor

@jeremyf Thinking about point no 3 first.(Backend)
Looks like sorting things should be quite straightforward.
From the UI we can ask for another parameter that defines the sorting sequence. Then we would add another parameter to the following method

def self.tree_for(commentable, limit = 0, sorting_sequence="score DESC")
    # make change here
    commentable.comments
      .includes(user: %i[setting profile])
      .arrange(order: sorting_sequence)
      .to_a[0..limit - 1]
      .to_h
end

All sorts should be

  • "created_at desc"
  • "created_at asc"
  • "score desc"

As for the cache we might want to add a new parameter

<%= render partial: "articles/comment_tree", collection: Comment.tree_for(@article, @comments_to_show_count), as: :comment_node, cached: proc { |comment, _sub_comments| [comment, sort_order] } %>

Point No 2
Should be similar to other customization settings.

On the front-end side we could refresh the page when user wants to change the sort or dynamically load the comments view again.

Anything else I should be aware of/or missing?

@vishaldeepak
Copy link
Contributor

@jeremyf can I start given the above?

@jeremyf
Copy link
Contributor

jeremyf commented Feb 11, 2022

Go for it! I'll assign this to you and me both, so we have a core member tracking this. Please ping me if you get stuck or need help with something. Your approach looks good.

@jeremyf
Copy link
Contributor

jeremyf commented Feb 18, 2022

@vishaldeepak checking in on where you're at with this.

@vishaldeepak
Copy link
Contributor

@jeremyf Was too busy. A need a litte more time. Maybe il have a PR in a weeks time.

@amywtlin amywtlin added the changelog: rollup Items that will be communicated in our monthly rollup changelogs label Feb 24, 2022
@djuber
Copy link
Contributor

djuber commented Apr 1, 2022

catching up on this now to determine if the work in #16686 closes this issue (or just part of it).

It looks like the user controlled sorting was added, but the admin option to set a community default sort order is an open goal. Do we want to open a new more focused issue about admin controlled default comment sort option, or refine the description to highlight that the original goals have been partly met?

I left a comment proposing Settings::UserExperience.comment_default_sort_order as the admin facing customization to add and what that looks like in the controller on the PR - it might be a small win to add a setting with a default value to the user experience customization in admin.

@vishaldeepak
Copy link
Contributor

#16686 Only covers Step 3. Step 1 and Step 2 remain. Maybe have news goals for each? I'd like to try my hand on them as well if open :-)

@djuber
Copy link
Contributor

djuber commented Apr 1, 2022

@vishaldeepak thanks for the clarification! I didn't read far enough down in the description (I was looking at the first few lines outlining the goals). Yes, I think the existing UserSetting for font selection, and the admin UserExperience setting for community default font is a good template to consider on how to add a default sort order.

If you peek at Users::Setting.config_font, Users::Setting.resolved_font_name, and Settings::UserExperience.default_font, that pattern captures one approach for this that makes sense to me (and I think adding a UI for both user and admin options completes the remaining two steps).

@djuber
Copy link
Contributor

djuber commented Apr 1, 2022

#17084 (caching?)

#17082 (mobile)
#17081 (mobile)

#17080 (caching, fixed)

Looks like these are related. the last one is something tied to DEV.to caching specifically, so wouldn't have been seen in reviewer testing, and the first one also is caching related. The other two appear to be something we could have caught better as reviewers by previewing the changes with mobile as well as desktop.

@vishaldeepak
Copy link
Contributor

@djuber @jeremyf Looks like the code has been revereted. How should I raise PR for the fixes?

@jeremyf
Copy link
Contributor

jeremyf commented Apr 4, 2022

@vishaldeepak in DEV things were breaking with this PR. I think you can build from the previous work (open a new PR). I'm uncertain of why it was breaking, I was just the one to issue the revert.

@aitchiss
Copy link
Contributor

aitchiss commented Aug 4, 2022

Following our chat @vishaldeepak, I've had an investigate and think I can summarise the issues we had when #16686 was first merged:

Caching issues:

These caching issues can be so difficult to spot in development, and we all missed it when reviewing too. I think when this work is next ready for review we can deploy it to one of our "canary" instances which would allow us to test in a production-like environment and make sure all is well 🙂

UI issues:

With these points in mind, are you happy to continue working on this feature? If you're up for it, I think you could use your previous code from #16686, update from main branch, and add these small tweaks in.

@vishaldeepak
Copy link
Contributor

thanks @aitchiss , i'l work on this

@vishaldeepak
Copy link
Contributor

@aitchiss I've done all that was required though Im running into random error. Described here - #18349 (comment)
Will need help from the team.

@amywtlin
Copy link

@mirie Can someone from the team help with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: comments & notifications area concerning interactions or notifications with user changelog: rollup Items that will be communicated in our monthly rollup changelogs tech: fullstack changes will heavily involve both frontend and backend technologies
Projects
None yet
Development

No branches or pull requests

7 participants