@aws-amplify/amplify-util-uibuilder 1.5.0-studio-forms.0 → 1.6.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -2
- package/lib/clients/amplify-studio-client.d.ts +2 -2
- package/lib/clients/amplify-studio-client.d.ts.map +1 -1
- package/lib/clients/amplify-studio-client.js +30 -30
- package/lib/clients/amplify-studio-client.js.map +1 -1
- package/lib/commands/generateComponents.d.ts.map +1 -1
- package/lib/commands/generateComponents.js +2 -5
- package/lib/commands/generateComponents.js.map +1 -1
- package/lib/commands/utils/codegenResources.d.ts +2 -1
- package/lib/commands/utils/codegenResources.d.ts.map +1 -1
- package/lib/commands/utils/codegenResources.js +3 -3
- package/lib/commands/utils/codegenResources.js.map +1 -1
- package/lib/commands/utils/featureFlags.d.ts +1 -2
- package/lib/commands/utils/featureFlags.d.ts.map +1 -1
- package/lib/commands/utils/featureFlags.js +5 -4
- package/lib/commands/utils/featureFlags.js.map +1 -1
- package/lib/commands/utils/shouldRenderComponents.d.ts +1 -1
- package/lib/commands/utils/shouldRenderComponents.d.ts.map +1 -1
- package/lib/commands/utils/shouldRenderComponents.js +14 -8
- package/lib/commands/utils/shouldRenderComponents.js.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +15 -0
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
- package/package.json +7 -7
- package/src/__tests__/cloneComponentsFromEnv.test.ts +11 -11
- package/src/__tests__/createUiBuilderComponent.test.ts +7 -2
- package/src/__tests__/generateComponents.test.ts +27 -32
- package/src/__tests__/getAmplifyDataSchema.test.ts +17 -25
- package/src/__tests__/shouldRenderComponents.test.ts +51 -4
- package/src/__tests__/syncAmplifyUiComponents.test.ts +19 -4
- package/src/clients/amplify-studio-client.ts +31 -26
- package/src/commands/generateComponents.ts +2 -5
- package/src/commands/utils/codegenResources.ts +8 -3
- package/src/commands/utils/featureFlags.ts +6 -5
- package/src/commands/utils/shouldRenderComponents.ts +20 -8
- package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +25 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { printer } from 'amplify-prompts';
|
|
2
2
|
import { $TSContext } from 'amplify-cli-core';
|
|
3
3
|
import {
|
|
4
|
-
StudioComponent, StudioTheme, GenericDataSchema, StudioForm, StudioSchema,checkIsSupportedAsForm
|
|
4
|
+
StudioComponent, StudioTheme, GenericDataSchema, StudioForm, StudioSchema, checkIsSupportedAsForm,
|
|
5
5
|
} from '@aws-amplify/codegen-ui';
|
|
6
6
|
import {
|
|
7
7
|
createUiBuilderComponent,
|
|
@@ -24,6 +24,8 @@ type CodegenResponse<T extends StudioSchema> =
|
|
|
24
24
|
schema?: T;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
// TODO: when types are updated in codegen-ui reference mappers here so the arguments accepted are not any
|
|
28
|
+
|
|
27
29
|
/**
|
|
28
30
|
* Returns instances of StudioComponent from the component schemas
|
|
29
31
|
*/
|
|
@@ -56,6 +58,9 @@ export const generateUiBuilderComponents = (
|
|
|
56
58
|
*/
|
|
57
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
60
|
export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]): CodegenResponse<StudioTheme>[] => {
|
|
61
|
+
if (themeSchemas.length === 0) {
|
|
62
|
+
return [generateDefaultTheme(context)];
|
|
63
|
+
}
|
|
59
64
|
const themeResults = themeSchemas.map<CodegenResponse<StudioTheme>>(schema => {
|
|
60
65
|
try {
|
|
61
66
|
const theme = createUiBuilderTheme(context, schema);
|
|
@@ -73,12 +78,29 @@ export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]
|
|
|
73
78
|
return themeResults;
|
|
74
79
|
};
|
|
75
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Generates the defaultTheme in the user's project that's exported from @aws-amplify/codegen-ui-react
|
|
83
|
+
*/
|
|
84
|
+
const generateDefaultTheme = (context: $TSContext): CodegenResponse<StudioTheme> => {
|
|
85
|
+
try {
|
|
86
|
+
const theme = createUiBuilderTheme(context, { name: 'studioTheme', values: [] }, { renderDefaultTheme: true });
|
|
87
|
+
printer.debug(
|
|
88
|
+
`Generated default theme in ${getUiBuilderComponentsPath(context)}`,
|
|
89
|
+
);
|
|
90
|
+
return { resultType: 'SUCCESS', schema: theme };
|
|
91
|
+
} catch (e) {
|
|
92
|
+
printer.debug(`Failure caught rendering default theme`);
|
|
93
|
+
printer.debug(e);
|
|
94
|
+
return { resultType: 'FAILURE', schemaName: 'studioTheme', error: e };
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
76
98
|
/**
|
|
77
99
|
* Returns instances of StudioForm from form schemas
|
|
78
100
|
*/
|
|
79
101
|
export const generateUiBuilderForms = (
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
102
|
context: $TSContext,
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
104
|
formSchemas: any[],
|
|
83
105
|
dataSchema?: GenericDataSchema,
|
|
84
106
|
autoGenerateForms?: boolean,
|
|
@@ -86,7 +108,7 @@ export const generateUiBuilderForms = (
|
|
|
86
108
|
const modelMap: { [model: string]: Set<'create' | 'update'> } = {};
|
|
87
109
|
if (dataSchema?.dataSourceType === 'DataStore' && autoGenerateForms) {
|
|
88
110
|
Object.entries(dataSchema.models).forEach(([name, model]) => {
|
|
89
|
-
if(checkIsSupportedAsForm(model) && !model.isJoinTable) {
|
|
111
|
+
if (checkIsSupportedAsForm(model) && !model.isJoinTable) {
|
|
90
112
|
modelMap[name] = new Set(['create', 'update']);
|
|
91
113
|
}
|
|
92
114
|
});
|