amplify-codegen icon indicating copy to clipboard operation
amplify-codegen copied to clipboard

Generate input fields for custom types in connected forms

Open chultquist opened this issue 1 year ago • 5 comments

Environment information

carl@Carls-MacBook-Pro ~/Devel/.../website (rel_20241010) npx ampx info
System:
  OS: macOS 14.6.1
  CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 1.10 GB / 32.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 22.4.1 - /usr/local/bin/node
  Yarn: undefined - undefined
  npm: 10.8.1 - /usr/local/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.4.0
  @aws-amplify/backend: 1.6.0
  @aws-amplify/backend-auth: 1.3.0
  @aws-amplify/backend-cli: 1.4.0
  @aws-amplify/backend-data: 1.1.6
  @aws-amplify/backend-deployer: 1.1.6
  @aws-amplify/backend-function: 1.7.3
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.3
  @aws-amplify/backend-secret: 1.1.4
  @aws-amplify/backend-storage: 1.2.2
  @aws-amplify/cli-core: 1.2.0
  @aws-amplify/client-config: 1.5.1
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.1
  @aws-amplify/sandbox: 1.2.4
  @aws-amplify/schema-generator: 1.2.5
  aws-amplify: 6.6.0
  aws-cdk: 2.165.0
  aws-cdk-lib: 2.165.0
  typescript: 5.5.4
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the feature

When generating connected forms using npx ampx generate forms, the resulting forms should include elements for custom types.

Use case

One of my models has a few custom types, for example:

  // Installation table
  Installation: a
    .model({
...
      // The location of the installation
      location: a.customType({
        lat: a.float(),
        lon: a.float(),
      }),

      // Fields required for Victron integration
      victronConfiguration: a.customType({
        installationId: a.string(),
        portalId: a.string(),
      }),

      // Solar PV plane configuration
      planes: a.ref('Plane').array(),

...


  // Solar plane definition
  Plane: a.customType({
    name: a.string(),
    azimuth: a.integer().required(),
    declination: a.integer().required(),
    kwp: a.float().required()
  }),

The connected forms generation is really helpful, except that it does not include form elements for custom types like the ones shown above. It would be really useful if it did. For arrays, what would be particularly handy is the ability to also add/remove elements from the array (see the "planes" element above).

chultquist avatar Dec 12 '24 06:12 chultquist

Hey,👋 thanks for raising this! I'm going to transfer this over to our codegen repository for better assistance 🙂

ykethan avatar Dec 12 '24 15:12 ykethan

Hi @chultquist 👋 thanks for raising this issue. I think I was able to reproduce the behavior you described.

Here are my repro steps:

  1. I deployed the Installation model and Plane customType from your example schema.
const schema = a.schema({
  Installation: a
    .model({
      location: a.customType({
        lat: a.float(),
        lon: a.float(),
      }),
      victronConfiguration: a.customType({
        installationId: a.string(),
        portalId: a.string(),
      }),
      planes: a.hasMany("Plane", "installationId"),
    })
    .authorization((allow) => [allow.guest()]),

  Plane: a.model({
    name: a.string(),
    azimuth: a.integer().required(),
    declination: a.integer().required(),
    kwp: a.float().required(),
  }),
});
  1. Ran the Amplify CLI command npx ampx generate forms
  2. Rendered the InstallationCreateForm and InstallationUpdateForm components.
  3. Observed that neither UI components rendered elements, or inputs, for the Plane customType.

Because there are no other fields in the Installation model, the form renders without any elements except buttons to clear, reset, or submit.

CleanShot 2025-01-08 at 12 25 38@2x

However, I'm not certain whether this is unexpected behavior or not. I will reach out to the team to find out and label this issue either as a bug or feature request accordingly once I found out.

chrisbonifacio avatar Jan 08 '25 17:01 chrisbonifacio

Thanks, @chrisbonifacio!

chultquist avatar Jan 08 '25 17:01 chultquist

We're categorizing this as a bug because we expect this behavior to work per some of our internal testing.

palpatim avatar Jan 15 '25 19:01 palpatim

We encountered this issue too. Could you give us an estimate when this bug will be fixed, please?

vbakavets avatar Feb 12 '25 11:02 vbakavets