Skip to content

Commit

Permalink
Add Change Request to hint and block other components
Browse files Browse the repository at this point in the history
  • Loading branch information
albertkol committed Jan 30, 2025
1 parent 4c0a6ac commit 4a120aa
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
31 changes: 31 additions & 0 deletions runner/src/client/sass/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,34 @@ $govuk-global-styles: true;
list-style-type: revert;
padding-left: revert;
}

.change-request-block {
padding: 0 0 0 15px;
margin: 15px 0;
border-color: #1d70b8;
header {
margin-bottom: 5px;
font-weight: bold;
p {
margin: 5px 0 0;
}
}
}

.change-request-disabled {
padding: 0 0 0 15px;
margin: 15px 0;
header {
margin-bottom: 5px;
font-weight: bold;
p {
margin: 5px 0 0;
}
}
}

.govuk-input--disabled {
cursor: not-allowed; /* Changes the cursor to indicate it's not interactive */
opacity: 0.5; /* Makes it visually appear disabled */
pointer-events: none; /* Disables click and other interactions */
}
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,18 @@ export class PageControllerBase {
}
return redirectTo(request, h, `/${this.model.basePath}/summary`);
}

if (state["metadata"] && state["metadata"]["change_requests"] && state.shouldGoToSummary !== false) {
// If there are Change Requests, redirect to Summary page, only the 1st time
await adapterCacheService.mergeState(request, {shouldGoToSummary: false});

let form_session_identifier = state.metadata?.form_session_identifier ?? "";
if (form_session_identifier) {
return redirectTo(request, h, `/${this.model.basePath}/summary?form_session_identifier=${form_session_identifier}`)
}
return redirectTo(request, h, `/${this.model.basePath}/summary`);
}

const progress = state.progress || [];
const {num} = request.query;
const currentPath = `/${this.model.basePath}${this.path}${request.url.search}`;
Expand Down Expand Up @@ -647,6 +659,51 @@ export class PageControllerBase {
);
}

const changeRequests = state["metadata"]["change_requests"];
if (changeRequests === null) {
// No Change Requests - Quick return

return evaluatedComponent;
}

// If there are Change Requests
const componentName = evaluatedComponent.model.name || "";
if (componentName in changeRequests) {
// Component has Change Request - Add feedback to hint

if (evaluatedComponent.model.hint === undefined) {
evaluatedComponent.model.hint = {html: ""};
}

const messages = changeRequests[componentName];
if (messages) {
const hints = messages.map((msg) => `<p>${msg}</p>`).join("");
evaluatedComponent.model.hint.html += `<div class="govuk-inset-text change-request-block"><header>Assessor feedback</header>${hints}</div>`;
}

return evaluatedComponent;
}

// Component has no Change Request
const pageHasNoComponentWithChangeRequest = this.pageDef.components.find(component => component.name in changeRequests);
if (pageHasNoComponentWithChangeRequest === undefined) {
// if no Change Request on page - We got here through a condition

return evaluatedComponent;
}


// Change Request on page - Disable all other components on page
if (evaluatedComponent.model.classes === undefined) {
evaluatedComponent.model.classes = "";
}
evaluatedComponent.model.classes += " govuk-input--disabled";

if (evaluatedComponent.model.hint === undefined) {
evaluatedComponent.model.hint = {html: ""};
}
evaluatedComponent.model.hint.html += `<div class="govuk-inset-text change-request-disabled"><header>Cannot edit</header></div>`;

return evaluatedComponent;
});

Expand Down

0 comments on commit 4a120aa

Please sign in to comment.