875dc1a6b8
Closes https://github.com/twentyhq/core-team-issues/issues/1535 Video QA: https://github.com/user-attachments/assets/153fa3f1-08d9-4952-9456-635c602e1f57 https://github.com/user-attachments/assets/d3111afb-4c84-4f57-8a56-5cf666748c86 There are still some formatting and design issues (the labels which are on top of each other and the values which should be formatted) that will be fixed in a future PR --------- Co-authored-by: ehconitin <nitinkoche03@gmail.com>
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
|
import { isCompositeFieldType } from '@/object-record/object-filter-dropdown/utils/isCompositeFieldType';
|
|
import { isFieldMorphRelation } from '@/object-record/record-field/ui/types/guards/isFieldMorphRelation';
|
|
import { isFieldRelation } from '@/object-record/record-field/ui/types/guards/isFieldRelation';
|
|
import { GRAPH_DEFAULT_DATE_GRANULARITY } from '@/page-layout/widgets/graph/constants/GraphDefaultDateGranularity.constant';
|
|
import { type ObjectRecordGroupByDateGranularity } from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|
|
|
export const buildGroupByFieldObject = ({
|
|
field,
|
|
subFieldName,
|
|
dateGranularity,
|
|
}: {
|
|
field: FieldMetadataItem;
|
|
subFieldName?: string | null;
|
|
dateGranularity?: ObjectRecordGroupByDateGranularity;
|
|
}): Record<string, boolean | Record<string, boolean | string>> => {
|
|
const isRelation = isFieldRelation(field) || isFieldMorphRelation(field);
|
|
const isComposite = isCompositeFieldType(field.type);
|
|
const isDateField =
|
|
field.type === FieldMetadataType.DATE ||
|
|
field.type === FieldMetadataType.DATE_TIME;
|
|
|
|
if (isRelation) {
|
|
return { [`${field.name}Id`]: true };
|
|
}
|
|
|
|
if (isComposite) {
|
|
if (!isDefined(subFieldName)) {
|
|
throw new Error(
|
|
`Composite field ${field.name} requires a subfield to be specified`,
|
|
);
|
|
}
|
|
return {
|
|
[field.name]: {
|
|
[subFieldName]: true,
|
|
},
|
|
};
|
|
}
|
|
|
|
if (isDateField) {
|
|
return {
|
|
[field.name]: {
|
|
granularity: dateGranularity ?? GRAPH_DEFAULT_DATE_GRANULARITY,
|
|
},
|
|
};
|
|
}
|
|
|
|
return { [field.name]: true };
|
|
};
|