-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
185 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/govuk-frontend-review/src/common/middleware/recolour.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import express from 'express' | ||
|
||
const router = express.Router() | ||
|
||
const RECOLOUR_COOKIE_NAME = 'use-recolour' | ||
|
||
router.use((req, res, next) => { | ||
// If we have the expected query param in the URL handle the cookie setting | ||
if (req.method === 'GET' && 'recolour' in req.query) { | ||
if (req.query.recolour === 'true') { | ||
const maxAgeInDays = 28 | ||
|
||
res.cookie(RECOLOUR_COOKIE_NAME, 'yes', { | ||
maxAge: maxAgeInDays * 24 * 60 * 60 * 1000, | ||
httpOnly: true | ||
}) | ||
} else { | ||
res.clearCookie(RECOLOUR_COOKIE_NAME) | ||
} | ||
|
||
const urlWithoutQueryString = req.url.split('?')[0] | ||
return res.redirect(urlWithoutQueryString) | ||
Check warning Code scanning / CodeQL Server-side URL redirect Medium
Untrusted URL redirection depends on a
user-provided value Error loading related location Loading |
||
} | ||
|
||
// Let express carry on and handle the request as usual | ||
next() | ||
}) | ||
|
||
router.use((req, res, next) => { | ||
if ('recolourOverride' in req.query) { | ||
res.locals.useRecolourClass = req.query.recolourOverride !== 'false' | ||
} else { | ||
res.locals.useRecolourClass = req.cookies?.[RECOLOUR_COOKIE_NAME] === 'yes' | ||
} | ||
|
||
next() | ||
}) | ||
|
||
router.use((req, res, next) => { | ||
res.locals.showAllFlagStates = | ||
'showAllFlagStates' in req.query && req.query.showAllFlagStates === 'true' | ||
next() | ||
}) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
packages/govuk-frontend-review/src/stylesheets/full-page-examples/campaign-page.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/govuk-frontend-review/src/stylesheets/partials/_feature-flag-banner.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.app-feature-flag-banner { | ||
padding: govuk-spacing(4) 0; | ||
border-bottom: 1px solid govuk-colour("mid-grey"); | ||
background-color: govuk-colour("light-grey"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/govuk-frontend-review/src/views/layouts/full-page-example.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{% extends "layouts/_generic.njk" %} | ||
|
||
{% set htmlClasses = "govuk-feature--recolour" if useRecolourClass else "" %} | ||
|
||
|
||
{% block banner %} | ||
{% include "../partials/exampleBanner.njk" %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/govuk-frontend-review/src/views/macros/featureFlags.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% macro featureFlags(useRecolourClass, showBothStatesButton, showBothStatesParam) %} | ||
<div class="app-feature-flag-banner"> | ||
<div class="govuk-width-container"> | ||
<h2 class="govuk-heading-m">Feature flag control</h2> | ||
<a class="govuk-button govuk-!-margin-bottom-0" href="?recolour={{ not useRecolourClass }}"> | ||
Turn {{ 'off' if useRecolourClass else 'on' }} updated header | ||
</a> | ||
{% if showBothStatesButton %} | ||
<a class="govuk-button govuk-!-margin-bottom-0" href="?showAllFlagStates={{ not showBothStatesParam }}"> | ||
{{ 'Only show one state' if showBothStatesParam else 'Show both states' }} | ||
</a> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters