Skip to content

Commit

Permalink
11373 add type for expressions (#11486)
Browse files Browse the repository at this point in the history
* Small refactor
  • Loading branch information
standeren authored Nov 9, 2023
1 parent 683c840 commit e883b87
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 219 deletions.
84 changes: 25 additions & 59 deletions frontend/packages/ux-editor/src/testing/expressionMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
ExpressionFunction,
ExpressionPropertyBase,
Operator,
SubExpression
SubExpression,
} from '../types/Expressions';
import { component1Mock } from "./layoutMock";
import { component1Mock } from './layoutMock';

export const componentId = component1Mock.id;
export const datamodelField = 'some-data-model-field';
Expand All @@ -17,107 +17,73 @@ export const booleanValue = true;
export const baseInternalSubExpression: SubExpression = {
id: 'some-sub-exp-id',
function: ExpressionFunction.Equals,
}
};
export const subExpression0: SubExpression = {
id: 'some-sub-exp-id-0',
function: ExpressionFunction.Equals,
dataSource: DataSource.Component,
value: componentId,
comparableDataSource: DataSource.String,
comparableValue: stringValue,
}
};
export const subExpression1: SubExpression = {
id: 'some-sub-exp-id-1',
function: ExpressionFunction.Equals,
dataSource: DataSource.Null,
value: nullValue,
comparableDataSource: DataSource.Number,
comparableValue: numberValue,
}
};
export const subExpression2: SubExpression = {
id: 'some-sub-exp-id-2',
function: ExpressionFunction.Equals,
dataSource: DataSource.Boolean,
value: booleanValue,
comparableDataSource: DataSource.Component,
comparableValue: componentId,
}
};
export const baseInternalExpression: Expression = {
id: 'some-id-0',
property: ExpressionPropertyBase.Hidden,
subExpressions: [
baseInternalSubExpression
]
}
subExpressions: [baseInternalSubExpression],
};
export const simpleInternalExpression: Expression = {
id: 'some-id-1',
property: ExpressionPropertyBase.Hidden,
subExpressions: [
subExpression0
]
subExpressions: [subExpression0],
};
export const internalExpressionWithMultipleSubExpressions: Expression = {
id: 'some-id-2',
property: ExpressionPropertyBase.Hidden,
operator: Operator.Or,
subExpressions: [
subExpression1,
subExpression2
]
subExpressions: [subExpression1, subExpression2],
};
export const equivalentExternalExpressionWithMultipleSubExpressions = [
'or', [
'equals',
nullValue,
numberValue
],
[
'equals',
booleanValue,
[
DataSource.Component,
componentId
]
]
]
export const parsableExternalExpression = [
'or',
['equals', nullValue, numberValue],
['equals', booleanValue, [DataSource.Component, componentId]],
];
export const parsableExternalExpression: any = [
'and',
[
'equals',
stringValue,
nullValue
],
[
'equals',
numberValue,
booleanValue
],
[
'not',
[
DataSource.Component,
componentId
],
[
DataSource.DataModel,
datamodelField
]
]
['equals', stringValue, nullValue],
['equals', numberValue, booleanValue],
['not', [DataSource.Component, componentId], [DataSource.DataModel, datamodelField]],
];
export const unParsableComplexExpression = '["equals, [datamodel, test, true]';
export const parsableComplexExpression = '["equals", ["datamodel", "test"], true]';
export const parsableNotStudioFriendlyComplexExpression = ["dataModel", "some-field"];
export const parsableNotStudioFriendlyLongComplexExpression = ["and",
["equals", ["equals", ["dataModel", "some-field"], "true"], "true"],
["equals", ["dataModel", "some-field"], "true"]
export const parsableNotStudioFriendlyComplexExpression: any = ['dataModel', 'some-field'];
export const parsableNotStudioFriendlyLongComplexExpression: any = [
'and',
['equals', ['equals', ['dataModel', 'some-field'], 'true'], 'true'],
['equals', ['dataModel', 'some-field'], 'true'],
];
export const internalUnParsableComplexExpression: Expression = {
id: 'some-id-4',
property: ExpressionPropertyBase.Hidden,
complexExpression: unParsableComplexExpression,
}
};
export const internalParsableComplexExpression: Expression = {
id: 'some-id-5',
property: ExpressionPropertyBase.Hidden,
complexExpression: parsableExternalExpression,
}
};
58 changes: 39 additions & 19 deletions frontend/packages/ux-editor/src/types/Expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SubExpression {

export enum Operator {
And = 'and',
Or = 'or'
Or = 'or',
}

export type ExpressionProperty = ExpressionPropertyBase | ExpressionPropertyForGroup;
Expand Down Expand Up @@ -50,21 +50,25 @@ export enum ExpressionFunction {
LessThanEq = 'lessThanEq',
}

export enum DataSource { // comments reflects available values to select if choosing the specific datasource
Component = 'component', // get all components-ids in layoutset
DataModel = 'dataModel', // get all datamodel-ids in selected datamodel
InstanceContext = 'instanceContext', // restrict to only; instanceOwnerPartyId, instanceId, appId
export enum DataSource {
Component = 'component',
DataModel = 'dataModel',
InstanceContext = 'instanceContext',
ApplicationSettings = 'applicationSettings', // get all fields from section "FrontEndSettings" in applicationSettings
String = 'string', // custom input field for string
Number = 'number', // custom input field for number
Boolean = 'boolean', // togglebuttons?
Null = 'null', // no additional field
String = 'string',
Number = 'number',
Boolean = 'boolean',
Null = 'null',
}

export const getExpressionPropertiesBasedOnComponentType = (componentType: LayoutItemType.Component | LayoutItemType.Container): ExpressionProperty[] => {
export const getExpressionPropertiesBasedOnComponentType = (
componentType: LayoutItemType.Component | LayoutItemType.Container,
): ExpressionProperty[] => {
const expressionProperties = Object.values(ExpressionPropertyBase) as string[];
if (componentType === LayoutItemType.Container) {
return expressionProperties.concat(Object.values(ExpressionPropertyForGroup) as string[]) as ExpressionProperty[];
return expressionProperties.concat(
Object.values(ExpressionPropertyForGroup) as string[],
) as ExpressionProperty[];
}
return expressionProperties as ExpressionProperty[];
};
Expand All @@ -83,20 +87,36 @@ export const expressionPropertyTexts = (t: UseText) => ({
[ExpressionPropertyBase.Hidden]: t('right_menu.expressions_property_hidden'),
[ExpressionPropertyBase.ReadOnly]: t('right_menu.expressions_property_read_only'),
[ExpressionPropertyBase.Required]: t('right_menu.expressions_property_required'),
[ExpressionPropertyForGroup.EditAddButton]: t('right_menu.expressions_group_property_show_add_button'),
[ExpressionPropertyForGroup.EditSaveAndNextButton]: t('right_menu.expressions_group_property_show_edit_button'),
[ExpressionPropertyForGroup.EditDeleteButton]: t('right_menu.expressions_group_property_show_delete_button'),
[ExpressionPropertyForGroup.EditSaveButton]: t('right_menu.expressions_group_property_show_save_button'),
[ExpressionPropertyForGroup.EditAddButton]: t(
'right_menu.expressions_group_property_show_add_button',
),
[ExpressionPropertyForGroup.EditSaveAndNextButton]: t(
'right_menu.expressions_group_property_show_edit_button',
),
[ExpressionPropertyForGroup.EditDeleteButton]: t(
'right_menu.expressions_group_property_show_delete_button',
),
[ExpressionPropertyForGroup.EditSaveButton]: t(
'right_menu.expressions_group_property_show_save_button',
),
});

export const expressionInPreviewPropertyTexts = (t: UseText) => ({
[ExpressionPropertyBase.Hidden]: t('right_menu.expressions_property_preview_hidden'),
[ExpressionPropertyBase.ReadOnly]: t('right_menu.expressions_property_preview_read_only'),
[ExpressionPropertyBase.Required]: t('right_menu.expressions_property_preview_required'),
[ExpressionPropertyForGroup.EditAddButton]: t('right_menu.expressions_group_property_preview_show_add_button'),
[ExpressionPropertyForGroup.EditSaveAndNextButton]: t('right_menu.expressions_group_property_preview_show_edit_button'),
[ExpressionPropertyForGroup.EditDeleteButton]: t('right_menu.expressions_group_property_preview_show_delete_button'),
[ExpressionPropertyForGroup.EditSaveButton]: t('right_menu.expressions_group_property_preview_show_save_button'),
[ExpressionPropertyForGroup.EditAddButton]: t(
'right_menu.expressions_group_property_preview_show_add_button',
),
[ExpressionPropertyForGroup.EditSaveAndNextButton]: t(
'right_menu.expressions_group_property_preview_show_edit_button',
),
[ExpressionPropertyForGroup.EditDeleteButton]: t(
'right_menu.expressions_group_property_preview_show_delete_button',
),
[ExpressionPropertyForGroup.EditSaveButton]: t(
'right_menu.expressions_group_property_preview_show_save_button',
),
});

export const expressionDataSourceTexts = (t: UseText) => ({
Expand Down
3 changes: 1 addition & 2 deletions frontend/packages/ux-editor/src/types/FormComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export interface FormComponentBase<T extends ComponentType = ComponentType> {
handleDeleteElement?: () => void;
handleUpdateFormData?: (formData: any) => void;
handleUpdateDataModel?: (dataModelBinding: string) => void;
disabled?: boolean; // Add dynamic type?
// TODO: Figure out if it is necessary to have the Dynamic type here since the type is not actually added to the field?
disabled?: boolean;
required?: boolean | any;
hidden?: boolean | any;
readOnly?: boolean | any;
Expand Down
Loading

0 comments on commit e883b87

Please sign in to comment.