Skip to content

Commit c4767da

Browse files
committed
fix: remove special 'value' handling for text, since it causes issues, and is replaced w/ 'label'
1 parent 58be31a commit c4767da

File tree

6 files changed

+163
-40
lines changed

6 files changed

+163
-40
lines changed

packages/studio-ui-codegen-react/lib/__tests__/__snapshots__/studio-ui-codegen-react.test.ts.snap

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,61 @@ export default function CustomButton(
16761676
"
16771677
`;
16781678
1679+
exports[`amplify render tests concat and conditional transform should render component with conditional data binding prop from a bug 1`] = `
1680+
"/* eslint-disable */
1681+
import React from \\"react\\";
1682+
import { Student } from \\"../models\\";
1683+
import {
1684+
Button,
1685+
EscapeHatchProps,
1686+
Flex,
1687+
FlexProps,
1688+
Text,
1689+
getOverrideProps,
1690+
} from \\"@aws-amplify/ui-react\\";
1691+
1692+
export type ConditionalComponentWithDataBindingProps = React.PropsWithChildren<
1693+
Partial<FlexProps> & {
1694+
student?: Student;
1695+
} & {
1696+
overrides?: EscapeHatchProps | undefined | null;
1697+
}
1698+
>;
1699+
export default function ConditionalComponentWithDataBinding(
1700+
props: ConditionalComponentWithDataBindingProps
1701+
): React.ReactElement {
1702+
const { student, overrides: overridesProp, ...rest } = props;
1703+
const overrides = { ...overridesProp };
1704+
return (
1705+
/* @ts-ignore: TS2322 */
1706+
<Flex {...rest} {...getOverrideProps(overrides, \\"Flex\\")}>
1707+
<Text
1708+
value={
1709+
student?.id && student?.id === \\"idstringuserinput\\"
1710+
? student?.createdAt
1711+
: student?.id
1712+
}
1713+
children={
1714+
student?.id && student?.id === \\"idstringuserinput\\"
1715+
? student?.createdAt
1716+
: student?.id
1717+
}
1718+
{...getOverrideProps(overrides, \\"Flex.Text[0]\\")}
1719+
></Text>
1720+
<Button
1721+
value={
1722+
student?.id && student?.id === \\"idstringuserinput\\"
1723+
? student?.createdAt
1724+
: student?.id
1725+
}
1726+
{...getOverrideProps(overrides, \\"Flex.Button[0]\\")}
1727+
></Button>
1728+
</Flex>
1729+
);
1730+
}
1731+
"
1732+
`;
1733+
16791734
exports[`amplify render tests concat and conditional transform should render component with conditional simple binding prop 1`] = `
16801735
"/* eslint-disable */
16811736
import React from \\"react\\";

packages/studio-ui-codegen-react/lib/__tests__/studio-ui-codegen-react.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ describe('amplify render tests', () => {
215215
const generatedCode = generateWithAmplifyRenderer('componentWithSimplePropertyConditional');
216216
expect(generatedCode.componentText).toMatchSnapshot();
217217
});
218+
219+
it('should render component with conditional data binding prop from a bug', () => {
220+
const generatedCode = generateWithAmplifyRenderer('conditionalComponentWithDataBinding');
221+
expect(generatedCode.componentText).toMatchSnapshot();
222+
});
218223
});
219224

220225
describe('component with binding', () => {
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "ConditionalComponentWithDataBinding",
3+
"children": [
4+
{
5+
"children": [],
6+
"name": "Placeholder text",
7+
"componentType": "Text",
8+
"properties": {
9+
"value": {
10+
"condition": {
11+
"property": "student",
12+
"operator": "eq",
13+
"operand": "idstringuserinput",
14+
"then": {
15+
"bindingProperties": {
16+
"property": "student",
17+
"field": "createdAt"
18+
}
19+
},
20+
"else": {
21+
"bindingProperties": {
22+
"property": "student",
23+
"field": "id"
24+
}
25+
},
26+
"field": "id"
27+
}
28+
},
29+
"label": {
30+
"condition": {
31+
"property": "student",
32+
"operator": "eq",
33+
"operand": "idstringuserinput",
34+
"then": {
35+
"bindingProperties": {
36+
"property": "student",
37+
"field": "createdAt"
38+
}
39+
},
40+
"else": {
41+
"bindingProperties": {
42+
"property": "student",
43+
"field": "id"
44+
}
45+
},
46+
"field": "id"
47+
}
48+
}
49+
},
50+
"overrides": {},
51+
"variants": []
52+
},
53+
{
54+
"children": [],
55+
"name": "Placeholder Button",
56+
"componentType": "Button",
57+
"properties": {
58+
"value": {
59+
"condition": {
60+
"property": "student",
61+
"operator": "eq",
62+
"operand": "idstringuserinput",
63+
"then": {
64+
"bindingProperties": {
65+
"property": "student",
66+
"field": "createdAt"
67+
}
68+
},
69+
"else": {
70+
"bindingProperties": {
71+
"property": "student",
72+
"field": "id"
73+
}
74+
},
75+
"field": "id"
76+
}
77+
}
78+
},
79+
"overrides": {},
80+
"variants": []
81+
}
82+
],
83+
"id": "c-YR5rdCGjwJCxfzvGlu",
84+
"bindingProperties": {
85+
"student": {
86+
"type": "Data",
87+
"bindingProperties": {
88+
"model": "Student"
89+
}
90+
}
91+
},
92+
"componentType": "Flex",
93+
"properties": {},
94+
"overrides": {},
95+
"variants": []
96+
}

packages/studio-ui-codegen-react/lib/amplify-ui-renderers/amplify-renderer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ import {
5252
ToggleButtonGroupProps,
5353
ViewProps,
5454
VisuallyHiddenProps,
55+
TextProps,
5556
} from '@aws-amplify/ui-react';
5657
import Primitive from '../primitive';
5758
import { ReactStudioTemplateRenderer } from '../react-studio-template-renderer';
58-
import TextRenderer from './text';
5959
import CustomComponentRenderer from './customComponent';
6060
import CollectionRenderer from './collection';
6161
import { ReactComponentWithChildrenRenderer } from '../react-component-with-children-renderer';
@@ -273,7 +273,11 @@ export class AmplifyRenderer extends ReactStudioTemplateRenderer {
273273
).renderElement(renderChildren);
274274

275275
case Primitive.Text:
276-
return new TextRenderer(component, this.importCollection, parent).renderElement();
276+
return new ReactComponentWithChildrenRenderer<TextProps>(
277+
component,
278+
this.importCollection,
279+
parent,
280+
).renderElement(renderChildren);
277281

278282
case Primitive.TextField:
279283
return new ReactComponentWithChildrenRenderer<TextFieldProps<boolean>>(

packages/studio-ui-codegen-react/lib/amplify-ui-renderers/text.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/test-generator/lib/components/basic-components/basicComponentText.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"width": {
1010
"value": "20px"
1111
},
12-
"value": {
12+
"label": {
1313
"value": "Basic Component Text"
1414
}
1515
}

0 commit comments

Comments
 (0)