Skip to content
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

Man 352 persist activity log filters #296

Merged
merged 6 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions integration_tests/e2e/activityLog.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ import Page from '../pages/page'
import ActivityLogPage from '../pages/activityLog'
import errorMessages from '../../server/properties/errorMessages'

const keywords = 'Phone call'
const dateFrom = '11/1/2025'
const dateTo = '12/1/2025'

const fillFilters = (page: ActivityLogPage) => {
page.getKeywordsInput().type(keywords)
page.getDateFromInput().type(dateFrom)
page.getDateToInput().type(dateTo)
page.getComplianceFilter(1).click()
page.getComplianceFilter(2).click()
page.getComplianceFilter(3).click()
}

const filtersAreFilled = (page: ActivityLogPage) => {
page.getKeywordsInput().should('have.value', keywords)
page.getDateFromInput().should('have.value', dateFrom)
page.getDateToInput().should('have.value', dateTo)
page.getComplianceFilter(1).should('be.checked')
page.getComplianceFilter(2).should('be.checked')
page.getComplianceFilter(3).should('be.checked')
}

context('Activity log', () => {
const today = new Date()
const day = today.getDate()
Expand Down Expand Up @@ -356,6 +378,7 @@ context('Activity log', () => {
cy.visit('/case/X000001/activity-log')
const page = Page.verifyOnPage(ActivityLogPage)
page.getPaginationLink(3).click()
// cy.pause()
cy.get('.govuk-pagination__link[rel="next"]').click()
page.getPaginationLink(3).should('not.have.attr', 'aria-current')
page.getPaginationLink(4).should('have.attr', 'aria-current')
Expand Down Expand Up @@ -437,4 +460,29 @@ context('Activity log', () => {
.find('li:nth-of-type(3)')
.should('contain.text', 'removing special characters like characters and accent letters')
})
it('should persist the selected filters when a pagination link is clicked', () => {
cy.visit('/case/X000001/activity-log')
const page = Page.verifyOnPage(ActivityLogPage)
fillFilters(page)
page.getApplyFiltersButton().click()
page.getPaginationItem(2).click()
filtersAreFilled(page)
})
it('should persist the selected filters when a view link is clicked', () => {
cy.visit('/case/X000001/activity-log')
const page = Page.verifyOnPage(ActivityLogPage)
fillFilters(page)
page.getApplyFiltersButton().click()
cy.get('.toggle-menu__list-item:nth-of-type(2) a').click()
filtersAreFilled(page)
})
it('should persist the selected filters when user clicks on record detail link, then returns to the page via the breadcrumb', () => {
cy.visit('/case/X000001/activity-log')
const page = Page.verifyOnPage(ActivityLogPage)
fillFilters(page)
page.getApplyFiltersButton().click()
page.getActivity('1').find('h2 a').click()
cy.get('.govuk-breadcrumbs__list .govuk-breadcrumbs__list-item:nth-of-type(3) a').click()
filtersAreFilled(page)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ context('Sentence', () => {
page.assertPageElementAtIndexWithin('section', 2, 'dd', 1, '1 February 2024')
page.assertPageElementAtIndexWithin('section', 2, 'dd', 2, '1 November 2024')
page.assertPageElementAtIndexWithin('section', 2, 'dd', 3, '31 January 2025')

const monthsElapsed = monthsOrDaysElapsed('2024-02-01')
page.assertPageElementAtIndexWithin('section', 2, 'dd', 4, `${monthsElapsed} elapsed (of 12 months)`)
page.assertPageElementAtIndexWithin('section', 2, 'dd', 5, 'Pre-sentence report')
Expand Down
4 changes: 3 additions & 1 deletion server/@types/ActivityLog.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface ActivityLogFilters {
dateFrom: string
dateTo: string
compliance: string[]
clearFilterKey?: string
clearFilterValue?: string
}

export interface ActivityLogRequestBody {
Expand Down Expand Up @@ -40,6 +42,6 @@ export interface ActivityLogCacheItem extends ActivityLogFilters {
}

export interface ActivityLogCache {
results: ActivityLogCacheItem[]
results?: ActivityLogCacheItem[]
filters?: ActivityLogFilters
}
1 change: 1 addition & 0 deletions server/middleware/filterActivityLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const filterActivityLog: Route<void> = (req, res, next) => {
}
return acc
}, '')

return queryStr
}

Expand Down
2 changes: 1 addition & 1 deletion server/middleware/getPersonActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getPersonActivity = async (

let personActivity: PersonActivity | null = null
let tierCalculation: TierCalculation | null = null
if (req?.session?.cache?.activityLog) {
if (req?.session?.cache?.activityLog?.results) {
const cache: ActivityLogCacheItem | undefined = req.session.cache.activityLog.results.find(
cacheItem =>
crn === cacheItem.crn &&
Expand Down
17 changes: 10 additions & 7 deletions server/routes/activityLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export default function activityLogRoutes(router: Router, { hmppsAuthClient }: S
res.render('pages/activity-log', {
personActivity,
crn,
query,
queryParams,
page,
view,
tierCalculation,
risksWidget,
predictorScores,
url: req.url,
query,
resultsStart,
resultsEnd,
})
Expand Down Expand Up @@ -146,7 +146,6 @@ export default function activityLogRoutes(router: Router, { hmppsAuthClient }: S
])
const isActivityLog = true
const queryParams = getQueryString(req.query)

const { category } = req.query

await auditService.sendAuditMessage({
Expand Down Expand Up @@ -175,13 +174,17 @@ export default function activityLogRoutes(router: Router, { hmppsAuthClient }: S

function getQueryString(params: Query): string[] {
const queryParams: string[] = []
if (params.view) {
queryParams.push(`view=${params.view}`)
const usedParams = ['view', 'requirement', 'keywords', 'dateFrom', 'dateTo', 'compliance', 'page']
for (const usedParam of usedParams) {
if (params[usedParam]) {
if (!Array.isArray(params[usedParam])) {
queryParams.push(`${usedParam}=${params[usedParam]}`)
} else {
params[usedParam].forEach(param => queryParams.push(`${usedParam}=${param}`))
}
}
}

if (params.requirement) {
queryParams.push(`requirement=${params.requirement}`)
}
return queryParams
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% set titleHtml %}
<span class="govuk-heading-s govuk-!-margin-bottom-0">
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=default&requirement={{ requirement }}"">{{ entry.type }} at {{ entry.startDateTime | govukTime }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span></a>
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=default&requirement={{ requirement }}&{{filters.queryStr}}&page={{page}}">{{ entry.type }} at {{ entry.startDateTime | govukTime }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span></a>
</span>
{% endset %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set titleHtml %}
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=default&requirement={{ requirement }}" class="govuk-!-font-weight-bold">{% include './_communication-title.njk' %} at&nbsp;{{ entry.startDateTime | govukTime }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span></a>
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=default&requirement={{ requirement }}&{{filters.queryStr}}&page={{page}}" class="govuk-!-font-weight-bold">{% include './_communication-title.njk' %} at&nbsp;{{ entry.startDateTime | govukTime }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span></a>
{% endset %}

{% set html %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% set titleHtml %}
<p class="govuk-body govuk-!-margin-bottom-1" data-qa="timeline{{ loop.index }}Card">
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=compact&requirement={{ requirement }}"">
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=compact&requirement={{ requirement }}&{{filters.queryStr}}&page={{page}}">
{% if entry.isAppointment === true %}
{{ appComplianceTag({ entry: entry, classes: 'govuk-!-margin-left-2', compact: true }) }}
{{ entry.type }} at&nbsp;{{ entry.startDateTime | govukTime }}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/activity-log/_compact-view.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<li>
{% if entry.isSystemContact === true and entry.isAppointment === false and entry.isCommunication === false %}
<div class="govuk-hint govuk-!-margin-bottom-1">
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=compact&requirement={{ requirement }}"" class="app-!-inherit-colour">{{ entry.type }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span></a>
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=compact&requirement={{ requirement }}&{{filters.queryStr}}&page={{page}}" class="app-!-inherit-colour">{{ entry.type }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span></a>
</div>
{% else %}
{% include "./_compact-timeline-entry.njk" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% set shouldPromptToRecordAnOutcome = entry.hasOutcome === false and entry.wasAbsent === false and hasAppointmentStartTimePassed and not entry.didTheyComply %}

{% set titleHtml %}
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=default&requirement={{ requirement }}"" class="govuk-!-font-weight-bold">
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=default&requirement={{ requirement }}&{{filters.queryStr}}&page={{page}}" class="govuk-!-font-weight-bold">
{{ entry.type }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span>
</a>
{% endset %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set titleHtml %}
<span class="govuk-heading-s govuk-!-margin-bottom-0">
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=default&requirement={{ requirement }}"" class="app-!-inherit-colour">{{ entry.type }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span></a>
<a href="/case/{{ crn }}/activity-log/activity/{{ entry.id }}?category={{ category }}&view=default&requirement={{ requirement }}&{{filters.queryStr}}&page={{page}}" class="app-!-inherit-colour">{{ entry.type }}<span class="govuk-visually-hidden"> on {{ thisDate }}</span></a>
</span>
{% endset %}

Expand Down
Loading