forked from ddrilling/asb_cloud_front
Улучшено форматирование значения виджета на дашборде ННБ
This commit is contained in:
parent
4606d96c88
commit
1da3bbe290
@ -17,10 +17,20 @@ export type WidgetSettings<T = any> = {
|
|||||||
unitColor?: string,
|
unitColor?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emptyNumber = '----'
|
||||||
|
|
||||||
|
const defaultFormatter = (v: any) => {
|
||||||
|
if (typeof v === 'undefined' || v === null || String(v) === 'NaN') return emptyNumber
|
||||||
|
if (Number.isNaN(+v)) return v
|
||||||
|
const f = parseFloat(v)
|
||||||
|
if (Number.isFinite(v)) return f.toFixed(2)
|
||||||
|
return `${f < 0 ? '-' : ''}\u221E`
|
||||||
|
}
|
||||||
|
|
||||||
export const defaultSettings: WidgetSettings = {
|
export const defaultSettings: WidgetSettings = {
|
||||||
unit: '----',
|
unit: '----',
|
||||||
label: 'Виджет',
|
label: 'Виджет',
|
||||||
formatter: v => isNaN(v) ? v : parseFloat(v).toFixed(2),
|
formatter: defaultFormatter,
|
||||||
|
|
||||||
labelColor: '#000000',
|
labelColor: '#000000',
|
||||||
valueColor: '#000000',
|
valueColor: '#000000',
|
||||||
@ -57,7 +67,7 @@ export const BaseWidget = memo<BaseWidgetProps>(({ value, onRemove, onEdit, ...s
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={'widget_value'} style={{ color: sets.valueColor }}>
|
<div className={'widget_value'} style={{ color: sets.valueColor }}>
|
||||||
{(sets.formatter === null ? value : sets.formatter?.(value)) ?? sets.defaultValue ?? '----'}
|
{(sets.formatter === null ? value : sets.formatter?.(value)) ?? sets.defaultValue ?? emptyNumber}
|
||||||
</div>
|
</div>
|
||||||
<div className={'widget_units'} style={{ color: sets.unitColor }}>{sets.unit}</div>
|
<div className={'widget_units'} style={{ color: sets.unitColor }}>{sets.unit}</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user