Skip to content
Snippets Groups Projects

Remember user's inline/tabular diff view preference in a cookie

As per #3071 (closed), some users (we have a local EE installation) prefer 2-column view in diff. In this MR I add an implementation for this feature, using a cookie.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
26 26 end
27 27 end
28 28
29 protected
30
31 def apply_diff_view_cookie!
32 view = params[:view] || cookies[:diff_view]
33 cookies.permanent[:diff_view] = params[:view] = view if view
  • What do you think about using an if block here?

    e.g.:

    if view = params[:view] || cookies[:diff_view]
      cookies.permanent[:diff_view] = params[:view] = view
    end
  • To me, as a C++ user, assignment in an if statement is one of the most obscure ways to write code. I do not know Ruby and its idiom well, but if I read your question literally, as in what I think about this code style, then I think this if statement would be extremely, utterly confusing to code readers. If, however, your point is that I must write this way according to GitLab or general Ruby code style, I will grudgingly rewrite it; a pointer to said code style would be very welcome in this case though!

  • Or maybe this would be more readable?

    view = params[:view] || cookies[:diff_view]
    if view
      cookies.permanent[:diff_view] = view
      params[:view] = view
    end
    Edited by username-removed-230683
  • Fair enough! Actually, the Ruby style-guide we're using tells "Favor modifier if/unless usage when you have a single-line body" (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier) so let's keep the original code as it is since the body is a single-line (even if there are actually two assignments in it).

    Regarding the style guides, they are listed in our CONTRIBUTING.md document. :)

  • @kkm Could you please add an acceptance test for this feature?

  • mentioned in merge request !2723 (merged)

  • username-removed-128633 Status changed to closed

    Status changed to closed

  • @kkm Thanks for your work, I've submitted a rebased merge request with a test at !2723 (merged).

  • mentioned in commit 9fdd605f

  • Please register or sign in to reply
    Loading