From cdadf44c27b7f018d38c1f3f4bf908ea205af238 Mon Sep 17 00:00:00 2001 From: sgrtye Date: Wed, 14 Feb 2024 22:10:56 +0000 Subject: [PATCH] add prefix and fix example --- docs/widgets/services/customapi.md | 8 ++++++-- src/widgets/customapi/component.jsx | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/widgets/services/customapi.md b/docs/widgets/services/customapi.md index 2e23f1d8a..e13874610 100644 --- a/docs/widgets/services/customapi.md +++ b/docs/widgets/services/customapi.md @@ -103,7 +103,7 @@ mappings: ## Data Transformation -You can manipulate data with the following tools `remap`, `scale` and `suffix`, for example: +You can manipulate data with the following tools `remap`, `scale`, `prefix` and `suffix`, for example: ```yaml - field: key4 @@ -120,7 +120,11 @@ You can manipulate data with the following tools `remap`, `scale` and `suffix`, label: Power format: float scale: 0.001 # can be number or string e.g. 1/16 - suffix: kW + suffix: "kW" +- field: key6 + label: Price + format: float + suffix: "$" ``` ## List View diff --git a/src/widgets/customapi/component.jsx b/src/widgets/customapi/component.jsx index 62405faf2..19a89a316 100644 --- a/src/widgets/customapi/component.jsx +++ b/src/widgets/customapi/component.jsx @@ -90,6 +90,12 @@ function formatValue(t, transformation, rawValue) { // nothing } + // Apply fixed prefix. + const prefix = transformation?.prefix; + if (prefix) { + value = `${prefix} ${value}`; + } + // Apply fixed suffix. const suffix = transformation?.suffix; if (suffix) {