Browse Source

Rename collection to DataCollection

collection-component
mohamedsalem401 2 years ago
parent
commit
68707db634
  1. 4
      packages/core/src/data_sources/model/DataVariableListenerManager.ts
  2. 4
      packages/core/src/data_sources/model/collection_component/CollectionComponentView.ts
  3. 48
      packages/core/src/data_sources/model/collection_component/types.ts
  4. 20
      packages/core/src/data_sources/model/data_collection/CollectionVariable.ts
  5. 33
      packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts
  6. 4
      packages/core/src/data_sources/model/data_collection/ComponentDataCollectionView.ts
  7. 0
      packages/core/src/data_sources/model/data_collection/constants.ts
  8. 53
      packages/core/src/data_sources/model/data_collection/types.ts
  9. 12
      packages/core/src/data_sources/model/utils.ts
  10. 6
      packages/core/src/data_sources/types.ts
  11. 10
      packages/core/src/dom_components/index.ts
  12. 8
      packages/core/src/dom_components/model/Component.ts
  13. 8
      packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts
  14. 10
      packages/core/src/dom_components/model/DynamicValueWatcher.ts
  15. 2
      packages/core/src/dom_components/model/SymbolUtils.ts
  16. 2
      packages/core/src/dom_components/model/types.ts
  17. 78
      packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollection.ts
  18. 0
      packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollection.ts.snap
  19. 9
      packages/core/test/specs/dom_components/model/ComponentTypes.ts

4
packages/core/src/data_sources/model/DataVariableListenerManager.ts

