twenty icon indicating copy to clipboard operation
twenty copied to clipboard

Rating field type is not properly created

Open charlesBochet opened this issue 1 year ago • 3 comments

Bug Description

In the DataModel settings, while creating a new field of fieldType = RATING, this is leading to an error: Cannot read properties of undefined (reading '0')

To reproduce:

  1. you'll need to enable IS_RATING_FIELD_TYPE_ENABLED on your workspace in featureFlag table to see the option in the table
  2. Go to Settings > Data Model > (any object) > add field
  3. Select field type "Rating"
  4. Click on "Save"

Expected behavior

The field is created without this error.

Technical inputs

Not sure, unfortunately we don't have a proper error reporting on this section. I recommend reproducing locally and check what's wrong.

charlesBochet avatar Jan 03 '24 10:01 charlesBochet

Technical input

When we create a fieldMetadata with a type RATING (as well as SELECT/MULTISELECT), the backend will try to create an enum in the DB which means we need to provide the possible values of the enum during the field creation. This is why we introduced an "options" field under the fieldMetadata table. This is correctly provided by the frontend for SELECT fields (since we actually ask the user to provide the different options) however it is absent for RATING fields. We need to

  • Reject the field creation if it's a RATING/SELECT/MULTI_SELECT and options is not provided or null (Backend)
  • Make sure we provide options for RATING (Frontend). Since we don't ask the user input for that field type, we will use [0, ..., 10] to represent the different stars (and half stars).

Weiko avatar Jan 03 '24 12:01 Weiko

Hi @charlesBochet, can take this up? :)

Thanks @Weiko! I included the necessary checks on the backend like you mentioned

Since we are not asking the user for input on frontend, I'm assuming we will pass a hard coded object array as options. How should I pass the [0,....,10] range?

The FieldMetadataOption currently has the following structure. export type FieldMetadataOption = { color?: ThemeColor; id?: string; isDefault?: boolean; label: string; };

If there is some other way I should do it, let me know.

AdityaPimpalkar avatar Jan 03 '24 16:01 AdityaPimpalkar

Hi @AdityaPimpalkar, Yes I think we can pass it hard coded at least for now with an array of FieldMetadataOption. 👍 Thanks!

Weiko avatar Jan 03 '24 17:01 Weiko

Closing as this is probably fixed by https://github.com/twentyhq/twenty/pull/3638

@charlesBochet please reopen if not!

FelixMalfait avatar Feb 19 '24 17:02 FelixMalfait