mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Table: Fix migrations from old angular table for cell color modes (#65760)
* Table: Fix migrations from old angular table * Update defaults
This commit is contained in:
parent
c4c406aacd
commit
3843c73162
@ -1,142 +1,5 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Table Migrations migrates styles to field config overrides and defaults 1`] = `
|
|
||||||
{
|
|
||||||
"fieldConfig": {
|
|
||||||
"defaults": {
|
|
||||||
"custom": {
|
|
||||||
"align": "right",
|
|
||||||
"displayMode": undefined,
|
|
||||||
},
|
|
||||||
"decimals": 2,
|
|
||||||
"displayName": "",
|
|
||||||
"unit": "short",
|
|
||||||
},
|
|
||||||
"overrides": [
|
|
||||||
{
|
|
||||||
"matcher": {
|
|
||||||
"id": "byName",
|
|
||||||
"options": "Time",
|
|
||||||
},
|
|
||||||
"properties": [
|
|
||||||
{
|
|
||||||
"id": "displayName",
|
|
||||||
"value": "Time",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "unit",
|
|
||||||
"value": "time: YYYY-MM-DD HH:mm:ss",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "custom.align",
|
|
||||||
"value": null,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matcher": {
|
|
||||||
"id": "byName",
|
|
||||||
"options": "ColorCell",
|
|
||||||
},
|
|
||||||
"properties": [
|
|
||||||
{
|
|
||||||
"id": "unit",
|
|
||||||
"value": "currencyUSD",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "decimals",
|
|
||||||
"value": 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "custom.displayMode",
|
|
||||||
"value": "color-background",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "custom.align",
|
|
||||||
"value": "left",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "thresholds",
|
|
||||||
"value": {
|
|
||||||
"mode": "absolute",
|
|
||||||
"steps": [
|
|
||||||
{
|
|
||||||
"color": "rgba(245, 54, 54, 0.9)",
|
|
||||||
"value": -Infinity,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"color": "rgba(237, 129, 40, 0.89)",
|
|
||||||
"value": 5,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"color": "rgba(50, 172, 45, 0.97)",
|
|
||||||
"value": 10,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matcher": {
|
|
||||||
"id": "byName",
|
|
||||||
"options": "ColorValue",
|
|
||||||
},
|
|
||||||
"properties": [
|
|
||||||
{
|
|
||||||
"id": "unit",
|
|
||||||
"value": "Bps",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "decimals",
|
|
||||||
"value": 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "links",
|
|
||||||
"value": [
|
|
||||||
{
|
|
||||||
"targetBlank": true,
|
|
||||||
"title": "",
|
|
||||||
"url": "http://www.grafana.com",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "custom.displayMode",
|
|
||||||
"value": "color-text",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "custom.align",
|
|
||||||
"value": null,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "thresholds",
|
|
||||||
"value": {
|
|
||||||
"mode": "absolute",
|
|
||||||
"steps": [
|
|
||||||
{
|
|
||||||
"color": "rgba(245, 54, 54, 0.9)",
|
|
||||||
"value": -Infinity,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"color": "rgba(237, 129, 40, 0.89)",
|
|
||||||
"value": 5,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"color": "rgba(50, 172, 45, 0.97)",
|
|
||||||
"value": 10,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
"transformations": [],
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Table Migrations migrates transform out to core transforms 1`] = `
|
exports[`Table Migrations migrates transform out to core transforms 1`] = `
|
||||||
{
|
{
|
||||||
"fieldConfig": {
|
"fieldConfig": {
|
||||||
|
@ -128,6 +128,144 @@ describe('Table Migrations', () => {
|
|||||||
};
|
};
|
||||||
const panel = {} as PanelModel;
|
const panel = {} as PanelModel;
|
||||||
tablePanelChangedHandler(panel, 'table-old', oldStyles);
|
tablePanelChangedHandler(panel, 'table-old', oldStyles);
|
||||||
expect(panel).toMatchSnapshot();
|
expect(panel).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"custom": {
|
||||||
|
"align": "right",
|
||||||
|
},
|
||||||
|
"decimals": 2,
|
||||||
|
"displayName": "",
|
||||||
|
"unit": "short",
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"matcher": {
|
||||||
|
"id": "byName",
|
||||||
|
"options": "Time",
|
||||||
|
},
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "displayName",
|
||||||
|
"value": "Time",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "unit",
|
||||||
|
"value": "time: YYYY-MM-DD HH:mm:ss",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "custom.align",
|
||||||
|
"value": null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matcher": {
|
||||||
|
"id": "byName",
|
||||||
|
"options": "ColorCell",
|
||||||
|
},
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "unit",
|
||||||
|
"value": "currencyUSD",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "decimals",
|
||||||
|
"value": 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "custom.cellOptions",
|
||||||
|
"value": {
|
||||||
|
"type": "color-background",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "custom.align",
|
||||||
|
"value": "left",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "thresholds",
|
||||||
|
"value": {
|
||||||
|
"mode": "absolute",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"color": "rgba(245, 54, 54, 0.9)",
|
||||||
|
"value": -Infinity,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "rgba(237, 129, 40, 0.89)",
|
||||||
|
"value": 5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "rgba(50, 172, 45, 0.97)",
|
||||||
|
"value": 10,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matcher": {
|
||||||
|
"id": "byName",
|
||||||
|
"options": "ColorValue",
|
||||||
|
},
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "unit",
|
||||||
|
"value": "Bps",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "decimals",
|
||||||
|
"value": 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "links",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"targetBlank": true,
|
||||||
|
"title": "",
|
||||||
|
"url": "http://www.grafana.com",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "custom.cellOptions",
|
||||||
|
"value": {
|
||||||
|
"type": "color-text",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "custom.align",
|
||||||
|
"value": null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "thresholds",
|
||||||
|
"value": {
|
||||||
|
"mode": "absolute",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"color": "rgba(245, 54, 54, 0.9)",
|
||||||
|
"value": -Infinity,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "rgba(237, 129, 40, 0.89)",
|
||||||
|
"value": 5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "rgba(50, 172, 45, 0.97)",
|
||||||
|
"value": 10,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"transformations": [],
|
||||||
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -163,8 +163,10 @@ const migrateTableStyleToOverride = (style: Style) => {
|
|||||||
|
|
||||||
if (style.colorMode) {
|
if (style.colorMode) {
|
||||||
override.properties.push({
|
override.properties.push({
|
||||||
id: 'custom.displayMode',
|
id: 'custom.cellOptions',
|
||||||
value: colorModeMap[style.colorMode],
|
value: {
|
||||||
|
type: colorModeMap[style.colorMode],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,11 +202,11 @@ const migrateDefaults = (prevDefaults: Style) => {
|
|||||||
displayName: prevDefaults.alias,
|
displayName: prevDefaults.alias,
|
||||||
custom: {
|
custom: {
|
||||||
align: prevDefaults.align === 'auto' ? null : prevDefaults.align,
|
align: prevDefaults.align === 'auto' ? null : prevDefaults.align,
|
||||||
displayMode: colorModeMap[prevDefaults.colorMode],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isNil
|
isNil
|
||||||
);
|
);
|
||||||
|
|
||||||
if (prevDefaults.thresholds.length) {
|
if (prevDefaults.thresholds.length) {
|
||||||
const thresholds: ThresholdsConfig = {
|
const thresholds: ThresholdsConfig = {
|
||||||
mode: ThresholdsMode.Absolute,
|
mode: ThresholdsMode.Absolute,
|
||||||
@ -212,6 +214,12 @@ const migrateDefaults = (prevDefaults: Style) => {
|
|||||||
};
|
};
|
||||||
defaults.thresholds = thresholds;
|
defaults.thresholds = thresholds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prevDefaults.colorMode) {
|
||||||
|
defaults.custom.cellOptions = {
|
||||||
|
type: colorModeMap[prevDefaults.colorMode],
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return defaults;
|
return defaults;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user