-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add pagination to user queues #14242
Changes from 6 commits
fe83559
dcdcb73
b0bf1be
08fcd51
0d964de
704aadc
5cf38a1
93e1f6a
78bbd55
aab8fea
6eb17a9
9bb778d
9d04534
aa99bda
82590b1
9aea0a9
b46a11e
99a85ae
d794622
8d7d82e
e0fbe61
0ad1143
56e9531
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
class Users::TaskPagesController < UsersController | ||
# /users/{user.id}/task_pages? | ||
# tab=on_hold& | ||
# sort_by=case_details_link& | ||
# order=desc& | ||
# filter[]=col%3Ddocket_type%26val%3Dlegacy& | ||
# filter[]=col%3Dtask_action%26val%3Dtranslation& | ||
# page=3 | ||
# | ||
# params = <ActionController::Parameters { | ||
# "tab"=>"on_hold", | ||
# "sort_by"=>"case_details_link", | ||
# "order"=>"desc", | ||
# "filter"=>[ | ||
# "col=docketNumberColumn&val=legacy,evidence_submission", | ||
# "col=taskColumn&val=Unaccredited rep,Extension" | ||
# ], | ||
# "page"=>"3" | ||
# }> | ||
|
||
def index | ||
render json: { | ||
tasks: json_tasks(task_pager.paged_tasks), | ||
task_page_count: task_pager.task_page_count, | ||
total_task_count: task_pager.total_task_count, | ||
tasks_per_page: TaskPager::TASKS_PER_PAGE | ||
} | ||
end | ||
|
||
private | ||
|
||
def task_pager | ||
@task_pager ||= TaskPager.new( | ||
assignee: user, | ||
tab_name: params[Constants.QUEUE_CONFIG.TAB_NAME_REQUEST_PARAM.to_sym], | ||
page: params[Constants.QUEUE_CONFIG.PAGE_NUMBER_REQUEST_PARAM.to_sym], | ||
sort_order: params[Constants.QUEUE_CONFIG.SORT_DIRECTION_REQUEST_PARAM.to_sym], | ||
sort_by: params[Constants.QUEUE_CONFIG.SORT_COLUMN_REQUEST_PARAM.to_sym], | ||
filters: params[Constants.QUEUE_CONFIG.FILTER_COLUMN_REQUEST_PARAM.to_sym] | ||
) | ||
end | ||
|
||
def json_tasks(tasks) | ||
tasks = AppealRepository.eager_load_legacy_appeals_for_tasks(tasks) | ||
params = { user: current_user } | ||
|
||
AmaAndLegacyTaskSerializer.new( | ||
tasks: tasks, params: params, ama_serializer: WorkQueue::TaskSerializer | ||
).call | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New controller for requesting paged tasks assigned to a user |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ def attach_tasks_to_tab(tab) | |
# This allows us to only instantiate TaskPager if we are using the task pages API. | ||
task_page_count: task_pager.task_page_count, | ||
total_task_count: tab.tasks.count, | ||
task_page_endpoint_base_path: "#{assignee_is_org? ? "#{assignee.path}/" : ''}#{endpoint}" | ||
task_page_endpoint_base_path: "#{assignee_is_org? ? "#{assignee.path}/" : "users/#{assignee.id}/"}#{endpoint}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the endpoint the front end uses to request paged tasks |
||
) | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,16 @@ def description | |
|
||
def tasks | ||
Task.includes(*task_includes).visible_in_queue_table_view.on_hold.where(assigned_to: assignee) | ||
.or(legacy_colocated_tasks) | ||
end | ||
|
||
def legacy_colocated_tasks | ||
Task.includes(*task_includes).open.where( | ||
assigned_by: assignee, | ||
assigned_to_type: Organization.name, | ||
appeal_type: LegacyAppeal.name, | ||
type: ColocatedTask.subclasses.map(&:name) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copies logic from AttorneyQueue. Only issue is that it will return multiple colocated tasks for one appeal. Debating on how to fix this. Currently affects 42 cases out of ~2500 legacy_colocated_tasks = ColocatedTask.open.where(appeal_type: LegacyAppeal.name, assigned_to: Colocated.singleton)
legacy_colocated_tasks.pluck(:appeal_id).uniq.count
=> 2593
legacy_colocated_tasks.group(:appeal_id).count.values.select { |count| count > 1 }.count
=> 42 |
||
end | ||
|
||
# rubocop:disable Metrics/AbcSize | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ def initialize(args) | |
end | ||
|
||
def paged_tasks | ||
sorted_tasks(filtered_tasks).page(page).per(TASKS_PER_PAGE) | ||
@paged_tasks ||= sorted_tasks(filtered_tasks).page(page).per(TASKS_PER_PAGE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
|
||
def sorted_tasks(tasks) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,7 +325,7 @@ def update_status!(new_status) | |
end | ||
|
||
def use_task_pages_api? | ||
false | ||
FeatureToggle.enabled?(:user_queue_pagination) | ||
end | ||
|
||
def queue_tabs | ||
|
@@ -337,7 +337,7 @@ def queue_tabs | |
end | ||
|
||
def self.default_active_tab | ||
Constants.QUEUE_CONFIG.ASSIGNED_TASKS_TAB_NAME | ||
Constants.QUEUE_CONFIG.INDIVIDUALLY_ASSIGNED_TASKS_TAB_NAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error from previous PRs |
||
end | ||
|
||
def assigned_tasks_tab | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ class AttorneyTaskListView extends React.PureComponent { | |
assignedTasks={this.props.workableTasks} | ||
onHoldTasks={this.props.onHoldTasks} | ||
completedTasks={this.props.completedTasks} | ||
paginationOptions={this.props.paginationOptions} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass pagination options though to queue table builder |
||
/> | ||
</AppSegment>; | ||
} | ||
|
@@ -86,8 +87,7 @@ const mapStateToProps = (state) => { | |
} | ||
}, | ||
ui: { | ||
messages, | ||
organizations | ||
messages | ||
} | ||
} = state; | ||
|
||
|
@@ -97,7 +97,6 @@ const mapStateToProps = (state) => { | |
completedTasks: completeTasksByAssigneeCssIdSelector(state), | ||
success: messages.success, | ||
error: messages.error, | ||
organizations, | ||
taskDecision | ||
}); | ||
}; | ||
|
@@ -124,7 +123,7 @@ AttorneyTaskListView.propTypes = { | |
resetErrorMessages: PropTypes.func, | ||
showErrorMessage: PropTypes.func, | ||
onHoldTasks: PropTypes.array, | ||
organizations: PropTypes.array, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Orgs was unused |
||
paginationOptions: PropTypes.object, | ||
success: PropTypes.shape({ | ||
title: PropTypes.string, | ||
detail: PropTypes.string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ class ColocatedTaskListView extends React.PureComponent { | |
assignedTasks={this.props.assignedTasks} | ||
onHoldTasks={this.props.onHoldTasks} | ||
completedTasks={this.props.completedTasks} | ||
paginationOptions={this.props.paginationOptions} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass pagination options though to queue table builder |
||
/> | ||
</AppSegment>; | ||
}; | ||
|
@@ -50,11 +51,9 @@ const mapStateToProps = (state) => { | |
|
||
return { | ||
success, | ||
organizations: state.ui.organizations, | ||
assignedTasks: newTasksByAssigneeCssIdSelector(state), | ||
onHoldTasks: onHoldTasksByAssigneeCssIdSelector(state), | ||
completedTasks: completeTasksByAssigneeCssIdSelector(state), | ||
queueConfig: state.queue.queueConfig | ||
completedTasks: completeTasksByAssigneeCssIdSelector(state) | ||
}; | ||
}; | ||
|
||
|
@@ -71,7 +70,6 @@ ColocatedTaskListView.propTypes = { | |
completedTasks: PropTypes.array, | ||
hideSuccessMessage: PropTypes.func, | ||
onHoldTasks: PropTypes.array, | ||
organizations: PropTypes.array, | ||
queueConfig: PropTypes.object, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. orgs and queue config were unused |
||
paginationOptions: PropTypes.object, | ||
success: PropTypes.object | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,10 +217,11 @@ | |
patch "/messages/:id", to: "inbox#update" | ||
end | ||
|
||
resources :users, only: [:index, :update] | ||
resources :users, only: [:index] do | ||
resources :users, only: [:index, :update] do | ||
resources :task_pages, only: [:index], controller: 'users/task_pages' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Route for user tasks pager |
||
get 'represented_organizations', on: :member | ||
end | ||
|
||
get 'user', to: 'users#search' | ||
get 'user_info/represented_organizations' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,25 @@ | |
|
||
expect(data.size).to be(1) | ||
end | ||
|
||
context "when using task pages api" do | ||
before do | ||
expect(QueueForRole).not_to receive(:new) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure we are not pulling tasks from QueueForRole |
||
FeatureToggle.enable!(:user_queue_pagination) | ||
end | ||
after { FeatureToggle.disable!(:user_queue_pagination) } | ||
|
||
it "gets tasks from task pager, not queue for role" do | ||
get :index, params: { user_id: user.id, role: "unknown" } | ||
expect(response.status).to eq 200 | ||
|
||
queue_for_role_tasks = JSON.parse(response.body)["tasks"]["data"] | ||
expect(queue_for_role_tasks.size).to be(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ensure tasks are not being sent to the front end outside of queue config |
||
|
||
paged_tasks = JSON.parse(response.body)["queue_config"]["tabs"].first["tasks"] | ||
expect(paged_tasks.size).to be(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ensure tasks are being sent though queue config |
||
end | ||
end | ||
end | ||
|
||
context "when a task is assignable" do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only improves the initial load time of a queue. Will file followup tickets to improve load times after creating or updating tasks. These tickets would remove
QueueForRole
herecaseflow/app/controllers/tasks_controller.rb
Lines 71 to 83 in b0bf1be
caseflow/app/controllers/tasks_controller.rb
Lines 95 to 102 in b0bf1be
and should exist outside of pagination