StateTimeline: Support hideFrom field config (#68586)

This commit is contained in:
Ryan McKinley 2023-05-16 12:18:35 -07:00 committed by GitHub
parent 160e207e47
commit 2e7b77a94a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "prettier",
"version": "2.8.1-sdk",
"version": "2.8.4-sdk",
"main": "./index.js",
"type": "commonjs"
}

View File

@ -444,6 +444,9 @@ export function prepareTimelineFields(
const fields: Field[] = [];
for (let field of nullToValue(nulledFrame).fields) {
if (field.config.custom?.hideFrom?.viz) {
continue;
}
switch (field.type) {
case FieldType.time:
isTimeseries = true;
@ -558,6 +561,7 @@ export function getFieldLegendItem(fields: Field[], theme: GrafanaTheme2): VizLe
const thresholds = fieldConfig.thresholds;
// If thresholds are enabled show each step in the legend
// This ignores the hide from legend since the range is valid
if (colorMode === FieldColorModeId.Thresholds && thresholds?.steps && thresholds.steps.length > 1) {
return getThresholdItems(fieldConfig, theme);
}
@ -567,15 +571,17 @@ export function getFieldLegendItem(fields: Field[], theme: GrafanaTheme2): VizLe
return undefined; // eventually a color bar
}
let stateColors: Map<string, string | undefined> = new Map();
const stateColors: Map<string, string | undefined> = new Map();
fields.forEach((field) => {
field.values.forEach((v) => {
let state = field.display!(v);
if (state.color) {
stateColors.set(state.text, state.color!);
}
});
if (!field.config.custom?.hideFrom?.legend) {
field.values.forEach((v) => {
let state = field.display!(v);
if (state.color) {
stateColors.set(state.text, state.color!);
}
});
}
});
stateColors.forEach((color, label) => {

View File

@ -60,6 +60,8 @@ export const plugin = new PanelPlugin<Options, FieldConfig>(StateTimelinePanel)
shouldApply: (f) => f.type !== FieldType.time,
process: identityOverrideProcessor,
});
commonOptionsBuilder.addHideFrom(builder);
},
})
.setPanelOptions((builder) => {

View File

@ -40,6 +40,8 @@ export const plugin = new PanelPlugin<Options, FieldConfig>(StatusHistoryPanel)
step: 1,
},
});
commonOptionsBuilder.addHideFrom(builder);
},
})
.setPanelOptions((builder) => {