Skip to content

The open alternative to Salesforce, designed for AI.

2.0 KB
Raw Blame
import { getDateGranularityPluralLabel } from '@/side-panel/pages/page-layout/utils/getDateGranularityPluralLabel';
import { BAR_CHART_CONSTANTS } from '@/page-layout/widgets/graph/graph-widget-bar-chart/constants/BarChartConstants';
import { LINE_CHART_CONSTANTS } from '@/page-layout/widgets/graph/graph-widget-line-chart/constants/LineChartConstants';
import { PIE_CHART_MAXIMUM_NUMBER_OF_SLICES } from '@/page-layout/widgets/graph/graph-widget-pie-chart/constants/PieChartMaximumNumberOfSlices';
import { t } from '@lingui/core/macro';
import { type ObjectRecordGroupByDateGranularity } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { WidgetConfigurationType } from '~/generated-metadata/graphql';

type GetChartLimitMessageParams = {
  widgetConfigurationType: WidgetConfigurationType;
  isPrimaryAxisDate: boolean;
  primaryAxisDateGranularity:
    | ObjectRecordGroupByDateGranularity
    | null
    | undefined;
};

export const getChartLimitMessage = ({
  widgetConfigurationType,
  isPrimaryAxisDate,
  primaryAxisDateGranularity,
}: GetChartLimitMessageParams): string => {
  const maxItems =
    widgetConfigurationType === WidgetConfigurationType.LINE_CHART
      ? LINE_CHART_CONSTANTS.MAXIMUM_NUMBER_OF_DATA_POINTS
      : widgetConfigurationType === WidgetConfigurationType.BAR_CHART
        ? BAR_CHART_CONSTANTS.MAXIMUM_NUMBER_OF_BARS
        : PIE_CHART_MAXIMUM_NUMBER_OF_SLICES;

  if (isPrimaryAxisDate && isDefined(primaryAxisDateGranularity)) {
    const granularityLabel = getDateGranularityPluralLabel(
      primaryAxisDateGranularity,
    );
    return t`Undisplayed data: max ${maxItems} ${granularityLabel} per chart.`;
  }

  if (widgetConfigurationType === WidgetConfigurationType.LINE_CHART) {
    return t`Undisplayed data: max ${maxItems} data points per chart.`;
  }

  if (widgetConfigurationType === WidgetConfigurationType.BAR_CHART) {
    return t`Undisplayed data: max ${maxItems} bars per chart.`;
  }

  return t`Undisplayed data: max ${maxItems} slices per chart.`;
};