Files
nocodb/packages/nc-gui/utils/aggregationUtils.ts

28 lines
942 B
TypeScript

import { type ColumnType, type SerializerOrParserFnProps, formatAggregation, formatBytes } from 'nocodb-sdk'
import { aggregationCache } from '../components/smartsheet/grid/canvas/utils/canvas'
export { formatBytes }
export const getFormattedAggrationValue = (
aggregation: string,
value: any,
col: ColumnType,
cacheKeyPath: string[] = [],
columnHelperParams?: SerializerOrParserFnProps['params'],
) => {
const cacheKey = `${col.id}-${col.uidt}-${aggregation}-${value?.toString()}-${cacheKeyPath.join('-')}-${
columnHelperParams?.meta?.columnsHash
}`
const cacheValue = aggregationCache.get(cacheKey)
if (!ncIsUndefined(cacheValue)) {
return isValidValue(cacheValue) ? cacheValue : undefined
}
const aggregationValue = formatAggregation(aggregation, value, col, columnHelperParams)
aggregationCache.set(cacheKey, aggregationValue)
return isValidValue(aggregationValue) ? aggregationValue : undefined
}