[Dashboards] Relation fields groupby (#16093)
This commit is contained in:
+30
-7
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user