-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aggregate follow-up #9547
Aggregate follow-up #9547
Changes from all commits
531d4fe
1aa4c2b
2b3633b
83bdc06
2ddfbe5
cff6b16
f98aefe
adfb7ac
226b59a
f308ad0
3f2f4bb
f6030ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations'; | ||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations'; | ||
|
||
export type RecordGqlFieldsAggregate = Record<string, AGGREGATE_OPERATIONS[]>; | ||
export type RecordGqlFieldsAggregate = Record< | ||
string, | ||
ExtendedAggregateOperations[] | ||
>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ 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 { 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/percentAggregateOperationOption'; | ||
import { PERCENT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/percentAggregateOperationOptions'; | ||
import { AvailableFieldsForAggregateOperation } from '@/object-record/types/AvailableFieldsForAggregateOperation'; | ||
import { getAvailableFieldsIdsForAggregationFromObjectFields } from '@/object-record/utils/getAvailableFieldsIdsForAggregationFromObjectFields'; | ||
|
||
|
@@ -41,15 +42,31 @@ export const AggregateDropdownContent = () => { | |
/> | ||
); | ||
} | ||
case 'datesAggregateOperationOptions': { | ||
const datesAvailableAggregations: AvailableFieldsForAggregateOperation = | ||
getAvailableFieldsIdsForAggregationFromObjectFields( | ||
objectMetadataItem.fields, | ||
[ | ||
DATE_AGGREGATE_OPERATIONS.earliest, | ||
DATE_AGGREGATE_OPERATIONS.latest, | ||
], | ||
Comment on lines
+49
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using DATE_AGGREGATE_OPERATIONS as an array directly rather than hardcoding array elements to avoid potential sync issues if new operations are added |
||
); | ||
return ( | ||
<RecordBoardColumnHeaderAggregateDropdownOptionsContent | ||
availableAggregations={datesAvailableAggregations} | ||
title="Dates" | ||
/> | ||
); | ||
} | ||
case 'moreAggregateOperationOptions': { | ||
const availableAggregations: AvailableFieldsForAggregateOperation = | ||
const availableAggregationsWithoutDates: AvailableFieldsForAggregateOperation = | ||
getAvailableFieldsIdsForAggregationFromObjectFields( | ||
objectMetadataItem.fields, | ||
NON_STANDARD_AGGREGATE_OPERATION_OPTIONS, | ||
); | ||
return ( | ||
<RecordBoardColumnHeaderAggregateDropdownOptionsContent | ||
availableAggregations={availableAggregations} | ||
availableAggregations={availableAggregationsWithoutDates} | ||
title="More options" | ||
/> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ import { AggregateRecordsData } from '@/object-record/hooks/useAggregateRecords' | |
import { getAggregateOperationLabel } from '@/object-record/record-board/record-board-column/utils/getAggregateOperationLabel'; | ||
import { AGGREGATE_OPERATIONS } 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/percentAggregateOperationOption'; | ||
import { convertAggregateOperationToExtendedAggregateOperation } from '@/object-record/utils/convertAggregateOperationToExtendedAggregateOperation'; | ||
import { PERCENT_AGGREGATE_OPERATION_OPTIONS } from '@/object-record/record-table/record-table-footer/constants/percentAggregateOperationOptions'; | ||
import { ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations'; | ||
import isEmpty from 'lodash.isempty'; | ||
import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
import { formatAmount } from '~/utils/format/formatAmount'; | ||
|
@@ -28,7 +28,7 @@ export const computeAggregateValueAndLabel = ({ | |
data: AggregateRecordsData; | ||
objectMetadataItem: ObjectMetadataItem; | ||
fieldMetadataId?: string | null; | ||
aggregateOperation?: AGGREGATE_OPERATIONS | null; | ||
aggregateOperation?: ExtendedAggregateOperations | null; | ||
fallbackFieldName?: string; | ||
dateFormat: DateFormat; | ||
timeFormat: TimeFormat; | ||
|
@@ -62,11 +62,19 @@ export const computeAggregateValueAndLabel = ({ | |
|
||
const displayAsRelativeDate = field?.settings?.displayAsRelativeDate; | ||
|
||
if (COUNT_AGGREGATE_OPERATION_OPTIONS.includes(aggregateOperation)) { | ||
if ( | ||
COUNT_AGGREGATE_OPERATION_OPTIONS.includes( | ||
aggregateOperation as AGGREGATE_OPERATIONS, | ||
) | ||
) { | ||
Comment on lines
+65
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: type assertion here could mask potential type mismatches between ExtendedAggregateOperations and AGGREGATE_OPERATIONS |
||
value = aggregateValue; | ||
} else if (!isDefined(aggregateValue)) { | ||
value = '-'; | ||
} else if (PERCENT_AGGREGATE_OPERATION_OPTIONS.includes(aggregateOperation)) { | ||
} else if ( | ||
PERCENT_AGGREGATE_OPERATION_OPTIONS.includes( | ||
aggregateOperation as AGGREGATE_OPERATIONS, | ||
) | ||
) { | ||
value = `${formatNumber(Number(aggregateValue) * 100)}%`; | ||
} else { | ||
switch (field.type) { | ||
|
@@ -110,16 +118,11 @@ export const computeAggregateValueAndLabel = ({ | |
} | ||
} | ||
} | ||
const convertedAggregateOperation = | ||
convertAggregateOperationToExtendedAggregateOperation( | ||
aggregateOperation, | ||
field.type, | ||
); | ||
const label = getAggregateOperationLabel(convertedAggregateOperation); | ||
const label = getAggregateOperationLabel(aggregateOperation); | ||
const labelWithFieldName = | ||
aggregateOperation === AGGREGATE_OPERATIONS.count | ||
? `${getAggregateOperationLabel(AGGREGATE_OPERATIONS.count)}` | ||
: `${getAggregateOperationLabel(convertedAggregateOperation)} of ${field.label}`; | ||
: `${getAggregateOperationLabel(aggregateOperation)} of ${field.label}`; | ||
|
||
return { | ||
value, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: toggling dropdown before resetting could cause visual glitches - consider resetting first