Skip to content

Commit

Permalink
Merge pull request #683 from ministryofjustice/revert-679-APG-171-a-c…
Browse files Browse the repository at this point in the history
…ase-list-search

Revert "(APG-171) Refer case list search"
  • Loading branch information
jsrobertson authored Jul 16, 2024
2 parents f979dc7 + 6b5004a commit 18ab496
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 209 deletions.
42 changes: 21 additions & 21 deletions assets/scss/local.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@
@include govuk-responsive-margin(7, 'bottom');

background-color: govuk-colour('light-grey');
}

.form-controls {
* {
width: 100%;
}

:last-child {
margin-bottom: 0;
}

@include govuk-media-query($from: desktop) {
display: flex;
align-items: flex-end;
flex-wrap: wrap;

.form-controls {
* {
width: auto;
width: 100%;
}

.govuk-button {
margin-bottom: $govuk-border-width-form-element;
:last-child {
margin-bottom: 0;
}

.govuk-form-group {
margin-bottom: 0;
margin-right: govuk-spacing(3);
@include govuk-media-query($from: desktop) {
display: flex;
align-items: flex-end;
flex-wrap: wrap;

* {
width: auto;
}

.govuk-button {
margin-bottom: $govuk-border-width-form-element;
}

.govuk-form-group {
margin-bottom: 0;
margin-right: govuk-spacing(3);
}
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions server/controllers/assess/caseListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('AssessCaseListController', () => {
const requestHandler = controller.filter()
await requestHandler(request, response, next)

expect(CaseListUtils.queryParamsExcludingPage).toHaveBeenCalledWith(audience, undefined, status)
expect(CaseListUtils.queryParamsExcludingPage)
expect(PathUtils.pathWithQuery).toHaveBeenLastCalledWith(redirectPathBase, queryParamsExcludingPage)
expect(response.redirect).toHaveBeenCalledWith(pathWithQuery)
})
Expand All @@ -113,7 +113,7 @@ describe('AssessCaseListController', () => {
const requestHandler = controller.filter()
await requestHandler(request, response, next)

expect(CaseListUtils.queryParamsExcludingPage).not.toHaveBeenCalled()
expect(CaseListUtils.queryParamsExcludingPage)
expect(request.flash).toHaveBeenCalledWith('audienceError', 'Choose a filter')
expect(response.redirect).toHaveBeenCalledWith(redirectPathBase)
})
Expand Down Expand Up @@ -217,7 +217,6 @@ describe('AssessCaseListController', () => {
undefined,
undefined,
undefined,
undefined,
)
expect(PaginationUtils.pagination).toHaveBeenLastCalledWith(
request.path,
Expand Down Expand Up @@ -293,7 +292,6 @@ describe('AssessCaseListController', () => {
})
expect(CaseListUtils.queryParamsExcludingPage).toHaveBeenLastCalledWith(
uiAudienceQueryParam,
undefined,
uiStatusQueryParam,
uiSortColumnQueryParam,
uiSortDirectionQueryParam,
Expand Down Expand Up @@ -375,7 +373,6 @@ describe('AssessCaseListController', () => {
undefined,
undefined,
undefined,
undefined,
)
expect(PaginationUtils.pagination).toHaveBeenLastCalledWith(
request.path,
Expand Down
16 changes: 4 additions & 12 deletions server/controllers/assess/caseListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class AssessCaseListController {
return res.redirect(
PathUtils.pathWithQuery(
assessPaths.caseList.show({ courseId, referralStatusGroup }),
CaseListUtils.queryParamsExcludingPage(audience, undefined, status),
CaseListUtils.queryParamsExcludingPage(audience, status),
),
)
}
Expand Down Expand Up @@ -57,14 +57,7 @@ export default class AssessCaseListController {
TypeUtils.assertHasUser(req)

const { courseId } = req.params
const {
nameOrId,
page,
status,
strand: audience,
sortColumn,
sortDirection,
} = req.query as Record<string, string>
const { page, status, strand: audience, sortColumn, sortDirection } = req.query as Record<string, string>
const referralsFiltered = !!status || !!audience
const { referralStatusGroup } = req.params as { referralStatusGroup: ReferralStatusGroup }

Expand All @@ -89,7 +82,6 @@ export default class AssessCaseListController {
this.referralService.getReferralViews(username, activeCaseLoadId, {
audience: CaseListUtils.uiToApiAudienceQueryParam(audience),
courseName: selectedCourse.name,
nameOrId,
page: page ? (Number(page) - 1).toString() : undefined,
sortColumn,
sortDirection,
Expand All @@ -105,14 +97,14 @@ export default class AssessCaseListController {

const pagination = PaginationUtils.pagination(
req.path,
CaseListUtils.queryParamsExcludingPage(audience, nameOrId, status, sortColumn, sortDirection),
CaseListUtils.queryParamsExcludingPage(audience, status, sortColumn, sortDirection),
paginatedReferralViews.pageNumber,
paginatedReferralViews.totalPages,
)

const basePathExcludingSort = PathUtils.pathWithQuery(
assessPaths.caseList.show({ courseId, referralStatusGroup }),
CaseListUtils.queryParamsExcludingSort(audience, nameOrId, status, page),
CaseListUtils.queryParamsExcludingSort(audience, status, page),
)

/* eslint-disable sort-keys */
Expand Down
68 changes: 1 addition & 67 deletions server/controllers/refer/caseListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,52 +41,14 @@ describe('ReferCaseListController', () => {
beforeEach(() => {
controller = new ReferCaseListController(referralService)

request = createMock<Request>({ body: {}, flash: jest.fn().mockReturnValue([]), originalUrl, user: { username } })
request = createMock<Request>({ flash: jest.fn().mockReturnValue([]), originalUrl, user: { username } })
response = createMock<Response>({ locals: { user: { activeCaseLoadId, username } } })
})

afterEach(() => {
jest.resetAllMocks()
})

describe('filter', () => {
beforeEach(() => {
;(PathUtils.pathWithQuery as jest.Mock).mockReturnValue(pathWithQuery)
;(CaseListUtils.queryParamsExcludingPage as jest.Mock).mockReturnValue(queryParamsExcludingPage)

request.params = { referralStatusGroup: 'open' }
})

it('redirects to the show action with the selected referral status group', async () => {
const requestHandler = controller.filter()
await requestHandler(request, response, next)

expect(PathUtils.pathWithQuery).toHaveBeenCalledWith(
referPaths.caseList.show({ referralStatusGroup: 'open' }),
[],
)
expect(CaseListUtils.queryParamsExcludingPage).toHaveBeenCalledWith(undefined, undefined)
expect(response.redirect).toHaveBeenCalledWith(pathWithQuery)
})

describe('when there is `nameOrId` in the request body', () => {
it('redirects to the show action with the selected referral status group and `nameOrId`', async () => {
const nameOrId = 'ABC1234'
request.body = { nameOrId }

const requestHandler = controller.filter()
await requestHandler(request, response, next)

expect(PathUtils.pathWithQuery).toHaveBeenCalledWith(
referPaths.caseList.show({ referralStatusGroup: 'open' }),
[],
)
expect(CaseListUtils.queryParamsExcludingPage).toHaveBeenCalledWith(undefined, nameOrId)
expect(response.redirect).toHaveBeenCalledWith(pathWithQuery)
})
})
})

describe('indexRedirect', () => {
it('redirects to the show action with the open referral state', async () => {
const requestHandler = controller.indexRedirect()
Expand Down Expand Up @@ -138,9 +100,7 @@ describe('ReferCaseListController', () => {

expect(request.session.recentCaseListPath).toBe(originalUrl)
expect(response.render).toHaveBeenCalledWith('referrals/caseList/refer/show', {
action: '/refer/referrals/case-list/open',
isMyReferralsPage: true,
otherStatusGroups: ['draft', 'closed'],
pageHeading: 'My referrals',
pagination,
referralStatusGroup: 'open',
Expand Down Expand Up @@ -188,12 +148,10 @@ describe('ReferCaseListController', () => {

describe('when there are query parameters', () => {
it('renders the show template with the correct response locals', async () => {
const uiNameOrIdParam = 'ABC1234'
const uiSortColumnQueryParam = 'surname'
const uiSortDirectionQueryParam = 'ascending'

request.query = {
nameOrId: uiNameOrIdParam,
sortColumn: uiSortColumnQueryParam,
sortDirection: uiSortDirectionQueryParam,
}
Expand All @@ -202,10 +160,7 @@ describe('ReferCaseListController', () => {
await requestHandler(request, response, next)

expect(response.render).toHaveBeenCalledWith('referrals/caseList/refer/show', {
action: '/refer/referrals/case-list/open',
isMyReferralsPage: true,
nameOrId: uiNameOrIdParam,
otherStatusGroups: ['draft', 'closed'],
pageHeading: 'My referrals',
pagination,
referralStatusGroup: 'open',
Expand All @@ -214,24 +169,16 @@ describe('ReferCaseListController', () => {
tableRows,
})
expect(referralService.getMyReferralViews).toHaveBeenCalledWith(username, {
nameOrId: uiNameOrIdParam,
sortColumn: uiSortColumnQueryParam,
sortDirection: uiSortDirectionQueryParam,
statusGroup: 'open',
})
expect(CaseListUtils.queryParamsExcludingPage).toHaveBeenLastCalledWith(
undefined,
uiNameOrIdParam,
undefined,
uiSortColumnQueryParam,
uiSortDirectionQueryParam,
)
expect(CaseListUtils.queryParamsExcludingSort).toHaveBeenLastCalledWith(
undefined,
uiNameOrIdParam,
undefined,
undefined,
)
expect(PaginationUtils.pagination).toHaveBeenLastCalledWith(
request.path,
queryParamsExcludingPage,
Expand Down Expand Up @@ -298,10 +245,8 @@ describe('ReferCaseListController', () => {
await requestHandler(request, response, next)

expect(response.render).toHaveBeenCalledWith('referrals/caseList/refer/show', {
action: '/refer/referrals/case-list/draft',
draftReferralDeletedMessage,
isMyReferralsPage: true,
otherStatusGroups: ['open', 'closed'],
pageHeading: 'My referrals',
pagination,
referralStatusGroup: 'draft',
Expand Down Expand Up @@ -358,17 +303,6 @@ describe('ReferCaseListController', () => {
const requestHandler = controller.show()
await requestHandler(request, response, next)

expect(response.render).toHaveBeenCalledWith('referrals/caseList/refer/show', {
action: '/refer/referrals/case-list/closed',
isMyReferralsPage: true,
otherStatusGroups: ['open', 'draft'],
pageHeading: 'My referrals',
pagination,
referralStatusGroup: 'closed',
subNavigationItems: CaseListUtils.referSubNavigationItems(request.path),
tableHeadings,
tableRows,
})
expect(referralService.getMyReferralViews).toHaveBeenCalledWith(username, {
statusGroup: 'closed',
})
Expand Down
26 changes: 3 additions & 23 deletions server/controllers/refer/caseListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ import { type CaseListColumnHeader, type SortableCaseListColumnKey } from '@accr
export default class ReferCaseListController {
constructor(private readonly referralService: ReferralService) {}

filter(): TypedRequestHandler<Request, Response> {
return async (req: Request, res: Response) => {
TypeUtils.assertHasUser(req)

const { referralStatusGroup } = req.params
const { nameOrId } = req.body

return res.redirect(
PathUtils.pathWithQuery(
referPaths.caseList.show({ referralStatusGroup }),
CaseListUtils.queryParamsExcludingPage(undefined, nameOrId),
),
)
}
}

indexRedirect(): TypedRequestHandler<Request, Response> {
return async (req: Request, res: Response) => {
TypeUtils.assertHasUser(req)
Expand All @@ -39,7 +23,7 @@ export default class ReferCaseListController {
return async (req: Request, res: Response) => {
TypeUtils.assertHasUser(req)

const { nameOrId, page, sortColumn, sortDirection } = req.query as Record<string, string>
const { page, sortColumn, sortDirection } = req.query as Record<string, string>
const { username } = res.locals.user
const { referralStatusGroup } = req.params as { referralStatusGroup: ReferralStatusGroup }

Expand All @@ -50,7 +34,6 @@ export default class ReferCaseListController {
}

const paginatedReferralViews = await this.referralService.getMyReferralViews(username, {
nameOrId,
page: page ? (Number(page) - 1).toString() : undefined,
sortColumn,
sortDirection,
Expand All @@ -61,14 +44,14 @@ export default class ReferCaseListController {

const pagination = PaginationUtils.pagination(
req.path,
CaseListUtils.queryParamsExcludingPage(undefined, nameOrId, undefined, sortColumn, sortDirection),
CaseListUtils.queryParamsExcludingPage(undefined, undefined, sortColumn, sortDirection),
paginatedReferralViews.pageNumber,
paginatedReferralViews.totalPages,
)

const basePathExcludingSort = PathUtils.pathWithQuery(
referPaths.caseList.show({ referralStatusGroup }),
CaseListUtils.queryParamsExcludingSort(undefined, nameOrId, undefined, page),
CaseListUtils.queryParamsExcludingSort(undefined, undefined, page),
)

/* eslint-disable sort-keys */
Expand Down Expand Up @@ -97,11 +80,8 @@ export default class ReferCaseListController {
req.session.recentCaseListPath = req.originalUrl

return res.render('referrals/caseList/refer/show', {
action: referPaths.caseList.filter({ referralStatusGroup }),
draftReferralDeletedMessage: req.flash('draftReferralDeletedMessage')[0],
isMyReferralsPage: true,
nameOrId,
otherStatusGroups: referralStatusGroups.filter(group => group !== referralStatusGroup),
pageHeading: 'My referrals',
pagination,
referralStatusGroup,
Expand Down
4 changes: 0 additions & 4 deletions server/data/accreditedProgrammesApi/referralClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default class ReferralClient {
}

async findMyReferralViews(query?: {
nameOrId?: string
page?: string
sortColumn?: string
sortDirection?: string
Expand All @@ -84,7 +83,6 @@ export default class ReferralClient {
return (await this.restClient.get({
path: apiPaths.referrals.myDashboard({}),
query: {
...(query?.nameOrId && { nameOrId: query.nameOrId }),
...(query?.page && { page: query.page }),
...(query?.status && { status: query.status }),
...(query?.statusGroup && { statusGroup: query.statusGroup }),
Expand All @@ -106,7 +104,6 @@ export default class ReferralClient {
query?: {
audience?: string
courseName?: string
nameOrId?: string
page?: string
sortColumn?: string
sortDirection?: string
Expand All @@ -119,7 +116,6 @@ export default class ReferralClient {
query: {
...(query?.audience && { audience: query.audience }),
...(query?.courseName && { courseName: query.courseName }),
...(query?.nameOrId && { nameOrId: query.nameOrId }),
...(query?.page && { page: query.page }),
...(query?.sortColumn && { sortColumn: query.sortColumn }),
...(query?.sortDirection && { sortDirection: query.sortDirection }),
Expand Down
1 change: 0 additions & 1 deletion server/paths/refer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const updateStatusSelectionShowPath = updateStatusPathBase.path('selection')

export default {
caseList: {
filter: caseListPath.path(':referralStatusGroup'),
index: caseListPath,
show: caseListPath.path(':referralStatusGroup'),
},
Expand Down
Loading

0 comments on commit 18ab496

Please sign in to comment.