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 f8571c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const SettingsDataModelFieldNumberSettingsFormCard = ({
objectMetadataItem,
}: SettingsDataModelFieldNumberSettingsFormCardProps) => {
const { watch } = useFormContext<SettingsDataModelFieldNumberFormValues>();

const settings = watch('settings');

return (
Expand Down
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 f8571c1

Please sign in to comment.