From fc220227e764d915f97bfbd1adf4b269ddb626d4 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 --- .../__snapshots__/primitives.test.ts.snap | 4 --- .../amplify-ui-renderers/primitives.test.ts | 25 ---------------- .../amplify-ui-renderers/amplify-renderer.ts | 5 ---- .../lib/amplify-ui-renderers/string.ts | 29 ------------------- 4 files changed, 63 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/__snapshots__/primitives.test.ts.snap b/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/__snapshots__/primitives.test.ts.snap index cd9a7bfb5..53bbb3500 100644 --- a/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/__snapshots__/primitives.test.ts.snap +++ b/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/__snapshots__/primitives.test.ts.snap @@ -62,10 +62,6 @@ exports[`Primitives SelectField 1`] = `""`; -exports[`Primitives StringRenderer 1`] = `"<>{\\"test\\"}"`; - -exports[`Primitives StringRenderer throws on missing props 1`] = `"Failed to render String - Unexpected component structure"`; - exports[`Primitives SwitchField 1`] = `""`; exports[`Primitives Tabs 1`] = `""`; diff --git a/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/primitives.test.ts b/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/primitives.test.ts index b5d6d8fa6..0c88dc735 100644 --- a/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/primitives.test.ts +++ b/packages/studio-ui-codegen-react/lib/__tests__/amplify-ui-renderers/primitives.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'; import Primitives from '../../primitives'; @@ -36,28 +35,4 @@ describe('Primitives', () => { }); }); }); - - test('StringRenderer', () => { - const component = { - componentType: 'String', - name: 'MyString', - properties: { - value: { - value: 'test', - }, - }, - bindingProperties: {}, - }; - testPrimitive(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 793bbc719..faf9a6970 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 @@ -56,7 +56,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'; @@ -329,10 +328,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()); -}