mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import {
|
|
DataFrame,
|
|
Field,
|
|
FieldType,
|
|
formattedValueToString,
|
|
getDisplayProcessor,
|
|
reduceField,
|
|
fieldReducers,
|
|
} from '@grafana/data';
|
|
import { FooterItem } from '@grafana/ui/src/components/Table/types';
|
|
import { config } from 'app/core/config';
|
|
|
|
import { TableFooterCalc } from './models.gen';
|
|
|
|
export function getFooterCells(frame: DataFrame, options?: TableFooterCalc): FooterItem[] {
|
|
return frame.fields.map((field, i) => {
|
|
if (field.type !== FieldType.number) {
|
|
// show the reducer in the first column
|
|
if (i === 0 && options && options.reducer.length > 0) {
|
|
const reducer = fieldReducers.get(options.reducer[0]);
|
|
return reducer.name;
|
|
}
|
|
return undefined;
|
|
}
|
|
if (options?.fields && options.fields.length > 0) {
|
|
const f = options.fields.find((f) => f === field.name);
|
|
if (f) {
|
|
return getFormattedValue(field, options.reducer);
|
|
}
|
|
return undefined;
|
|
}
|
|
return getFormattedValue(field, options?.reducer || []);
|
|
});
|
|
}
|
|
|
|
function getFormattedValue(field: Field, reducer: string[]) {
|
|
const fmt = field.display ?? getDisplayProcessor({ field, theme: config.theme2 });
|
|
const calc = reducer[0];
|
|
const v = reduceField({ field, reducers: reducer })[calc];
|
|
return formattedValueToString(fmt(v));
|
|
}
|