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): preview usecase #7330

Merged
merged 18 commits into from
Dec 19, 2024
Merged

feat(api): preview usecase #7330

merged 18 commits into from
Dec 19, 2024

Conversation

djabarovgeorge
Copy link
Contributor

@djabarovgeorge djabarovgeorge commented Dec 18, 2024

What changed? Why was the change needed?

https://linear.app/novu/issue/NV-5064/api-preview-parse-tiptap-content-variables-extraction-on-the-new

https://linear.app/novu/issue/NV-5065/api-preview-remove-the-responsibility-of-parsing-variables-in-bridge

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

netlify bot commented Dec 18, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit e6a1720
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/6763e9b5968b2000082e96ff
😎 Deploy Preview https://deploy-preview-7330.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 18, 2024

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

Name Link
🔨 Latest commit e6a1720
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/6763e9b5ffb9290008ac7648
😎 Deploy Preview https://deploy-preview-7330.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.

@djabarovgeorge djabarovgeorge changed the title feat(api): cherry pick liquid parser refactor feat(api): preview usecase Dec 18, 2024
Copy link
Contributor

@SokratisVidros SokratisVidros left a comment

Choose a reason for hiding this comment

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

I just did a first very quick pass

const { fallback } = node.attrs;
const variableName = node.attrs.id;
const buildLiquidJSDefault = (mailyFallback: string) => (mailyFallback ? ` | default: '${mailyFallback}'` : '');
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider moving all the variable calculations from start to end into the buildLiquidJSVariable function defined once either on the class or as a single util. That is combine line 122 and 133.

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 also add an extra step of sanitization in the above function that caters for weird cases where the variableName ends with |.

Copy link
Contributor

Choose a reason for hiding this comment

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

Lastly, this transformation should happena cross all steps, not just email.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider moving all the variable calculations from start to end into the buildLiquidJSVariable function defined once either on the class or as a single util. That is combine line 122 and 133.

If you refer to the show resolver, i totally agree, this was postponed until we have full show support.

Let's also add an extra step of sanitization in the above function that caters for weird cases where the variableName ends with |.

I love the idea but i believe we can postpone such sanitization because liquid js does not care about filter suffixes.
image

Lastly, this transformation should happena cross all steps, not just email.

can you elaborate please what do you mean by this transformation

const client = new Liquid();
const templateString = client.parse(JSON.stringify(value));
const parsedTipTap = await client.render(templateString, {
payload: renderCommand.fullPayloadForRender.payload,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get rid of the fullPayloadForRender extra nesting? It will make the code way more beautiful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe we can, but this refactor is focused on doing the minimum needed to make the code work with what we currently have. We'll try to avoid major changes as much as possible.

The goal is to ensure the use cases—like sending a simple email, "show" component, then "for" components—work as expected with minimal refactoring. If that's not possible, we'll consider a bigger refactor.

Once we have a working solution, we can refactor further if needed. One potential improvement could be flattening the data as you suggested.

# Conflicts:
#	apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts
};
}

function sanitizePush(controlValues: Record<string, unknown>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would suggest using here typed control schemas from the framework

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done :)

Comment on lines 82 to 86
if (typeof normalized === 'object' && normalized !== null) {
return Object.fromEntries(
Object.entries(normalized).filter(([_, value]) => value !== null),
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would suggest maybe to introduce function or add comment (a little hard to understand what it's doing)

@djabarovgeorge djabarovgeorge marked this pull request as ready for review December 19, 2024 09:36
@djabarovgeorge djabarovgeorge merged commit 487ec6a into next Dec 19, 2024
34 checks passed
@djabarovgeorge djabarovgeorge deleted the preview-usecase branch December 19, 2024 09:57
Copy link

pkg-pr-new bot commented Dec 21, 2024

Open in Stackblitz

@novu/client

npm i https://pkg.pr.new/novuhq/novu/@novu/client@7330

@novu/js

npm i https://pkg.pr.new/novuhq/novu/@novu/js@7330

@novu/framework

npm i https://pkg.pr.new/novuhq/novu/@novu/framework@7330

@novu/nest

npm i https://pkg.pr.new/novuhq/novu/@novu/nest@7330

@novu/headless

npm i https://pkg.pr.new/novuhq/novu/@novu/headless@7330

@novu/nextjs

npm i https://pkg.pr.new/novuhq/novu/@novu/nextjs@7330

@novu/node

npm i https://pkg.pr.new/novuhq/novu/@novu/node@7330

@novu/notification-center

npm i https://pkg.pr.new/novuhq/novu/@novu/notification-center@7330

novu

npm i https://pkg.pr.new/novuhq/novu@7330

@novu/providers

npm i https://pkg.pr.new/novuhq/novu/@novu/providers@7330

@novu/react

npm i https://pkg.pr.new/novuhq/novu/@novu/react@7330

@novu/react-native

npm i https://pkg.pr.new/novuhq/novu/@novu/react-native@7330

@novu/shared

npm i https://pkg.pr.new/novuhq/novu/@novu/shared@7330

@novu/stateless

npm i https://pkg.pr.new/novuhq/novu/@novu/stateless@7330

commit: 0bfbbb8

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.

3 participants