-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrated components with 'useExpressions'
- Loading branch information
ivan
committed
May 3, 2023
1 parent
1363235
commit c101fb3
Showing
14 changed files
with
200 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
81 changes: 81 additions & 0 deletions
81
shesha-reactjs/src/designer-components/_common-migrations/migrateUseExpression.ts
This file contains 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,81 @@ | ||
import { ITableViewProps } from "providers/tableViewSelectorConfigurator/models"; | ||
|
||
interface IArgumentEvaluationResult { | ||
handled: boolean; | ||
value?: any; | ||
} | ||
type JsonLogicContainerProcessingCallback = (operator: string, args: object[], argIndex: number) => IArgumentEvaluationResult; | ||
|
||
const convertJsonLogicNode = (jsonLogic: object, argumentEvaluator: JsonLogicContainerProcessingCallback): object => { | ||
if (!jsonLogic) | ||
return null; | ||
|
||
const result = {}; | ||
for (const operator in jsonLogic) { | ||
if (!jsonLogic.hasOwnProperty(operator)) | ||
continue; | ||
|
||
const args = jsonLogic[operator]; | ||
|
||
let convertedArgs = null; | ||
|
||
if (Array.isArray(args)) { | ||
convertedArgs = args.map((arg, argIdx) => { | ||
if (typeof (arg) === 'object') | ||
return convertJsonLogicNode(arg, argumentEvaluator); | ||
|
||
const evaluationResult = argumentEvaluator(operator, args, argIdx); | ||
return evaluationResult.handled | ||
? evaluationResult.value | ||
: arg; | ||
}); | ||
} else { | ||
// note: single arguments may be presented as objects, example: {"!!": {"var": "user.userName"}} | ||
if (typeof (args) === 'object') { | ||
convertedArgs = convertJsonLogicNode(args, argumentEvaluator); | ||
} else { | ||
const evaluationResult = argumentEvaluator(operator, [args], 0); | ||
convertedArgs = evaluationResult.handled | ||
? evaluationResult.value | ||
: args; | ||
} | ||
} | ||
result[operator] = convertedArgs; | ||
} | ||
return result; | ||
}; | ||
|
||
export const migrateDynamicExpression = (expression: any): object => { | ||
try { | ||
const parsedExpression = typeof(expression) === 'string' ? JSON.parse(expression) : expression; | ||
|
||
const convertedExpression = convertJsonLogicNode(parsedExpression, (_operator: string, args: object[], argIndex: number) => { | ||
const argValue = args[argIndex]; | ||
if (argValue && typeof(argValue) === 'string' && (argValue as string).includes('{{')){ | ||
return { | ||
handled: true, | ||
value: { evaluate: [ { expression: argValue, type: 'text' } ] }, | ||
}; | ||
} | ||
return { | ||
handled: false | ||
}; | ||
}); | ||
return convertedExpression; | ||
} catch(error) { | ||
console.error('Failed to parse expression', error); | ||
return expression; | ||
}; | ||
}; | ||
|
||
export const migrateFilterMustacheExpressions = (filter: ITableViewProps): ITableViewProps => { | ||
const useExpression = Boolean(filter['useExpression']); | ||
if (!useExpression) | ||
return filter; | ||
|
||
delete filter['useExpression']; | ||
const { expression } = filter; | ||
|
||
const convertedExpression = migrateDynamicExpression(expression); | ||
return { ...filter, expression: convertedExpression }; | ||
}; |
This file contains 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 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 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
12 changes: 12 additions & 0 deletions
12
shesha-reactjs/src/designer-components/dataTable/childTable/migrations/migrate-v3.ts
This file contains 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,12 @@ | ||
import { migrateFilterMustacheExpressions } from "designer-components/_common-migrations/migrateUseExpression"; | ||
import { IChildTableComponentProps } from ".."; | ||
import { SettingsMigrationContext } from "interfaces/formDesigner"; | ||
|
||
export const migrateV2toV3 = (props: IChildTableComponentProps, _context: SettingsMigrationContext): IChildTableComponentProps => { | ||
const { filters } = props; | ||
|
||
return { | ||
...props, | ||
filters: filters?.map(filter => migrateFilterMustacheExpressions(filter)) ?? [] | ||
}; | ||
}; |
4 changes: 1 addition & 3 deletions
4
shesha-reactjs/src/designer-components/dataTable/tableViewSelector/models.ts
This file contains 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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { IConfigurableFormComponent } from '../../../providers/form/models'; | ||
import { ITableViewProps } from '../../../providers/tableViewSelectorConfigurator/models'; | ||
import { MutableRefObject } from 'react'; | ||
|
||
export interface ITableViewSelectorProps extends IConfigurableFormComponent { | ||
export interface ITableViewSelectorComponentProps extends IConfigurableFormComponent { | ||
filters: ITableViewProps[]; | ||
persistSelectedFilters?: boolean; | ||
componentRef: MutableRefObject<any>; | ||
} |
This file contains 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.