Add updated at column (#6506)
Introduced `updatedAt` column. and fix an existing bug where the field
edition page was crashing because we were trying to compute Date('now')
(param coming from the default value)
This commit is contained in:
@ -0,0 +1,17 @@
|
|||||||
|
// Some default value are special keywords such as 'uuid' or 'now'
|
||||||
|
// that are mapped to a function that generates a value on the backend.
|
||||||
|
// (see serializeFunctionDefaultValue.ts on the server)
|
||||||
|
// We need to do a similar mapping on the frontend
|
||||||
|
|
||||||
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
|
export const getComputedDefaultValue = (defaultValue?: any) => {
|
||||||
|
switch (defaultValue) {
|
||||||
|
case 'uuid':
|
||||||
|
return v4();
|
||||||
|
case 'now':
|
||||||
|
return new Date().toISOString();
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||||
import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty';
|
import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty';
|
||||||
|
import { getComputedDefaultValue } from '@/settings/data-model/fields/preview/utils/getComputedDefaultValue';
|
||||||
import { getSettingsFieldTypeConfig } from '@/settings/data-model/utils/getSettingsFieldTypeConfig';
|
import { getSettingsFieldTypeConfig } from '@/settings/data-model/utils/getSettingsFieldTypeConfig';
|
||||||
import { isFieldTypeSupportedInSettings } from '@/settings/data-model/utils/isFieldTypeSupportedInSettings';
|
import { isFieldTypeSupportedInSettings } from '@/settings/data-model/utils/isFieldTypeSupportedInSettings';
|
||||||
import { isDefined } from '~/utils/isDefined';
|
import { isDefined } from '~/utils/isDefined';
|
||||||
@ -17,7 +18,7 @@ export const getFieldPreviewValue = ({
|
|||||||
fieldValue: fieldMetadataItem.defaultValue,
|
fieldValue: fieldMetadataItem.defaultValue,
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
return fieldMetadataItem.defaultValue;
|
return getComputedDefaultValue(fieldMetadataItem.defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldTypeConfig = getSettingsFieldTypeConfig(fieldMetadataItem.type);
|
const fieldTypeConfig = getSettingsFieldTypeConfig(fieldMetadataItem.type);
|
||||||
@ -27,7 +28,7 @@ export const getFieldPreviewValue = ({
|
|||||||
'defaultValue' in fieldTypeConfig &&
|
'defaultValue' in fieldTypeConfig &&
|
||||||
isDefined(fieldTypeConfig.defaultValue)
|
isDefined(fieldTypeConfig.defaultValue)
|
||||||
) {
|
) {
|
||||||
return fieldTypeConfig.defaultValue;
|
return getComputedDefaultValue(fieldTypeConfig.defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -30,11 +30,10 @@ export abstract class BaseWorkspaceEntity {
|
|||||||
@WorkspaceField({
|
@WorkspaceField({
|
||||||
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.updatedAt,
|
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.updatedAt,
|
||||||
type: FieldMetadataType.DATE_TIME,
|
type: FieldMetadataType.DATE_TIME,
|
||||||
label: 'Update date',
|
label: 'Last update',
|
||||||
description: 'Update date',
|
description: 'Last time the record was changed',
|
||||||
icon: 'IconCalendar',
|
icon: 'IconCalendarClock',
|
||||||
defaultValue: 'now',
|
defaultValue: 'now',
|
||||||
})
|
})
|
||||||
@WorkspaceIsSystem()
|
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user