Follow-up: Refactor controller to make code clearer and remove unused variables
As per @mwoolf's suggestion:
suggestion: There are two very similarly named objects being exposed to the view here @events
and @table_events
and it's not immediately clear what the difference between them is but both are used in the view, so must be necessary.
events: @table_events.to_json,
is_last_page: @events.last_page?.to_json
For readability, I would suggest naming the events that are passed to the Vue application events
. The intention behind events: @events.json
is very clear IMO.
Additionally, consider refactoring the controller so that is_last_page: @events.last_page?.to_json
becomes is_last_page: @is_last_page.to_json
or something similar.
events = Gitlab::Audit::Events::Preloader.preload!(
AuditLogFinder
.new(level: level, params: audit_logs_params)
.execute
.page(params[:page])
.without_count
)
@is_last_page = events.last_page?
@events = AuditEventSerializer.new.represent(events)
You could then refactor the view:
events: @events.to_json,
is_last_page: @is_last_page.to_json,
I make no guarantees about how well this will play with Vue, as there may be things I've missed but hopefully, the intent behind my comment is clear
We should change the following locations:
ee/app/controllers/admin/audit_logs_controller.rb:14
ee/app/views/admin/audit_logs/index.html.haml:4
ee/app/controllers/groups/audit_events_controller.rb:23
ee/app/views/groups/audit_events/index.html.haml:7
ee/app/controllers/projects/audit_events_controller.rb:23
ee/app/views/projects/audit_events/index.html.haml:7