2023-01-05 11:55:55 -06:00
|
|
|
import React from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-04-12 11:21:05 -05:00
|
|
|
import { DataFrame, DataTransformerID, getFrameDisplayName, SelectableValue } from '@grafana/data';
|
2023-01-06 17:14:20 -06:00
|
|
|
import { Field, HorizontalGroup, Select, Switch, VerticalGroup, useStyles2 } from '@grafana/ui';
|
2021-04-12 11:21:05 -05:00
|
|
|
import { QueryOperationRow } from 'app/core/components/QueryOperationRow/QueryOperationRow';
|
2022-10-06 10:34:04 -05:00
|
|
|
import { t } from 'app/core/internationalization';
|
2021-04-12 11:21:05 -05:00
|
|
|
import { PanelModel } from 'app/features/dashboard/state';
|
|
|
|
import { DetailText } from 'app/features/inspector/DetailText';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { GetDataOptions } from 'app/features/query/state/PanelQueryRunner';
|
|
|
|
|
2023-01-06 17:14:20 -06:00
|
|
|
import { getPanelInspectorStyles2 } from './styles';
|
2021-04-12 11:21:05 -05:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
options: GetDataOptions;
|
|
|
|
dataFrames: DataFrame[];
|
|
|
|
transformId: DataTransformerID;
|
|
|
|
transformationOptions: Array<SelectableValue<DataTransformerID>>;
|
|
|
|
selectedDataFrame: number | DataTransformerID;
|
|
|
|
downloadForExcel: boolean;
|
|
|
|
onDataFrameChange: (item: SelectableValue<DataTransformerID | number>) => void;
|
|
|
|
toggleDownloadForExcel: () => void;
|
|
|
|
data?: DataFrame[];
|
|
|
|
panel?: PanelModel;
|
|
|
|
onOptionsChange?: (options: GetDataOptions) => void;
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:55:55 -06:00
|
|
|
export const InspectDataOptions = ({
|
2021-04-12 11:21:05 -05:00
|
|
|
options,
|
|
|
|
onOptionsChange,
|
|
|
|
panel,
|
|
|
|
data,
|
|
|
|
dataFrames,
|
|
|
|
transformId,
|
|
|
|
transformationOptions,
|
|
|
|
selectedDataFrame,
|
|
|
|
onDataFrameChange,
|
|
|
|
downloadForExcel,
|
|
|
|
toggleDownloadForExcel,
|
2023-01-05 11:55:55 -06:00
|
|
|
}: Props) => {
|
2023-01-06 17:14:20 -06:00
|
|
|
const styles = useStyles2(getPanelInspectorStyles2);
|
2021-04-12 11:21:05 -05:00
|
|
|
|
|
|
|
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;
|
2022-08-23 12:14:03 -05:00
|
|
|
if (selectedDataFrame === DataTransformerID.joinByField) {
|
2021-04-12 11:21:05 -05:00
|
|
|
dataSelect = data!;
|
|
|
|
}
|
|
|
|
|
|
|
|
const choices = dataSelect.map((frame, index) => {
|
|
|
|
return {
|
|
|
|
value: index,
|
|
|
|
label: `${getFrameDisplayName(frame)} (${index})`,
|
|
|
|
} as SelectableValue<number>;
|
|
|
|
});
|
|
|
|
|
|
|
|
const selectableOptions = [...transformationOptions, ...choices];
|
|
|
|
|
|
|
|
function getActiveString() {
|
|
|
|
let activeString = '';
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return activeString;
|
|
|
|
}
|
|
|
|
|
|
|
|
const parts: string[] = [];
|
|
|
|
|
2022-08-23 12:14:03 -05:00
|
|
|
if (selectedDataFrame === DataTransformerID.joinByField) {
|
2022-10-06 10:34:04 -05:00
|
|
|
parts.push(t('dashboard.inspect-data.series-to-columns', 'Series joined by time'));
|
2021-04-12 11:21:05 -05:00
|
|
|
} else if (data.length > 1) {
|
|
|
|
parts.push(getFrameDisplayName(data[selectedDataFrame as number]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.withTransforms || options.withFieldConfig) {
|
|
|
|
if (options.withTransforms) {
|
2022-10-06 10:34:04 -05:00
|
|
|
parts.push(t('dashboard.inspect-data.panel-transforms', 'Panel transforms'));
|
2021-04-12 11:21:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.withTransforms && options.withFieldConfig) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.withFieldConfig) {
|
2022-10-06 10:34:04 -05:00
|
|
|
parts.push(t('dashboard.inspect-data.formatted', 'Formatted data'));
|
2021-04-12 11:21:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (downloadForExcel) {
|
2022-10-06 10:34:04 -05:00
|
|
|
parts.push(t('dashboard.inspect-data.excel-header', 'Excel header'));
|
2021-04-12 11:21:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return parts.join(', ');
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.dataDisplayOptions}>
|
|
|
|
<QueryOperationRow
|
|
|
|
id="Data options"
|
|
|
|
index={0}
|
2022-10-06 10:34:04 -05:00
|
|
|
title={t('dashboard.inspect-data.data-options', 'Data options')}
|
2021-04-12 11:21:05 -05:00
|
|
|
headerElement={<DetailText>{getActiveString()}</DetailText>}
|
|
|
|
isOpen={false}
|
|
|
|
>
|
|
|
|
<div className={styles.options} data-testid="dataOptions">
|
|
|
|
<VerticalGroup spacing="none">
|
|
|
|
{data!.length > 1 && (
|
2022-10-06 10:34:04 -05:00
|
|
|
<Field label={t('dashboard.inspect-data.dataframe-label', 'Show data frame')}>
|
2021-04-12 11:21:05 -05:00
|
|
|
<Select
|
|
|
|
options={selectableOptions}
|
|
|
|
value={selectedDataFrame}
|
|
|
|
onChange={onDataFrameChange}
|
|
|
|
width={30}
|
2022-10-06 10:34:04 -05:00
|
|
|
aria-label={t('dashboard.inspect-data.dataframe-aria-label', 'Select dataframe')}
|
2021-04-12 11:21:05 -05:00
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<HorizontalGroup>
|
|
|
|
{showPanelTransformationsOption && onOptionsChange && (
|
|
|
|
<Field
|
2022-10-06 10:34:04 -05:00
|
|
|
label={t('dashboard.inspect-data.transformations-label', 'Apply panel transformations')}
|
|
|
|
description={t(
|
|
|
|
'dashboard.inspect-data.transformations-description',
|
|
|
|
'Table data is displayed with transformations defined in the panel Transform tab.'
|
|
|
|
)}
|
2021-04-12 11:21:05 -05:00
|
|
|
>
|
|
|
|
<Switch
|
|
|
|
value={!!options.withTransforms}
|
|
|
|
onChange={() => onOptionsChange({ ...options, withTransforms: !options.withTransforms })}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
)}
|
|
|
|
{showFieldConfigsOption && onOptionsChange && (
|
|
|
|
<Field
|
2022-10-06 10:34:04 -05:00
|
|
|
label={t('dashboard.inspect-data.formatted-data-label', 'Formatted data')}
|
|
|
|
description={t(
|
|
|
|
'dashboard.inspect-data.formatted-data-description',
|
|
|
|
'Table data is formatted with options defined in the Field and Override tabs.'
|
|
|
|
)}
|
2021-04-12 11:21:05 -05:00
|
|
|
>
|
|
|
|
<Switch
|
2021-11-01 09:45:23 -05:00
|
|
|
id="formatted-data-toggle"
|
2021-04-12 11:21:05 -05:00
|
|
|
value={!!options.withFieldConfig}
|
|
|
|
onChange={() => onOptionsChange({ ...options, withFieldConfig: !options.withFieldConfig })}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
)}
|
2022-07-15 08:38:14 -05:00
|
|
|
<Field
|
2022-10-06 10:34:04 -05:00
|
|
|
label={t('dashboard.inspect-data.download-excel-label', 'Download for Excel')}
|
|
|
|
description={t(
|
|
|
|
'dashboard.inspect-data.download-excel-description',
|
|
|
|
'Adds header to CSV for use with Excel'
|
|
|
|
)}
|
2022-07-15 08:38:14 -05:00
|
|
|
>
|
2021-11-01 09:45:23 -05:00
|
|
|
<Switch id="excel-toggle" value={downloadForExcel} onChange={toggleDownloadForExcel} />
|
2021-04-12 11:21:05 -05:00
|
|
|
</Field>
|
|
|
|
</HorizontalGroup>
|
|
|
|
</VerticalGroup>
|
|
|
|
</div>
|
|
|
|
</QueryOperationRow>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|