* #3476 round sum total amount in board * Fix issues --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -29,6 +29,7 @@ export const variables = {
|
|||||||
updatePayload: {
|
updatePayload: {
|
||||||
description: 'newDescription',
|
description: 'newDescription',
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
|
labelIdentifierFieldMetadataId: null,
|
||||||
labelPlural: 'labelPlural',
|
labelPlural: 'labelPlural',
|
||||||
labelSingular: 'labelSingular',
|
labelSingular: 'labelSingular',
|
||||||
namePlural: 'labelPlural',
|
namePlural: 'labelPlural',
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { selectorFamily } from 'recoil';
|
import { selectorFamily } from 'recoil';
|
||||||
|
|
||||||
import { companyProgressesFamilyState } from '@/companies/states/companyProgressesFamilyState';
|
import { companyProgressesFamilyState } from '@/companies/states/companyProgressesFamilyState';
|
||||||
|
import { amountFormat } from '~/utils/format/amountFormat';
|
||||||
|
|
||||||
import { recordBoardCardIdsByColumnIdFamilyState } from '../recordBoardCardIdsByColumnIdFamilyState';
|
import { recordBoardCardIdsByColumnIdFamilyState } from '../recordBoardCardIdsByColumnIdFamilyState';
|
||||||
|
|
||||||
@ -26,6 +27,6 @@ export const recordBoardColumnTotalsFamilySelector = selectorFamily({
|
|||||||
0,
|
0,
|
||||||
) || 0;
|
) || 0;
|
||||||
|
|
||||||
return pipelineStepTotal;
|
return amountFormat(pipelineStepTotal);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
11
packages/twenty-front/src/utils/format/amountFormat.ts
Normal file
11
packages/twenty-front/src/utils/format/amountFormat.ts
Normal 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';
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user