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

Add validation mode support #56

Merged
merged 26 commits into from
Nov 7, 2019
Merged

Conversation

henryaddison
Copy link
Contributor

@henryaddison henryaddison commented Oct 29, 2019

Final part of openactive/data-models#41

Adds a drop-down for selecting validation mode.

Screenshot 2019-11-04 at 16 02 03

Samples drop-down now supports groups depending on usage type (e.g. RDPE or Booking) with optionally supplied associated validation mode for an example (selecting a sample with a validation mode associated with set the site's validation mode to it). The examples in each group are displayed via sub-menus to ensure the initial drop-down is now illegibly long.

Screenshot 2019-11-04 at 16 02 00

samples are now grouped according to usage (Opportunity Data or Booking).
Also samples may have a validation mode associated with them so need to add that the link url.
Plus tweak styling slightly to take groups into account in downdown.
as a way for a sample link to specify the validation mode it should run against
@henryaddison
Copy link
Contributor Author

NB while tests pass until the 2.0.0 version of data-models (with the validation mode groups and updated format of examples) is released this will not run successfully.

so guaranteed to have validation modes in metadata and new format of examples in spec
validate endpoint really expects a string containing the JSON data, rather than a neat JSON object
for better consistency - respond with errors early or get to end and give good response
to make naming convention with validateURL
it works out from body whether to get data to validate from passed JSON or remote url

also allowed refactoring of ApiHelper to a share validate method with helpers for validateUrl and validateJSON
data-models, data-model-validator and rpde-validator have all been updated to allow this validation modes stuff to work in the site
for some reason ...data not working so cloning the argument and settings the extra data needed on the object
partly because validationMode is dependent on version (particularly the default one)
and also to fix an issue with validationMode not returning to default if none is provided by a link
otherwise the list of examples gets too long very quickly for even larger screens
@henryaddison henryaddison marked this pull request as ready for review November 4, 2019 16:04
@henryaddison henryaddison requested a review from ylt November 4, 2019 16:04
static validateURL(url, version) {
return fetch(`/api/validateUrl/${version}`, {
static validate(data, version, validationMode) {
let body = JSON.parse(JSON.stringify(data));
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems fishy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something I was going to pick up with Joe during review, for some reason it's not liking the spread operator as I was hoping to just to const body = { ...date, validationMode }; rather than clone the data object and add validationMode to it.

Choose a reason for hiding this comment

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

If the spread isn’t working for whatever reason (weird it doesn’t) I noticed jQuery is in the project, it has it’s own method for that kind of thing https://api.jquery.com/jquery.extend/

TL;DR

const body = $.extend({}, data, { validationMode });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, Ben. Just seen this - we went for Object.assign which looks like it's the same thing.

Choose a reason for hiding this comment

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

Nice! As long as that’s okay with browser support then that’s nice.

Basically no IE and in built Android browsers.

https://caniuse.com/#feat=mdn-javascript_builtins_object_assign

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the warning, Ben. The site is a tool for devs so IE unlikely to be used.

Spread operator is not available for object literals yet (experimental) and JSON stringify & parse to clone is a bit unnecessary
@henryaddison henryaddison merged commit 7a97056 into master Nov 7, 2019
@henryaddison henryaddison deleted the validation-modes-dropdown branch November 7, 2019 10:26
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.

4 participants