Skip to content

Commit

Permalink
get multiple sources working on issue details page
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall committed Oct 30, 2024
1 parent 348ae5e commit e40ede1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/middleware/datasetTaskList.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const prepareDatasetTaskListTemplateParams = (req, res, next) => {
const taskList = tasks.map((task) => {

Check failure on line 52 in src/middleware/datasetTaskList.middleware.js

View workflow job for this annotation

GitHub Actions / run-tests / test

test/unit/middleware/datasetTaskList.middleware.test.js > datasetTaskList.middleware.js > prepareDatasetTaskListParams > sets the correct template params on the request object

TypeError: Cannot read properties of undefined (reading 'map') ❯ Module.prepareDatasetTaskListTemplateParams src/middleware/datasetTaskList.middleware.js:52:26 ❯ test/unit/middleware/datasetTaskList.middleware.test.js:44:7

Check failure on line 52 in src/middleware/datasetTaskList.middleware.js

View workflow job for this annotation

GitHub Actions / test

test/unit/middleware/datasetTaskList.middleware.test.js > datasetTaskList.middleware.js > prepareDatasetTaskListParams > sets the correct template params on the request object

TypeError: Cannot read properties of undefined (reading 'map') ❯ Module.prepareDatasetTaskListTemplateParams src/middleware/datasetTaskList.middleware.js:52:26 ❯ test/unit/middleware/datasetTaskList.middleware.test.js:44:7
return {
title: {
text: performanceDbApi.getTaskMessage({ ...task, entityCount, field: task.field }) // using the entity count here doesn't make sense, should be using the entry count for each resource
text: performanceDbApi.getTaskMessage({ ...task, field: task.field }) // using the entity count here doesn't make sense, should be using the entry count for each resource
},
href: `/organisations/${lpa}/${datasetId}/${task.issue_type}/${task.field}`,
status: getStatusTag(task.status)
Expand Down
28 changes: 9 additions & 19 deletions src/middleware/issueDetails.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,29 +178,19 @@ const processEntryRow = (issueType, issuesByEntryNumber, row) => {
* Middleware. Updates req with `templateParams`
*/
export function prepareIssueDetailsTemplateParams (req, res, next) {
const { entryData, pageNumber, issueEntitiesCount, issuesByEntryNumber, entryNumber, entityCount: entityCountRow } = req
const { entryData, pageNumber, issueEntitiesCount, issuesByEntryNumber, entryNumber } = req
const { lpa, dataset: datasetId, issue_type: issueType, issue_field: issueField } = req.params
const { entity_count: entityCount } = entityCountRow ?? { entity_count: 0 }

let errorHeading
let issueItems

const BaseSubpath = `/organisations/${lpa}/${datasetId}/${issueType}/${issueField}/`

if (Object.keys(issuesByEntryNumber).length < entityCount) {
errorHeading = performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: issueEntitiesCount, entityCount, field: issueField }, true)
issueItems = Object.entries(issuesByEntryNumber).map(([entryNumber, issues], i) => {
const pageNum = i + 1
return {
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: 1, field: issueField }) + ` in record ${issues[0].entry_number}`,
href: `${BaseSubpath}${pageNum}`
}
})
} else {
issueItems = [{
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: issueEntitiesCount, entityCount, field: issueField }, true)
}]
}
const errorHeading = performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: issueEntitiesCount, field: issueField }, true)
const issueItems = Object.entries(issuesByEntryNumber).map(([entryNumber, issues], i) => {
const pageNum = i + 1
return {
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: 1, field: issueField }) + ` in record ${issues[0].entry_number}`,
href: `${BaseSubpath}${pageNum}`
}
})

const fields = entryData.map((row) => processEntryRow(issueType, issuesByEntryNumber, row))
const entityIssues = Object.values(issuesByEntryNumber)[pageNumber - 1] || []
Expand Down
2 changes: 1 addition & 1 deletion src/services/performanceDbApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export default {
issueField
}, database = 'digital-land') {
const sql = `
SELECT count(DISTINCT entry_number) as count
SELECT count(entry_number) as count
FROM issue
WHERE resource in ('${resources.join("', '")}')
AND issue_type = '${issueType}'
Expand Down

0 comments on commit e40ede1

Please sign in to comment.