Update enums to be all caps (#12372)
- Make custom domain public (remove from lab) - Use ALL_CAPS definition for enums
This commit is contained in:
@ -5,7 +5,7 @@ import {
|
||||
} from '@/object-record/hooks/__mocks__/useAggregateRecords';
|
||||
import { useAggregateRecords } from '@/object-record/hooks/useAggregateRecords';
|
||||
import { useAggregateRecordsQuery } from '@/object-record/hooks/useAggregateRecordsQuery';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
@ -20,9 +20,9 @@ const mockObjectMetadataItem = {
|
||||
};
|
||||
|
||||
const mockGqlFieldToFieldMap = {
|
||||
sumAmount: ['amount', AGGREGATE_OPERATIONS.sum],
|
||||
avgAmount: ['amount', AGGREGATE_OPERATIONS.avg],
|
||||
totalCount: ['name', AGGREGATE_OPERATIONS.count],
|
||||
sumAmount: ['amount', AggregateOperations.SUM],
|
||||
avgAmount: ['amount', AggregateOperations.AVG],
|
||||
totalCount: ['name', AggregateOperations.COUNT],
|
||||
};
|
||||
|
||||
describe('useAggregateRecords', () => {
|
||||
@ -48,19 +48,19 @@ describe('useAggregateRecords', () => {
|
||||
useAggregateRecords({
|
||||
objectNameSingular: 'opportunity',
|
||||
recordGqlFieldsAggregate: {
|
||||
amount: [AGGREGATE_OPERATIONS.sum, AGGREGATE_OPERATIONS.avg],
|
||||
name: [AGGREGATE_OPERATIONS.count],
|
||||
amount: [AggregateOperations.SUM, AggregateOperations.AVG],
|
||||
name: [AggregateOperations.COUNT],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.current.data).toEqual({
|
||||
amount: {
|
||||
[AGGREGATE_OPERATIONS.sum]: 1000000,
|
||||
[AGGREGATE_OPERATIONS.avg]: 23800,
|
||||
[AggregateOperations.SUM]: 1000000,
|
||||
[AggregateOperations.AVG]: 23800,
|
||||
},
|
||||
name: {
|
||||
[AGGREGATE_OPERATIONS.count]: 42,
|
||||
[AggregateOperations.COUNT]: 42,
|
||||
},
|
||||
});
|
||||
expect(result.current.loading).toBe(false);
|
||||
@ -78,7 +78,7 @@ describe('useAggregateRecords', () => {
|
||||
useAggregateRecords({
|
||||
objectNameSingular: 'opportunity',
|
||||
recordGqlFieldsAggregate: {
|
||||
amount: [AGGREGATE_OPERATIONS.sum],
|
||||
amount: [AggregateOperations.SUM],
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -99,7 +99,7 @@ describe('useAggregateRecords', () => {
|
||||
useAggregateRecords({
|
||||
objectNameSingular: 'opportunity',
|
||||
recordGqlFieldsAggregate: {
|
||||
amount: [AGGREGATE_OPERATIONS.sum],
|
||||
amount: [AggregateOperations.SUM],
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -113,7 +113,7 @@ describe('useAggregateRecords', () => {
|
||||
useAggregateRecords({
|
||||
objectNameSingular: 'opportunity',
|
||||
recordGqlFieldsAggregate: {
|
||||
amount: [AGGREGATE_OPERATIONS.sum],
|
||||
amount: [AggregateOperations.SUM],
|
||||
},
|
||||
skip: true,
|
||||
}),
|
||||
|
||||
@ -2,7 +2,7 @@ import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadata
|
||||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { useAggregateRecordsQuery } from '@/object-record/hooks/useAggregateRecordsQuery';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { generateAggregateQuery } from '@/object-record/utils/generateAggregateQuery';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { FieldMetadataType } from '~/generated/graphql';
|
||||
@ -71,7 +71,7 @@ describe('useAggregateRecordsQuery', () => {
|
||||
useAggregateRecordsQuery({
|
||||
objectNameSingular: 'company',
|
||||
recordGqlFieldsAggregate: {
|
||||
name: [AGGREGATE_OPERATIONS.count],
|
||||
name: [AggregateOperations.COUNT],
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -92,7 +92,7 @@ describe('useAggregateRecordsQuery', () => {
|
||||
useAggregateRecordsQuery({
|
||||
objectNameSingular: 'company',
|
||||
recordGqlFieldsAggregate: {
|
||||
amount: [AGGREGATE_OPERATIONS.sum],
|
||||
amount: [AggregateOperations.SUM],
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -115,7 +115,7 @@ describe('useAggregateRecordsQuery', () => {
|
||||
useAggregateRecordsQuery({
|
||||
objectNameSingular: 'company',
|
||||
recordGqlFieldsAggregate: {
|
||||
name: [AGGREGATE_OPERATIONS.sum],
|
||||
name: [AggregateOperations.SUM],
|
||||
},
|
||||
}),
|
||||
),
|
||||
@ -127,8 +127,8 @@ describe('useAggregateRecordsQuery', () => {
|
||||
useAggregateRecordsQuery({
|
||||
objectNameSingular: 'company',
|
||||
recordGqlFieldsAggregate: {
|
||||
amount: [AGGREGATE_OPERATIONS.sum],
|
||||
name: [AGGREGATE_OPERATIONS.count],
|
||||
amount: [AggregateOperations.SUM],
|
||||
name: [AggregateOperations.COUNT],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@ -3,7 +3,7 @@ import { RecordBoardColumnHeaderAggregateDropdownContext } from '@/object-record
|
||||
import { RecordBoardColumnHeaderAggregateDropdownFieldsContent } from '@/object-record/record-board/record-board-column/components/RecordBoardColumnHeaderAggregateDropdownFieldsContent';
|
||||
import { RecordBoardColumnHeaderAggregateDropdownMenuContent } from '@/object-record/record-board/record-board-column/components/RecordBoardColumnHeaderAggregateDropdownMenuContent';
|
||||
import { RecordBoardColumnHeaderAggregateDropdownOptionsContent } from '@/object-record/record-board/record-board-column/components/RecordBoardColumnHeaderAggregateDropdownOptionsContent';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { COUNT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/countAggregateOperationOptions';
|
||||
import { NON_STANDARD_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/nonStandardAggregateOperationsOptions';
|
||||
import { PERCENT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/percentAggregateOperationOptions';
|
||||
@ -47,10 +47,7 @@ export const AggregateDropdownContent = () => {
|
||||
const datesAvailableAggregations: AvailableFieldsForAggregateOperation =
|
||||
getAvailableFieldsIdsForAggregationFromObjectFields(
|
||||
objectMetadataItem.fields,
|
||||
[
|
||||
DATE_AGGREGATE_OPERATIONS.earliest,
|
||||
DATE_AGGREGATE_OPERATIONS.latest,
|
||||
],
|
||||
[DateAggregateOperations.EARLIEST, DateAggregateOperations.LATEST],
|
||||
);
|
||||
return (
|
||||
<RecordBoardColumnHeaderAggregateDropdownOptionsContent
|
||||
|
||||
@ -8,7 +8,7 @@ import { aggregateOperationComponentState } from '@/object-record/record-board/r
|
||||
import { availableFieldIdsForAggregateOperationComponentState } from '@/object-record/record-board/record-board-column/states/availableFieldIdsForAggregateOperationComponentState';
|
||||
import { getAggregateOperationLabel } from '@/object-record/record-board/record-board-column/utils/getAggregateOperationLabel';
|
||||
import { recordIndexKanbanAggregateOperationState } from '@/object-record/record-index/states/recordIndexKanbanAggregateOperationState';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { TableOptionsHotkeyScope } from '@/object-record/record-table/types/TableOptionsHotkeyScope';
|
||||
import { AvailableFieldsForAggregateOperation } from '@/object-record/types/AvailableFieldsForAggregateOperation';
|
||||
@ -82,7 +82,7 @@ export const RecordBoardColumnHeaderAggregateDropdownOptionsContent = ({
|
||||
key={`aggregate-dropdown-menu-content-${availableAggregationOperation}`}
|
||||
onContentChange={() => {
|
||||
if (
|
||||
availableAggregationOperation !== AGGREGATE_OPERATIONS.count
|
||||
availableAggregationOperation !== AggregateOperations.COUNT
|
||||
) {
|
||||
setAggregateOperation(
|
||||
availableAggregationOperation as ExtendedAggregateOperations,
|
||||
@ -97,7 +97,7 @@ export const RecordBoardColumnHeaderAggregateDropdownOptionsContent = ({
|
||||
kanbanAggregateOperationFieldMetadataId:
|
||||
availableAggregationFieldsIdsForOperation[0],
|
||||
kanbanAggregateOperation:
|
||||
availableAggregationOperation as AGGREGATE_OPERATIONS,
|
||||
availableAggregationOperation as AggregateOperations,
|
||||
});
|
||||
closeDropdown();
|
||||
}
|
||||
@ -106,15 +106,14 @@ export const RecordBoardColumnHeaderAggregateDropdownOptionsContent = ({
|
||||
availableAggregationOperation as ExtendedAggregateOperations,
|
||||
)}
|
||||
hasSubMenu={
|
||||
availableAggregationOperation === AGGREGATE_OPERATIONS.count
|
||||
availableAggregationOperation === AggregateOperations.COUNT
|
||||
? false
|
||||
: true
|
||||
}
|
||||
RightIcon={
|
||||
availableAggregationOperation ===
|
||||
AGGREGATE_OPERATIONS.count &&
|
||||
availableAggregationOperation === AggregateOperations.COUNT &&
|
||||
recordIndexKanbanAggregateOperation?.operation ===
|
||||
AGGREGATE_OPERATIONS.count
|
||||
AggregateOperations.COUNT
|
||||
? IconCheck
|
||||
: undefined
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { buildRecordGqlFieldsAggregateForView } from '@/object-record/record-board/record-board-column/utils/buildRecordGqlFieldsAggregateForView';
|
||||
import { KanbanAggregateOperation } from '@/object-record/record-index/states/recordIndexKanbanAggregateOperationState';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
const MOCK_FIELD_ID = '7d2d7b5e-7b3e-4b4a-8b0a-7b3e4b4a8b0a';
|
||||
@ -47,7 +47,7 @@ describe('buildRecordGqlFieldsAggregateForView', () => {
|
||||
it('should build fields for numeric aggregate', () => {
|
||||
const kanbanAggregateOperation: KanbanAggregateOperation = {
|
||||
fieldMetadataId: MOCK_FIELD_ID,
|
||||
operation: AGGREGATE_OPERATIONS.sum,
|
||||
operation: AggregateOperations.SUM,
|
||||
};
|
||||
|
||||
const result = buildRecordGqlFieldsAggregateForView({
|
||||
@ -56,14 +56,14 @@ describe('buildRecordGqlFieldsAggregateForView', () => {
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
amount: [AGGREGATE_OPERATIONS.sum],
|
||||
amount: [AggregateOperations.SUM],
|
||||
});
|
||||
});
|
||||
|
||||
it('should default to count when no field is found', () => {
|
||||
const operation: KanbanAggregateOperation = {
|
||||
fieldMetadataId: 'non-existent-id',
|
||||
operation: AGGREGATE_OPERATIONS.count,
|
||||
operation: AggregateOperations.COUNT,
|
||||
};
|
||||
|
||||
const result = buildRecordGqlFieldsAggregateForView({
|
||||
@ -72,14 +72,14 @@ describe('buildRecordGqlFieldsAggregateForView', () => {
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
id: [AGGREGATE_OPERATIONS.count],
|
||||
id: [AggregateOperations.COUNT],
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw error for non-count operation with invalid field', () => {
|
||||
const operation: KanbanAggregateOperation = {
|
||||
fieldMetadataId: 'non-existent-id',
|
||||
operation: AGGREGATE_OPERATIONS.sum,
|
||||
operation: AggregateOperations.SUM,
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
@ -88,7 +88,7 @@ describe('buildRecordGqlFieldsAggregateForView', () => {
|
||||
recordIndexKanbanAggregateOperation: operation,
|
||||
}),
|
||||
).toThrow(
|
||||
`No field found to compute aggregate operation ${AGGREGATE_OPERATIONS.sum} on object ${mockObjectMetadata.nameSingular}`,
|
||||
`No field found to compute aggregate operation ${AggregateOperations.SUM} on object ${mockObjectMetadata.nameSingular}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,8 +4,8 @@ import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { AggregateRecordsData } from '@/object-record/hooks/useAggregateRecords';
|
||||
import { computeAggregateValueAndLabel } from '@/object-record/record-board/record-board-column/utils/computeAggregateValueAndLabel';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { enUS } from 'date-fns/locale';
|
||||
import { FieldMetadataType } from '~/generated/graphql';
|
||||
|
||||
@ -35,7 +35,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
data: {} as AggregateRecordsData,
|
||||
objectMetadataItem: mockObjectMetadata,
|
||||
fieldMetadataId: MOCK_FIELD_ID,
|
||||
aggregateOperation: AGGREGATE_OPERATIONS.sum,
|
||||
aggregateOperation: AggregateOperations.SUM,
|
||||
localeCatalog: enUS,
|
||||
...defaultParams,
|
||||
});
|
||||
@ -46,7 +46,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
it('should handle currency field with division by 1M', () => {
|
||||
const mockData = {
|
||||
amount: {
|
||||
[AGGREGATE_OPERATIONS.sum]: 2000000,
|
||||
[AggregateOperations.SUM]: 2000000,
|
||||
},
|
||||
} as AggregateRecordsData;
|
||||
|
||||
@ -54,7 +54,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
data: mockData,
|
||||
objectMetadataItem: mockObjectMetadata,
|
||||
fieldMetadataId: MOCK_FIELD_ID,
|
||||
aggregateOperation: AGGREGATE_OPERATIONS.sum,
|
||||
aggregateOperation: AggregateOperations.SUM,
|
||||
localeCatalog: enUS,
|
||||
...defaultParams,
|
||||
});
|
||||
@ -84,7 +84,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
|
||||
const mockData = {
|
||||
percentage: {
|
||||
[AGGREGATE_OPERATIONS.avg]: 0.3,
|
||||
[AggregateOperations.AVG]: 0.3,
|
||||
},
|
||||
} as AggregateRecordsData;
|
||||
|
||||
@ -92,7 +92,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
data: mockData,
|
||||
objectMetadataItem: mockObjectMetadataWithPercentageField,
|
||||
fieldMetadataId: MOCK_FIELD_ID,
|
||||
aggregateOperation: AGGREGATE_OPERATIONS.avg,
|
||||
aggregateOperation: AggregateOperations.AVG,
|
||||
localeCatalog: enUS,
|
||||
...defaultParams,
|
||||
});
|
||||
@ -122,7 +122,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
|
||||
const mockData = {
|
||||
decimals: {
|
||||
[AGGREGATE_OPERATIONS.sum]: 0.009,
|
||||
[AggregateOperations.SUM]: 0.009,
|
||||
},
|
||||
} as AggregateRecordsData;
|
||||
|
||||
@ -130,7 +130,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
data: mockData,
|
||||
objectMetadataItem: mockObjectMetadataWithDecimalsField,
|
||||
fieldMetadataId: MOCK_FIELD_ID,
|
||||
aggregateOperation: AGGREGATE_OPERATIONS.sum,
|
||||
aggregateOperation: AggregateOperations.SUM,
|
||||
localeCatalog: enUS,
|
||||
...defaultParams,
|
||||
});
|
||||
@ -157,7 +157,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
|
||||
const mockFormattedData = {
|
||||
createdAt: {
|
||||
[DATE_AGGREGATE_OPERATIONS.earliest]: '2023-01-01T12:00:00Z',
|
||||
[DateAggregateOperations.EARLIEST]: '2023-01-01T12:00:00Z',
|
||||
},
|
||||
} as AggregateRecordsData;
|
||||
|
||||
@ -165,7 +165,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
data: mockFormattedData,
|
||||
objectMetadataItem: mockObjectMetadataWithDatetimeField,
|
||||
fieldMetadataId: MOCK_FIELD_ID,
|
||||
aggregateOperation: DATE_AGGREGATE_OPERATIONS.earliest,
|
||||
aggregateOperation: DateAggregateOperations.EARLIEST,
|
||||
localeCatalog: enUS,
|
||||
...defaultParams,
|
||||
});
|
||||
@ -192,7 +192,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
|
||||
const mockFormattedData = {
|
||||
updatedAt: {
|
||||
[DATE_AGGREGATE_OPERATIONS.latest]: '2023-12-31T23:59:59Z',
|
||||
[DateAggregateOperations.LATEST]: '2023-12-31T23:59:59Z',
|
||||
},
|
||||
} as AggregateRecordsData;
|
||||
|
||||
@ -200,7 +200,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
data: mockFormattedData,
|
||||
objectMetadataItem: mockObjectMetadataWithDatetimeField,
|
||||
fieldMetadataId: MOCK_FIELD_ID,
|
||||
aggregateOperation: DATE_AGGREGATE_OPERATIONS.latest,
|
||||
aggregateOperation: DateAggregateOperations.LATEST,
|
||||
localeCatalog: enUS,
|
||||
...defaultParams,
|
||||
});
|
||||
@ -215,7 +215,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
it('should default to count when field not found', () => {
|
||||
const mockData = {
|
||||
id: {
|
||||
[AGGREGATE_OPERATIONS.count]: 42,
|
||||
[AggregateOperations.COUNT]: 42,
|
||||
},
|
||||
} as AggregateRecordsData;
|
||||
|
||||
@ -236,7 +236,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
it('should handle undefined aggregate value', () => {
|
||||
const mockData = {
|
||||
amount: {
|
||||
[AGGREGATE_OPERATIONS.sum]: undefined,
|
||||
[AggregateOperations.SUM]: undefined,
|
||||
},
|
||||
} as AggregateRecordsData;
|
||||
|
||||
@ -244,7 +244,7 @@ describe('computeAggregateValueAndLabel', () => {
|
||||
data: mockData,
|
||||
objectMetadataItem: mockObjectMetadata,
|
||||
fieldMetadataId: MOCK_FIELD_ID,
|
||||
aggregateOperation: AGGREGATE_OPERATIONS.sum,
|
||||
aggregateOperation: AggregateOperations.SUM,
|
||||
localeCatalog: enUS,
|
||||
...defaultParams,
|
||||
});
|
||||
|
||||
@ -1,45 +1,43 @@
|
||||
import { getAggregateOperationLabel } from '@/object-record/record-board/record-board-column/utils/getAggregateOperationLabel';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { expect } from '@storybook/test';
|
||||
|
||||
describe('getAggregateOperationLabel', () => {
|
||||
it('should return correct labels for each operation', () => {
|
||||
expect(getAggregateOperationLabel(AGGREGATE_OPERATIONS.min)).toBe('Min');
|
||||
expect(getAggregateOperationLabel(AGGREGATE_OPERATIONS.max)).toBe('Max');
|
||||
expect(getAggregateOperationLabel(AGGREGATE_OPERATIONS.avg)).toBe(
|
||||
'Average',
|
||||
);
|
||||
expect(getAggregateOperationLabel(DATE_AGGREGATE_OPERATIONS.earliest)).toBe(
|
||||
expect(getAggregateOperationLabel(AggregateOperations.MIN)).toBe('Min');
|
||||
expect(getAggregateOperationLabel(AggregateOperations.MAX)).toBe('Max');
|
||||
expect(getAggregateOperationLabel(AggregateOperations.AVG)).toBe('Average');
|
||||
expect(getAggregateOperationLabel(DateAggregateOperations.EARLIEST)).toBe(
|
||||
'Earliest date',
|
||||
);
|
||||
expect(getAggregateOperationLabel(DATE_AGGREGATE_OPERATIONS.latest)).toBe(
|
||||
expect(getAggregateOperationLabel(DateAggregateOperations.LATEST)).toBe(
|
||||
'Latest date',
|
||||
);
|
||||
expect(getAggregateOperationLabel(AGGREGATE_OPERATIONS.sum)).toBe('Sum');
|
||||
expect(getAggregateOperationLabel(AGGREGATE_OPERATIONS.count)).toBe(
|
||||
expect(getAggregateOperationLabel(AggregateOperations.SUM)).toBe('Sum');
|
||||
expect(getAggregateOperationLabel(AggregateOperations.COUNT)).toBe(
|
||||
'Count all',
|
||||
);
|
||||
expect(getAggregateOperationLabel(AGGREGATE_OPERATIONS.countEmpty)).toBe(
|
||||
expect(getAggregateOperationLabel(AggregateOperations.COUNT_EMPTY)).toBe(
|
||||
'Count empty',
|
||||
);
|
||||
expect(getAggregateOperationLabel(AGGREGATE_OPERATIONS.countNotEmpty)).toBe(
|
||||
'Count not empty',
|
||||
);
|
||||
expect(
|
||||
getAggregateOperationLabel(AGGREGATE_OPERATIONS.countUniqueValues),
|
||||
getAggregateOperationLabel(AggregateOperations.COUNT_NOT_EMPTY),
|
||||
).toBe('Count not empty');
|
||||
expect(
|
||||
getAggregateOperationLabel(AggregateOperations.COUNT_UNIQUE_VALUES),
|
||||
).toBe('Count unique values');
|
||||
expect(
|
||||
getAggregateOperationLabel(AGGREGATE_OPERATIONS.percentageEmpty),
|
||||
getAggregateOperationLabel(AggregateOperations.PERCENTAGE_EMPTY),
|
||||
).toBe('Percent empty');
|
||||
expect(
|
||||
getAggregateOperationLabel(AGGREGATE_OPERATIONS.percentageNotEmpty),
|
||||
getAggregateOperationLabel(AggregateOperations.PERCENTAGE_NOT_EMPTY),
|
||||
).toBe('Percent not empty');
|
||||
});
|
||||
|
||||
it('should throw error for unknown operation', () => {
|
||||
expect(() =>
|
||||
getAggregateOperationLabel('INVALID' as AGGREGATE_OPERATIONS),
|
||||
getAggregateOperationLabel('INVALID' as AggregateOperations),
|
||||
).toThrow('Unknown aggregate operation: INVALID');
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { RecordGqlFieldsAggregate } from '@/object-record/graphql/types/RecordGqlFieldsAggregate';
|
||||
import { KanbanAggregateOperation } from '@/object-record/record-index/states/recordIndexKanbanAggregateOperationState';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { FIELD_FOR_TOTAL_COUNT_AGGREGATE_OPERATION } from 'twenty-shared/constants';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
@ -23,7 +23,7 @@ export const buildRecordGqlFieldsAggregateForView = ({
|
||||
if (
|
||||
isDefined(recordIndexKanbanAggregateOperation?.operation) &&
|
||||
recordIndexKanbanAggregateOperation.operation !==
|
||||
AGGREGATE_OPERATIONS.count
|
||||
AggregateOperations.COUNT
|
||||
) {
|
||||
throw new Error(
|
||||
`No field found to compute aggregate operation ${recordIndexKanbanAggregateOperation.operation} on object ${objectMetadataItem.nameSingular}`,
|
||||
@ -31,7 +31,7 @@ export const buildRecordGqlFieldsAggregateForView = ({
|
||||
} else {
|
||||
recordGqlFieldsAggregate = {
|
||||
[FIELD_FOR_TOTAL_COUNT_AGGREGATE_OPERATION]: [
|
||||
AGGREGATE_OPERATIONS.count,
|
||||
AggregateOperations.COUNT,
|
||||
],
|
||||
};
|
||||
}
|
||||
@ -39,7 +39,7 @@ export const buildRecordGqlFieldsAggregateForView = ({
|
||||
recordGqlFieldsAggregate = {
|
||||
[kanbanAggregateOperationFieldName]: [
|
||||
recordIndexKanbanAggregateOperation?.operation ??
|
||||
AGGREGATE_OPERATIONS.count,
|
||||
AggregateOperations.COUNT,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { AggregateRecordsData } from '@/object-record/hooks/useAggregateRecords';
|
||||
import { getAggregateOperationLabel } from '@/object-record/record-board/record-board-column/utils/getAggregateOperationLabel';
|
||||
import { getAggregateOperationShortLabel } from '@/object-record/record-board/record-board-column/utils/getAggregateOperationShortLabel';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { COUNT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/countAggregateOperationOptions';
|
||||
import { PERCENT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/percentAggregateOperationOptions';
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
@ -48,12 +48,10 @@ export const computeAggregateValueAndLabel = ({
|
||||
return {
|
||||
value:
|
||||
data?.[FIELD_FOR_TOTAL_COUNT_AGGREGATE_OPERATION]?.[
|
||||
AGGREGATE_OPERATIONS.count
|
||||
AggregateOperations.COUNT
|
||||
],
|
||||
label: getAggregateOperationLabel(AGGREGATE_OPERATIONS.count),
|
||||
labelWithFieldName: getAggregateOperationLabel(
|
||||
AGGREGATE_OPERATIONS.count,
|
||||
),
|
||||
label: getAggregateOperationLabel(AggregateOperations.COUNT),
|
||||
labelWithFieldName: getAggregateOperationLabel(AggregateOperations.COUNT),
|
||||
};
|
||||
}
|
||||
|
||||
@ -69,7 +67,7 @@ export const computeAggregateValueAndLabel = ({
|
||||
|
||||
if (
|
||||
COUNT_AGGREGATE_OPERATION_OPTIONS.includes(
|
||||
aggregateOperation as AGGREGATE_OPERATIONS,
|
||||
aggregateOperation as AggregateOperations,
|
||||
)
|
||||
) {
|
||||
value = aggregateValue;
|
||||
@ -77,7 +75,7 @@ export const computeAggregateValueAndLabel = ({
|
||||
value = '-';
|
||||
} else if (
|
||||
PERCENT_AGGREGATE_OPERATION_OPTIONS.includes(
|
||||
aggregateOperation as AGGREGATE_OPERATIONS,
|
||||
aggregateOperation as AggregateOperations,
|
||||
)
|
||||
) {
|
||||
value = `${formatNumber(Number(aggregateValue) * 100)}%`;
|
||||
@ -128,8 +126,8 @@ export const computeAggregateValueAndLabel = ({
|
||||
const aggregateLabel = t(getAggregateOperationShortLabel(aggregateOperation));
|
||||
const fieldLabel = field.label;
|
||||
const labelWithFieldName =
|
||||
aggregateOperation === AGGREGATE_OPERATIONS.count
|
||||
? `${getAggregateOperationLabel(AGGREGATE_OPERATIONS.count)}`
|
||||
aggregateOperation === AggregateOperations.COUNT
|
||||
? `${getAggregateOperationLabel(AggregateOperations.COUNT)}`
|
||||
: t`${aggregateLabel} of ${fieldLabel}`;
|
||||
|
||||
return {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
@ -7,33 +7,33 @@ export const getAggregateOperationLabel = (
|
||||
operation: ExtendedAggregateOperations,
|
||||
) => {
|
||||
switch (operation) {
|
||||
case AGGREGATE_OPERATIONS.min:
|
||||
case AggregateOperations.MIN:
|
||||
return t`Min`;
|
||||
case AGGREGATE_OPERATIONS.max:
|
||||
case AggregateOperations.MAX:
|
||||
return t`Max`;
|
||||
case AGGREGATE_OPERATIONS.avg:
|
||||
case AggregateOperations.AVG:
|
||||
return t`Average`;
|
||||
case AGGREGATE_OPERATIONS.sum:
|
||||
case AggregateOperations.SUM:
|
||||
return t`Sum`;
|
||||
case AGGREGATE_OPERATIONS.count:
|
||||
case AggregateOperations.COUNT:
|
||||
return t`Count all`;
|
||||
case AGGREGATE_OPERATIONS.countEmpty:
|
||||
case AggregateOperations.COUNT_EMPTY:
|
||||
return t`Count empty`;
|
||||
case AGGREGATE_OPERATIONS.countNotEmpty:
|
||||
case AggregateOperations.COUNT_NOT_EMPTY:
|
||||
return t`Count not empty`;
|
||||
case AGGREGATE_OPERATIONS.countUniqueValues:
|
||||
case AggregateOperations.COUNT_UNIQUE_VALUES:
|
||||
return t`Count unique values`;
|
||||
case AGGREGATE_OPERATIONS.percentageEmpty:
|
||||
case AggregateOperations.PERCENTAGE_EMPTY:
|
||||
return t`Percent empty`;
|
||||
case AGGREGATE_OPERATIONS.percentageNotEmpty:
|
||||
case AggregateOperations.PERCENTAGE_NOT_EMPTY:
|
||||
return t`Percent not empty`;
|
||||
case DATE_AGGREGATE_OPERATIONS.earliest:
|
||||
case DateAggregateOperations.EARLIEST:
|
||||
return t`Earliest date`;
|
||||
case DATE_AGGREGATE_OPERATIONS.latest:
|
||||
case DateAggregateOperations.LATEST:
|
||||
return t`Latest date`;
|
||||
case AGGREGATE_OPERATIONS.countTrue:
|
||||
case AggregateOperations.COUNT_TRUE:
|
||||
return t`Count true`;
|
||||
case AGGREGATE_OPERATIONS.countFalse:
|
||||
case AggregateOperations.COUNT_FALSE:
|
||||
return t`Count false`;
|
||||
default:
|
||||
throw new Error(`Unknown aggregate operation: ${operation}`);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
|
||||
@ -7,31 +7,31 @@ export const getAggregateOperationShortLabel = (
|
||||
operation: ExtendedAggregateOperations,
|
||||
) => {
|
||||
switch (operation) {
|
||||
case AGGREGATE_OPERATIONS.min:
|
||||
case AggregateOperations.MIN:
|
||||
return msg`Min`;
|
||||
case AGGREGATE_OPERATIONS.max:
|
||||
case AggregateOperations.MAX:
|
||||
return msg`Max`;
|
||||
case AGGREGATE_OPERATIONS.avg:
|
||||
case AggregateOperations.AVG:
|
||||
return msg`Average`;
|
||||
case AGGREGATE_OPERATIONS.sum:
|
||||
case AggregateOperations.SUM:
|
||||
return msg`Sum`;
|
||||
case AGGREGATE_OPERATIONS.count:
|
||||
case AggregateOperations.COUNT:
|
||||
return msg`All`;
|
||||
case AGGREGATE_OPERATIONS.countEmpty:
|
||||
case AGGREGATE_OPERATIONS.percentageEmpty:
|
||||
case AggregateOperations.COUNT_EMPTY:
|
||||
case AggregateOperations.PERCENTAGE_EMPTY:
|
||||
return msg`Empty`;
|
||||
case AGGREGATE_OPERATIONS.countNotEmpty:
|
||||
case AGGREGATE_OPERATIONS.percentageNotEmpty:
|
||||
case AggregateOperations.COUNT_NOT_EMPTY:
|
||||
case AggregateOperations.PERCENTAGE_NOT_EMPTY:
|
||||
return msg`Not empty`;
|
||||
case AGGREGATE_OPERATIONS.countUniqueValues:
|
||||
case AggregateOperations.COUNT_UNIQUE_VALUES:
|
||||
return msg`Unique`;
|
||||
case DATE_AGGREGATE_OPERATIONS.earliest:
|
||||
case DateAggregateOperations.EARLIEST:
|
||||
return msg`Earliest`;
|
||||
case DATE_AGGREGATE_OPERATIONS.latest:
|
||||
case DateAggregateOperations.LATEST:
|
||||
return msg`Latest`;
|
||||
case AGGREGATE_OPERATIONS.countTrue:
|
||||
case AggregateOperations.COUNT_TRUE:
|
||||
return msg`True`;
|
||||
case AGGREGATE_OPERATIONS.countFalse:
|
||||
case AggregateOperations.COUNT_FALSE:
|
||||
return msg`False`;
|
||||
default:
|
||||
throw new Error(`Unknown aggregate operation: ${operation}`);
|
||||
|
||||
@ -10,8 +10,6 @@ import { RecordLayoutTab } from '@/ui/layout/tab/types/RecordLayoutTab';
|
||||
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
|
||||
import { useMemo } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { FeatureFlagKey } from '~/generated/graphql';
|
||||
import {
|
||||
IconCalendarEvent,
|
||||
IconHome,
|
||||
@ -19,6 +17,8 @@ import {
|
||||
IconNotes,
|
||||
IconSettings,
|
||||
} from 'twenty-ui/display';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { FeatureFlagKey } from '~/generated/graphql';
|
||||
|
||||
export const useRecordShowContainerTabs = (
|
||||
loading: boolean,
|
||||
@ -152,7 +152,7 @@ export const useRecordShowContainerTabs = (
|
||||
ifMobile: false,
|
||||
ifDesktop: false,
|
||||
ifInRightDrawer: false,
|
||||
ifFeaturesDisabled: [FeatureFlagKey.IsWorkflowEnabled],
|
||||
ifFeaturesDisabled: [FeatureFlagKey.IS_WORKFLOW_ENABLED],
|
||||
ifRequiredObjectsInactive: [],
|
||||
ifRelationsMissing: [],
|
||||
},
|
||||
@ -175,7 +175,7 @@ export const useRecordShowContainerTabs = (
|
||||
ifMobile: false,
|
||||
ifDesktop: false,
|
||||
ifInRightDrawer: false,
|
||||
ifFeaturesDisabled: [FeatureFlagKey.IsWorkflowEnabled],
|
||||
ifFeaturesDisabled: [FeatureFlagKey.IS_WORKFLOW_ENABLED],
|
||||
ifRequiredObjectsInactive: [],
|
||||
ifRelationsMissing: [],
|
||||
},
|
||||
@ -197,7 +197,7 @@ export const useRecordShowContainerTabs = (
|
||||
ifMobile: false,
|
||||
ifDesktop: false,
|
||||
ifInRightDrawer: false,
|
||||
ifFeaturesDisabled: [FeatureFlagKey.IsWorkflowEnabled],
|
||||
ifFeaturesDisabled: [FeatureFlagKey.IS_WORKFLOW_ENABLED],
|
||||
ifRequiredObjectsInactive: [],
|
||||
ifRelationsMissing: [],
|
||||
},
|
||||
|
||||
@ -13,7 +13,7 @@ import { RecordDetailRelationSectionDropdown } from '@/object-record/record-show
|
||||
import { RecordDetailSection } from '@/object-record/record-show/record-detail-section/components/RecordDetailSection';
|
||||
import { RecordDetailSectionHeader } from '@/object-record/record-show/record-detail-section/components/RecordDetailSectionHeader';
|
||||
import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { prefetchIndexViewIdFromObjectMetadataItemFamilySelector } from '@/prefetch/states/selector/prefetchIndexViewIdFromObjectMetadataItemFamilySelector';
|
||||
import { AppPath } from '@/types/AppPath';
|
||||
@ -109,7 +109,7 @@ export const RecordDetailRelationSection = ({
|
||||
filter: filtersForAggregate,
|
||||
skip: !isToManyObjects,
|
||||
recordGqlFieldsAggregate: {
|
||||
id: [AGGREGATE_OPERATIONS.count],
|
||||
id: [AggregateOperations.COUNT],
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
export enum AGGREGATE_OPERATIONS {
|
||||
min = 'MIN',
|
||||
max = 'MAX',
|
||||
avg = 'AVG',
|
||||
sum = 'SUM',
|
||||
count = 'COUNT',
|
||||
countEmpty = 'COUNT_EMPTY',
|
||||
countNotEmpty = 'COUNT_NOT_EMPTY',
|
||||
countUniqueValues = 'COUNT_UNIQUE_VALUES',
|
||||
percentageEmpty = 'PERCENTAGE_EMPTY',
|
||||
percentageNotEmpty = 'PERCENTAGE_NOT_EMPTY',
|
||||
countTrue = 'COUNT_TRUE',
|
||||
countFalse = 'COUNT_FALSE',
|
||||
export enum AggregateOperations {
|
||||
MIN = 'MIN',
|
||||
MAX = 'MAX',
|
||||
AVG = 'AVG',
|
||||
SUM = 'SUM',
|
||||
COUNT = 'COUNT',
|
||||
COUNT_EMPTY = 'COUNT_EMPTY',
|
||||
COUNT_NOT_EMPTY = 'COUNT_NOT_EMPTY',
|
||||
COUNT_UNIQUE_VALUES = 'COUNT_UNIQUE_VALUES',
|
||||
PERCENTAGE_EMPTY = 'PERCENTAGE_EMPTY',
|
||||
PERCENTAGE_NOT_EMPTY = 'PERCENTAGE_NOT_EMPTY',
|
||||
COUNT_TRUE = 'COUNT_TRUE',
|
||||
COUNT_FALSE = 'COUNT_FALSE',
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export enum DATE_AGGREGATE_OPERATIONS {
|
||||
earliest = 'EARLIEST',
|
||||
latest = 'LATEST',
|
||||
export enum DateAggregateOperations {
|
||||
EARLIEST = 'EARLIEST',
|
||||
LATEST = 'LATEST',
|
||||
}
|
||||
|
||||
@ -1,31 +1,31 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
export const FIELD_TYPES_AVAILABLE_FOR_NON_STANDARD_AGGREGATE_OPERATION = {
|
||||
[AGGREGATE_OPERATIONS.min]: [
|
||||
[AggregateOperations.MIN]: [
|
||||
FieldMetadataType.NUMBER,
|
||||
FieldMetadataType.CURRENCY,
|
||||
],
|
||||
[AGGREGATE_OPERATIONS.max]: [
|
||||
[AggregateOperations.MAX]: [
|
||||
FieldMetadataType.NUMBER,
|
||||
FieldMetadataType.CURRENCY,
|
||||
],
|
||||
[AGGREGATE_OPERATIONS.avg]: [
|
||||
[AggregateOperations.AVG]: [
|
||||
FieldMetadataType.NUMBER,
|
||||
FieldMetadataType.CURRENCY,
|
||||
],
|
||||
[AGGREGATE_OPERATIONS.sum]: [
|
||||
[AggregateOperations.SUM]: [
|
||||
FieldMetadataType.NUMBER,
|
||||
FieldMetadataType.CURRENCY,
|
||||
],
|
||||
[AGGREGATE_OPERATIONS.countFalse]: [FieldMetadataType.BOOLEAN],
|
||||
[AGGREGATE_OPERATIONS.countTrue]: [FieldMetadataType.BOOLEAN],
|
||||
[DATE_AGGREGATE_OPERATIONS.earliest]: [
|
||||
[AggregateOperations.COUNT_FALSE]: [FieldMetadataType.BOOLEAN],
|
||||
[AggregateOperations.COUNT_TRUE]: [FieldMetadataType.BOOLEAN],
|
||||
[DateAggregateOperations.EARLIEST]: [
|
||||
FieldMetadataType.DATE_TIME,
|
||||
FieldMetadataType.DATE,
|
||||
],
|
||||
[DATE_AGGREGATE_OPERATIONS.latest]: [
|
||||
[DateAggregateOperations.LATEST]: [
|
||||
FieldMetadataType.DATE_TIME,
|
||||
FieldMetadataType.DATE,
|
||||
],
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { useDropdown } from '@/dropdown/hooks/useDropdown';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { RecordTableColumnAggregateFooterDropdownSubmenuContent } from '@/object-record/record-table/record-table-footer/components/RecordTableColumnAggregateDropdownSubmenuContent';
|
||||
import { RecordTableColumnAggregateFooterDropdownContext } from '@/object-record/record-table/record-table-footer/components/RecordTableColumnAggregateFooterDropdownContext';
|
||||
import { RecordTableColumnAggregateFooterMenuContent } from '@/object-record/record-table/record-table-footer/components/RecordTableColumnAggregateFooterMenuContent';
|
||||
@ -28,7 +28,7 @@ export const RecordTableColumnAggregateFooterDropdownContent = () => {
|
||||
const aggregateOperations = availableAggregateOperations.filter(
|
||||
(aggregateOperation) =>
|
||||
!STANDARD_AGGREGATE_OPERATION_OPTIONS.includes(
|
||||
aggregateOperation as AGGREGATE_OPERATIONS,
|
||||
aggregateOperation as AggregateOperations,
|
||||
),
|
||||
);
|
||||
|
||||
@ -43,7 +43,7 @@ export const RecordTableColumnAggregateFooterDropdownContent = () => {
|
||||
const aggregateOperations = availableAggregateOperations.filter(
|
||||
(aggregateOperation) =>
|
||||
COUNT_AGGREGATE_OPERATION_OPTIONS.includes(
|
||||
aggregateOperation as AGGREGATE_OPERATIONS,
|
||||
aggregateOperation as AggregateOperations,
|
||||
),
|
||||
);
|
||||
return (
|
||||
@ -57,7 +57,7 @@ export const RecordTableColumnAggregateFooterDropdownContent = () => {
|
||||
const aggregateOperations = availableAggregateOperations.filter(
|
||||
(aggregateOperation) =>
|
||||
PERCENT_AGGREGATE_OPERATION_OPTIONS.includes(
|
||||
aggregateOperation as AGGREGATE_OPERATIONS,
|
||||
aggregateOperation as AggregateOperations,
|
||||
),
|
||||
);
|
||||
return (
|
||||
@ -71,7 +71,7 @@ export const RecordTableColumnAggregateFooterDropdownContent = () => {
|
||||
const aggregateOperations = availableAggregateOperations.filter(
|
||||
(aggregateOperation) =>
|
||||
DATE_AGGREGATE_OPERATION_OPTIONS.includes(
|
||||
aggregateOperation as DATE_AGGREGATE_OPERATIONS,
|
||||
aggregateOperation as DateAggregateOperations,
|
||||
),
|
||||
);
|
||||
return (
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
|
||||
import { RecordTableColumnAggregateFooterDropdownContext } from '@/object-record/record-table/record-table-footer/components/RecordTableColumnAggregateFooterDropdownContext';
|
||||
import { NON_STANDARD_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/nonStandardAggregateOperationsOptions';
|
||||
@ -51,7 +51,7 @@ export const RecordTableColumnAggregateFooterMenuContent = () => {
|
||||
const nonStandardAvailableAggregateOperation =
|
||||
availableAggregateOperation.filter((aggregateOperation) =>
|
||||
NON_STANDARD_AGGREGATE_OPERATION_OPTIONS.includes(
|
||||
aggregateOperation as AGGREGATE_OPERATIONS,
|
||||
aggregateOperation as AggregateOperations,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
|
||||
export const COUNT_AGGREGATE_OPERATION_OPTIONS = [
|
||||
AGGREGATE_OPERATIONS.count,
|
||||
AGGREGATE_OPERATIONS.countEmpty,
|
||||
AGGREGATE_OPERATIONS.countNotEmpty,
|
||||
AGGREGATE_OPERATIONS.countUniqueValues,
|
||||
AGGREGATE_OPERATIONS.countTrue,
|
||||
AGGREGATE_OPERATIONS.countFalse,
|
||||
AggregateOperations.COUNT,
|
||||
AggregateOperations.COUNT_EMPTY,
|
||||
AggregateOperations.COUNT_NOT_EMPTY,
|
||||
AggregateOperations.COUNT_UNIQUE_VALUES,
|
||||
AggregateOperations.COUNT_TRUE,
|
||||
AggregateOperations.COUNT_FALSE,
|
||||
];
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
|
||||
export const DATE_AGGREGATE_OPERATION_OPTIONS = [
|
||||
DATE_AGGREGATE_OPERATIONS.earliest,
|
||||
DATE_AGGREGATE_OPERATIONS.latest,
|
||||
DateAggregateOperations.EARLIEST,
|
||||
DateAggregateOperations.LATEST,
|
||||
];
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
|
||||
export const NON_STANDARD_AGGREGATE_OPERATION_OPTIONS = [
|
||||
AGGREGATE_OPERATIONS.min,
|
||||
AGGREGATE_OPERATIONS.max,
|
||||
AGGREGATE_OPERATIONS.avg,
|
||||
AGGREGATE_OPERATIONS.sum,
|
||||
AggregateOperations.MIN,
|
||||
AggregateOperations.MAX,
|
||||
AggregateOperations.AVG,
|
||||
AggregateOperations.SUM,
|
||||
];
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
|
||||
export const PERCENT_AGGREGATE_OPERATION_OPTIONS = [
|
||||
AGGREGATE_OPERATIONS.percentageEmpty,
|
||||
AGGREGATE_OPERATIONS.percentageNotEmpty,
|
||||
AggregateOperations.PERCENTAGE_EMPTY,
|
||||
AggregateOperations.PERCENTAGE_NOT_EMPTY,
|
||||
];
|
||||
|
||||
@ -5,7 +5,7 @@ import { useFilterValueDependencies } from '@/object-record/record-filter/hooks/
|
||||
import { currentRecordFiltersComponentState } from '@/object-record/record-filter/states/currentRecordFiltersComponentState';
|
||||
import { computeRecordGqlOperationFilter } from '@/object-record/record-filter/utils/computeRecordGqlOperationFilter';
|
||||
import { useRecordGroupFilter } from '@/object-record/record-group/hooks/useRecordGroupFilter';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } 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';
|
||||
@ -62,9 +62,9 @@ export const useAggregateRecordsForRecordTableColumnFooter = (
|
||||
isFieldMetadataDateKind(fieldMetadataItem.type) &&
|
||||
isDefined(aggregateOperationForViewFieldWithProbableImpossibleValues) &&
|
||||
(aggregateOperationForViewFieldWithProbableImpossibleValues ===
|
||||
AGGREGATE_OPERATIONS.min ||
|
||||
AggregateOperations.MIN ||
|
||||
aggregateOperationForViewFieldWithProbableImpossibleValues ===
|
||||
AGGREGATE_OPERATIONS.max);
|
||||
AggregateOperations.MAX);
|
||||
|
||||
const aggregateOperationForViewField:
|
||||
| ExtendedAggregateOperations
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import { RecordGqlFieldsAggregate } from '@/object-record/graphql/types/RecordGqlFieldsAggregate';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
|
||||
export const buildRecordGqlFieldsAggregateForRecordTable = ({
|
||||
aggregateOperation,
|
||||
fieldName,
|
||||
}: {
|
||||
fieldName: string;
|
||||
aggregateOperation?: AGGREGATE_OPERATIONS | null;
|
||||
aggregateOperation?: AggregateOperations | null;
|
||||
}): RecordGqlFieldsAggregate => {
|
||||
return {
|
||||
[fieldName]: [aggregateOperation ?? AGGREGATE_OPERATIONS.count],
|
||||
[fieldName]: [aggregateOperation ?? AggregateOperations.COUNT],
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { FIELD_TYPES_AVAILABLE_FOR_NON_STANDARD_AGGREGATE_OPERATION } from '@/object-record/record-table/constants/FieldTypesAvailableForNonStandardAggregateOperation';
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { AggregateOperationsOmittingStandardOperations } from '@/object-record/types/AggregateOperationsOmittingStandardOperations';
|
||||
import { isFieldTypeValidForAggregateOperation } from '@/object-record/utils/isFieldTypeValidForAggregateOperation';
|
||||
import { FieldMetadataType } from '~/generated/graphql';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { FieldMetadataType } from '~/generated/graphql';
|
||||
|
||||
export const getAvailableAggregateOperationsForFieldMetadataType = ({
|
||||
fieldMetadataType,
|
||||
@ -12,16 +12,16 @@ export const getAvailableAggregateOperationsForFieldMetadataType = ({
|
||||
fieldMetadataType?: FieldMetadataType;
|
||||
}) => {
|
||||
if (fieldMetadataType === FieldMetadataType.RELATION) {
|
||||
return [AGGREGATE_OPERATIONS.count];
|
||||
return [AggregateOperations.COUNT];
|
||||
}
|
||||
|
||||
const availableAggregateOperations = new Set<ExtendedAggregateOperations>([
|
||||
AGGREGATE_OPERATIONS.count,
|
||||
AGGREGATE_OPERATIONS.countEmpty,
|
||||
AGGREGATE_OPERATIONS.countNotEmpty,
|
||||
AGGREGATE_OPERATIONS.countUniqueValues,
|
||||
AGGREGATE_OPERATIONS.percentageEmpty,
|
||||
AGGREGATE_OPERATIONS.percentageNotEmpty,
|
||||
AggregateOperations.COUNT,
|
||||
AggregateOperations.COUNT_EMPTY,
|
||||
AggregateOperations.COUNT_NOT_EMPTY,
|
||||
AggregateOperations.COUNT_UNIQUE_VALUES,
|
||||
AggregateOperations.PERCENTAGE_EMPTY,
|
||||
AggregateOperations.PERCENTAGE_NOT_EMPTY,
|
||||
]);
|
||||
|
||||
if (!isDefined(fieldMetadataType)) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
|
||||
export type ExtendedAggregateOperations =
|
||||
| AGGREGATE_OPERATIONS
|
||||
| DATE_AGGREGATE_OPERATIONS;
|
||||
| AggregateOperations
|
||||
| DateAggregateOperations;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
|
||||
export type AggregateOperationsOmittingStandardOperations = Exclude<
|
||||
AGGREGATE_OPERATIONS,
|
||||
| AGGREGATE_OPERATIONS.count
|
||||
| AGGREGATE_OPERATIONS.countEmpty
|
||||
| AGGREGATE_OPERATIONS.countNotEmpty
|
||||
| AGGREGATE_OPERATIONS.countUniqueValues
|
||||
| AGGREGATE_OPERATIONS.percentageEmpty
|
||||
| AGGREGATE_OPERATIONS.percentageNotEmpty
|
||||
AggregateOperations,
|
||||
| AggregateOperations.COUNT
|
||||
| AggregateOperations.COUNT_EMPTY
|
||||
| AggregateOperations.COUNT_NOT_EMPTY
|
||||
| AggregateOperations.COUNT_UNIQUE_VALUES
|
||||
| AggregateOperations.PERCENTAGE_EMPTY
|
||||
| AggregateOperations.PERCENTAGE_NOT_EMPTY
|
||||
>;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { COUNT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/countAggregateOperationOptions';
|
||||
import { NON_STANDARD_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/nonStandardAggregateOperationsOptions';
|
||||
import { PERCENT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/percentAggregateOperationOptions';
|
||||
@ -23,43 +23,43 @@ jest.mock(
|
||||
() => ({
|
||||
getAvailableAggregationsFromObjectFields: jest.fn().mockReturnValue({
|
||||
active: {
|
||||
[AGGREGATE_OPERATIONS.countTrue]: 'countTrueActive',
|
||||
[AGGREGATE_OPERATIONS.countFalse]: 'CountFalseActive',
|
||||
[AggregateOperations.COUNT_TRUE]: 'countTrueActive',
|
||||
[AggregateOperations.COUNT_FALSE]: 'CountFalseActive',
|
||||
},
|
||||
amount: {
|
||||
[AGGREGATE_OPERATIONS.sum]: 'sumAmount',
|
||||
[AGGREGATE_OPERATIONS.avg]: 'avgAmount',
|
||||
[AGGREGATE_OPERATIONS.min]: 'minAmount',
|
||||
[AGGREGATE_OPERATIONS.max]: 'maxAmount',
|
||||
[AGGREGATE_OPERATIONS.count]: 'totalCount',
|
||||
[AGGREGATE_OPERATIONS.countUniqueValues]: 'countUniqueValuesAmount',
|
||||
[AGGREGATE_OPERATIONS.countEmpty]: 'countEmptyAmount',
|
||||
[AGGREGATE_OPERATIONS.countNotEmpty]: 'countNotEmptyAmount',
|
||||
[AGGREGATE_OPERATIONS.percentageEmpty]: 'percentageEmptyAmount',
|
||||
[AGGREGATE_OPERATIONS.percentageNotEmpty]: 'percentageNotEmptyAmount',
|
||||
[AggregateOperations.SUM]: 'sumAmount',
|
||||
[AggregateOperations.AVG]: 'avgAmount',
|
||||
[AggregateOperations.MIN]: 'minAmount',
|
||||
[AggregateOperations.MAX]: 'maxAmount',
|
||||
[AggregateOperations.COUNT]: 'totalCount',
|
||||
[AggregateOperations.COUNT_UNIQUE_VALUES]: 'countUniqueValuesAmount',
|
||||
[AggregateOperations.COUNT_EMPTY]: 'countEmptyAmount',
|
||||
[AggregateOperations.COUNT_NOT_EMPTY]: 'countNotEmptyAmount',
|
||||
[AggregateOperations.PERCENTAGE_EMPTY]: 'percentageEmptyAmount',
|
||||
[AggregateOperations.PERCENTAGE_NOT_EMPTY]: 'percentageNotEmptyAmount',
|
||||
},
|
||||
price: {
|
||||
[AGGREGATE_OPERATIONS.sum]: 'sumPriceAmountMicros',
|
||||
[AGGREGATE_OPERATIONS.avg]: 'avgPriceAmountMicros',
|
||||
[AGGREGATE_OPERATIONS.min]: 'minPriceAmountMicros',
|
||||
[AGGREGATE_OPERATIONS.max]: 'maxPriceAmountMicros',
|
||||
[AGGREGATE_OPERATIONS.count]: 'totalCount',
|
||||
[AGGREGATE_OPERATIONS.countUniqueValues]:
|
||||
[AggregateOperations.SUM]: 'sumPriceAmountMicros',
|
||||
[AggregateOperations.AVG]: 'avgPriceAmountMicros',
|
||||
[AggregateOperations.MIN]: 'minPriceAmountMicros',
|
||||
[AggregateOperations.MAX]: 'maxPriceAmountMicros',
|
||||
[AggregateOperations.COUNT]: 'totalCount',
|
||||
[AggregateOperations.COUNT_UNIQUE_VALUES]:
|
||||
'countUniqueValuesPriceAmountMicros',
|
||||
[AGGREGATE_OPERATIONS.countEmpty]: 'countEmptyPriceAmountMicros',
|
||||
[AGGREGATE_OPERATIONS.countNotEmpty]: 'countNotEmptyPriceAmountMicros',
|
||||
[AGGREGATE_OPERATIONS.percentageEmpty]:
|
||||
[AggregateOperations.COUNT_EMPTY]: 'countEmptyPriceAmountMicros',
|
||||
[AggregateOperations.COUNT_NOT_EMPTY]: 'countNotEmptyPriceAmountMicros',
|
||||
[AggregateOperations.PERCENTAGE_EMPTY]:
|
||||
'percentageEmptyPriceAmountMicros',
|
||||
[AGGREGATE_OPERATIONS.percentageNotEmpty]:
|
||||
[AggregateOperations.PERCENTAGE_NOT_EMPTY]:
|
||||
'percentageNotEmptyPriceAmountMicros',
|
||||
},
|
||||
name: {
|
||||
[AGGREGATE_OPERATIONS.count]: 'totalCount',
|
||||
[AGGREGATE_OPERATIONS.countUniqueValues]: 'countUniqueValuesName',
|
||||
[AGGREGATE_OPERATIONS.countEmpty]: 'countEmptyName',
|
||||
[AGGREGATE_OPERATIONS.countNotEmpty]: 'countNotEmptyName',
|
||||
[AGGREGATE_OPERATIONS.percentageEmpty]: 'percentageEmptyName',
|
||||
[AGGREGATE_OPERATIONS.percentageNotEmpty]: 'percentageNotEmptyName',
|
||||
[AggregateOperations.COUNT]: 'totalCount',
|
||||
[AggregateOperations.COUNT_UNIQUE_VALUES]: 'countUniqueValuesName',
|
||||
[AggregateOperations.COUNT_EMPTY]: 'countEmptyName',
|
||||
[AggregateOperations.COUNT_NOT_EMPTY]: 'countNotEmptyName',
|
||||
[AggregateOperations.PERCENTAGE_EMPTY]: 'percentageEmptyName',
|
||||
[AggregateOperations.PERCENTAGE_NOT_EMPTY]: 'percentageNotEmptyName',
|
||||
},
|
||||
}),
|
||||
}),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { FIELD_TYPES_AVAILABLE_FOR_NON_STANDARD_AGGREGATE_OPERATION } from '@/object-record/record-table/constants/FieldTypesAvailableForNonStandardAggregateOperation';
|
||||
import { COUNT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/countAggregateOperationOptions';
|
||||
import { PERCENT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/percentAggregateOperationOptions';
|
||||
@ -10,7 +10,7 @@ describe('initializeAvailableFieldsForAggregateOperationMap', () => {
|
||||
const result = initializeAvailableFieldsForAggregateOperationMap(
|
||||
Object.keys(
|
||||
FIELD_TYPES_AVAILABLE_FOR_NON_STANDARD_AGGREGATE_OPERATION,
|
||||
) as AGGREGATE_OPERATIONS[],
|
||||
) as AggregateOperations[],
|
||||
);
|
||||
|
||||
expect(Object.keys(result)).toEqual(
|
||||
@ -25,11 +25,11 @@ describe('initializeAvailableFieldsForAggregateOperationMap', () => {
|
||||
const result = initializeAvailableFieldsForAggregateOperationMap(
|
||||
Object.keys(
|
||||
FIELD_TYPES_AVAILABLE_FOR_NON_STANDARD_AGGREGATE_OPERATION,
|
||||
) as AGGREGATE_OPERATIONS[],
|
||||
) as AggregateOperations[],
|
||||
);
|
||||
expect(
|
||||
result[
|
||||
AGGREGATE_OPERATIONS.count as AggregateOperationsOmittingStandardOperations
|
||||
AggregateOperations.COUNT as AggregateOperationsOmittingStandardOperations
|
||||
],
|
||||
).toBeUndefined();
|
||||
});
|
||||
@ -38,21 +38,21 @@ describe('initializeAvailableFieldsForAggregateOperationMap', () => {
|
||||
const result = initializeAvailableFieldsForAggregateOperationMap(
|
||||
COUNT_AGGREGATE_OPERATION_OPTIONS,
|
||||
);
|
||||
expect(result[AGGREGATE_OPERATIONS.count]).toEqual([]);
|
||||
expect(result[AGGREGATE_OPERATIONS.countEmpty]).toEqual([]);
|
||||
expect(result[AGGREGATE_OPERATIONS.countNotEmpty]).toEqual([]);
|
||||
expect(result[AGGREGATE_OPERATIONS.countUniqueValues]).toEqual([]);
|
||||
expect(result[AGGREGATE_OPERATIONS.min]).toBeUndefined();
|
||||
expect(result[AGGREGATE_OPERATIONS.percentageEmpty]).toBeUndefined();
|
||||
expect(result[AggregateOperations.COUNT]).toEqual([]);
|
||||
expect(result[AggregateOperations.COUNT_EMPTY]).toEqual([]);
|
||||
expect(result[AggregateOperations.COUNT_NOT_EMPTY]).toEqual([]);
|
||||
expect(result[AggregateOperations.COUNT_UNIQUE_VALUES]).toEqual([]);
|
||||
expect(result[AggregateOperations.MIN]).toBeUndefined();
|
||||
expect(result[AggregateOperations.PERCENTAGE_EMPTY]).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should include percent operation when called with count aggregate operations', () => {
|
||||
const result = initializeAvailableFieldsForAggregateOperationMap(
|
||||
PERCENT_AGGREGATE_OPERATION_OPTIONS,
|
||||
);
|
||||
expect(result[AGGREGATE_OPERATIONS.percentageEmpty]).toEqual([]);
|
||||
expect(result[AGGREGATE_OPERATIONS.percentageNotEmpty]).toEqual([]);
|
||||
expect(result[AGGREGATE_OPERATIONS.count]).toBeUndefined();
|
||||
expect(result[AGGREGATE_OPERATIONS.min]).toBeUndefined();
|
||||
expect(result[AggregateOperations.PERCENTAGE_EMPTY]).toEqual([]);
|
||||
expect(result[AggregateOperations.PERCENTAGE_NOT_EMPTY]).toEqual([]);
|
||||
expect(result[AggregateOperations.COUNT]).toBeUndefined();
|
||||
expect(result[AggregateOperations.MIN]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { AggregateOperationsOmittingStandardOperations } from '@/object-record/types/AggregateOperationsOmittingStandardOperations';
|
||||
import { isFieldTypeValidForAggregateOperation } from '@/object-record/utils/isFieldTypeValidForAggregateOperation';
|
||||
import { FieldMetadataType } from '~/generated/graphql';
|
||||
@ -8,14 +8,14 @@ describe('isFieldTypeValidForAggregateOperation', () => {
|
||||
expect(
|
||||
isFieldTypeValidForAggregateOperation(
|
||||
FieldMetadataType.NUMBER,
|
||||
AGGREGATE_OPERATIONS.sum,
|
||||
AggregateOperations.SUM,
|
||||
),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
isFieldTypeValidForAggregateOperation(
|
||||
FieldMetadataType.CURRENCY,
|
||||
AGGREGATE_OPERATIONS.min,
|
||||
AggregateOperations.MIN,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
@ -24,14 +24,14 @@ describe('isFieldTypeValidForAggregateOperation', () => {
|
||||
expect(
|
||||
isFieldTypeValidForAggregateOperation(
|
||||
FieldMetadataType.TEXT,
|
||||
AGGREGATE_OPERATIONS.avg,
|
||||
AggregateOperations.AVG,
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
isFieldTypeValidForAggregateOperation(
|
||||
FieldMetadataType.BOOLEAN,
|
||||
AGGREGATE_OPERATIONS.max,
|
||||
AggregateOperations.MAX,
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
@ -39,10 +39,10 @@ describe('isFieldTypeValidForAggregateOperation', () => {
|
||||
it('should handle all aggregate operations', () => {
|
||||
const numericField = FieldMetadataType.NUMBER;
|
||||
const operations = [
|
||||
AGGREGATE_OPERATIONS.min,
|
||||
AGGREGATE_OPERATIONS.max,
|
||||
AGGREGATE_OPERATIONS.avg,
|
||||
AGGREGATE_OPERATIONS.sum,
|
||||
AggregateOperations.MIN,
|
||||
AggregateOperations.MAX,
|
||||
AggregateOperations.AVG,
|
||||
AggregateOperations.SUM,
|
||||
];
|
||||
|
||||
operations.forEach((operation) => {
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isFieldMetadataDateKind } from 'twenty-shared/utils';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
export const convertAggregateOperationToExtendedAggregateOperation = (
|
||||
aggregateOperation: AGGREGATE_OPERATIONS,
|
||||
aggregateOperation: AggregateOperations,
|
||||
fieldType?: FieldMetadataType,
|
||||
): ExtendedAggregateOperations => {
|
||||
if (isFieldMetadataDateKind(fieldType) === true) {
|
||||
if (aggregateOperation === AGGREGATE_OPERATIONS.min) {
|
||||
return DATE_AGGREGATE_OPERATIONS.earliest;
|
||||
if (aggregateOperation === AggregateOperations.MIN) {
|
||||
return DateAggregateOperations.EARLIEST;
|
||||
}
|
||||
if (aggregateOperation === AGGREGATE_OPERATIONS.max) {
|
||||
return DATE_AGGREGATE_OPERATIONS.latest;
|
||||
if (aggregateOperation === AggregateOperations.MAX) {
|
||||
return DateAggregateOperations.LATEST;
|
||||
}
|
||||
}
|
||||
return aggregateOperation;
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
|
||||
export const convertExtendedAggregateOperationToAggregateOperation = (
|
||||
extendedAggregateOperation: ExtendedAggregateOperations | null,
|
||||
) => {
|
||||
if (extendedAggregateOperation === DATE_AGGREGATE_OPERATIONS.earliest) {
|
||||
return AGGREGATE_OPERATIONS.min;
|
||||
if (extendedAggregateOperation === DateAggregateOperations.EARLIEST) {
|
||||
return AggregateOperations.MIN;
|
||||
}
|
||||
if (extendedAggregateOperation === DATE_AGGREGATE_OPERATIONS.latest) {
|
||||
return AGGREGATE_OPERATIONS.max;
|
||||
if (extendedAggregateOperation === DateAggregateOperations.LATEST) {
|
||||
return AggregateOperations.MAX;
|
||||
}
|
||||
return extendedAggregateOperation;
|
||||
};
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
|
||||
import { DateAggregateOperations } from '@/object-record/record-table/constants/DateAggregateOperations';
|
||||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { capitalize, isFieldMetadataDateKind } from 'twenty-shared/utils';
|
||||
import { FIELD_FOR_TOTAL_COUNT_AGGREGATE_OPERATION } from 'twenty-shared/constants';
|
||||
import { capitalize, isFieldMetadataDateKind } from 'twenty-shared/utils';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
type NameForAggregation = {
|
||||
[T in ExtendedAggregateOperations]?: string;
|
||||
@ -25,53 +25,53 @@ export const getAvailableAggregationsFromObjectFields = (
|
||||
|
||||
if (field.type === FieldMetadataType.RELATION) {
|
||||
acc[field.name] = {
|
||||
[AGGREGATE_OPERATIONS.count]: 'totalCount',
|
||||
[AggregateOperations.COUNT]: 'totalCount',
|
||||
};
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc[field.name] = {
|
||||
[AGGREGATE_OPERATIONS.countUniqueValues]: `countUniqueValues${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.countEmpty]: `countEmpty${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.countNotEmpty]: `countNotEmpty${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.percentageEmpty]: `percentageEmpty${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.percentageNotEmpty]: `percentageNotEmpty${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.count]: 'totalCount',
|
||||
[AggregateOperations.COUNT_UNIQUE_VALUES]: `countUniqueValues${capitalize(field.name)}`,
|
||||
[AggregateOperations.COUNT_EMPTY]: `countEmpty${capitalize(field.name)}`,
|
||||
[AggregateOperations.COUNT_NOT_EMPTY]: `countNotEmpty${capitalize(field.name)}`,
|
||||
[AggregateOperations.PERCENTAGE_EMPTY]: `percentageEmpty${capitalize(field.name)}`,
|
||||
[AggregateOperations.PERCENTAGE_NOT_EMPTY]: `percentageNotEmpty${capitalize(field.name)}`,
|
||||
[AggregateOperations.COUNT]: 'totalCount',
|
||||
};
|
||||
|
||||
if (field.type === FieldMetadataType.NUMBER) {
|
||||
acc[field.name] = {
|
||||
...acc[field.name],
|
||||
[AGGREGATE_OPERATIONS.min]: `min${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.max]: `max${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.avg]: `avg${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.sum]: `sum${capitalize(field.name)}`,
|
||||
[AggregateOperations.MIN]: `min${capitalize(field.name)}`,
|
||||
[AggregateOperations.MAX]: `max${capitalize(field.name)}`,
|
||||
[AggregateOperations.AVG]: `avg${capitalize(field.name)}`,
|
||||
[AggregateOperations.SUM]: `sum${capitalize(field.name)}`,
|
||||
};
|
||||
}
|
||||
|
||||
if (field.type === FieldMetadataType.CURRENCY) {
|
||||
acc[field.name] = {
|
||||
...acc[field.name],
|
||||
[AGGREGATE_OPERATIONS.min]: `min${capitalize(field.name)}AmountMicros`,
|
||||
[AGGREGATE_OPERATIONS.max]: `max${capitalize(field.name)}AmountMicros`,
|
||||
[AGGREGATE_OPERATIONS.avg]: `avg${capitalize(field.name)}AmountMicros`,
|
||||
[AGGREGATE_OPERATIONS.sum]: `sum${capitalize(field.name)}AmountMicros`,
|
||||
[AggregateOperations.MIN]: `min${capitalize(field.name)}AmountMicros`,
|
||||
[AggregateOperations.MAX]: `max${capitalize(field.name)}AmountMicros`,
|
||||
[AggregateOperations.AVG]: `avg${capitalize(field.name)}AmountMicros`,
|
||||
[AggregateOperations.SUM]: `sum${capitalize(field.name)}AmountMicros`,
|
||||
};
|
||||
}
|
||||
|
||||
if (field.type === FieldMetadataType.BOOLEAN) {
|
||||
acc[field.name] = {
|
||||
...acc[field.name],
|
||||
[AGGREGATE_OPERATIONS.countTrue]: `countTrue${capitalize(field.name)}`,
|
||||
[AGGREGATE_OPERATIONS.countFalse]: `countFalse${capitalize(field.name)}`,
|
||||
[AggregateOperations.COUNT_TRUE]: `countTrue${capitalize(field.name)}`,
|
||||
[AggregateOperations.COUNT_FALSE]: `countFalse${capitalize(field.name)}`,
|
||||
};
|
||||
}
|
||||
|
||||
if (isFieldMetadataDateKind(field.type) === true) {
|
||||
acc[field.name] = {
|
||||
...acc[field.name],
|
||||
[DATE_AGGREGATE_OPERATIONS.earliest]: `min${capitalize(field.name)}`,
|
||||
[DATE_AGGREGATE_OPERATIONS.latest]: `max${capitalize(field.name)}`,
|
||||
[DateAggregateOperations.EARLIEST]: `min${capitalize(field.name)}`,
|
||||
[DateAggregateOperations.LATEST]: `max${capitalize(field.name)}`,
|
||||
};
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ export const getAvailableAggregationsFromObjectFields = (
|
||||
},
|
||||
{
|
||||
[FIELD_FOR_TOTAL_COUNT_AGGREGATE_OPERATION]: {
|
||||
[AGGREGATE_OPERATIONS.count]: 'totalCount',
|
||||
[AggregateOperations.COUNT]: 'totalCount',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user