diff --git a/package-lock.json b/package-lock.json index 961baacf..21874699 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "@testing-library/user-event": "^14.5.2", "@typescript-eslint/eslint-plugin": "^5.48.2", "@typescript-eslint/parser": "^5.48.2", - "@victronenergy/mfd-modules": "^6.0.3", + "@victronenergy/mfd-modules": "^7.0.0", "axios": "^0.28.1", "babel-eslint": "^10.1.0", "babel-jest": "^26.6.0", @@ -5340,9 +5340,9 @@ } }, "node_modules/@victronenergy/mfd-modules": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/@victronenergy/mfd-modules/-/mfd-modules-6.0.3.tgz", - "integrity": "sha512-gFXuz5QvyS7ytz5ALDibw0KPku+/+mmm75SOW8D65Sb8RQbeQsI6GSOhp7ikadMF+J/Ga40iarcdm7CgiYA7Sw==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@victronenergy/mfd-modules/-/mfd-modules-7.0.0.tgz", + "integrity": "sha512-fWUHfprCMQwlkn+ciGGMQAjgCuRiC9/32b0BVLj3ks/0dtwYJ+ZrBYTd9bembNN2ZEZ0dTl/Iw9hEQHAuGcYfw==", "license": "ISC", "dependencies": { "axios": "^0.28.1", diff --git a/package.json b/package.json index 30d2d2b7..523972ca 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@testing-library/user-event": "^14.5.2", "@typescript-eslint/eslint-plugin": "^5.48.2", "@typescript-eslint/parser": "^5.48.2", - "@victronenergy/mfd-modules": "^6.0.3", + "@victronenergy/mfd-modules": "^7.0.0", "axios": "^0.28.1", "babel-eslint": "^10.1.0", "babel-jest": "^26.6.0", diff --git a/src/app/Marine2/components/boxes/EnvironmentOverview/EnvironmentOverview.tsx b/src/app/Marine2/components/boxes/EnvironmentOverview/EnvironmentOverview.tsx index 6c704a93..2a534240 100644 --- a/src/app/Marine2/components/boxes/EnvironmentOverview/EnvironmentOverview.tsx +++ b/src/app/Marine2/components/boxes/EnvironmentOverview/EnvironmentOverview.tsx @@ -1,6 +1,6 @@ import { observer } from "mobx-react-lite" -import { useTemperatures, TemperatureInstanceId } from "@victronenergy/mfd-modules" -import { useState, createContext, useCallback } from "react" +import { useTemperatures, TemperatureState } from "@victronenergy/mfd-modules" +import { useState } from "react" import { useVisibilityNotifier } from "../../../modules" import Box from "../../ui/Box" import TemperatureData from "./TemperatureData" @@ -19,91 +19,73 @@ interface Props { pageSelectorPropsSetter?: (arg0: PageSelectorProps) => void } -export const VisibleComponentsContext = createContext({ - passVisibility: (id: number, type: SensorInformationType, visible: boolean) => {}, -}) - -type SensorInformationType = "humidity" | "pressure" | "temperature" - const EnvironmentOverview = ({ componentMode = "full", pageSelectorPropsSetter }: Props) => { const { temperatures: sensors } = useTemperatures() - const [visibleElements, setVisibleElements] = useState({}) const [boxSize, setBoxSize] = useState({ width: 0, height: 0 }) - const passVisibility = useCallback((id: number, type: SensorInformationType, visible: boolean) => { - setVisibleElements((prev: any) => ({ - ...prev, - [id]: { - ...prev[id], - [type]: visible, - }, - })) - }, []) - - let temperatureComponents = (sensors || []).map((temperatureId: TemperatureInstanceId) => ( - - )) + let temperatureComponents = (sensors.filter((sensor) => sensor.temperature !== undefined) || []).map( + (sensor: TemperatureState) => ( + + ) + ) - let humidityComponents = (sensors || []).map((temperatureId: TemperatureInstanceId) => ( - - )) + let humidityComponents = (sensors.filter((sensor) => sensor.humidity !== undefined) || []).map( + (sensor: TemperatureState) => ( + + ) + ) - let pressureComponents = (sensors || []).map((temperatureId: TemperatureInstanceId) => ( - - )) + let pressureComponents = (sensors.filter((sensor) => sensor.pressure !== undefined) || []).map( + (sensor: TemperatureState) => ( + + ) + ) const components = [...temperatureComponents, ...humidityComponents, ...pressureComponents] as JSX.Element[] - const sensorHasData: boolean = Object.values(visibleElements).some( - (sensor: any) => sensor.temperature || sensor.humidity || sensor.pressure - ) - const hasValidData = sensorHasData + const hasValidData = components.length > 0 useVisibilityNotifier({ widgetName: BOX_TYPES.ENVIRONMENT, isVisible: hasValidData }) if (componentMode === "compact") { return ( - - } - withPagination={true} - paginationOrientation={"vertical"} - getBoxSizeCallback={setBoxSize} - > - {components} - - + } + withPagination={true} + paginationOrientation={"vertical"} + getBoxSizeCallback={setBoxSize} + > + {components} + ) } return ( - - window.innerHeight ? "row" : "col"} - > - {components} - - + window.innerHeight ? "row" : "col"} + > + {components} + ) } diff --git a/src/app/Marine2/components/boxes/EnvironmentOverview/HumidityData.tsx b/src/app/Marine2/components/boxes/EnvironmentOverview/HumidityData.tsx index ebed68d8..9d7ea315 100644 --- a/src/app/Marine2/components/boxes/EnvironmentOverview/HumidityData.tsx +++ b/src/app/Marine2/components/boxes/EnvironmentOverview/HumidityData.tsx @@ -4,8 +4,6 @@ import ValueOverview from "../../ui/ValueOverview" import HumidityIcon from "../../../images/icons/humidity.svg" import ValueBox from "../../ui/ValueBox" import { translate } from "react-i18nify" -import { useContext, useEffect, useCallback } from "react" -import { VisibleComponentsContext } from "./EnvironmentOverview" import { ComponentMode } from "@m2Types/generic/component-mode" import { AdditionalInformation } from "../GeneratorFp/AdditionalInformation/AdditionalInformation" import { ISize } from "@m2Types/generic/size" @@ -18,22 +16,6 @@ interface Props { const HumidityData = ({ dataId, componentMode, boxSize }: Props) => { const { humidity, customName } = useHumidity(dataId) - const { passVisibility } = useContext(VisibleComponentsContext) - - const handlePassVisibility = useCallback( - (id: number, isVisible: boolean) => { - passVisibility(id, "humidity", isVisible) - }, - [passVisibility] - ) - - useEffect(() => { - if (humidity !== undefined) { - handlePassVisibility(dataId, true) - } else { - handlePassVisibility(dataId, false) - } - }, [humidity, customName, dataId, handlePassVisibility]) if (humidity === undefined) { return null diff --git a/src/app/Marine2/components/boxes/EnvironmentOverview/PressureData.tsx b/src/app/Marine2/components/boxes/EnvironmentOverview/PressureData.tsx index 2ed74d5a..46f1caca 100644 --- a/src/app/Marine2/components/boxes/EnvironmentOverview/PressureData.tsx +++ b/src/app/Marine2/components/boxes/EnvironmentOverview/PressureData.tsx @@ -4,8 +4,6 @@ import ValueOverview from "../../ui/ValueOverview" import PressureIcon from "../../../images/icons/pressure.svg" import ValueBox from "../../ui/ValueBox" import { translate } from "react-i18nify" -import { useContext, useEffect, useCallback } from "react" -import { VisibleComponentsContext } from "./EnvironmentOverview" import { ComponentMode } from "@m2Types/generic/component-mode" import { ISize } from "@m2Types/generic/size" @@ -17,22 +15,6 @@ interface Props { const PressureData = ({ dataId, componentMode, boxSize }: Props) => { const { pressure, customName } = usePressure(dataId) - const { passVisibility } = useContext(VisibleComponentsContext) - - const handlePassVisibility = useCallback( - (id: number, isVisible: boolean) => { - passVisibility(id, "pressure", isVisible) - }, - [passVisibility] - ) - - useEffect(() => { - if (pressure !== undefined) { - handlePassVisibility(dataId, true) - } else { - handlePassVisibility(dataId, false) - } - }, [pressure, customName, dataId, handlePassVisibility]) if (pressure === undefined) { return null diff --git a/src/app/Marine2/components/boxes/EnvironmentOverview/TemperatureData.tsx b/src/app/Marine2/components/boxes/EnvironmentOverview/TemperatureData.tsx index d3832e7e..45ab497c 100644 --- a/src/app/Marine2/components/boxes/EnvironmentOverview/TemperatureData.tsx +++ b/src/app/Marine2/components/boxes/EnvironmentOverview/TemperatureData.tsx @@ -4,8 +4,6 @@ import ValueOverview from "../../ui/ValueOverview" import ThermometerIcon from "../../../images/icons/thermometer.svg" import ValueBox from "../../ui/ValueBox" import { translate } from "react-i18nify" -import { useCallback, useContext, useEffect } from "react" -import { VisibleComponentsContext } from "./EnvironmentOverview" import { ComponentMode } from "@m2Types/generic/component-mode" import { ISize } from "@m2Types/generic/size" import { temperatureValueFor } from "../../../utils/formatters/temperature/temperature-value-for" @@ -18,24 +16,8 @@ interface Props { const TemperatureData = ({ dataId, componentMode, boxSize }: Props) => { const { temperature, customName } = useTemperature(dataId) - const { passVisibility } = useContext(VisibleComponentsContext) const { temperatureUnitToHumanReadable, temperatureUnit } = useAppStore() - const handlePassVisibility = useCallback( - (id: number, isVisible: boolean) => { - passVisibility(id, "temperature", isVisible) - }, - [passVisibility] - ) - - useEffect(() => { - if (temperature !== undefined) { - handlePassVisibility(dataId, true) - } else { - handlePassVisibility(dataId, false) - } - }, [temperature, customName, dataId, handlePassVisibility]) - if (temperature === undefined) { return null }