mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech: ran pretttier on all typescript files
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import _ from 'lodash';
|
||||
import {GRID_COLUMN_COUNT, GRID_CELL_HEIGHT, GRID_CELL_VMARGIN,
|
||||
DEFAULT_ROW_HEIGHT, MIN_PANEL_HEIGHT, DEFAULT_PANEL_SPAN} from 'app/core/constants';
|
||||
import {PanelModel} from './panel_model';
|
||||
import {DashboardModel} from './dashboard_model';
|
||||
import _ from "lodash";
|
||||
import {
|
||||
GRID_COLUMN_COUNT,
|
||||
GRID_CELL_HEIGHT,
|
||||
GRID_CELL_VMARGIN,
|
||||
DEFAULT_ROW_HEIGHT,
|
||||
MIN_PANEL_HEIGHT,
|
||||
DEFAULT_PANEL_SPAN
|
||||
} from "app/core/constants";
|
||||
import { PanelModel } from "./panel_model";
|
||||
import { DashboardModel } from "./dashboard_model";
|
||||
|
||||
export class DashboardMigrator {
|
||||
dashboard: DashboardModel;
|
||||
@@ -32,16 +38,16 @@ export class DashboardMigrator {
|
||||
|
||||
panelUpgrades.push(function(panel) {
|
||||
// rename panel type
|
||||
if (panel.type === 'graphite') {
|
||||
panel.type = 'graph';
|
||||
if (panel.type === "graphite") {
|
||||
panel.type = "graph";
|
||||
}
|
||||
|
||||
if (panel.type !== 'graph') {
|
||||
if (panel.type !== "graph") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_.isBoolean(panel.legend)) {
|
||||
panel.legend = {show: panel.legend};
|
||||
panel.legend = { show: panel.legend };
|
||||
}
|
||||
|
||||
if (panel.grid) {
|
||||
@@ -84,11 +90,11 @@ export class DashboardMigrator {
|
||||
if (oldVersion < 4) {
|
||||
// move aliasYAxis changes
|
||||
panelUpgrades.push(function(panel) {
|
||||
if (panel.type !== 'graph') {
|
||||
if (panel.type !== "graph") {
|
||||
return;
|
||||
}
|
||||
_.each(panel.aliasYAxis, function(value, key) {
|
||||
panel.seriesOverrides = [{alias: key, yaxis: value}];
|
||||
panel.seriesOverrides = [{ alias: key, yaxis: value }];
|
||||
});
|
||||
delete panel.aliasYAxis;
|
||||
});
|
||||
@@ -96,11 +102,11 @@ export class DashboardMigrator {
|
||||
|
||||
if (oldVersion < 6) {
|
||||
// move pulldowns to new schema
|
||||
var annotations = _.find(old.pulldowns, {type: 'annotations'});
|
||||
var annotations = _.find(old.pulldowns, { type: "annotations" });
|
||||
|
||||
if (annotations) {
|
||||
this.dashboard.annotations = {
|
||||
list: annotations.annotations || [],
|
||||
list: annotations.annotations || []
|
||||
};
|
||||
}
|
||||
|
||||
@@ -110,14 +116,14 @@ export class DashboardMigrator {
|
||||
if (variable.datasource === void 0) {
|
||||
variable.datasource = null;
|
||||
}
|
||||
if (variable.type === 'filter') {
|
||||
variable.type = 'query';
|
||||
if (variable.type === "filter") {
|
||||
variable.type = "query";
|
||||
}
|
||||
if (variable.type === void 0) {
|
||||
variable.type = 'query';
|
||||
variable.type = "query";
|
||||
}
|
||||
if (variable.allFormat === void 0) {
|
||||
variable.allFormat = 'glob';
|
||||
variable.allFormat = "glob";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +141,7 @@ export class DashboardMigrator {
|
||||
if (!target.refId) {
|
||||
target.refId = this.dashboard.getNextQueryLetter(panel);
|
||||
}
|
||||
}.bind(this),
|
||||
}.bind(this)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -151,30 +157,30 @@ export class DashboardMigrator {
|
||||
} else {
|
||||
target.select = _.map(target.fields, function(field) {
|
||||
var parts = [];
|
||||
parts.push({type: 'field', params: [field.name]});
|
||||
parts.push({type: field.func, params: []});
|
||||
parts.push({ type: "field", params: [field.name] });
|
||||
parts.push({ type: field.func, params: [] });
|
||||
if (field.mathExpr) {
|
||||
parts.push({type: 'math', params: [field.mathExpr]});
|
||||
parts.push({ type: "math", params: [field.mathExpr] });
|
||||
}
|
||||
if (field.asExpr) {
|
||||
parts.push({type: 'alias', params: [field.asExpr]});
|
||||
parts.push({ type: "alias", params: [field.asExpr] });
|
||||
}
|
||||
return parts;
|
||||
});
|
||||
delete target.fields;
|
||||
_.each(target.groupBy, function(part) {
|
||||
if (part.type === 'time' && part.interval) {
|
||||
if (part.type === "time" && part.interval) {
|
||||
part.params = [part.interval];
|
||||
delete part.interval;
|
||||
}
|
||||
if (part.type === 'tag' && part.key) {
|
||||
if (part.type === "tag" && part.key) {
|
||||
part.params = [part.key];
|
||||
delete part.key;
|
||||
}
|
||||
});
|
||||
|
||||
if (target.fill) {
|
||||
target.groupBy.push({type: 'fill', params: [target.fill]});
|
||||
target.groupBy.push({ type: "fill", params: [target.fill] });
|
||||
delete target.fill;
|
||||
}
|
||||
}
|
||||
@@ -187,16 +193,16 @@ export class DashboardMigrator {
|
||||
if (oldVersion < 9) {
|
||||
// move aliasYAxis changes
|
||||
panelUpgrades.push(function(panel) {
|
||||
if (panel.type !== 'singlestat' && panel.thresholds !== '') {
|
||||
if (panel.type !== "singlestat" && panel.thresholds !== "") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (panel.thresholds) {
|
||||
var k = panel.thresholds.split(',');
|
||||
var k = panel.thresholds.split(",");
|
||||
|
||||
if (k.length >= 3) {
|
||||
k.shift();
|
||||
panel.thresholds = k.join(',');
|
||||
panel.thresholds = k.join(",");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -206,7 +212,7 @@ export class DashboardMigrator {
|
||||
if (oldVersion < 10) {
|
||||
// move aliasYAxis changes
|
||||
panelUpgrades.push(function(panel) {
|
||||
if (panel.type !== 'table') {
|
||||
if (panel.type !== "table") {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -240,7 +246,7 @@ export class DashboardMigrator {
|
||||
if (oldVersion < 12) {
|
||||
// update graph yaxes changes
|
||||
panelUpgrades.push(function(panel) {
|
||||
if (panel.type !== 'graph') {
|
||||
if (panel.type !== "graph") {
|
||||
return;
|
||||
}
|
||||
if (!panel.grid) {
|
||||
@@ -250,25 +256,25 @@ export class DashboardMigrator {
|
||||
if (!panel.yaxes) {
|
||||
panel.yaxes = [
|
||||
{
|
||||
show: panel['y-axis'],
|
||||
show: panel["y-axis"],
|
||||
min: panel.grid.leftMin,
|
||||
max: panel.grid.leftMax,
|
||||
logBase: panel.grid.leftLogBase,
|
||||
format: panel.y_formats[0],
|
||||
label: panel.leftYAxisLabel,
|
||||
label: panel.leftYAxisLabel
|
||||
},
|
||||
{
|
||||
show: panel['y-axis'],
|
||||
show: panel["y-axis"],
|
||||
min: panel.grid.rightMin,
|
||||
max: panel.grid.rightMax,
|
||||
logBase: panel.grid.rightLogBase,
|
||||
format: panel.y_formats[1],
|
||||
label: panel.rightYAxisLabel,
|
||||
},
|
||||
label: panel.rightYAxisLabel
|
||||
}
|
||||
];
|
||||
|
||||
panel.xaxis = {
|
||||
show: panel['x-axis'],
|
||||
show: panel["x-axis"]
|
||||
};
|
||||
|
||||
delete panel.grid.leftMin;
|
||||
@@ -280,8 +286,8 @@ export class DashboardMigrator {
|
||||
delete panel.y_formats;
|
||||
delete panel.leftYAxisLabel;
|
||||
delete panel.rightYAxisLabel;
|
||||
delete panel['y-axis'];
|
||||
delete panel['x-axis'];
|
||||
delete panel["y-axis"];
|
||||
delete panel["x-axis"];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -289,7 +295,7 @@ export class DashboardMigrator {
|
||||
if (oldVersion < 13) {
|
||||
// update graph yaxes changes
|
||||
panelUpgrades.push(function(panel) {
|
||||
if (panel.type !== 'graph') {
|
||||
if (panel.type !== "graph") {
|
||||
return;
|
||||
}
|
||||
if (!panel.grid) {
|
||||
@@ -305,11 +311,11 @@ export class DashboardMigrator {
|
||||
if (panel.grid.thresholdLine) {
|
||||
t1.line = true;
|
||||
t1.lineColor = panel.grid.threshold1Color;
|
||||
t1.colorMode = 'custom';
|
||||
t1.colorMode = "custom";
|
||||
} else {
|
||||
t1.fill = true;
|
||||
t1.fillColor = panel.grid.threshold1Color;
|
||||
t1.colorMode = 'custom';
|
||||
t1.colorMode = "custom";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,27 +324,27 @@ export class DashboardMigrator {
|
||||
if (panel.grid.thresholdLine) {
|
||||
t2.line = true;
|
||||
t2.lineColor = panel.grid.threshold2Color;
|
||||
t2.colorMode = 'custom';
|
||||
t2.colorMode = "custom";
|
||||
} else {
|
||||
t2.fill = true;
|
||||
t2.fillColor = panel.grid.threshold2Color;
|
||||
t2.colorMode = 'custom';
|
||||
t2.colorMode = "custom";
|
||||
}
|
||||
}
|
||||
|
||||
if (_.isNumber(t1.value)) {
|
||||
if (_.isNumber(t2.value)) {
|
||||
if (t1.value > t2.value) {
|
||||
t1.op = t2.op = 'lt';
|
||||
t1.op = t2.op = "lt";
|
||||
panel.thresholds.push(t1);
|
||||
panel.thresholds.push(t2);
|
||||
} else {
|
||||
t1.op = t2.op = 'gt';
|
||||
t1.op = t2.op = "gt";
|
||||
panel.thresholds.push(t1);
|
||||
panel.thresholds.push(t2);
|
||||
}
|
||||
} else {
|
||||
t1.op = 'gt';
|
||||
t1.op = "gt";
|
||||
panel.thresholds.push(t1);
|
||||
}
|
||||
}
|
||||
@@ -374,9 +380,13 @@ export class DashboardMigrator {
|
||||
let yPos = 0;
|
||||
let widthFactor = GRID_COLUMN_COUNT / 12;
|
||||
|
||||
const maxPanelId = _.max(_.flattenDeep(_.map(old.rows, (row) => {
|
||||
return _.map(row.panels, 'id');
|
||||
})));
|
||||
const maxPanelId = _.max(
|
||||
_.flattenDeep(
|
||||
_.map(old.rows, row => {
|
||||
return _.map(row.panels, "id");
|
||||
})
|
||||
)
|
||||
);
|
||||
let nextRowId = maxPanelId + 1;
|
||||
|
||||
if (!old.rows) {
|
||||
@@ -384,7 +394,10 @@ export class DashboardMigrator {
|
||||
}
|
||||
|
||||
// Add special "row" panels if even one row is collapsed, repeated or has visible title
|
||||
const showRows = _.some(old.rows, (row) => row.collapse || row.showTitle || row.repeat);
|
||||
const showRows = _.some(
|
||||
old.rows,
|
||||
row => row.collapse || row.showTitle || row.repeat
|
||||
);
|
||||
|
||||
for (let row of old.rows) {
|
||||
if (row.repeatIteration) {
|
||||
@@ -399,12 +412,17 @@ export class DashboardMigrator {
|
||||
if (showRows) {
|
||||
// add special row panel
|
||||
rowPanel.id = nextRowId;
|
||||
rowPanel.type = 'row';
|
||||
rowPanel.type = "row";
|
||||
rowPanel.title = row.title;
|
||||
rowPanel.collapsed = row.collapse;
|
||||
rowPanel.repeat = row.repeat;
|
||||
rowPanel.panels = [];
|
||||
rowPanel.gridPos = {x: 0, y: yPos, w: GRID_COLUMN_COUNT, h: rowGridHeight};
|
||||
rowPanel.gridPos = {
|
||||
x: 0,
|
||||
y: yPos,
|
||||
w: GRID_COLUMN_COUNT,
|
||||
h: rowGridHeight
|
||||
};
|
||||
rowPanelModel = new PanelModel(rowPanel);
|
||||
nextRowId++;
|
||||
yPos++;
|
||||
@@ -415,11 +433,18 @@ export class DashboardMigrator {
|
||||
for (let panel of row.panels) {
|
||||
panel.span = panel.span || DEFAULT_PANEL_SPAN;
|
||||
const panelWidth = Math.floor(panel.span) * widthFactor;
|
||||
const panelHeight = panel.height ? getGridHeight(panel.height) : rowGridHeight;
|
||||
const panelHeight = panel.height
|
||||
? getGridHeight(panel.height)
|
||||
: rowGridHeight;
|
||||
|
||||
let panelPos = rowArea.getPanelPosition(panelHeight, panelWidth);
|
||||
yPos = rowArea.yPos;
|
||||
panel.gridPos = {x: panelPos.x, y: yPos + panelPos.y, w: panelWidth, h: panelHeight};
|
||||
panel.gridPos = {
|
||||
x: panelPos.x,
|
||||
y: yPos + panelPos.y,
|
||||
w: panelWidth,
|
||||
h: panelHeight
|
||||
};
|
||||
rowArea.addPanel(panel.gridPos);
|
||||
|
||||
delete panel.span;
|
||||
@@ -444,7 +469,7 @@ export class DashboardMigrator {
|
||||
|
||||
function getGridHeight(height) {
|
||||
if (_.isString(height)) {
|
||||
height = parseInt(height.replace('px', ''), 10);
|
||||
height = parseInt(height.replace("px", ""), 10);
|
||||
}
|
||||
|
||||
if (height < MIN_PANEL_HEIGHT) {
|
||||
@@ -503,7 +528,7 @@ class RowArea {
|
||||
if (endPlace === undefined) {
|
||||
endPlace = i;
|
||||
} else {
|
||||
if (i < this.area.length - 1 && this.area[i] <= this.area[i+1]) {
|
||||
if (i < this.area.length - 1 && this.area[i] <= this.area[i + 1]) {
|
||||
startPlace = i;
|
||||
} else {
|
||||
break;
|
||||
@@ -514,7 +539,11 @@ class RowArea {
|
||||
}
|
||||
}
|
||||
|
||||
if (startPlace !== undefined && endPlace !== undefined && endPlace - startPlace >= panelWidth - 1) {
|
||||
if (
|
||||
startPlace !== undefined &&
|
||||
endPlace !== undefined &&
|
||||
endPlace - startPlace >= panelWidth - 1
|
||||
) {
|
||||
const yPos = _.max(this.area.slice(startPlace));
|
||||
place = {
|
||||
x: startPlace,
|
||||
|
||||
Reference in New Issue
Block a user