From 0a56527ed9d7c80ffb7300cfecfc960667c9e2f6 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Mon, 12 Apr 2021 18:21:05 +0200 Subject: [PATCH] Inspector: Download logs for manual processing (#32764) * Add download logs functionality * Refactor InspectDataTab to be smaller * Add test * Remove console log * Add metedata info * Add metedata info --- .../features/inspector/InspectDataOptions.tsx | 148 +++++++++++++ .../inspector/InspectDataTab.test.tsx | 24 ++- .../app/features/inspector/InspectDataTab.tsx | 194 ++++++------------ 3 files changed, 235 insertions(+), 131 deletions(-) create mode 100644 public/app/features/inspector/InspectDataOptions.tsx diff --git a/public/app/features/inspector/InspectDataOptions.tsx b/public/app/features/inspector/InspectDataOptions.tsx new file mode 100644 index 00000000000..e0997cce6b0 --- /dev/null +++ b/public/app/features/inspector/InspectDataOptions.tsx @@ -0,0 +1,148 @@ +import React, { FC } from 'react'; +import { DataFrame, DataTransformerID, getFrameDisplayName, SelectableValue } from '@grafana/data'; +import { Field, HorizontalGroup, Select, Switch, VerticalGroup } from '@grafana/ui'; +import { getPanelInspectorStyles } from './styles'; +import { GetDataOptions } from 'app/features/query/state/PanelQueryRunner'; +import { QueryOperationRow } from 'app/core/components/QueryOperationRow/QueryOperationRow'; +import { PanelModel } from 'app/features/dashboard/state'; +import { DetailText } from 'app/features/inspector/DetailText'; + +interface Props { + options: GetDataOptions; + dataFrames: DataFrame[]; + transformId: DataTransformerID; + transformationOptions: Array>; + selectedDataFrame: number | DataTransformerID; + downloadForExcel: boolean; + onDataFrameChange: (item: SelectableValue) => void; + toggleDownloadForExcel: () => void; + data?: DataFrame[]; + panel?: PanelModel; + onOptionsChange?: (options: GetDataOptions) => void; +} + +export const InspectDataOptions: FC = ({ + options, + onOptionsChange, + panel, + data, + dataFrames, + transformId, + transformationOptions, + selectedDataFrame, + onDataFrameChange, + downloadForExcel, + toggleDownloadForExcel, +}) => { + const styles = getPanelInspectorStyles(); + + const panelTransformations = panel?.getTransformations(); + const showPanelTransformationsOption = + Boolean(panelTransformations?.length) && (transformId as any) !== 'join by time'; + const showFieldConfigsOption = panel && !panel.plugin?.fieldConfigRegistry.isEmpty(); + + let dataSelect = dataFrames; + if (selectedDataFrame === DataTransformerID.seriesToColumns) { + dataSelect = data!; + } + + const choices = dataSelect.map((frame, index) => { + return { + value: index, + label: `${getFrameDisplayName(frame)} (${index})`, + } as SelectableValue; + }); + + const selectableOptions = [...transformationOptions, ...choices]; + + function getActiveString() { + let activeString = ''; + + if (!data) { + return activeString; + } + + const parts: string[] = []; + + if (selectedDataFrame === DataTransformerID.seriesToColumns) { + parts.push('Series joined by time'); + } else if (data.length > 1) { + parts.push(getFrameDisplayName(data[selectedDataFrame as number])); + } + + if (options.withTransforms || options.withFieldConfig) { + if (options.withTransforms) { + parts.push('Panel transforms'); + } + + if (options.withTransforms && options.withFieldConfig) { + } + + if (options.withFieldConfig) { + parts.push('Formatted data'); + } + } + + if (downloadForExcel) { + parts.push('Excel header'); + } + + return parts.join(', '); + } + + return ( +
+ {getActiveString()}} + isOpen={false} + > +
+ + {data!.length > 1 && ( + + - - )} - - - {showPanelTransformationsOption && onOptionsChange && ( - - onOptionsChange({ ...options, withTransforms: !options.withTransforms })} - /> - - )} - {showFieldConfigsOption && onOptionsChange && ( - - onOptionsChange({ ...options, withFieldConfig: !options.withFieldConfig })} - /> - - )} - - this.setState({ downloadForExcel: !this.state.downloadForExcel })} - /> - - - -
-
- ); - } - render() { - const { isLoading } = this.props; - const { dataFrameIndex } = this.state; + const { isLoading, options, data, panel, onOptionsChange } = this.props; + const { dataFrameIndex, transformId, transformationOptions, selectedDataFrame, downloadForExcel } = this.state; const styles = getPanelInspectorStyles(); if (isLoading) { @@ -269,12 +178,25 @@ export class InspectDataTab extends PureComponent { // let's make sure we don't try to render a frame that doesn't exists const index = !dataFrames[dataFrameIndex] ? 0 : dataFrameIndex; - const data = dataFrames[index]; + const dataFrame = dataFrames[index]; + const hasLogs = dataFrames.some((df) => df?.meta?.preferredVisualisationType === 'logs'); return (
-
{this.renderDataOptions(dataFrames)}
+ + {hasLogs && ( + + )}
@@ -294,7 +228,7 @@ export class InspectDataTab extends PureComponent { return (
- +
); }}