Commit cf618f04 authored by Eulyeon Ko's avatar Eulyeon Ko

Use startup js for initial api fetch

The API paths for project and group issue list are
added to startup calls when users visit issue list pages
without any parameters and sorting preferences.

Also explicitly set "type" prop to "issues" when
we inject js-issuable-list data for project and group -
issue list pages in their issues partials.
parent 60e36e72
......@@ -137,6 +137,21 @@ module IssuesHelper
issue.moved_from.project.service_desk_enabled? && !issue.project.service_desk_enabled?
end
def use_startup_call?
request.query_parameters.empty? && @sort == 'created_date'
end
def startup_call_params
{
state: 'opened',
with_labels_details: 'true',
page: 1,
per_page: 20,
order_by: 'created_at',
sort: 'desc'
}
end
end
IssuesHelper.prepend_if_ee('EE::IssuesHelper')
......@@ -23,9 +23,12 @@
= render_if_exists 'shared/issuable/group_bulk_update_sidebar', group: @group, type: :issues
- if Feature.enabled?(:vue_issuables_list, @group)
- if use_startup_call?
- add_page_startup_api_call(api_v4_groups_issues_path(id: @group.id, params: startup_call_params))
.js-issuables-list{ data: { endpoint: expose_url(api_v4_groups_issues_path(id: @group.id)),
'can-bulk-edit': @can_bulk_update.to_json,
'empty-state-meta': { svg_path: image_path('illustrations/issues.svg') },
'sort-key': @sort } }
'sort-key': @sort,
type: 'issues' } }
- else
= render 'shared/issues'
......@@ -4,12 +4,14 @@
- data_endpoint = local_assigns.fetch(:data_endpoint, expose_path(api_v4_projects_issues_path(id: @project.id)))
- default_empty_state_meta = { create_issue_path: new_project_issue_path(@project), svg_path: image_path('illustrations/issues.svg') }
- data_empty_state_meta = local_assigns.fetch(:data_empty_state_meta, default_empty_state_meta)
- type = local_assigns.fetch(:type, '')
- type = local_assigns.fetch(:type, 'issues')
- if type == 'issues' && use_startup_call?
- add_page_startup_api_call(api_v4_projects_issues_path(id: @project.id, params: startup_call_params))
.js-issuables-list{ data: { endpoint: data_endpoint,
'empty-state-meta': data_empty_state_meta.to_json,
'can-bulk-edit': @can_bulk_update.to_json,
'sort-key': @sort,
'type': type } }
type: type } }
- else
- empty_state_path = local_assigns.fetch(:empty_state_path, 'shared/empty_states/issues')
%ul.content-list.issues-list.issuable-list{ class: ("manual-ordering" if @sort == 'relative_position') }
......
......@@ -233,4 +233,25 @@ RSpec.describe IssuesHelper do
expect(helper.show_moved_service_desk_issue_warning?(new_issue)).to be(false)
end
end
describe '#use_startup_call' do
it "returns false when a query param is present" do
allow(controller.request).to receive(:query_parameters).and_return({ foo: 'bar' })
expect(helper.use_startup_call?).to eq(false)
end
it "returns false when user has stored sort preference" do
controller.instance_variable_set(:@sort, 'updated_asc')
expect(helper.use_startup_call?).to eq(false)
end
it 'returns true when request.query_parameters is empty with default sorting preference' do
controller.instance_variable_set(:@sort, 'created_date')
allow(controller.request).to receive(:query_parameters).and_return({})
expect(helper.use_startup_call?).to eq(true)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment