-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FSR-1237 | Add Latest Levels on TA Warnings Page (#782)
* FSR-1237: Add logic to show trigger levels on target area page * FSR-1237: Add CSS for latest levels box * FSR-1237: Update the logic to not show the latest levels box for TAs with more than 4 thresholds * FSR-1237: Fix failing tests, update hyperlink text in target-area.html, and refactor code * FSR-1237: Add unit tests for latest levels box * FSR-1237: Fix SonarCloud issues and refactor code for improved quality * FSR-1237: Add logic to show 'levels unavailable' message for offline and suspended stations and fix tests * FSR-1237: Add unit tests for stations with different status * FSR-1237: Exclude Closed and Welsh stations with no data from latest levels display and add tests * FSR-1237: Refactor code to move HTML logic to the model and change the method name to en-UK spelling * FSR-1237: Fix css * FSR-1237: Fix console errors * FSR-1237: Update elapsed time formatting and tests * FSR-1237: Refactor code --------- Co-authored-by: nikiwycherley <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,398 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { formatElapsedTime } = require('../../../util') | ||
|
||
const WARNING_THRESHOLD_TYPES = ['FW RES FW', 'FW ACT FW', 'FW ACTCON FW'] | ||
|
||
function getThresholdsForTargetArea (thresholds) { | ||
const filteredThresholds = thresholds.filter(threshold => | ||
threshold.status !== 'Closed' && | ||
!(threshold.iswales && threshold.latest_level === null) | ||
) | ||
|
||
const warningThresholds = findPrioritisedThresholds(filteredThresholds, WARNING_THRESHOLD_TYPES) | ||
return warningThresholds.map(threshold => { | ||
threshold.formatted_time = formatElapsedTime(threshold.value_timestamp) | ||
threshold.isSuspendedOrOffline = threshold.status === 'Suspended' || (threshold.status === 'Active' && threshold.latest_level === null) | ||
return threshold | ||
}) | ||
} | ||
|
||
function findPrioritisedThresholds (thresholds, types) { | ||
const thresholdMap = {} | ||
|
||
for (const type of types) { | ||
for (const threshold of thresholds) { | ||
if (threshold.threshold_type === type && !thresholdMap[threshold.rloi_id]) { | ||
thresholdMap[threshold.rloi_id] = threshold | ||
} | ||
} | ||
} | ||
|
||
return Object.values(thresholdMap) | ||
} | ||
|
||
module.exports = getThresholdsForTargetArea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.defra-live { | ||
position: relative; | ||
border: 2px solid govuk-colour('blue'); | ||
margin-top: 30px; | ||
margin-bottom: 15px; | ||
padding: 15px; | ||
&__title { | ||
@extend .govuk-tag; | ||
@include govuk-font($size: 16); | ||
margin-top: 0px; | ||
margin-bottom: 15px; | ||
font-weight: bold; | ||
text-transform: uppercase; | ||
background-color: #1C70B8; | ||
color: white; | ||
} | ||
&__supplementary { | ||
@include govuk-font($size: 16); | ||
color: $govuk-secondary-text-colour; | ||
margin: 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="defra-live"> | ||
<h2 class="defra-live__title">Latest level{% if model.latestLevels.length > 1 %}s{% endif %}</h2> | ||
{% for warnings in model.latestLevels %} | ||
<div class="defra-live__item"> | ||
{% if warnings.isSuspendedOrOffline %} | ||
<p class="defra-flood-meta defra-flood-meta--no-border govuk-!-margin-bottom-0"><strong>Latest Level</strong></p> | ||
<p>The {{ warnings.river_name }} level at {{ warnings.agency_name }} is currently unavailable.</p> | ||
{% else %} | ||
<p class="defra-flood-meta defra-flood-meta--no-border govuk-!-margin-bottom-0"><strong>{{ warnings.formatted_time }}</strong></p> | ||
<p>The {{ warnings.river_name }} level at {{ warnings.agency_name }} was {{ warnings.latest_level | toFixed(2) }} metres. Property flooding is possible when it goes above {{ warnings.threshold_value | toFixed(2) }} metres. | ||
{% if model.latestLevels.length > 1 %} | ||
<a href="/station/{{ warnings.rloi_id }}{% if warnings.direction == 'd' %}-downstage{% endif %}">Monitor the {{ warnings.river_name }} level at {{ warnings.agency_name }}</a> | ||
{% endif %} | ||
</p> | ||
{% if model.latestLevels.length == 1 %} | ||
<p> | ||
<a href="/station/{{ warnings.rloi_id }}{% if warnings.direction == 'd' %}-downstage{% endif %}">Monitor the latest{% if model.latestLevels.length > 1 %} {{ warnings.river_name }}{% endif %} level at {{ warnings.agency_name }}</a> | ||
</p> | ||
{% endif %} | ||
{% endif %} | ||
</div> | ||
{% endfor %} | ||
</div> |
Oops, something went wrong.