Table: Fixes broken link styles after recent cell options PR (#61582)

* Table: Fixes broken link styles after recent cell options PR

* Share migration and fix bar gauge as well

* Remove unused import

* Review fixes

* Fixed test

Co-authored-by: Kyle Cunningham <kyle@codeincarnate.com>
This commit is contained in:
Torkel Ödegaard
2023-01-17 17:08:23 +01:00
committed by GitHub
parent bb7410aa09
commit 8620909006
8 changed files with 168 additions and 179 deletions

View File

@@ -26,8 +26,8 @@ import {
import { labelsToFieldsTransformer } from '@grafana/data/src/transformations/transformers/labelsToFields';
import { mergeTransformer } from '@grafana/data/src/transformations/transformers/merge';
import { getDataSourceSrv, setDataSourceSrv } from '@grafana/runtime';
import { BarGaugeDisplayMode, TableCellBackgroundDisplayMode, TableCellOptions } from '@grafana/schema';
import { AxisPlacement, GraphFieldConfig, TableCellDisplayMode } from '@grafana/ui';
import { AxisPlacement, GraphFieldConfig } from '@grafana/ui';
import { migrateTableDisplayModeToCellOptions } from '@grafana/ui/src/components/Table/utils';
import { getAllOptionEditors, getAllStandardFieldConfigs } from 'app/core/components/OptionsUI/registry';
import { config } from 'app/core/config';
import {
@@ -818,7 +818,7 @@ export class DashboardMigrator {
// Update field configuration
if (displayMode !== undefined) {
// Migrate any options for the panel
panel.fieldConfig.defaults.custom.cellOptions = migrateTableCellConfig(displayMode);
panel.fieldConfig.defaults.custom.cellOptions = migrateTableDisplayModeToCellOptions(displayMode);
// Delete the legacy field
delete panel.fieldConfig.defaults.custom.displayMode;
@@ -831,7 +831,8 @@ export class DashboardMigrator {
if (panel.fieldConfig.overrides[i].properties[j].id === 'custom.displayMode') {
panel.fieldConfig.overrides[i].properties[j].id = 'custom.cellOptions';
panel.fieldConfig.overrides[i].properties[j].value = migrateTableCellConfig(overrideDisplayMode);
panel.fieldConfig.overrides[i].properties[j].value =
migrateTableDisplayModeToCellOptions(overrideDisplayMode);
}
}
}
@@ -1364,50 +1365,3 @@ function ensureXAxisVisibility(panel: PanelModel) {
return panel;
}
/**
* Migrates table cell display mode to new object format.
*
* @param displayMode The display mode of the cell
* @returns TableCellOptions object in the correct format
* relative to the old display mode.
*/
function migrateTableCellConfig(displayMode: TableCellDisplayMode): TableCellOptions {
switch (displayMode) {
// In the case of the gauge we move to a different option
case 'basic':
case 'gradient-gauge':
case 'lcd-gauge':
let gaugeMode = BarGaugeDisplayMode.Basic;
if (displayMode === 'gradient-gauge') {
gaugeMode = BarGaugeDisplayMode.Gradient;
} else if (displayMode === 'lcd-gauge') {
gaugeMode = BarGaugeDisplayMode.Lcd;
}
return {
type: TableCellDisplayMode.Gauge,
mode: gaugeMode,
};
// Also true in the case of the color background
case 'color-background':
case 'color-background-solid':
let mode = TableCellBackgroundDisplayMode.Basic;
// Set the new mode field, somewhat confusingly the
// color-background mode is for gradient display
if (displayMode === 'color-background') {
mode = TableCellBackgroundDisplayMode.Gradient;
}
return {
type: TableCellDisplayMode.ColorBackground,
mode: mode,
};
default:
return {
type: displayMode,
};
}
}