generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DT-2902 Basic plumbing for a demo page for GraphQL
- Loading branch information
Showing
22 changed files
with
617 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* ========================================================================== | ||
COMPONENTS / #CARD | ||
========================================================================== */ | ||
|
||
$card-border-width: 1px; | ||
$card-border-bottom-width: govuk-spacing(1); | ||
$card-border-hover-color: $govuk-border-colour; | ||
$card-border-color: lighten($card-border-hover-color, 15%); | ||
|
||
.card { | ||
margin-bottom: govuk-spacing(7); | ||
background: $govuk-body-background-colour; | ||
border: $card-border-width solid $card-border-color; | ||
position: relative; | ||
width: 100%; | ||
padding: govuk-spacing(5); | ||
|
||
&__heading { | ||
margin-top: 0; | ||
margin-bottom: govuk-spacing(3); | ||
} | ||
|
||
&__description { | ||
margin-bottom: 0; | ||
} | ||
|
||
/* Clickable card | ||
========================================================================== */ | ||
&--clickable { | ||
border-bottom-width: $card-border-bottom-width; | ||
|
||
&:hover, | ||
&:active { | ||
cursor: pointer; | ||
|
||
.card__heading a, | ||
.card__link { | ||
color: $govuk-link-hover-colour; | ||
text-decoration: none; | ||
|
||
&:focus { | ||
@include govuk-focused-text; | ||
} | ||
} | ||
} | ||
|
||
&:hover { | ||
border-color: $card-border-hover-color; | ||
} | ||
|
||
&:active { | ||
border-color: $card-border-hover-color; | ||
bottom: -$card-border-width; | ||
} | ||
} | ||
} | ||
|
||
/* Card group | ||
========================================================================== */ | ||
|
||
/** | ||
* Card group allows you to have a row of cards. | ||
* | ||
* Flexbox is used to make each card in a row the same height. | ||
*/ | ||
|
||
.card-group { | ||
display: flex; | ||
flex-wrap: wrap; | ||
margin-bottom: govuk-spacing(3); | ||
padding: 0; | ||
|
||
@include govuk-media-query($until: desktop) { | ||
margin-bottom: govuk-spacing(6); | ||
} | ||
|
||
&__item { | ||
display: flex; | ||
list-style-type: none; | ||
margin-bottom: 0; | ||
|
||
@include govuk-media-query($until: desktop) { | ||
flex: 0 0 100%; | ||
} | ||
|
||
.card { | ||
margin-bottom: govuk-spacing(5); | ||
} | ||
|
||
@include govuk-media-query($until: desktop) { | ||
.card { | ||
margin-bottom: govuk-spacing(3); | ||
} | ||
|
||
&:last-child .card { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
} |
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
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
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
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,11 +1,13 @@ | ||
import createApp from './app' | ||
import HmppsAuthClient from './data/hmppsAuthClient' | ||
import TokenStore from './data/tokenStore' | ||
import GraphQLDemoService from './services/graphQLDemoService' | ||
import UserService from './services/userService' | ||
|
||
const hmppsAuthClient = new HmppsAuthClient(new TokenStore()) | ||
const userService = new UserService(hmppsAuthClient) | ||
const graphQLDemoService = new GraphQLDemoService(hmppsAuthClient) | ||
|
||
const app = createApp(userService) | ||
const app = createApp(userService, graphQLDemoService) | ||
|
||
export default app |
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,35 @@ | ||
import { Request, Response } from 'express' | ||
|
||
import GraphQLDemoService from '../../services/graphQLDemoService' | ||
|
||
export default class GraphqlDemoController { | ||
constructor(private readonly graphQLDemoService: GraphQLDemoService) {} | ||
|
||
async demo(req: Request, res: Response): Promise<void> { | ||
const form = req.session.prisonerSearchForm || {} | ||
const errors = req.flash('errors') || [] | ||
res.render('pages/graphql/demo', { form, errors }) | ||
} | ||
|
||
async details(req: Request, res: Response): Promise<void> { | ||
const { id } = req.query as { id: string } | ||
const form = req.session.prisonerSearchForm || {} | ||
req.session.prisonerSearchForm = { ...form, prisonerNumber: id } | ||
const prisoners = await this.graphQLDemoService.search({}, req.session.prisonerSearchForm) | ||
res.render('pages/graphql/prisoner-details', { data: JSON.stringify(prisoners), prisoner: prisoners[0] }) | ||
} | ||
|
||
async search(req: Request, res: Response): Promise<void> { | ||
req.session.prisonerSearchForm = { ...req.body } | ||
const prisoners = await this.graphQLDemoService.search({}, req.session.prisonerSearchForm) | ||
|
||
if (prisoners.length > 1) { | ||
res.render('pages/graphql/search-results', { data: JSON.stringify(prisoners), prisoners }) | ||
} else if (prisoners.length === 1) { | ||
res.render('pages/graphql/prisoner-details', { data: JSON.stringify(prisoners), prisoner: prisoners[0] }) | ||
} else { | ||
req.flash('errors', [{ text: 'No prisoners found' }]) | ||
res.redirect('/graphql/demo') | ||
} | ||
} | ||
} |
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 @@ | ||
import type { RequestHandler, Router } from 'express' | ||
|
||
import asyncMiddleware from '../../middleware/asyncMiddleware' | ||
import GraphQLDemoService from '../../services/graphQLDemoService' | ||
import GraphQLDemoController from './graphQLDemoController' | ||
|
||
export interface Services { | ||
graphQLDemoService: GraphQLDemoService | ||
} | ||
export default function routes(router: Router, services: Services): Router { | ||
const get = (path: string, handler: RequestHandler) => router.get(path, asyncMiddleware(handler)) | ||
const post = (path: string, handler: RequestHandler) => router.post(path, asyncMiddleware(handler)) | ||
|
||
const graphqlDemoController = new GraphQLDemoController(services.graphQLDemoService) | ||
|
||
get('/graphql/demo', (req, res) => graphqlDemoController.demo(req, res)) | ||
get('/graphql/details', (req, res) => graphqlDemoController.details(req, res)) | ||
post('/graphql/search', (req, res) => graphqlDemoController.search(req, res)) | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import type { RequestHandler, Router } from 'express' | ||
|
||
import graphQLRoutes from './graphql/graphQLRouter' | ||
|
||
import asyncMiddleware from '../middleware/asyncMiddleware' | ||
import GraphQLDemoService from '../services/graphQLDemoService' | ||
|
||
export interface Services { | ||
graphQLDemoService: GraphQLDemoService | ||
} | ||
|
||
export default function routes(router: Router): Router { | ||
export default function routes(router: Router, services: Services): Router { | ||
const get = (path: string, handler: RequestHandler) => router.get(path, asyncMiddleware(handler)) | ||
|
||
get('/', (req, res, next) => { | ||
res.render('pages/index') | ||
}) | ||
graphQLRoutes(router, services) | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import HmppsAuthClient from '../../data/hmppsAuthClient' | ||
import GraphQLDemoService from '../../services/graphQLDemoService' | ||
|
||
jest.mock('../../services/graphQLDemoService') | ||
|
||
const graphQLDemoService = new GraphQLDemoService({} as HmppsAuthClient) as jest.Mocked<GraphQLDemoService> | ||
|
||
export default graphQLDemoService |
Oops, something went wrong.