Skip to content
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

feat: add ODP Schema validation example for FileTypes to publish checks #3373

Merged
merged 7 commits into from
Jul 8, 2024

Conversation

jessicamcinchak
Copy link
Member

@jessicamcinchak jessicamcinchak commented Jul 4, 2024

Relies on theopensystemslab/planx-core#436

Changes:

  • Adds a new validation check for "File types" which compares the data fields set by FileUpload and/or FileUploadAndLabel nodes to the ODP Schema's FileType enum values
    • Skips validation check if the FileUploadAndLabel component is used in info-only mode with a hidden dropzone
  • Adds a new status "Warn" which will not disable the "Publish" button (eg discretionary services may legitmately want to collect bespoke, "unsupported" file types!)
  • Adds/updates API tests

What this doesn't do yet / future design scope:

  • Link to exact node(s) with unsupported variables
  • Link to ODP Schema definitions (could even be Issue template?)

Screenshot from 2024-07-05 10-03-07

@jessicamcinchak
Copy link
Member Author

Copy link

github-actions bot commented Jul 4, 2024

Removed vultr server and associated DNS entries

const sortedValidationChecks = failingChecks
.concat(warningChecks)
.concat(passingChecks)
.concat(notApplicableChecks);
Copy link
Member Author

@jessicamcinchak jessicamcinchak Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone have a more clever suggestion for how to sort in a custom order by "status" ? This is explicit and easy-to-read, but a bit lengthy and I feel like there's probably some cool one-liner I'm missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can think of a few ways!

Map.groupBy is pretty new but seems to have decent coverage https://caniuse.com/?search=map.groupby

I think it would then just be Map.groupBy(passingChecks, (check) => check.status)).

If we hit browser compatibility issues here we could import groupBy from lodash, or use a reduce().

Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah just realised we're in the API here on Node 18 - I don't think Map.groupBy() would be available.

Lodash or reduce() would be the way to go here 👍

@jessicamcinchak jessicamcinchak marked this pull request as ready for review July 8, 2024 06:54
@jessicamcinchak jessicamcinchak requested a review from a team July 8, 2024 06:54
@jessicamcinchak jessicamcinchak changed the title feat: add ODP Schema validation example to publish checks feat: add ODP Schema validation example for FileTypes to publish checks Jul 8, 2024
Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looking very good, a few small comments / suggestions here and there 👍

Link to exact node(s) with unsupported variables

Nice idea! Yep let's pick this up once we have this function ready for search.

Link to ODP Schema definitions (could even be Issue template?)

Another great idea 💡

const sortedValidationChecks = failingChecks
.concat(warningChecks)
.concat(passingChecks)
.concat(notApplicableChecks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can think of a few ways!

Map.groupBy is pretty new but seems to have decent coverage https://caniuse.com/?search=map.groupby

I think it would then just be Map.groupBy(passingChecks, (check) => check.status)).

If we hit browser compatibility issues here we could import groupBy from lodash, or use a reduce().

Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy

const sortedValidationChecks = failingChecks
.concat(warningChecks)
.concat(passingChecks)
.concat(notApplicableChecks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah just realised we're in the API here on Node 18 - I don't think Map.groupBy() would be available.

Lodash or reduce() would be the way to go here 👍


const getFileUploadNodeFns = (flowGraph: FlowGraph): string[] => {
const fileUploadNodes = Object.entries(flowGraph).filter(
(entry): entry is [string, Node] =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, as of TS 5.5 I think we can lose the entry is [string, Node] here and it should be inferred from isComponentType().

Docs: https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#inferred-type-predicates

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're correct this is just properly inferred from isComponentType() - removed unnecessary verbose-ness!

api.planx.uk/modules/flows/validate/validate.test.ts Outdated Show resolved Hide resolved
@@ -23,7 +25,7 @@ type AlteredNode = {

type ValidationResponse = {
title: string;
status: "Pass" | "Fail" | "Not applicable";
status: "Pass" | "Fail" | "Warn" | "Not applicable";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting to see this change also picked up in docs.yaml, but it looks like we've missed adding in the validationChecks property.

Happy for this to be picked up here, or in a follow up PR 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this, Swagger docs now updated ✅

Screenshot from 2024-07-08 12-22-07

@jessicamcinchak jessicamcinchak merged commit 8adce6a into main Jul 8, 2024
12 checks passed
@jessicamcinchak jessicamcinchak deleted the jess/validate-files-against-schema branch July 8, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants