Skip to content

Commit

Permalink
Feature/pic 3835 refactor nunjucks templates (#949)
Browse files Browse the repository at this point in the history
* 3835: Refactor case list to move logic to controller

* 3835: Fixed case list e2e tests

* 3835: Fix probation status column

* 3835: Fixed probation status html

* 3835: Added unit tests for probation status badge / html

* 3835: Fix linting

* Rerun

* 3835: Fix linting

* 3835: Fixed unit tests

* Delete test-results/jest/results.xml
  • Loading branch information
ArronChave3 authored Jul 22, 2024
1 parent a8a6a54 commit c9b8175
Show file tree
Hide file tree
Showing 7 changed files with 556 additions and 286 deletions.
6 changes: 3 additions & 3 deletions integration-tests/cypress/e2e/case-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Feature: Case list
| Defendant | Probation status | Offence | Listing | Session | Court |

And I should see the following table rows
| Kara Ayers | No record | Attempt theft from the person of another | 1st | Morning | Crown Court 3-1 |
| Kara Ayers | No record | Attempt theft from the person of another | 1st | Morning | Crown Court 3-1 |

And I should see link "Robert Hardin" with href "/hearing/bbe36cfc-dc6f-421f-bac2-d4ae987d618f/defendant/81b6e516-4e9d-4c92-a38b-68e159cfd6c4/summary"
And I should see link "Vance Landry" with href "/hearing/6046236a-5517-4445-a349-73f8f653b23a/defendant/903ecefd-8697-4d0e-bf01-f892f9dee7e7/summary"
Expand Down Expand Up @@ -124,7 +124,7 @@ Feature: Case list
| Defendant | Probation status | Offence | Listing | Session | Court |

And I should see the following table rows
| Kara Ayers | No record | Attempt theft from the person of another | 1st | Morning | Crown Court 3-1 |
| Kara Ayers | No record | Attempt theft from the person of another | 1st | Morning | Crown Court 3-1 |

And I should see link "Sara Ortega" with href "/hearing/228fdfe6-0056-47ce-974d-b0ba9cc6d6f8/defendant/c8fe5f8a-57f2-43a0-b5fb-73562036f080/summary"
And I should see link "Pamela Stanton" with href "/hearing/f9a66faa-a758-46d3-928c-8666367f6649/defendant/b8ea0ada-bc7f-4aed-99e3-1b3146274df6/summary"
Expand Down Expand Up @@ -158,7 +158,7 @@ Feature: Case list
| Defendant | Probation status | Offence | Listing | Session | Court | Libra case number |

And I should see the following table rows
| Kara Ayers | No record | Attempt theft from the person of another | 1st | Morning | Crown Court 3-1 |
| Kara Ayers | No record | Attempt theft from the person of another | 1st | Morning | Crown Court 3-1 |

And I should see link "Geoff McTaggart" with href "/hearing/bae9a472-d1fc-403d-b639-a65d304089a2/defendant/523137c4-4dfe-40a4-aa99-9cbe64bf0476/summary"

Expand Down
210 changes: 181 additions & 29 deletions server/routes/handlers/getPagedCaseListRouteHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const trackEvent = require('../../utils/analytics.js')
const workflow = require('../../utils/workflow')
const queryParamBuilder = require('../../utils/queryParamBuilder.js')
const moment = require('moment')
const { constructTableData } = require('../../utils/caseListTableData.js')

const getTodaysDate = () => {
return moment(new Date()).format('YYYY-MM-DD')
Expand All @@ -25,6 +26,151 @@ const getPagelessQueryParams = params => {
return remainder
}

const getPageTitle = (params) => {
switch (params.subsection) {
case 'added':
return 'Recently added cases'
case 'removed':
return 'Removed cases'
default:
return 'Case list'
}
}

const getPageTabs = (params) => {
const pageTabs = []

const getPageLink = (subsection) => {
const subsectionLink = subsection ? `/${subsection}` : ''
return `/${params.courtCode}/cases/${params.date}${subsectionLink}`
}

if (params.hearingOutcomesEnabled) {
pageTabs.push(...[
{
title: 'Hearing outcome still to be added',
a11yTitle: 'View outcome still to be added case list',
link: getPageLink(),
current: params.subsection === ''
},
{
title: 'Hearing outcome added',
a11yTitle: 'View outcome added case list',
link: getPageLink('heard'),
current: params.subsection === 'heard'
}
])
} else {
pageTabs.push({
title: 'Case list',
a11yTitle: 'View current case list',
link: getPageLink(),
current: params.subsection === ''
})
}

if (params.addedCount > 0) {
pageTabs.push({
title: 'Recently added',
a11yTitle: 'View list of recently added cases',
link: getPageLink('added'),
current: params.subsection === 'added',
count: params.addedCount
})
}

if (params.removedCount > 0) {
pageTabs.push({
title: 'Removed cases',
a11yTitle: 'View list of removed cases',
link: getPageLink('removed'),
current: params.subsection === 'removed',
count: params.removedCount
})
}

return pageTabs
}

const getPaginationObject = (pageParams) => {
const maximumPages = 4
const currentPage = pageParams.page
let startNum = pageParams.page - ((maximumPages - 1) / 2)
let endNum = pageParams.page + ((maximumPages - 1) / 2)
const totalPages = Math.round(Math.ceil((pageParams.caseCount / pageParams.limit)))

const pageItems = []
const recentlyAddedPageItems = []
let previousLink
let recentlyAddedPreviousLink
let recentlyAddedNextLink
let nextLink

if (startNum < 1 || totalPages <= maximumPages) {
startNum = 1
endNum = maximumPages
} else if (endNum > totalPages) {
startNum = totalPages - (maximumPages - 1)
}

if (endNum > totalPages) {
endNum = totalPages
}

for (let i = startNum; i <= endNum; i++) {
pageItems.push({
text: i,
href: pageParams.baseUrl + 'page=' + i,
selected: currentPage === i
})

recentlyAddedPageItems.push({
text: i,
href: '/' + pageParams.courtCode + '/cases/' + pageParams.date + '/' + pageParams.subsection + '?page=' + i,
selected: currentPage === i
})
}

if (currentPage !== 1) {
previousLink = {
text: 'Previous',
href: pageParams.baseUrl + 'page=' + (currentPage - 1)
}

recentlyAddedPreviousLink = {
text: 'Previous',
href: '/' + pageParams.courtCode + '/cases/' + pageParams.date + '/' + pageParams.subsection + '?page=' + (currentPage - 1)
}
}

if (currentPage < totalPages) {
nextLink = {
text: 'Next',
href: pageParams.baseUrl + 'page=' + (currentPage + 1)
}

recentlyAddedNextLink = {
text: 'Next',
href: '/' + pageParams.courtCode + '/cases/' + pageParams.date + '/' + pageParams.subsection + '?page=' + (currentPage + 1)
}
}

return {
maxPagesDisplay: maximumPages,
currentPage,
startNum,
endNum,
totalPages,
pageItems,
recentlyAddedPageItems,
previousLink,
recentlyAddedPreviousLink,
nextLink,
recentlyAddedNextLink

}
}

const getPagedCaseListRouteHandler = caseService => async (req, res) => {
const {
redisClient: { getAsync },
Expand Down Expand Up @@ -90,39 +236,45 @@ const getPagedCaseListRouteHandler = caseService => async (req, res) => {
})
}

const templateValues = {
title: 'Cases',
params: {
...params,
workflow: {
enabled: workflowEnabled,
tasks: {
prep: {
items: workflow.tasks.get('prep').states.getAllOrderBySequence
}
const pageParams = {
...params,
workflow: {
enabled: workflowEnabled,
tasks: {
prep: {
items: workflow.tasks.get('prep').states.getAllOrderBySequence
}
},
hearingOutcomesEnabled,
date: currentDate,
notification: currentNotification || '',
filters: response.filters,
page: parseInt(queryParams.page, 10) || 1,
from: startCount,
to: endCount,
caseCount,
addedCount: response.recentlyAddedCount,
unmatchedRecords: response.possibleMatchesCount,
removedCount: response.removedCount,
totalDays: pastCaseNavigationEnabled ? settings.casesTotalDays : 7,
casesPastDays: pastCaseNavigationEnabled ? settings.casesPastDays : -1,
enablePastCasesNavigation: settings.enablePastCasesNavigation,
subsection: subsection || (!date && session.currentView) || '',
filtersApplied: !!getPagelessQueryParams(queryParams) && Object.keys(getPagelessQueryParams(queryParams)).length > 0,
baseUrl: createBaseUrl({ courtCode, date }, queryParams)
}
},
hearingOutcomesEnabled,
date: currentDate,
notification: currentNotification || '',
filters: response.filters,
page: parseInt(queryParams.page, 10) || 1,
from: startCount,
to: endCount,
caseCount,
addedCount: response.recentlyAddedCount,
unmatchedRecords: response.possibleMatchesCount,
removedCount: response.removedCount,
totalDays: pastCaseNavigationEnabled ? settings.casesTotalDays : 7,
casesPastDays: pastCaseNavigationEnabled ? settings.casesPastDays : -1,
enablePastCasesNavigation: settings.enablePastCasesNavigation,
subsection: subsection || (!date && session.currentView) || '',
filtersApplied: !!getPagelessQueryParams(queryParams) && Object.keys(getPagelessQueryParams(queryParams)).length > 0,
baseUrl: createBaseUrl({ courtCode, date }, queryParams)
}

const templateValues = {
params: pageParams,
data: response.cases,
hearingOutcomesEnabled
tableData: constructTableData(pageParams, response.cases),
hearingOutcomesEnabled,
title: getPageTitle(pageParams),
listTabs: getPageTabs(pageParams),
pagination: getPaginationObject(pageParams)
}

session.currentView = subsection

session.caseListDate = currentDate
Expand Down
Loading

0 comments on commit c9b8175

Please sign in to comment.