Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to use breadcrumb trail #630

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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