mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-05 21:47:48 +01:00
Compare commits
3 Commits
c77dfa4c64
...
copilot/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
384eaae6c1 | ||
|
|
40fb55ced0 | ||
|
|
d0fc2bcef8 |
@@ -159,6 +159,30 @@ Widgets can tint their metric block text automatically based on rules defined al
|
||||
|
||||
Supported numeric operators for the `when` property are `gt`, `gte`, `lt`, `lte`, `eq`, `ne`, `between`, and `outside`. String rules support `equals`, `includes`, `startsWith`, `endsWith`, and `regex`. Each rule can be inverted with `negate: true`, and string rules may pass `caseSensitive: true` or custom regex `flags`. The highlight engine does its best to coerce formatted values, but you will get the most reliable results when you pass plain numbers or strings into `<Block>`.
|
||||
|
||||
#### Value Only Highlighting
|
||||
|
||||
You can optionally apply highlighting only to the value portion of a block (not the label) by setting `valueOnly: true` on the field configuration. This keeps the label visible while highlighting only the metric value itself.
|
||||
|
||||
```yaml
|
||||
- Sonarr:
|
||||
icon: sonarr.png
|
||||
href: http://sonarr.host.or.ip
|
||||
widget:
|
||||
type: sonarr
|
||||
url: http://sonarr.host.or.ip
|
||||
key: ${SONARR_API_KEY}
|
||||
highlight:
|
||||
queued:
|
||||
valueOnly: true
|
||||
numeric:
|
||||
- level: danger
|
||||
when: gte
|
||||
value: 20
|
||||
- level: warn
|
||||
when: gte
|
||||
value: 5
|
||||
```
|
||||
|
||||
## Descriptions
|
||||
|
||||
Services may have descriptions,
|
||||
|
||||
@@ -32,18 +32,22 @@ export default function Block({ value, label, field }) {
|
||||
return getHighlightClass(highlight.level, highlightConfig);
|
||||
}, [highlight, highlightConfig]);
|
||||
|
||||
const applyToValueOnly = highlight?.valueOnly === true;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
"bg-theme-200/50 dark:bg-theme-900/20 rounded-sm m-1 flex-1 flex flex-col items-center justify-center text-center p-1",
|
||||
value === undefined ? "animate-pulse" : "",
|
||||
highlightClass,
|
||||
!applyToValueOnly && highlightClass,
|
||||
"service-block",
|
||||
)}
|
||||
data-highlight-level={highlight?.level}
|
||||
data-highlight-source={highlight?.source}
|
||||
>
|
||||
<div className="font-thin text-sm">{value === undefined || value === null ? "-" : value}</div>
|
||||
<div className={classNames("font-thin text-sm", applyToValueOnly && highlightClass)}>
|
||||
{value === undefined || value === null ? "-" : value}
|
||||
</div>
|
||||
<div className="font-bold text-xs uppercase">{t(label)}</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -200,7 +200,7 @@ const ensureArray = (value) => {
|
||||
};
|
||||
|
||||
const findHighlightLevel = (ruleSet, numericValue, stringValue) => {
|
||||
const { numeric, string } = ruleSet;
|
||||
const { numeric, string, valueOnly } = ruleSet;
|
||||
|
||||
if (numeric && numericValue !== undefined) {
|
||||
const numericRules = ensureArray(numeric);
|
||||
@@ -208,7 +208,7 @@ const findHighlightLevel = (ruleSet, numericValue, stringValue) => {
|
||||
for (const candidate of numericCandidates) {
|
||||
for (const rule of numericRules) {
|
||||
if (rule?.level && evaluateNumericRule(candidate, rule)) {
|
||||
return { level: rule.level, source: "numeric", rule };
|
||||
return { level: rule.level, source: "numeric", rule, valueOnly };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +218,7 @@ const findHighlightLevel = (ruleSet, numericValue, stringValue) => {
|
||||
const stringRules = ensureArray(string);
|
||||
for (const rule of stringRules) {
|
||||
if (rule?.level && evaluateStringRule(stringValue, rule)) {
|
||||
return { level: rule.level, source: "string", rule };
|
||||
return { level: rule.level, source: "string", rule, valueOnly };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user