Skip to content

Commit

Permalink
Merge commit 'b91dc88aca0bb6e03d76aa0d67ca70ec3e8ce7e6' into 682-data…
Browse files Browse the repository at this point in the history
…set-task-list-fetch-data-from-all-active-resources
  • Loading branch information
GeorgeGoodall committed Dec 9, 2024
2 parents c3d1ad6 + b91dc88 commit 2d19b15
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 142 deletions.
2 changes: 1 addition & 1 deletion src/content/statusPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const headingTexts = {
checking: 'Checking your data',
checked: 'Data Checked'
checked: 'Data checked'
}

export const messageTexts = {
Expand Down
8 changes: 7 additions & 1 deletion src/controllers/resultsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ class ResultsController extends PageController {
fields: responseDetails.getFields()
}

req.form.options.errorSummary = requestData.getErrorSummary()
req.form.options.errorSummary = requestData.getErrorSummary().map(message => {
return {
text: message,
href: ''
}
})
req.form.options.mappings = responseDetails.getFieldMappings()
req.form.options.geometries = responseDetails.getGeometries()
req.form.options.pagination = responseDetails.getPagination(req.params.pageNumber)
req.form.options.id = req.params.id
req.form.options.lastPage = `/check/status/${req.params.id}`
} else {
req.form.options.error = requestData.getError()
}
Expand Down
20 changes: 20 additions & 0 deletions src/controllers/statusController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ import { getRequestData } from '../services/asyncRequestApi.js'
import { finishedProcessingStatuses } from '../utils/utils.js'
import { headingTexts, messageTexts } from '../content/statusPage.js'

/**
* Attempts to infer how we ended up on this page.
*
* @param req
* @returns {string?}
*/
function getLastPage (req) {
let lastPage
if ('url' in req.form.options.data.params) {
lastPage = '/check/url'
} else if ('original_filename' in req.form.options.data.params) {
lastPage = '/check/upload'
}
return lastPage
}

class StatusController extends PageController {
async locals (req, res, next) {
try {
Expand All @@ -11,6 +27,10 @@ class StatusController extends PageController {
req.form.options.headingTexts = headingTexts
req.form.options.messageTexts = messageTexts
req.form.options.pollingEndpoint = `/api/status/${req.form.options.data.id}`
const lastPage = getLastPage(req)
if (lastPage) {
req.form.options.lastPage = lastPage
}
super.locals(req, res, next)
} catch (error) {
next(error, req, res, next)
Expand Down
38 changes: 5 additions & 33 deletions src/middleware/common.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,43 +620,15 @@ export const getSetDataRange = (pageLength) => (req, res, next) => {

export function getErrorSummaryItems (req, res, next) {
const { issue_type: issueType, issue_field: issueField } = req.params
const { baseSubpath, issues, issueCount, entities, resources } = req

let errorHeading = ''
let issueItems
const { issues, issueCount, entities, resources } = req

const totalRecordCount = entities ? entities.length : resources[0].entry_count
const totalIssues = issueCount?.count || issues.length

if (issues.length <= 0) {
// currently the task list page is getting its issues incorrectly, not factoring in the fact that an issue might have been fixed.
logger.warn(`entry issue details was accessed from ${req.headers.referer} but there was no issues`)
const error = new Error('issue count must be larger than 0')
return next(error)
} else if (issues.length < totalRecordCount) {
errorHeading = performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: totalIssues, rowCount: totalRecordCount, field: issueField }, true)
issueItems = issues.map((issue, i) => {
const pageNum = i + 1
let inString = ''

// we have to hard code this in because though the entitiy has beeb assigned, it has been assigned incorrectly
const specialIssueTypeCases = ['reference values are not unique']

if (issue.reference && !specialIssueTypeCases.includes(issue.issue_type)) {
inString = ` in entity with reference ${issue.reference}`
} else if (issue.line_number) {
inString = ` on row ${issue.line_number}`
}
return {
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: 1, field: issueField }) + inString,
href: `${baseSubpath}/${pageNum}`
}
})
} else {
issueItems = [{
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: totalIssues, rowCount: totalRecordCount, field: issueField }, true)
}]
}
const errorHeading = ''
const issueItems = [{
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: totalIssues, entityCount: totalRecordCount, field: issueField }, true)
}]

