Chore: Clenaup unused exports/modules in explore (#41072)

* Chore: remove unused files

* Chore: Remove unused explore  extports and files
This commit is contained in:
Giordano Ricci 2021-10-29 11:34:48 +01:00 committed by GitHub
parent d069f0900e
commit e375558fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 8 additions and 344 deletions

View File

@ -31,7 +31,7 @@ interface Props extends OwnProps, ConnectedProps<typeof connector> {}
* This component is responsible for handling initialization of an Explore pane and triggering synchronization
* of state based on URL changes and preventing any infinite loops.
*/
export class ExplorePaneContainerUnconnected extends React.PureComponent<Props> {
class ExplorePaneContainerUnconnected extends React.PureComponent<Props> {
el: any;
exploreEvents: EventBusExtended;

View File

@ -29,7 +29,7 @@ interface OwnProps {
type Props = OwnProps & ConnectedProps<typeof connector>;
export class UnConnectedExploreToolbar extends PureComponent<Props> {
class UnConnectedExploreToolbar extends PureComponent<Props> {
onChangeDatasource = async (dsSettings: DataSourceInstanceSettings) => {
this.props.changeDatasource(this.props.exploreId, dsSettings.uid, { importQueries: true });
};

View File

@ -1,9 +0,0 @@
import React from 'react';
export default function JSONViewer({ value }: any) {
return (
<div>
<pre>{JSON.stringify(value, undefined, 2)}</pre>
</div>
);
}

View File

@ -86,7 +86,7 @@ interface State {
forceEscape: boolean;
}
export class UnthemedLogs extends PureComponent<Props, State> {
class UnthemedLogs extends PureComponent<Props, State> {
flipOrderTimer?: number;
cancelFlippingTimer?: number;
topLogsRef = createRef<HTMLDivElement>();

View File

@ -36,7 +36,7 @@ interface LogsContainerProps extends PropsFromRedux {
onStopScanning: () => void;
}
export class LogsContainer extends PureComponent<LogsContainerProps> {
class LogsContainer extends PureComponent<LogsContainerProps> {
onChangeTime = (absoluteRange: AbsoluteTimeRange) => {
const { exploreId, updateTimeRange } = this.props;
updateTimeRange({ exploreId, absoluteRange });

View File

@ -38,7 +38,7 @@ export interface MetaItemProps {
value: string | JSX.Element;
}
export const MetaInfoItem = memo(function MetaInfoItem(props: MetaItemProps) {
const MetaInfoItem = memo(function MetaInfoItem(props: MetaItemProps) {
const style = useStyles2(getStyles);
const { label, value } = props;
@ -50,7 +50,7 @@ export const MetaInfoItem = memo(function MetaInfoItem(props: MetaItemProps) {
);
});
export interface MetaInfoTextProps {
interface MetaInfoTextProps {
metaItems: MetaItemProps[];
}
@ -66,5 +66,3 @@ export const MetaInfoText = memo(function MetaInfoText(props: MetaInfoTextProps)
</div>
);
});
export default MetaInfoText;

View File

@ -39,7 +39,7 @@ describe('NodeGraphContainer', () => {
const emptyFrame = new MutableDataFrame();
export const nodes = new MutableDataFrame({
const nodes = new MutableDataFrame({
fields: toFields([
['id', ['3fa414edcef6ad90']],
['title', ['tempo-querier']],
@ -50,7 +50,7 @@ export const nodes = new MutableDataFrame({
]),
});
export function toFields(fields: Array<[string, any[]]>) {
function toFields(fields: Array<[string, any[]]>) {
return fields.map(([name, values]) => {
return { name, values };
});

View File

@ -1,147 +0,0 @@
import { colors } from '@grafana/ui';
import {
getFlotPairs,
getDisplayProcessor,
NullValueMode,
reduceField,
FieldType,
DisplayValue,
GraphSeriesXY,
getTimeField,
DataFrame,
getSeriesTimeStep,
TimeZone,
hasMsResolution,
systemDateFormats,
FieldColor,
FieldColorModeId,
FieldConfigSource,
getFieldDisplayName,
} from '@grafana/data';
import { config } from 'app/core/config';
import { SeriesOptions, GraphOptions, GraphLegendEditorLegendOptions } from './types';
export const getGraphSeriesModel = (
dataFrames: DataFrame[],
timeZone: TimeZone,
seriesOptions: SeriesOptions,
graphOptions: GraphOptions,
legendOptions: GraphLegendEditorLegendOptions,
fieldOptions?: FieldConfigSource
) => {
const graphs: GraphSeriesXY[] = [];
const displayProcessor = getDisplayProcessor({
field: {
config: {
unit: fieldOptions?.defaults?.unit,
decimals: legendOptions.decimals,
},
},
theme: config.theme2,
timeZone,
});
let fieldColumnIndex = -1;
for (const series of dataFrames) {
const { timeField } = getTimeField(series);
if (!timeField) {
continue;
}
for (const field of series.fields) {
if (field.type !== FieldType.number) {
continue;
}
// Storing index of series field for future inspection
fieldColumnIndex++;
// Use external calculator just to make sure it works :)
const points = getFlotPairs({
xField: timeField,
yField: field,
nullValueMode: NullValueMode.Null,
});
if (points.length > 0) {
const seriesStats = reduceField({ field, reducers: legendOptions.stats || [] });
let statsDisplayValues: DisplayValue[] = [];
if (legendOptions.stats) {
statsDisplayValues = legendOptions.stats.map<DisplayValue>((stat) => {
const statDisplayValue = displayProcessor(seriesStats[stat]);
return {
...statDisplayValue,
title: stat,
};
});
}
let color: FieldColor;
if (seriesOptions[field.name] && seriesOptions[field.name].color) {
// Case when panel has settings provided via SeriesOptions, i.e. graph panel
color = {
mode: FieldColorModeId.Fixed,
fixedColor: seriesOptions[field.name].color,
};
} else if (field.config && field.config.color) {
// Case when color settings are set on field, i.e. Explore logs histogram (see makeSeriesForLogs)
color = field.config.color;
} else {
color = {
mode: FieldColorModeId.Fixed,
fixedColor: colors[graphs.length % colors.length],
};
}
field.config = fieldOptions
? {
...field.config,
unit: fieldOptions.defaults.unit,
decimals: fieldOptions.defaults.decimals,
color,
}
: { ...field.config, color };
field.display = getDisplayProcessor({ field, timeZone, theme: config.theme2 });
// Time step is used to determine bars width when graph is rendered as bar chart
const timeStep = getSeriesTimeStep(timeField);
const useMsDateFormat = hasMsResolution(timeField);
timeField.display = getDisplayProcessor({
timeZone,
field: {
...timeField,
type: timeField.type,
config: {
unit: systemDateFormats.getTimeFieldUnit(useMsDateFormat),
},
},
theme: config.theme2,
});
graphs.push({
label: getFieldDisplayName(field, series, dataFrames),
data: points,
color: field.config.color?.fixedColor,
info: statsDisplayValues,
isVisible: true,
yAxis: {
index: (seriesOptions[field.name] && seriesOptions[field.name].yAxis) || 1,
},
// This index is used later on to retrieve appropriate series/time for X and Y axes
seriesIndex: fieldColumnIndex,
timeField: { ...timeField },
valueField: { ...field },
timeStep,
});
}
}
}
return graphs;
};

View File

@ -1,48 +0,0 @@
import { VizTooltipOptions, TooltipDisplayMode, LegendDisplayMode, LegendPlacement } from '@grafana/schema';
import { YAxis } from '@grafana/data';
export interface SeriesOptions {
color?: string;
yAxis?: YAxis;
[key: string]: any;
}
export interface GraphOptions {
showBars: boolean;
showLines: boolean;
showPoints: boolean;
}
export interface Options {
graph: GraphOptions;
legend: {
displayMode: LegendDisplayMode;
placement: LegendPlacement;
};
series: {
[alias: string]: SeriesOptions;
};
tooltipOptions: VizTooltipOptions;
}
export const defaults: Options = {
graph: {
showBars: false,
showLines: true,
showPoints: false,
},
legend: {
displayMode: LegendDisplayMode.List,
placement: 'bottom',
},
series: {},
tooltipOptions: { mode: TooltipDisplayMode.Single },
};
export interface GraphLegendEditorLegendOptions {
displayMode: LegendDisplayMode;
placement: LegendPlacement;
stats?: string[];
decimals?: number;
sortBy?: string;
sortDesc?: boolean;
}

View File

@ -1,130 +0,0 @@
import React from 'react';
import Prism from 'prismjs';
import { Decoration } from 'slate';
import { Editor } from '@grafana/slate-react';
const TOKEN_MARK = 'prism-token';
export function setPrismTokens(language: string, field: string | number, values: any, alias = 'variable') {
Prism.languages[language][field] = {
alias,
pattern: new RegExp(`(?:^|\\s)(${values.join('|')})(?:$|\\s)`),
};
}
/**
* Code-highlighting plugin based on Prism and
* https://github.com/ianstormtaylor/slate/blob/master/examples/code-highlighting/index.js
*
* (Adapted to handle nested grammar definitions.)
*/
export default function PrismPlugin({ definition, language }: { definition: any; language: string }) {
if (definition) {
// Don't override exising modified definitions
Prism.languages[language] = Prism.languages[language] || definition;
}
return {
/**
* Render a Slate mark with appropriate CSS class names
*
* @param {Object} props
* @returns {Element}
*/
renderDecoration(props: any, editor: Editor, next: () => any): JSX.Element {
const { children, decoration } = props;
// Only apply spans to marks identified by this plugin
if (decoration.type !== TOKEN_MARK) {
return next();
}
const className = `token ${decoration.data.get('types')}`;
return <span className={className}>{children}</span>;
},
/**
* Decorate code blocks with Prism.js highlighting.
*
* @param {Node} node
* @returns {Array}
*/
decorateNode(node: any, editor: Editor, next: () => any): any[] {
if (node.type !== 'paragraph') {
return [];
}
const texts = node.getTexts().toArray();
const tstring = texts.map((t: { text: any }) => t.text).join('\n');
const grammar = Prism.languages[language];
const tokens = Prism.tokenize(tstring, grammar);
const decorations: Decoration[] = [];
let startText = texts.shift();
let endText = startText;
let startOffset = 0;
let endOffset = 0;
let start = 0;
function processToken(token: any, acc?: string) {
// Accumulate token types down the tree
const types = `${acc || ''} ${token.type || ''} ${token.alias || ''}`;
// Add mark for token node
if (typeof token === 'string' || typeof token.content === 'string') {
startText = endText;
startOffset = endOffset;
const content = typeof token === 'string' ? token : token.content;
const newlines = content.split('\n').length - 1;
const length = content.length - newlines;
const end = start + length;
let available = startText.text.length - startOffset;
let remaining = length;
endOffset = startOffset + remaining;
while (available < remaining) {
endText = texts.shift();
remaining = length - available;
available = endText.text.length;
endOffset = remaining;
}
// Inject marks from up the tree (acc) as well
if (typeof token !== 'string' || acc) {
const range = node.createDecoration({
anchor: {
key: startText.key,
offset: startOffset,
},
focus: {
key: endText.key,
offset: endOffset,
},
type: TOKEN_MARK,
data: { types },
});
decorations.push(range);
}
start = end;
} else if (token.content && token.content.length) {
// Tokens can be nested
for (const subToken of token.content) {
processToken(subToken, types);
}
}
}
// Process top-level tokens
for (const token of tokens) {
processToken(token);
}
return decorations;
},
};
}