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

[webui] Refactoring user requests datatables #2680

Merged
merged 1 commit into from
Feb 17, 2017

Conversation

ChrisBr
Copy link
Member

@ChrisBr ChrisBr commented Feb 14, 2017

@ChrisBr
Copy link
Member Author

ChrisBr commented Feb 14, 2017

@evanrolfe please have a look!

@ChrisBr ChrisBr force-pushed the requests_table_refactoring branch 4 times, most recently from 57af8a8 to f6aa274 Compare February 15, 2017 08:47
@mdeniz mdeniz added the Frontend Things related to the OBS RoR app label Feb 15, 2017
@ChrisBr ChrisBr force-pushed the requests_table_refactoring branch from f6aa274 to 8f8a9a6 Compare February 15, 2017 09:57
@@ -0,0 +1,140 @@
class RequestsDatatable
delegate :sprite_tag, :common_parts, :user_with_realname_and_icon, :fuzzy_time,
:project_or_package_link, :params, :link_to, :request_show_path, to: :@view

Choose a reason for hiding this comment

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

I dont understand what this is for?

Copy link
Member Author

Choose a reason for hiding this comment

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

These are view helper methods which I use e.g. in show_column or requester_column

@ChrisBr ChrisBr force-pushed the requests_table_refactoring branch from 8f8a9a6 to 8aa80f1 Compare February 15, 2017 10:25
@evanrolfe
Copy link

Nice work on this, the code is definitely not easy to work with! I have some suggestions with your class design though, the RequestsDatatable is too complicated and does not follow SOLID principles.

I would split RequestsDatatable into two classes: RequestsDatatable and RequestsDatatableRow. Also I don't think you should have any view methods like link_to, project_or_package_link inside a model because it doesn't follow the MVC pattern. Those methods should only ever be in views or helpers.

So I would use move the view methods to a json erb view file like it was done originally i.e.
https://gist.github.com/evanrolfe/ca834754a183f75986d825458ed55d21

(Warning: Code not tested.)

@@ -0,0 +1,79 @@
class RequestsDataTable

Choose a reason for hiding this comment

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

Can this go into a submodule i.e. BsRequest::DataTable and also: BsRequest::DataTableRow? Or something like that?

@requests ||= fetch_requests
end

def length

Choose a reason for hiding this comment

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

does this method ever get used?

else
super
end
end

Choose a reason for hiding this comment

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

IMO these two methods make the class more complicated than it needs to be.. There are simpler alternatives I think i.e.

  1. Just call row.request.X since @request is an attr_reader
  2. use def_delegators to delegate the desired methods to @request
  3. Use SimpleDelegator to make this a decorator class for a request

context 'sort direction' do
context 'defaults to sort by :created_at :desc' do
before do
@data = RequestsDataTable.new({ format: :json, length: 10, start: 0 }, user).rows

Choose a reason for hiding this comment

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

Why is format: :json a param here? It doesn't ever get used by this class does it?

target_package: target_package)
}

context 'sort direction' do

Choose a reason for hiding this comment

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

Can you please have a look at the betterspecs guidelines for rspec because this isn't the way context is meant to be used.

Here is an example of how the spec could be written to follow the rspec guidelines (and also I've added tests for the untested public methods on this class - draw, records_total, count_requests:

https://gist.github.com/evanrolfe/eb422ca6766cd063b1f90012e9a97bf9

@requests = @displayed_user.send(request_method, search)
@requests_count = @requests.count
@requests = @requests.offset(params[:start].to_i).limit(params[:length].to_i).reorder(sorting_field => sorting_dir)
@data = RequestsDataTable.new(params, @displayed_user)

Choose a reason for hiding this comment

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

Can we call this something more descriptive? i.e. @requests_data_table?

]
<% unless index == @data.rows.length - 1 %>
,
<% end %>

Choose a reason for hiding this comment

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

looks like something is wrong with the indentation here?

@ChrisBr ChrisBr force-pushed the requests_table_refactoring branch 6 times, most recently from f94e544 to 4478970 Compare February 16, 2017 10:37
- Moved logic from controller to RequestsDatatable class
- Fix request sorting ordering by column (introduced by 509370a)
Fixes openSUSE#2572
@ChrisBr ChrisBr force-pushed the requests_table_refactoring branch from 4478970 to 4f07d4c Compare February 16, 2017 11:39
@evanrolfe
Copy link

LGTM (assuming the build passes)

@evanrolfe evanrolfe merged commit 5039e3e into openSUSE:master Feb 17, 2017
ChrisBr added a commit to ChrisBr/open-build-service that referenced this pull request Mar 7, 2017
ChrisBr added a commit to ChrisBr/open-build-service that referenced this pull request Mar 9, 2017
bgeuken pushed a commit to bgeuken/open-build-service that referenced this pull request Mar 15, 2017
@ChrisBr ChrisBr deleted the requests_table_refactoring branch July 18, 2017 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend Things related to the OBS RoR app Refactoring 🏭
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants