File tree Expand file tree Collapse file tree
Plan/react/dashboard/src/util/format Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export const useDecimalFormatter = () => {
66 const { decimalFormat} = usePreferences ( ) ;
77
88 const formatDecimals = useCallback ( ( value ) => {
9- if ( ! decimalFormat || Number . isNaN ( value ) || isString ( value ) ) return value ;
9+ if ( ! decimalFormat || Number . isNaN ( Number ( value ) ) || isString ( value ) ) return value ;
1010 const split = decimalFormat . includes ( '.' ) ? decimalFormat . split ( '.' ) : decimalFormat . split ( ',' ) ;
1111 if ( split . length <= 1 ) return value . toFixed ( 0 ) ;
1212 return value . toFixed ( split [ 1 ] . length ) ;
Original file line number Diff line number Diff line change 11import { isNumber } from "../isNumber.js" ;
22import { useCallback , useMemo } from "react" ;
33import { useI18nFriendlyLanguage } from "../../service/localeService.js" ;
4+ import { useDecimalFormatter } from "./useDecimalFormatter.js" ;
45
56export const usePingFormatter = ( ) => {
67 const locale = useI18nFriendlyLanguage ( ) ;
8+ const { formatDecimals} = useDecimalFormatter ( ) ;
79 const formatter = useMemo ( ( ) => {
810 return new Intl . DurationFormat ( locale , { style : 'narrow' } )
911 } , [ locale ] ) ;
1012
1113 const formatPing = useCallback ( ( value ) => {
1214 if ( isNumber ( value ) && ! String ( value ) . includes ( "ms" ) ) {
13- const split = isNumber ( value ) ? [ value ] : value . split ( '.' ) ;
14- const decimals = split . length > 1 ? split [ 1 ] : value % 1 ;
15- const parts = formatter . formatToParts ( { milliseconds : Math . floor ( Number ( split [ 0 ] ) ) } ) ;
16-
17- const ints = parts . map ( ( part , i ) => part . type === 'integer' ? i : - 1 )
18- . filter ( ( i ) => i >= 0 ) ;
19- const lastIndex = ints [ ints . length - 1 ] ;
20- return parts . map ( ( part , i ) => {
21- if ( part . type === 'group' ) {
22- return '' ;
23- }
24- if ( lastIndex === i && split . length > 1 ) {
25- return isNumber ( decimals ) ? Number ( part . value ) + decimals : part . value + '.' + decimals ;
26- }
27- return part . value ;
28- } ) . join ( '' ) ;
15+ return formatter . format ( { milliseconds : 1 } ) . replaceAll ( "1" , formatDecimals ( value ) )
2916 }
3017 return value ;
3118 } , [ formatter ] ) ;
You can’t perform that action at this time.
0 commit comments