@ -6,8 +6,8 @@ import DataVariable, { DataVariableType } from './DataVariable';
import { DynamicValue } from '../types';
import { DataCondition, ConditionalVariableType } from './conditional_variables/DataCondition';
import ComponentDataVariable from './ComponentDataVariable';
import { CollectionVariableType } from './collection_component/constants';
import CollectionVariable from './collection_component/CollectionVariable';
import { CollectionVariableType } from './data_collection/constants';
import CollectionVariable from './data_collection/CollectionVariable';
export interface DynamicVariableListenerManagerOptions {
em: EditorModel;

4
packages/core/src/data_sources/model/collection_component/CollectionComponentView.ts

@ -1,4 +0,0 @@
import ComponentView from '../../../dom_components/view/ComponentView';
import CollectionComponent from './CollectionComponent';
export default class CollectionComponentView extends ComponentView<CollectionComponent> {}

48
packages/core/src/data_sources/model/collection_component/types.ts

@ -1,48 +0,0 @@
import { CollectionComponentType, keyCollectionDefinition } from './constants';
import { ComponentDefinition } from '../../../dom_components/model/types';
import { CollectionVariableDefinition } from '../../../../test/specs/dom_components/model/ComponentTypes';
import { DataVariableDefinition } from '../DataVariable';
export type CollectionDataSource = any[] | DataVariableDefinition | CollectionVariableDefinition;
export interface CollectionConfig {
startIndex?: number;
endIndex?: number;
dataSource: CollectionDataSource;
}
export enum CollectionStateVariableType {
currentIndex = 'currentIndex',
startIndex = 'startIndex',
currentItem = 'currentItem',
endIndex = 'endIndex',
collectionName = 'collectionName',
totalItems = 'totalItems',
remainingItems = 'remainingItems',
}
export interface CollectionState {
[CollectionStateVariableType.currentIndex]: number;
[CollectionStateVariableType.startIndex]: number;
[CollectionStateVariableType.currentItem]: any;
[CollectionStateVariableType.endIndex]: number;
[CollectionStateVariableType.collectionName]?: string;
[CollectionStateVariableType.totalItems]: number;
[CollectionStateVariableType.remainingItems]: number;
}
export interface CollectionsStateMap {
[key: string]: CollectionState;
}
export interface CollectionComponentDefinition extends ComponentDefinition {
[keyCollectionDefinition]: CollectionDefinition;
}
export interface CollectionDefinition {
type: typeof CollectionComponentType;
collectionName?: string;
config: CollectionConfig;
block: ComponentDefinition;
}

20
packages/core/src/data_sources/model/collection_component/CollectionVariable.ts → packages/core/src/data_sources/model/data_collection/CollectionVariable.ts

@ -1,20 +1,20 @@
import { CollectionVariableDefinition } from '../../../../test/specs/dom_components/model/ComponentTypes';
import { DataCollectionVariableDefinition } from './types';
import { Model } from '../../../common';
import EditorModel from '../../../editor/model/Editor';
import DataVariable, { DataVariableType } from '../DataVariable';
import { keyInnerCollectionState } from './constants';
import { CollectionState, CollectionsStateMap } from './types';
import { DataCollectionState, DataCollectionStateMap } from './types';
export default class CollectionVariable extends Model<CollectionVariableDefinition> {
export default class CollectionVariable extends Model<DataCollectionVariableDefinition> {
em: EditorModel;
collectionsStateMap: CollectionsStateMap;
collectionsStateMap: DataCollectionStateMap;
dataVariable?: DataVariable;
constructor(
attrs: CollectionVariableDefinition,
attrs: DataCollectionVariableDefinition,
options: {
em: EditorModel;
collectionsStateMap: CollectionsStateMap;
collectionsStateMap: DataCollectionStateMap;
},
) {
super(attrs, options);
@ -39,7 +39,7 @@ export default class CollectionVariable extends Model<CollectionVariableDefiniti
private updateDataVariable() {
const resolvedValue = resolveCollectionVariable(
this.attributes as CollectionVariableDefinition,
this.attributes as DataCollectionVariableDefinition,
this.collectionsStateMap,
this.em,
);
@ -59,8 +59,8 @@ export default class CollectionVariable extends Model<CollectionVariableDefiniti
}
function resolveCollectionVariable(
collectionVariableDefinition: CollectionVariableDefinition,
collectionsStateMap: CollectionsStateMap,
collectionVariableDefinition: DataCollectionVariableDefinition,
collectionsStateMap: DataCollectionStateMap,
em: EditorModel,
) {
const { collectionName = keyInnerCollectionState, variableType, path } = collectionVariableDefinition;
@ -86,7 +86,7 @@ function resolveCollectionVariable(
}
function resolveCurrentItem(
collectionItem: CollectionState,
collectionItem: DataCollectionState,
path: string | undefined,
collectionName: string,
em: EditorModel,

33
packages/core/src/data_sources/model/collection_component/CollectionComponent.ts → packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts

@ -1,4 +1,4 @@
import DataVariable, { DataVariableType } from './../DataVariable';
import DataVariable, { DataVariableType } from '../DataVariable';
import { isArray } from 'underscore';
import Component from '../../../dom_components/model/Component';
import { ComponentOptions } from '../../../dom_components/model/types';
@ -7,7 +7,12 @@ import DataSource from '../DataSource';
import { ObjectAny } from '../../../common';
import EditorModel from '../../../editor/model/Editor';
import { keyCollectionsStateMap } from '../../../dom_components/model/Component';
import { CollectionComponentDefinition, CollectionDefinition, CollectionState, CollectionsStateMap } from './types';
import {
ComponentDataCollectionDefinition,
DataCollectionDefinition,
DataCollectionState,
DataCollectionStateMap,
} from './types';
import {
keyCollectionDefinition,
keyInnerCollectionState,
@ -16,11 +21,11 @@ import {
} from './constants';
import DynamicVariableListenerManager from '../DataVariableListenerManager';
export default class CollectionComponent extends Component {
constructor(props: CollectionComponentDefinition, opt: ComponentOptions) {
export default class ComponentDataCollection extends Component {
constructor(props: ComponentDataCollectionDefinition, opt: ComponentOptions) {
const em = opt.em;
// @ts-ignore
const cmp: CollectionComponent = super(
const cmp: ComponentDataCollection = super(
// @ts-ignore
{
...props,
@ -37,7 +42,7 @@ export default class CollectionComponent extends Component {
return cmp;
}
const parentCollectionStateMap = (props[keyCollectionsStateMap] || {}) as CollectionsStateMap;
const parentCollectionStateMap = (props[keyCollectionsStateMap] || {}) as DataCollectionStateMap;
const components: Component[] = getCollectionItems(em, collectionDefinition, parentCollectionStateMap, opt);
@ -59,7 +64,7 @@ export default class CollectionComponent extends Component {
}
toJSON(opts?: ObjectAny) {
const json = super.toJSON(opts) as CollectionComponentDefinition;
const json = super.toJSON(opts) as ComponentDataCollectionDefinition;
const firstChild = this.getBlockDefinition();
json[keyCollectionDefinition].block = firstChild;
@ -78,8 +83,8 @@ export default class CollectionComponent extends Component {
private watchDataSource(
em: EditorModel,
collectionDefinition: CollectionDefinition,
parentCollectionStateMap: CollectionsStateMap,
collectionDefinition: DataCollectionDefinition,
parentCollectionStateMap: DataCollectionStateMap,
opt: ComponentOptions,
) {
const path = this.get(keyCollectionDefinition).config.dataSource?.path;
@ -103,8 +108,8 @@ export default class CollectionComponent extends Component {
function getCollectionItems(
em: EditorModel,
collectionDefinition: CollectionDefinition,
parentCollectionStateMap: CollectionsStateMap,
collectionDefinition: DataCollectionDefinition,
parentCollectionStateMap: DataCollectionStateMap,
opt: ComponentOptions,
) {
const { collectionName, block, config } = collectionDefinition;
@ -128,7 +133,7 @@ function getCollectionItems(
let blockSymbolMain: Component;
for (let index = startIndex; index <= endIndex; index++) {
const item = items[index];
const collectionState: CollectionState = {
const collectionState: DataCollectionState = {
collectionName,
currentIndex: index,
currentItem: item,
@ -138,7 +143,7 @@ function getCollectionItems(
remainingItems: totalItems - (index + 1),
};
const collectionsStateMap: CollectionsStateMap = {
const collectionsStateMap: DataCollectionStateMap = {
...parentCollectionStateMap,
...(collectionName && { [collectionName]: collectionState }),
[keyInnerCollectionState]: collectionState,
@ -170,7 +175,7 @@ function getCollectionItems(
return components;
}
function setCollectionStateMap(collectionsStateMap: CollectionsStateMap) {
function setCollectionStateMap(collectionsStateMap: DataCollectionStateMap) {
return (cmp: Component) => {
cmp.set(keyIsCollectionItem, true);
cmp.set(keyCollectionsStateMap, collectionsStateMap);

4
packages/core/src/data_sources/model/data_collection/ComponentDataCollectionView.ts

@ -0,0 +1,4 @@
import ComponentView from '../../../dom_components/view/ComponentView';
import ComponentDataCollection from './ComponentDataCollection';
export default class ComponentDataCollectionView extends ComponentView<ComponentDataCollection> {}

0
packages/core/src/data_sources/model/collection_component/constants.ts → packages/core/src/data_sources/model/data_collection/constants.ts

53
packages/core/src/data_sources/model/data_collection/types.ts

@ -0,0 +1,53 @@
import { CollectionComponentType, CollectionVariableType, keyCollectionDefinition } from './constants';
import { ComponentDefinition } from '../../../dom_components/model/types';
import { DataVariableDefinition } from '../DataVariable';
export type DataCollectionDataSource = any[] | DataVariableDefinition | DataCollectionVariableDefinition;
export interface DataCollectionConfig {
startIndex?: number;
endIndex?: number;
dataSource: DataCollectionDataSource;
}
export enum DataCollectionStateVariableType {
currentIndex = 'currentIndex',
startIndex = 'startIndex',
currentItem = 'currentItem',
endIndex = 'endIndex',
collectionName = 'collectionName',
totalItems = 'totalItems',
remainingItems = 'remainingItems',
}
export interface DataCollectionState {
[DataCollectionStateVariableType.currentIndex]: number;
[DataCollectionStateVariableType.startIndex]: number;
[DataCollectionStateVariableType.currentItem]: any;
[DataCollectionStateVariableType.endIndex]: number;
[DataCollectionStateVariableType.collectionName]?: string;
[DataCollectionStateVariableType.totalItems]: number;
[DataCollectionStateVariableType.remainingItems]: number;
}
export interface DataCollectionStateMap {
[key: string]: DataCollectionState;
}
export interface ComponentDataCollectionDefinition extends ComponentDefinition {
[keyCollectionDefinition]: DataCollectionDefinition;
}
export interface DataCollectionDefinition {
type: typeof CollectionComponentType;
collectionName?: string;
config: DataCollectionConfig;
block: ComponentDefinition;
}
export type DataCollectionVariableDefinition = {
type: typeof CollectionVariableType;
variableType: DataCollectionStateVariableType;
collectionName?: string;
path?: string;
};

12
packages/core/src/data_sources/model/utils.ts

@ -1,9 +1,9 @@
import EditorModel from '../../editor/model/Editor';
import { DynamicValue, DynamicValueDefinition } from '../types';
import { CollectionsStateMap } from './collection_component/types';
import CollectionVariable from './collection_component/CollectionVariable';
import { CollectionVariableDefinition } from '../../../test/specs/dom_components/model/ComponentTypes';
import { CollectionVariableType } from './collection_component/constants';
import { DataCollectionStateMap } from './data_collection/types';
import CollectionVariable from './data_collection/CollectionVariable';
import { DataCollectionVariableDefinition } from './data_collection/types';
import { CollectionVariableType } from './data_collection/constants';
import { ConditionalVariableType, DataCondition } from './conditional_variables/DataCondition';
import DataVariable, { DataVariableType } from './DataVariable';
@ -34,7 +34,7 @@ export function getDynamicValueInstance(
valueDefinition: DynamicValueDefinition,
options: {
em: EditorModel;
collectionsStateMap?: CollectionsStateMap;
collectionsStateMap?: DataCollectionStateMap;
},
): DynamicValue {
const { em } = options;
@ -66,7 +66,7 @@ export function evaluateDynamicValueDefinition(
valueDefinition: DynamicValueDefinition,
options: {
em: EditorModel;
collectionsStateMap?: CollectionsStateMap;
collectionsStateMap?: DataCollectionStateMap;
},
) {
const dynamicVariable = getDynamicValueInstance(valueDefinition, options);

6
packages/core/src/data_sources/types.ts

@ -1,6 +1,6 @@
import { ObjectAny } from '../common';
import CollectionVariable from './model/collection_component/CollectionVariable';
import { CollectionVariableDefinition } from '../../test/specs/dom_components/model/ComponentTypes';
import CollectionVariable from './model/data_collection/CollectionVariable';
import { DataCollectionVariableDefinition } from './model/data_collection/types';
import ComponentDataVariable from './model/ComponentDataVariable';
import DataRecord from './model/DataRecord';
import DataRecords from './model/DataRecords';
@ -11,7 +11,7 @@ export type DynamicValue = DataVariable | ComponentDataVariable | DataCondition
export type DynamicValueDefinition =
| DataVariableDefinition
| ConditionalVariableDefinition
| CollectionVariableDefinition;
| DataCollectionVariableDefinition;
export interface DataRecordProps extends ObjectAny {
/**
* Record id.

10
packages/core/src/dom_components/index.ts

@ -128,9 +128,9 @@ 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 CollectionComponent from '../data_sources/model/collection_component/CollectionComponent';
import CollectionComponentView from '../data_sources/model/collection_component/CollectionComponentView';
import { CollectionComponentType } from '../data_sources/model/collection_component/constants';
import ComponentDataCollection from '../data_sources/model/data_collection/ComponentDataCollection';
import ComponentDataCollectionView from '../data_sources/model/data_collection/ComponentDataCollectionView';
import { CollectionComponentType } from '../data_sources/model/data_collection/constants';
export type ComponentEvent =
| 'component:create'
@ -198,8 +198,8 @@ export default class ComponentManager extends ItemManagerModule<DomComponentsCon
componentTypes: ComponentStackItem[] = [
{
id: CollectionComponentType,
model: CollectionComponent,
view: CollectionComponentView,
model: ComponentDataCollection,
view: ComponentDataCollectionView,
},
{
id: ConditionalVariableType,

8
packages/core/src/dom_components/model/Component.ts

@ -1,4 +1,4 @@
import { CollectionsStateMap } from '../../data_sources/model/collection_component/types';
import { DataCollectionStateMap } from '../../data_sources/model/data_collection/types';
import {
isUndefined,
isFunction,
@ -55,7 +55,7 @@ import {
} from './SymbolUtils';
import { ComponentDynamicValueWatcher } from './ComponentDynamicValueWatcher';
import { DynamicWatchersOptions } from './DynamicValueWatcher';
import { keyIsCollectionItem } from '../../data_sources/model/collection_component/constants';
import { keyIsCollectionItem } from '../../data_sources/model/data_collection/constants';
export interface IComponent extends ExtractMethods<Component> {}
export interface SetAttrOptions extends SetOptions, UpdateStyleOptions, DynamicWatchersOptions {}
@ -349,7 +349,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
}
}
getCollectionStateMap(): CollectionsStateMap {
getCollectionStateMap(): DataCollectionStateMap {
const collectionStateMapProp = this.get(keyCollectionsStateMap);
if (collectionStateMapProp) {
return collectionStateMapProp;
@ -2012,7 +2012,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
selector && selector.set({ name: id, label: id });
}
private handleCollectionsMapStateChange(m: any, v: CollectionsStateMap, opts = {}) {
private handleCollectionsMapStateChange(m: any, v: DataCollectionStateMap, opts = {}) {
this.componentDVListener.updateCollectionStateMap(v);
this.components()?.forEach((child) => {
child.set?.(keyCollectionsStateMap, v);

8
packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts

@ -1,6 +1,6 @@
import { Model, ObjectAny } from '../../common';
import { CollectionVariableType, keyIsCollectionItem } from '../../data_sources/model/collection_component/constants';
import { CollectionsStateMap } from '../../data_sources/model/collection_component/types';
import { CollectionVariableType, 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, { keyCollectionsStateMap } from './Component';
import { DynamicWatchersOptions } from './DynamicValueWatcher';
@ -15,7 +15,7 @@ export class ComponentDynamicValueWatcher extends Model<Component> {
private component: Component | undefined,
options: {
em: EditorModel;
collectionsStateMap?: CollectionsStateMap;
collectionsStateMap?: DataCollectionStateMap;
},
) {
super(component, options);
@ -44,7 +44,7 @@ export class ComponentDynamicValueWatcher extends Model<Component> {
this.updateSymbolOverride();
}
updateCollectionStateMap(collectionsStateMap: CollectionsStateMap) {
updateCollectionStateMap(collectionsStateMap: DataCollectionStateMap) {
this.propertyWatcher.updateCollectionStateMap(collectionsStateMap);
this.attributeWatcher.updateCollectionStateMap(collectionsStateMap);
}

10
packages/core/src/dom_components/model/DynamicValueWatcher.ts

@ -1,11 +1,11 @@
import { DynamicValueDefinition } from './../../data_sources/types';
import { CollectionsStateMap } from '../../data_sources/model/collection_component/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/collection_component/constants';
import { CollectionVariableType } from '../../data_sources/model/data_collection/constants';
import { ModelDestroyOptions } from 'backbone';
export interface DynamicWatchersOptions {
@ -18,13 +18,13 @@ type UpdateFn = (component: Component | undefined, key: string, value: any) => v
export class DynamicValueWatcher extends Model<{ component: Component | undefined; updateFn: UpdateFn }> {
private dynamicVariableListeners: { [key: string]: DynamicVariableListenerManager } = {};
private em: EditorModel;
private collectionsStateMap?: CollectionsStateMap;
private collectionsStateMap?: DataCollectionStateMap;
constructor(
private component: Component | undefined,
private updateFn: UpdateFn,
options: {
em: EditorModel;
collectionsStateMap?: CollectionsStateMap;
collectionsStateMap?: DataCollectionStateMap;
},
) {
super({ component, updateFn }, options);
@ -36,7 +36,7 @@ export class DynamicValueWatcher extends Model<{ component: Component | undefine
this.component = component;
}
updateCollectionStateMap(collectionsStateMap: CollectionsStateMap) {
updateCollectionStateMap(collectionsStateMap: DataCollectionStateMap) {
this.collectionsStateMap = collectionsStateMap;
const collectionVariablesKeys = this.getDynamicValuesOfType(CollectionVariableType);

2
packages/core/src/dom_components/model/SymbolUtils.ts

@ -3,7 +3,7 @@ import Component, { keySymbol, keySymbolOvrd, keySymbols } from './Component';
import { SymbolToUpOptions } from './types';
import { isEmptyObj } from '../../utils/mixins';
import Components from './Components';
import { CollectionVariableType } from '../../data_sources/model/collection_component/constants';
import { CollectionVariableType } from '../../data_sources/model/data_collection/constants';
export const isSymbolMain = (cmp: Component) => isArray(cmp.get(keySymbols));

2
packages/core/src/dom_components/model/types.ts

@ -12,7 +12,7 @@ import Component from './Component';
import Components from './Components';
import { ToolbarButtonProps } from './ToolbarButton';
import { ParseNodeOptions } from '../../parser/config/config';
import { CollectionsStateMap } from '../../data_sources/model/collection_component/types';
import { DataCollectionStateMap } from '../../data_sources/model/data_collection/types';
export type DragMode = 'translate' | 'absolute' | '';

78
packages/core/test/specs/data_sources/model/collection_component/CollectionComponent.ts → packages/core/test/specs/data_sources/model/data_collection/ComponentDataCollection.ts

@ -3,8 +3,8 @@ import { DataVariableType } from '../../../../../src/data_sources/model/DataVari
import {
CollectionComponentType,
CollectionVariableType,
} from '../../../../../src/data_sources/model/collection_component/constants';
import { CollectionStateVariableType } from '../../../../../src/data_sources/model/collection_component/types';
} 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';
import { filterObjectForSnapshot, setupTestEditor } from '../../../../common';
import { getSymbolMain } from '../../../../../src/dom_components/model/SymbolUtils';
@ -130,19 +130,19 @@ describe('Collection component', () => {
type: 'default',
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
],
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
custom_property: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -205,7 +205,7 @@ describe('Collection component', () => {
firstChild.set('name', {
// @ts-ignore
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'age',
});
expect(firstChild.get('name')).toBe('12');
@ -223,7 +223,7 @@ describe('Collection component', () => {
firstGrandchild.set('name', {
// @ts-ignore
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'age',
});
expect(firstGrandchild.get('name')).toBe('new_value_12');
@ -286,7 +286,7 @@ describe('Collection component', () => {
attributes: {
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -295,7 +295,7 @@ describe('Collection component', () => {
attributes: {
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -356,7 +356,7 @@ describe('Collection component', () => {
name: {
// @ts-ignore
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'age',
},
});
@ -376,7 +376,7 @@ describe('Collection component', () => {
name: {
// @ts-ignore
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'age',
},
});
@ -435,7 +435,7 @@ describe('Collection component', () => {
name: 'attribute_trait',
value: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -444,7 +444,7 @@ describe('Collection component', () => {
changeProp: true,
value: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -486,18 +486,18 @@ describe('Collection component', () => {
type: 'default',
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
custom_prop: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentIndex,
variableType: DataCollectionStateVariableType.currentIndex,
path: 'user',
},
attributes: {
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -506,7 +506,7 @@ describe('Collection component', () => {
name: 'attribute_trait',
value: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -515,7 +515,7 @@ describe('Collection component', () => {
changeProp: true,
value: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -552,7 +552,7 @@ describe('Collection component', () => {
type: 'default',
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentIndex,
variableType: DataCollectionStateVariableType.currentIndex,
path: 'user',
},
};
@ -573,7 +573,7 @@ describe('Collection component', () => {
type: 'default',
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentIndex,
variableType: DataCollectionStateVariableType.currentIndex,
path: 'user',
},
};
@ -597,12 +597,12 @@ describe('Collection component', () => {
attribute_trait: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
name: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
},
components: [
@ -611,18 +611,18 @@ describe('Collection component', () => {
attribute_trait: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
name: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
},
name: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
custom_prop: {
path: 'user',
@ -632,7 +632,7 @@ describe('Collection component', () => {
property_trait: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
type: 'default',
},
@ -641,18 +641,18 @@ describe('Collection component', () => {
attribute_trait: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
name: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
},
name: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
custom_prop: {
path: 'user',
@ -662,7 +662,7 @@ describe('Collection component', () => {
property_trait: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
type: 'default',
},
@ -670,7 +670,7 @@ describe('Collection component', () => {
name: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
custom_prop: {
path: 'user',
@ -680,7 +680,7 @@ describe('Collection component', () => {
property_trait: {
path: 'user',
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
},
type: 'default',
},
@ -766,7 +766,7 @@ describe('Collection component', () => {
type: 'default',
name: {
type: CollectionVariableType,
variableType: CollectionStateVariableType.currentItem,
variableType: DataCollectionStateVariableType.currentItem,
path: 'user',
},
},
@ -792,15 +792,15 @@ describe('Collection component', () => {
describe('Diffirent Collection variable types', () => {
const stateVariableTests = [
{ variableType: CollectionStateVariableType.currentIndex, expectedValues: [0, 1, 2] },
{ variableType: CollectionStateVariableType.startIndex, expectedValues: [0, 0, 0] },
{ variableType: CollectionStateVariableType.endIndex, expectedValues: [2, 2, 2] },
{ variableType: DataCollectionStateVariableType.currentIndex, expectedValues: [0, 1, 2] },
{ variableType: DataCollectionStateVariableType.startIndex, expectedValues: [0, 0, 0] },
{ variableType: DataCollectionStateVariableType.endIndex, expectedValues: [2, 2, 2] },
{
variableType: CollectionStateVariableType.collectionName,
variableType: DataCollectionStateVariableType.collectionName,
expectedValues: ['my_collection', 'my_collection', 'my_collection'],
},
{ variableType: CollectionStateVariableType.totalItems, expectedValues: [3, 3, 3] },
{ variableType: CollectionStateVariableType.remainingItems, expectedValues: [2, 1, 0] },
{ variableType: DataCollectionStateVariableType.totalItems, expectedValues: [3, 3, 3] },
{ variableType: DataCollectionStateVariableType.remainingItems, expectedValues: [2, 1, 0] },
];
stateVariableTests.forEach(({ variableType, expectedValues }) => {

0
packages/core/test/specs/data_sources/model/collection_component/__snapshots__/CollectionComponent.ts.snap → packages/core/test/specs/data_sources/model/data_collection/__snapshots__/ComponentDataCollection.ts.snap

9
packages/core/test/specs/dom_components/model/ComponentTypes.ts

@ -1,5 +1,3 @@
import { CollectionVariableType } from '../../../../src/data_sources/model/collection_component/constants';
import { CollectionStateVariableType } from '../../../../src/data_sources/model/collection_component/types';
import Editor from '../../../../src/editor';
describe('Component Types', () => {
@ -98,10 +96,3 @@ describe('Component Types', () => {
expect(cmp.components().at(0).is('svg-in')).toBe(true);
});
});
export type CollectionVariableDefinition = {
type: typeof CollectionVariableType;
variableType: CollectionStateVariableType;
collectionName?: string;
path?: string;
};

Loading…
Cancel
Save