mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Minor refactoring of stats picker / shared singlestat code
This commit is contained in:
parent
e0ecbc4c68
commit
beba9676f6
@ -73,15 +73,8 @@ export class StatsPicker extends PureComponent<Props> {
|
||||
};
|
||||
});
|
||||
|
||||
const value: SelectOptionItem[] = [];
|
||||
stats.forEach(s => {
|
||||
const o = options.find(v => v.value === s);
|
||||
if (o) {
|
||||
value.push(o);
|
||||
}
|
||||
});
|
||||
const value: SelectOptionItem[] = options.filter(option => stats.find(stat => option.value === stat));
|
||||
|
||||
//getStatsCalculators(stats);
|
||||
return (
|
||||
<Select
|
||||
width={width}
|
||||
|
@ -35,7 +35,6 @@ export interface StatCalculatorInfo {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
|
||||
alias?: string; // optional secondary key. 'avg' vs 'mean', 'total' vs 'sum'
|
||||
|
||||
// Internal details
|
||||
@ -54,6 +53,7 @@ export function getStatsCalculators(ids?: string[]): StatCalculatorInfo[] {
|
||||
}
|
||||
return listOfStats;
|
||||
}
|
||||
|
||||
return ids.reduce((list, id) => {
|
||||
const stat = getById(id);
|
||||
if (stat) {
|
||||
@ -123,6 +123,7 @@ export function calculateStats(options: CalculateStatsOptions): ColumnStats {
|
||||
interface TableStatIndex {
|
||||
[id: string]: StatCalculatorInfo;
|
||||
}
|
||||
|
||||
const listOfStats: StatCalculatorInfo[] = [];
|
||||
const index: TableStatIndex = {};
|
||||
let hasBuiltIndex = false;
|
||||
@ -166,7 +167,7 @@ function getById(id: string): StatCalculatorInfo | undefined {
|
||||
{
|
||||
id: StatID.delta,
|
||||
name: 'Delta',
|
||||
description: 'Cumulative change in value (??? help not really sure ???)',
|
||||
description: 'Cumulative change in value',
|
||||
standard: true,
|
||||
},
|
||||
{
|
||||
@ -217,6 +218,7 @@ function getById(id: string): StatCalculatorInfo | undefined {
|
||||
});
|
||||
hasBuiltIndex = true;
|
||||
}
|
||||
|
||||
return index[id];
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ export const getSingleStatValues = (props: PanelProps<SingleStatBaseOptions>): D
|
||||
if (column.type === ColumnType.number) {
|
||||
const stats = calculateStats({
|
||||
table,
|
||||
columnIndex: i, // Hardcoded for now!
|
||||
columnIndex: i,
|
||||
stats: [stat], // The stats to calculate
|
||||
nullValueMode: NullValueMode.Null,
|
||||
});
|
||||
@ -49,7 +49,10 @@ export const getSingleStatValues = (props: PanelProps<SingleStatBaseOptions>): D
|
||||
}
|
||||
|
||||
if (values.length === 0) {
|
||||
throw { message: 'Could not find numeric data' };
|
||||
values.push({
|
||||
numeric: 0,
|
||||
text: 'No data',
|
||||
});
|
||||
}
|
||||
|
||||
return values;
|
||||
|
@ -14,11 +14,11 @@ export const singleStatBaseOptionsCheck = (
|
||||
prevOptions?: any
|
||||
) => {
|
||||
if (prevOptions) {
|
||||
optionsToKeep.forEach(v => {
|
||||
if (prevOptions.hasOwnProperty(v)) {
|
||||
options[v] = cloneDeep(prevOptions.display);
|
||||
for (const otk of optionsToKeep) {
|
||||
if (prevOptions.hasOwnProperty(otk)) {
|
||||
options[otk] = cloneDeep(prevOptions[otk]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 6.1 renamed some stats, This makes sure they are up to date
|
||||
|
Loading…
Reference in New Issue
Block a user