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): add query parser #7267

Open
wants to merge 12 commits into
base: next
Choose a base branch
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

linear bot commented Dec 10, 2024

Copy link

netlify bot commented Dec 10, 2024

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

Name Link
🔨 Latest commit 9f9534c
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/67596ce96771b300089bde8d
😎 Deploy Preview https://deploy-preview-7267.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.

Copy link

netlify bot commented Dec 10, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 9f9534c
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/67596ce950a1cd0008a999c1
😎 Deploy Preview https://deploy-preview-7267.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.

@@ -84,6 +85,7 @@ export enum UiComponentEnum {
CHAT_BODY = 'CHAT_BODY',
PUSH_BODY = 'PUSH_BODY',
PUSH_SUBJECT = 'PUSH_SUBJECT',
SKIP_RULES = 'SKIP_RULES',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

was not sure how to call. should we switch to SKIP?

Suggested change
SKIP_RULES = 'SKIP_RULES',
SKIP = 'SKIP',

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
SKIP_RULES = 'SKIP_RULES',
SKIP_RULES = 'QUERY_EDITOR',

@@ -0,0 +1,47 @@
import jsonLogic, { AdditionalOperation, RulesLogic } from 'json-logic-js';

const initializeCustomOperators = (): void => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

self note:
validate that we cover all the react-querybuilder operators.

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

Copy link
Contributor

@SokratisVidros SokratisVidros Dec 12, 2024

Choose a reason for hiding this comment

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

Nice! @djabarovgeorge Isn't there an npm package that does this already so that it saves us from adding custom operators?

Do they maybe have it for another JSON representation of conditionals that is more complete out of the box?

What about this?

If not, it's a great opportunity to make an OS contribution to react-querybuilder.

@@ -199,7 +209,25 @@ export class ConstructFrameworkWorkflow {

return foundWorkflow;
}

private processSkipOption(controlValues: { [x: string]: unknown }, variables: FullPayloadForRender) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can convert this to renderer.

as a side note, at the moment i am not sure we need to have Injectable use-cases for the renderer feels like overkill.

@djabarovgeorge djabarovgeorge marked this pull request as ready for review December 11, 2024 09:59
Comment on lines +191 to +193
private constructCommonStepOptions(
staticStep: NotificationStepEntity,
fullPayloadForRender: FullPayloadForRender
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need FullPayloadForRender variables(===frameweork.payload) data in the skip method to execute the skip function.


return (await novuClient.trigger(request)).result;
}

describe('Trigger Event New Dashboard - /v1/events/trigger (POST)', function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we rename it to v2 workflow?

Suggested change
describe('Trigger Event New Dashboard - /v1/events/trigger (POST)', function () {
describe('Trigger Event v2 workflow - /v1/events/trigger (POST)', function () {

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

Copy link

pkg-pr-new bot commented Dec 11, 2024

Open in Stackblitz

@novu/client

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

@novu/framework

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

@novu/headless

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

@novu/js

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

@novu/nest

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

@novu/nextjs

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

@novu/node

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

@novu/notification-center

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

novu

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

@novu/providers

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

@novu/react

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

@novu/react-native

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

@novu/shared

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

@novu/stateless

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

commit: 9f9534c

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the main reason for this spec is that we are adding new operators to the json logic js, which are not tests in json logic js. Therefore, we need to make sure we are testing it here.

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.

👏 👏 👏

);
case StepTypeEnum.DELAY:
return step.delay(
stepId,
async (controlValues) => {
return this.delayOutputRendererUseCase.execute({ controlValues, fullPayloadForRender });
},
this.constructActionStepOptions(staticStep)
this.constructActionStepOptions(staticStep, fullPayloadForRender)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-picky: This function is the same across all steps, we can remove it out side the switch.

* Used to construct conditions defined with https://react-querybuilder.js.org/ or similar
*/
skip: (controlValues) => false,
skip: (controlValues: { [x: string]: unknown }) => this.processSkipOption(controlValues, fullPayloadForRender),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
skip: (controlValues: { [x: string]: unknown }) => this.processSkipOption(controlValues, fullPayloadForRender),
skip: (controlValues: Record<string, unknown>) => this.processSkipOption(controlValues, fullPayloadForRender),

const skipRules = controlValues.skip as RulesLogic<AdditionalOperation>;

// TODO: check if we need to add more validation here (is empty object, etc.)
if (!skipRules) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use lodash/isEmpty and cover all of the empty cases of an object ;)

Suggested change
if (!skipRules) {
if (isEmpty(skipRules)) {

const { result, error } = evaluateRules(skipRules, variables);

if (error) {
this.logger.error({ err: error }, 'Failed to evaluate skip rule', LOG_CONTEXT);
Copy link
Contributor

@SokratisVidros SokratisVidros Dec 12, 2024

Choose a reason for hiding this comment

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

Shall we pause workflow execution when there is a skip condition error? I think we should and we need to show it in activity feed.


return (await novuClient.trigger(request)).result;
}

describe('Trigger Event New Dashboard - /v1/events/trigger (POST)', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

yes

@@ -0,0 +1,47 @@
import jsonLogic, { AdditionalOperation, RulesLogic } from 'json-logic-js';

const initializeCustomOperators = (): void => {
Copy link
Contributor

@SokratisVidros SokratisVidros Dec 12, 2024

Choose a reason for hiding this comment

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

Nice! @djabarovgeorge Isn't there an npm package that does this already so that it saves us from adding custom operators?

Do they maybe have it for another JSON representation of conditionals that is more complete out of the box?

What about this?

If not, it's a great opportunity to make an OS contribution to react-querybuilder.

@@ -84,6 +85,7 @@ export enum UiComponentEnum {
CHAT_BODY = 'CHAT_BODY',
PUSH_BODY = 'PUSH_BODY',
PUSH_SUBJECT = 'PUSH_SUBJECT',
SKIP_RULES = 'SKIP_RULES',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
SKIP_RULES = 'SKIP_RULES',
SKIP_RULES = 'QUERY_EDITOR',

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.

2 participants