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-service): polish action steps #7389

Merged
merged 6 commits into from
Dec 26, 2024
Merged

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 26, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 0ba3b78
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/676d7eb0e848ee0008cdf5e6
😎 Deploy Preview https://deploy-preview-7389.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 26, 2024

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

Name Link
🔨 Latest commit 0ba3b78
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/676d7eb04deb440009dc954f
😎 Deploy Preview https://deploy-preview-7389.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 +70 to +91
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,
};
};
Copy link
Contributor Author

@djabarovgeorge djabarovgeorge Dec 26, 2024

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) {
Copy link
Contributor Author

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
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: execute the todo

Comment on lines +8 to +10
@Transform(({ value }) => (value ? Number(value) : value))
@IsNumber()
amount?: number;
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 should be a number as we use it as number in the usecase

type,
_id: crypto.randomUUID(),
});
export const createStep = (type: StepTypeEnum): StepCreateDto => {
Copy link
Contributor Author

@djabarovgeorge djabarovgeorge Dec 26, 2024

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

@djabarovgeorge djabarovgeorge merged commit 8414e78 into next Dec 26, 2024
36 of 37 checks passed
@djabarovgeorge djabarovgeorge deleted the polish-delay-step branch December 26, 2024 16:52
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