mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Add click on explore table cell to add filter to query - move query state from query row to explore container to be able to set modified queries - added TS interface for columns in table model - plumbing from table cell click to datasource - add modifyQuery to prometheus datasource - implement addFilter as addLabelToQuery with tests * Review feedback - using airbnb style for Cell declaration - fixed addLabelToQuery for complex label values
55 lines
1.0 KiB
TypeScript
55 lines
1.0 KiB
TypeScript
interface Column {
|
|
text: string;
|
|
title?: string;
|
|
type?: string;
|
|
sort?: boolean;
|
|
desc?: boolean;
|
|
filterable?: boolean;
|
|
unit?: string;
|
|
}
|
|
|
|
export default class TableModel {
|
|
columns: Column[];
|
|
rows: any[];
|
|
type: string;
|
|
columnMap: any;
|
|
|
|
constructor() {
|
|
this.columns = [];
|
|
this.columnMap = {};
|
|
this.rows = [];
|
|
this.type = 'table';
|
|
}
|
|
|
|
sort(options) {
|
|
if (options.col === null || this.columns.length <= options.col) {
|
|
return;
|
|
}
|
|
|
|
this.rows.sort(function(a, b) {
|
|
a = a[options.col];
|
|
b = b[options.col];
|
|
// Sort null or undefined seperately from comparable values
|
|
return +(a == null) - +(b == null) || +(a > b) || -(a < b);
|
|
});
|
|
|
|
if (options.desc) {
|
|
this.rows.reverse();
|
|
}
|
|
|
|
this.columns[options.col].sort = true;
|
|
this.columns[options.col].desc = options.desc;
|
|
}
|
|
|
|
addColumn(col) {
|
|
if (!this.columnMap[col.text]) {
|
|
this.columns.push(col);
|
|
this.columnMap[col.text] = col;
|
|
}
|
|
}
|
|
|
|
addRow(row) {
|
|
this.rows.push(row);
|
|
}
|
|
}
|