frigate/web/src/utils/lifecycleUtil.ts
GuoQing Liu ef19332fe5
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
Add zones friend name (#20761)
* feat: add zones friendly name

* fix: fix the issue where the input field was empty when there was no friendly_name

* chore: fix the issue where the friendly name would replace spaces with underscores

* docs: update zones docs

* Update web/src/components/settings/ZoneEditPane.tsx

Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>

* Add friendly_name option for zone configuration

Added optional friendly name for zones in configuration.

* fix: fix the logical error in the null/empty check for the polygons parameter

* fix: remove the toast name for zones will use the friendly_name instead

* docs: remove emoji tips

* revert: revert zones doc ui tips

* Update docs/docs/configuration/zones.md

Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>

* Update docs/docs/configuration/zones.md

Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>

* Update docs/docs/configuration/zones.md

Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>

* feat: add friendly zone names to tracking details and lifecycle item descriptions

* chore: lint fix

* refactor: add friendly zone names to timeline entries and clean up unused code

* refactor: add formatList

---------

Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
2025-11-07 08:02:06 -06:00

85 lines
2.4 KiB
TypeScript

import { TrackingDetailsSequence } from "@/types/timeline";
import { t } from "i18next";
import { getTranslatedLabel } from "./i18n";
import { capitalizeFirstLetter, formatList } from "./stringUtil";
export function getLifecycleItemDescription(
lifecycleItem: TrackingDetailsSequence,
) {
const rawLabel = Array.isArray(lifecycleItem.data.sub_label)
? lifecycleItem.data.sub_label[0]
: lifecycleItem.data.sub_label || lifecycleItem.data.label;
const label = lifecycleItem.data.sub_label
? capitalizeFirstLetter(rawLabel)
: getTranslatedLabel(rawLabel);
switch (lifecycleItem.class_type) {
case "visible":
return t("trackingDetails.lifecycleItemDesc.visible", {
ns: "views/explore",
label,
});
case "entered_zone":
return t("trackingDetails.lifecycleItemDesc.entered_zone", {
ns: "views/explore",
label,
zones: formatList(
lifecycleItem.data.zones_friendly_names ?? lifecycleItem.data.zones,
),
});
case "active":
return t("trackingDetails.lifecycleItemDesc.active", {
ns: "views/explore",
label,
});
case "stationary":
return t("trackingDetails.lifecycleItemDesc.stationary", {
ns: "views/explore",
label,
});
case "attribute": {
let title = "";
if (
lifecycleItem.data.attribute == "face" ||
lifecycleItem.data.attribute == "license_plate"
) {
title = t(
"trackingDetails.lifecycleItemDesc.attribute.faceOrLicense_plate",
{
ns: "views/explore",
label,
attribute: getTranslatedLabel(
lifecycleItem.data.attribute.replaceAll("_", " "),
),
},
);
} else {
title = t("trackingDetails.lifecycleItemDesc.attribute.other", {
ns: "views/explore",
label: lifecycleItem.data.label,
attribute: getTranslatedLabel(
lifecycleItem.data.attribute.replaceAll("_", " "),
),
});
}
return title;
}
case "gone":
return t("trackingDetails.lifecycleItemDesc.gone", {
ns: "views/explore",
label,
});
case "heard":
return t("trackingDetails.lifecycleItemDesc.heard", {
ns: "views/explore",
label,
});
case "external":
return t("trackingDetails.lifecycleItemDesc.external", {
ns: "views/explore",
label,
});
}
}