mirror of
https://github.com/AppFlowy-IO/AppFlowy-Web.git
synced 2025-11-30 03:18:02 +08:00
fix: date time undefined get
This commit is contained in:
@@ -36,7 +36,8 @@ export function getRowTimeString(field: YDatabaseField, timeStamp: string, curre
|
|||||||
const typeOption = getTypeOptions(field);
|
const typeOption = getTypeOptions(field);
|
||||||
const typeOptionValue = getFieldDateTimeFormats(typeOption, currentUser);
|
const typeOptionValue = getFieldDateTimeFormats(typeOption, currentUser);
|
||||||
|
|
||||||
const includeTime = typeOption.get(YjsDatabaseKey.include_time);
|
const includeTimeRaw = typeOption?.get(YjsDatabaseKey.include_time);
|
||||||
|
const includeTime = typeof includeTimeRaw === 'boolean' ? includeTimeRaw : Boolean(includeTimeRaw);
|
||||||
|
|
||||||
return getDateTimeStr({
|
return getDateTimeStr({
|
||||||
timeStamp,
|
timeStamp,
|
||||||
@@ -45,16 +46,36 @@ export function getRowTimeString(field: YDatabaseField, timeStamp: string, curre
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFieldDateTimeFormats(typeOption: YMapFieldTypeOption, currentUser?: User) {
|
export function getFieldDateTimeFormats(typeOption: YMapFieldTypeOption | undefined, currentUser?: User) {
|
||||||
const typeOptionTimeFormat = typeOption.get(YjsDatabaseKey.time_format);
|
/**
|
||||||
const typeOptionDateFormat = typeOption.get(YjsDatabaseKey.date_format);
|
* Resolve the preferred date/time formats for a field.
|
||||||
|
* 1. Read any persisted overrides from the Yjs type option map.
|
||||||
|
* 2. Fall back to the signed-in user's preference metadata.
|
||||||
|
* 3. Default to AppFlowy's locale-aware formats as a final safety net.
|
||||||
|
*/
|
||||||
|
const typeOptionTimeFormat = typeOption?.get(YjsDatabaseKey.time_format);
|
||||||
|
const typeOptionDateFormat = typeOption?.get(YjsDatabaseKey.date_format);
|
||||||
|
|
||||||
const dateFormat = typeOptionDateFormat === undefined
|
const fallbackDateFormat = currentUser?.metadata?.[MetadataKey.DateFormat] as DateFormat | undefined;
|
||||||
? currentUser?.metadata?.[MetadataKey.DateFormat] as DateFormat ?? DateFormat.Local
|
const fallbackTimeFormat = currentUser?.metadata?.[MetadataKey.TimeFormat] as TimeFormat | undefined;
|
||||||
: parseInt(typeOptionDateFormat) as DateFormat;
|
|
||||||
const timeFormat = typeOptionTimeFormat === undefined
|
const parsedDateFormat =
|
||||||
? currentUser?.metadata?.[MetadataKey.TimeFormat] as TimeFormat ?? TimeFormat.TwelveHour
|
typeOptionDateFormat === undefined || typeOptionDateFormat === null
|
||||||
: parseInt(typeOptionTimeFormat) as TimeFormat;
|
? undefined
|
||||||
|
: Number.parseInt(String(typeOptionDateFormat), 10);
|
||||||
|
const parsedTimeFormat =
|
||||||
|
typeOptionTimeFormat === undefined || typeOptionTimeFormat === null
|
||||||
|
? undefined
|
||||||
|
: Number.parseInt(String(typeOptionTimeFormat), 10);
|
||||||
|
|
||||||
|
const dateFormat =
|
||||||
|
parsedDateFormat === undefined || Number.isNaN(parsedDateFormat)
|
||||||
|
? fallbackDateFormat ?? DateFormat.Local
|
||||||
|
: parsedDateFormat as DateFormat;
|
||||||
|
const timeFormat =
|
||||||
|
parsedTimeFormat === undefined || Number.isNaN(parsedTimeFormat)
|
||||||
|
? fallbackTimeFormat ?? TimeFormat.TwelveHour
|
||||||
|
: parsedTimeFormat as TimeFormat;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dateFormat,
|
dateFormat,
|
||||||
@@ -64,7 +85,7 @@ export function getFieldDateTimeFormats(typeOption: YMapFieldTypeOption, current
|
|||||||
|
|
||||||
export function getDateCellStr({ cell, field, currentUser }: { cell: DateTimeCell; field: YDatabaseField, currentUser?: User }) {
|
export function getDateCellStr({ cell, field, currentUser }: { cell: DateTimeCell; field: YDatabaseField, currentUser?: User }) {
|
||||||
const typeOptionMap = field.get(YjsDatabaseKey.type_option);
|
const typeOptionMap = field.get(YjsDatabaseKey.type_option);
|
||||||
const typeOption = typeOptionMap.get(String(cell.fieldType));
|
const typeOption = typeOptionMap?.get(String(cell.fieldType));
|
||||||
|
|
||||||
const typeOptionValue = getFieldDateTimeFormats(typeOption, currentUser);
|
const typeOptionValue = getFieldDateTimeFormats(typeOption, currentUser);
|
||||||
|
|
||||||
|
|||||||
@@ -1235,11 +1235,12 @@ export const useRowTimeString = (rowId: string, fieldId: string, attrName: strin
|
|||||||
const typeOption = getTypeOptions(field);
|
const typeOption = getTypeOptions(field);
|
||||||
|
|
||||||
const { dateFormat, timeFormat } = getFieldDateTimeFormats(typeOption, currentUser);
|
const { dateFormat, timeFormat } = getFieldDateTimeFormats(typeOption, currentUser);
|
||||||
|
const includeTimeRaw = typeOption?.get(YjsDatabaseKey.include_time);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dateFormat,
|
dateFormat,
|
||||||
timeFormat,
|
timeFormat,
|
||||||
includeTime: typeOption.get(YjsDatabaseKey.include_time),
|
includeTime: typeof includeTimeRaw === 'boolean' ? includeTimeRaw : Boolean(includeTimeRaw),
|
||||||
};
|
};
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [field, clock, currentUser?.metadata]);
|
}, [field, clock, currentUser?.metadata]);
|
||||||
|
|||||||
Reference in New Issue
Block a user