[Dashboards] Relation fields groupby (#16093)

This commit is contained in:
nitin
2025-11-28 00:58:53 +05:30
committed by GitHub
parent f23aa632a7
commit fa87603fd8
22 changed files with 597 additions and 136 deletions
@@ -8,9 +8,12 @@ import {
type FirstDayOfTheWeek,
ObjectRecordGroupByDateGranularity,
} from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { isDefined, isFieldMetadataDateKind } from 'twenty-shared/utils';
import { FieldMetadataType } from '~/generated-metadata/graphql';
export type GroupByFieldObject = Record<
string,
boolean | Record<string, boolean | string | Record<string, boolean | string>>
>;
export const buildGroupByFieldObject = ({
field,
@@ -22,15 +25,35 @@ export const buildGroupByFieldObject = ({
subFieldName?: string | null;
dateGranularity?: ObjectRecordGroupByDateGranularity;
firstDayOfTheWeek?: number | null;
}): Record<string, boolean | Record<string, boolean | string>> => {
}): GroupByFieldObject => {
const isRelation = isFieldRelation(field) || isFieldMorphRelation(field);
const isComposite = isCompositeFieldType(field.type);
const isDateField =
field.type === FieldMetadataType.DATE ||
field.type === FieldMetadataType.DATE_TIME;
const isDateField = isFieldMetadataDateKind(field.type);
if (isRelation) {
return { [`${field.name}Id`]: true };
if (!isDefined(subFieldName)) {
return { [`${field.name}Id`]: true };
}
const parts = subFieldName.split('.');
const nestedFieldName = parts[0];
const nestedSubFieldName = parts[1];
if (isDefined(nestedSubFieldName)) {
return {
[field.name]: {
[nestedFieldName]: {
[nestedSubFieldName]: true,
},
},
};
}
return {
[field.name]: {
[nestedFieldName]: true,
},
};
}
if (isComposite) {