diff --git a/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.styles.scss b/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.styles.scss index 091df7e750..a92d670a91 100644 --- a/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.styles.scss +++ b/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.styles.scss @@ -297,6 +297,16 @@ box-shadow: none; } } + + .invalid-unit { + color: var(--bg-vanilla-400); + font-family: 'Space Mono'; + font-size: 11px; + font-style: normal; + font-weight: 400; + line-height: 16px; + letter-spacing: 0.48px; + } } .threshold-card-container:hover { diff --git a/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.tsx b/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.tsx index dbcdda1d20..6f2a31ff19 100644 --- a/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.tsx +++ b/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.tsx @@ -14,6 +14,7 @@ import { showAsOptions, unitOptions, } from '../constants'; +import { convertUnit } from '../dataFormatCategories'; import ColorSelector from './ColorSelector'; import CustomColor from './CustomColor'; import ShowCaseValue from './ShowCaseValue'; @@ -40,6 +41,7 @@ function Threshold({ thresholdLabel = '', tableOptions, thresholdTableOptions = '', + columnUnits, }: ThresholdProps): JSX.Element { const [isEditMode, setIsEditMode] = useState(isEditEnabled); const [operator, setOperator] = useState( @@ -339,6 +341,12 @@ function Threshold({ )} + {unit !== 'none' && convertUnit(value, unit, columnUnits) === null && ( + + Threshold unit ({unit}) is not valid in comparison with the column unit ( + {columnUnits || 'none'}) + + )} {isEditMode && (
diff --git a/frontend/src/container/NewWidget/RightContainer/Threshold/types.ts b/frontend/src/container/NewWidget/RightContainer/Threshold/types.ts index 820a621d84..96049a36d0 100644 --- a/frontend/src/container/NewWidget/RightContainer/Threshold/types.ts +++ b/frontend/src/container/NewWidget/RightContainer/Threshold/types.ts @@ -1,5 +1,6 @@ import { PANEL_TYPES } from 'constants/queryBuilder'; import { Dispatch, ReactNode, SetStateAction } from 'react'; +import { ColumnUnit } from 'types/api/dashboard/getAll'; export type ThresholdOperators = '>' | '<' | '>=' | '<=' | '='; @@ -19,6 +20,7 @@ export type ThresholdProps = { moveThreshold: (dragIndex: number, hoverIndex: number) => void; selectedGraph: PANEL_TYPES; tableOptions?: Array<{ value: string; label: string }>; + columnUnits?: string; }; export type ShowCaseValueProps = { @@ -36,4 +38,5 @@ export type ThresholdSelectorProps = { thresholds: ThresholdProps[]; setThresholds: Dispatch>; selectedGraph: PANEL_TYPES; + columnUnits: ColumnUnit; }; diff --git a/frontend/src/container/NewWidget/RightContainer/dataFormatCategories.ts b/frontend/src/container/NewWidget/RightContainer/dataFormatCategories.ts index 272a8d442c..e7b85f600c 100644 --- a/frontend/src/container/NewWidget/RightContainer/dataFormatCategories.ts +++ b/frontend/src/container/NewWidget/RightContainer/dataFormatCategories.ts @@ -518,15 +518,6 @@ const conversionFactors: ConversionFactors = { [DataRateFormats.PetaBytesPerSec]: 1000000000000000, [DataRateFormats.PetaBitsPerSec]: 125000000000000, }, - [CategoryNames.HashRate]: { - [HashRateFormats.HashesPerSec]: 1, - [HashRateFormats.KiloHashesPerSec]: 1e3, - [HashRateFormats.MegaHashesPerSec]: 1e6, - [HashRateFormats.GigaHashesPerSec]: 1e9, - [HashRateFormats.TeraHashesPerSec]: 1e12, - [HashRateFormats.PetaHashesPerSec]: 1e15, - [HashRateFormats.ExaHashesPerSec]: 1e18, - }, [CategoryNames.Miscellaneous]: { [MiscellaneousFormats.None]: null, [MiscellaneousFormats.String]: null, @@ -541,205 +532,6 @@ const conversionFactors: ConversionFactors = { [MiscellaneousFormats.LocaleFormat]: null, [MiscellaneousFormats.Pixels]: null, }, - [CategoryNames.Acceleration]: { - [AccelerationFormats.MetersPerSecondSquared]: 1, - [AccelerationFormats.FeetPerSecondSquared]: 0.3048, - [AccelerationFormats.GUnit]: 9.80665, - }, - [CategoryNames.Angle]: { - [AngularFormats.Degree]: 1, - [AngularFormats.Radian]: 57.29577951308232, - [AngularFormats.Gradian]: 0.9, - [AngularFormats.ArcMinute]: 1 / 60, - [AngularFormats.ArcSecond]: 1 / 3600, - }, - [CategoryNames.Area]: { - [AreaFormats.SquareMeters]: 1, - [AreaFormats.SquareFeet]: 0.09290304, - [AreaFormats.SquareMiles]: 2589988.110336, - }, - [CategoryNames.Computation]: { - [FlopsFormats.FLOPs]: 1, - [FlopsFormats.MFLOPs]: 1e6, - [FlopsFormats.GFLOPs]: 1e9, - [FlopsFormats.TFLOPs]: 1e12, - [FlopsFormats.PFLOPs]: 1e15, - [FlopsFormats.EFLOPs]: 1e18, - [FlopsFormats.ZFLOPs]: 1e21, - [FlopsFormats.YFLOPs]: 1e24, - }, - [CategoryNames.Concentration]: { - [ConcentrationFormats.PPM]: 1, - [ConcentrationFormats.PPB]: 0.001, - [ConcentrationFormats.NgM3]: null, // Requires density information - [ConcentrationFormats.NgNM3]: null, // Requires density information - [ConcentrationFormats.UgM3]: null, // Requires density information - [ConcentrationFormats.UgNM3]: null, // Requires density information - [ConcentrationFormats.MgM3]: null, // Requires density information - [ConcentrationFormats.MgNM3]: null, // Requires density information - [ConcentrationFormats.GM3]: null, // Requires density information - [ConcentrationFormats.GNM3]: null, // Requires density information - [ConcentrationFormats.MgDL]: null, // Requires density information - [ConcentrationFormats.MmolL]: null, // Requires molecular weight information - }, - [CategoryNames.Currency]: { - // Exchange rates would need to be updated regularly - [CurrencyFormats.USD]: 1, - [CurrencyFormats.GBP]: null, - [CurrencyFormats.EUR]: null, - [CurrencyFormats.JPY]: null, - [CurrencyFormats.RUB]: null, - [CurrencyFormats.UAH]: null, - [CurrencyFormats.BRL]: null, - [CurrencyFormats.DKK]: null, - [CurrencyFormats.ISK]: null, - [CurrencyFormats.NOK]: null, - [CurrencyFormats.SEK]: null, - [CurrencyFormats.CZK]: null, - [CurrencyFormats.CHF]: null, - [CurrencyFormats.PLN]: null, - [CurrencyFormats.BTC]: null, - [CurrencyFormats.MBTC]: null, - [CurrencyFormats.UBTC]: null, - [CurrencyFormats.ZAR]: null, - [CurrencyFormats.INR]: null, - [CurrencyFormats.KRW]: null, - [CurrencyFormats.IDR]: null, - [CurrencyFormats.PHP]: null, - [CurrencyFormats.VND]: null, - }, - [CategoryNames.Datetime]: { - // These require special handling - [DatetimeFormats.ISO]: null, - [DatetimeFormats.ISONoDateIfToday]: null, - [DatetimeFormats.US]: null, - [DatetimeFormats.USNoDateIfToday]: null, - [DatetimeFormats.Local]: null, - [DatetimeFormats.LocalNoDateIfToday]: null, - [DatetimeFormats.System]: null, - [DatetimeFormats.FromNow]: null, - }, - [CategoryNames.Energy]: { - [PowerElectricalFormats.WATT]: 1, - [PowerElectricalFormats.KWATT]: 1000, - [PowerElectricalFormats.MEGWATT]: 1e6, - [PowerElectricalFormats.GWATT]: 1e9, - [PowerElectricalFormats.MWATT]: 0.001, - [PowerElectricalFormats.WM2]: null, // Requires area information - [PowerElectricalFormats.VOLTAMP]: 1, - [PowerElectricalFormats.KVOLTAMP]: 1000, - [PowerElectricalFormats.VOLTAMPREACT]: 1, - [PowerElectricalFormats.KVOLTAMPREACT]: 1000, - [PowerElectricalFormats.WATTH]: 3600, - [PowerElectricalFormats.WATTHPERKG]: null, // Requires mass information - [PowerElectricalFormats.KWATTH]: 3.6e6, - [PowerElectricalFormats.KWATTM]: 60000, - [PowerElectricalFormats.AMPH]: null, // Requires voltage information - [PowerElectricalFormats.KAMPH]: null, // Requires voltage information - [PowerElectricalFormats.MAMPH]: null, // Requires voltage information - [PowerElectricalFormats.JOULE]: 1, - [PowerElectricalFormats.EV]: 1.602176634e-19, - [PowerElectricalFormats.AMP]: null, // Requires voltage information - [PowerElectricalFormats.KAMP]: null, // Requires voltage information - [PowerElectricalFormats.MAMP]: null, // Requires voltage information - [PowerElectricalFormats.VOLT]: null, // Requires current information - [PowerElectricalFormats.KVOLT]: null, // Requires current information - [PowerElectricalFormats.MVOLT]: null, // Requires current information - [PowerElectricalFormats.DBM]: null, // Requires special conversion - [PowerElectricalFormats.OHM]: null, // Requires voltage and current information - [PowerElectricalFormats.KOHM]: null, // Requires voltage and current information - [PowerElectricalFormats.MOHM]: null, // Requires voltage and current information - [PowerElectricalFormats.FARAD]: null, // Capacitance unit, not directly convertible - [PowerElectricalFormats.µFARAD]: null, // Capacitance unit, not directly convertible - [PowerElectricalFormats.NFARAD]: null, // Capacitance unit, not directly convertible - [PowerElectricalFormats.PFARAD]: null, // Capacitance unit, not directly convertible - [PowerElectricalFormats.FFARAD]: null, // Capacitance unit, not directly convertible - [PowerElectricalFormats.HENRY]: null, // Inductance unit, not directly convertible - [PowerElectricalFormats.MHENRY]: null, // Inductance unit, not directly convertible - [PowerElectricalFormats.µHENRY]: null, // Inductance unit, not directly convertible - [PowerElectricalFormats.LUMENS]: null, // Luminous flux unit, not directly convertible - }, - [CategoryNames.Flow]: { - [FlowFormats.FLOWGPM]: 0.00006309020833, - [FlowFormats.FLOWCMS]: 1, - [FlowFormats.FLOWCFS]: 0.028316846592, - [FlowFormats.FLOWCFM]: 0.000471, - [FlowFormats.LITREH]: 2.777777777778e-7, - [FlowFormats.FLOWLPM]: 1.666666666667e-5, - [FlowFormats.FLOWMLPM]: 1.666666666667e-8, - [FlowFormats.LUX]: null, // Light measurement, not directly convertible - }, - [CategoryNames.Force]: { - [ForceFormats.FORCENM]: 1, - [ForceFormats.FORCEKNM]: 1000, - [ForceFormats.FORCEN]: null, // Requires distance information - [ForceFormats.FORCEKN]: null, // Requires distance information - }, - [CategoryNames.Mass]: { - [MassFormats.MASSMG]: 0.000001, - [MassFormats.MASSG]: 0.001, - [MassFormats.MASSLB]: 0.45359237, - [MassFormats.MASSKG]: 1, - [MassFormats.MASST]: 1000, - }, - [CategoryNames.Length]: { - [LengthFormats.LENGTHMM]: 0.001, - [LengthFormats.LENGTHIN]: 0.0254, - [LengthFormats.LENGTHFT]: 0.3048, - [LengthFormats.LENGTHM]: 1, - [LengthFormats.LENGTHKM]: 1000, - [LengthFormats.LENGTHMI]: 1609.344, - }, - [CategoryNames.Pressure]: { - [PressureFormats.PRESSUREMBAR]: 100, - [PressureFormats.PRESSUREBAR]: 100000, - [PressureFormats.PRESSUREKBAR]: 100000000, - [PressureFormats.PRESSUREPA]: 1, - [PressureFormats.PRESSUREHPA]: 100, - [PressureFormats.PRESSUREKPA]: 1000, - [PressureFormats.PRESSUREHG]: 3386.389, - [PressureFormats.PRESSUREPSI]: 6894.75729, - }, - [CategoryNames.Radiation]: { - [RadiationFormats.RADBQ]: 1, - [RadiationFormats.RADCI]: 3.7e10, - [RadiationFormats.RADGY]: 1, - [RadiationFormats.RADRAD]: 0.01, - [RadiationFormats.RADSV]: 1, - [RadiationFormats.RADMSV]: 0.001, - [RadiationFormats.RADUSV]: 0.000001, - [RadiationFormats.RADREM]: 0.01, - [RadiationFormats.RADEXPCKG]: 1, - [RadiationFormats.RADR]: 0.000258, - [RadiationFormats.RADSVH]: 3600, - [RadiationFormats.RADMSVH]: 3.6, - [RadiationFormats.RADUSVH]: 0.0036, - }, - [CategoryNames.RotationSpeed]: { - [RotationSpeedFormats.ROTRPM]: 0.10471975512, - [RotationSpeedFormats.ROTHZ]: 6.283185307, - [RotationSpeedFormats.ROTRADS]: 1, - [RotationSpeedFormats.ROTDEGS]: 0.017453292519943295, - }, - [CategoryNames.Temperature]: { - [TemperatureFormats.CELSIUS]: null, // Requires special conversion - [TemperatureFormats.FAHRENHEIT]: null, // Requires special conversion - [TemperatureFormats.KELVIN]: null, // Requires special conversion - }, - [CategoryNames.Velocity]: { - [VelocityFormats.METERS_PER_SECOND]: 1, - [VelocityFormats.KILOMETERS_PER_HOUR]: 0.277777778, - [VelocityFormats.MILES_PER_HOUR]: 0.44704, - [VelocityFormats.KNOT]: 0.514444444, - }, - [CategoryNames.Volume]: { - [VolumeFormats.MILLILITRE]: 0.000001, - [VolumeFormats.LITRE]: 0.001, - [VolumeFormats.CUBIC_METER]: 1, - [VolumeFormats.NORMAL_CUBIC_METER]: 1, // Assuming standard temperature and pressure - [VolumeFormats.CUBIC_DECIMETER]: 0.001, - [VolumeFormats.GALLONS]: 0.00378541, - }, [CategoryNames.Boolean]: { [BooleanFormats.TRUE_FALSE]: null, // Not convertible [BooleanFormats.YES_NO]: null, // Not convertible diff --git a/frontend/src/container/NewWidget/RightContainer/index.tsx b/frontend/src/container/NewWidget/RightContainer/index.tsx index 43e3b5611d..55968c5aee 100644 --- a/frontend/src/container/NewWidget/RightContainer/index.tsx +++ b/frontend/src/container/NewWidget/RightContainer/index.tsx @@ -311,6 +311,7 @@ function RightContainer({ setThresholds={setThresholds} yAxisUnit={yAxisUnit} selectedGraph={selectedGraph} + columnUnits={columnUnits} /> )}