Drop fields

This commit is contained in:
shamoon
2025-10-12 21:39:53 -07:00
parent 8361378a89
commit 1d110d7ff9
2 changed files with 26 additions and 21 deletions

View File

@@ -131,26 +131,25 @@ Widgets can tint their metric blocks automatically based on rules defined alongs
url: http://sonarr.host.or.ip
key: ${SONARR_API_KEY}
highlight:
fields:
sonarr.queued:
numeric:
- level: danger
when: gte
value: 20
- level: warn
when: gte
value: 5
- level: good
when: eq
value: 0
sonarr.status:
string:
- level: danger
when: regex
value: "(failed|import) pending"
- level: good
when: equals
value: "All good"
sonarr.queued:
numeric:
- level: danger
when: gte
value: 20
- level: warn
when: gte
value: 5
- level: good
when: eq
value: 0
sonarr.status:
string:
- level: danger
when: regex
value: "(failed|import) pending"
- level: good
when: equals
value: "All good"
```
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`. If you format values before passing them into `<Block>`, also pass the unformatted number or string via the `valueRaw` prop so the highlight engine can evaluate correctly.

View File

@@ -11,7 +11,13 @@ export const buildHighlightConfig = (globalConfig, widgetConfig) => {
...(widgetConfig?.levels || {}),
};
const fields = widgetConfig?.fields || {};
const { levels: _levels, ...fields } = widgetConfig || {};
Object.keys(fields).forEach((key) => {
if (fields[key] === null || fields[key] === undefined) {
delete fields[key];
}
});
const hasLevels = Object.values(levels).some(Boolean);
const hasFields = Object.keys(fields).length > 0;