Skip to main content

Threshold

Threshold settings allow users to define multiple threshold values with associated colors and descriptions. This is particularly useful for metrics that have different states or levels (e.g., warning, critical, failure).

Basic Usage​

import { useMMAppSetting } from '@machinemetrics/mm-react-tools';
import { Palette } from '@machinemetrics/mm-react-tools';

function MyWidget() {
useMMAppSetting('utilization', {
type: 'thresholds',
fields: [
{
name: 'goal',
label: 'Goal %',
color: Palette.Green600,
description: 'At or above this value',
},
{
name: 'warning',
label: 'Warning %',
color: Palette.Orange500,
description: 'Below goal but above this value',
},
{
name: 'failure',
label: 'Failure %',
color: Palette.Red600,
description: 'Below this value',
},
],
});
}

Properties​

PropertyTypeDescription
type"thresholds"Must be set to "thresholds"
fieldsarrayArray of threshold field objects
visiblebooleanWhether the setting is visible

Threshold Field Properties​

PropertyTypeDescription
namestringUnique identifier for the threshold
labelstringDisplay label for the threshold
colorstringColor for the threshold (using Palette)
descriptionstringDescription of what the threshold means
valuenumberA hardcoded value
maxnumberMaximum allowed value
minnumberMinimum allowed value

Examples​

Basic Thresholds with Dependencies​

useMMAppSetting(
'utilization',
{
type: 'thresholds',
visible: thresholdEnabled === 'custom',
fields: [
{
name: 'goal',
label: 'Goal %',
color: Palette.Green600,
description: `At or above ${utilization?.warning || '-'}% in-cycle`,
value: utilization?.warning,
},
{
name: 'warning',
label: 'Warning %',
color: Palette.Orange500,
description: `Below ${utilization?.warning || '-'}% in-cycle`,
},
{
name: 'failure',
label: 'Failure %',
color: Palette.Red600,
description: `Below ${utilization?.failure || '-'}% in-cycle`,
max: utilization?.warning,
},
],
},
[thresholdEnabled, utilization],
);

Thresholds with Dynamic Descriptions​

useMMAppSetting('quality', {
type: 'thresholds',
fields: [
{
name: 'excellent',
label: 'Excellent',
color: Palette.Green600,
description: `Quality rate >= ${quality?.excellent || 0}%`,
},
{
name: 'good',
label: 'Good',
color: Palette.Orange500,
description: `Quality rate between ${quality?.good || 0}% and ${quality?.excellent || 0}%`,
},
{
name: 'poor',
label: 'Poor',
color: Palette.Red600,
description: `Quality rate < ${quality?.good || 0}%`,
},
],
});