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

PIC-4093: Code change to display matching defendant records in descen… #990

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

sameermoj
Copy link
Contributor

const getPaginationObject = (pageParams) => {
const maximumPages = 4
const currentPage = pageParams.page
let startNum = pageParams.page - ((maximumPages - 1) / 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use currentPage here instead of pageParams.page

Might even be nice to destructure pageParams into something like

({page: currentPage, limit,matchingRecordsCount})

let endNum = pageParams.page + ((maximumPages - 1) / 2)
const totalPages = Math.round(Math.ceil((pageParams.matchingRecordsCount / pageParams.limit)))

const startCount = ((parseInt(pageParams.page, 10) - 1) || 0) * pageParams.limit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the parseInt doing anything useful here? Compare line 65 where we subtract from it without parseInt first.

const currentPage = parseInt(queryParams.page, 10) || 1
const limit = 5

// Calculate start and end index for slicing data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this logic belongs in getPaginationObject? It seems to be derived from values we are passing into that method anyway?

Copy link
Contributor

@johnyfarrar johnyfarrar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move all of this -

Screenshot 2024-09-24 at 18 17 22

in to server/routes/handlers/matching

so that we don't have all that in the index.js

@@ -27,6 +27,11 @@

.pac-\!-grid-column-45 {
width: 45%;
padding: 10px 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried that putting this here with mean if someone uses this in the future we have these overrides.... Could we add it as an additional class ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have the handler in a new routing file - we need to make sure we have unit tests for it too. I can help you with these. We either follow a given, when, then style or I use arrange, act, assert which is much the same.

const response = await getMatchDetails(defendantId)

const matchingRecordsCount = response.offenderMatchDetails.length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever check if this is zero? I know that to get here there must be a match as it's from a list but just wondering as it's a wild edge case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also as we're not typescript can we checkresponse.offenderMatchDetails is an array...

@@ -34,6 +34,14 @@ const createCaseService = apiUrl => {
const res = (await request(
`${apiUrl}/defendant/${defendantId}/matchesDetail`
)) || { data: {} }
// Sort offenderMatchDetails based on matchProbability in descending order
if (res.data.offenderMatchDetails) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to check this is an array? just in case we get nothing?

const response = await getMatchDetails(defendantId)

const matchingRecordsCount = response.offenderMatchDetails.length
const currentPage = parseInt(queryParams.page, 10) || 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bit over the top but what if someone changes the url and adds a minus or not a number?


const matchingRecordsCount = response.offenderMatchDetails.length
const currentPage = parseInt(queryParams.page, 10) || 1
const limit = 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the limit 50%?

if (!Array.isArray(offenderMatchDetails)) {
return res.render('error', {
...templateValues,
message: 'Unexpected data format received from the server.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test for this?

dependabot bot and others added 16 commits September 28, 2024 06:19
Bumps [webpack](https://github.com/webpack/webpack) from 5.89.0 to 5.94.0.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](webpack/webpack@v5.89.0...v5.94.0)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
build(deps-dev): bump webpack from 5.89.0 to 5.94.0 (#980)

Bumps [webpack](https://github.com/webpack/webpack) from 5.89.0 to 5.94.0.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](webpack/webpack@v5.89.0...v5.94.0)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

PIC-4093: Changes based on review

PIC-4093: Code change to display matching defendant records in descending order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants