[DASHBOARDS] Move all the graph computing logic to the backend (#17189)

- Create resolvers for each type of charts which needs data
transformation after the group by operation: Bar Chart, Line Chart and
Pie Chart
- Move all the utils to the backend and refactored some into services

This allows all the computation to be done in the backend, improving
performances in the frontend.
This commit is contained in:
Raphaël Bosi
2026-01-19 18:25:45 +01:00
committed by GitHub
parent 1f1ccb281e
commit d0bc8b9ffe
264 changed files with 12408 additions and 8872 deletions
@@ -0,0 +1,64 @@
import { type MessageDescriptor } from '@lingui/core';
import { msg } from '@lingui/core/macro';
import { assertUnreachable } from 'twenty-shared/utils';
import { CustomException } from 'src/utils/custom-exception';
export enum ChartDataExceptionCode {
WIDGET_NOT_FOUND = 'WIDGET_NOT_FOUND',
INVALID_WIDGET_CONFIGURATION = 'INVALID_WIDGET_CONFIGURATION',
OBJECT_METADATA_NOT_FOUND = 'OBJECT_METADATA_NOT_FOUND',
FIELD_METADATA_NOT_FOUND = 'FIELD_METADATA_NOT_FOUND',
QUERY_EXECUTION_FAILED = 'QUERY_EXECUTION_FAILED',
TRANSFORMATION_FAILED = 'TRANSFORMATION_FAILED',
}
const getChartDataExceptionUserFriendlyMessage = (
code: ChartDataExceptionCode,
): MessageDescriptor => {
switch (code) {
case ChartDataExceptionCode.WIDGET_NOT_FOUND:
return msg`Widget not found.`;
case ChartDataExceptionCode.INVALID_WIDGET_CONFIGURATION:
return msg`Invalid widget configuration.`;
case ChartDataExceptionCode.OBJECT_METADATA_NOT_FOUND:
return msg`Object metadata not found.`;
case ChartDataExceptionCode.FIELD_METADATA_NOT_FOUND:
return msg`Field metadata not found.`;
case ChartDataExceptionCode.QUERY_EXECUTION_FAILED:
return msg`Query execution failed.`;
case ChartDataExceptionCode.TRANSFORMATION_FAILED:
return msg`Transformation failed.`;
default:
assertUnreachable(code);
}
};
export class ChartDataException extends CustomException<ChartDataExceptionCode> {
constructor(
message: string,
code: ChartDataExceptionCode,
{ userFriendlyMessage }: { userFriendlyMessage?: MessageDescriptor } = {},
) {
super(message, code, {
userFriendlyMessage:
userFriendlyMessage ?? getChartDataExceptionUserFriendlyMessage(code),
});
}
}
export const generateChartDataExceptionMessage = (
code: ChartDataExceptionCode,
context?: string,
): string => {
const messages: Record<ChartDataExceptionCode, string> = {
[ChartDataExceptionCode.WIDGET_NOT_FOUND]: `Widget not found${context ? `: ${context}` : ''}`,
[ChartDataExceptionCode.INVALID_WIDGET_CONFIGURATION]: `Invalid widget configuration${context ? `: ${context}` : ''}`,
[ChartDataExceptionCode.OBJECT_METADATA_NOT_FOUND]: `Object metadata not found${context ? `: ${context}` : ''}`,
[ChartDataExceptionCode.FIELD_METADATA_NOT_FOUND]: `Field metadata not found${context ? `: ${context}` : ''}`,
[ChartDataExceptionCode.QUERY_EXECUTION_FAILED]: `Query execution failed${context ? `: ${context}` : ''}`,
[ChartDataExceptionCode.TRANSFORMATION_FAILED]: `Transformation failed${context ? `: ${context}` : ''}`,
};
return messages[code];
};