mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Fixes so Show context shows results again (#18675)
* Fix: Fixes so Show context shows results again Fixes: #18656 * Refactor: Removes unused import that made it thrugh the pre-commit somehow
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { FieldType, DataFrameDTO, FieldDTO } from '../types/index';
|
||||
import { DataFrameDTO, FieldDTO, FieldType } from '../types';
|
||||
import { DataFrameHelper } from './dataFrameHelper';
|
||||
|
||||
describe('dataFrameHelper', () => {
|
||||
@@ -87,3 +87,29 @@ describe('FieldCache', () => {
|
||||
expect(fieldCache.getFieldByName('null')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('reverse', () => {
|
||||
describe('when called with a DataFrame', () => {
|
||||
it('then it should reverse the order of values in all fields', () => {
|
||||
const frame: DataFrameDTO = {
|
||||
fields: [
|
||||
{ name: 'time', type: FieldType.time, values: [100, 200, 300] },
|
||||
{ name: 'name', type: FieldType.string, values: ['a', 'b', 'c'] },
|
||||
{ name: 'value', type: FieldType.number, values: [1, 2, 3] },
|
||||
],
|
||||
};
|
||||
|
||||
const helper = new DataFrameHelper(frame);
|
||||
|
||||
expect(helper.getFieldByName('time')!.values.toArray()).toEqual([100, 200, 300]);
|
||||
expect(helper.getFieldByName('name')!.values.toArray()).toEqual(['a', 'b', 'c']);
|
||||
expect(helper.getFieldByName('value')!.values.toArray()).toEqual([1, 2, 3]);
|
||||
|
||||
helper.reverse();
|
||||
|
||||
expect(helper.getFieldByName('time')!.values.toArray()).toEqual([300, 200, 100]);
|
||||
expect(helper.getFieldByName('name')!.values.toArray()).toEqual(['c', 'b', 'a']);
|
||||
expect(helper.getFieldByName('value')!.values.toArray()).toEqual([3, 2, 1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -44,10 +44,7 @@ export class DataFrameHelper implements DataFrame {
|
||||
*/
|
||||
reverse() {
|
||||
for (const f of this.fields) {
|
||||
if (isArray(f.values)) {
|
||||
const arr = f.values as any[];
|
||||
arr.reverse();
|
||||
}
|
||||
f.values.toArray().reverse();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user