Skip to content

Commit

Permalink
FS-3664: read-only summary flag on the summary page
Browse files Browse the repository at this point in the history
This introduces a new flag `is_read_only_summary` that can be passed in
the existing `metadata` payload when instantiating a new form. This
instructs the summary page to not show "Change" links on the questions
summary list and provides a direct back link.

Currently this fixes the back link and page title text for the summary
page according to if the flag is set but it would be preferable for
these values to be set using options bassed in my the service requesting
a new form rather than fixed in the form logic -- if there are existing
`options` payloads for customising this we should move to use those.

I'm applying the change to the existing custom form builder as well as
the newer form builder adpater to not be blocked on deployments as the
new patterns gains maturity and is released in different environments.

Note it doesn't look like individual flags like this are curretly
covered by tests even though they can change the behaviour of the
server, I'll look to do this in lining up with the methodology used by
the newer form builder adapter.
  • Loading branch information
sfount committed Sep 4, 2024
1 parent dbad3fa commit 2b202a6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions runner/src/server/plugins/engine/models/viewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class ViewModel {
saveAndContinueText: string;
confirmAndContinueText?: string;
isConfirmPageControllerRequest?: boolean;
isReadOnlySummary?: boolean;
continueText: string;
footer?: any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ export class SummaryPageController extends PageController {
);
viewModel.backLink = state.callback?.returnUrl;
}
if (state["metadata"] && state["metadata"]["is_read_only_summary"]) {
viewModel.isReadOnlySummary =
state["metadata"]["is_read_only_summary"];
viewModel.backLinkText = UtilHelper.getBackLinkText(
true,
this.model.def?.metadata?.isWelsh
);
viewModel.backLink = state.callback?.returnUrl;
}

return h.view("summary", viewModel);
};
}
Expand Down
6 changes: 3 additions & 3 deletions runner/src/server/views/partials/summary-detail.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% from "./summary-row.html" import summaryRow %}

{% macro summaryDetail(data) %}
{% macro summaryDetail(data, isReadOnlySummary=false) %}
{% set isRepeatableSection = (data.items[0] | isArray) %}
{% if not isRepeatableSection %}
{% if (not isRepeatableSection and not isReadOnlySummary) %}
<h2 class="govuk-heading-m">{{data.title}}</h2>
{% endif %}
<dl class="govuk-summary-list">
Expand All @@ -14,7 +14,7 @@ <h2 class="govuk-heading-m govuk-!-margin-top-4 govuk-!-margin-bottom-0">{{data.
{{ summaryRow(repeated) }}
{% endfor %}
{% else %}
{{ summaryRow(item, data.notSuppliedText, data.changeText) }}
{{ summaryRow(item, data.notSuppliedText, data.changeText, isReadOnlySummary) }}
{% endif %}
{% endif %}
{% endfor %}
Expand Down
4 changes: 3 additions & 1 deletion runner/src/server/views/partials/summary-row.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro summaryRow(item, notSuppliedText, changeText) %}
{% macro summaryRow(item, notSuppliedText, changeText, isReadOnlySummary) %}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
{{item.label}}
Expand Down Expand Up @@ -47,9 +47,11 @@
{% endif %}
</dd>
<dd class="govuk-summary-list__actions">
{% if not isReadOnlySummary %}
<a class="govuk-link" href="{{item.url}}">
{{changeText}}<span class="govuk-visually-hidden"> {{item.label}}</span>
</a>
{% endif %}
</dd>
</div>
{% endmacro %}
20 changes: 16 additions & 4 deletions runner/src/server/views/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
{% from "components/checkboxes/macro.njk" import govukCheckboxes %}
{% extends 'layout.html' %}

{% set pageTitle = pageTitle if not isReadOnlySummary else "View your answers" %}

{% block beforeContent %}
{{ govukPhaseBanner({
tag: {
text: "beta"
},
html: "This is a new service."
}) }}
{% if isConfirmPageControllerRequest %}
{% if isConfirmPageControllerRequest or isReadOnlySummary %}
{{ govukBackLink({
href: backLink,
text: backLinkText
text: backLinkText if not isReadOnlySummary else "Back to application for funding overview"
}) }}
{% endif %}
{% endblock %}
Expand All @@ -24,6 +26,11 @@
{% if migrationBannerEnabled %}
{{migrationBanner()}}
{% endif %}

{% set hasMultipleSections = (details and details.length > 1 and details[0].items[0] | isArray) %}
{% if not hasMultipleSections %}
<span class="govuk-caption-l">{{ details[0].title }}</span>
{% endif %}
<h1 class="govuk-heading-l">{{ pageTitle }}</h1>
{% if callback and callback.message %}
<div class="govuk-inset-text">
Expand All @@ -35,8 +42,13 @@ <h1 class="govuk-heading-l">{{ pageTitle }}</h1>
Check your uploaded file is visible. If not, upload it again.
</div>
{% endif %}

{% if isReadOnlySummary %}
<p class="govuk-body">You cannot change your answers.</p>
{% endif %}

{% for detail in details %}
{{ summaryDetail(detail) }}
{{ summaryDetail(detail, isReadOnlySummary) }}
{% endfor %}

{% if fees and fees.details|length %}
Expand All @@ -49,7 +61,7 @@ <h2 class="govuk-heading-m">Fees</h2>
<p class="govuk-body">Total cost: £{{fees.total / 100 }}</p>
{% endif %}

{% if not result.error %}
{% if not result.error and not isReadOnlySummary %}
<form method="post" enctype="multipart/form-data" autocomplete="off" novalidate>
<input type="hidden" name="crumb" value="{{crumb}}"/>

Expand Down

0 comments on commit 2b202a6

Please sign in to comment.