Skip to content

Commit 18c6cda

Browse files
authored
[WIP] Consumer views (#53)
* Accept a base page layout path in plugin options * remove non-engine pages, leaving just a development UI * allow plugin consumer to provide viewContext props * Export engine dir * take nunjucks paths and view context from consumer * add local devtool UI * Drop redundant configureEnginePlugin * make DXT devtool layout more obvious * update docs * fix circular reference error when stringifying error * an example of custom styling * remove unused type * Remove service banner text * Remove cookies + blankie * Revert "Drop redundant configureEnginePlugin" This reverts commit a8a59a7. * remove runner responsibilities: health, cookies tests * remove runner responsibility: feedback tests * Remove consumer responsibility: phase banner * fix linting issues * Remove runner responsibility: help page tests * Move devtool view context into separate function * Load engine forms from disk * Only load file-based forms when running the devserver * Resolve form mocking issue when running tests * Move base layout into nunjucks options * clarify when localFormsService returns a function, not the serviec * patch context test for new required plugin
1 parent 1e962d8 commit 18c6cda

56 files changed

Lines changed: 986 additions & 3714 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/GETTING_STARTED.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,44 @@ await server.register({
9292
}
9393
})
9494

95+
const viewPaths = [join(config.get('appDir'), 'views')]
96+
9597
// Register the `forms-engine-plugin`
9698
await server.register({
97-
plugin
99+
plugin,
100+
options: {
101+
cacheName: 'session', // must match a session you've instantiated in your hapi server config
102+
/**
103+
* Options that DXT uses to render Nunjucks templates
104+
*/
105+
nunjucks: {
106+
basePageLayout: 'your-base-layout.html', // the base page layout. Usually based off https://design-system.service.gov.uk/styles/page-template/
107+
viewPaths // list of directories DXT should use to render your views. Must contain basePageLayout.
108+
},
109+
/**
110+
* Services is what DXT uses to interact with external APIs
111+
*/
112+
services: {
113+
formsService, // where your forms should be downloaded from.
114+
formSubmissionService, // handles temporary storage of file uploads
115+
outputService // where your form should be submitted to
116+
},
117+
/**
118+
* View context attributes made available to your pages. Returns an object containing an arbitrary set of key-value pairs.
119+
*/
120+
viewContext: (request) => {
121+
"example": "hello world" // available to render on a nunjucks page as {{ example }}
122+
}
123+
}
98124
})
99125

100126
await server.start()
101127
```
102128

103129
## Step 3: Handling static assets
104130

131+
TODO: CSS will be updated with a proper build process using SASS.
132+
105133
1. [Update webpack to bundle the DXT application assets (CSS, JavaScript, etc)](https://github.com/DEFRA/forms-engine-plugin-example-ui/pull/1/files#diff-1fb26bc12ac780c7ad7325730ed09fc4c2c3d757c276c3dacc44bfe20faf166f)
106134
2. [Serve the newly bundled assets from your web server](https://github.com/DEFRA/forms-engine-plugin-example-ui/pull/1/files#diff-e5b183306056f90c7f606b526dbc0d0b7e17bccd703945703a0811b6e6bb3503)
107135

@@ -116,8 +144,7 @@ Blocks marked with `# FEATURE: <name>` are optional and can be omitted if the fe
116144
FEEDBACK_LINK=http://test.com
117145
# END FEATURE: Phase banner
118146

119-
# START FEATURE: DXT -- used if using DXT's infrastructure to store your forms and file uploads
120-
MANAGER_URL=http://localhost:3001
147+
# START FEATURE: DXT -- used if using DXT's infrastructure for file uploads
121148
DESIGNER_URL=http://localhost:3000
122149
SUBMISSION_URL=http://localhost:3002
123150

