From e40ede12c8d434a17078527d19037d665f1a1860 Mon Sep 17 00:00:00 2001 From: George Goodall Date: Wed, 30 Oct 2024 16:47:25 +0000 Subject: [PATCH] get multiple sources working on issue details page --- src/middleware/datasetTaskList.middleware.js | 2 +- src/middleware/issueDetails.middleware.js | 28 +++++++------------- src/services/performanceDbApi.js | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/middleware/datasetTaskList.middleware.js b/src/middleware/datasetTaskList.middleware.js index ffa17b78..f16c2d63 100644 --- a/src/middleware/datasetTaskList.middleware.js +++ b/src/middleware/datasetTaskList.middleware.js @@ -52,7 +52,7 @@ export const prepareDatasetTaskListTemplateParams = (req, res, next) => { const taskList = tasks.map((task) => { 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) diff --git a/src/middleware/issueDetails.middleware.js b/src/middleware/issueDetails.middleware.js index 42f8645d..f90290b8 100644 --- a/src/middleware/issueDetails.middleware.js +++ b/src/middleware/issueDetails.middleware.js @@ -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] || [] diff --git a/src/services/performanceDbApi.js b/src/services/performanceDbApi.js index a06d7d12..837524ce 100644 --- a/src/services/performanceDbApi.js +++ b/src/services/performanceDbApi.js @@ -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}'