Skip to content

1180 display tasks in lpa dashboard - #1213

Merged
pooleycodes merged 8 commits into
mainfrom
1180-display-tasks-in-lpa-dashboard
Jun 25, 2026
Merged

1180 display tasks in lpa dashboard#1213
pooleycodes merged 8 commits into
mainfrom
1180-display-tasks-in-lpa-dashboard

Conversation

@pooleycodes

@pooleycodes pooleycodes commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

The tasks in the LPA overview page, dataset details, data view and task list are all now sourced from the Platform API instead of Datasette.

As far as review; the pages should look identical except for the caveat that it can't differentiate individual tasks that are duplicated across different resources, so say if two endpoints for the same provision are provided, with some of the same data in it, no longer can the service count distinct entities in the issue log.

The fix for this; for the time being is to just take the endpoint with the larger number of tasks. An example of where this can lead to problem would be say Brighton and Hove where the task count is smaller then when you click through and it queries the issue logs directly.

Also two extra changes:

All issue loading now goes directly to the issue logs in the specific database, so instead of digital-land/issues table it would go to brownfield-land/issues table, the only loss here is the drop of the issue-type table, this means that a user could edit the url to looks at any issue type even if it is a internal issue. This is not considered dangerous and helps avoid the problem of very slow task loading.

The details drop down for arcgis URL has also been updated. (to be a dropdown).

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

Go to as many task lists provision pages as possible and confirm they are identical.

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes
  • No, and this is why: Please replace this line with details on why tests have not been included
  • I need help with writing tests

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added mainWebsiteUrl settings for development, staging and production.
  • Bug Fixes

    • Updated task and issue information across key pages to use platform task data (deduplicated for consistency), with task counts and lists more reliable.
    • Adjusted issue counting to align with the updated issue query logic.
  • Documentation

    • Improved the organisation get-started help content by replacing the ArcGIS help block with a collapsible GOV.UK Details section.

@pooleycodes pooleycodes linked an issue Jun 23, 2026 that may be closed by this pull request
2 tasks
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 45e10b5c-dd78-448b-b710-cf1d59379f73

📥 Commits

Reviewing files that changed from the base of the PR and between 06d55f0 and f35f440.

📒 Files selected for processing (1)
  • src/middleware/common.middleware.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/middleware/common.middleware.js

Walkthrough

Adds Platform API task fetching and rewires several middleware flows to use req.tasks instead of database issue counts. Also adds mainWebsiteUrl to environment configs and updates the get-started ArcGIS help content to a GOV.UK Details component.

Changes

Platform API task counts migration

Layer / File(s) Summary
Issue query alignment
src/middleware/common.middleware.js, src/middleware/entryIssueDetails.middleware.js
Updates the issue SQL used for entity, entry, and entry-detail counts to remove issue_type joins and severity/responsibility filtering, while adding dataset filtering where applicable.
Platform API fetchTasks
src/services/platformApi.js, test/unit/services/platformApi.test.js
Adds fetchTasks, which builds a /task.json request with optional parameters and returns formatted tasks and count data.
Common middleware task fetch
src/middleware/common.middleware.js, test/unit/middleware/common.middleware.test.js
Adds fetchTasksFromPlatformApi, which fetches Platform tasks, deduplicates them by (dataset, issue_type, field), and stores { tasks, count } on req.tasks.
datasetOverview uses req.tasks
src/middleware/datasetOverview.middleware.js, test/unit/middleware/datasetOverview.middleware.test.js
Swaps the dataset overview middleware to fetch Platform tasks and derive taskCount from tasks?.count ?? 0 instead of entityIssueCounts.
datasetTaskList builds from req.tasks
src/middleware/datasetTaskList.middleware.js, test/unit/middleware/datasetTaskList.middleware.test.js
Rebuilds prepareTasks to consume tasksData.tasks, keeps special row-count handling, and wires the middleware chain to fetchTasksFromPlatformApi.
dataview uses task counts and out-of-bounds expectations
src/middleware/dataview.middleware.js, test/unit/middleware/dataview.middleware.test.js
Replaces the entity-issue-count middleware with Platform task fetching, adds conditional out-of-bounds expectation fetching, and computes taskCount from tasks?.count plus any out-of-bounds increment.
lpa-overview groups tasks by dataset
src/middleware/lpa-overview.middleware.js, test/unit/middleware/lpa-overview.middleware.test.js
Replaces the database-backed issue fetch with Platform task fetching and reduces req.tasks?.tasks into req.issues by dataset.

Per-environment mainWebsiteUrl config

Layer / File(s) Summary
mainWebsiteUrl in environment config
config/development.yaml, config/staging.yaml, config/production.yaml
Sets mainWebsiteUrl in the development, staging, and production configuration files with their corresponding planning.data.gov.uk hostnames.

