fixing Numbers formatting (#14403)
fix #13880 --------- Co-authored-by: Félix Malfait <felix@twenty.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { ApolloError } from '@apollo/client';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { formatNumber } from '~/utils/format/number';
|
||||
import { formatNumber } from '~/utils/format/formatNumber';
|
||||
|
||||
export const useBatchCreateManyRecords = <
|
||||
CreatedObjectRecord extends ObjectRecord = ObjectRecord,
|
||||
|
||||
+3
-3
@@ -13,8 +13,8 @@ import isEmpty from 'lodash.isempty';
|
||||
import { FIELD_FOR_TOTAL_COUNT_AGGREGATE_OPERATION } from 'twenty-shared/constants';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { formatAmount } from '~/utils/format/formatAmount';
|
||||
import { formatNumber } from '~/utils/format/number';
|
||||
import { formatToShortNumber } from '~/utils/format/formatToShortNumber';
|
||||
import { formatNumber } from '~/utils/format/formatNumber';
|
||||
import { formatDateString } from '~/utils/string/formatDateString';
|
||||
import { formatDateTimeString } from '~/utils/string/formatDateTimeString';
|
||||
|
||||
@@ -83,7 +83,7 @@ export const computeAggregateValueAndLabel = ({
|
||||
switch (field.type) {
|
||||
case FieldMetadataType.CURRENCY: {
|
||||
value = Number(aggregateValue);
|
||||
value = formatAmount(value / 1_000_000);
|
||||
value = formatToShortNumber(value / 1_000_000);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+28
-12
@@ -1,22 +1,38 @@
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { getNumberFormatFromWorkspaceNumberFormat } from '@/localization/utils/getNumberFormatFromWorkspaceNumberFormat';
|
||||
import { useNumberFieldDisplay } from '@/object-record/record-field/ui/meta-types/hooks/useNumberFieldDisplay';
|
||||
import { NumberDisplay } from '@/ui/field/display/components/NumberDisplay';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { formatAmount } from '~/utils/format/formatAmount';
|
||||
import { formatNumber } from '~/utils/format/number';
|
||||
import { formatToShortNumber } from '~/utils/format/formatToShortNumber';
|
||||
import { formatNumber } from '~/utils/format/formatNumber';
|
||||
|
||||
export const NumberFieldDisplay = () => {
|
||||
const { fieldValue, fieldDefinition } = useNumberFieldDisplay();
|
||||
const decimals = fieldDefinition.metadata.settings?.decimals;
|
||||
const [currentWorkspaceMember] = useRecoilState(currentWorkspaceMemberState);
|
||||
const type = fieldDefinition.metadata.settings?.type;
|
||||
const decimals = fieldDefinition.metadata.settings?.decimals;
|
||||
|
||||
if (!isDefined(fieldValue))
|
||||
return <NumberDisplay value={null} decimals={decimals} />;
|
||||
const value =
|
||||
type === 'percentage'
|
||||
? `${formatNumber(Number(fieldValue) * 100, decimals)}%`
|
||||
: type === 'shortNumber'
|
||||
? formatAmount(Number(fieldValue))
|
||||
: formatNumber(Number(fieldValue), decimals);
|
||||
if (!isDefined(fieldValue)) {
|
||||
return <NumberDisplay value={null} />;
|
||||
}
|
||||
|
||||
return <NumberDisplay value={value} decimals={decimals} />;
|
||||
const numericValue = Number(fieldValue);
|
||||
let formattedValue: string;
|
||||
|
||||
if (type === 'percentage') {
|
||||
formattedValue = `${formatNumber(numericValue * 100, getNumberFormatFromWorkspaceNumberFormat(currentWorkspaceMember?.numberFormat!), decimals)}%`;
|
||||
} else if (type === 'shortNumber') {
|
||||
formattedValue = formatToShortNumber(numericValue);
|
||||
} else {
|
||||
formattedValue = formatNumber(
|
||||
numericValue,
|
||||
getNumberFormatFromWorkspaceNumberFormat(
|
||||
currentWorkspaceMember?.numberFormat!,
|
||||
),
|
||||
decimals,
|
||||
);
|
||||
}
|
||||
|
||||
return <NumberDisplay value={formattedValue} />;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user