Skip to content

Commit

Permalink
feat: conditional logic extend item type M2-7011(#883)
Browse files Browse the repository at this point in the history
* feature / conditional logic extend item teype

* lint fix

* fixing tests and creating new test

* eslint fix to test

* fixing type GREATER THAN TIME

* lint fix

* turning minutes const to fix lint

* fixing lint, turning minute into cons

* fixing lint desestructuring hour and minute

* lint fix

* fixing multiple row option

* reverting Podfile.lock

* feature/including time range logic, improving IanswerValidator and answerValidator, adding fieldValue to time range and improving payloads

* set delete updatedCondition.itemName back

* Update src/entities/conditional-logic/model/conditions.ts

Co-authored-by: André Vital <[email protected]>

* fix: fixing comments on PR, adding new casses to mapConditionalLogic, fixing order of condition, improving isValidTimeFormat validation, and creating a parse Time string

* removing input validation from answerValidator and passing to conditions, and fixing unit tests

* improving validators  on conditions.ts

---------

Co-authored-by: Felipe Imperio <[email protected]>
Co-authored-by: André Vital <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 8438d4d commit b083b94
Show file tree
Hide file tree
Showing 11 changed files with 1,646 additions and 35 deletions.
6 changes: 6 additions & 0 deletions src/entities/activity/lib/services/timeToMinutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const timeToMinutes = (time: {
hours: number;
minutes: number;
}): number => {
return time.hours * 60 + time.minutes;
};
328 changes: 326 additions & 2 deletions src/entities/activity/lib/types/conditionalLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type ConditionalLogic = {
conditions: Array<Condition>;
};

type Condition =
export type Condition =
| IncludesOptionCondition
| NotIncludesOptionCondition
| EqualToOptionCondition
Expand All @@ -15,10 +15,130 @@ type Condition =
| EqualCondition
| NotEqualCondition
| BetweenCondition
| OutsideOfCondition;
| OutsideOfCondition
| GreaterThanDateCondition
| LessThanDateCondition
| EqualToDateCondition
| NotEqualToDateCondition
| BetweenDatesCondition
| OutsideOfDatesCondition
| GreaterThanTimeCondition
| LessThanTimeCondition
| EqualToTimeCondition
| NotEqualToTimeCondition
| BetweenTimesCondition
| OutsideOfTimesCondition
| GreaterThanTimeRangeCondition
| LessThanTimeRangeCondition
| EqualToTimeRangeCondition
| NotEqualToTimeRangeCondition
| BetweenTimesRangeCondition
| OutsideOfTimesRangeCondition
| EqualToRowOptionCondition
| NotEqualToRowOptionCondition
| IncludesRowOptionCondition
| NotIncludesRowOptionCondition
| EqualToSliderRowCondition
| NotEqualToSliderRowCondition
| GreaterThanSliderRowCondition
| LessThanSliderRowCondition
| BetweenSliderRowCondition
| OutsideOfSliderRowCondition;

export type ConditionType = Condition['type'];

type EqualToRowOptionCondition = {
activityItemName: string;
type: 'EQUAL_TO_ROW_OPTION';
payload: {
optionValue: string;
rowIndex: number;
};
};

type NotEqualToRowOptionCondition = {
activityItemName: string;
type: 'NOT_EQUAL_TO_ROW_OPTION';
payload: {
optionValue: string;
rowIndex: number;
};
};

type IncludesRowOptionCondition = {
activityItemName: string;
type: 'INCLUDES_ROW_OPTION';
payload: {
optionValue: string;
rowIndex: number;
};
};

type NotIncludesRowOptionCondition = {
activityItemName: string;
type: 'NOT_INCLUDES_ROW_OPTION';
payload: {
optionValue: string;
rowIndex: number;
};
};

type EqualToSliderRowCondition = {
activityItemName: string;
type: 'EQUAL_TO_SLIDER_ROWS';
payload: {
value: number;
rowIndex: number;
};
};

type NotEqualToSliderRowCondition = {
activityItemName: string;
type: 'NOT_EQUAL_TO_SLIDER_ROWS';
payload: {
value: number;
rowIndex: number;
};
};

type GreaterThanSliderRowCondition = {
activityItemName: string;
type: 'GREATER_THAN_SLIDER_ROWS';
payload: {
value: number;
rowIndex: number;
};
};

type LessThanSliderRowCondition = {
activityItemName: string;
type: 'LESS_THAN_SLIDER_ROWS';
payload: {
value: number;
rowIndex: number;
};
};

type BetweenSliderRowCondition = {
activityItemName: string;
type: 'BETWEEN_SLIDER_ROWS';
payload: {
minValue: number;
maxValue: number;
rowIndex: number;
};
};

type OutsideOfSliderRowCondition = {
activityItemName: string;
type: 'OUTSIDE_OF_SLIDER_ROWS';
payload: {
minValue: number;
maxValue: number;
rowIndex: number;
};
};

type IncludesOptionCondition = {
activityItemName: string;
type: 'INCLUDES_OPTION';
Expand Down Expand Up @@ -100,3 +220,207 @@ type OutsideOfCondition = {
maxValue: number;
};
};

type GreaterThanDateCondition = {
activityItemName: string;
type: 'GREATER_THAN_DATE';
payload: {
date: string;
};
};

type LessThanDateCondition = {
activityItemName: string;
type: 'LESS_THAN_DATE';
payload: {
date: string;
};
};

type EqualToDateCondition = {
activityItemName: string;
type: 'EQUAL_TO_DATE';
payload: {
date: string;
};
};

type NotEqualToDateCondition = {
activityItemName: string;
type: 'NOT_EQUAL_TO_DATE';
payload: {
date: string;
};
};

type BetweenDatesCondition = {
activityItemName: string;
type: 'BETWEEN_DATES';
payload: {
minDate: string;
maxDate: string;
};
};

type OutsideOfDatesCondition = {
activityItemName: string;
type: 'OUTSIDE_OF_DATES';
payload: {
minDate: string;
maxDate: string;
};
};

type GreaterThanTimeCondition = {
activityItemName: string;
type: 'GREATER_THAN_TIME';
payload: {
time: {
hours: number;
minutes: number;
};
};
};

type LessThanTimeCondition = {
activityItemName: string;
type: 'LESS_THAN_TIME';
payload: {
time: {
hours: number;
minutes: number;
};
};
};

type EqualToTimeCondition = {
activityItemName: string;
type: 'EQUAL_TO_TIME';
payload: {
time: {
hours: number;
minutes: number;
};
};
};

type NotEqualToTimeCondition = {
activityItemName: string;
type: 'NOT_EQUAL_TO_TIME';
payload: {
time: {
hours: number;
minutes: number;
};
};
};

type BetweenTimesCondition = {
activityItemName: string;
type: 'BETWEEN_TIMES';
payload: {
minTime: {
hours: number;
minutes: number;
};
maxTime: {
hours: number;
minutes: number;
};
};
};

type OutsideOfTimesCondition = {
activityItemName: string;
type: 'OUTSIDE_OF_TIMES';
payload: {
minTime: {
hours: number;
minutes: number;
};
maxTime: {
hours: number;
minutes: number;
};
};
};

type GreaterThanTimeRangeCondition = {
activityItemName: string;
type: 'GREATER_THAN_TIME_RANGE';
payload: {
time: {
hours: number;
minutes: number;
};
fieldName: string;
};
};

type LessThanTimeRangeCondition = {
activityItemName: string;
type: 'LESS_THAN_TIME_RANGE';
payload: {
time: {
hours: number;
minutes: number;
};
fieldName: string;
};
};

type EqualToTimeRangeCondition = {
activityItemName: string;
type: 'EQUAL_TO_TIME_RANGE';
payload: {
time: {
hours: number;
minutes: number;
};
fieldName: string;
};
};

type NotEqualToTimeRangeCondition = {
activityItemName: string;
type: 'NOT_EQUAL_TO_TIME_RANGE';
payload: {
time: {
hours: number;
minutes: number;
};
fieldName: string;
};
};

type BetweenTimesRangeCondition = {
activityItemName: string;
type: 'BETWEEN_TIMES_RANGE';
payload: {
minTime: {
hours: number;
minutes: number;
};
maxTime: {
hours: number;
minutes: number;
};
fieldName: string;
};
};

type OutsideOfTimesRangeCondition = {
activityItemName: string;
type: 'OUTSIDE_OF_TIMES_RANGE';
payload: {
minTime: {
hours: number;
minutes: number;
};
maxTime: {
hours: number;
minutes: number;
};
fieldName: string;
};
};
Loading

0 comments on commit b083b94

Please sign in to comment.