Skip to content

Commit

Permalink
fix: added invalid comparison text and removed unsupported unit categ…
Browse files Browse the repository at this point in the history
…ories
  • Loading branch information
SagarRajput-7 committed Oct 2, 2024
1 parent 029e0e1 commit a7cea12
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -40,6 +41,7 @@ function Threshold({
thresholdLabel = '',
tableOptions,
thresholdTableOptions = '',
columnUnits,
}: ThresholdProps): JSX.Element {
const [isEditMode, setIsEditMode] = useState<boolean>(isEditEnabled);
const [operator, setOperator] = useState<string | number>(
Expand Down Expand Up @@ -339,6 +341,12 @@ function Threshold({
</>
)}
</div>
{unit !== 'none' && convertUnit(value, unit, columnUnits) === null && (
<Typography.Text className="invalid-unit">
Threshold unit ({unit}) is not valid in comparison with the column unit (
{columnUnits || 'none'})
</Typography.Text>
)}
{isEditMode && (
<div className="threshold-action-button">
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function ThresholdSelector({
setThresholds,
yAxisUnit,
selectedGraph,
columnUnits,
}: ThresholdSelectorProps): JSX.Element {
const [tableOptions, setTableOptions] = useState<
Array<{ value: string; label: string }>
Expand Down Expand Up @@ -107,6 +108,7 @@ function ThresholdSelector({
thresholdLabel={threshold.thresholdLabel}
tableOptions={tableOptions}
thresholdTableOptions={threshold.thresholdTableOptions}
columnUnits={columnUnits[threshold.thresholdTableOptions || '']}
/>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = '>' | '<' | '>=' | '<=' | '=';

Expand All @@ -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 = {
Expand All @@ -36,4 +38,5 @@ export type ThresholdSelectorProps = {
thresholds: ThresholdProps[];
setThresholds: Dispatch<SetStateAction<ThresholdProps[]>>;
selectedGraph: PANEL_TYPES;
columnUnits: ColumnUnit;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions frontend/src/container/NewWidget/RightContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ function RightContainer({
setThresholds={setThresholds}
yAxisUnit={yAxisUnit}
selectedGraph={selectedGraph}
columnUnits={columnUnits}
/>
</section>
)}
Expand Down

0 comments on commit a7cea12

Please sign in to comment.