-
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.
refactor: Extract assessment answer presentation
This change extracts the handling of rendering assessment answers within another component, for example, a list of panels with a tag into another presenter. This will allow it to be shared by other parts of the app and give the ability to present the assessment answers in separate ways more easily. This change does still contain a style of loading settings internally that we would like to get rid of (see #696) as the refactor would be a much bigger and more time consuming change at this stage.
- Loading branch information
1 parent
9e9850a
commit db049af
Showing
8 changed files
with
126 additions
and
42 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
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
52 changes: 52 additions & 0 deletions
52
common/presenters/assessment-answers-to-meta-list-component.js
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,52 @@ | ||
const i18n = require('../../config/i18n') | ||
const filters = require('../../config/nunjucks/filters') | ||
|
||
function _mapAnswer({ | ||
comments, | ||
created_at: createdAt, | ||
nomis_alert_description: description, | ||
}) { | ||
let html = '' | ||
|
||
if (description) { | ||
html = ` | ||
<h4 class="govuk-!-margin-top-0 govuk-!-margin-bottom-2"> | ||
${description} | ||
</h4> | ||
` | ||
} | ||
|
||
html += comments || '' | ||
|
||
if (description) { | ||
html += ` | ||
<div class="app-secondary-text-colour govuk-!-margin-top-2 govuk-!-font-size-14"> | ||
${i18n.t('created_on')} ${filters.formatDateWithDay(createdAt)} | ||
</div> | ||
` | ||
} | ||
|
||
return { | ||
value: { | ||
html: ` | ||
<div> | ||
${ | ||
html || | ||
`<span class="app-secondary-text-colour">${i18n.t( | ||
'empty_details' | ||
)}</span>` | ||
} | ||
</div> | ||
`, | ||
}, | ||
} | ||
} | ||
|
||
function assessmentAnswersToMetaListComponent(answers = []) { | ||
return { | ||
classes: 'app-meta-list--divider govuk-!-font-size-16', | ||
items: answers.map(_mapAnswer), | ||
} | ||
} | ||
|
||
module.exports = assessmentAnswersToMetaListComponent |
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