diff --git a/packages/core/src/data_sources/model/DataSource.ts b/packages/core/src/data_sources/model/DataSource.ts index 4ea82ddfb..3b8aeff94 100644 --- a/packages/core/src/data_sources/model/DataSource.ts +++ b/packages/core/src/data_sources/model/DataSource.ts @@ -31,7 +31,7 @@ import { AddOptions, collectionEvents, CombinedModelConstructorOptions, Model, RemoveOptions } from '../../common'; import EditorModel from '../../editor/model/Editor'; -import { DataSourceTransformers, DataSourceType, DataSourceProps, RecordPropsType, DataRecordProps } from '../types'; +import { DataSourceTransformers, DataSourceType, DataSourceProps, DataRecordProps } from '../types'; import DataRecord from './DataRecord'; import DataRecords from './DataRecords'; import DataSources from './DataSources'; diff --git a/packages/core/src/data_sources/model/DataVariable.ts b/packages/core/src/data_sources/model/DataVariable.ts index 915642ebf..65cb8db8d 100644 --- a/packages/core/src/data_sources/model/DataVariable.ts +++ b/packages/core/src/data_sources/model/DataVariable.ts @@ -3,11 +3,12 @@ import EditorModel from '../../editor/model/Editor'; import { stringToPath } from '../../utils/mixins'; export const DataVariableType = 'data-variable'; -export type DataVariableDefinition = { + +export interface DataVariableProps { type: typeof DataVariableType; path: string; defaultValue?: string; -}; +} export default class DataVariable extends Model { em?: EditorModel; @@ -20,8 +21,8 @@ export default class DataVariable extends Model { }; } - constructor(attrs: DataVariableDefinition, options: any) { - super(attrs, options); + constructor(props: DataVariableProps, options: any) { + super(props, options); this.em = options.em; this.listenToDataSource(); } diff --git a/packages/core/src/data_sources/model/DataVariableListenerManager.ts b/packages/core/src/data_sources/model/DataVariableListenerManager.ts index 62e165a5f..f754f549a 100644 --- a/packages/core/src/data_sources/model/DataVariableListenerManager.ts +++ b/packages/core/src/data_sources/model/DataVariableListenerManager.ts @@ -4,9 +4,9 @@ import { Model } from '../../common'; import EditorModel from '../../editor/model/Editor'; import DataVariable, { DataVariableType } from './DataVariable'; import { DynamicValue } from '../types'; -import { DataCondition, ConditionalVariableType } from './conditional_variables/DataCondition'; +import { DataCondition, DataConditionType } from './conditional_variables/DataCondition'; import ComponentDataVariable from './ComponentDataVariable'; -import { CollectionVariableType } from './data_collection/constants'; +import { DataCollectionVariableType } from './data_collection/constants'; import DataCollectionVariable from './data_collection/DataCollectionVariable'; export interface DynamicVariableListenerManagerOptions { @@ -43,13 +43,13 @@ export default class DynamicVariableListenerManager { const type = dynamicVariable.get('type'); let dataListeners: DataVariableListener[] = []; switch (type) { - case CollectionVariableType: + case DataCollectionVariableType: dataListeners = this.listenToDataCollectionVariable(dynamicVariable as DataCollectionVariable); break; case DataVariableType: dataListeners = this.listenToDataVariable(dynamicVariable as DataVariable | ComponentDataVariable, em); break; - case ConditionalVariableType: + case DataConditionType: dataListeners = this.listenToConditionalVariable(dynamicVariable as DataCondition, em); break; } diff --git a/packages/core/src/data_sources/model/TraitDataVariable.ts b/packages/core/src/data_sources/model/TraitDataVariable.ts index f213e4b73..df26de066 100644 --- a/packages/core/src/data_sources/model/TraitDataVariable.ts +++ b/packages/core/src/data_sources/model/TraitDataVariable.ts @@ -1,14 +1,14 @@ -import DataVariable, { DataVariableDefinition } from './DataVariable'; +import DataVariable, { DataVariableProps } from './DataVariable'; import Trait from '../../trait_manager/model/Trait'; import { TraitProperties } from '../../trait_manager/types'; -export type TraitDataVariableDefinition = TraitProperties & DataVariableDefinition; +export interface TraitDataVariableProps extends Omit, DataVariableProps {} export default class TraitDataVariable extends DataVariable { trait?: Trait; - constructor(attrs: TraitDataVariableDefinition, options: any) { - super(attrs, options); + constructor(props: TraitDataVariableProps, options: any) { + super(props, options); this.trait = options.trait; } diff --git a/packages/core/src/data_sources/model/conditional_variables/ConditionalComponent.ts b/packages/core/src/data_sources/model/conditional_variables/ComponentDataCondition.ts similarity index 56% rename from packages/core/src/data_sources/model/conditional_variables/ConditionalComponent.ts rename to packages/core/src/data_sources/model/conditional_variables/ComponentDataCondition.ts index c6bba9aec..f13d93db0 100644 --- a/packages/core/src/data_sources/model/conditional_variables/ConditionalComponent.ts +++ b/packages/core/src/data_sources/model/conditional_variables/ComponentDataCondition.ts @@ -1,30 +1,23 @@ import Component from '../../../dom_components/model/Component'; -import Components from '../../../dom_components/model/Components'; import { ComponentDefinition, ComponentOptions } from '../../../dom_components/model/types'; import { toLowerCase } from '../../../utils/mixins'; -import { DataCondition, ConditionalVariableType, ExpressionDefinition, LogicGroupDefinition } from './DataCondition'; +import { DataCondition, DataConditionProps, DataConditionType } from './DataCondition'; -type ConditionalComponentDefinition = { - condition: ExpressionDefinition | LogicGroupDefinition | boolean; - ifTrue: any; - ifFalse: any; -}; - -export default class ComponentConditionalVariable extends Component { +export default class ComponentDataCondition extends Component { dataCondition: DataCondition; - componentDefinition: ConditionalComponentDefinition; + componentDefinition: DataConditionProps; - constructor(componentDefinition: ConditionalComponentDefinition, opt: ComponentOptions) { - const { condition, ifTrue, ifFalse } = componentDefinition; + constructor(props: DataConditionProps, opt: ComponentOptions) { + const { condition, ifTrue, ifFalse } = props; const dataConditionInstance = new DataCondition(condition, ifTrue, ifFalse, { em: opt.em }); const initialComponentsProps = dataConditionInstance.getDataValue(); const conditionalCmptDef = { - type: ConditionalVariableType, + type: DataConditionType, components: initialComponentsProps, }; super(conditionalCmptDef, opt); - this.componentDefinition = componentDefinition; + this.componentDefinition = props; this.dataCondition = dataConditionInstance; this.dataCondition.onValueChange = this.handleConditionChange.bind(this); } @@ -37,7 +30,7 @@ export default class ComponentConditionalVariable extends Component { } static isComponent(el: HTMLElement) { - return toLowerCase(el.tagName) === ConditionalVariableType; + return toLowerCase(el.tagName) === DataConditionType; } toJSON(): ComponentDefinition { diff --git a/packages/core/src/data_sources/model/conditional_variables/Condition.ts b/packages/core/src/data_sources/model/conditional_variables/Condition.ts index a17fd70bf..e2b42c353 100644 --- a/packages/core/src/data_sources/model/conditional_variables/Condition.ts +++ b/packages/core/src/data_sources/model/conditional_variables/Condition.ts @@ -1,7 +1,7 @@ -import { DataVariableDefinition, DataVariableType } from './../DataVariable'; +import { DataVariableProps } from './../DataVariable'; import EditorModel from '../../../editor/model/Editor'; import { evaluateVariable, isDataVariable } from '../utils'; -import { ExpressionDefinition, LogicGroupDefinition } from './DataCondition'; +import { ExpressionProps, LogicGroupProps } from './DataCondition'; import { LogicalGroupStatement } from './LogicalGroupStatement'; import { Operator } from './operators'; import { GenericOperation, GenericOperator } from './operators/GenericOperator'; @@ -10,13 +10,15 @@ import { NumberOperator, NumberOperation } from './operators/NumberOperator'; import { StringOperator, StringOperation } from './operators/StringOperations'; import { Model } from '../../../common'; +export type ConditionProps = ExpressionProps | LogicGroupProps | boolean; + export class Condition extends Model { - private condition: ExpressionDefinition | LogicGroupDefinition | boolean; + private condition: ConditionProps; private em: EditorModel; - constructor(condition: ExpressionDefinition | LogicGroupDefinition | boolean, opts: { em: EditorModel }) { - super(condition); - this.condition = condition; + constructor(props: ConditionProps, opts: { em: EditorModel }) { + super(props); + this.condition = props; this.em = opts.em; } @@ -68,7 +70,7 @@ export class Condition extends Model { * Extracts all data variables from the condition, including nested ones. */ getDataVariables() { - const variables: DataVariableDefinition[] = []; + const variables: DataVariableProps[] = []; this.extractVariables(this.condition, variables); return variables; } @@ -77,8 +79,8 @@ export class Condition extends Model { * Recursively extracts variables from expressions or logic groups. */ private extractVariables( - condition: boolean | LogicGroupDefinition | ExpressionDefinition, - variables: DataVariableDefinition[], + condition: boolean | LogicGroupProps | ExpressionProps, + variables: DataVariableProps[], ): void { if (this.isExpression(condition)) { if (isDataVariable(condition.left)) variables.push(condition.left); @@ -91,14 +93,14 @@ export class Condition extends Model { /** * Checks if a condition is a LogicGroup. */ - private isLogicGroup(condition: any): condition is LogicGroupDefinition { + private isLogicGroup(condition: any): condition is LogicGroupProps { return condition && typeof condition.logicalOperator !== 'undefined' && Array.isArray(condition.statements); } /** * Checks if a condition is an Expression. */ - private isExpression(condition: any): condition is ExpressionDefinition { + private isExpression(condition: any): condition is ExpressionProps { return condition && typeof condition.left !== 'undefined' && typeof condition.operator === 'string'; } diff --git a/packages/core/src/data_sources/model/conditional_variables/DataCondition.ts b/packages/core/src/data_sources/model/conditional_variables/DataCondition.ts index 6208a318f..7c9a6fd5f 100644 --- a/packages/core/src/data_sources/model/conditional_variables/DataCondition.ts +++ b/packages/core/src/data_sources/model/conditional_variables/DataCondition.ts @@ -5,37 +5,35 @@ import { Model } from '../../../common'; import { LogicalOperation } from './operators/LogicalOperator'; import DynamicVariableListenerManager from '../DataVariableListenerManager'; import EditorModel from '../../../editor/model/Editor'; -import { Condition } from './Condition'; -import DataVariable, { DataVariableDefinition } from '../DataVariable'; +import { Condition, ConditionProps } from './Condition'; +import DataVariable, { DataVariableProps } from '../DataVariable'; import { evaluateVariable, isDataVariable } from '../utils'; -export const ConditionalVariableType = 'conditional-variable'; -export type ExpressionDefinition = { +export const DataConditionType = 'data-condition'; + +export interface ExpressionProps { left: any; operator: GenericOperation | StringOperation | NumberOperation; right: any; -}; +} -export type LogicGroupDefinition = { +export interface LogicGroupProps { logicalOperator: LogicalOperation; - statements: (ExpressionDefinition | LogicGroupDefinition | boolean)[]; -}; + statements: ConditionProps[]; +} -export type ConditionDefinition = ExpressionDefinition | LogicGroupDefinition | boolean; -export type ConditionalVariableDefinition = { - type: typeof ConditionalVariableType; - condition: ConditionDefinition; +export interface DataConditionProps { + type: typeof DataConditionType; + condition: ConditionProps; ifTrue: any; ifFalse: any; -}; +} -type DataConditionType = { - type: typeof ConditionalVariableType; +interface DataConditionPropsDefined extends Omit { condition: Condition; - ifTrue: any; - ifFalse: any; -}; -export class DataCondition extends Model { +} + +export class DataCondition extends Model { lastEvaluationResult: boolean; private condition: Condition; private em: EditorModel; @@ -43,7 +41,7 @@ export class DataCondition extends Model { private _onValueChange?: () => void; constructor( - condition: ExpressionDefinition | LogicGroupDefinition | boolean, + condition: ConditionProps, public ifTrue: any, public ifFalse: any, opts: { em: EditorModel; onValueChange?: () => void }, @@ -54,7 +52,7 @@ export class DataCondition extends Model { const conditionInstance = new Condition(condition, { em: opts.em }); super({ - type: ConditionalVariableType, + type: DataConditionType, condition: conditionInstance, ifTrue, ifFalse, @@ -107,7 +105,7 @@ export class DataCondition extends Model { } getDependentDataVariables() { - const dataVariables: DataVariableDefinition[] = this.condition.getDataVariables(); + const dataVariables: DataVariableProps[] = this.condition.getDataVariables(); if (isDataVariable(this.ifTrue)) dataVariables.push(this.ifTrue); if (isDataVariable(this.ifFalse)) dataVariables.push(this.ifFalse); @@ -121,7 +119,7 @@ export class DataCondition extends Model { toJSON() { return { - type: ConditionalVariableType, + type: DataConditionType, condition: this.condition, ifTrue: this.ifTrue, ifFalse: this.ifFalse, diff --git a/packages/core/src/data_sources/model/conditional_variables/LogicalGroupStatement.ts b/packages/core/src/data_sources/model/conditional_variables/LogicalGroupStatement.ts index 284e99e96..c3294a02c 100644 --- a/packages/core/src/data_sources/model/conditional_variables/LogicalGroupStatement.ts +++ b/packages/core/src/data_sources/model/conditional_variables/LogicalGroupStatement.ts @@ -1,14 +1,13 @@ -import { LogicalOperator } from './operators/LogicalOperator'; -import { ExpressionDefinition, LogicGroupDefinition } from './DataCondition'; -import { Condition } from './Condition'; import EditorModel from '../../../editor/model/Editor'; +import { Condition, ConditionProps } from './Condition'; +import { LogicalOperator } from './operators/LogicalOperator'; export class LogicalGroupStatement { private em: EditorModel; constructor( private operator: LogicalOperator, - private statements: (ExpressionDefinition | LogicGroupDefinition | boolean)[], + private statements: ConditionProps[], opts: { em: EditorModel }, ) { this.em = opts.em; diff --git a/packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts b/packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts index 508b14e58..bbeaae747 100644 --- a/packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts +++ b/packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts @@ -1,28 +1,23 @@ -import DataVariable, { DataVariableType } from '../DataVariable'; import { isArray } from 'underscore'; +import { ObjectAny } from '../../../common'; import Component from '../../../dom_components/model/Component'; import { ComponentDefinition, ComponentDefinitionDefined, ComponentOptions } from '../../../dom_components/model/types'; +import EditorModel from '../../../editor/model/Editor'; import { toLowerCase } from '../../../utils/mixins'; import DataSource from '../DataSource'; -import { ObjectAny } from '../../../common'; -import EditorModel from '../../../editor/model/Editor'; +import DataVariable, { DataVariableType } from '../DataVariable'; +import DynamicVariableListenerManager from '../DataVariableListenerManager'; +import { DataCollectionType, keyCollectionDefinition, keyCollectionsStateMap, keyIsCollectionItem } from './constants'; import { - ComponentDataCollectionDefinition, + ComponentDataCollectionProps, DataCollectionConfig, - DataCollectionDefinition, + DataCollectionProps, DataCollectionState, DataCollectionStateMap, } from './types'; -import { - keyCollectionDefinition, - keyCollectionsStateMap, - CollectionComponentType, - keyIsCollectionItem, -} from './constants'; -import DynamicVariableListenerManager from '../DataVariableListenerManager'; export default class ComponentDataCollection extends Component { - constructor(props: ComponentDataCollectionDefinition, opt: ComponentOptions) { + constructor(props: ComponentDataCollectionProps, opt: ComponentOptions) { const collectionDef = props[keyCollectionDefinition]; if (opt.forCloning) { // If we are cloning, leave setting the collection items to the main symbol collection @@ -58,7 +53,7 @@ export default class ComponentDataCollection extends Component { } static isComponent(el: HTMLElement) { - return toLowerCase(el.tagName) === CollectionComponentType; + return toLowerCase(el.tagName) === DataCollectionType; } hasDynamicDataSource() { @@ -67,7 +62,7 @@ export default class ComponentDataCollection extends Component { } toJSON(opts?: ObjectAny) { - const json = super.toJSON.call(this, opts) as ComponentDataCollectionDefinition; + const json = super.toJSON.call(this, opts) as ComponentDataCollectionProps; json[keyCollectionDefinition].componentDef = this.getComponentDef(); delete json.components; @@ -127,7 +122,7 @@ export default class ComponentDataCollection extends Component { function getCollectionItems( em: EditorModel, - collectionDef: DataCollectionDefinition, + collectionDef: DataCollectionProps, parentCollectionStateMap: DataCollectionStateMap, opt: ComponentOptions, ) { diff --git a/packages/core/src/data_sources/model/data_collection/ComponentDataCollectionVariable.ts b/packages/core/src/data_sources/model/data_collection/ComponentDataCollectionVariable.ts index 928eb6bba..8cd1a436d 100644 --- a/packages/core/src/data_sources/model/data_collection/ComponentDataCollectionVariable.ts +++ b/packages/core/src/data_sources/model/data_collection/ComponentDataCollectionVariable.ts @@ -1,9 +1,9 @@ import Component from '../../../dom_components/model/Component'; -import { ComponentOptions, ComponentProperties } from '../../../dom_components/model/types'; +import { ComponentOptions } from '../../../dom_components/model/types'; import { toLowerCase } from '../../../utils/mixins'; import DataCollectionVariable from './DataCollectionVariable'; -import { CollectionVariableType, keyCollectionsStateMap } from './constants'; -import { DataCollectionStateMap, DataCollectionVariableDefinition } from './types'; +import { DataCollectionVariableType, keyCollectionsStateMap } from './constants'; +import { ComponentDataCollectionVariableProps, DataCollectionStateMap } from './types'; export default class ComponentDataCollectionVariable extends Component { datacollectionVariable: DataCollectionVariable; @@ -14,14 +14,14 @@ export default class ComponentDataCollectionVariable extends Component { return { ...componentDefaults, - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: undefined, variableType: undefined, path: undefined, }; } - constructor(props: DataCollectionVariableDefinition & ComponentProperties, opt: ComponentOptions) { + constructor(props: ComponentDataCollectionVariableProps, opt: ComponentOptions) { super(props, opt); const em = opt.em; const { type, variableType, path, collectionId } = props; @@ -50,6 +50,6 @@ export default class ComponentDataCollectionVariable extends Component { } static isComponent(el: HTMLElement) { - return toLowerCase(el.tagName) === CollectionVariableType; + return toLowerCase(el.tagName) === DataCollectionVariableType; } } diff --git a/packages/core/src/data_sources/model/data_collection/DataCollectionVariable.ts b/packages/core/src/data_sources/model/data_collection/DataCollectionVariable.ts index f77f28915..2cbaab338 100644 --- a/packages/core/src/data_sources/model/data_collection/DataCollectionVariable.ts +++ b/packages/core/src/data_sources/model/data_collection/DataCollectionVariable.ts @@ -1,23 +1,24 @@ -import { DataCollectionVariableDefinition } from './types'; +import { DataCollectionVariableProps } from './types'; import { Model } from '../../../common'; import EditorModel from '../../../editor/model/Editor'; import DataVariable, { DataVariableType } from '../DataVariable'; -import { CollectionVariableType } from './constants'; +import { DataCollectionVariableType } from './constants'; import { DataCollectionState, DataCollectionStateMap } from './types'; import DynamicVariableListenerManager from '../DataVariableListenerManager'; -type ResolvedDataCollectionVariable = DataCollectionVariableDefinition & { + +interface DataCollectionVariablePropsDefined extends DataCollectionVariableProps { value?: any; -}; +} -export default class DataCollectionVariable extends Model { +export default class DataCollectionVariable extends Model { em: EditorModel; collectionsStateMap?: DataCollectionStateMap; dataVariable?: DataVariable; dynamicValueListener?: DynamicVariableListenerManager; - defaults(): Partial { + defaults(): Partial { return { - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: undefined, variableType: undefined, path: undefined, @@ -26,13 +27,13 @@ export default class DataCollectionVariable extends Model {} + +export interface DataCollectionProps { + type: typeof DataCollectionType; collectionConfig: DataCollectionConfig; componentDef: ComponentDefinition; } -export type DataCollectionVariableDefinition = { - type: typeof CollectionVariableType; +export interface DataCollectionVariableProps { + type: typeof DataCollectionVariableType; variableType: DataCollectionStateVariableType; collectionId: string; path?: string; -}; +} diff --git a/packages/core/src/data_sources/model/utils.ts b/packages/core/src/data_sources/model/utils.ts index ba8f9acf0..8acf4a355 100644 --- a/packages/core/src/data_sources/model/utils.ts +++ b/packages/core/src/data_sources/model/utils.ts @@ -1,15 +1,14 @@ import EditorModel from '../../editor/model/Editor'; -import { DynamicValue, DynamicValueDefinition } from '../types'; +import { DynamicValue, DynamicValueProps } from '../types'; import { DataCollectionStateMap } from './data_collection/types'; import DataCollectionVariable from './data_collection/DataCollectionVariable'; -import { CollectionVariableType } from './data_collection/constants'; -import { ConditionalVariableType, DataCondition } from './conditional_variables/DataCondition'; +import { DataCollectionVariableType } from './data_collection/constants'; +import { DataConditionType, DataCondition } from './conditional_variables/DataCondition'; import DataVariable, { DataVariableType } from './DataVariable'; -export function isDynamicValueDefinition(value: any): value is DynamicValueDefinition { +export function isDynamicValueDefinition(value: any): value is DynamicValueProps { return ( - typeof value === 'object' && - [DataVariableType, ConditionalVariableType, CollectionVariableType].includes(value?.type) + typeof value === 'object' && [DataVariableType, DataConditionType, DataCollectionVariableType].includes(value?.type) ); } @@ -22,7 +21,7 @@ export function isDataVariable(variable: any) { } export function isDataCondition(variable: any) { - return variable?.type === ConditionalVariableType; + return variable?.type === DataConditionType; } export function evaluateVariable(variable: any, em: EditorModel) { @@ -30,7 +29,7 @@ export function evaluateVariable(variable: any, em: EditorModel) { } export function getDynamicValueInstance( - valueDefinition: DynamicValueDefinition, + valueDefinition: DynamicValueProps, options: { em: EditorModel; collectionsStateMap?: DataCollectionStateMap; @@ -44,12 +43,12 @@ export function getDynamicValueInstance( case DataVariableType: dynamicVariable = new DataVariable(valueDefinition, { em: em }); break; - case ConditionalVariableType: { + case DataConditionType: { const { condition, ifTrue, ifFalse } = valueDefinition; dynamicVariable = new DataCondition(condition, ifTrue, ifFalse, { em: em }); break; } - case CollectionVariableType: { + case DataCollectionVariableType: { dynamicVariable = new DataCollectionVariable(valueDefinition, options); break; } @@ -61,7 +60,7 @@ export function getDynamicValueInstance( } export function evaluateDynamicValueDefinition( - valueDefinition: DynamicValueDefinition, + valueDefinition: DynamicValueProps, options: { em: EditorModel; collectionsStateMap?: DataCollectionStateMap; diff --git a/packages/core/src/data_sources/types.ts b/packages/core/src/data_sources/types.ts index fd18e469d..649aa34af 100644 --- a/packages/core/src/data_sources/types.ts +++ b/packages/core/src/data_sources/types.ts @@ -1,17 +1,16 @@ import { ObjectAny } from '../common'; import DataCollectionVariable from './model/data_collection/DataCollectionVariable'; -import { DataCollectionVariableDefinition } from './model/data_collection/types'; +import { DataCollectionVariableProps } from './model/data_collection/types'; import ComponentDataVariable from './model/ComponentDataVariable'; import DataRecord from './model/DataRecord'; import DataRecords from './model/DataRecords'; -import DataVariable, { DataVariableDefinition } from './model/DataVariable'; -import { ConditionalVariableDefinition, DataCondition } from './model/conditional_variables/DataCondition'; +import DataVariable, { DataVariableProps } from './model/DataVariable'; +import { DataConditionProps, DataCondition } from './model/conditional_variables/DataCondition'; export type DynamicValue = DataVariable | ComponentDataVariable | DataCondition | DataCollectionVariable; -export type DynamicValueDefinition = - | DataVariableDefinition - | ConditionalVariableDefinition - | DataCollectionVariableDefinition; + +export type DynamicValueProps = DataVariableProps | DataConditionProps | DataCollectionVariableProps; + export interface DataRecordProps extends ObjectAny { /** * Record id. diff --git a/packages/core/src/data_sources/view/ComponentDataConditionView.ts b/packages/core/src/data_sources/view/ComponentDataConditionView.ts new file mode 100644 index 000000000..c8bf42438 --- /dev/null +++ b/packages/core/src/data_sources/view/ComponentDataConditionView.ts @@ -0,0 +1,4 @@ +import ComponentView from '../../dom_components/view/ComponentView'; +import ComponentDataCondition from '../model/conditional_variables/ComponentDataCondition'; + +export default class ComponentDataConditionView extends ComponentView {} diff --git a/packages/core/src/data_sources/view/ComponentDynamicView.ts b/packages/core/src/data_sources/view/ComponentDynamicView.ts deleted file mode 100644 index 75c287d45..000000000 --- a/packages/core/src/data_sources/view/ComponentDynamicView.ts +++ /dev/null @@ -1,4 +0,0 @@ -import ComponentView from '../../dom_components/view/ComponentView'; -import ConditionalComponent from '../model/conditional_variables/ConditionalComponent'; - -export default class ConditionalComponentView extends ComponentView {} diff --git a/packages/core/src/dom_components/index.ts b/packages/core/src/dom_components/index.ts index 053b50a1f..ee202c248 100644 --- a/packages/core/src/dom_components/index.ts +++ b/packages/core/src/dom_components/index.ts @@ -125,12 +125,12 @@ import { BlockProperties } from '../block_manager/model/Block'; import ComponentDataVariable from '../data_sources/model/ComponentDataVariable'; import ComponentDataVariableView from '../data_sources/view/ComponentDataVariableView'; import { DataVariableType } from '../data_sources/model/DataVariable'; -import { ConditionalVariableType } from '../data_sources/model/conditional_variables/DataCondition'; -import ComponentConditionalVariable from '../data_sources/model/conditional_variables/ConditionalComponent'; -import ConditionalComponentView from '../data_sources/view/ComponentDynamicView'; +import { DataConditionType } from '../data_sources/model/conditional_variables/DataCondition'; +import ComponentDataCondition from '../data_sources/model/conditional_variables/ComponentDataCondition'; +import ComponentDataConditionView from '../data_sources/view/ComponentDataConditionView'; import ComponentDataCollection from '../data_sources/model/data_collection/ComponentDataCollection'; import ComponentDataCollectionView from '../data_sources/model/data_collection/ComponentDataCollectionView'; -import { CollectionComponentType, CollectionVariableType } from '../data_sources/model/data_collection/constants'; +import { DataCollectionType, DataCollectionVariableType } from '../data_sources/model/data_collection/constants'; import ComponentDataCollectionVariable from '../data_sources/model/data_collection/ComponentDataCollectionVariable'; import ComponentDataCollectionVariableView from '../data_sources/model/data_collection/ComponentDataCollectionVariableView'; @@ -199,19 +199,19 @@ export interface CanMoveResult { export default class ComponentManager extends ItemManagerModule { componentTypes: ComponentStackItem[] = [ { - id: CollectionVariableType, + id: DataCollectionVariableType, model: ComponentDataCollectionVariable, view: ComponentDataCollectionVariableView, }, { - id: CollectionComponentType, + id: DataCollectionType, model: ComponentDataCollection, view: ComponentDataCollectionView, }, { - id: ConditionalVariableType, - model: ComponentConditionalVariable, - view: ConditionalComponentView, + id: DataConditionType, + model: ComponentDataCondition, + view: ComponentDataConditionView, }, { id: DataVariableType, diff --git a/packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts b/packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts index 075d1df44..c38e4f408 100644 --- a/packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts +++ b/packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts @@ -1,5 +1,5 @@ import { Model, ObjectAny } from '../../common'; -import { CollectionVariableType, keyIsCollectionItem } from '../../data_sources/model/data_collection/constants'; +import { DataCollectionVariableType, keyIsCollectionItem } from '../../data_sources/model/data_collection/constants'; import { DataCollectionStateMap } from '../../data_sources/model/data_collection/types'; import EditorModel from '../../editor/model/Editor'; import Component from './Component'; @@ -82,8 +82,8 @@ export class ComponentDynamicValueWatcher extends Model { private updateSymbolOverride() { if (!this.component || !this.component.get(keyIsCollectionItem)) return; - const keys = this.propertyWatcher.getDynamicValuesOfType(CollectionVariableType); - const attributesKeys = this.attributeWatcher.getDynamicValuesOfType(CollectionVariableType); + const keys = this.propertyWatcher.getDynamicValuesOfType(DataCollectionVariableType); + const attributesKeys = this.attributeWatcher.getDynamicValuesOfType(DataCollectionVariableType); const combinedKeys = [keyCollectionsStateMap, ...keys]; const haveOverridenAttributes = Object.keys(attributesKeys).length; diff --git a/packages/core/src/dom_components/model/DynamicValueWatcher.ts b/packages/core/src/dom_components/model/DynamicValueWatcher.ts index 6673d4b26..d15820b85 100644 --- a/packages/core/src/dom_components/model/DynamicValueWatcher.ts +++ b/packages/core/src/dom_components/model/DynamicValueWatcher.ts @@ -1,11 +1,11 @@ -import { DynamicValueDefinition } from './../../data_sources/types'; +import { DynamicValueProps } from './../../data_sources/types'; import { DataCollectionStateMap } from '../../data_sources/model/data_collection/types'; import { Model, ObjectAny } from '../../common'; import DynamicVariableListenerManager from '../../data_sources/model/DataVariableListenerManager'; import { evaluateDynamicValueDefinition, isDynamicValueDefinition } from '../../data_sources/model/utils'; import EditorModel from '../../editor/model/Editor'; import Component from './Component'; -import { CollectionVariableType } from '../../data_sources/model/data_collection/constants'; +import { DataCollectionVariableType } from '../../data_sources/model/data_collection/constants'; import { ModelDestroyOptions } from 'backbone'; export interface DynamicWatchersOptions { @@ -39,9 +39,9 @@ export class DynamicValueWatcher extends Model<{ component: Component | undefine updateCollectionStateMap(collectionsStateMap: DataCollectionStateMap) { this.collectionsStateMap = collectionsStateMap; - const collectionVariablesKeys = this.getDynamicValuesOfType(CollectionVariableType); + const collectionVariablesKeys = this.getDynamicValuesOfType(DataCollectionVariableType); const collectionVariablesObject = collectionVariablesKeys.reduce( - (acc: { [key: string]: DynamicValueDefinition | null }, key) => { + (acc: { [key: string]: DynamicValueProps | null }, key) => { acc[key] = null; return acc; }, @@ -163,7 +163,7 @@ export class DynamicValueWatcher extends Model<{ component: Component | undefine return serializableValues; } - getDynamicValuesOfType(type: DynamicValueDefinition['type']) { + getDynamicValuesOfType(type: DynamicValueProps['type']) { const keys = Object.keys(this.dynamicVariableListeners).filter((key: string) => { // @ts-ignore return this.dynamicVariableListeners[key].dynamicVariable.get('type') === type; diff --git a/packages/core/src/dom_components/model/SymbolUtils.ts b/packages/core/src/dom_components/model/SymbolUtils.ts index e187fe61e..eb0de8292 100644 --- a/packages/core/src/dom_components/model/SymbolUtils.ts +++ b/packages/core/src/dom_components/model/SymbolUtils.ts @@ -3,7 +3,10 @@ import Component, { keySymbol, keySymbolOvrd, keySymbols } from './Component'; import { SymbolToUpOptions } from './types'; import { isEmptyObj } from '../../utils/mixins'; import Components from './Components'; -import { CollectionVariableType, keyCollectionDefinition } from '../../data_sources/model/data_collection/constants'; +import { + DataCollectionVariableType, + keyCollectionDefinition, +} from '../../data_sources/model/data_collection/constants'; export const isSymbolMain = (cmp: Component) => isArray(cmp.get(keySymbols)); @@ -175,10 +178,10 @@ const shouldPropagateProperty = (props: Record, prop: string, compo const isCollectionVariableDefinition = (() => { if (prop === 'attributes') { const attributes = props['attributes']; - return Object.values(attributes).some((attr: any) => attr?.type === CollectionVariableType); + return Object.values(attributes).some((attr: any) => attr?.type === DataCollectionVariableType); } - return props[prop]?.type === CollectionVariableType; + return props[prop]?.type === DataCollectionVariableType; })(); return !isSymbolOverride(component, prop) || isCollectionVariableDefinition; diff --git a/packages/core/src/domain_abstract/model/StyleableModel.ts b/packages/core/src/domain_abstract/model/StyleableModel.ts index 5621b4d67..a7f6619e1 100644 --- a/packages/core/src/domain_abstract/model/StyleableModel.ts +++ b/packages/core/src/domain_abstract/model/StyleableModel.ts @@ -1,23 +1,23 @@ import { isArray, isString, keys } from 'underscore'; -import { Model, ObjectAny, ObjectHash, SetOptions, View } from '../../common'; +import { Model, ObjectAny, ObjectHash, SetOptions } from '../../common'; import ParserHtml from '../../parser/model/ParserHtml'; import Selectors from '../../selector_manager/model/Selectors'; import { shallowDiff } from '../../utils/mixins'; import EditorModel from '../../editor/model/Editor'; import StyleDataVariable from '../../data_sources/model/StyleDataVariable'; -import { DataVariableDefinition, DataVariableType } from '../../data_sources/model/DataVariable'; +import { DataVariableProps, DataVariableType } from '../../data_sources/model/DataVariable'; import DynamicVariableListenerManager from '../../data_sources/model/DataVariableListenerManager'; import CssRuleView from '../../css_composer/view/CssRuleView'; import ComponentView from '../../dom_components/view/ComponentView'; import Frame from '../../canvas/model/Frame'; import { DataCondition, - ConditionalVariableType, - ConditionalVariableDefinition, + DataConditionType, + DataConditionProps, } from '../../data_sources/model/conditional_variables/DataCondition'; import { isDynamicValue, isDynamicValueDefinition } from '../../data_sources/model/utils'; -import { DynamicValueDefinition } from '../../data_sources/types'; -export type StyleProps = Record; +import { DynamicValueProps } from '../../data_sources/types'; +export type StyleProps = Record; export type UpdateStyleOptions = SetOptions & { partial?: boolean; @@ -139,21 +139,21 @@ export default class StyleableModel extends Model return newStyle; } - private resolveDynamicValue(styleValue: DynamicValueDefinition) { + private resolveDynamicValue(styleValue: DynamicValueProps) { const dynamicType = styleValue.type; let styleDynamicVariable; switch (dynamicType) { case DataVariableType: styleDynamicVariable = new StyleDataVariable(styleValue, { em: this.em }); break; - case ConditionalVariableType: { + case DataConditionType: { const { condition, ifTrue, ifFalse } = styleValue; styleDynamicVariable = new DataCondition(condition, ifTrue, ifFalse, { em: this.em! }); break; } default: throw new Error( - `Unsupported dynamic value type for styles. Only '${DataVariableType}' and '${ConditionalVariableType}' are supported. Received '${dynamicType}'.`, + `Unsupported dynamic value type for styles. Only '${DataVariableType}' and '${DataConditionType}' are supported. Received '${dynamicType}'.`, ); } diff --git a/packages/core/src/trait_manager/model/Trait.ts b/packages/core/src/trait_manager/model/Trait.ts index 497a0741d..6a6e57187 100644 --- a/packages/core/src/trait_manager/model/Trait.ts +++ b/packages/core/src/trait_manager/model/Trait.ts @@ -1,4 +1,4 @@ -import { ConditionalVariableType, DataCondition } from './../../data_sources/model/conditional_variables/DataCondition'; +import { DataCondition } from './../../data_sources/model/conditional_variables/DataCondition'; import { isString, isUndefined } from 'underscore'; import Category from '../../abstract/ModuleCategory'; import { LocaleOptions, Model, SetOptions } from '../../common'; diff --git a/packages/core/test/specs/data_sources/model/conditional_variables/ComponentConditionalVariable.ts b/packages/core/test/specs/data_sources/model/conditional_variables/ComponentConditionalVariable.ts index 478bed43e..95710a7ac 100644 --- a/packages/core/test/specs/data_sources/model/conditional_variables/ComponentConditionalVariable.ts +++ b/packages/core/test/specs/data_sources/model/conditional_variables/ComponentConditionalVariable.ts @@ -1,11 +1,12 @@ import { Component, DataSourceManager, Editor } from '../../../../../src'; import { DataVariableType } from '../../../../../src/data_sources/model/DataVariable'; -import { MissingConditionError } from '../../../../../src/data_sources/model/conditional_variables/DataCondition'; -import { ConditionalVariableType } from '../../../../../src/data_sources/model/conditional_variables/DataCondition'; +import { + MissingConditionError, + DataConditionType, +} from '../../../../../src/data_sources/model/conditional_variables/DataCondition'; import { GenericOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/GenericOperator'; import { NumberOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/NumberOperator'; -import { DataSourceProps } from '../../../../../src/data_sources/types'; -import ConditionalComponentView from '../../../../../src/data_sources/view/ComponentDynamicView'; +import ComponentDataConditionView from '../../../../../src/data_sources/view/ComponentDataConditionView'; import ComponentWrapper from '../../../../../src/dom_components/model/ComponentWrapper'; import ComponentTableView from '../../../../../src/dom_components/view/ComponentTableView'; import ComponentTextView from '../../../../../src/dom_components/view/ComponentTextView'; @@ -28,7 +29,7 @@ describe('ComponentConditionalVariable', () => { it('should add a component with a condition that evaluates a component definition', () => { const component = cmpRoot.append({ - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, @@ -41,10 +42,10 @@ describe('ComponentConditionalVariable', () => { }, })[0]; expect(component).toBeDefined(); - expect(component.get('type')).toBe(ConditionalVariableType); + expect(component.get('type')).toBe(DataConditionType); expect(component.getInnerHTML()).toBe('

some text

'); const componentView = component.getView(); - expect(componentView).toBeInstanceOf(ConditionalComponentView); + expect(componentView).toBeInstanceOf(ComponentDataConditionView); expect(componentView?.el.textContent).toBe('some text'); const childComponent = getFirstChild(component); @@ -58,7 +59,7 @@ describe('ComponentConditionalVariable', () => { it('should add a component with a condition that evaluates a string', () => { const component = cmpRoot.append({ - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, @@ -67,10 +68,10 @@ describe('ComponentConditionalVariable', () => { ifTrue: '

some text

', })[0]; expect(component).toBeDefined(); - expect(component.get('type')).toBe(ConditionalVariableType); + expect(component.get('type')).toBe(DataConditionType); expect(component.getInnerHTML()).toBe('

some text

'); const componentView = component.getView(); - expect(componentView).toBeInstanceOf(ConditionalComponentView); + expect(componentView).toBeInstanceOf(ComponentDataConditionView); expect(componentView?.el.textContent).toBe('some text'); const childComponent = getFirstChild(component); @@ -93,7 +94,7 @@ describe('ComponentConditionalVariable', () => { dsm.add(dataSource); const component = cmpRoot.append({ - type: ConditionalVariableType, + type: DataConditionType, condition: { left: { type: DataVariableType, @@ -142,7 +143,7 @@ describe('ComponentConditionalVariable', () => { dsm.add(dataSource); const component = cmpRoot.append({ - type: ConditionalVariableType, + type: DataConditionType, condition: { left: { type: DataVariableType, @@ -158,7 +159,7 @@ describe('ComponentConditionalVariable', () => { tagName: 'div', components: [ { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: { type: DataVariableType, @@ -189,7 +190,7 @@ describe('ComponentConditionalVariable', () => { it('should store conditional components', () => { const conditionalCmptDef = { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, @@ -215,7 +216,7 @@ describe('ComponentConditionalVariable', () => { it('should throw an error if no condition is passed', () => { const conditionalCmptDef = { - type: ConditionalVariableType, + type: DataConditionType, ifTrue: { tagName: 'h1', type: 'text', diff --git a/packages/core/test/specs/data_sources/model/conditional_variables/ConditionalStyles.ts b/packages/core/test/specs/data_sources/model/conditional_variables/ConditionalStyles.ts index 516dd2f4d..5f7d4af0f 100644 --- a/packages/core/test/specs/data_sources/model/conditional_variables/ConditionalStyles.ts +++ b/packages/core/test/specs/data_sources/model/conditional_variables/ConditionalStyles.ts @@ -1,12 +1,11 @@ import { DataSourceManager, Editor } from '../../../../../src'; import { DataVariableType } from '../../../../../src/data_sources/model/DataVariable'; import { - ConditionalVariableType, + DataConditionType, MissingConditionError, } from '../../../../../src/data_sources/model/conditional_variables/DataCondition'; import { GenericOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/GenericOperator'; import { NumberOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/NumberOperator'; -import { DataSourceProps } from '../../../../../src/data_sources/types'; import ComponentWrapper from '../../../../../src/dom_components/model/ComponentWrapper'; import EditorModel from '../../../../../src/editor/model/Editor'; import { filterObjectForSnapshot, setupTestEditor } from '../../../../common'; @@ -32,7 +31,7 @@ describe('StyleConditionalVariable', () => { content: 'some text', style: { color: { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, @@ -64,7 +63,7 @@ describe('StyleConditionalVariable', () => { content: 'some text', style: { color: { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: { type: DataVariableType, @@ -96,7 +95,7 @@ describe('StyleConditionalVariable', () => { content: 'some text', style: { color: { - type: ConditionalVariableType, + type: DataConditionType, ifTrue: 'grey', ifFalse: 'red', }, @@ -112,7 +111,7 @@ describe('StyleConditionalVariable', () => { content: 'some text', style: { color: { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, diff --git a/packages/core/test/specs/data_sources/model/conditional_variables/ConditionalTraits.ts b/packages/core/test/specs/data_sources/model/conditional_variables/ConditionalTraits.ts index a9907207a..0a65a2321 100644 --- a/packages/core/test/specs/data_sources/model/conditional_variables/ConditionalTraits.ts +++ b/packages/core/test/specs/data_sources/model/conditional_variables/ConditionalTraits.ts @@ -1,5 +1,5 @@ import { DataSourceManager, Editor } from '../../../../../src'; -import { ConditionalVariableType } from '../../../../../src/data_sources/model/conditional_variables/DataCondition'; +import { DataConditionType } from '../../../../../src/data_sources/model/conditional_variables/DataCondition'; import { NumberOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/NumberOperator'; import ComponentWrapper from '../../../../../src/dom_components/model/ComponentWrapper'; import EditorModel from '../../../../../src/editor/model/Editor'; @@ -34,7 +34,7 @@ describe('conditional traits', () => { label: 'Value', name: 'value', value: { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, @@ -68,7 +68,7 @@ describe('conditional traits', () => { name: 'value', changeProp: true, value: { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, @@ -103,7 +103,7 @@ describe('conditional traits', () => { name: 'value', changeProp: true, value: { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, @@ -138,7 +138,7 @@ describe('conditional traits', () => { name: 'value', changeProp: true, value: { - type: ConditionalVariableType, + type: DataConditionType, condition: { left: 0, operator: NumberOperation.greaterThan, diff --git a/packages/core/test/specs/data_sources/model/conditional_variables/DataCondition.ts b/packages/core/test/specs/data_sources/model/conditional_variables/DataCondition.ts index 31c350ade..c90cb7250 100644 --- a/packages/core/test/specs/data_sources/model/conditional_variables/DataCondition.ts +++ b/packages/core/test/specs/data_sources/model/conditional_variables/DataCondition.ts @@ -1,15 +1,14 @@ import { DataSourceManager } from '../../../../../src'; import { DataCondition, - ExpressionDefinition, - LogicGroupDefinition, + ExpressionProps, + LogicGroupProps, } from '../../../../../src/data_sources/model/conditional_variables/DataCondition'; import { GenericOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/GenericOperator'; import { LogicalOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/LogicalOperator'; import { NumberOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/NumberOperator'; import { StringOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/StringOperations'; import { DataVariableType } from '../../../../../src/data_sources/model/DataVariable'; -import { DataSourceProps } from '../../../../../src/data_sources/types'; import Editor from '../../../../../src/editor/model/Editor'; import EditorModel from '../../../../../src/editor/model/Editor'; @@ -52,14 +51,14 @@ describe('DataCondition', () => { describe('Operator Tests', () => { test('should evaluate using GenericOperation operators', () => { - const condition: ExpressionDefinition = { left: 5, operator: GenericOperation.equals, right: 5 }; + const condition: ExpressionProps = { left: 5, operator: GenericOperation.equals, right: 5 }; const dataCondition = new DataCondition(condition, 'Equal', 'Not Equal', { em }); expect(dataCondition.getDataValue()).toBe('Equal'); }); test('equals (false)', () => { - const condition: ExpressionDefinition = { + const condition: ExpressionProps = { left: 'hello', operator: GenericOperation.equals, right: 'world', @@ -69,21 +68,21 @@ describe('DataCondition', () => { }); test('should evaluate using StringOperation operators', () => { - const condition: ExpressionDefinition = { left: 'apple', operator: StringOperation.contains, right: 'app' }; + const condition: ExpressionProps = { left: 'apple', operator: StringOperation.contains, right: 'app' }; const dataCondition = new DataCondition(condition, 'Contains', "Doesn't contain", { em }); expect(dataCondition.getDataValue()).toBe('Contains'); }); test('should evaluate using NumberOperation operators', () => { - const condition: ExpressionDefinition = { left: 10, operator: NumberOperation.lessThan, right: 15 }; + const condition: ExpressionProps = { left: 10, operator: NumberOperation.lessThan, right: 15 }; const dataCondition = new DataCondition(condition, 'Valid', 'Invalid', { em }); expect(dataCondition.getDataValue()).toBe('Valid'); }); test('should evaluate using LogicalOperation operators', () => { - const logicGroup: LogicGroupDefinition = { + const logicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.and, statements: [ { left: true, operator: GenericOperation.equals, right: true }, @@ -103,7 +102,7 @@ describe('DataCondition', () => { }); test('should evaluate complex nested conditions', () => { - const nestedLogicGroup: LogicGroupDefinition = { + const nestedLogicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.or, statements: [ { @@ -124,7 +123,7 @@ describe('DataCondition', () => { describe('LogicalGroup Tests', () => { test('should correctly handle AND logical operator', () => { - const logicGroup: LogicGroupDefinition = { + const logicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.and, statements: [ { left: true, operator: GenericOperation.equals, right: true }, @@ -137,7 +136,7 @@ describe('DataCondition', () => { }); test('should correctly handle OR logical operator', () => { - const logicGroup: LogicGroupDefinition = { + const logicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.or, statements: [ { left: true, operator: GenericOperation.equals, right: false }, @@ -150,7 +149,7 @@ describe('DataCondition', () => { }); test('should correctly handle XOR logical operator', () => { - const logicGroup: LogicGroupDefinition = { + const logicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.xor, statements: [ { left: true, operator: GenericOperation.equals, right: true }, @@ -164,7 +163,7 @@ describe('DataCondition', () => { }); test('should handle nested logical groups', () => { - const logicGroup: LogicGroupDefinition = { + const logicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.and, statements: [ { left: true, operator: GenericOperation.equals, right: true }, @@ -183,7 +182,7 @@ describe('DataCondition', () => { }); test('should handle groups with false conditions', () => { - const logicGroup: LogicGroupDefinition = { + const logicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.and, statements: [ { left: true, operator: GenericOperation.equals, right: true }, @@ -199,7 +198,7 @@ describe('DataCondition', () => { describe('Conditions with dataVariables', () => { test('should return "Yes" when dataVariable matches expected value', () => { - const condition: ExpressionDefinition = { + const condition: ExpressionProps = { left: { type: DataVariableType, path: 'USER_STATUS_SOURCE.USER_1.status' }, operator: GenericOperation.equals, right: 'active', @@ -210,7 +209,7 @@ describe('DataCondition', () => { }); test('should return "No" when dataVariable does not match expected value', () => { - const condition: ExpressionDefinition = { + const condition: ExpressionProps = { left: { type: DataVariableType, path: 'USER_STATUS_SOURCE.USER_1.status' }, operator: GenericOperation.equals, right: 'inactive', @@ -222,7 +221,7 @@ describe('DataCondition', () => { // TODO: unskip after adding UndefinedOperator test.skip('should handle missing data variable gracefully', () => { - const condition: ExpressionDefinition = { + const condition: ExpressionProps = { left: { type: DataVariableType, path: 'USER_STATUS_SOURCE.not_a_user.status' }, operator: GenericOperation.isDefined, right: undefined, @@ -233,7 +232,7 @@ describe('DataCondition', () => { }); test('should correctly compare numeric values from dataVariables', () => { - const condition: ExpressionDefinition = { + const condition: ExpressionProps = { left: { type: DataVariableType, path: 'USER_STATUS_SOURCE.USER_1.age' }, operator: NumberOperation.greaterThan, right: 24, @@ -249,7 +248,7 @@ describe('DataCondition', () => { }; dsm.add(dataSource2); - const logicGroup: LogicGroupDefinition = { + const logicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.and, statements: [ { @@ -270,7 +269,7 @@ describe('DataCondition', () => { }); test('should handle nested logical conditions with data variables', () => { - const logicGroup: LogicGroupDefinition = { + const logicGroup: LogicGroupProps = { logicalOperator: LogicalOperation.or, statements: [ { diff --git a/packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollection.ts b/packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollection.ts index cdd8737f6..55c3dc296 100644 --- a/packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollection.ts +++ b/packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollection.ts @@ -1,8 +1,8 @@ import { Component, DataRecord, DataSource, DataSourceManager, Editor } from '../../../../../src'; import { DataVariableType } from '../../../../../src/data_sources/model/DataVariable'; import { - CollectionComponentType, - CollectionVariableType, + DataCollectionType, + DataCollectionVariableType, } from '../../../../../src/data_sources/model/data_collection/constants'; import { DataCollectionStateVariableType } from '../../../../../src/data_sources/model/data_collection/types'; import EditorModel from '../../../../../src/editor/model/Editor'; @@ -41,7 +41,7 @@ describe('Collection component', () => { test('Collection component should be undroppable', () => { const cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', @@ -61,7 +61,7 @@ describe('Collection component', () => { test('Collection items should be undraggable', () => { const cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', @@ -83,7 +83,7 @@ describe('Collection component', () => { test('Collection items should be symbols', () => { const cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', @@ -138,7 +138,7 @@ describe('Collection component', () => { beforeEach(() => { cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', @@ -146,7 +146,7 @@ describe('Collection component', () => { { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -154,20 +154,20 @@ describe('Collection component', () => { }, { tagName: 'span', - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: 'currentItem', collectionId: 'my_collection', path: 'firstName', }, ], name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', }, custom_property: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -280,7 +280,7 @@ describe('Collection component', () => { test('Updating the value to a different collection variable', async () => { firstChild.set('name', { // @ts-ignore - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'age', @@ -299,7 +299,7 @@ describe('Collection component', () => { firstGrandchild.set('name', { // @ts-ignore - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'age', @@ -354,7 +354,7 @@ describe('Collection component', () => { beforeEach(() => { cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', @@ -363,7 +363,7 @@ describe('Collection component', () => { type: 'default', attributes: { name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -373,7 +373,7 @@ describe('Collection component', () => { ], attributes: { name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -446,7 +446,7 @@ describe('Collection component', () => { firstChild.setAttributes({ name: { // @ts-ignore - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'age', @@ -471,7 +471,7 @@ describe('Collection component', () => { firstGrandchild.setAttributes({ name: { // @ts-ignore - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'age', @@ -533,7 +533,7 @@ describe('Collection component', () => { test('Traits', () => { const cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', @@ -541,7 +541,7 @@ describe('Collection component', () => { { name: 'attribute_trait', value: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -551,7 +551,7 @@ describe('Collection component', () => { name: 'property_trait', changeProp: true, value: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -599,20 +599,20 @@ describe('Collection component', () => { const cmpDefinition = { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', }, custom_prop: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentIndex, collectionId: 'my_collection', path: 'user', }, attributes: { name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -622,7 +622,7 @@ describe('Collection component', () => { { name: 'attribute_trait', value: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -632,7 +632,7 @@ describe('Collection component', () => { name: 'property_trait', changeProp: true, value: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -642,7 +642,7 @@ describe('Collection component', () => { }; const collectionComponentDefinition = { - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { ...cmpDefinition, @@ -670,7 +670,7 @@ describe('Collection component', () => { const newChildDefinition = { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentIndex, collectionId: 'my_collection', path: 'user', @@ -692,7 +692,7 @@ describe('Collection component', () => { const newChildDefinition = { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentIndex, collectionId: 'my_collection', path: 'user', @@ -717,12 +717,12 @@ describe('Collection component', () => { attributes: { attribute_trait: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, }, name: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, @@ -732,32 +732,32 @@ describe('Collection component', () => { attributes: { attribute_trait: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, name: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, }, name: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, custom_prop: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: 'currentIndex', }, property_trait: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, @@ -767,32 +767,32 @@ describe('Collection component', () => { attributes: { attribute_trait: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, name: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, }, name: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, custom_prop: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: 'currentIndex', }, property_trait: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, @@ -801,19 +801,19 @@ describe('Collection component', () => { ], name: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, custom_prop: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: 'currentIndex', }, property_trait: { path: 'user', - type: CollectionVariableType, + type: DataCollectionVariableType, collectionId: 'my_collection', variableType: DataCollectionStateVariableType.currentItem, }, @@ -829,7 +829,7 @@ describe('Collection component', () => { startIndex: 0, }, }, - type: 'collection-component', + type: DataCollectionType, }, ], docEl: { @@ -895,12 +895,12 @@ describe('Collection component', () => { describe('Configuration options', () => { test('Collection with start and end indexes', () => { const cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -943,18 +943,18 @@ describe('Collection component', () => { stateVariableTests.forEach(({ variableType, expectedValues }) => { test(`Variable type: ${variableType}`, () => { const cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: variableType, collectionId: 'my_collection', }, attributes: { custom_attribute: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: variableType, collectionId: 'my_collection', }, @@ -963,7 +963,7 @@ describe('Collection component', () => { { name: 'attribute_trait', value: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: variableType, collectionId: 'my_collection', }, @@ -972,7 +972,7 @@ describe('Collection component', () => { name: 'property_trait', changeProp: true, value: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: variableType, collectionId: 'my_collection', }, diff --git a/packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollectionVariable.ts b/packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollectionVariable.ts index d6045cd93..a66c0136c 100644 --- a/packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollectionVariable.ts +++ b/packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollectionVariable.ts @@ -1,8 +1,8 @@ import { Component, DataRecord, DataSource, DataSourceManager, Editor } from '../../../../../src'; import { DataVariableType } from '../../../../../src/data_sources/model/DataVariable'; import { - CollectionComponentType, - CollectionVariableType, + DataCollectionType, + DataCollectionVariableType, } from '../../../../../src/data_sources/model/data_collection/constants'; import { DataCollectionStateVariableType } from '../../../../../src/data_sources/model/data_collection/types'; import EditorModel from '../../../../../src/editor/model/Editor'; @@ -40,13 +40,13 @@ describe('Collection variable components', () => { test('Gets the correct static value', async () => { const cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', components: [ { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -74,12 +74,12 @@ describe('Collection variable components', () => { test('Watches collection variable changes', async () => { const cmp = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', components: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -110,14 +110,14 @@ describe('Collection variable components', () => { beforeEach(() => { const variableCmpDef = { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', }; const collectionComponentDefinition = { - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', @@ -148,7 +148,7 @@ describe('Collection variable components', () => { const firstChild = cmp.components().at(0); const newChildDefinition = { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentIndex, collectionId: 'my_collection', path: 'user', @@ -167,7 +167,7 @@ describe('Collection variable components', () => { const firstChild = cmp.components().at(0); const newChildDefinition = { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentIndex, collectionId: 'my_collection', path: 'user', @@ -192,7 +192,7 @@ describe('Collection variable components', () => { type: 'default', components: [ { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'my_collection', path: 'user', @@ -209,7 +209,7 @@ describe('Collection variable components', () => { startIndex: 0, }, }, - type: 'collection-component', + type: DataCollectionType, }, ], docEl: { diff --git a/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollection.ts.snap b/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollection.ts.snap index 2e851b715..79be166cd 100644 --- a/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollection.ts.snap +++ b/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollection.ts.snap @@ -17,13 +17,13 @@ exports[`Collection component Serialization Saving: Collection with grandchildre "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, @@ -33,13 +33,13 @@ exports[`Collection component Serialization Saving: Collection with grandchildre "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, @@ -48,7 +48,7 @@ exports[`Collection component Serialization Saving: Collection with grandchildre "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "type": "default", @@ -57,19 +57,19 @@ exports[`Collection component Serialization Saving: Collection with grandchildre "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", @@ -79,32 +79,32 @@ exports[`Collection component Serialization Saving: Collection with grandchildre "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", @@ -113,25 +113,25 @@ exports[`Collection component Serialization Saving: Collection with grandchildre "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", } `; @@ -152,13 +152,13 @@ exports[`Collection component Serialization Saving: Collection with no grandchil "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, @@ -168,32 +168,32 @@ exports[`Collection component Serialization Saving: Collection with no grandchil "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", @@ -203,32 +203,32 @@ exports[`Collection component Serialization Saving: Collection with no grandchil "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", @@ -237,25 +237,25 @@ exports[`Collection component Serialization Saving: Collection with no grandchil "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", } `; @@ -276,13 +276,13 @@ exports[`Collection component Serialization Serializion with Collection Variable "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, @@ -292,13 +292,13 @@ exports[`Collection component Serialization Serializion with Collection Variable "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, @@ -307,7 +307,7 @@ exports[`Collection component Serialization Serializion with Collection Variable "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "type": "default", @@ -316,19 +316,19 @@ exports[`Collection component Serialization Serializion with Collection Variable "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", @@ -338,32 +338,32 @@ exports[`Collection component Serialization Serializion with Collection Variable "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", @@ -372,25 +372,25 @@ exports[`Collection component Serialization Serializion with Collection Variable "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", } `; @@ -411,13 +411,13 @@ exports[`Collection component Serialization Serializion with Collection Variable "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, @@ -427,32 +427,32 @@ exports[`Collection component Serialization Serializion with Collection Variable "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", @@ -462,32 +462,32 @@ exports[`Collection component Serialization Serializion with Collection Variable "attribute_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, }, "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", @@ -496,24 +496,24 @@ exports[`Collection component Serialization Serializion with Collection Variable "custom_prop": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, "name": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "property_trait": { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", } `; diff --git a/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollectionVariable.ts.snap b/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollectionVariable.ts.snap index e22d545fc..8edb6a4d2 100644 --- a/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollectionVariable.ts.snap +++ b/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollectionVariable.ts.snap @@ -20,14 +20,14 @@ exports[`Collection variable components Serialization Saving: Collection with co { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, ], "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", } `; @@ -50,7 +50,7 @@ exports[`Collection variable components Serialization Saving: Collection with co { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, ], @@ -59,14 +59,14 @@ exports[`Collection variable components Serialization Saving: Collection with co { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, ], "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", } `; @@ -90,14 +90,14 @@ exports[`Collection variable components Serialization Serializion to JSON: Colle { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, ], "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", } `; @@ -120,7 +120,7 @@ exports[`Collection variable components Serialization Serializion to JSON: Colle { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentIndex", }, ], @@ -129,13 +129,13 @@ exports[`Collection variable components Serialization Serializion to JSON: Colle { "collectionId": "my_collection", "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, ], "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", } `; diff --git a/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/nestedComponentDataCollections.ts.snap b/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/nestedComponentDataCollections.ts.snap index 36dae289f..92ce3f6c8 100644 --- a/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/nestedComponentDataCollections.ts.snap +++ b/packages/core/test/specs/data_sources/model/data_collection/__snapshots__/nestedComponentDataCollections.ts.snap @@ -22,15 +22,15 @@ exports[`Collection component Nested collections are correctly serialized 1`] = "componentDef": { "name": { "path": "user", - "type": "parent-collection-variable", + "type": "data-collection-variable", "variableType": "currentItem", }, "type": "default", }, }, - "type": "collection-component", + "type": "data-collection", }, }, - "type": "collection-component", + "type": "data-collection", } `; diff --git a/packages/core/test/specs/data_sources/model/data_collection/nestedComponentDataCollections.ts b/packages/core/test/specs/data_sources/model/data_collection/nestedComponentDataCollections.ts index d5536355a..e7b3a48f2 100644 --- a/packages/core/test/specs/data_sources/model/data_collection/nestedComponentDataCollections.ts +++ b/packages/core/test/specs/data_sources/model/data_collection/nestedComponentDataCollections.ts @@ -1,8 +1,8 @@ import { Component, DataRecord, DataSource, DataSourceManager, Editor } from '../../../../../src'; import { DataVariableType } from '../../../../../src/data_sources/model/DataVariable'; import { - CollectionComponentType, - CollectionVariableType, + DataCollectionType, + DataCollectionVariableType, } from '../../../../../src/data_sources/model/data_collection/constants'; import { DataCollectionStateVariableType } from '../../../../../src/data_sources/model/data_collection/types'; import EditorModel from '../../../../../src/editor/model/Editor'; @@ -52,15 +52,15 @@ describe('Collection component', () => { test('Nested collections bind to correct data sources', () => { const parentCollection = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'nested_collection', path: 'user', @@ -95,15 +95,15 @@ describe('Collection component', () => { test('Updates in parent collection propagate to nested collections', () => { const parentCollection = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'nested_collection', path: 'user', @@ -139,15 +139,15 @@ describe('Collection component', () => { test('Nested collections are correctly serialized', () => { const parentCollection = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, path: 'user', }, @@ -177,15 +177,15 @@ describe('Collection component', () => { test('Nested collections respect startIndex and endIndex', () => { const parentCollection = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'nested_collection', path: 'user', @@ -218,15 +218,15 @@ describe('Collection component', () => { test('Nested collection gets and watches value from the parent collection', () => { const parentCollection = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'parent_collection', path: 'user', @@ -264,15 +264,15 @@ describe('Collection component', () => { test('Nested collection switches to using its own collection variable', () => { const parentCollection = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, path: 'user', collectionId: 'parent_collection', @@ -303,7 +303,7 @@ describe('Collection component', () => { // Replace the collection variable with one from the inner collection firstChild.set('name', { // @ts-ignore - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, path: 'user', collectionId: 'nested_collection', @@ -319,12 +319,12 @@ describe('Collection component', () => { beforeEach(() => { // Initialize the parent and nested collections parentCollection = wrapper.components({ - type: CollectionComponentType, + type: DataCollectionType, collectionDef: { componentDef: { - type: CollectionComponentType, + type: DataCollectionType, name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'parent_collection', path: 'user', @@ -333,7 +333,7 @@ describe('Collection component', () => { componentDef: { type: 'default', name: { - type: CollectionVariableType, + type: DataCollectionVariableType, variableType: DataCollectionStateVariableType.currentItem, collectionId: 'nested_collection', path: 'user',