Skip to content

Commit

Permalink
fix(composer): refactor scene modal rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
sheilaXu authored and mukeshsahay committed Feb 12, 2024
1 parent da7281a commit 1d797b1
Show file tree
Hide file tree
Showing 27 changed files with 328 additions and 3,531 deletions.
38 changes: 38 additions & 0 deletions packages/scene-composer/src/common/componentTypeStings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useIntl } from 'react-intl';

import { KnownComponentType } from '../interfaces';
import { Component } from '../models/SceneModels';
import { IDataOverlayComponentInternal, ISceneComponentInternal } from '../store';

import { getLocalizedComponentType } from './componentTypeStings';

describe('getLocalizedComponentType', () => {
const intl = useIntl();

it('should get correct string for EntityBinding', () => {
const component: ISceneComponentInternal = { ref: 'entity-binding-ref', type: KnownComponentType.EntityBinding };
expect(getLocalizedComponentType(component, intl)).toEqual('Entity data binding');
});

it('should get correct string for Overlay', () => {
const component: IDataOverlayComponentInternal = {
ref: 'overlay-ref',
type: KnownComponentType.DataOverlay,
subType: Component.DataOverlaySubType.OverlayPanel,
dataRows: [],
valueDataBindings: [],
};
expect(getLocalizedComponentType(component, intl)).toEqual('Overlay');
});

it('should get correct string for Annotation', () => {
const component: IDataOverlayComponentInternal = {
ref: 'annotation-ref',
type: KnownComponentType.DataOverlay,
subType: Component.DataOverlaySubType.TextAnnotation,
dataRows: [],
valueDataBindings: [],
};
expect(getLocalizedComponentType(component, intl)).toEqual('Annotation');
});
});
65 changes: 65 additions & 0 deletions packages/scene-composer/src/common/componentTypeStings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { IntlShape, defineMessages } from 'react-intl';

import { IDataOverlayComponent, KnownComponentType } from '../interfaces';
import { Component } from '../models/SceneModels';
import { ISceneComponentInternal } from '../store';

export const i18nKnownComponentTypesStrings = defineMessages({
[KnownComponentType.ModelRef]: {
defaultMessage: 'Model Reference',
description: 'Expandable Section title',
},
[KnownComponentType.SubModelRef]: {
defaultMessage: 'Model Reference',
description: 'Expandable Section Title',
},
[KnownComponentType.Camera]: {
defaultMessage: 'Camera',
description: 'Expandable Section title',
},
[KnownComponentType.Light]: {
defaultMessage: 'Light',
description: 'Expandable Section title',
},
[KnownComponentType.Tag]: {
defaultMessage: 'Tag',
description: 'Expandable Section title',
},
[KnownComponentType.EntityBinding]: {
defaultMessage: 'Entity data binding',
description: 'Expandable Section title',
},
[KnownComponentType.ModelShader]: {
defaultMessage: 'Model Shader',
description: 'Expandable Section title',
},
[KnownComponentType.MotionIndicator]: {
defaultMessage: 'Motion Indicator',
description: 'Expandable Section title',
},
[Component.DataOverlaySubType.TextAnnotation]: {
defaultMessage: 'Annotation',
description: 'Expandable Section title',
},
[Component.DataOverlaySubType.OverlayPanel]: {
defaultMessage: 'Overlay',
description: 'Expandable Section title',
},
[KnownComponentType.Animation]: {
defaultMessage: 'Animation',
description: 'Expandable Section title',
},
[KnownComponentType.PlaneGeometry]: {
defaultMessage: 'Plane Geometry',
description: 'Expandable Section title',
},
});

export const getLocalizedComponentType = (component: ISceneComponentInternal, intl: IntlShape): string => {
return (
(component.type === KnownComponentType.DataOverlay
? intl.formatMessage(i18nKnownComponentTypesStrings[(component as IDataOverlayComponent).subType]) ||
(component as IDataOverlayComponent).subType
: intl.formatMessage(i18nKnownComponentTypesStrings[component.type])) || component.type
);
};
2 changes: 2 additions & 0 deletions packages/scene-composer/src/common/entityModelConstants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { KnownComponentType } from '../interfaces';

// Backend limits
export const MAX_PROPERTY_STRING_LENGTH = 2048;
export const MAX_QUERY_HOP = 30;

// Scene Nodes
const SCENE_COMPONENT_TYPE_ID_PREFIX = 'com.amazon.iottwinmaker.3d';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ exports[`DefaultErrorFallback should render correctly with a Error type 1`] = `
</MockTextContent>
</Styled(MockContainer)>
}
showModal={true}
/>
`;

Expand All @@ -42,7 +41,6 @@ exports[`DefaultErrorFallback should render correctly with a SceneComposerRuntim
</MockTextContent>
</Styled(MockContainer)>
}
showModal={true}
/>
`;

Expand All @@ -65,7 +63,6 @@ exports[`DefaultErrorFallback should render correctly with a String type 1`] = `
</MockTextContent>
</Styled(MockContainer)>
}
showModal={true}
/>
`;

Expand All @@ -88,6 +85,5 @@ exports[`DefaultErrorFallback should render correctly with a Unknown type 1`] =
</MockTextContent>
</Styled(MockContainer)>
}
showModal={true}
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const DefaultErrorFallback: FC<ErrorFallbackProps> = ({ error }) => {

return (
<StaticLayout
showModal={true}
modalContent={
<CenteredContainer header={<Header variant='h2'>{errorTitle}</Header>}>
<TextContent>
Expand Down
8 changes: 4 additions & 4 deletions packages/scene-composer/src/components/StateManager.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { DataStream } from '@iot-app-kit/core';
import useActiveCamera from '../hooks/useActiveCamera';
import { KnownComponentType } from '..';
import * as THREE from 'three';
import { SCENE_CAPABILITY_MATTERPORT } from '../common/constants';
import { MATTERPORT_ERROR, SCENE_CAPABILITY_MATTERPORT } from '../common/constants';
import { TwinMakerSceneMetadataModule } from '@iot-app-kit/source-iottwinmaker';
import { MpSdk } from '@matterport/webcomponent';
import { SceneComposerInternalConfig } from '../interfaces/sceneComposerInternal';
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('StateManager', () => {
const getObject3DBySceneNodeRef = jest.fn().mockReturnValue(object3D);
const baseState = {
loadScene: jest.fn(),
getMessages: jest.fn().mockReturnValue(['messagge']),
addMessages: jest.fn(),
getObject3DBySceneNodeRef,
selectedSceneNodeRef: undefined,
sceneLoaded: false,
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('StateManager', () => {
...createState('mockConnectionName'),
getSceneProperty: jest.fn().mockReturnValue('mockMatterportModelId'),
});
getSceneInfo.mockResolvedValue({ error: { message: 'Client id and secret not valid' } });
getSceneInfo.mockResolvedValue({ error: { message: 'Client id and secret not valid', code: MATTERPORT_ERROR } });

let container;
await act(async () => {
Expand All @@ -301,7 +301,7 @@ describe('StateManager', () => {
await flushPromises();
});

expect(container).toMatchSnapshot();
expect(baseState.addMessages).toBeCalledTimes(1);
});

it("should subscribe to query's provider succcessfully", async () => {
Expand Down
7 changes: 0 additions & 7 deletions packages/scene-composer/src/components/StateManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const StateManager: React.FC<SceneComposerInternalProps> = ({
const [updatedExternalLibraryConfig, setUpdatedExternalLibraryConfig] = useState<ExternalLibraryConfig | undefined>(
externalLibraryConfig,
);
const messages = useStore(sceneComposerId)((state) => state.getMessages());
const matterportModelId = useStore(sceneComposerId)((state) =>
state.getSceneProperty<string>(KnownSceneProperty.MatterportModelId),
);
Expand All @@ -104,8 +103,6 @@ const StateManager: React.FC<SceneComposerInternalProps> = ({
const prevSelection = useRef<string | undefined>(undefined);
const [matterportReady, setMatterportReady] = useState<boolean>(false);

const convertSceneModalVisible = useStore(sceneComposerId)((state) => !!state.convertSceneModalVisible);

const { setActiveCameraSettings, setActiveCameraName } = useActiveCamera();

const standardUriModifier = useMemo(
Expand Down Expand Up @@ -416,13 +413,9 @@ const StateManager: React.FC<SceneComposerInternalProps> = ({
[setSelectedSceneNodeRef],
);

const showMessageModal = messages.length > 0;

return (
<SceneLayout
isViewing={isViewing}
showMessageModal={showMessageModal}
showConvertSceneModal={convertSceneModalVisible}
externalLibraryConfig={updatedExternalLibraryConfig}
LoadingView={
<IntlProvider locale={config.locale}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ exports[`SceneComposerInternal should render a default error view when loading a
}
/>
}
showModal={true}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -100,7 +99,6 @@ exports[`SceneComposerInternal should render a default error view when unknown e
</MockTextContent>
</Styled(MockContainer)>
}
showModal={true}
/>
</div>
`;
Expand Down Expand Up @@ -171,7 +169,6 @@ exports[`SceneComposerInternal should render both valid and invalid scene correc
}
/>
}
showModal={true}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -228,7 +225,7 @@ exports[`SceneComposerInternal should render both valid and invalid scene correc
</LogProvider>
</React.Fragment>
}
modalContent={<MessageModal />}
modalContent={null}
rightPanel={
<ScenePanel
direction="Right"
Expand All @@ -239,7 +236,6 @@ exports[`SceneComposerInternal should render both valid and invalid scene correc
}
/>
}
showModal={false}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -300,7 +296,7 @@ exports[`SceneComposerInternal should render correctly with a valid scene in edi
</LogProvider>
</React.Fragment>
}
modalContent={<MessageModal />}
modalContent={null}
rightPanel={
<ScenePanel
direction="Right"
Expand All @@ -311,7 +307,6 @@ exports[`SceneComposerInternal should render correctly with a valid scene in edi
}
/>
}
showModal={false}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -365,7 +360,7 @@ exports[`SceneComposerInternal should render correctly with an empty scene in ed
</LogProvider>
</React.Fragment>
}
modalContent={<MessageModal />}
modalContent={null}
rightPanel={
<ScenePanel
direction="Right"
Expand All @@ -376,7 +371,6 @@ exports[`SceneComposerInternal should render correctly with an empty scene in ed
}
/>
}
showModal={false}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -430,9 +424,8 @@ exports[`SceneComposerInternal should render correctly with an empty scene in vi
</LogProvider>
</React.Fragment>
}
modalContent={<MessageModal />}
modalContent={null}
rightPanel={false}
showModal={false}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -503,7 +496,6 @@ exports[`SceneComposerInternal should render error when major version is newer 1
}
/>
}
showModal={true}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -574,7 +566,6 @@ exports[`SceneComposerInternal should render error when specVersion is invalid 1
}
/>
}
showModal={true}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -645,7 +636,6 @@ exports[`SceneComposerInternal should render warning when minor version is newer
}
/>
}
showModal={true}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -706,7 +696,7 @@ exports[`SceneComposerInternal should support rendering multiple valid scenes 1`
</LogProvider>
</React.Fragment>
}
modalContent={<MessageModal />}
modalContent={null}
rightPanel={
<ScenePanel
direction="Right"
Expand All @@ -717,7 +707,6 @@ exports[`SceneComposerInternal should support rendering multiple valid scenes 1`
}
/>
}
showModal={false}
topBar={<TopBar />}
/>
</div>
Expand Down Expand Up @@ -774,7 +763,7 @@ exports[`SceneComposerInternal should support rendering multiple valid scenes 1`
</LogProvider>
</React.Fragment>
}
modalContent={<MessageModal />}
modalContent={null}
rightPanel={
<ScenePanel
direction="Right"
Expand All @@ -785,7 +774,6 @@ exports[`SceneComposerInternal should support rendering multiple valid scenes 1`
}
/>
}
showModal={false}
topBar={<TopBar />}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ exports[`StateManager should render correctly 1`] = `
externalLibraryConfig={Object {}}
isViewing={false}
onPointerMissed={[Function]}
showConvertSceneModal={false}
showMessageModal={true}
/>
`;

Expand All @@ -33,22 +31,6 @@ exports[`StateManager should render correctly with Matterport configuration 1`]
}
isViewing={false}
onPointerMissed={[Function]}
showConvertSceneModal={false}
showMessageModal={true}
/>
`;

exports[`StateManager should render correctly with error in Matterport configuration 1`] = `
<SceneLayout
LoadingView={
<Provider>
<LoadingProgress />
</Provider>
}
isViewing={false}
onPointerMissed={[Function]}
showConvertSceneModal={false}
showMessageModal={true}
/>
`;

Expand Down

0 comments on commit 1d797b1

Please sign in to comment.