2.1.2 • Published 9 days ago

@ministryofjustice/probation-search-frontend v2.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

Probation Search Front-end Components

A Nunjucks component and Express middleware to search for probation cases.

Use this component to build probation case search functionality into your HMPPS service and deliver a consistent search experience to probation practitioners.

Try it out in the dev environment: https://probation-search-dev.hmpps.service.justice.gov.uk/examples

Get started

This guide assumes you are using the hmpps-template-typescript.

1. Install the dependency

npm install --save @ministryofjustice/probation-search-frontend

2. Add the Nunjucks component

Use the caseSearch component in your Nunjucks file:

{% from "probation/case-search/macro.njk" import caseSearch %}

{{ caseSearch({ 
    id: "search", 
    results: searchResults
}) }}

Full example: views/search.njk

3. Configure the Express routes

Create an instance of the CaseSearchService:

import CaseSearchService from '@ministryofjustice/probation-search-frontend/service/caseSearchService'

const searchService = new CaseSearchService({
  environment: config.environment,      // whether you want to search cases in the dev, preprod or prod environment 
  oauthClient: service.hmppsAuthClient, // a reference to your HMPPS Auth client
})

Full example: services/index.ts

Then use it to set up the post and get routes for your search page.

router.post('/search', searchService.post)
router.get('/search', searchService.get, (req, res) => res.render('pages/search'))

Full example: routes/search.ts

That's it! Start your service and visit http://localhost:3000/search to try it out.

Examples

For a fully working example, check out the probation-search-ui project.

The front-end can be accessed here: https://probation-search-dev.hmpps.service.justice.gov.uk/search

Configuration

Nunjucks (front-end) configuration

The caseSearch Nunjucks macro takes the following options:

OptionDescriptionDefault
labelThe label used by the text input component."Find a person on probation"
hintCan be used to add a hint to the text input component."You can search by name, date of birth or any other identifier (for example CRN or PNC id)."
idThe id of the text input field"search"
typeType of input control to render."search"
classesClasses to add to the input.""
resultsThis must always be set to searchResults. The value of searchResults is populated by the Express routes, and contains the results of the search query to be rendered by the component.(none)

Express (back-end) configuration

The CaseSearchService function takes the following options:

OptionDescriptionDefault
environmentWhether you want to search cases in the dev, preprod or prod environment. You can also specify local to use some hard-coded test data - override the test data by setting localData.(none)
oauthClientA function for returning a HMPPS Auth client_credentials token. This will be used to get a token for calling the Probation Search API.(none)
resultPathA function used to generate a link to the case in your service, based on the case reference number (CRN).(crn: string) => /case/${crn}
extraColumnsAn optional array of extra columns to display in search results, in addition to Name, CRN, and Date of Birth. For example, to add an Age column: [{ header: 'Age', result => result.age }].[]
pageSizeThe number of results to return per page.10
maxPagesToShowThe maximum number of pages to show on the paginator.7
localDataA list of search results to return during local development (i.e. when environment = 'local')Two dummy records - John Doe and Jane Doe

Support

For any issues or questions, please contact the Probation Integration team via the #probation-integration-tech Slack channel. Or feel free to create a new issue in this repository.

2.1.2

9 days ago

2.1.1

2 months ago

2.1.0

3 months ago

2.0.1

3 months ago

2.0.0

3 months ago

1.12.0

5 months ago

1.11.2

5 months ago

1.11.1

5 months ago

1.11.0

5 months ago

1.10.0

5 months ago

1.9.2

7 months ago

1.9.1

7 months ago

1.9.0

7 months ago

1.8.0

8 months ago

1.7.0

8 months ago

1.6.0

8 months ago

1.5.0

8 months ago

1.4.0

8 months ago

1.3.0

8 months ago

1.2.0

8 months ago

1.1.0

8 months ago

1.0.0

8 months ago

0.4.0

8 months ago

0.3.0

8 months ago

0.2.0

8 months ago

0.1.0

9 months ago