Skip to content

Commit

Permalink
Enable org queues to use task pagination API (#11213)
Browse files Browse the repository at this point in the history
Connects #11054. Enables back-end pagination for certain organizations (VSOs, VLJ support staff, hearing management branch) when the current user has the `use_task_pages_api` feature toggle on. Still needs some cosmetic love, but it's far enough along that I'd like some feedback on how this approach can be improved.

![caching-pagination](https://user-images.githubusercontent.com/32683958/60212556-8a23d600-982f-11e9-8dda-dca70423f50f.gif)
  • Loading branch information
lowellrex authored and va-bot committed Jun 27, 2019
1 parent 9a8adf9 commit 9495744
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 423 deletions.
2 changes: 2 additions & 0 deletions app/controllers/organizations/tasks_controller.rb
Expand Up @@ -17,6 +17,8 @@ def index
private

def tasks
return [] if queue_config[:use_task_pages_api]

Rails.logger.debug("starting GenericQueue tasks")

# Temporarily limit hearings-management tasks to AOD tasks, because currently no tasks are loading
Expand Down
4 changes: 4 additions & 0 deletions app/models/organization.rb
Expand Up @@ -24,6 +24,10 @@ def show_regional_office_in_queue?
false
end

def use_task_pages_api?
false
end

def non_admins
organizations_users.includes(:user).non_admin.map(&:user)
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/organizations/colocated.rb
Expand Up @@ -8,4 +8,8 @@ def self.singleton
def next_assignee(options = {})
ColocatedTaskDistributor.new.next_assignee(options)
end

def use_task_pages_api?
true
end
end
8 changes: 6 additions & 2 deletions app/models/organizations/hearings_management.rb
@@ -1,6 +1,10 @@
# frozen_string_literal: true

class HearingsManagement < Organization
def self.singleton
HearingsManagement.first || HearingsManagement.create(name: "Hearings Management", url: "hearings-management")
end

def can_bulk_assign_tasks?
true
end
Expand All @@ -9,7 +13,7 @@ def show_regional_office_in_queue?
true
end

def self.singleton
HearingsManagement.first || HearingsManagement.create(name: "Hearings Management", url: "hearings-management")
def use_task_pages_api?
true
end
end
6 changes: 5 additions & 1 deletion app/models/organizations/vso.rb
@@ -1,3 +1,7 @@
# frozen_string_literal: true

class Vso < Representative; end
class Vso < Representative
def use_task_pages_api?
true
end
end
63 changes: 29 additions & 34 deletions app/models/queue_config.rb
Expand Up @@ -17,17 +17,21 @@ def initialize(args)
end

def to_hash_for_user(user)
serialized_tabs = tabs.each { |tab| tab[:tasks] = serialized_tasks_for_user(tab[:tasks], user) }

{
table_title: format(COPY::ORGANIZATION_QUEUE_TABLE_TITLE, organization.name),
active_tab: Constants.QUEUE_CONFIG.UNASSIGNED_TASKS_TAB_NAME,
tabs: serialized_tabs
tasks_per_page: TaskPager::TASKS_PER_PAGE,
use_task_pages_api: use_task_pages_api?,
tabs: tabs.map { |tab| attach_tasks_to_tab(tab, user) }
}
end

private

def use_task_pages_api?
FeatureToggle.enabled?(:use_task_pages_api) && organization.use_task_pages_api?
end

def tabs
[
include_tracking_tasks_tab? ? tracking_tasks_tab : nil,
Expand All @@ -37,8 +41,23 @@ def tabs
].compact
end

def attach_tasks_to_tab(tab, user)
task_pager = TaskPager.new(assignee: organization, tab_name: tab[:name])

# Only return tasks in the configuration if we are using it to populate the first page of results.
# Otherwise avoid the overhead of the additional database requests.
tasks = use_task_pages_api? ? serialized_tasks_for_user(task_pager.paged_tasks, user) : []

tab.merge(
label: format(tab[:label], task_pager.total_task_count),
tasks: tasks,
task_page_count: task_pager.task_page_count,
total_task_count: task_pager.total_task_count,
task_page_endpoint_base_path: "#{organization.path}/task_pages?tab=#{tab[:name]}"
)
end

def serialized_tasks_for_user(tasks, user)
return [] unless FeatureToggle.enabled?(:use_task_pages_api)
return [] if tasks.empty?

primed_tasks = AppealRepository.eager_load_legacy_appeals_for_tasks(tasks)
Expand All @@ -55,33 +74,24 @@ def include_tracking_tasks_tab?
end

def tracking_tasks_tab
name = Constants.QUEUE_CONFIG.TRACKING_TASKS_TAB_NAME
tasks = TaskPager.new(assignee: organization, tab_name: name).tasks_for_tab

{
label: COPY::ALL_CASES_QUEUE_TABLE_TAB_TITLE,
name: name,
name: Constants.QUEUE_CONFIG.TRACKING_TASKS_TAB_NAME,
description: format(COPY::ALL_CASES_QUEUE_TABLE_TAB_DESCRIPTION, organization.name),
columns: [
Constants.QUEUE_CONFIG.CASE_DETAILS_LINK_COLUMN,
Constants.QUEUE_CONFIG.ISSUE_COUNT_COLUMN,
Constants.QUEUE_CONFIG.APPEAL_TYPE_COLUMN,
Constants.QUEUE_CONFIG.DOCKET_NUMBER_COLUMN
],
task_group: Constants.QUEUE_CONFIG.TRACKING_TASKS_GROUP,
tasks: tasks,
allow_bulk_assign: false
}
end

# rubocop:disable Metrics/AbcSize
def unassigned_tasks_tab
name = Constants.QUEUE_CONFIG.UNASSIGNED_TASKS_TAB_NAME
tasks = TaskPager.new(assignee: organization, tab_name: name).tasks_for_tab

{
label: format(COPY::ORGANIZATIONAL_QUEUE_PAGE_UNASSIGNED_TAB_TITLE, tasks.count),
name: name,
label: COPY::ORGANIZATIONAL_QUEUE_PAGE_UNASSIGNED_TAB_TITLE,
name: Constants.QUEUE_CONFIG.UNASSIGNED_TASKS_TAB_NAME,
description: format(COPY::ORGANIZATIONAL_QUEUE_PAGE_UNASSIGNED_TASKS_DESCRIPTION, organization.name),
# Compact to account for the maybe absent regional office column
columns: [
Expand All @@ -94,21 +104,14 @@ def unassigned_tasks_tab
Constants.QUEUE_CONFIG.DAYS_ON_HOLD_COLUMN,
organization.is_a?(Representative) ? nil : Constants.QUEUE_CONFIG.DOCUMENT_COUNT_READER_LINK_COLUMN
].compact,
task_group: Constants.QUEUE_CONFIG.UNASSIGNED_TASKS_GROUP,
tasks: tasks,
allow_bulk_assign: organization.can_bulk_assign_tasks?
}
end
# rubocop:enable Metrics/AbcSize

# rubocop:disable Metrics/AbcSize
def assigned_tasks_tab
name = Constants.QUEUE_CONFIG.ASSIGNED_TASKS_TAB_NAME
tasks = TaskPager.new(assignee: organization, tab_name: name).tasks_for_tab

{
label: format(COPY::QUEUE_PAGE_ASSIGNED_TAB_TITLE, tasks.count),
name: name,
label: COPY::QUEUE_PAGE_ASSIGNED_TAB_TITLE,
name: Constants.QUEUE_CONFIG.ASSIGNED_TASKS_TAB_NAME,
description: format(COPY::ORGANIZATIONAL_QUEUE_PAGE_ASSIGNED_TASKS_DESCRIPTION, organization.name),
# Compact to account for the maybe absent regional office column
columns: [
Expand All @@ -121,20 +124,14 @@ def assigned_tasks_tab
Constants.QUEUE_CONFIG.DOCKET_NUMBER_COLUMN,
Constants.QUEUE_CONFIG.DAYS_ON_HOLD_COLUMN
].compact,
task_group: Constants.QUEUE_CONFIG.ASSIGNED_TASKS_GROUP,
tasks: tasks,
allow_bulk_assign: false
}
end
# rubocop:enable Metrics/AbcSize

def completed_tasks_tab
name = Constants.QUEUE_CONFIG.COMPLETED_TASKS_TAB_NAME
tasks = TaskPager.new(assignee: organization, tab_name: name).tasks_for_tab

{
label: COPY::QUEUE_PAGE_COMPLETE_TAB_TITLE,
name: name,
name: Constants.QUEUE_CONFIG.COMPLETED_TASKS_TAB_NAME,
description: format(COPY::QUEUE_PAGE_COMPLETE_TASKS_DESCRIPTION, organization.name),
# Compact to account for the maybe absent regional office column
columns: [
Expand All @@ -147,8 +144,6 @@ def completed_tasks_tab
Constants.QUEUE_CONFIG.DOCKET_NUMBER_COLUMN,
Constants.QUEUE_CONFIG.DAYS_ON_HOLD_COLUMN
].compact,
task_group: Constants.QUEUE_CONFIG.COMPLETED_TASKS_GROUP,
tasks: tasks,
allow_bulk_assign: false
}
end
Expand Down
16 changes: 12 additions & 4 deletions app/models/task_pager.rb
Expand Up @@ -46,14 +46,22 @@ def paged_tasks
# tasks
# end

def task_page_count
@task_page_count ||= paged_tasks.total_pages
end

def total_task_count
@total_task_count ||= tasks_for_tab.count
end

def tasks_for_tab
case tab_name
when Constants.QUEUE_CONFIG.TRACKING_TASKS_TAB_NAME
tracking_tasks
when Constants.QUEUE_CONFIG.UNASSIGNED_TASKS_TAB_NAME
unassigned_tasks
active_tasks
when Constants.QUEUE_CONFIG.ASSIGNED_TASKS_TAB_NAME
assigned_tasks
on_hold_tasks
when Constants.QUEUE_CONFIG.COMPLETED_TASKS_TAB_NAME
recently_completed_tasks
else
Expand All @@ -67,12 +75,12 @@ def tracking_tasks
TrackVeteranTask.includes(*task_includes).active.where(assigned_to: assignee)
end

def unassigned_tasks
def active_tasks
Task.includes(*task_includes)
.visible_in_queue_table_view.where(assigned_to: assignee).active
end

def assigned_tasks
def on_hold_tasks
Task.includes(*task_includes)
.visible_in_queue_table_view.where(assigned_to: assignee).on_hold
end
Expand Down
145 changes: 0 additions & 145 deletions client/app/components/TablePagination.jsx

This file was deleted.

0 comments on commit 9495744

Please sign in to comment.