-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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-service): polish action steps #7389
Conversation
✅ Deploy Preview for dev-web-novu ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for dashboard-v2-novu-staging ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
export const createStep = (type: StepTypeEnum): StepCreateDto => { | ||
const controlValue: Record<string, unknown> = {}; | ||
|
||
if (type === StepTypeEnum.DIGEST) { | ||
controlValue.amount = DEFAULT_CONTROL_DIGEST_AMOUNT; | ||
controlValue.unit = DEFAULT_CONTROL_DIGEST_UNIT; | ||
controlValue.digestKey = DEFAULT_CONTROL_DIGEST_DIGEST_KEY; | ||
controlValue.cron = DEFAULT_CONTROL_DIGEST_CRON; | ||
} | ||
|
||
if (type === StepTypeEnum.DELAY) { | ||
controlValue.amount = DEFAULT_CONTROL_DELAY_AMOUNT; | ||
controlValue.unit = DEFAULT_CONTROL_DELAY_UNIT; | ||
controlValue.type = DEFAULT_CONTROL_DELAY_TYPE; | ||
} | ||
|
||
return { | ||
name: STEP_TYPE_LABELS[type] + ' Step', | ||
type, | ||
controlValues: controlValue, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The summary of the findings of the best approach, why the change is necessary, and what is happening in the current implementation.
The main reason for this change is that we cannot create a step with control values during step creation. This limitation causes unexpected behavior, like the bug we are experiencing.
Currently, we cannot move schemas with default values to the Shared
package and reuse them in the Dashboard
because these schemas depend on Zod
and Zod-to-JSON-Schema
.
The solution we originally wanted—to move default values from the UiSchema
to the dataSchema
—is not supported natively. The solution should be Zod
schema with default values (used by the Dashboard
) and make certain attributes, like body
, required for generating issues
. However, this approach fails because zod-to-json-schema
removes the required attributes if there is a default value meaning we will need to manipulate the schema manually.
This solution is reducing the amount of code. In addition once we store the default values during step creation, we wouldn't need to handle parsing them (placeholders/defaults) in the Dashboard
or maintain "placeholders" or default values in the API.
Next Steps
- Remove placeholders from the API.
- Eliminate placeholder parsing in the
Dashboard
.
skip: controlValues.skip || undefined, | ||
}; | ||
|
||
return filterNullishValues(mappedValues); | ||
} | ||
|
||
function parseAmount(amount?: unknown) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
safe parse just in case
amount: controlValues.amount || 0, | ||
unit: controlValues.unit || TimeUnitEnum.SECONDS, | ||
// Cast to trigger Ajv validation errors - possible undefined | ||
...(parseAmount(controlValues) as { amount?: number }), // TODO FIX THIS - should be controlValues.amount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self note: execute the todo
@Transform(({ value }) => (value ? Number(value) : value)) | ||
@IsNumber() | ||
amount?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a number as we use it as number in the usecase
type, | ||
_id: crypto.randomUUID(), | ||
}); | ||
export const createStep = (type: StepTypeEnum): StepCreateDto => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we used the wrong type here, this is why we passed redundant data to the API such as slug prefix
What changed? Why was the change needed?
Screenshots
Expand for optional sections
Related enterprise PR
Special notes for your reviewer