4135a6473a
# Introduction In this pull-request we're refactoring the page layout widget configuration entity to be containing its discriminated key simplifying underlying code and maintainability - Made the configuration and title non nullable - Introduced a generic predicate for the `widgetConfigurationType` - Upgraded command to remove `graphType` and insert new `configurationType` to existing entries - Migrated frontend to new type system --------- Co-authored-by: bosiraphael <raphael.bosi@gmail.com> Co-authored-by: Raphaël Bosi <71827178+bosiraphael@users.noreply.github.com>
48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
import { getDateGranularityPluralLabel } from '@/command-menu/pages/page-layout/utils/getDateGranularityPluralLabel';
|
|
import { BAR_CHART_CONSTANTS } from '@/page-layout/widgets/graph/graphWidgetBarChart/constants/BarChartConstants';
|
|
import { LINE_CHART_CONSTANTS } from '@/page-layout/widgets/graph/graphWidgetLineChart/constants/LineChartConstants';
|
|
import { PIE_CHART_MAXIMUM_NUMBER_OF_SLICES } from '@/page-layout/widgets/graph/graphWidgetPieChart/constants/PieChartMaximumNumberOfSlices.constant';
|
|
import { t } from '@lingui/core/macro';
|
|
import { type ObjectRecordGroupByDateGranularity } from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { WidgetConfigurationType } from '~/generated/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.`;
|
|
};
|