-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reactive form preview #8663
base: main
Are you sure you want to change the base?
Reactive form preview #8663
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,27 @@ | ||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty'; | ||
import { generateDefaultFieldValue } from '@/object-record/utils/generateDefaultFieldValue'; | ||
import { SettingsFieldType } from '@/settings/data-model/types/SettingsFieldType'; | ||
import { getSettingsFieldTypeConfig } from '@/settings/data-model/utils/getSettingsFieldTypeConfig'; | ||
import { isFieldTypeSupportedInSettings } from '@/settings/data-model/utils/isFieldTypeSupportedInSettings'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
|
||
const DEFAULT_NUMBER_PREVIEW_VALUE = 2000; | ||
|
||
export const getFieldPreviewValue = ({ | ||
fieldMetadataItem, | ||
}: { | ||
fieldMetadataItem: Pick<FieldMetadataItem, 'type' | 'defaultValue'>; | ||
fieldMetadataItem: Pick< | ||
FieldMetadataItem, | ||
'type' | 'defaultValue' | ||
>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: 'settings' property is picked but never used in the function |
||
}) => { | ||
if (!isFieldTypeSupportedInSettings(fieldMetadataItem.type)) return null; | ||
|
||
if ( | ||
!isFieldValueEmpty({ | ||
fieldDefinition: { type: fieldMetadataItem.type }, | ||
fieldValue: fieldMetadataItem.defaultValue, | ||
}) | ||
) { | ||
return generateDefaultFieldValue(fieldMetadataItem); | ||
if (fieldMetadataItem.defaultValue !== undefined && fieldMetadataItem.defaultValue !== null) { | ||
return fieldMetadataItem.defaultValue; | ||
} | ||
|
||
const fieldTypeConfig = getSettingsFieldTypeConfig(fieldMetadataItem.type); | ||
|
||
if ( | ||
isDefined(fieldTypeConfig) && | ||
'exampleValue' in fieldTypeConfig && | ||
isDefined(fieldTypeConfig.exampleValue) | ||
) { | ||
return fieldTypeConfig.exampleValue; | ||
const fieldTypeConfig = getSettingsFieldTypeConfig(fieldMetadataItem.type as SettingsFieldType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Type assertion to SettingsFieldType may be unsafe if fieldMetadataItem.type is not a valid SettingsFieldType |
||
|
||
if (fieldMetadataItem.type === FieldMetadataType.Number) { | ||
return fieldTypeConfig.exampleValue || DEFAULT_NUMBER_PREVIEW_VALUE; | ||
} | ||
|
||
return null; | ||
return fieldTypeConfig.exampleValue ?? null; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider handling invalid number conversion (NaN) cases here