Skip to content

Commit

Permalink
[v9.5.x] Table: Fix migrations from old angular table for cell color …
Browse files Browse the repository at this point in the history
…modes (#66085)

Table: Fix migrations from old angular table for cell color modes  (#65760)

* Table: Fix migrations from old angular table

* Update defaults

(cherry picked from commit 3843c73)

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
  • Loading branch information
grafanabot and torkelo committed Apr 6, 2023
1 parent 7104dc3 commit ec109a9
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 141 deletions.
137 changes: 0 additions & 137 deletions public/app/plugins/panel/table/__snapshots__/migrations.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,142 +1,5 @@
// 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`] = `
{
"fieldConfig": {
Expand Down
140 changes: 139 additions & 1 deletion public/app/plugins/panel/table/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,144 @@ describe('Table Migrations', () => {
};
const panel = {} as PanelModel;
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": [],
}
`);
});
});
14 changes: 11 additions & 3 deletions public/app/plugins/panel/table/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ const migrateTableStyleToOverride = (style: Style) => {

if (style.colorMode) {
override.properties.push({
id: 'custom.displayMode',
value: colorModeMap[style.colorMode],
id: 'custom.cellOptions',
value: {
type: colorModeMap[style.colorMode],
},
});
}

Expand Down Expand Up @@ -200,18 +202,24 @@ const migrateDefaults = (prevDefaults: Style) => {
displayName: prevDefaults.alias,
custom: {
align: prevDefaults.align === 'auto' ? null : prevDefaults.align,
displayMode: colorModeMap[prevDefaults.colorMode],
},
},
isNil
);

if (prevDefaults.thresholds.length) {
const thresholds: ThresholdsConfig = {
mode: ThresholdsMode.Absolute,
steps: generateThresholds(prevDefaults.thresholds, prevDefaults.colors),
};
defaults.thresholds = thresholds;
}

if (prevDefaults.colorMode) {
defaults.custom.cellOptions = {
type: colorModeMap[prevDefaults.colorMode],
};
}
}
return defaults;
};
Expand Down

0 comments on commit ec109a9

Please sign in to comment.