-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Aggregate queries for table views - #2] Add aggregate queries footer…
… for simple views (#9025) In this PR, we are introducing aggregate queries on table views, behind a feature flag. This does not work with view groups yet, nor with views that have records until the bottom. (both will be tackled next)
- Loading branch information
Showing
20 changed files
with
662 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 32 additions & 24 deletions
56
...les/object-record/record-board/record-board-column/utils/computeAggregateValueAndLabel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,59 @@ | ||
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 { KanbanAggregateOperation } from '@/object-record/record-index/states/recordIndexKanbanAggregateOperationState'; | ||
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations'; | ||
import isEmpty from 'lodash.isempty'; | ||
import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
export const computeAggregateValueAndLabel = ( | ||
data: AggregateRecordsData, | ||
objectMetadataItem: ObjectMetadataItem, | ||
recordIndexKanbanAggregateOperation: KanbanAggregateOperation, | ||
kanbanFieldName: string, | ||
) => { | ||
export const computeAggregateValueAndLabel = ({ | ||
data, | ||
objectMetadataItem, | ||
fieldMetadataId, | ||
aggregateOperation, | ||
fallbackFieldName, | ||
}: { | ||
data: AggregateRecordsData; | ||
objectMetadataItem: ObjectMetadataItem; | ||
fieldMetadataId?: string | null; | ||
aggregateOperation?: AGGREGATE_OPERATIONS | null; | ||
fallbackFieldName?: string; | ||
}) => { | ||
if (isEmpty(data)) { | ||
return {}; | ||
} | ||
const kanbanAggregateOperationField = objectMetadataItem.fields?.find( | ||
(field) => | ||
field.id === recordIndexKanbanAggregateOperation?.fieldMetadataId, | ||
const field = objectMetadataItem.fields?.find( | ||
(field) => field.id === fieldMetadataId, | ||
); | ||
|
||
const kanbanAggregateOperationFieldName = kanbanAggregateOperationField?.name; | ||
|
||
if ( | ||
!isDefined(kanbanAggregateOperationFieldName) || | ||
!isDefined(recordIndexKanbanAggregateOperation?.operation) | ||
) { | ||
if (!isDefined(field)) { | ||
if (!fallbackFieldName) { | ||
throw new Error('Missing fallback field name'); | ||
} | ||
return { | ||
value: data?.[kanbanFieldName]?.[AGGREGATE_OPERATIONS.count], | ||
value: data?.[fallbackFieldName]?.[AGGREGATE_OPERATIONS.count], | ||
label: `${getAggregateOperationLabel(AGGREGATE_OPERATIONS.count)}`, | ||
}; | ||
} | ||
|
||
const aggregateValue = | ||
data[kanbanAggregateOperationFieldName]?.[ | ||
recordIndexKanbanAggregateOperation.operation | ||
]; | ||
if (!isDefined(aggregateOperation)) { | ||
throw new Error('Missing aggregate operation'); | ||
} | ||
|
||
const aggregateValue = data[field.name]?.[aggregateOperation]; | ||
|
||
const value = | ||
isDefined(aggregateValue) && | ||
kanbanAggregateOperationField?.type === FieldMetadataType.Currency | ||
isDefined(aggregateValue) && field.type === FieldMetadataType.Currency | ||
? Number(aggregateValue) / 1_000_000 | ||
: aggregateValue; | ||
|
||
const label = | ||
aggregateOperation === AGGREGATE_OPERATIONS.count | ||
? `${getAggregateOperationLabel(AGGREGATE_OPERATIONS.count)}` | ||
: `${getAggregateOperationLabel(aggregateOperation)} of ${field.name}`; | ||
|
||
return { | ||
value, | ||
label: `${getAggregateOperationLabel(recordIndexKanbanAggregateOperation.operation)} of ${kanbanAggregateOperationFieldName}`, | ||
label, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.