#3476 round sum total amount in board (#3484)

* #3476 round sum total amount in board

* Fix issues

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jeet Desai
2024-01-17 21:14:44 +05:30
committed by GitHub
parent bbfe62df9a
commit e812878bc3
4 changed files with 42 additions and 1 deletions

View File

@ -29,6 +29,7 @@ export const variables = {
updatePayload: {
description: 'newDescription',
icon: undefined,
labelIdentifierFieldMetadataId: null,
labelPlural: 'labelPlural',
labelSingular: 'labelSingular',
namePlural: 'labelPlural',

View File

@ -1,6 +1,7 @@
import { selectorFamily } from 'recoil';
import { companyProgressesFamilyState } from '@/companies/states/companyProgressesFamilyState';
import { amountFormat } from '~/utils/format/amountFormat';
import { recordBoardCardIdsByColumnIdFamilyState } from '../recordBoardCardIdsByColumnIdFamilyState';
@ -26,6 +27,6 @@ export const recordBoardColumnTotalsFamilySelector = selectorFamily({
0,
) || 0;
return pipelineStepTotal;
return amountFormat(pipelineStepTotal);
},
});

View File

@ -0,0 +1,28 @@
import { amountFormat } from '../amountFormat';
describe('amountFormat', () => {
it('formats numbers less than 1000 correctly', () => {
expect(amountFormat(500)).toBe('500');
expect(amountFormat(123.456)).toBe('123.5');
});
it('formats numbers between 1000 and 999999 correctly', () => {
expect(amountFormat(1500)).toBe('1.5k');
expect(amountFormat(789456)).toBe('789.5k');
});
it('formats numbers between 1000000 and 999999999 correctly', () => {
expect(amountFormat(2000000)).toBe('2m');
expect(amountFormat(654987654)).toBe('655m');
});
it('formats numbers greater than or equal to 1000000000 correctly', () => {
expect(amountFormat(1200000000)).toBe('1.2b');
expect(amountFormat(987654321987)).toBe('987.7b');
});
it('handles numbers with decimal places correctly', () => {
expect(amountFormat(123.456)).toBe('123.5');
expect(amountFormat(789.0123)).toBe('789');
});
});

View File

@ -0,0 +1,11 @@
export const amountFormat = (number: number) => {
if (number < 1000) {
return number.toFixed(1).replace(/\.?0+$/, '');
} else if (number < 1000000) {
return (number / 1000).toFixed(1).replace(/\.?0+$/, '') + 'k';
} else if (number < 1000000000) {
return (number / 1000000).toFixed(1).replace(/\.?0+$/, '') + 'm';
} else {
return (number / 1000000000).toFixed(1).replace(/\.?0+$/, '') + 'b';
}
};