-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- new route: '/check/link' which requires query params and redirects to the correct step in the wizard - added DeepLinkController - to populate the session/history with passed query params - new filter for generating a deep link (path+params) - removed cookie parser (express docs say it's no longer needed and can actually cause issues) - update check tool templates to display the dataset and organisation names when the wizard was entered via a deep link - some utility functions/maps to simplify looking up datasets info - moved a predicate out of DatasetController so it can be reused
- Loading branch information
Showing
25 changed files
with
326 additions
and
75 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
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,59 @@ | ||
import PageController from './pageController.js' | ||
|
||
import { datasets } from '../utils/utils.js' | ||
import logger from '../utils/logger.js' | ||
import { types } from '../utils/logging.js' | ||
import * as v from 'valibot' | ||
import { NonEmptyString } from '../routes/schemas.js' | ||
|
||
const QueryParams = v.object({ | ||
dataset: NonEmptyString, | ||
orgName: NonEmptyString | ||
}) | ||
|
||
/** | ||
* Handles deep links in the Check Tool. | ||
* | ||
* It is meant to extract required params from query params | ||
* and partially pre-populate the session with them, | ||
* then redirect the user to the "next" page in the wizard | ||
*/ | ||
class DeepLinkController extends PageController { | ||
get (req, res, next) { | ||
// if the query params don't contain what we need, redirect to the "get started" page, | ||
// this way the user can still proceed (but need to fill the dataset+orgName themselves) | ||
const { dataset, orgName } = req.query | ||
const validationResult = v.safeParse(QueryParams, req.query) | ||
if (!(validationResult.success && datasets.has(dataset))) { | ||
logger.info('DeepLinkController.get(): invalid params for deep link, redirecting to start page', | ||
{ type: types.App, query: req.query }) | ||
return res.redirect('/check') | ||
} | ||
|
||
req.sessionModel.set('dataset', dataset) | ||
const datasetInfo = datasets.get(dataset) ?? { dataSubject: '', requiresGeometryTypeSelection: false } | ||
req.sessionModel.set('data-subject', datasetInfo.dataSubject) | ||
req.sessionModel.set(this.checkToolDeepLinkSessionKey, | ||
{ 'data-subject': datasetInfo.dataSubject, orgName, dataset, datasetName: datasetInfo.text }) | ||
|
||
this.#addHistoryStep(req, '/check/dataset') | ||
|
||
super.post(req, res, next) | ||
} | ||
|
||
#addHistoryStep (req, path, next) { | ||
const newItem = { | ||
path, | ||
wizard: 'check-wizard', | ||
fields: ['dataset', 'data-subject'], | ||
skip: false, | ||
continueOnEdit: false | ||
} | ||
|
||
const history = req.journeyModel.get('history') || [] | ||
history.push(newItem) | ||
req.journeyModel.set('history', history) | ||
} | ||
} | ||
|
||
export default DeepLinkController |
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,11 @@ | ||
/** | ||
* Returns the deep link to the check tool for a given dataset and organisation | ||
* | ||
* @param {{name:string}} organisation | ||
* @param {{dataset:string, name:string}} dataset | ||
* | ||
* @return {string} | ||
*/ | ||
export function checkToolDeepLink (organisation, dataset) { | ||
return `/check/link?dataset=${encodeURIComponent(dataset.dataset)}&orgName=${encodeURIComponent(organisation.name)}` | ||
} |
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
Oops, something went wrong.