req.errorSummary = {
heading: errorHeading,
Expand Down
4 changes: 4 additions & 0 deletions src/models/requestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default class ResultData {
return new ResponseDetails(this.id, response.data, pagination, this.getColumnFieldLog())
}

/**
*
* @returns {string[]}
*/
getErrorSummary () {
if (!this.response || !this.response.data || !this.response.data['error-summary']) {
logger.warn('trying to get error summary when there is none', { requestId: this.id })
Expand Down
12 changes: 10 additions & 2 deletions src/views/check/confirmation.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

{% from 'govuk/components/back-link/macro.njk' import govukBackLink %}
{% from 'govuk/components/panel/macro.njk' import govukPanel %}
{% from "govuk/components/details/macro.njk" import govukDetails %}

Expand All @@ -7,6 +7,14 @@
{% set serviceType = 'Check' %}
{% set pageName = "You can now publish your data" %}

{% block beforeContent %}
{{ govukBackLink({
text: "Back",
href: "javascript:window.history.back()"
}) }}
{% endblock %}


{% set content %}

# What to do next
Expand All @@ -31,7 +39,7 @@
Details about what to do next are also available [in the guidance](/guidance)

{% if options.deepLink %}
<p><a href="{{ options.deepLink.referrer }}">Return to {{ options.deepLink.dataset }} overview</a></p>
<p><a href="{{ options.deepLink.referrer }}">Return to {{ options.deepLink.dataset | datasetSlugToReadableName }} overview</a></p>
{% else %}
<p><a href="/">Return to Home</a></p>
{% endif %}
Expand Down
55 changes: 40 additions & 15 deletions src/views/check/results/errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{% from 'govuk/components/radios/macro.njk' import govukRadios %}
{% from 'govuk/components/inset-text/macro.njk' import govukInsetText %}
{% from "govuk/components/pagination/macro.njk" import govukPagination %}

{% from 'components/dataset-banner.html' import datasetBanner %}
{% from 'components/table.html' import table %}
{% from 'govuk/components/error-summary/macro.njk' import govukErrorSummary %}
{% from "../../components/table.html" import table %}
{% from '../../components/dataset-banner.html' import datasetBanner %}

{% set serviceType = 'Check' %}
{% set pageName = 'Your data has errors' %}
Expand Down Expand Up @@ -36,23 +36,22 @@ <h1 class="govuk-heading-l">
{{pageName}}
</h1>

<ul class="govuk-list govuk-list--bullet">
{% for summaryMessage in options.errorSummary %}
<li>
{{summaryMessage}}
</li>
{% endfor %}
</ul>
{{ govukErrorSummary({
titleText: "There’s a problem",
errorList: options.errorSummary
}) }}

</div>
</div>

<div class="govuk-grid-row">

<div class="govuk-grid-column-full">
{% if options.tableParams.rows|length > 0 %}
<h2 class="govuk-heading-m">
Check your errors
</h2>
{% if options.geometries %}
<div id="map" class="app-map" aria-label="Map showing contour of the submitted data on a map"></div>
{% endif %}

{% if options.tableParams.rows|length > 0 %}
{{ table(options.tableParams) }}
{% endif %}

Expand All @@ -72,11 +71,37 @@ <h2 class="govuk-heading-m">

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

{% if options.deepLink.orgName %}
<h3 class="govuk-heading-m">How to improve {{ options.deepLink.orgName }}'s data</h3>
{% else %}
<h3 class="govuk-heading-m">How to improve the data</h3>
{% endif %}

<ol class="govuk-list govuk-list--number">
<li>Fix the errors indicated. You should use the <a href="/guidance/specifications/">data specifications</a> to help you do this.</li>
<li>Check your updated data to make sure it meets the specifications.</li>
</ol>

{{ govukButton({
text: "Upload a new version",
text: "Check your data",
href: "/check/upload-method"
}) }}

</div>
</div>
{% endblock %}

{% block scripts %}
{{ super() }}
{% if options.geometries %}
<link href='https://unpkg.com/maplibre-gl@latest/dist/maplibre-gl.css' rel='stylesheet' />
<script>
window.serverContext = {
containerId: 'map',
geometries: {{ options.geometries | dump | safe }},
}
</script>
<script src="/public/js/map.bundle.js"></script>
{% endif %}
{% endblock %}
11 changes: 4 additions & 7 deletions src/views/check/results/no-errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ <h1 class="govuk-heading-l">
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">

{% if options.geometries %}
<div id="map" class="app-map" aria-label="Map showing contour of the submitted data on a map"></div>
{% endif %}

{{ table(options.tableParams) }}

{% if options.pagination.items | length > 1 %}
Expand All @@ -69,13 +73,6 @@ <h1 class="govuk-heading-l">
{% endif %}



{% if options.geometries %}
<p>Here’s your data on a map:</p>
<div id="map" class="app-map"></div>
{% endif %}


</div>
</div>

Expand Down
10 changes: 10 additions & 0 deletions src/views/check/statusPage/status.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from 'govuk/components/back-link/macro.njk' import govukBackLink %}
{% from "./statusContentMacro.html" import statusContent %}
{% from '../../components/dataset-banner.html' import datasetBanner %}

Expand All @@ -17,6 +18,15 @@
{% set buttonClasses = "js-hidden" %}
{% endif %}

{% block beforeContent %}
{% if options.lastPage %}
{{ govukBackLink({
text: options.backLinkText | default("Back"),
href: options.lastPage
}) }}
{% endif %}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds" aria-live="assertive">
Expand Down
2 changes: 1 addition & 1 deletion src/views/components/dataset-banner.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% macro datasetBanner(datasetName) %}
<span class="govuk-caption-xl">{{ datasetName }}</span>
<span class="govuk-caption-xl">{{ datasetName | datasetSlugToReadableName }}</span>
{% endmacro %}
5 changes: 5 additions & 0 deletions src/views/components/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
{% macro table(params) %}
<div class="app-scrollable-container dl-scrollable">
<table class="govuk-table dl-table">
<colgroup>
{% for field in params.fields %}
<col class="{% if (r/.*-date/g).test(field) %}govuk-table__cell--numeric{% endif %}" />
{% endfor %}
</colgroup>
<thead class="govuk-table__head dl-table__head">
<tr class="govuk-table__row">
{% for column in params.columns %}
Expand Down
2 changes: 0 additions & 2 deletions src/views/error.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

{% from "govuk/components/button/macro.njk" import govukButton %}

{% set pageName = "Error" %}

{% extends "layouts/main.html" %}

{% block content %}
<h1 class="govuk-heading-xl">Error</h1>

Expand Down
2 changes: 1 addition & 1 deletion src/views/organisations/dataview.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{% if pagination.items | length > 1 %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<p>Showing rows {{dataRange.minRow}} to {{dataRange.maxRow}} of {{dataRange.totalRows}}</p>
<p>Showing rows {{dataRange.minRow + 1}} to {{dataRange.maxRow}} of {{dataRange.totalRows}}</p>
{{ govukPagination(pagination) }}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/views/organisations/issueTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
{% if pagination.items | length > 1 %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<p>Showing rows {{dataRange.minRow}} to {{dataRange.maxRow}} of {{dataRange.totalRows}}</p>
<p>Showing rows {{dataRange.minRow + 1}} to {{dataRange.maxRow}} of {{dataRange.totalRows}}</p>
{{ govukPagination(pagination) }}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions test/PageObjectModels/resultsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export default class ResultsPage extends BasePage {
// Check if there's a table
expect(await this.page.locator('table').isVisible())

await this.page.waitForSelector('.govuk-list.govuk-list--bullet')
await this.page.waitForSelector('.govuk-error-summary .govuk-list')
// Get the text content of the bullet points
const summarytext = await this.page.evaluate(() => {
const bulletPoints = Array.from(document.querySelectorAll('.govuk-list.govuk-list--bullet li'))
const bulletPoints = Array.from(document.querySelectorAll('.govuk-error-summary .govuk-list li'))
return bulletPoints.map(li => li.textContent.trim())
})

Expand Down
4 changes: 1 addition & 3 deletions test/integration/test_recieving_results.playwright.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ test('receiving a result with errors', async ({ page }) => {
await resultsPage.navigateToRequest('complete-errors')
await resultsPage.expectPageIsErrorsPage()

await page.getByText('1 geometry must be in Well-Known Text (WKT) format 1 documentation URL must be').click()

for (const error of errorResponse.response.data['error-summary']) {
await expect(page.locator('.govuk-list')).toContainText(error)
await expect(page.locator('ul.govuk-list')).toContainText(error)
}

const tableValues = await getTableContents(page, 'govuk-table')
Expand Down
11 changes: 9 additions & 2 deletions test/unit/errorsPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ describe('errors page', () => {
limit: 50
}

const summaryItem = (errorMessage) => {
return {
text: errorMessage,
href: ''
}
}

const params = {
options: {
tableParams: {
Expand All @@ -46,7 +53,7 @@ describe('errors page', () => {
fields: responseDetails.getFields()
},
requestParams: requestData.getParams(),
errorSummary: requestData.getErrorSummary(),
errorSummary: requestData.getErrorSummary().map(summaryItem),
mappings: responseDetails.getFieldMappings(),
verboseRows: responseDetails.getRowsWithVerboseColumns(),
pagination: responseDetails.getPagination(0)
Expand All @@ -65,7 +72,7 @@ describe('errors page', () => {
expect(errorItems.length).toEqual(6)

params.options.errorSummary.forEach((message, i) => {
expect(errorItems[i].textContent).toContain(message)
expect(errorItems[i].textContent).toContain(message.text)
})

// table
Expand Down
Loading

0 comments on commit 2d19b15

Please sign in to comment.