@@ -10,7 +10,7 @@ import {GenericFilter} from "../../dataHooks/model/GenericFilter";
1010import { useNavigation } from "../../hooks/navigationHook" ;
1111import { useQuery } from "@tanstack/react-query" ;
1212import { queryRetry } from "../../dataHooks/queryRetry" ;
13- import { useEffect } from "react" ;
13+ import React , { useEffect } from "react" ;
1414import { Datapoint as DatapointComponent , DatapointProps } from "./Datapoint" ;
1515import FormattedTime from "../text/FormattedTime" ;
1616import { DatapointLoader } from "../navigation/Loader" ;
@@ -22,11 +22,14 @@ import {useTranslation} from "react-i18next";
2222import { DateObj , isDateObj } from "../../dataHooks/model/datapoint/DateObj" ;
2323import FormattedDate from "../text/FormattedDate" ;
2424import BigTrend from "../trend/BigTrend" ;
25+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
26+ import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons" ;
2527
2628type Props < K extends DatapointType > = {
2729 dataType : K ;
2830 filter ?: GenericFilter ;
2931 permission ?: string ;
32+ fallbackUnavailableExplanation ?: string
3033} & Omit < DatapointProps , 'value' > ;
3134
3235type ValueProps < K extends DatapointType > = Omit < Props < K > , 'color' | 'name' | 'icon' > ;
@@ -67,6 +70,8 @@ function Format<K extends DatapointType>({value, formatType}: FormatProps<K>) {
6770 return < FormattedTime timeMs = { value } />
6871 case "PERCENTAGE" :
6972 return formatDecimals ( value as number * 100 ) + '%'
73+ case "DECIMAL" :
74+ return formatDecimals ( value as number )
7075 case "SPECIAL" :
7176 if ( isOutOf ( value ) ) {
7277 return < FormattedOutOf outOf = { value as OutOf } />
@@ -94,13 +99,27 @@ export function calculatePermission(dataType: DatapointType, permission?: string
9499 return 'data.network.' + asPermission ;
95100}
96101
97- export function QueryDatapoint < K extends DatapointType > ( { permission, dataType, filter, ...props } : Props < K > ) {
102+ export function QueryDatapoint < K extends DatapointType > ( {
103+ permission,
104+ dataType,
105+ filter,
106+ fallbackUnavailableExplanation,
107+ ...props
108+ } : Props < K > ) {
98109 const { hasPermission} = useAuth ( ) ;
99110 const allowed = hasPermission ( calculatePermission ( dataType , permission , filter ) ) ;
100111 const { data, isFetching, error} = useDatapointQuery ( allowed , dataType , filter ) ;
101112
102113 if ( ! allowed ) return null ;
103114 if ( error ) {
115+ if ( error . status === 404 ) {
116+ return < DatapointComponent
117+ { ...props }
118+ value = { 'plugin.generic.unavailable' }
119+ valueLabel = { < span
120+ title = { fallbackUnavailableExplanation } > < FontAwesomeIcon icon = { faQuestionCircle } /> </ span > }
121+ />
122+ }
104123 console . error ( error ) ;
105124 return < DatapointComponent
106125 { ...props }
0 commit comments