-
Notifications
You must be signed in to change notification settings - Fork 338
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
[DO NOT MERGE] Experiment with toggling the header colour via a top-level class in the review app #5746
Draft
owenatgov
wants to merge
1
commit into
main
Choose a base branch
from
recolour-header-class-with-swap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+211
−8
Draft
[DO NOT MERGE] Experiment with toggling the header colour via a top-level class in the review app #5746
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions
9
packages/govuk-frontend-review/src/common/lib/feature-flags.json
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,9 @@ | ||
[ | ||
{ | ||
"name": "Recolour", | ||
"description": "An experimentation of changing the colours of some things", | ||
"param": "recolour", | ||
"cookieName": "use-recolour", | ||
"affectedComponents": ["header"] | ||
} | ||
] |
53 changes: 53 additions & 0 deletions
53
packages/govuk-frontend-review/src/common/middleware/feature-flags.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,53 @@ | ||
import express from 'express' | ||
|
||
import featureFlags from '../lib/feature-flags.json' with { type: 'json' } | ||
|
||
const router = express.Router() | ||
|
||
router.use((req, res, next) => { | ||
// If we have the expected query param in the URL handle the cookie setting | ||
|
||
for (const flag of featureFlags) { | ||
if (req.method === 'GET' && flag.param in req.query) { | ||
if (req.query[flag.param] === 'true') { | ||
const maxAgeInDays = 28 | ||
|
||
res.cookie(flag.cookieName, 'yes', { | ||
maxAge: maxAgeInDays * 24 * 60 * 60 * 1000, | ||
httpOnly: true | ||
}) | ||
} else { | ||
res.clearCookie(flag.cookieName) | ||
} | ||
|
||
const urlWithoutQueryString = req.url.split('?')[0] | ||
return res.redirect(urlWithoutQueryString) | ||
} | ||
} | ||
|
||
// Let express carry on and handle the request as usual | ||
next() | ||
}) | ||
|
||
router.use((req, res, next) => { | ||
res.locals.featureFlagStates = {} | ||
|
||
for (const flag of featureFlags) { | ||
if (`${flag.param}Override` in req.query) { | ||
res.locals.featureFlagStates[flag.param] = | ||
req.query[`${flag.param}Override`] !== 'false' | ||
} else { | ||
res.locals.featureFlagStates[flag.param] = | ||
req.cookies?.[flag.cookieName] === '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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
@import "govuk/base"; | ||
@import "govuk/core"; | ||
|
||
.app-header--campaign { | ||
.app-header--campaign, | ||
.govuk-feature--recolour .app-header--campaign { | ||
owenatgov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
padding-bottom: govuk-spacing(2); | ||
} | ||
|
||
.govuk-feature--recolour .app-header--campaign { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ I like how having a global class enabling the feature allows us to easily update the app code to accomodate the flag (though I'd guess in a service, you'd either have or not have the flag enable so would need that less so). |
||
padding-bottom: 0; | ||
border-bottom: $govuk-border-width-wide solid #fff500; | ||
} | ||
|
||
|
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
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 featureFlagStates['recolour'] 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
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
21 changes: 21 additions & 0 deletions
21
packages/govuk-frontend-review/src/views/partials/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,21 @@ | ||
<div class="app-feature-flag-banner"> | ||
<div class="govuk-width-container"> | ||
<h2 class="govuk-heading-m">Feature flag control</h2> | ||
<p class="govuk-body">This component is impacted by the following feature flags:</p> | ||
|
||
{% for flag in featureFlags %} | ||
<h3 class="govuk-heading-s">{{ flag.name }}</h3> | ||
<p class="govuk-body">{{ flag.description }}</p> | ||
<p class="govuk-body"> | ||
<a class="govuk-button govuk-!-margin-bottom-0" href="?{{ flag.param }}={{ not featureFlagStates[flag.param] }}"> | ||
Turn flag '{{ flag.name }}' {{ 'off' if featureFlagStates[flag.param] else 'on' }} | ||
</a> | ||
</p> | ||
{% endfor %} | ||
<p class="govuk-body"> | ||
<a class="govuk-button govuk-!-margin-bottom-0" href="?showAllFlagStates={{ not showAllFlagStates }}"> | ||
{{ 'Only show one example state' if showAllFlagStates else 'Show both states' }} | ||
</a> | ||
</p> | ||
</div> | ||
</div> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Server-side URL redirect Medium