get-started ArcGIS help block UI update

Layer / File(s) Summary
get-started uses govukDetails
src/views/organisations/get-started.html
Adds the govukDetails macro import and renders the ArcGIS help content inside a collapsible Details component.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • digital-land/submit#707: Both PRs touch the entry issue counting flow in src/middleware/entryIssueDetails.middleware.js.
  • digital-land/submit#717: Both PRs modify src/middleware/common.middleware.js issue-fetching logic and downstream task-list inputs.
  • digital-land/submit#951: Both PRs update the dataset overview/task list task-count flow to use Platform tasks.

Suggested labels

enhancement

Suggested reviewers

  • CharliePatterson
  • rosado

Poem

🐇 Hop, hop, the tasks are in line,
URLs set, and the details component shines.
From Platform API to a tidy new nest,
This little warren is neatly dressed.
A carrot for configs, a cabbage for flow,
And off we go—hoppity, ho!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly matches the main change: displaying tasks in the LPA dashboard.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 1180-display-tasks-in-lpa-dashboard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 70.77% 2497 / 3528
🔵 Statements 69.93% 2633 / 3765
🔵 Functions 64.18% 500 / 779
🔵 Branches 63.66% 1223 / 1921
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/middleware/common.middleware.js 60.63% 50% 38.16% 62.18% 35-43, 48, 62-81, 90, 91, 92, 95, 98, 105, 111-112, 117-138, 153-159, 183-196, 213, 234, 257-271, 277, 282, 329-342, 348-368, 375, 384, 398-407, 446, 476-484, 501-513, 527-533, 539, 580-582, 590-591, 622-623, 673-689, 749-752, 758-761, 773-776, 806-816, 825-833, 845-852, 857-873, 943-944, 1018-1025, 1038-1049, 1054-1111, 1141, 1145-1147, 1151-1163, 1182, 1189-1192, 1205-1206, 1216, 1267-1300, 1314-1323
src/middleware/datasetOverview.middleware.js 82.35% 73.33% 46.15% 81.81% 16-38, 44, 79-82, 94-98, 135-139, 220, 230, 235, 260-281
src/middleware/datasetTaskList.middleware.js 82.92% 66.66% 66.66% 82.92% 45, 114-121, 158-165, 202, 216
src/middleware/dataview.middleware.js 85.36% 64% 45.45% 85% 34, 43, 101, 106, 125-146
src/middleware/entryIssueDetails.middleware.js 71.42% 65.51% 54.54% 70.73% 12, 21-24, 47-56, 82-84, 125-129
src/middleware/lpa-overview.middleware.js 78.48% 78.7% 80.64% 77.35% 19-20, 62-63, 76-77, 84-85, 108-118, 136-137, 148-149, 199, 203, 259-266, 280-284, 340-341, 399-406, 412, 434-445
src/services/platformApi.js 46.98% 42.42% 50% 48.38% 27, 33, 34, 37, 65-123, 132
Generated in workflow #1535 for commit f35f440 by the Vitest Coverage Report Action

@pooleycodes
pooleycodes marked this pull request as ready for review June 23, 2026 16:01

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
src/middleware/common.middleware.js (1)

1236-1244: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Fail closed when organisation is unavailable.

On Line 1239, this can call /task.json without an organisation filter when req.orgInfo is missing, which risks surfacing cross-authority task data. Add an early guard before the API call.

Proposed change
 export const fetchTasksFromPlatformApi = async (req, res, next) => {
   const dataset = req.params.dataset
+  const organisation = req.orgInfo?.organisation
+  if (!organisation) {
+    req.tasks = { tasks: [], count: 0 }
+    return next()
+  }
   try {
     const { formattedData } = await platformApi.fetchTasks({
-      organisation: req.orgInfo?.organisation,
+      organisation,
       ...(dataset && { dataset }),
       severity: 'error',
       task_source: 'issue',
       limit: dataset ? 100 : 500
     })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/middleware/common.middleware.js` around lines 1236 - 1244, The
platformApi.fetchTasks call on line 1239 can be executed without an organisation
filter when req.orgInfo is missing or undefined, which risks exposing
cross-authority task data. Add an early guard check before the try block to
verify that req.orgInfo and req.orgInfo.organisation exist. If either is
missing, the function should return early with an appropriate error response to
fail closed and prevent unauthorised data exposure.
test/unit/middleware/common.middleware.test.js (1)

1659-1734: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Add a regression test for missing orgInfo.organisation.

Please add a case that verifies no unscoped task fetch occurs and req.tasks remains empty when organisation context is absent.

Suggested test case
 describe('fetchTasksFromPlatformApi', () => {
   const next = vi.fn()
@@
   it('falls back to empty tasks on API error', async () => {
@@
     expect(next).toHaveBeenCalledTimes(1)
   })
+
+  it('fails closed when organisation is missing', async () => {
+    const req = { orgInfo: {}, params: { dataset: 'brownfield-land' } }
+    await fetchTasksFromPlatformApi(req, {}, next)
+
+    expect(platformApi.fetchTasks).not.toHaveBeenCalled()
+    expect(req.tasks).toEqual({ tasks: [], count: 0 })
+    expect(next).toHaveBeenCalledTimes(1)
+  })
 })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/middleware/common.middleware.test.js` around lines 1659 - 1734, Add
a new test case in the fetchTasksFromPlatformApi test suite that verifies the
behavior when orgInfo.organisation is missing or undefined. The test should
create a request object where orgInfo lacks the organisation property, call
fetchTasksFromPlatformApi, and assert that platformApi.fetchTasks is either not
called or called without an organisation parameter, and that req.tasks is set to
an empty object with an empty tasks array and count of 0 to ensure the function
handles missing organisation context gracefully.
test/unit/middleware/dataview.middleware.test.js (1)

181-219: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add branch coverage for the new taskCount paths.

This suite currently validates only the zero/default case. Please add explicit cases for out-of-bounds incrementing and the authority === 'some' override so regressions in the new logic are caught.

Proposed test additions
 describe('prepareTemplateParams', () => {
+  it('increments taskCount when out-of-bounds expectations exist', () => {
+    const req = {
+      orgInfo: { name: 'Mock Org', entity: 'mock-entity' },
+      dataset: { name: 'Mock Dataset', dataset: 'mock-dataset' },
+      tableParams: { columns: ['foo'], fields: ['foo'] },
+      tasks: { tasks: [{ dataset: 'mock-dataset' }], count: 1 },
+      expectationOutOfBounds: [{ dataset: 'mock-dataset' }],
+      pagination: {},
+      dataRange: { minRow: 1, maxRow: 1, totalRows: 1 },
+      authority: 'mock-authority'
+    }
+    const next = vi.fn()
+    prepareTemplateParams(req, {}, next)
+    expect(req.templateParams.taskCount).toBe(2)
+    expect(next).toHaveBeenCalledTimes(1)
+  })
+
+  it('forces taskCount to 1 when authority is some', () => {
+    const req = {
+      orgInfo: { name: 'Mock Org', entity: 'mock-entity' },
+      dataset: { name: 'Mock Dataset', dataset: 'mock-dataset' },
+      tableParams: { columns: ['foo'], fields: ['foo'] },
+      tasks: { tasks: [{ dataset: 'mock-dataset' }], count: 5 },
+      expectationOutOfBounds: [{ dataset: 'mock-dataset' }],
+      pagination: {},
+      dataRange: { minRow: 1, maxRow: 1, totalRows: 1 },
+      authority: 'some'
+    }
+    const next = vi.fn()
+    prepareTemplateParams(req, {}, next)
+    expect(req.templateParams.taskCount).toBe(1)
+    expect(next).toHaveBeenCalledTimes(1)
+  })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/middleware/dataview.middleware.test.js` around lines 181 - 219, The
current test for prepareTemplateParams in the describe block only validates the
default case where taskCount is 0. Add two additional test cases within the same
describe block to cover the new taskCount logic: one test case where the tasks
array contains items to verify taskCount increments correctly (out-of-bounds
case), and another test case where authority is set to 'some' to verify the
authority override behavior is properly applied to the templateParams object.
Ensure both new test cases follow the same structure as the existing test,
setting up appropriate req and res objects, calling prepareTemplateParams, and
asserting the expected templateParams values.
test/unit/middleware/datasetOverview.middleware.test.js (1)

27-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a regression test for non-displayable platform tasks.

Please add a case where req.tasks.count is non-zero but task entries are missing details.issue_type/details.field, and assert the overview count matches displayable tasks. This will guard cross-page count consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/middleware/datasetOverview.middleware.test.js` around lines 27 -
60, Add a new test case after the existing 'should prepare template params for
dataset overview' test to verify regression handling of non-displayable platform
tasks. Create a test scenario where req.tasks has a non-zero count property but
the task entries are missing the required details.issue_type and details.field
properties. Call prepareDatasetOverviewTemplateParams with this configuration
and assert that the resulting reqWithResults.templateParams.taskCount reflects
only the count of displayable tasks (those with proper details), not the total
tasks.count value, to ensure cross-page count consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/middleware/datasetOverview.middleware.js`:
- Around line 222-224: The taskCount calculation in the
datasetOverview.middleware.js file at line 222 uses the raw tasks.count without
filtering, but the task-list rendering filters tasks to only include those with
both details.issue_type and details.field properties. Update the taskCount
calculation to apply the same filtering logic - instead of using tasks?.count
directly, filter the tasks array to count only those items that have both
details.issue_type and details.field defined before adding the other count
values (endpointErrorIssues and expectationOutOfBounds check).

---

Nitpick comments:
In `@src/middleware/common.middleware.js`:
- Around line 1236-1244: The platformApi.fetchTasks call on line 1239 can be
executed without an organisation filter when req.orgInfo is missing or
undefined, which risks exposing cross-authority task data. Add an early guard
check before the try block to verify that req.orgInfo and
req.orgInfo.organisation exist. If either is missing, the function should return
early with an appropriate error response to fail closed and prevent unauthorised
data exposure.

In `@test/unit/middleware/common.middleware.test.js`:
- Around line 1659-1734: Add a new test case in the fetchTasksFromPlatformApi
test suite that verifies the behavior when orgInfo.organisation is missing or
undefined. The test should create a request object where orgInfo lacks the
organisation property, call fetchTasksFromPlatformApi, and assert that
platformApi.fetchTasks is either not called or called without an organisation
parameter, and that req.tasks is set to an empty object with an empty tasks
array and count of 0 to ensure the function handles missing organisation context
gracefully.

In `@test/unit/middleware/datasetOverview.middleware.test.js`:
- Around line 27-60: Add a new test case after the existing 'should prepare
template params for dataset overview' test to verify regression handling of
non-displayable platform tasks. Create a test scenario where req.tasks has a
non-zero count property but the task entries are missing the required
details.issue_type and details.field properties. Call
prepareDatasetOverviewTemplateParams with this configuration and assert that the
resulting reqWithResults.templateParams.taskCount reflects only the count of
displayable tasks (those with proper details), not the total tasks.count value,
to ensure cross-page count consistency.

In `@test/unit/middleware/dataview.middleware.test.js`:
- Around line 181-219: The current test for prepareTemplateParams in the
describe block only validates the default case where taskCount is 0. Add two
additional test cases within the same describe block to cover the new taskCount
logic: one test case where the tasks array contains items to verify taskCount
increments correctly (out-of-bounds case), and another test case where authority
is set to 'some' to verify the authority override behavior is properly applied
to the templateParams object. Ensure both new test cases follow the same
structure as the existing test, setting up appropriate req and res objects,
calling prepareTemplateParams, and asserting the expected templateParams values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1da74ec0-acb2-4280-b002-8be9c44a0e7e

📥 Commits

Reviewing files that changed from the base of the PR and between aef64ed and 78a2490.

📒 Files selected for processing (16)
  • config/default.yaml
  • config/development.yaml
  • config/production.yaml
  • config/staging.yaml
  • src/middleware/common.middleware.js
  • src/middleware/datasetOverview.middleware.js
  • src/middleware/datasetTaskList.middleware.js
  • src/middleware/dataview.middleware.js
  • src/middleware/lpa-overview.middleware.js
  • src/services/platformApi.js
  • test/unit/middleware/common.middleware.test.js
  • test/unit/middleware/datasetOverview.middleware.test.js
  • test/unit/middleware/datasetTaskList.middleware.test.js
  • test/unit/middleware/dataview.middleware.test.js
  • test/unit/middleware/lpa-overview.middleware.test.js
  • test/unit/services/platformApi.test.js

Comment thread src/middleware/datasetOverview.middleware.js

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/middleware/common.middleware.js`:
- Around line 805-811: Guard the entry issue query in the same place that builds
the SQL for fetchIssueCount so it does not dereference req.resources[0].resource
when no resource exists. Update the query function in common.middleware.js to
check req.resources[0] before constructing the WHERE clause, and return an
empty/no-op result path for datasets without a resource so the entry details
route stays safe. Use the existing fetchIssueCount guard pattern and the query
builder that references issueTypeClause and issueFieldClause to locate the fix.

In `@src/middleware/entryIssueDetails.middleware.js`:
- Around line 50-56: The count query in the middleware is missing the same
dataset and entry-row constraints used by fetchEntryIssues, so align the query
in the entry issue details logic with that method’s filtering. Update the count
builder to use the same resource, dataset, and entry row conditions as
fetchEntryIssues, keeping the query shape consistent so issueCount and
pagination match the actual rows returned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 94df23dd-bf06-4b79-b233-388bbf99c8a9

📥 Commits

Reviewing files that changed from the base of the PR and between 2e57b78 and 06d55f0.

📒 Files selected for processing (2)
  • src/middleware/common.middleware.js
  • src/middleware/entryIssueDetails.middleware.js

Comment thread src/middleware/common.middleware.js
Comment thread src/middleware/entryIssueDetails.middleware.js

@gibahjoe gibahjoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@pooleycodes
pooleycodes merged commit bebc0dc into main Jun 25, 2026
5 checks passed
@pooleycodes
pooleycodes deleted the 1180-display-tasks-in-lpa-dashboard branch June 25, 2026 08:44
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.

Display tasks in LPA Dashboard

2 participants