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
Activity
👍 @dzaporozhets, what do you think?@stanhu I think this is very useful for people who use split diff regularly. Can you check if implementation works smooth?
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 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-230683Fair 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)
@kkm Thanks for your work, I've submitted a rebased merge request with a test at !2723 (merged).
mentioned in commit 9fdd605f