jest.setup.cjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
process.env.MANAGER_URL = 'http://localhost:3001'
21
process.env.REDIS_HOST = 'dummy'
32
process.env.REDIS_KEY_PREFIX = 'forms-designer'
43
process.env.REDIS_PASSWORD = 'dummy'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"./file-form-service.js": "./.server/server/utils/file-form-service.js",
2525
"./controllers/*": "./.server/server/plugins/engine/pageControllers/*",
2626
"./services/*": "./.server/server/plugins/engine/services/*",
27+
"./engine/*": "./.server/server/plugins/engine/*",
2728
"./package.json": "./package.json"
2829
},
2930
"scripts": {

src/client/stylesheets/application.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@
1212
.autocomplete__option {
1313
@include govuk-typography-common;
1414
}
15+
16+
// An example of some user-supplied styling
17+
// Not great practice but it illustrates the point
18+
.govuk-header {
19+
background: #008531;
20+
}
21+
22+
.govuk-header__container {
23+
border-bottom: 10px solid #003d16;
24+
}

src/common/cookies.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/common/cookies.test.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/common/types.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/config/index.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,6 @@ export const config = convict({
179179
/**
180180
* API integrations
181181
*/
182-
managerUrl: {
183-
format: String,
184-
default: 'http://localhost:3001',
185-
env: 'MANAGER_URL'
186-
} as SchemaObj<string>,
187-
188182
designerUrl: {
189183
format: String,
190184
default: 'http://localhost:3000',
@@ -253,19 +247,12 @@ export const config = convict({
253247
env: 'STAGING_PREFIX'
254248
},
255249

256-
serviceBannerText: {
257-
doc: 'Service banner text used to show a maintenance message on all pages when set',
258-
format: String,
259-
default: '',
260-
env: 'SERVICE_BANNER_TEXT'
261-
},
262-
263-
googleAnalyticsTrackingId: {
264-
doc: 'Google analytics tracking ID to be used when a user has opted in to additional cookies',
250+
submissionEmailAddress: {
251+
doc: 'Email address to send the form to (local devtool only)',
265252
format: String,
266253
default: '',
267-
env: 'GOOGLE_ANALYTICS_TRACKING_ID'
268-
}
254+
env: 'SUBMISSION_EMAIL_ADDRESS'
255+
} as SchemaObj<string>
269256
})
270257

271258
config.validate({ allowed: 'strict' })
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{% extends "govuk/template.njk" %}
2+
3+
{% from "govuk/components/back-link/macro.njk" import govukBackLink -%}
4+
{% from "govuk/components/footer/macro.njk" import govukFooter -%}
5+
{% from "govuk/components/phase-banner/macro.njk" import govukPhaseBanner -%}
6+
{% from "govuk/components/skip-link/macro.njk" import govukSkipLink -%}
7+
{% from "govuk/macros/attributes.njk" import govukAttributes -%}
8+
{% from "components/service-banner/macro.njk" import appServiceBanner -%}
9+
{% from "components/tag-env/macro.njk" import appTagEnv -%}
10+
{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner -%}
11+
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner -%}
12+
13+
{% set productName %}
14+
{{ appTagEnv({ env: "devtool" }) }}
15+
{% endset %}
16+
17+
{% block head %}
18+
<link rel="preload" as="font" href="{{ assetPath }}/fonts/bold-b542beb274-v2.woff2" type="font/woff2" crossorigin="anonymous">
19+
<link rel="preload" as="font" href="{{ assetPath }}/fonts/light-94a07e06a1-v2.woff2" type="font/woff2" crossorigin="anonymous">
20+
<link rel="stylesheet" href="{{ getDxtAssetPath("stylesheets/application.scss") }}">
21+
{% endblock %}
22+
23+
{% block pageTitle -%}
24+
{{ "Error: " if errors | length }}{{ pageTitle | evaluate }} - {{ name if name else config.serviceName }} - GOV.UK
25+
{%- endblock %}
26+
27+
{% block skipLink %}
28+
{{ govukSkipLink({
29+
href: '#main-content',
30+
text: 'Skip to main content'
31+
}) }}
32+
{% endblock %}
33+
34+
{% block header %}
35+
{{ govukHeader({
36+
homepageUrl: currentPath if context.isForceAccess else "https://defra.github.io/forms-engine-plugin/",
37+
containerClasses: "govuk-width-container",
38+
productName: productName | safe | trim,
39+
serviceName: "Digital Express Toolkit",
40+
serviceUrl: currentPath if context.isForceAccess else serviceUrl
41+
}) }}
42+
{% endblock %}
43+
44+
{% block beforeContent %}
45+
{% if backLink %}
46+
{{ govukBackLink(backLink) }}
47+
{% endif %}
48+
{% endblock %}
49+
50+
{% block content %}
51+
<h1 class="govuk-heading-l">Default page template</h1>
52+
{% endblock %}
53+
54+
{% block bodyEnd %}
55+
<script type="module" nonce="{{ cspNonce }}" src="{{ getDxtAssetPath("application.js") }}"></script>
56+
{% endblock %}
57+
58+
{% block footer %}
59+
{% set meta = {
60+
items: [
61+
{
62+
href: 'https://defra.github.io/forms-engine-plugin/',
63+
text: 'DXT documentation'
64+
}
65+
]
66+
} if slug %}
67+
68+
{% if not context.isForceAccess %}
69+
{{ govukFooter({ meta: meta }) }}
70+
{% endif %}
71+
{% endblock %}

src/server/forms/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)