-
Notifications
You must be signed in to change notification settings - Fork 123
feat: Use cron input in start workflow form #1040
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
Merged
Assem-Uber
merged 15 commits into
cadence-workflow:master
from
Assem-Uber:feature/15436/use-cron-input-in-start-form
Oct 7, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
34b69c2
Create cron schedule input
Assem-Uber ae5a45f
use cron input in start form
Assem-Uber 4c394ee
add trigger to test cases
Assem-Uber 275e6aa
fix test cases
Assem-Uber 7935c34
Merge branch 'master' into feature/15436/create-cron-schedule-input
Assem-Uber 1718596
refactor popover and other cron input components
Assem-Uber 5b45ea7
Merge branch 'feature/15436/create-cron-schedule-input' into feature/…
Assem-Uber 710caa0
Merge branch 'master' into feature/15436/use-cron-input-in-start-form
Assem-Uber 6079b6c
address comments
Assem-Uber 8e52843
fix ranges to match backend
Assem-Uber 3121a12
fix test cases
Assem-Uber 7678861
fix typecheck
Assem-Uber c505c30
fix unit test
Assem-Uber 8f3b07a
fix unit tests
Assem-Uber c349f99
Merge branch 'master' into feature/15436/use-cron-input-in-start-form
adhityamamallan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...rkflow-actions/workflow-action-start-form/helpers/__tests__/get-cron-fields-error.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { cronValidate } from '@/utils/cron-validate/cron-validate'; | ||
|
|
||
| import { getCronFieldsError } from '../get-cron-fields-error'; | ||
|
|
||
| jest.mock('@/utils/cron-validate/cron-validate'); | ||
|
|
||
| const mockCronValidate = cronValidate as jest.MockedFunction< | ||
| typeof cronValidate | ||
| >; | ||
|
|
||
| type CronValidateResult = ReturnType<typeof cronValidate>; | ||
|
|
||
| describe('getCronFieldsError', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should return null for valid cron expression', () => { | ||
| const { result } = setup({ | ||
| isValid: true, | ||
| }); | ||
|
|
||
| expect(result).toBeNull(); | ||
| }); | ||
|
|
||
| it('should handle field-specific errors correctly', () => { | ||
| const { result } = setup({ | ||
| isValid: false, | ||
| errors: [ | ||
| 'Invalid value for minutes field: x', | ||
| 'Invalid value for hours field: x', | ||
| 'Invalid value for daysOfMonth field: x', | ||
| 'Invalid value for months field: x', | ||
| 'Invalid value for daysOfWeek field: x', | ||
| ], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| minutes: 'Invalid value for minutes field: x', | ||
| hours: 'Invalid value for hours field: x', | ||
| daysOfWeek: 'Invalid value for daysOfWeek field: x', | ||
| daysOfMonth: 'Invalid value for daysOfMonth field: x', | ||
| months: 'Invalid value for months field: x', | ||
| }); | ||
| }); | ||
|
|
||
| it('should return general error when errors array has no field-specific matches', () => { | ||
| const { result } = setup({ | ||
| isValid: false, | ||
| errors: ['Malformed cron expression', 'Cannot parse input'], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| general: 'Malformed cron expression', | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle mixed field-specific and general errors', () => { | ||
| const { result } = setup({ | ||
| isValid: false, | ||
| errors: [ | ||
| 'Invalid value for minutes field: abc', | ||
| 'Syntax error in expression', | ||
| 'Invalid value for hours field: xyz', | ||
| ], | ||
| }); | ||
|
|
||
| // Should prioritize field-specific errors over general ones | ||
| expect(result).toEqual({ | ||
| minutes: 'Invalid value for minutes field: abc', | ||
| hours: 'Invalid value for hours field: xyz', | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| function setup({ | ||
| cronText = '* * * * *', | ||
| isValid = true, | ||
| errors = [], | ||
| }: { | ||
| cronText?: string; | ||
| isValid?: boolean; | ||
| errors?: string[]; | ||
| }) { | ||
| const mockCronResult: Partial<CronValidateResult> = { | ||
| isValid: jest.fn(() => isValid), | ||
| getError: jest.fn(() => errors), | ||
| }; | ||
|
|
||
| mockCronValidate.mockReturnValue(mockCronResult as CronValidateResult); | ||
|
|
||
| const result = getCronFieldsError(cronText); | ||
|
|
||
| return { | ||
| result, | ||
| mockCronResult, | ||
| mockIsValid: mockCronResult.isValid, | ||
| mockGetError: mockCronResult.getError, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/views/workflow-actions/workflow-action-start-form/helpers/get-cron-fields-error.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { CRON_FIELD_ORDER } from '@/components/cron-schedule-input/cron-schedule-input.constants'; | ||
| import { cronValidate } from '@/utils/cron-validate/cron-validate'; | ||
| import { type CronData } from '@/utils/cron-validate/cron-validate.types'; | ||
|
|
||
| import { type CronFieldsError } from '../workflow-action-start-form.types'; | ||
|
|
||
| export const getCronFieldsError = (cronString: string): CronFieldsError => { | ||
| const cronObj = cronValidate(cronString); | ||
|
|
||
| if (!cronObj.isValid()) { | ||
| const errors = cronObj.getError(); | ||
| const errorFieldsKeys = CRON_FIELD_ORDER; | ||
| const fieldsErrors: Partial<Record<keyof CronData, string>> = {}; | ||
| errors.forEach((e) => { | ||
| const errorKey = errorFieldsKeys.find((key) => | ||
| e.includes(`${key} field`) | ||
| ); | ||
| if (errorKey) fieldsErrors[errorKey] = e; | ||
| }); | ||
|
|
||
| if (!Object.keys(fieldsErrors).length) return { general: errors[0] }; | ||
| else return fieldsErrors; | ||
| } | ||
|
|
||
| return null; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.