Skip to content

Commit

Permalink
feat(TM-source): add entity data binding provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sheilaXu committed Jun 29, 2023
1 parent c0595f6 commit d1c459d
Show file tree
Hide file tree
Showing 21 changed files with 1,044 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/scene-composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"convert-svg": "npx @svgr/cli --out-dir src/assets/auto-gen/icons/ --typescript --index-template tools/index-template.js -- src/assets/icons/",
"release": "run-s compile copy-assets",
"copy-assets": "copyfiles -e \"**/*.tsx\" -e \"**/*.ts\" -e \"**/*.snap\" -e \"**/*.js\" -e \"**/*.jsx\" -e \"**/*.json\" \"src/**/*\" dist/",
"lint": "eslint . --max-warnings=718",
"lint": "eslint . --max-warnings=714",
"fix": "eslint --fix .",
"test": "jest --config jest.config.ts --coverage --silent",
"test:dev": "jest --config jest.config.ts --coverage",
Expand Down Expand Up @@ -78,7 +78,6 @@
"@babel/preset-react": "^7.22.5",
"@babel/runtime": "^7.22.5",
"@formatjs/cli": "6.1.3",
"@iot-app-kit/source-iottwinmaker": "6.3.1",
"@react-spring/three": "^9.7.2",
"@storybook/addon-essentials": "^6.5.16",
"@storybook/addon-links": "^6.5.16",
Expand Down Expand Up @@ -137,6 +136,7 @@
"@formatjs/ts-transformer": "3.13.3",
"@iot-app-kit/core": "6.3.1",
"@iot-app-kit/related-table": "6.3.1",
"@iot-app-kit/source-iottwinmaker": "6.3.1",
"@matterport/r3f": "^0.2.6",
"@matterport/webcomponent": "^0.1.26",
"@react-three/drei": "9.56.27",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('AddComponentMenu', () => {
expect(addComponentInternal).toBeCalledWith(selectedSceneNodeRef, {
ref: expect.any(String),
type: KnownComponentType.EntityBinding,
valueDataBinding: { dataBindingContext: '' },
valueDataBinding: { dataBindingContext: undefined },
});
expect(mockMetricRecorder.recordClick).toBeCalledTimes(1);
expect(mockMetricRecorder.recordClick).toBeCalledWith('add-component-data-binding');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const AddComponentMenu: React.FC<AddComponentMenuProps> = ({ onSelect })
const component: IEntityBindingComponentInternal = {
ref: THREE.MathUtils.generateUUID(),
type: KnownComponentType.EntityBinding,
valueDataBinding: { dataBindingContext: '' },
valueDataBinding: { dataBindingContext: undefined },
};

addComponentInternal(selectedSceneNodeRef, component);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useState } from 'react';
import React, { useState } from 'react';

import { Direction } from './utils';
import FoldableContainer from './FoldableContainer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GetState, SetState } from 'zustand';
import { isEmpty } from 'lodash';
import { isDataBindingTemplate } from '@iot-app-kit/source-iottwinmaker';

import DebugLogger from '../../logger/DebugLogger';
import { RecursivePartial } from '../../utils/typeUtils';
import { mergeDeep } from '../../utils/objectUtils';
import { containsMatchingEntityComponent } from '../../utils/dataBindingUtils';
import { isDataBindingTemplate } from '../../utils/dataBindingTemplateUtils';
import { RootState } from '../Store';
import serializationHelpers, { IDeserializeOptions } from '../helpers/serializationHelpers';
import {
Expand Down
31 changes: 0 additions & 31 deletions packages/scene-composer/src/utils/dataBindingTemplateUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,9 @@ import {
applyDataBindingTemplate,
createDataBindingTemplateOptions,
dataBindingConfigSelector,
decorateDataBindingTemplate,
extractEntityId,
isDataBindingTemplate,
undecorateDataBindingTemplate,
} from './dataBindingTemplateUtils';

describe('isDataBindingTemplate', () => {
it('should return true for valid data binding template', () => {
expect(isDataBindingTemplate('${abc}')).toBe(true);
});

it('should return false for empty data binding template', () => {
expect(isDataBindingTemplate('${}')).toBe(false);
expect(isDataBindingTemplate('')).toBe(false);
expect(isDataBindingTemplate()).toBe(false);
});
});

describe('decorateDataBindingTemplate', () => {
it('should return decorated data binding template', () => {
expect(decorateDataBindingTemplate('abc')).toBe('${abc}');
});
});

describe('undecorateDataBindingTemplate', () => {
it('should return undecorated data binding template', () => {
expect(undecorateDataBindingTemplate('${abc}')).toBe('abc');
});

it('should return original string for invalid data binding template', () => {
expect(undecorateDataBindingTemplate('${abc')).toBe('${abc');
});
});

describe('dataBindingTemplatesSelector', () => {
let mockDataBindingConfig;

Expand Down
18 changes: 6 additions & 12 deletions packages/scene-composer/src/utils/dataBindingTemplateUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { cloneDeep, pick } from 'lodash';
import {
isDataBindingTemplate,
undecorateDataBindingTemplate,
decorateDataBindingTemplate,
} from '@iot-app-kit/source-iottwinmaker';

import {
DEFAULT_DATA_BINDING_TEMPLATE_COMPONENT_NAME,
Expand All @@ -14,18 +19,6 @@ import {
} from '../interfaces';
import { RootState } from '../store';

/**
* Data binding templates will be stored as ${my-value} in IValueDataBinding
*/
const dataBindingTemplateRegExp = /^\$\{([\s\S]+)\}$/;

export const isDataBindingTemplate = (item?: string): boolean => (item ? dataBindingTemplateRegExp.test(item) : false);

export const decorateDataBindingTemplate = (item: string): string => '${' + item + '}';

export const undecorateDataBindingTemplate = (item: string): string =>
item.match(dataBindingTemplateRegExp)?.[1] ?? item;

export const dataBindingConfigSelector = (state: RootState): IDataBindingConfig => {
const dataBindingConfig: IDataBindingConfig =
cloneDeep(state.getSceneProperty(KnownSceneProperty.DataBindingConfig)) ?? {};
Expand All @@ -39,6 +32,7 @@ export const dataBindingConfigSelector = (state: RootState): IDataBindingConfig
return dataBindingConfig;
};

// TODO: to be removed in next change
/**
* Create selection options for data binding templates, these options will be shown on top of existing options. E.g. ${sel_entity} will
* be shown before all entity IDs
Expand Down
4 changes: 2 additions & 2 deletions packages/scene-composer/stories/Trees.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Box from '@awsui/components-react/box';
import React, { FC, useCallback, useState } from 'react';
import React, { FC, ReactNode, useCallback, useState } from 'react';
import * as awsui from '@awsui/design-tokens';
import { applyMode, Mode } from '@awsui/global-styles';
import styled, { ThemeProvider } from 'styled-components';
Expand All @@ -22,7 +22,7 @@ const FancyBox = styled(Box)`
background-color: ${awsui.colorBackgroundLayoutMain};
`;

const Layout: FC = ({ children }) => {
const Layout: FC<{ children: ReactNode }> = ({ children }) => {
applyMode(Mode.Dark);

return (
Expand Down
1 change: 1 addition & 0 deletions packages/source-iottwinmaker/src/common/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type TwinMakerErrorCode = 'ListEntitiesError' | 'GetEntityError';

0 comments on commit d1c459d

Please sign in to comment.