Fix bug with table aggregate footer when switching object (#10198)
This PR fixes a bug that happens when switching from an object to another. It is a temporary fix because it fixes a problem downstream, that shouldn't happen, but it is tied to the new implementation of the main context store. We should find a way to have context store states defined earlier because it might impact logic that was developed during the previous months that didn't anticipated the state of current view id taking more re-renders to be correctly set between page change / table change.
This commit is contained in:
@ -5,13 +5,16 @@ import { computeViewRecordGqlOperationFilter } from '@/object-record/record-filt
|
||||
import { useRecordGroupFilter } from '@/object-record/record-group/hooks/useRecordGroupFilter';
|
||||
import { recordIndexFiltersState } from '@/object-record/record-index/states/recordIndexFiltersState';
|
||||
import { recordIndexViewFilterGroupsState } from '@/object-record/record-index/states/recordIndexViewFilterGroupsState';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
|
||||
import { RecordTableColumnAggregateFooterCellContext } from '@/object-record/record-table/record-table-footer/components/RecordTableColumnAggregateFooterCellContext';
|
||||
import { viewFieldAggregateOperationState } from '@/object-record/record-table/record-table-footer/states/viewFieldAggregateOperationState';
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { convertAggregateOperationToExtendedAggregateOperation } from '@/object-record/utils/convertAggregateOperationToExtendedAggregateOperation';
|
||||
import { UserContext } from '@/users/contexts/UserContext';
|
||||
import { useContext } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { isDefined, isFieldMetadataDateKind } from 'twenty-shared';
|
||||
|
||||
export const useAggregateRecordsForRecordTableColumnFooter = (
|
||||
fieldMetadataId: string,
|
||||
@ -37,13 +40,37 @@ export const useAggregateRecordsForRecordTableColumnFooter = (
|
||||
const { viewFieldId } = useContext(
|
||||
RecordTableColumnAggregateFooterCellContext,
|
||||
);
|
||||
const aggregateOperationForViewField = useRecoilValue(
|
||||
viewFieldAggregateOperationState({ viewFieldId }),
|
||||
|
||||
const fieldMetadataItem = objectMetadataItem.fields.find(
|
||||
(field) => field.id === fieldMetadataId,
|
||||
);
|
||||
|
||||
const fieldName = objectMetadataItem.fields.find(
|
||||
(field) => field.id === fieldMetadataId,
|
||||
)?.name;
|
||||
// TODO: This shouldn't be set with impossible values,
|
||||
// see problem with view id not being set early enoughby Effect component in context store,
|
||||
// This happens here when switching from a view to another.
|
||||
const aggregateOperationForViewFieldWithProbableImpossibleValues =
|
||||
useRecoilValue(viewFieldAggregateOperationState({ viewFieldId }));
|
||||
|
||||
const isAggregateOperationImpossibleForDateField =
|
||||
isDefined(fieldMetadataItem) &&
|
||||
isFieldMetadataDateKind(fieldMetadataItem.type) &&
|
||||
isDefined(aggregateOperationForViewFieldWithProbableImpossibleValues) &&
|
||||
(aggregateOperationForViewFieldWithProbableImpossibleValues ===
|
||||
AGGREGATE_OPERATIONS.min ||
|
||||
aggregateOperationForViewFieldWithProbableImpossibleValues ===
|
||||
AGGREGATE_OPERATIONS.max);
|
||||
|
||||
const aggregateOperationForViewField:
|
||||
| ExtendedAggregateOperations
|
||||
| undefined
|
||||
| null = isAggregateOperationImpossibleForDateField
|
||||
? convertAggregateOperationToExtendedAggregateOperation(
|
||||
aggregateOperationForViewFieldWithProbableImpossibleValues,
|
||||
fieldMetadataItem.type,
|
||||
)
|
||||
: aggregateOperationForViewFieldWithProbableImpossibleValues;
|
||||
|
||||
const fieldName = fieldMetadataItem?.name;
|
||||
|
||||
const recordGqlFieldsAggregate =
|
||||
isDefined(aggregateOperationForViewField) && isDefined(fieldName)
|
||||
|
||||
Reference in New Issue
Block a user