Datasource/CloudWatch: Prevents hidden dataframe fields from displaying in tables (#24580)

* Datasource/CloudWatch: Prevents hidden dataframe fields from displaying in tables
This commit is contained in:
kay delaney
2020-05-13 14:34:23 +01:00
committed by GitHub
parent cd9cbe5e16
commit 277aee8642
12 changed files with 81 additions and 22 deletions

View File

@@ -57,9 +57,9 @@ export class FieldCache {
return types && types.length > 0;
}
getFirstFieldOfType(type: FieldType): FieldWithIndex | undefined {
getFirstFieldOfType(type: FieldType, includeHidden = false): FieldWithIndex | undefined {
const fields = this.fieldByType[type];
const firstField = fields.find(field => !(field.config.custom && field.config.custom['Hidden']));
const firstField = fields.find(field => includeHidden || !field.config.custom?.hidden);
return firstField;
}

View File

@@ -96,6 +96,7 @@ export interface Column {
text: string; // For a Column, the 'text' is the field name
filterable?: boolean;
unit?: string;
custom?: Record<string, any>;
}
export interface TableData extends QueryResultBase {

View File

@@ -83,8 +83,10 @@ class UnThemedLogDetails extends PureComponent<Props> {
return (
row.dataFrame.fields
.map((field, index) => ({ ...field, index }))
// Remove Id which we use for react key and entry field which we are showing as the log message.
.filter((field, index) => 'id' !== field.name && row.entryFieldIndex !== index)
// Remove Id which we use for react key and entry field which we are showing as the log message. Also remove hidden fields.
.filter(
(field, index) => !('id' === field.name || row.entryFieldIndex === index || field.config.custom?.hidden)
)
// Filter out fields without values. For example in elastic the fields are parsed from the document which can
// have different structure per row and so the dataframe is pretty sparse.
.filter(field => {

View File

@@ -7,6 +7,7 @@ export interface TableFieldOptions {
width: number;
align: FieldTextAlignment;
displayMode: TableCellDisplayMode;
hidden?: boolean;
}
export enum TableCellDisplayMode {

View File

@@ -38,10 +38,13 @@ export function getColumns(data: DataFrame, availableWidth: number, columnMinWid
const columns: Column[] = [];
let fieldCountWithoutWidth = data.fields.length;
for (let fieldIndex = 0; fieldIndex < data.fields.length; fieldIndex++) {
const field = data.fields[fieldIndex];
for (const [fieldIndex, field] of data.fields.entries()) {
const fieldTableOptions = (field.config.custom || {}) as TableFieldOptions;
if (fieldTableOptions.hidden) {
continue;
}
if (fieldTableOptions.width) {
availableWidth -= fieldTableOptions.width;
fieldCountWithoutWidth -= 1;