Skip to content

Commit

Permalink
Switch to use breadcrumb trail
Browse files Browse the repository at this point in the history
- Replace backlink with breadcrumb trail
- Update drugs section page titles
  • Loading branch information
LucasCairns committed Oct 7, 2024
1 parent 21ca5f8 commit bea367a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 1 addition & 7 deletions app/controllers/saveAndContinueController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ class SaveAndContinueController extends BaseController {
req.form.persistedAnswers,
).getPageNavigation()

const getBackLinkFromTrail = (currentStep: string, stepsTaken: string[]) => {
const currentStepIndex = stepsTaken.indexOf(currentStep)

return currentStepIndex > 0 ? stepsTaken[currentStepIndex - 1] : null
}

res.locals.generatedBackLink = getBackLinkFromTrail(req.url.slice(1), pageNavigation.stepsTaken)
res.locals.stepsTaken = pageNavigation.stepsTaken

if (req.query.action === 'resume') {
const currentPageToComplete = pageNavigation.url
Expand Down
6 changes: 6 additions & 0 deletions app/form/v1_0/steps/drugs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const sectionConfig: SectionConfig = {
section,
steps: [
{
pageTitle: 'Drug use',
url: stepUrls.drugs,
fields: [
drugsFields.drugUseGroup,
Expand All @@ -32,6 +33,7 @@ const sectionConfig: SectionConfig = {
sectionProgressRules: [setFieldToIncomplete(section.sectionCompleteField)],
},
{
pageTitle: 'Drug use details',
url: stepUrls.drugUse,
fields: [
drugsFields.drugUsageDetailsGroup,
Expand All @@ -42,6 +44,7 @@ const sectionConfig: SectionConfig = {
sectionProgressRules: [setFieldToIncomplete(section.sectionCompleteField)],
},
{
pageTitle: 'Select drugs',
url: stepUrls.selectDrugs,
fields: [
drugsFields.drugUseTypeGroup,
Expand All @@ -53,6 +56,7 @@ const sectionConfig: SectionConfig = {
sectionProgressRules: [setFieldToIncomplete(section.sectionCompleteField)],
},
{
pageTitle: 'Drug usage details',
url: stepUrls.drugUsageDetails,
fields: [
drugsFields.drugUseTypeDetailsGroup,
Expand All @@ -64,6 +68,7 @@ const sectionConfig: SectionConfig = {
sectionProgressRules: [setFieldToIncomplete(section.sectionCompleteField)],
},
{
pageTitle: 'Drug use changes',
url: stepUrls.drugUseChanges,
fields: [
drugsFields.wantToMakeChanges(),
Expand All @@ -74,6 +79,7 @@ const sectionConfig: SectionConfig = {
sectionProgressRules: [setFieldToIncomplete(section.sectionCompleteField)],
},
{
pageTitle: 'Summary',
url: stepUrls.summary,
fields: [
drugsFields.practitionerAnalysis(),
Expand Down
5 changes: 4 additions & 1 deletion app/utils/fieldDependencyTreeBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,10 @@ describe('app/utils/fieldDependencyTreeBuilder', () => {

expect(result).toEqual({
url: 'step-2',
stepsTaken: ['step-1', 'step-2'],
stepsTaken: [
{ href: 'step-1', pageTitle: 'Step 1' },
{ href: 'step-2', text: 'Step 2' },
],
isSectionComplete: false,
})
})
Expand Down
4 changes: 2 additions & 2 deletions app/utils/fieldDependencyTreeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class FieldDependencyTreeBuilder {
)
}

getPageNavigation(): { url: string; stepsTaken: string[]; isSectionComplete: boolean } {
getPageNavigation(): { url: string; stepsTaken: Array<{ href: string; text: string }>; isSectionComplete: boolean } {
const [initialStepPath, initialStep] = this.getInitialStep()

let nextStep = initialStepPath
Expand All @@ -241,7 +241,7 @@ export class FieldDependencyTreeBuilder {

for (const [stepUrl, step] of steps) {
nextStep = stepUrl
stepsTaken.push(stepUrl)
stepsTaken.push({ href: stepUrl, text: step.pageTitle })

const hasErrors = Object.values(step.fields)
.filter(it => dependencyMet(it, this.answers))
Expand Down
9 changes: 3 additions & 6 deletions server/views/forms/default.njk
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{% extends "./layout.njk" %}
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "govuk/components/back-link/macro.njk" import govukBackLink %}
{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% from "components/question/macro.njk" import renderQuestion %}
{% from "govuk/components/breadcrumbs/macro.njk" import govukBreadcrumbs %}

{% block backLink %}
{%- if generatedBackLink -%}
{{ govukBackLink({
text: "Back",
href: generatedBackLink
}) }}
{%- if stepsTaken -%}
{{ govukBreadcrumbs({ items: stepsTaken }) }}
{%- endif -%}
{% endblock %}

Expand Down

0 comments on commit bea367a

Please sign in to comment.