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

#3831 Add validation support for sub pipelines #3832

Merged
merged 9 commits into from Jul 6, 2022

Conversation

BALEHOK
Copy link
Contributor

@BALEHOK BALEHOK commented Jul 1, 2022

What does this PR do?

Demo

Nunjucks validation:
Screen Shot 2022-07-04 at 4 39 32 PM

Renderers validation:
Screen Shot 2022-07-04 at 4 37 21 PM

Inputs validation:
Screen Shot 2022-07-04 at 4 38 51 PM

Trace errors:
Screen Shot 2022-07-04 at 4 36 46 PM

Future Work

  • Store error tree in Redux, gradually reducing the scope of Formik

Checklist

  • Add tests
  • Designate a primary reviewer @BLoe

@BALEHOK BALEHOK force-pushed the feature/3831-subpipelines-validation branch from 6148991 to 9d3f648 Compare July 4, 2022 10:13
@BALEHOK BALEHOK requested review from BLoe and twschiller July 4, 2022 14:41
@BALEHOK BALEHOK marked this pull request as ready for review July 4, 2022 14:42
* Join parts of a path, ignoring null/blank parts.
* @param nameParts the parts of the name
*/
export function joinPathParts(...nameParts: Array<string | number>): string {
Copy link
Contributor

@twschiller twschiller Jul 4, 2022

Choose a reason for hiding this comment

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

Could we add some documentation on why/when the developer should use this method vs. joinName above?

@@ -49,6 +49,7 @@ const specialCharsRegex = /[.[\]]/;

/**
* Create a Formik field name, validating the individual path parts.
* Wraps parts with special characters in brackets, so Formik treat it as a single property name.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@twschiller
Copy link
Contributor

twschiller commented Jul 5, 2022

@BALEHOK thanks for the PR! I checked it out and it's working for me. I'll provide some minor wording tweaks on the error messages. @BLoe please review for architecture/details

One thing that could be confusing is the behavior for nested bricks.

In the parent brick, if there's no errors in the brick itself, I think we need a message that says: "Error in one or more nested bricks. Click on the brick in the Extension Overview to view the error" to clarify that the parent brick itself doesn't have any errors

image

import { joinName } from "@/utils";
import { joinName, joinPathParts } from "@/utils";
import { traversePipeline } from "@/pageEditor/utils";
import { setPipelineBlockError } from "./setPipelineBlockError";

const MUSTACHE_ERROR_MESSAGE =
"Invalid string template. Read more about string templates: https://docs.pixiebrix.com/nunjucks-templates";
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's change the name of this constant to TEMPLATE_ERROR_MESSAGE

Let's change to "Invalid text template. Read more about text templates: https://docs.pixiebrix.com/nunjucks-templates"

Copy link
Collaborator

@BLoe BLoe left a comment

Choose a reason for hiding this comment

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

Just had a few questions, but overall looks good!

@@ -50,23 +50,15 @@ const forEachBlock = new ForEach();
const immediateUserEvent = userEvent.setup({ delay: null });

beforeAll(async () => {
jest.useFakeTimers();

jest.setTimeout(30_000); // This test is flaky with the default timeout of 5000 ms
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this work for you? I think I tried this before and it didn't work. Doesn't it have to be top-level in the file? Also it just applies to the current file so I don't think you have to "clean it up" and set it back to the previous value? I may be wrong here but this is exactly what I tried to do at first and it wasn't working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works for me, yes. Maybe it was failing for you because of jest cache. You can clear it with jest flag:
--clearCache. With npm it is: npm run test -- --clearCache

Copy link
Collaborator

Choose a reason for hiding this comment

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

As long as this works locally and on CI, then I'm fine with it. Just surprising since it wasn't working when I tried it like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind, I've reverted this change

<span
style="color: rgb(241, 89, 80);"
>
undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it supposed to print undefined in the UI like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, in the test. this is the @input of the extension reported to the Data Panel. normally it is the HTML document meta data, but in the test there's no document and we get undefined

@BALEHOK BALEHOK enabled auto-merge (squash) July 6, 2022 19:32
@BALEHOK BALEHOK merged commit 4ef5b9a into main Jul 6, 2022
@BALEHOK BALEHOK deleted the feature/3831-subpipelines-validation branch July 6, 2022 19:34
@twschiller twschiller modified the milestones: 1.7.1, 1.7.2 Jul 8, 2022
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.

Add validation support for sub pipelines
3 participants