@collabdt/core 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/components/AppSidebarContent.d.ts.map +1 -1
- package/dist/core/components/AppSidebarContent.js +2 -7
- package/dist/core/components/AppSidebarContent.js.map +1 -1
- package/dist/core/components/ui/LegendCard.d.ts +8 -3
- package/dist/core/components/ui/LegendCard.d.ts.map +1 -1
- package/dist/core/components/ui/LegendCard.js +36 -18
- package/dist/core/components/ui/LegendCard.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorDetailDialog.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorDetailDialog.js +56 -19
- package/dist/core/components/ui/Sensors/SensorDetailDialog.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorLegend.d.ts +6 -3
- package/dist/core/components/ui/Sensors/SensorLegend.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorLegend.js +95 -27
- package/dist/core/components/ui/Sensors/SensorLegend.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.d.ts +10 -4
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.js +60 -9
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorsSection.d.ts +1 -2
- package/dist/core/components/ui/Sensors/SensorsSection.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorsSection.js +34 -4
- package/dist/core/components/ui/Sensors/SensorsSection.js.map +1 -1
- package/dist/core/components/ui/Sensors/buildingSensorColours.d.ts +49 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.js +68 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.js.map +1 -0
- package/dist/core/components/ui/Sensors/sensorScope.js +1 -1
- package/dist/core/components/ui/Sensors/sensorScope.js.map +1 -1
- package/dist/core/components/ui/Sensors/sensorVisibility.d.ts +47 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.js +29 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.js.map +1 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.d.ts +30 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.js +92 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.js.map +1 -0
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.d.ts +1 -1
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js +17 -17
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.js +27 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.d.ts +36 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.js +95 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.js +55 -42
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.d.ts +32 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.js +56 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js +61 -39
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts +18 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js +61 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js +36 -19
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.d.ts +22 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.js +36 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.d.ts +5 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.js +6 -2
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.js.map +1 -1
- package/dist/core/i18n/messages/en.json +11 -1
- package/dist/core/i18n/messages/es.json +11 -1
- package/dist/core/i18n/messages/fr.json +11 -1
- package/dist/core/store/Menus/context.d.ts.map +1 -1
- package/dist/core/store/Menus/context.js +4 -2
- package/dist/core/store/Menus/context.js.map +1 -1
- package/dist/core/store/Menus/reducer.d.ts +15 -26
- package/dist/core/store/Menus/reducer.d.ts.map +1 -1
- package/dist/core/store/Menus/reducer.js +38 -4
- package/dist/core/store/Menus/reducer.js.map +1 -1
- package/dist/core/utils/appContent.d.ts +15 -0
- package/dist/core/utils/appContent.d.ts.map +1 -0
- package/dist/core/utils/appContent.js +24 -0
- package/dist/core/utils/appContent.js.map +1 -0
- package/dist/core/utils/colourUtils.d.ts +9 -0
- package/dist/core/utils/colourUtils.d.ts.map +1 -1
- package/dist/core/utils/colourUtils.js +16 -0
- package/dist/core/utils/colourUtils.js.map +1 -1
- package/package.json +1 -1
|
@@ -27,15 +27,15 @@ import { useSensorTypes } from "../../../../../../../hooks/sensorTypes/sensorTyp
|
|
|
27
27
|
import { useUsers } from "../../../../../../../hooks/users/users";
|
|
28
28
|
import { AppConfigContext, MenusContext } from "../../../../../../../store";
|
|
29
29
|
import { ViewerNames } from "../../../../../../../types/dbTypes";
|
|
30
|
-
import { UNTAGGED_TAG } from "../../../../../../ui/Sensors/SensorsSection";
|
|
31
30
|
import { readingsKey, valueColoursBySensor } from "../../../../../../ui/Sensors/sensorValueColours";
|
|
31
|
+
import { activeSensorTypeId, visibleSensors } from "../../../../../../ui/Sensors/sensorVisibility";
|
|
32
32
|
import { useSensorSeriesMulti } from "../../../../../../ui/Sensors/useSensorSeriesMulti";
|
|
33
33
|
import BimSensor from "./BimSensor";
|
|
34
34
|
import { renderCSS2DMarkers } from "./renderCSS2DMarkers";
|
|
35
35
|
function useSensorMarkers(world, buildingId) {
|
|
36
|
-
var _a
|
|
36
|
+
var _a;
|
|
37
37
|
const { state: menusState, dispatch: menusDispatch } = React.useContext(MenusContext);
|
|
38
|
-
const { currentSensorId, focusedSensorId, visibleSensorTypes, visibleSensorTags } = menusState.menus;
|
|
38
|
+
const { currentSensorId, focusedSensorId, visibleSensorTypes, visibleSensorTags, sensorLegendTypeId } = menusState.menus;
|
|
39
39
|
const { state: appConfigState } = React.useContext(AppConfigContext);
|
|
40
40
|
const timeZone = appConfigState.appConfig.displayTimeZone;
|
|
41
41
|
const sessionUser = (_a = useSession().data) == null ? void 0 : _a.user;
|
|
@@ -57,20 +57,22 @@ function useSensorMarkers(world, buildingId) {
|
|
|
57
57
|
if (buildingId !== -1 && sensor.buildingId !== buildingId) return false;
|
|
58
58
|
return true;
|
|
59
59
|
}).map((sensor) => {
|
|
60
|
-
var _a2,
|
|
60
|
+
var _a2, _b;
|
|
61
61
|
const user = users.find((u) => u.id === sensor.authorId);
|
|
62
62
|
const sensorType = sensorTypes.find((t) => t.id === sensor.typeId);
|
|
63
63
|
return __spreadProps(__spreadValues({}, sensor), {
|
|
64
64
|
authorName: (_a2 = user == null ? void 0 : user.name) != null ? _a2 : "Unknown User",
|
|
65
|
-
imageFileId: (
|
|
65
|
+
imageFileId: (_b = user == null ? void 0 : user.imageFileId) != null ? _b : "images/default-avatar.svg",
|
|
66
66
|
sensorType
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
const eligibleSensorsRef = React.useRef(eligibleSensors);
|
|
70
70
|
eligibleSensorsRef.current = eligibleSensors;
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const haloTypeId = activeSensorTypeId(eligibleSensors, {
|
|
72
|
+
legendTypeId: sensorLegendTypeId == null ? void 0 : sensorLegendTypeId[ViewerNames.bim],
|
|
73
|
+
activeSensorId: focusedSensorId
|
|
74
|
+
});
|
|
75
|
+
const haloSensors = haloTypeId == null ? [] : eligibleSensors.filter((s) => s.typeId === haloTypeId);
|
|
74
76
|
const { seriesById } = useSensorSeriesMulti(haloSensors, { enabled: haloSensors.length > 0 });
|
|
75
77
|
const haloIdsKey = haloSensors.map((s) => s.id).join(",");
|
|
76
78
|
const readings = React.useMemo(
|
|
@@ -104,15 +106,13 @@ function useSensorMarkers(world, buildingId) {
|
|
|
104
106
|
React.useEffect(() => {
|
|
105
107
|
const typesVisible = (visibleSensorTypes == null ? void 0 : visibleSensorTypes[ViewerNames.bim]) || [];
|
|
106
108
|
const tagsVisible = (visibleSensorTags == null ? void 0 : visibleSensorTags[ViewerNames.bim]) || [];
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const matchesTag = hasNoTags ? tagsVisible.includes(UNTAGGED_TAG) : (_c = (_b2 = sensor.tags) == null ? void 0 : _b2.some((tag) => tagsVisible.includes(tag))) != null ? _c : false;
|
|
112
|
-
return matchesType || matchesTag;
|
|
109
|
+
const markerSensors = visibleSensors(eligibleSensorsRef.current, {
|
|
110
|
+
viewer: ViewerNames.bim,
|
|
111
|
+
visibleTypeIds: typesVisible,
|
|
112
|
+
visibleTags: tagsVisible
|
|
113
113
|
});
|
|
114
114
|
const allSensors = [
|
|
115
|
-
...
|
|
115
|
+
...markerSensors.map((s) => __spreadProps(__spreadValues({}, s), { isPending: false })),
|
|
116
116
|
...pendingSensors.map((p) => ({
|
|
117
117
|
id: p.id,
|
|
118
118
|
name: "Creating...",
|
|
@@ -138,7 +138,7 @@ function useSensorMarkers(world, buildingId) {
|
|
|
138
138
|
component: BimSensor,
|
|
139
139
|
hooksContextValue: coreHooks,
|
|
140
140
|
propsMapper: (sensor) => {
|
|
141
|
-
var _a2,
|
|
141
|
+
var _a2, _b;
|
|
142
142
|
return {
|
|
143
143
|
sensorName: sensor.name,
|
|
144
144
|
sensorType: sensorTypes.find((t) => t.id === sensor.typeId),
|
|
@@ -150,7 +150,7 @@ function useSensorMarkers(world, buildingId) {
|
|
|
150
150
|
timestamp: new Date(sensor.createdAt),
|
|
151
151
|
highlight: currentSensorId === sensor.id,
|
|
152
152
|
focused: focusedSensorId === sensor.id,
|
|
153
|
-
haloColour: (
|
|
153
|
+
haloColour: (_b = readingsRef.current.get(sensor.id)) == null ? void 0 : _b.colour,
|
|
154
154
|
timeZone,
|
|
155
155
|
showActions: true,
|
|
156
156
|
onSelect: () => focusSensor(sensor.id),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.ts"],"sourcesContent":["\"use client\"\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { useSession } from \"next-auth/react\"\r\nimport { useTranslations } from \"next-intl\"\r\nimport * as React from \"react\"\r\n\r\nimport { useCoreHooks } from \"../../../../../../../hooks/provider\"\r\nimport { useSensors, useSensor } from \"../../../../../../../hooks/sensors/sensors\"\r\nimport { useSensorTypes } from \"../../../../../../../hooks/sensorTypes/sensorTypes\"\r\nimport { useUsers } from \"../../../../../../../hooks/users/users\"\r\nimport { AppConfigContext, MenusContext } from \"../../../../../../../store\"\r\nimport { ViewerNames, type Sensor } from \"../../../../../../../types/dbTypes\"\r\nimport { UNTAGGED_TAG } from \"../../../../../../ui/Sensors/SensorsSection\"\r\nimport { readingsKey, valueColoursBySensor } from \"../../../../../../ui/Sensors/sensorValueColours\"\r\nimport { useSensorSeriesMulti } from \"../../../../../../ui/Sensors/useSensorSeriesMulti\"\r\n\r\nimport BimSensor from \"./BimSensor\"\r\nimport { renderCSS2DMarkers, type MarkerRef } from \"./renderCSS2DMarkers\"\r\n\r\nexport function useSensorMarkers(world: any, buildingId: number) {\r\n const { state: menusState, dispatch: menusDispatch } = React.useContext(MenusContext)\r\n const { currentSensorId, focusedSensorId, visibleSensorTypes, visibleSensorTags } = menusState.menus\r\n const { state: appConfigState } = React.useContext(AppConfigContext)\r\n const timeZone = appConfigState.appConfig.displayTimeZone\r\n const sessionUser = useSession().data?.user\r\n const tr = useTranslations('SensorsSection')\r\n const actionLabels = { expand: tr('expandSensor'), edit: tr('editSensor'), delete: tr('deleteSensor') }\r\n const [detailSensor, setDetailSensor] = React.useState<Sensor | null>(null)\r\n const [editSensor, setEditSensor] = React.useState<Sensor | null>(null)\r\n\r\n const registry = React.useRef<Map<string, MarkerRef>>(new Map())\r\n\r\n const { sensors } = useSensors()\r\n const { users } = useUsers()\r\n const { sensorTypes } = useSensorTypes()\r\n const coreHooks = useCoreHooks()\r\n\r\n const [sensorToDelete, setSensorToDelete] = React.useState<number | null>(null)\r\n const { deleteSensor } = useSensor(sensorToDelete)\r\n\r\n const eligibleSensors = sensors\r\n .filter((sensor) => {\r\n const { x, y, z, viewer } = sensor\r\n if (x == null || y == null || z == null) return false\r\n if (viewer !== ViewerNames.bim) return false\r\n if (buildingId !== -1 && sensor.buildingId !== buildingId) return false\r\n return true\r\n })\r\n .map((sensor) => {\r\n const user = users.find(u => u.id === sensor.authorId)\r\n const sensorType = sensorTypes.find(t => t.id === sensor.typeId)\r\n return {\r\n ...sensor,\r\n authorName: user?.name ?? \"Unknown User\",\r\n imageFileId: user?.imageFileId ?? \"images/default-avatar.svg\",\r\n sensorType,\r\n }\r\n })\r\n\r\n // Stable ref so the render effect reads current sensors without re-running on every change\r\n const eligibleSensorsRef = React.useRef(eligibleSensors)\r\n eligibleSensorsRef.current = eligibleSensors\r\n\r\n // Every sensor sharing the focused sensor's type gets a halo coloured by its own current\r\n // value, so the whole set can be read against the legend at a glance. Only that type is\r\n // polled: haloing all types would fan out a request per sensor in the building.\r\n const focusedSensor = focusedSensorId == null\r\n ? undefined\r\n : eligibleSensors.find(s => s.id === focusedSensorId)\r\n const focusedTypeId = focusedSensor?.typeId ?? null\r\n\r\n const haloSensors = focusedTypeId == null\r\n ? []\r\n : eligibleSensors.filter(s => s.typeId === focusedTypeId)\r\n // A fresh array each render is fine: the hook keys on the sensors' id+url string.\r\n const { seriesById } = useSensorSeriesMulti(haloSensors, { enabled: haloSensors.length > 0 })\r\n\r\n const haloIdsKey = haloSensors.map(s => s.id).join(',')\r\n const readings = React.useMemo(\r\n () => valueColoursBySensor(haloSensors, sensorTypes, seriesById),\r\n [seriesById, sensorTypes, haloIdsKey],\r\n )\r\n\r\n // Colour strings, not map identity, decide whether markers need re-rendering: a poll that\r\n // returns the same reading must not re-render every marker.\r\n const haloKey = readingsKey(readings)\r\n const readingsRef = React.useRef(readings)\r\n readingsRef.current = readings\r\n\r\n const focusSensor = React.useCallback((sensorId: number) => {\r\n menusDispatch({ type: 'SET_FOCUSED_SENSOR_ID', payload: { sensorId } })\r\n }, [menusDispatch])\r\n\r\n React.useEffect(() => {\r\n if (sensorToDelete !== null) {\r\n void deleteSensor()\r\n setSensorToDelete(null)\r\n }\r\n }, [sensorToDelete, deleteSensor])\r\n\r\n const handleRemoveSensor = React.useCallback((sensorId: number) => {\r\n setSensorToDelete(sensorId)\r\n }, [])\r\n\r\n // Pending markers for loading indicators while sensor is being created\r\n const [pendingSensors, setPendingSensors] = React.useState<Array<{ id: number; x: number; y: number; z: number }>>([])\r\n\r\n const addPendingSensor = React.useCallback((position: { x: number; y: number; z: number }) => {\r\n const id = -Date.now()\r\n setPendingSensors(prev => [...prev, { id, ...position }])\r\n return id\r\n }, [])\r\n\r\n const removePendingSensor = React.useCallback((id: number) => {\r\n setPendingSensors(prev => prev.filter(p => p.id !== id))\r\n }, [])\r\n\r\n // Render sensor markers with visibility filtering\r\n React.useEffect(() => {\r\n const typesVisible = visibleSensorTypes?.[ViewerNames.bim] || []\r\n const tagsVisible = visibleSensorTags?.[ViewerNames.bim] || []\r\n\r\n const visibleSensors = eligibleSensorsRef.current.filter(sensor => {\r\n const matchesType = typesVisible.includes(sensor.typeId)\r\n const hasNoTags = !sensor.tags?.length\r\n const matchesTag = hasNoTags\r\n ? tagsVisible.includes(UNTAGGED_TAG)\r\n : sensor.tags?.some((tag: string) => tagsVisible.includes(tag)) ?? false\r\n return matchesType || matchesTag\r\n })\r\n\r\n const allSensors = [\r\n ...visibleSensors.map(s => ({ ...s, isPending: false })),\r\n ...pendingSensors.map(p => ({\r\n id: p.id,\r\n name: \"Creating...\",\r\n sensorType: undefined,\r\n typeId: undefined,\r\n x: p.x,\r\n y: p.y,\r\n z: p.z,\r\n url: \"\",\r\n dataFormat: \"Json\",\r\n updateFrequency: 0,\r\n createdAt: new Date().toISOString(),\r\n buildingId,\r\n tags: [],\r\n authorId: -1,\r\n isPending: true,\r\n })),\r\n ]\r\n\r\n renderCSS2DMarkers(world, {\r\n items: allSensors,\r\n markerIdKey: \"sensorId\",\r\n registry,\r\n component: BimSensor,\r\n hooksContextValue: coreHooks,\r\n propsMapper: (sensor) => ({\r\n sensorName: sensor.name,\r\n sensorType: sensorTypes.find(t => t.id === sensor.typeId),\r\n tags: sensor.tags,\r\n dataUrl: sensor.url ?? \"\",\r\n dataFormat: sensor.dataFormat,\r\n updateFrequency: sensor.updateFrequency,\r\n buildingId: sensor.buildingId,\r\n timestamp: new Date(sensor.createdAt),\r\n highlight: currentSensorId === sensor.id,\r\n focused: focusedSensorId === sensor.id,\r\n haloColour: readingsRef.current.get(sensor.id)?.colour,\r\n timeZone,\r\n showActions: true,\r\n onSelect: () => focusSensor(sensor.id),\r\n onExpand: () => setDetailSensor(sensor as unknown as Sensor),\r\n onEdit: () => setEditSensor(sensor as unknown as Sensor),\r\n actionLabels,\r\n canEdit: sessionUser?.id === String(sensor.authorId),\r\n canDelete: sessionUser?.id === String(sensor.authorId),\r\n }),\r\n sphereColor: \"#10b981\",\r\n isVisible: true,\r\n onRemove: handleRemoveSensor,\r\n })\r\n }, [world, sensors, pendingSensors, handleRemoveSensor, visibleSensorTypes, visibleSensorTags, buildingId, currentSensorId, focusedSensorId, haloKey, focusSensor, sensorTypes, coreHooks, timeZone, sessionUser?.id])\r\n\r\n const sensorCount = sensors.filter(\r\n s => s.viewer === ViewerNames.bim && (!buildingId || buildingId === -1 || s.buildingId === buildingId)\r\n ).length\r\n\r\n const detailSensorType = detailSensor ? sensorTypes.find(t => t.id === detailSensor.typeId) : undefined\r\n\r\n return {\r\n addPendingSensor,\r\n removePendingSensor,\r\n sensorCount,\r\n detailSensor,\r\n detailSensorType,\r\n closeSensorDetail: () => setDetailSensor(null),\r\n editSensor,\r\n closeSensorEdit: () => setEditSensor(null),\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAKA,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAEvB,SAAS,oBAAoB;AAC7B,SAAS,YAAY,iBAAiB;AACtC,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAC/C,SAAS,mBAAgC;AACzC,SAAS,oBAAoB;AAC7B,SAAS,aAAa,4BAA4B;AAClD,SAAS,4BAA4B;AAErC,OAAO,eAAe;AACtB,SAAS,0BAA0C;AAE5C,SAAS,iBAAiB,OAAY,YAAoB;AAtBjE;AAuBE,QAAM,EAAE,OAAO,YAAY,UAAU,cAAc,IAAI,MAAM,WAAW,YAAY;AACpF,QAAM,EAAE,iBAAiB,iBAAiB,oBAAoB,kBAAkB,IAAI,WAAW;AAC/F,QAAM,EAAE,OAAO,eAAe,IAAI,MAAM,WAAW,gBAAgB;AACnE,QAAM,WAAW,eAAe,UAAU;AAC1C,QAAM,eAAc,gBAAW,EAAE,SAAb,mBAAmB;AACvC,QAAM,KAAK,gBAAgB,gBAAgB;AAC3C,QAAM,eAAe,EAAE,QAAQ,GAAG,cAAc,GAAG,MAAM,GAA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ers.ts"],"sourcesContent":["\"use client\"\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { useSession } from \"next-auth/react\"\r\nimport { useTranslations } from \"next-intl\"\r\nimport * as React from \"react\"\r\n\r\nimport { useCoreHooks } from \"../../../../../../../hooks/provider\"\r\nimport { useSensors, useSensor } from \"../../../../../../../hooks/sensors/sensors\"\r\nimport { useSensorTypes } from \"../../../../../../../hooks/sensorTypes/sensorTypes\"\r\nimport { useUsers } from \"../../../../../../../hooks/users/users\"\r\nimport { AppConfigContext, MenusContext } from \"../../../../../../../store\"\r\nimport { ViewerNames, type Sensor } from \"../../../../../../../types/dbTypes\"\r\nimport { readingsKey, valueColoursBySensor } from \"../../../../../../ui/Sensors/sensorValueColours\"\r\nimport { activeSensorTypeId, visibleSensors } from \"../../../../../../ui/Sensors/sensorVisibility\"\r\nimport { useSensorSeriesMulti } from \"../../../../../../ui/Sensors/useSensorSeriesMulti\"\r\n\r\nimport BimSensor from \"./BimSensor\"\r\nimport { renderCSS2DMarkers, type MarkerRef } from \"./renderCSS2DMarkers\"\r\n\r\nexport function useSensorMarkers(world: any, buildingId: number) {\r\n const { state: menusState, dispatch: menusDispatch } = React.useContext(MenusContext)\r\n const { currentSensorId, focusedSensorId, visibleSensorTypes, visibleSensorTags, sensorLegendTypeId } = menusState.menus\r\n const { state: appConfigState } = React.useContext(AppConfigContext)\r\n const timeZone = appConfigState.appConfig.displayTimeZone\r\n const sessionUser = useSession().data?.user\r\n const tr = useTranslations('SensorsSection')\r\n const actionLabels = { expand: tr('expandSensor'), edit: tr('editSensor'), delete: tr('deleteSensor') }\r\n const [detailSensor, setDetailSensor] = React.useState<Sensor | null>(null)\r\n const [editSensor, setEditSensor] = React.useState<Sensor | null>(null)\r\n\r\n const registry = React.useRef<Map<string, MarkerRef>>(new Map())\r\n\r\n const { sensors } = useSensors()\r\n const { users } = useUsers()\r\n const { sensorTypes } = useSensorTypes()\r\n const coreHooks = useCoreHooks()\r\n\r\n const [sensorToDelete, setSensorToDelete] = React.useState<number | null>(null)\r\n const { deleteSensor } = useSensor(sensorToDelete)\r\n\r\n const eligibleSensors = sensors\r\n .filter((sensor) => {\r\n const { x, y, z, viewer } = sensor\r\n if (x == null || y == null || z == null) return false\r\n if (viewer !== ViewerNames.bim) return false\r\n if (buildingId !== -1 && sensor.buildingId !== buildingId) return false\r\n return true\r\n })\r\n .map((sensor) => {\r\n const user = users.find(u => u.id === sensor.authorId)\r\n const sensorType = sensorTypes.find(t => t.id === sensor.typeId)\r\n return {\r\n ...sensor,\r\n authorName: user?.name ?? \"Unknown User\",\r\n imageFileId: user?.imageFileId ?? \"images/default-avatar.svg\",\r\n sensorType,\r\n }\r\n })\r\n\r\n // Stable ref so the render effect reads current sensors without re-running on every change\r\n const eligibleSensorsRef = React.useRef(eligibleSensors)\r\n eligibleSensorsRef.current = eligibleSensors\r\n\r\n // Every sensor sharing the active type gets a halo coloured by its own current value, so the\r\n // whole set can be read against the legend at a glance. Only that type is polled: haloing all\r\n // types would fan out a request per sensor in the building. The type comes from the same\r\n // helper the legend uses, so a type pinned in the legend dropdown moves the halos with it.\r\n const haloTypeId = activeSensorTypeId(eligibleSensors, {\r\n legendTypeId: sensorLegendTypeId?.[ViewerNames.bim],\r\n activeSensorId: focusedSensorId,\r\n })\r\n\r\n const haloSensors = haloTypeId == null\r\n ? []\r\n : eligibleSensors.filter(s => s.typeId === haloTypeId)\r\n // A fresh array each render is fine: the hook keys on the sensors' id+url string.\r\n const { seriesById } = useSensorSeriesMulti(haloSensors, { enabled: haloSensors.length > 0 })\r\n\r\n const haloIdsKey = haloSensors.map(s => s.id).join(',')\r\n const readings = React.useMemo(\r\n () => valueColoursBySensor(haloSensors, sensorTypes, seriesById),\r\n [seriesById, sensorTypes, haloIdsKey],\r\n )\r\n\r\n // Colour strings, not map identity, decide whether markers need re-rendering: a poll that\r\n // returns the same reading must not re-render every marker.\r\n const haloKey = readingsKey(readings)\r\n const readingsRef = React.useRef(readings)\r\n readingsRef.current = readings\r\n\r\n const focusSensor = React.useCallback((sensorId: number) => {\r\n menusDispatch({ type: 'SET_FOCUSED_SENSOR_ID', payload: { sensorId } })\r\n }, [menusDispatch])\r\n\r\n React.useEffect(() => {\r\n if (sensorToDelete !== null) {\r\n void deleteSensor()\r\n setSensorToDelete(null)\r\n }\r\n }, [sensorToDelete, deleteSensor])\r\n\r\n const handleRemoveSensor = React.useCallback((sensorId: number) => {\r\n setSensorToDelete(sensorId)\r\n }, [])\r\n\r\n // Pending markers for loading indicators while sensor is being created\r\n const [pendingSensors, setPendingSensors] = React.useState<Array<{ id: number; x: number; y: number; z: number }>>([])\r\n\r\n const addPendingSensor = React.useCallback((position: { x: number; y: number; z: number }) => {\r\n const id = -Date.now()\r\n setPendingSensors(prev => [...prev, { id, ...position }])\r\n return id\r\n }, [])\r\n\r\n const removePendingSensor = React.useCallback((id: number) => {\r\n setPendingSensors(prev => prev.filter(p => p.id !== id))\r\n }, [])\r\n\r\n // Render sensor markers with visibility filtering\r\n React.useEffect(() => {\r\n const typesVisible = visibleSensorTypes?.[ViewerNames.bim] || []\r\n const tagsVisible = visibleSensorTags?.[ViewerNames.bim] || []\r\n\r\n const markerSensors = visibleSensors(eligibleSensorsRef.current, {\r\n viewer: ViewerNames.bim,\r\n visibleTypeIds: typesVisible,\r\n visibleTags: tagsVisible,\r\n })\r\n\r\n const allSensors = [\r\n ...markerSensors.map(s => ({ ...s, isPending: false })),\r\n ...pendingSensors.map(p => ({\r\n id: p.id,\r\n name: \"Creating...\",\r\n sensorType: undefined,\r\n typeId: undefined,\r\n x: p.x,\r\n y: p.y,\r\n z: p.z,\r\n url: \"\",\r\n dataFormat: \"Json\",\r\n updateFrequency: 0,\r\n createdAt: new Date().toISOString(),\r\n buildingId,\r\n tags: [],\r\n authorId: -1,\r\n isPending: true,\r\n })),\r\n ]\r\n\r\n renderCSS2DMarkers(world, {\r\n items: allSensors,\r\n markerIdKey: \"sensorId\",\r\n registry,\r\n component: BimSensor,\r\n hooksContextValue: coreHooks,\r\n propsMapper: (sensor) => ({\r\n sensorName: sensor.name,\r\n sensorType: sensorTypes.find(t => t.id === sensor.typeId),\r\n tags: sensor.tags,\r\n dataUrl: sensor.url ?? \"\",\r\n dataFormat: sensor.dataFormat,\r\n updateFrequency: sensor.updateFrequency,\r\n buildingId: sensor.buildingId,\r\n timestamp: new Date(sensor.createdAt),\r\n highlight: currentSensorId === sensor.id,\r\n focused: focusedSensorId === sensor.id,\r\n haloColour: readingsRef.current.get(sensor.id)?.colour,\r\n timeZone,\r\n showActions: true,\r\n onSelect: () => focusSensor(sensor.id),\r\n onExpand: () => setDetailSensor(sensor as unknown as Sensor),\r\n onEdit: () => setEditSensor(sensor as unknown as Sensor),\r\n actionLabels,\r\n canEdit: sessionUser?.id === String(sensor.authorId),\r\n canDelete: sessionUser?.id === String(sensor.authorId),\r\n }),\r\n sphereColor: \"#10b981\",\r\n isVisible: true,\r\n onRemove: handleRemoveSensor,\r\n })\r\n }, [world, sensors, pendingSensors, handleRemoveSensor, visibleSensorTypes, visibleSensorTags, buildingId, currentSensorId, focusedSensorId, haloKey, focusSensor, sensorTypes, coreHooks, timeZone, sessionUser?.id])\r\n\r\n const sensorCount = sensors.filter(\r\n s => s.viewer === ViewerNames.bim && (!buildingId || buildingId === -1 || s.buildingId === buildingId)\r\n ).length\r\n\r\n const detailSensorType = detailSensor ? sensorTypes.find(t => t.id === detailSensor.typeId) : undefined\r\n\r\n return {\r\n addPendingSensor,\r\n removePendingSensor,\r\n sensorCount,\r\n detailSensor,\r\n detailSensorType,\r\n closeSensorDetail: () => setDetailSensor(null),\r\n editSensor,\r\n closeSensorEdit: () => setEditSensor(null),\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAKA,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAEvB,SAAS,oBAAoB;AAC7B,SAAS,YAAY,iBAAiB;AACtC,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F,QAAM,mBAAmB,eAAe,YAAY,KAAK,OAAK,EAAE,OAAO,aAAa,MAAM,IAAI;AAE9F,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,MAAM,gBAAgB,IAAI;AAAA,IAC7C;AAAA,IACA,iBAAiB,MAAM,cAAc,IAAI;AAAA,EAC3C;AACF;","names":["_a"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAY/B,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEnD,KAAK,4BAA4B,GAAG;IAChC,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAE,EAC7C,OAAO,EACP,MAAM,EACN,aAAa,GACZ,EAAE,4BAA4B,qBA+MlC"}
|
|
@@ -7,12 +7,16 @@ import { Button, Separator, Skeleton, Badge } from "../../../../../../../compone
|
|
|
7
7
|
import { PopoverContent } from "../../../../../../../components/ui/Popover";
|
|
8
8
|
import { useBuilding } from "../../../../../../../hooks/buildings/buildings";
|
|
9
9
|
import { MapContext } from "../../../../../../../store";
|
|
10
|
+
import { ViewerNames } from "../../../../../../../types/dbTypes";
|
|
11
|
+
import { useBuildingSensorColours } from "../../../../../../ui/Sensors/useBuildingSensorColours";
|
|
12
|
+
import { BuildingSensorList, BuildingSensorSummary } from "./src/BuildingSensorDetails";
|
|
10
13
|
import BuildingTools from "./src/BuildingsTools";
|
|
11
14
|
function DatabaseBuildingPopover({
|
|
12
15
|
feature,
|
|
13
16
|
isOpen,
|
|
14
17
|
onCloseAction
|
|
15
18
|
}) {
|
|
19
|
+
var _a;
|
|
16
20
|
const t = useTranslations("DatabaseBuildingPopover");
|
|
17
21
|
const { state: mapState } = React.useContext(MapContext);
|
|
18
22
|
const featureProps = React.useMemo(
|
|
@@ -64,6 +68,9 @@ function DatabaseBuildingPopover({
|
|
|
64
68
|
]
|
|
65
69
|
);
|
|
66
70
|
const [expanded, setExpanded] = React.useState(false);
|
|
71
|
+
const sensorColours = useBuildingSensorColours(ViewerNames.map);
|
|
72
|
+
const sensorsOfType = buildingId == null ? [] : (_a = sensorColours.sensorsByBuilding.get(buildingId)) != null ? _a : [];
|
|
73
|
+
const showSensors = Boolean(sensorColours.sensorType) && sensorsOfType.length > 0;
|
|
67
74
|
const shortSubdivision = React.useMemo(() => {
|
|
68
75
|
const code = locationData.countrySubdivision;
|
|
69
76
|
if (!code) return null;
|
|
@@ -99,6 +106,17 @@ function DatabaseBuildingPopover({
|
|
|
99
106
|
}
|
|
100
107
|
)
|
|
101
108
|
] }),
|
|
109
|
+
!isError && !isLoading && showSensors && sensorColours.sensorType && /* @__PURE__ */ jsx(
|
|
110
|
+
BuildingSensorSummary,
|
|
111
|
+
{
|
|
112
|
+
sensorType: sensorColours.sensorType,
|
|
113
|
+
sensors: sensorsOfType,
|
|
114
|
+
readings: sensorColours.readings,
|
|
115
|
+
average: buildingId == null ? void 0 : sensorColours.averages.get(buildingId),
|
|
116
|
+
latestAt: buildingId == null ? void 0 : sensorColours.latestAtByBuilding.get(buildingId),
|
|
117
|
+
unit: sensorColours.unit
|
|
118
|
+
}
|
|
119
|
+
),
|
|
102
120
|
!isError && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
103
121
|
isLoading ? /* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-24 mt-1" }) : /* @__PURE__ */ jsxs(
|
|
104
122
|
Button,
|
|
@@ -113,7 +131,15 @@ function DatabaseBuildingPopover({
|
|
|
113
131
|
]
|
|
114
132
|
}
|
|
115
133
|
),
|
|
116
|
-
expanded && !isLoading && /* @__PURE__ */
|
|
134
|
+
expanded && !isLoading && showSensors && /* @__PURE__ */ jsx(
|
|
135
|
+
BuildingSensorList,
|
|
136
|
+
{
|
|
137
|
+
sensors: sensorsOfType,
|
|
138
|
+
readings: sensorColours.readings,
|
|
139
|
+
unit: sensorColours.unit
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
expanded && !isLoading && !showSensors && /* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-col gap-2", children: [
|
|
117
143
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
118
144
|
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground font-medium", children: t("address") }),
|
|
119
145
|
locationData.site && /* @__PURE__ */ jsx("p", { className: "text-sm", children: locationData.site.replace("_", " ") }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.tsx"],"sourcesContent":["\"use client\";\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as LR from \"lucide-react\";\r\nimport {useTranslations} from \"next-intl\";\r\nimport * as React from \"react\";\r\n\r\nimport {Button, Separator, Skeleton, Badge} from \"../../../../../../../components/ui/\";\r\nimport {PopoverContent} from \"../../../../../../../components/ui/Popover\";\r\nimport {useBuilding} from \"../../../../../../../hooks/buildings/buildings\";\r\nimport {MapContext} from \"../../../../../../../store\";\r\n\r\nimport BuildingTools from \"./src/BuildingsTools\";\r\n\r\nimport type {MapGeoJSONFeature} from \"maplibre-gl\";\r\n\r\ntype DatabaseBuildingPopoverProps = {\r\n \"feature\": MapGeoJSONFeature;\r\n \"isOpen\": boolean;\r\n \"onCloseAction\": () => void;\r\n};\r\n\r\nexport default function DatabaseBuildingPopover ({\r\n feature,\r\n isOpen,\r\n onCloseAction,\r\n }: DatabaseBuildingPopoverProps) {\r\n\r\n const t = useTranslations('DatabaseBuildingPopover')\r\n\r\n\r\n const {state: mapState} = React.useContext(MapContext);\r\n\r\n const featureProps = React.useMemo(\r\n () => feature?.properties || {},\r\n [feature?.properties],\r\n );\r\n const buildingId = React.useMemo(\r\n () => {\r\n\r\n const id = Number(featureProps.dbId);\r\n return isNaN(id)\r\n ? null\r\n : id;\r\n\r\n },\r\n [featureProps.dbId],\r\n );\r\n\r\n const locationData = React.useMemo(\r\n () => ({\r\n \"countrySubdivision\": featureProps.de_ao_prov || mapState.map.currentLocation.countrySubdivision || null,\r\n \"municipality\": featureProps.de_ao_city || mapState.map.currentLocation.municipality || null,\r\n \"address\": featureProps.de_ao_stre || mapState.map.currentLocation.address || null,\r\n \"postalCode\": featureProps.de_ao_post || mapState.map.currentLocation.postalCode || null,\r\n \"site\": mapState.map.currentLocation.site || null,\r\n }),\r\n [\r\n featureProps.de_ao_prov,\r\n featureProps.de_ao_city,\r\n featureProps.de_ao_stre,\r\n featureProps.de_ao_post,\r\n mapState.map.currentLocation.countrySubdivision,\r\n mapState.map.currentLocation.municipality,\r\n mapState.map.currentLocation.address,\r\n mapState.map.currentLocation.postalCode,\r\n mapState.map.currentLocation.site,\r\n ]);\r\n\r\n const shouldFetchData = Boolean(buildingId && isOpen);\r\n const {building, isLoading, isError} = useBuilding(shouldFetchData\r\n ? buildingId\r\n : null);\r\n\r\n const displayData = React.useMemo(\r\n () => ({\r\n \"name\": building?.buildingName || t('namePlaceholder'),\r\n \"displayAddress\": building?.buildingAddress || locationData.address,\r\n \"buildingType\": building?.buildingType,\r\n \"NumberOfStoreys\": building?.buildingStoreyNum,\r\n }),\r\n [\r\n building?.buildingName,\r\n building?.buildingAddress,\r\n building?.buildingType,\r\n building?.buildingStoreyNum,\r\n locationData.address,\r\n]\r\n );\r\n\r\n const [expanded, setExpanded] = React.useState(false);\r\n\r\n // Show only the short subdivision code (e.g. \"ON\" from \"CA-ON\")\r\n const shortSubdivision = React.useMemo(() => {\r\n const code = locationData.countrySubdivision;\r\n if (!code) return null;\r\n const dash = code.lastIndexOf('-');\r\n return dash >= 0 ? code.slice(dash + 1) : code;\r\n }, [locationData.countrySubdivision]);\r\n\r\n // After every hook, so the hook order holds for features without a building.\r\n if (!buildingId) {\r\n\r\n return null;\r\n\r\n }\r\n\r\n return (\r\n <PopoverContent\r\n className=\"w-64 -m-1\"\r\n side=\"top\"\r\n >\r\n {/* Header row: title + close button, no overlap */}\r\n <div className=\"flex items-center justify-between gap-2 mb-1\">\r\n <div className=\"flex-1 min-w-0\">\r\n {isLoading\r\n ? <Skeleton className=\"h-4 w-32\" />\r\n : isError\r\n ? (\r\n <div className=\"flex items-center gap-2 text-destructive\">\r\n <LR.AlertCircle className=\"w-4 h-4 shrink-0\" />\r\n <h4 className=\"font-medium leading-none truncate\">{t('loadingError')}</h4>\r\n </div>\r\n )\r\n : <h4 className=\"font-medium leading-snug\">{displayData.name}</h4>\r\n }\r\n {isError && <p className=\"text-xs text-muted-foreground mt-1\">{String(isError)}</p>}\r\n </div>\r\n <Button\r\n aria-label=\"Close\"\r\n className=\"shrink-0 p-0 m-0 text-muted-foreground hover:text-foreground\"\r\n onClick={onCloseAction}\r\n variant=\"ghost\"\r\n size=\"icon\"\r\n >\r\n <LR.X className=\"w-4 h-4\" />\r\n </Button>\r\n </div>\r\n {/* Expand/collapse details */}\r\n {!isError && (\r\n <>\r\n {isLoading\r\n ? <Skeleton className=\"h-5 w-24 mt-1\" />\r\n : (\r\n <Button\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n className=\"w-full h-7 text-xs text-muted-foreground justify-start gap-1 px-0 hover:text-foreground hover:bg-transparent\"\r\n onClick={() => setExpanded(v => !v)}\r\n >\r\n {expanded ? <LR.ChevronUp className=\"w-3 h-3\" /> : <LR.ChevronDown className=\"w-3 h-3\" />}\r\n {expanded ? t('hideDetails') : t('showDetails')}\r\n </Button>\r\n )}\r\n\r\n {expanded && !isLoading && (\r\n <div className=\"mt-2 flex flex-col gap-2\">\r\n {/* Address */}\r\n <div>\r\n <p className=\"text-xs text-muted-foreground font-medium\">{t('address')}</p>\r\n {locationData.site && (\r\n <p className=\"text-sm\">{locationData.site.replace(\"_\", \" \")}</p>\r\n )}\r\n {displayData.displayAddress && (\r\n <p className=\"text-sm\">{displayData.displayAddress}</p>\r\n )}\r\n {(locationData.municipality || shortSubdivision || locationData.postalCode) && (\r\n <p className=\"text-sm\">\r\n {[locationData.municipality, shortSubdivision, locationData.postalCode]\r\n .filter(Boolean)\r\n .join(\", \")}\r\n </p>\r\n )}\r\n </div>\r\n {/* Building Type */}\r\n {displayData.buildingType && (\r\n <div>\r\n <p className=\"text-xs text-muted-foreground font-medium\">{t('buildingType')}</p>\r\n <Badge variant=\"secondary\">{displayData.buildingType}</Badge>\r\n </div>\r\n )}\r\n {/* Number of Storeys */}\r\n {displayData.NumberOfStoreys && (\r\n <div>\r\n <p className=\"text-xs text-muted-foreground font-medium\">{t('StoreysNum')}</p>\r\n <p className=\"text-sm\">{displayData.NumberOfStoreys}</p>\r\n </div>\r\n )}\r\n </div>\r\n )}\r\n </>\r\n )}\r\n\r\n <Separator className=\"my-3\" />\r\n <BuildingTools\r\n building={building}\r\n feature={feature}\r\n isError={isError}\r\n isLoading={isLoading}\r\n onCloseAction={onCloseAction}\r\n />\r\n </PopoverContent>\r\n );\r\n\r\n}\r\n"],"mappings":";AAsH0B,SAwBV,UAxBU,KAGM,YAHN;AAjH1B,YAAY,QAAQ;AACpB,SAAQ,uBAAsB;AAC9B,YAAY,WAAW;AAEvB,SAAQ,QAAQ,WAAW,UAAU,aAAY;AACjD,SAAQ,sBAAqB;AAC7B,SAAQ,mBAAkB;AAC1B,SAAQ,kBAAiB;AAEzB,OAAO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AA,YACA;AAAA,YACA;AAAA,YACA;AAAA;AAAA,QACJ;AAAA;AAAA;AAAA,EACJ;AAGR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.tsx"],"sourcesContent":["\"use client\";\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as LR from \"lucide-react\";\r\nimport {useTranslations} from \"next-intl\";\r\nimport * as React from \"react\";\r\n\r\nimport {Button, Separator, Skeleton, Badge} from \"../../../../../../../components/ui/\";\r\nimport {PopoverContent} from \"../../../../../../../components/ui/Popover\";\r\nimport {useBuilding} from \"../../../../../../../hooks/buildings/buildings\";\r\nimport {MapContext} from \"../../../../../../../store\";\r\nimport {ViewerNames} from \"../../../../../../../types/dbTypes\";\r\nimport {useBuildingSensorColours} from \"../../../../../../ui/Sensors/useBuildingSensorColours\";\r\n\r\nimport {BuildingSensorList, BuildingSensorSummary} from \"./src/BuildingSensorDetails\";\r\nimport BuildingTools from \"./src/BuildingsTools\";\r\n\r\nimport type {MapGeoJSONFeature} from \"maplibre-gl\";\r\n\r\ntype DatabaseBuildingPopoverProps = {\r\n \"feature\": MapGeoJSONFeature;\r\n \"isOpen\": boolean;\r\n \"onCloseAction\": () => void;\r\n};\r\n\r\nexport default function DatabaseBuildingPopover ({\r\n feature,\r\n isOpen,\r\n onCloseAction,\r\n }: DatabaseBuildingPopoverProps) {\r\n\r\n const t = useTranslations('DatabaseBuildingPopover')\r\n\r\n\r\n const {state: mapState} = React.useContext(MapContext);\r\n\r\n const featureProps = React.useMemo(\r\n () => feature?.properties || {},\r\n [feature?.properties],\r\n );\r\n const buildingId = React.useMemo(\r\n () => {\r\n\r\n const id = Number(featureProps.dbId);\r\n return isNaN(id)\r\n ? null\r\n : id;\r\n\r\n },\r\n [featureProps.dbId],\r\n );\r\n\r\n const locationData = React.useMemo(\r\n () => ({\r\n \"countrySubdivision\": featureProps.de_ao_prov || mapState.map.currentLocation.countrySubdivision || null,\r\n \"municipality\": featureProps.de_ao_city || mapState.map.currentLocation.municipality || null,\r\n \"address\": featureProps.de_ao_stre || mapState.map.currentLocation.address || null,\r\n \"postalCode\": featureProps.de_ao_post || mapState.map.currentLocation.postalCode || null,\r\n \"site\": mapState.map.currentLocation.site || null,\r\n }),\r\n [\r\n featureProps.de_ao_prov,\r\n featureProps.de_ao_city,\r\n featureProps.de_ao_stre,\r\n featureProps.de_ao_post,\r\n mapState.map.currentLocation.countrySubdivision,\r\n mapState.map.currentLocation.municipality,\r\n mapState.map.currentLocation.address,\r\n mapState.map.currentLocation.postalCode,\r\n mapState.map.currentLocation.site,\r\n ]);\r\n\r\n const shouldFetchData = Boolean(buildingId && isOpen);\r\n const {building, isLoading, isError} = useBuilding(shouldFetchData\r\n ? buildingId\r\n : null);\r\n\r\n const displayData = React.useMemo(\r\n () => ({\r\n \"name\": building?.buildingName || t('namePlaceholder'),\r\n \"displayAddress\": building?.buildingAddress || locationData.address,\r\n \"buildingType\": building?.buildingType,\r\n \"NumberOfStoreys\": building?.buildingStoreyNum,\r\n }),\r\n [\r\n building?.buildingName,\r\n building?.buildingAddress,\r\n building?.buildingType,\r\n building?.buildingStoreyNum,\r\n locationData.address,\r\n]\r\n );\r\n\r\n const [expanded, setExpanded] = React.useState(false);\r\n\r\n // While the map is tinted by a sensor type, this building's readings are what the popover is\r\n // being opened to find, so they take the details slot instead of the postal address.\r\n // Same poll the footprint colours already run on, so opening the card costs no requests.\r\n const sensorColours = useBuildingSensorColours(ViewerNames.map);\r\n const sensorsOfType = buildingId == null\r\n ? []\r\n : sensorColours.sensorsByBuilding.get(buildingId) ?? [];\r\n const showSensors = Boolean(sensorColours.sensorType) && sensorsOfType.length > 0;\r\n\r\n // Show only the short subdivision code (e.g. \"ON\" from \"CA-ON\")\r\n const shortSubdivision = React.useMemo(() => {\r\n const code = locationData.countrySubdivision;\r\n if (!code) return null;\r\n const dash = code.lastIndexOf('-');\r\n return dash >= 0 ? code.slice(dash + 1) : code;\r\n }, [locationData.countrySubdivision]);\r\n\r\n // After every hook, so the hook order holds for features without a building.\r\n if (!buildingId) {\r\n\r\n return null;\r\n\r\n }\r\n\r\n return (\r\n <PopoverContent\r\n className=\"w-64 -m-1\"\r\n side=\"top\"\r\n >\r\n {/* Header row: title + close button, no overlap */}\r\n <div className=\"flex items-center justify-between gap-2 mb-1\">\r\n <div className=\"flex-1 min-w-0\">\r\n {isLoading\r\n ? <Skeleton className=\"h-4 w-32\" />\r\n : isError\r\n ? (\r\n <div className=\"flex items-center gap-2 text-destructive\">\r\n <LR.AlertCircle className=\"w-4 h-4 shrink-0\" />\r\n <h4 className=\"font-medium leading-none truncate\">{t('loadingError')}</h4>\r\n </div>\r\n )\r\n : <h4 className=\"font-medium leading-snug\">{displayData.name}</h4>\r\n }\r\n {isError && <p className=\"text-xs text-muted-foreground mt-1\">{String(isError)}</p>}\r\n </div>\r\n <Button\r\n aria-label=\"Close\"\r\n className=\"shrink-0 p-0 m-0 text-muted-foreground hover:text-foreground\"\r\n onClick={onCloseAction}\r\n variant=\"ghost\"\r\n size=\"icon\"\r\n >\r\n <LR.X className=\"w-4 h-4\" />\r\n </Button>\r\n </div>\r\n {/* The footprint's own number, always visible: the colour on the map is only\r\n readable once you can see the value behind it. */}\r\n {!isError && !isLoading && showSensors && sensorColours.sensorType && (\r\n <BuildingSensorSummary\r\n sensorType={sensorColours.sensorType}\r\n sensors={sensorsOfType}\r\n readings={sensorColours.readings}\r\n average={buildingId == null ? undefined : sensorColours.averages.get(buildingId)}\r\n latestAt={buildingId == null ? undefined : sensorColours.latestAtByBuilding.get(buildingId)}\r\n unit={sensorColours.unit}\r\n />\r\n )}\r\n {/* Expand/collapse details */}\r\n {!isError && (\r\n <>\r\n {isLoading\r\n ? <Skeleton className=\"h-5 w-24 mt-1\" />\r\n : (\r\n <Button\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n className=\"w-full h-7 text-xs text-muted-foreground justify-start gap-1 px-0 hover:text-foreground hover:bg-transparent\"\r\n onClick={() => setExpanded(v => !v)}\r\n >\r\n {expanded ? <LR.ChevronUp className=\"w-3 h-3\" /> : <LR.ChevronDown className=\"w-3 h-3\" />}\r\n {expanded ? t('hideDetails') : t('showDetails')}\r\n </Button>\r\n )}\r\n\r\n {expanded && !isLoading && showSensors && (\r\n <BuildingSensorList\r\n sensors={sensorsOfType}\r\n readings={sensorColours.readings}\r\n unit={sensorColours.unit}\r\n />\r\n )}\r\n\r\n {expanded && !isLoading && !showSensors && (\r\n <div className=\"mt-2 flex flex-col gap-2\">\r\n {/* Address */}\r\n <div>\r\n <p className=\"text-xs text-muted-foreground font-medium\">{t('address')}</p>\r\n {locationData.site && (\r\n <p className=\"text-sm\">{locationData.site.replace(\"_\", \" \")}</p>\r\n )}\r\n {displayData.displayAddress && (\r\n <p className=\"text-sm\">{displayData.displayAddress}</p>\r\n )}\r\n {(locationData.municipality || shortSubdivision || locationData.postalCode) && (\r\n <p className=\"text-sm\">\r\n {[locationData.municipality, shortSubdivision, locationData.postalCode]\r\n .filter(Boolean)\r\n .join(\", \")}\r\n </p>\r\n )}\r\n </div>\r\n {/* Building Type */}\r\n {displayData.buildingType && (\r\n <div>\r\n <p className=\"text-xs text-muted-foreground font-medium\">{t('buildingType')}</p>\r\n <Badge variant=\"secondary\">{displayData.buildingType}</Badge>\r\n </div>\r\n )}\r\n {/* Number of Storeys */}\r\n {displayData.NumberOfStoreys && (\r\n <div>\r\n <p className=\"text-xs text-muted-foreground font-medium\">{t('StoreysNum')}</p>\r\n <p className=\"text-sm\">{displayData.NumberOfStoreys}</p>\r\n </div>\r\n )}\r\n </div>\r\n )}\r\n </>\r\n )}\r\n\r\n <Separator className=\"my-3\" />\r\n <BuildingTools\r\n building={building}\r\n feature={feature}\r\n isError={isError}\r\n isLoading={isLoading}\r\n onCloseAction={onCloseAction}\r\n />\r\n </PopoverContent>\r\n );\r\n\r\n}\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;AAAA,cACG,SAAS;AAAA,cACT,UAAU,cAAc;AAAA,cACxB,MAAM,cAAc;AAAA;AAAA,UACxB;AAAA,UAGH,YAAY,CAAC,aAAa,CAAC,eACxB,qBAAC,SAAI,WAAU,4BAEX;AAAA,iCAAC,SACG;AAAA,kCAAC,OAAE,WAAU,6CAA6C,YAAE,SAAS,GAAE;AAAA,cACtE,aAAa,QACV,oBAAC,OAAE,WAAU,WAAW,uBAAa,KAAK,QAAQ,KAAK,GAAG,GAAE;AAAA,cAE/D,YAAY,kBACT,oBAAC,OAAE,WAAU,WAAW,sBAAY,gBAAe;AAAA,eAErD,aAAa,gBAAgB,oBAAoB,aAAa,eAC5D,oBAAC,OAAE,WAAU,WACR,WAAC,aAAa,cAAc,kBAAkB,aAAa,UAAU,EACjE,OAAO,OAAO,EACd,KAAK,IAAI,GAClB;AAAA,eAER;AAAA,YAEC,YAAY,gBACT,qBAAC,SACG;AAAA,kCAAC,OAAE,WAAU,6CAA6C,YAAE,cAAc,GAAE;AAAA,cAC5E,oBAAC,SAAM,SAAQ,aAAa,sBAAY,cAAa;AAAA,eACzD;AAAA,YAGH,YAAY,mBACT,qBAAC,SACG;AAAA,kCAAC,OAAE,WAAU,6CAA6C,YAAE,YAAY,GAAE;AAAA,cAC1E,oBAAC,OAAE,WAAU,WAAW,sBAAY,iBAAgB;AAAA,eACxD;AAAA,aAER;AAAA,WAER;AAAA,QAGJ,oBAAC,aAAU,WAAU,QAAO;AAAA,QAC5B;AAAA,UAAC;AAAA;AAAA,YACG;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA;AAAA,QACJ;AAAA;AAAA;AAAA,EACJ;AAGR;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { Sensor, SensorType } from "../../../../../../../../types/dbTypes";
|
|
3
|
+
import type { BuildingSensorAverage } from "../../../../../../../ui/Sensors/buildingSensorColours";
|
|
4
|
+
import type { SensorReading } from "../../../../../../../ui/Sensors/sensorValueColours";
|
|
5
|
+
export interface BuildingSensorSummaryProps {
|
|
6
|
+
sensorType: SensorType;
|
|
7
|
+
sensors: Sensor[];
|
|
8
|
+
readings: ReadonlyMap<number, SensorReading>;
|
|
9
|
+
average?: BuildingSensorAverage;
|
|
10
|
+
/** Most recent reading time across these sensors, epoch ms. */
|
|
11
|
+
latestAt?: number;
|
|
12
|
+
unit?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The one number behind this building's footprint colour, plus how much data is standing behind
|
|
16
|
+
* it.
|
|
17
|
+
*
|
|
18
|
+
* Rendered outside the popover's collapsible section: with the map tinted by sensor data, this
|
|
19
|
+
* is the thing the card is being opened to read, so it should not need a second click.
|
|
20
|
+
*
|
|
21
|
+
* Presentational: the caller owns the data, so the poll behind it stays a single one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function BuildingSensorSummary({ sensorType, sensors, readings, average, latestAt, unit, }: BuildingSensorSummaryProps): React.ReactElement;
|
|
24
|
+
export interface BuildingSensorListProps {
|
|
25
|
+
sensors: Sensor[];
|
|
26
|
+
readings: ReadonlyMap<number, SensorReading>;
|
|
27
|
+
unit?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The individual sensors behind the average, for the popover's expandable section.
|
|
31
|
+
*
|
|
32
|
+
* Caps at ten rows and scrolls past that, so a building with a large array does not push the
|
|
33
|
+
* tool row off the bottom of the card.
|
|
34
|
+
*/
|
|
35
|
+
export declare function BuildingSensorList({ sensors, readings, unit, }: BuildingSensorListProps): React.ReactElement;
|
|
36
|
+
//# sourceMappingURL=BuildingSensorDetails.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildingSensorDetails.d.ts","sourceRoot":"","sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AACnG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AAexF,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,OAAO,EACP,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,IAAI,GACL,EAAE,0BAA0B,GAAG,KAAK,CAAC,YAAY,CAkCjD;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,QAAQ,EACR,IAAI,GACL,EAAE,uBAAuB,GAAG,KAAK,CAAC,YAAY,CAyC9C"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useTranslations } from "next-intl";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { Badge } from "../../../../../../../../components/ui/";
|
|
6
|
+
import { AppConfigContext, MenusContext } from "../../../../../../../../store";
|
|
7
|
+
import { formatInZone } from "../../../../../../../../utils/timeUtils";
|
|
8
|
+
const valueNumber = new Intl.NumberFormat(void 0, { maximumFractionDigits: 1 });
|
|
9
|
+
const typeLabel = (name) => String(name).replace(/_/g, " ");
|
|
10
|
+
const MAX_VISIBLE_SENSORS = 10;
|
|
11
|
+
const ROW_HEIGHT_PX = 26;
|
|
12
|
+
const formatter = (unit) => (value) => `${valueNumber.format(value)}${unit ? ` ${unit}` : ""}`;
|
|
13
|
+
function BuildingSensorSummary({
|
|
14
|
+
sensorType,
|
|
15
|
+
sensors,
|
|
16
|
+
readings,
|
|
17
|
+
average,
|
|
18
|
+
latestAt,
|
|
19
|
+
unit
|
|
20
|
+
}) {
|
|
21
|
+
const t = useTranslations("BuildingSensors");
|
|
22
|
+
const { state: appConfigState } = React.useContext(AppConfigContext);
|
|
23
|
+
const timeZone = appConfigState.appConfig.displayTimeZone;
|
|
24
|
+
const formatValue = formatter(unit);
|
|
25
|
+
const reporting = sensors.filter((s) => readings.has(s.id)).length;
|
|
26
|
+
return /* @__PURE__ */ jsxs("div", { className: "mt-1 flex flex-col gap-1", children: [
|
|
27
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground font-medium", children: typeLabel(sensorType.name) }),
|
|
28
|
+
average && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
29
|
+
/* @__PURE__ */ jsx(
|
|
30
|
+
"span",
|
|
31
|
+
{
|
|
32
|
+
"aria-hidden": "true",
|
|
33
|
+
className: "h-3.5 w-3.5 shrink-0 rounded-full border",
|
|
34
|
+
style: { backgroundColor: average.colour }
|
|
35
|
+
}
|
|
36
|
+
),
|
|
37
|
+
/* @__PURE__ */ jsx("span", { className: "text-base font-semibold tabular-nums", children: formatValue(average.average) }),
|
|
38
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("average") })
|
|
39
|
+
] }),
|
|
40
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2 text-xs text-muted-foreground", children: [
|
|
41
|
+
/* @__PURE__ */ jsx(Badge, { variant: "secondary", children: t("reporting", { reporting, total: sensors.length }) }),
|
|
42
|
+
latestAt != null && /* @__PURE__ */ jsx("span", { children: t("updated", {
|
|
43
|
+
time: formatInZone(latestAt, timeZone, { hour: "2-digit", minute: "2-digit", hourCycle: "h23" })
|
|
44
|
+
}) })
|
|
45
|
+
] })
|
|
46
|
+
] });
|
|
47
|
+
}
|
|
48
|
+
function BuildingSensorList({
|
|
49
|
+
sensors,
|
|
50
|
+
readings,
|
|
51
|
+
unit
|
|
52
|
+
}) {
|
|
53
|
+
const t = useTranslations("BuildingSensors");
|
|
54
|
+
const { dispatch: menusDispatch } = React.useContext(MenusContext);
|
|
55
|
+
const formatValue = formatter(unit);
|
|
56
|
+
return /* @__PURE__ */ jsx(
|
|
57
|
+
"ul",
|
|
58
|
+
{
|
|
59
|
+
className: "mt-2 space-y-0.5 overflow-y-auto",
|
|
60
|
+
style: sensors.length > MAX_VISIBLE_SENSORS ? { maxHeight: MAX_VISIBLE_SENSORS * ROW_HEIGHT_PX } : void 0,
|
|
61
|
+
children: sensors.map((sensor) => {
|
|
62
|
+
var _a;
|
|
63
|
+
const reading = readings.get(sensor.id);
|
|
64
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
65
|
+
"button",
|
|
66
|
+
{
|
|
67
|
+
type: "button",
|
|
68
|
+
onClick: () => menusDispatch({
|
|
69
|
+
type: "SET_FOCUSED_SENSOR_ID",
|
|
70
|
+
payload: { sensorId: sensor.id }
|
|
71
|
+
}),
|
|
72
|
+
className: "flex w-full items-center gap-2 rounded px-1 py-1 text-left text-xs hover:bg-accent",
|
|
73
|
+
children: [
|
|
74
|
+
/* @__PURE__ */ jsx(
|
|
75
|
+
"span",
|
|
76
|
+
{
|
|
77
|
+
"aria-hidden": "true",
|
|
78
|
+
className: "h-2.5 w-2.5 shrink-0 rounded-full border",
|
|
79
|
+
style: { backgroundColor: (_a = reading == null ? void 0 : reading.colour) != null ? _a : "transparent" }
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: sensor.name }),
|
|
83
|
+
/* @__PURE__ */ jsx("span", { className: "shrink-0 tabular-nums text-muted-foreground", children: reading ? formatValue(reading.value) : t("noReading") })
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
) }, sensor.id);
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
BuildingSensorList,
|
|
93
|
+
BuildingSensorSummary
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=BuildingSensorDetails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.tsx"],"sourcesContent":["\"use client\";\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { useTranslations } from \"next-intl\";\r\nimport * as React from \"react\";\r\n\r\nimport { Badge } from \"../../../../../../../../components/ui/\";\r\nimport { AppConfigContext, MenusContext } from \"../../../../../../../../store\";\r\nimport { formatInZone } from \"../../../../../../../../utils/timeUtils\";\r\n\r\nimport type { Sensor, SensorType } from \"../../../../../../../../types/dbTypes\";\r\nimport type { BuildingSensorAverage } from \"../../../../../../../ui/Sensors/buildingSensorColours\";\r\nimport type { SensorReading } from \"../../../../../../../ui/Sensors/sensorValueColours\";\r\n\r\nconst valueNumber = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 });\r\n\r\n/** `Air_Quality` reads as `Air Quality`, matching the legend and the cards. */\r\nconst typeLabel = (name: string): string => String(name).replace(/_/g, \" \");\r\n\r\n/** Rows shown before the list starts scrolling. */\r\nconst MAX_VISIBLE_SENSORS = 10;\r\n/** One row at text-xs with py-1 padding and the list's 2px gap. */\r\nconst ROW_HEIGHT_PX = 26;\r\n\r\nconst formatter = (unit?: string) => (value: number): string =>\r\n `${valueNumber.format(value)}${unit ? ` ${unit}` : \"\"}`;\r\n\r\nexport interface BuildingSensorSummaryProps {\r\n sensorType: SensorType;\r\n sensors: Sensor[];\r\n readings: ReadonlyMap<number, SensorReading>;\r\n average?: BuildingSensorAverage;\r\n /** Most recent reading time across these sensors, epoch ms. */\r\n latestAt?: number;\r\n unit?: string;\r\n}\r\n\r\n/**\r\n * The one number behind this building's footprint colour, plus how much data is standing behind\r\n * it.\r\n *\r\n * Rendered outside the popover's collapsible section: with the map tinted by sensor data, this\r\n * is the thing the card is being opened to read, so it should not need a second click.\r\n *\r\n * Presentational: the caller owns the data, so the poll behind it stays a single one.\r\n */\r\nexport function BuildingSensorSummary({\r\n sensorType,\r\n sensors,\r\n readings,\r\n average,\r\n latestAt,\r\n unit,\r\n}: BuildingSensorSummaryProps): React.ReactElement {\r\n const t = useTranslations(\"BuildingSensors\");\r\n const { state: appConfigState } = React.useContext(AppConfigContext);\r\n const timeZone = appConfigState.appConfig.displayTimeZone;\r\n const formatValue = formatter(unit);\r\n\r\n const reporting = sensors.filter(s => readings.has(s.id)).length;\r\n\r\n return (\r\n <div className=\"mt-1 flex flex-col gap-1\">\r\n <p className=\"text-xs text-muted-foreground font-medium\">{typeLabel(sensorType.name)}</p>\r\n {average && (\r\n <div className=\"flex items-center gap-2\">\r\n <span\r\n aria-hidden=\"true\"\r\n className=\"h-3.5 w-3.5 shrink-0 rounded-full border\"\r\n style={{ backgroundColor: average.colour }}\r\n />\r\n <span className=\"text-base font-semibold tabular-nums\">{formatValue(average.average)}</span>\r\n <span className=\"text-xs text-muted-foreground\">{t(\"average\")}</span>\r\n </div>\r\n )}\r\n <div className=\"flex flex-wrap items-center gap-2 text-xs text-muted-foreground\">\r\n <Badge variant=\"secondary\">{t(\"reporting\", { reporting, total: sensors.length })}</Badge>\r\n {latestAt != null && (\r\n <span>\r\n {t(\"updated\", {\r\n time: formatInZone(latestAt, timeZone, { hour: \"2-digit\", minute: \"2-digit\", hourCycle: \"h23\" }),\r\n })}\r\n </span>\r\n )}\r\n </div>\r\n </div>\r\n );\r\n}\r\n\r\nexport interface BuildingSensorListProps {\r\n sensors: Sensor[];\r\n readings: ReadonlyMap<number, SensorReading>;\r\n unit?: string;\r\n}\r\n\r\n/**\r\n * The individual sensors behind the average, for the popover's expandable section.\r\n *\r\n * Caps at ten rows and scrolls past that, so a building with a large array does not push the\r\n * tool row off the bottom of the card.\r\n */\r\nexport function BuildingSensorList({\r\n sensors,\r\n readings,\r\n unit,\r\n}: BuildingSensorListProps): React.ReactElement {\r\n const t = useTranslations(\"BuildingSensors\");\r\n const { dispatch: menusDispatch } = React.useContext(MenusContext);\r\n const formatValue = formatter(unit);\r\n\r\n return (\r\n <ul\r\n className=\"mt-2 space-y-0.5 overflow-y-auto\"\r\n style={sensors.length > MAX_VISIBLE_SENSORS\r\n ? { maxHeight: MAX_VISIBLE_SENSORS * ROW_HEIGHT_PX }\r\n : undefined}\r\n >\r\n {sensors.map(sensor => {\r\n const reading = readings.get(sensor.id);\r\n return (\r\n <li key={sensor.id}>\r\n {/* Focus is global, so picking one here moves the legend caret, the marker halos\r\n and the detail charts together. */}\r\n <button\r\n type=\"button\"\r\n onClick={() => menusDispatch({\r\n type: \"SET_FOCUSED_SENSOR_ID\",\r\n payload: { sensorId: sensor.id },\r\n })}\r\n className=\"flex w-full items-center gap-2 rounded px-1 py-1 text-left text-xs hover:bg-accent\"\r\n >\r\n <span\r\n aria-hidden=\"true\"\r\n className=\"h-2.5 w-2.5 shrink-0 rounded-full border\"\r\n style={{ backgroundColor: reading?.colour ?? \"transparent\" }}\r\n />\r\n <span className=\"min-w-0 flex-1 truncate\">{sensor.name}</span>\r\n <span className=\"shrink-0 tabular-nums text-muted-foreground\">\r\n {reading ? formatValue(reading.value) : t(\"noReading\")}\r\n </span>\r\n </button>\r\n </li>\r\n );\r\n })}\r\n </ul>\r\n );\r\n}\r\n"],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,"file":"BuildingsTools.d.ts","sourceRoot":"","sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"BuildingsTools.d.ts","sourceRoot":"","sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B,OAAO,KAAK,EAAE,QAAQ,EAAU,MAAM,uCAAuC,CAAC;AAE9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,SAAS,EACT,OAAO,EACP,QAAQ,EACR,OAAO,EACP,aAAa,EACd,EAAE,kBAAkB,qBA0XpB"}
|
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
import { useFileUploadHandler } from "../../../../../../../../components/ui/FilesManager/src/useFileUploadHandler";
|
|
14
14
|
import { useFilesByBuildingId, useUploadFileToBuilding } from "../../../../../../../../hooks/files/files";
|
|
15
15
|
import { usePermissions } from "../../../../../../../../store";
|
|
16
|
-
import { BuildingsContext, BimContext, MapContext, MenusContext, useMenusContext } from "../../../../../../../../store";
|
|
16
|
+
import { AppConfigContext, BuildingsContext, BimContext, MapContext, MenusContext, useMenusContext } from "../../../../../../../../store";
|
|
17
17
|
import { ViewerNames } from "../../../../../../../../types/";
|
|
18
|
+
import { hasAppContent } from "../../../../../../../../utils/appContent";
|
|
18
19
|
import { toggleBimToMap as dispatchToggleBimToMap } from "../../../../../utils/toggleBimToMap";
|
|
19
20
|
import Compare from "../../../../compare";
|
|
20
21
|
function BuildingTools({
|
|
@@ -27,6 +28,8 @@ function BuildingTools({
|
|
|
27
28
|
const t = useTranslations("BuildingTools");
|
|
28
29
|
const { ability } = usePermissions();
|
|
29
30
|
const { dispatch: menusDispatch } = React.useContext(MenusContext);
|
|
31
|
+
const { state: appConfigState } = React.useContext(AppConfigContext);
|
|
32
|
+
const { organization } = appConfigState.appConfig;
|
|
30
33
|
const { state: mapState } = React.useContext(MapContext);
|
|
31
34
|
const { dispatch: bimDispatch, state: bimState } = React.useContext(BimContext);
|
|
32
35
|
const { bimModelsAddedToMap } = bimState.bim;
|
|
@@ -124,54 +127,64 @@ function BuildingTools({
|
|
|
124
127
|
[buildingFiles]
|
|
125
128
|
);
|
|
126
129
|
const buildingButtons = React.useMemo(
|
|
127
|
-
() =>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
{
|
|
136
|
-
id: "open-building-page",
|
|
137
|
-
icon: LR.Building2,
|
|
138
|
-
title: t("openBIMTitle"),
|
|
139
|
-
onClick: () => {
|
|
140
|
-
changeViewer(ViewerNames.buildings);
|
|
141
|
-
setSelectedItem(building);
|
|
142
|
-
setView("detail");
|
|
130
|
+
() => {
|
|
131
|
+
const tools = [
|
|
132
|
+
{
|
|
133
|
+
id: "map-compare-buildings",
|
|
134
|
+
icon: LR.Columns3,
|
|
135
|
+
title: t("compareTitle"),
|
|
136
|
+
component: Compare,
|
|
137
|
+
disabled: !ability.can("read", "Building")
|
|
143
138
|
},
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
139
|
+
{
|
|
140
|
+
id: "open-building-page",
|
|
141
|
+
icon: LR.Building2,
|
|
142
|
+
title: t("openBIMTitle"),
|
|
143
|
+
onClick: () => {
|
|
144
|
+
changeViewer(ViewerNames.buildings);
|
|
145
|
+
setSelectedItem(building);
|
|
146
|
+
setView("detail");
|
|
147
|
+
},
|
|
148
|
+
disabled: !ability.can("read", "Building"),
|
|
149
|
+
opensViewer: ViewerNames.buildings
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
id: "open-bim-viewer",
|
|
153
|
+
icon: LR.Box,
|
|
154
|
+
title: t("OpenBIMViewerTitle"),
|
|
155
|
+
onClick: onOpenBimViewer,
|
|
156
|
+
disabled: !ability.can("read", "File"),
|
|
157
|
+
opensViewer: ViewerNames.bim
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: "open-pointcloud",
|
|
161
|
+
title: t("openPointCloudTitle"),
|
|
162
|
+
icon: LR.Grip,
|
|
163
|
+
onClick: () => changeViewer(ViewerNames.pointcloud),
|
|
164
|
+
disabled: pcFiles.length === 0 || !ability.can("read", "File"),
|
|
165
|
+
opensViewer: ViewerNames.pointcloud
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: "map-add-file",
|
|
169
|
+
icon: isUploading ? LR.Loader : LR.FilePlus,
|
|
170
|
+
title: t("addFileTitle"),
|
|
171
|
+
onClick: triggerFileInput,
|
|
172
|
+
disabled: !ability.can("create", "File")
|
|
173
|
+
}
|
|
174
|
+
];
|
|
175
|
+
return tools.filter(
|
|
176
|
+
(tool) => tool.opensViewer == null || hasAppContent(organization, tool.opensViewer)
|
|
177
|
+
);
|
|
178
|
+
},
|
|
168
179
|
[
|
|
169
180
|
changeViewer,
|
|
170
181
|
building,
|
|
171
182
|
setSelectedItem,
|
|
172
183
|
setView,
|
|
173
184
|
isUploading,
|
|
174
|
-
triggerFileInput
|
|
185
|
+
triggerFileInput,
|
|
186
|
+
organization,
|
|
187
|
+
pcFiles.length
|
|
175
188
|
]
|
|
176
189
|
);
|
|
177
190
|
const onLoadBIM = React.useCallback(
|