473efb5dc5
Closes https://github.com/twentyhq/core-team-issues/issues/1727 <img width="1415" height="625" alt="image" src="https://github.com/user-attachments/assets/cd132582-4a95-463c-8946-87b77670e023" />
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import gql from 'graphql-tag';
|
|
import { capitalize } from 'twenty-shared/utils';
|
|
|
|
type GroupByOperationFactoryParams = {
|
|
objectMetadataSingularName: string;
|
|
objectMetadataPluralName: string;
|
|
orderByForRecords?: object[];
|
|
groupBy: object[];
|
|
filter?: object;
|
|
orderBy?: object[];
|
|
viewId?: string;
|
|
gqlFields?: string;
|
|
};
|
|
|
|
export const groupByOperationFactory = ({
|
|
objectMetadataSingularName,
|
|
objectMetadataPluralName,
|
|
groupBy,
|
|
filter = {},
|
|
orderBy = [],
|
|
orderByForRecords = [],
|
|
viewId,
|
|
gqlFields,
|
|
}: GroupByOperationFactoryParams) => ({
|
|
query: gql`
|
|
query ${capitalize(objectMetadataPluralName)}GroupBy($groupBy: [${capitalize(objectMetadataSingularName)}GroupByInput!]!, $filter: ${capitalize(objectMetadataSingularName)}FilterInput, $orderBy: [${capitalize(objectMetadataSingularName)}OrderByWithGroupByInput!], $viewId: UUID) {
|
|
${objectMetadataPluralName}GroupBy(groupBy: $groupBy, filter: $filter, orderBy: $orderBy, viewId: $viewId) {
|
|
${gqlFields ? gqlFields : ''}
|
|
groupByDimensionValues
|
|
totalCount
|
|
}
|
|
}
|
|
`,
|
|
variables: {
|
|
groupBy,
|
|
filter,
|
|
orderBy,
|
|
orderByForRecords,
|
|
...(viewId && { viewId }),
|
|
},
|
|
});
|