feat(map): refine SCADA feature experience
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getFeaturePanelModel, getFeaturePanelProperties } from "./feature-properties";
|
||||
import { getFeaturePanelModel, getFeaturePanelProperties, getLocalizedFeatureProperties } from "./feature-properties";
|
||||
|
||||
describe("feature panel properties", () => {
|
||||
it.each([
|
||||
@@ -68,4 +68,14 @@ describe("feature panel properties", () => {
|
||||
expect(model.badge).toBeUndefined();
|
||||
expect(model.attributes.map((entry) => entry.key)).toEqual(["invert_elevation", "max_depth"]);
|
||||
});
|
||||
|
||||
it("omits the internal SCADA clustering size from user-facing properties", () => {
|
||||
const entries = getLocalizedFeatureProperties({
|
||||
point_name: "THC雷达液位计(MQTT)",
|
||||
cluster_size: 29,
|
||||
device_external_id: "DEVICE-002"
|
||||
});
|
||||
|
||||
expect(entries.map((entry) => entry.key)).toEqual(["point_name", "device_external_id"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,7 +58,19 @@ const PROPERTY_LABELS: Record<string, string> = {
|
||||
zone: "分区",
|
||||
district: "片区",
|
||||
source: "来源",
|
||||
updated_at: "更新时间"
|
||||
updated_at: "更新时间",
|
||||
point_id: "测点 ID",
|
||||
point_external_id: "测点编号",
|
||||
point_name: "测点名称",
|
||||
device_id: "设备 ID",
|
||||
device_external_id: "设备编号",
|
||||
device_type_id: "设备类型 ID",
|
||||
device_type_name: "设备类型",
|
||||
device_icon_code: "设备图标编码",
|
||||
active: "运行状态",
|
||||
junction_id: "关联检查井",
|
||||
location_source: "位置来源",
|
||||
synced_at: "同步时间"
|
||||
};
|
||||
|
||||
const PROPERTY_ORDER: Record<string, number> = {
|
||||
@@ -121,7 +133,8 @@ const FEATURE_PANEL_PROPERTY_KEYS: Record<WaterNetworkSourceId, readonly string[
|
||||
conduits: ["id", "length", "diameter"],
|
||||
junctions: ["id", "invert_elevation", "max_depth"],
|
||||
orifices: ["id", "discharge_coeff", "gated", "shape", "geom1", "geom2"],
|
||||
outfalls: ["id", "invert_elevation", "outfall_type"]
|
||||
outfalls: ["id", "invert_elevation", "outfall_type"],
|
||||
scada: ["point_external_id", "device_type_name", "device_external_id", "junction_id", "synced_at"]
|
||||
};
|
||||
|
||||
const FEATURE_PANEL_BADGE_KEYS: Partial<Record<WaterNetworkSourceId, string>> = {
|
||||
@@ -130,7 +143,7 @@ const FEATURE_PANEL_BADGE_KEYS: Partial<Record<WaterNetworkSourceId, string>> =
|
||||
};
|
||||
|
||||
export function getLocalizedFeatureProperties(properties: Record<string, unknown>): LocalizedFeatureProperty[] {
|
||||
return Object.entries(properties).map(([key, value]) => ({
|
||||
return Object.entries(properties).filter(([key]) => normalizePropertyKey(key) !== "cluster_size").map(([key, value]) => ({
|
||||
key,
|
||||
label: getFeaturePropertyLabel(key),
|
||||
value: formatFeaturePropertyValue(key, value)
|
||||
@@ -159,14 +172,15 @@ export function getFeaturePanelModel(
|
||||
featureId?: string
|
||||
): FeaturePanelModel {
|
||||
const entries = getFeaturePanelProperties(layer, properties, featureId);
|
||||
const id = entries.find((entry) => entry.key === "id")?.value ?? "暂无";
|
||||
const idKey = layer === "scada" ? "point_external_id" : "id";
|
||||
const id = entries.find((entry) => entry.key === idKey)?.value ?? "暂无";
|
||||
const badgeKey = FEATURE_PANEL_BADGE_KEYS[layer];
|
||||
const badgeEntry = badgeKey ? entries.find((entry) => entry.key === badgeKey) : undefined;
|
||||
|
||||
return {
|
||||
id,
|
||||
badge: badgeEntry ? getFeaturePanelBadge(layer, badgeEntry.value) : undefined,
|
||||
attributes: entries.filter((entry) => entry.key !== "id" && entry.key !== badgeKey)
|
||||
attributes: entries.filter((entry) => entry.key !== idKey && entry.key !== badgeKey)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -190,6 +204,14 @@ export function formatFeaturePropertyValue(key: string, value: unknown) {
|
||||
return GATED_LABELS[String(value).toLowerCase()] ?? formatValue(value);
|
||||
}
|
||||
|
||||
if (normalizedKey === "active" && typeof value === "boolean") {
|
||||
return value ? "在线" : "离线";
|
||||
}
|
||||
|
||||
if (normalizedKey === "location_source" && value === "density_cluster_demo") {
|
||||
return "密度聚类模拟位置";
|
||||
}
|
||||
|
||||
if ((normalizedKey === "diameter" || normalizedKey === "dn") && value !== null && value !== undefined && value !== "") {
|
||||
const diameterInMeters = typeof value === "number" ? value : Number(value);
|
||||
return Number.isFinite(diameterInMeters)
|
||||
|
||||
Reference in New Issue
Block a user