Use aggregate operations in the widget configuration instead of extended aggregate operations (#15248)
- Use aggregate operations in the widget configuration instead of extended aggregate operations - Use aggregate operation from generated graphql in the frontend
This commit is contained in:
+17
-8
@@ -1,11 +1,10 @@
|
||||
import { usePageLayoutIdFromContextStoreTargetedRecord } from '@/command-menu/pages/page-layout/hooks/usePageLayoutFromContextStoreTargetedRecord';
|
||||
import { useUpdateCurrentWidgetConfig } from '@/command-menu/pages/page-layout/hooks/useUpdateCurrentWidgetConfig';
|
||||
import { useWidgetInEditMode } from '@/command-menu/pages/page-layout/hooks/useWidgetInEditMode';
|
||||
import { mapToGraphQLExtendedAggregateOperation } from '@/command-menu/pages/page-layout/utils/mapToGraphQLExtendedAggregateOperation';
|
||||
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
|
||||
import { getAggregateOperationLabel } from '@/object-record/record-board/record-board-column/utils/getAggregateOperationLabel';
|
||||
import { getAvailableAggregateOperationsForFieldMetadataType } from '@/object-record/record-table/record-table-footer/utils/getAvailableAggregateOperationsForFieldMetadataType';
|
||||
import { type ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { convertExtendedAggregateOperationToAggregateOperation } from '@/object-record/utils/convertExtendedAggregateOperationToAggregateOperation';
|
||||
import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader/DropdownMenuHeader';
|
||||
import { DropdownMenuHeaderLeftComponent } from '@/ui/layout/dropdown/components/DropdownMenuHeader/internal/DropdownMenuHeaderLeftComponent';
|
||||
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
|
||||
@@ -23,6 +22,7 @@ import { useState } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { IconChevronLeft } from 'twenty-ui/display';
|
||||
import { MenuItemSelect } from 'twenty-ui/navigation';
|
||||
import { type AggregateOperations } from '~/generated/graphql';
|
||||
import { filterBySearchQuery } from '~/utils/filterBySearchQuery';
|
||||
|
||||
export const ChartAggregateOperationSelectionDropdownContent = ({
|
||||
@@ -94,13 +94,12 @@ export const ChartAggregateOperationSelectionDropdownContent = ({
|
||||
}
|
||||
|
||||
const handleSelectAggregateOperation = (
|
||||
aggregateOperation: ExtendedAggregateOperations,
|
||||
aggregateOperation: AggregateOperations,
|
||||
) => {
|
||||
updateCurrentWidgetConfig({
|
||||
configToUpdate: {
|
||||
aggregateFieldMetadataId: currentFieldMetadataId,
|
||||
aggregateOperation:
|
||||
mapToGraphQLExtendedAggregateOperation(aggregateOperation),
|
||||
aggregateOperation,
|
||||
},
|
||||
});
|
||||
closeDropdown();
|
||||
@@ -139,18 +138,28 @@ export const ChartAggregateOperationSelectionDropdownContent = ({
|
||||
key={item.operation}
|
||||
itemId={item.operation}
|
||||
onEnter={() => {
|
||||
handleSelectAggregateOperation(item.operation);
|
||||
handleSelectAggregateOperation(
|
||||
convertExtendedAggregateOperationToAggregateOperation(
|
||||
item.operation,
|
||||
),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<MenuItemSelect
|
||||
text={item.label}
|
||||
selected={
|
||||
currentAggregateOperation ===
|
||||
mapToGraphQLExtendedAggregateOperation(item.operation)
|
||||
convertExtendedAggregateOperationToAggregateOperation(
|
||||
item.operation,
|
||||
)
|
||||
}
|
||||
focused={selectedItemId === item.operation}
|
||||
onClick={() => {
|
||||
handleSelectAggregateOperation(item.operation);
|
||||
handleSelectAggregateOperation(
|
||||
convertExtendedAggregateOperationToAggregateOperation(
|
||||
item.operation,
|
||||
),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</SelectableListItem>
|
||||
|
||||
+3
-3
@@ -6,10 +6,10 @@ import { CHART_CONFIGURATION_SETTING_IDS } from '@/command-menu/pages/page-layou
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import {
|
||||
AggregateOperations,
|
||||
AxisNameDisplay,
|
||||
type BarChartConfiguration,
|
||||
BarChartGroupMode,
|
||||
ExtendedAggregateOperations,
|
||||
FieldMetadataType,
|
||||
GraphOrderBy,
|
||||
GraphType,
|
||||
@@ -64,7 +64,7 @@ const buildBarChartConfiguration = (
|
||||
({
|
||||
__typename: 'BarChartConfiguration',
|
||||
aggregateFieldMetadataId: 'field-amount',
|
||||
aggregateOperation: ExtendedAggregateOperations.SUM,
|
||||
aggregateOperation: AggregateOperations.SUM,
|
||||
graphType: GraphType.VERTICAL_BAR,
|
||||
primaryAxisGroupByFieldMetadataId: 'field-company-name',
|
||||
primaryAxisGroupBySubFieldName: null,
|
||||
@@ -545,7 +545,7 @@ describe('useChartSettingsValues', () => {
|
||||
primaryAxisGroupByFieldMetadataId: 'field-company-name',
|
||||
secondaryAxisGroupByFieldMetadataId: 'field-stage',
|
||||
aggregateFieldMetadataId: 'field-amount',
|
||||
aggregateOperation: ExtendedAggregateOperations.SUM,
|
||||
aggregateOperation: AggregateOperations.SUM,
|
||||
primaryAxisOrderBy: GraphOrderBy.FIELD_ASC,
|
||||
secondaryAxisOrderBy: GraphOrderBy.FIELD_DESC,
|
||||
axisNameDisplay: AxisNameDisplay.BOTH,
|
||||
|
||||
+2
-4
@@ -1,14 +1,12 @@
|
||||
import { getFieldLabelWithSubField } from '@/command-menu/pages/page-layout/utils/getFieldLabelWithSubField';
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { getAggregateOperationLabel } from '@/object-record/record-board/record-board-column/utils/getAggregateOperationLabel';
|
||||
import { type ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { type CompositeFieldSubFieldName } from 'twenty-shared/types';
|
||||
import { assertUnreachable, isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
type ExtendedAggregateOperations,
|
||||
GraphOrderBy,
|
||||
} from '~/generated/graphql';
|
||||
import { GraphOrderBy } from '~/generated/graphql';
|
||||
|
||||
export const useGraphXSortOptionLabels = ({
|
||||
objectMetadataId,
|
||||
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { type ExtendedAggregateOperations as FrontendExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { ExtendedAggregateOperations as GraphQLExtendedAggregateOperations } from '~/generated-metadata/graphql';
|
||||
|
||||
const AGGREGATE_OPERATION_MAPPING: Record<
|
||||
FrontendExtendedAggregateOperations,
|
||||
GraphQLExtendedAggregateOperations
|
||||
> = {
|
||||
[AggregateOperations.MIN]: GraphQLExtendedAggregateOperations.MIN,
|
||||
[AggregateOperations.MAX]: GraphQLExtendedAggregateOperations.MAX,
|
||||
[AggregateOperations.AVG]: GraphQLExtendedAggregateOperations.AVG,
|
||||
[AggregateOperations.SUM]: GraphQLExtendedAggregateOperations.SUM,
|
||||
[AggregateOperations.COUNT]: GraphQLExtendedAggregateOperations.COUNT,
|
||||
[AggregateOperations.COUNT_EMPTY]:
|
||||
GraphQLExtendedAggregateOperations.COUNT_EMPTY,
|
||||
[AggregateOperations.COUNT_NOT_EMPTY]:
|
||||
GraphQLExtendedAggregateOperations.COUNT_NOT_EMPTY,
|
||||
[AggregateOperations.COUNT_UNIQUE_VALUES]:
|
||||
GraphQLExtendedAggregateOperations.COUNT_UNIQUE_VALUES,
|
||||
[AggregateOperations.PERCENTAGE_EMPTY]:
|
||||
GraphQLExtendedAggregateOperations.PERCENTAGE_EMPTY,
|
||||
[AggregateOperations.PERCENTAGE_NOT_EMPTY]:
|
||||
GraphQLExtendedAggregateOperations.PERCENTAGE_NOT_EMPTY,
|
||||
[AggregateOperations.COUNT_TRUE]:
|
||||
GraphQLExtendedAggregateOperations.COUNT_TRUE,
|
||||
[AggregateOperations.COUNT_FALSE]:
|
||||
GraphQLExtendedAggregateOperations.COUNT_FALSE,
|
||||
[DateAggregateOperations.EARLIEST]:
|
||||
GraphQLExtendedAggregateOperations.EARLIEST,
|
||||
[DateAggregateOperations.LATEST]: GraphQLExtendedAggregateOperations.LATEST,
|
||||
};
|
||||
|
||||
export const mapToGraphQLExtendedAggregateOperation = (
|
||||
operation: FrontendExtendedAggregateOperations,
|
||||
): GraphQLExtendedAggregateOperations => {
|
||||
return AGGREGATE_OPERATION_MAPPING[operation];
|
||||
};
|
||||
Reference in New Issue
Block a user