Include Date fields in aggregate operations on dates (#9479)

Follow-up on https://github.com/twentyhq/twenty/pull/9444/files - I had
forgotten to include Date field types (in addition to DateTime)
This commit is contained in:
Marie
2025-01-09 13:13:21 +01:00
committed by GitHub
parent efb2a59e06
commit c535d21587
13 changed files with 176 additions and 40 deletions

View File

@ -13,6 +13,7 @@ import { formatAmount } from '~/utils/format/formatAmount';
import { formatNumber } from '~/utils/format/number';
import { isDefined } from '~/utils/isDefined';
import { formatDateString } from '~/utils/string/formatDateString';
import { formatDateTimeString } from '~/utils/string/formatDateTimeString';
export const computeAggregateValueAndLabel = ({
data,
@ -87,7 +88,7 @@ export const computeAggregateValueAndLabel = ({
case FieldMetadataType.DateTime: {
value = aggregateValue as string;
value = formatDateString({
value = formatDateTimeString({
value,
displayAsRelativeDate,
timeZone,
@ -96,6 +97,17 @@ export const computeAggregateValueAndLabel = ({
});
break;
}
case FieldMetadataType.Date: {
value = aggregateValue as string;
value = formatDateString({
value,
displayAsRelativeDate,
timeZone,
dateFormat,
});
break;
}
}
}
const convertedAggregateOperation =

View File

@ -6,11 +6,13 @@ export const FIELD_TYPES_AVAILABLE_FOR_NON_STANDARD_AGGREGATE_OPERATION = {
FieldMetadataType.Number,
FieldMetadataType.Currency,
FieldMetadataType.DateTime,
FieldMetadataType.Date,
],
[AGGREGATE_OPERATIONS.max]: [
FieldMetadataType.Number,
FieldMetadataType.Currency,
FieldMetadataType.DateTime,
FieldMetadataType.Date,
],
[AGGREGATE_OPERATIONS.avg]: [
FieldMetadataType.Number,

View File

@ -1,12 +1,13 @@
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
import { isFieldMetadataDateKind } from 'twenty-shared';
import { FieldMetadataType } from '~/generated-metadata/graphql';
export const convertAggregateOperationToExtendedAggregateOperation = (
aggregateOperation: AGGREGATE_OPERATIONS,
fieldType?: FieldMetadataType,
): ExtendedAggregateOperations => {
if (fieldType === FieldMetadataType.DateTime) {
if (isFieldMetadataDateKind(fieldType) === true) {
if (aggregateOperation === AGGREGATE_OPERATIONS.min) {
return 'EARLIEST';
}

View File

@ -1,6 +1,6 @@
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
import { capitalize } from 'twenty-shared';
import { capitalize, isFieldMetadataDateKind } from 'twenty-shared';
import { FieldMetadataType } from '~/generated-metadata/graphql';
type NameForAggregation = {
@ -55,7 +55,7 @@ export const getAvailableAggregationsFromObjectFields = (
};
}
if (field.type === FieldMetadataType.DateTime) {
if (isFieldMetadataDateKind(field.type) === true) {
acc[field.name] = {
...acc[field.name],
[AGGREGATE_OPERATIONS.min]: `min${capitalize(field.name)}`,

View File

@ -1,7 +1,6 @@
import { formatDateISOStringToDate } from '@/localization/utils/formatDateISOStringToDate';
import { formatDateISOStringToRelativeDate } from '@/localization/utils/formatDateISOStringToRelativeDate';
import { UserContext } from '@/users/contexts/UserContext';
import { useContext } from 'react';
import { formatDateString } from '~/utils/string/formatDateString';
import { EllipsisDisplay } from './EllipsisDisplay';
type DateDisplayProps = {
@ -15,11 +14,12 @@ export const DateDisplay = ({
}: DateDisplayProps) => {
const { dateFormat, timeZone } = useContext(UserContext);
const formattedDate = value
? displayAsRelativeDate
? formatDateISOStringToRelativeDate(value, true)
: formatDateISOStringToDate(value, timeZone, dateFormat)
: '';
const formattedDate = formatDateString({
value,
timeZone,
dateFormat,
displayAsRelativeDate,
});
return <EllipsisDisplay>{formattedDate}</EllipsisDisplay>;
};

View File

@ -1,6 +1,6 @@
import { UserContext } from '@/users/contexts/UserContext';
import { useContext } from 'react';
import { formatDateString } from '~/utils/string/formatDateString';
import { formatDateTimeString } from '~/utils/string/formatDateTimeString';
import { EllipsisDisplay } from './EllipsisDisplay';
type DateTimeDisplayProps = {
@ -14,7 +14,7 @@ export const DateTimeDisplay = ({
}: DateTimeDisplayProps) => {
const { dateFormat, timeFormat, timeZone } = useContext(UserContext);
const formattedDate = formatDateString({
const formattedDate = formatDateTimeString({
value,
displayAsRelativeDate,
timeZone,