@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.
Files changed (37) hide show
  1. package/CHANGELOG.md +44 -2
  2. package/lib/clients/amplify-studio-client.d.ts +2 -2
  3. package/lib/clients/amplify-studio-client.d.ts.map +1 -1
  4. package/lib/clients/amplify-studio-client.js +30 -30
  5. package/lib/clients/amplify-studio-client.js.map +1 -1
  6. package/lib/commands/generateComponents.d.ts.map +1 -1
  7. package/lib/commands/generateComponents.js +2 -5
  8. package/lib/commands/generateComponents.js.map +1 -1
  9. package/lib/commands/utils/codegenResources.d.ts +2 -1
  10. package/lib/commands/utils/codegenResources.d.ts.map +1 -1
  11. package/lib/commands/utils/codegenResources.js +3 -3
  12. package/lib/commands/utils/codegenResources.js.map +1 -1
  13. package/lib/commands/utils/featureFlags.d.ts +1 -2
  14. package/lib/commands/utils/featureFlags.d.ts.map +1 -1
  15. package/lib/commands/utils/featureFlags.js +5 -4
  16. package/lib/commands/utils/featureFlags.js.map +1 -1
  17. package/lib/commands/utils/shouldRenderComponents.d.ts +1 -1
  18. package/lib/commands/utils/shouldRenderComponents.d.ts.map +1 -1
  19. package/lib/commands/utils/shouldRenderComponents.js +14 -8
  20. package/lib/commands/utils/shouldRenderComponents.js.map +1 -1
  21. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
  22. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +15 -0
  23. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
  24. package/package.json +7 -7
  25. package/src/__tests__/cloneComponentsFromEnv.test.ts +11 -11
  26. package/src/__tests__/createUiBuilderComponent.test.ts +7 -2
  27. package/src/__tests__/generateComponents.test.ts +27 -32
  28. package/src/__tests__/getAmplifyDataSchema.test.ts +17 -25
  29. package/src/__tests__/shouldRenderComponents.test.ts +51 -4
  30. package/src/__tests__/syncAmplifyUiComponents.test.ts +19 -4
  31. package/src/clients/amplify-studio-client.ts +31 -26
  32. package/src/commands/generateComponents.ts +2 -5
  33. package/src/commands/utils/codegenResources.ts +8 -3
  34. package/src/commands/utils/featureFlags.ts +6 -5
  35. package/src/commands/utils/shouldRenderComponents.ts +20 -8
  36. package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +25 -3
  37. 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
  });