Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet committed Dec 19, 2024
1 parent 3fae330 commit c8da726
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { SettingsFieldType } from '@/settings/data-model/types/SettingsFieldType';
import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty';
import { generateDefaultFieldValue } from '@/object-record/utils/generateDefaultFieldValue';
import { getSettingsFieldTypeConfig } from '@/settings/data-model/utils/getSettingsFieldTypeConfig';
import { FieldMetadataType } from '~/generated-metadata/graphql';

const DEFAULT_NUMBER_PREVIEW_VALUE = 2000;
import { isFieldTypeSupportedInSettings } from '@/settings/data-model/utils/isFieldTypeSupportedInSettings';
import { isDefined } from '~/utils/isDefined';

export const getFieldPreviewValue = ({
fieldMetadataItem,
}: {
fieldMetadataItem: Pick<
FieldMetadataItem,
'type' | 'defaultValue'
>;
fieldMetadataItem: Pick<FieldMetadataItem, 'type' | 'defaultValue'>;
}) => {
if (fieldMetadataItem.defaultValue !== undefined && fieldMetadataItem.defaultValue !== null) {
return fieldMetadataItem.defaultValue;
if (!isFieldTypeSupportedInSettings(fieldMetadataItem.type)) return null;

if (
!isFieldValueEmpty({
fieldDefinition: { type: fieldMetadataItem.type },
fieldValue: fieldMetadataItem.defaultValue,
})
) {
return generateDefaultFieldValue(fieldMetadataItem);
}

const fieldTypeConfig = getSettingsFieldTypeConfig(fieldMetadataItem.type as SettingsFieldType);

if (fieldMetadataItem.type === FieldMetadataType.Number) {
return fieldTypeConfig.exampleValue || DEFAULT_NUMBER_PREVIEW_VALUE;
const fieldTypeConfig = getSettingsFieldTypeConfig(fieldMetadataItem.type);

if (
isDefined(fieldTypeConfig) &&
'exampleValue' in fieldTypeConfig &&
isDefined(fieldTypeConfig.exampleValue)
) {
return fieldTypeConfig.exampleValue;
}

return fieldTypeConfig.exampleValue ?? null;
return null;
};

0 comments on commit c8da726

Please sign in to comment.