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(api): poc preview usecase #7303

Draft
wants to merge 2 commits into
base: next
Choose a base branch
from
Draft

feat(api): poc preview usecase #7303

wants to merge 2 commits into from

Conversation

djabarovgeorge
Copy link
Contributor

What changed? Why was the change needed?

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

netlify bot commented Dec 13, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 5e6754e
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/675c5976cf281b00099a3b96
😎 Deploy Preview https://deploy-preview-7303.dashboard.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 13, 2024

Deploy Preview for dashboard-v2-novu-staging ready!

Name Link
🔨 Latest commit 5e6754e
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/675c597606b8bd0008914732
😎 Deploy Preview https://deploy-preview-7303.dashboard-v2.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +382 to +404
/*
* TODO: Consider if this validation is necessary since we already normalize in normalizeControlValues and,
* we can make it more robust by adding custom parsable by liquid js values
*
* Current purposes:
* 1. Validates control schema for code-first approach
* 2. Allows adding custom validation rules
* Example: If emailEditor is renamed to 'body', we can validate it's valid TipTap JSON
*/
if (controlSchema) {
const ajv = new Ajv({ allErrors: true });
addFormats(ajv);

const validate = ajv.compile(controlSchema);
const isValid = validate(schemaCompliantControls);
const errors = validate.errors as null | ErrorObject[];

if (!isValid && errors && errors?.length !== 0 && schemaCompliantControls) {
fixedValues = replaceInvalidControlValues(schemaCompliantControls, errors);

return { issues, schemaCompliantControls: fixedValues };
}
}
Copy link
Contributor Author

@djabarovgeorge djabarovgeorge Dec 13, 2024

Choose a reason for hiding this comment

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

this part, with the help of strict JSON schema/Zod, will work well for generating issues on context of type validation ("<param> required", <param> must be URL, etc...). However, in this context, I believe we can focus on improving normalizeControlValues to handle the heavy lifting. At this stage, the control values would then be clean and valid (aligned with the control schema and framework output schema), ensuring the preview runs smoothly.

invalid: [...invalidVariables, ...invalidSchemaVariables],
};

return resultVariables;
Copy link
Contributor Author

@djabarovgeorge djabarovgeorge Dec 13, 2024

Choose a reason for hiding this comment

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

resultVariables.invalid will work well for generating issues based on the liquid errors (for example {{subscriber..firstName}} is invalid, etc...).

Comment on lines +140 to +141
// eslint-disable-next-line no-console
console.log('No template variables found');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo remove.

invalidVariableExpression
);

controlValuesString = replaceAll(controlValuesString, invalidVariable.template, liquidJsParsableString);
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 part will filter out all non-parsable content (which would otherwise throw errors in Liquid JS) and replace it with the placeholder error message PREVIEW_ERROR_MESSAGE_PLACEHOLDER. Invalid output without {{ }} will also be handled (example [[Invalid Variable: subscriber.. email | upcase]]), ensuring the preview (in frameworks that use Liquid for parsing) doesn’t fail at runtime.

At this point, we have a single location where invalid "text" is identified. Now, we need to decide what to replace it with to provide the best possible UX. we could use an empty string here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant