From 0cbbbdc2df9d9d8b179c956e5fe70c4d4b95d3ab Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Wed, 3 Nov 2021 19:47:36 +0000 Subject: [PATCH] feat: remove string component type --- .../component-renderer.test.ts | 25 ---------------- .../amplify-ui-renderers/amplify-renderer.ts | 5 ---- .../lib/amplify-ui-renderers/string.ts | 29 ------------------- 3 files changed, 59 deletions(-) delete mode 100644 packages/studio-ui-codegen-react/lib/amplify-ui-renderers/string.ts diff --git a/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/component-renderer.test.ts b/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/component-renderer.test.ts index 57308814b..19e4d02cb 100644 --- a/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/component-renderer.test.ts +++ b/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/component-renderer.test.ts @@ -16,7 +16,6 @@ import { StudioComponent } from '@amzn/studio-ui-codegen'; import { assertASTMatchesSnapshot } from '../__utils__/snapshot-helpers'; -import renderString from '../../amplify-ui-renderers/string'; import { AmplifyRenderer } from '../../amplify-ui-renderers/amplify-renderer'; function testComponentRenderer(component: StudioComponent) { @@ -124,28 +123,4 @@ describe('Component Renderers', () => { }; testComponentRenderer(component); }); - - test('StringRenderer', () => { - const component = { - componentType: 'String', - name: 'MyString', - properties: { - value: { - value: 'test', - }, - }, - bindingProperties: {}, - }; - testComponentRenderer(component); - }); - - test('StringRenderer throws on missing props', () => { - const component = { - componentType: 'String', - name: 'MyString', - properties: {}, - bindingProperties: {}, - }; - expect(() => renderString(component)).toThrowErrorMatchingSnapshot(); - }); }); diff --git a/packages/studio-ui-codegen-react/lib/amplify-ui-renderers/amplify-renderer.ts b/packages/studio-ui-codegen-react/lib/amplify-ui-renderers/amplify-renderer.ts index 7df3eddf8..125b2c9f6 100644 --- a/packages/studio-ui-codegen-react/lib/amplify-ui-renderers/amplify-renderer.ts +++ b/packages/studio-ui-codegen-react/lib/amplify-ui-renderers/amplify-renderer.ts @@ -27,7 +27,6 @@ import { import Primitives from '../primitives'; import { ReactStudioTemplateRenderer } from '../react-studio-template-renderer'; import TextRenderer from './text'; -import renderString from './string'; import CustomComponentRenderer from './customComponent'; import CollectionRenderer from './collection'; import { ReactComponentWithChildrenRenderer } from '../react-component-with-children-renderer'; @@ -402,10 +401,6 @@ export class AmplifyRenderer extends ReactStudioTemplateRenderer { parent, ).renderElement(renderChildren); - // to be removed - case 'String': - return renderString(component as StudioComponentChild); - default: return new CustomComponentRenderer(component, this.importCollection, parent).renderElement(renderChildren); } diff --git a/packages/studio-ui-codegen-react/lib/amplify-ui-renderers/string.ts b/packages/studio-ui-codegen-react/lib/amplify-ui-renderers/string.ts deleted file mode 100644 index fccb1bbda..000000000 --- a/packages/studio-ui-codegen-react/lib/amplify-ui-renderers/string.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"). - You may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ -import { StudioComponentChild } from '@amzn/studio-ui-codegen'; -import { factory, JsxChild, JsxFragment } from 'typescript'; -import { buildChildElement } from '../react-component-render-helper'; - -export default function renderString(component: StudioComponentChild): JsxFragment { - if (!('value' in component.properties)) { - throw new Error('Failed to render String - Unexpected component structure'); - } - - const childElement = buildChildElement(component.properties.value); - const children: JsxChild[] = childElement ? [childElement] : []; - - return factory.createJsxFragment(factory.createJsxOpeningFragment(), children, factory.createJsxJsxClosingFragment()); -}