diff --git a/public/app/features/dashboard/containers/__snapshots__/DashboardPage.test.tsx.snap b/public/app/features/dashboard/containers/__snapshots__/DashboardPage.test.tsx.snap index eadcc366dc5..da633484cd3 100644 --- a/public/app/features/dashboard/containers/__snapshots__/DashboardPage.test.tsx.snap +++ b/public/app/features/dashboard/containers/__snapshots__/DashboardPage.test.tsx.snap @@ -78,7 +78,7 @@ exports[`DashboardPage Dashboard init completed Should render dashboard grid 1` ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -191,7 +191,7 @@ exports[`DashboardPage Dashboard init completed Should render dashboard grid 1` ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -285,7 +285,7 @@ exports[`DashboardPage Dashboard init completed Should render dashboard grid 1` ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -410,7 +410,7 @@ exports[`DashboardPage When dashboard has editview url state should render setti ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -523,7 +523,7 @@ exports[`DashboardPage When dashboard has editview url state should render setti ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -617,7 +617,7 @@ exports[`DashboardPage When dashboard has editview url state should render setti ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -717,7 +717,7 @@ exports[`DashboardPage When dashboard has editview url state should render setti ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], diff --git a/public/app/features/dashboard/dashgrid/__snapshots__/DashboardGrid.test.tsx.snap b/public/app/features/dashboard/dashgrid/__snapshots__/DashboardGrid.test.tsx.snap index a8e39e9555b..d9494e674a8 100644 --- a/public/app/features/dashboard/dashgrid/__snapshots__/DashboardGrid.test.tsx.snap +++ b/public/app/features/dashboard/dashgrid/__snapshots__/DashboardGrid.test.tsx.snap @@ -235,7 +235,7 @@ exports[`DashboardGrid Can render dashboard grid Should render 1`] = ` ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -477,7 +477,7 @@ exports[`DashboardGrid Can render dashboard grid Should render 1`] = ` ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -719,7 +719,7 @@ exports[`DashboardGrid Can render dashboard grid Should render 1`] = ` ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], @@ -961,7 +961,7 @@ exports[`DashboardGrid Can render dashboard grid Should render 1`] = ` ], "refresh": undefined, "revision": undefined, - "schemaVersion": 23, + "schemaVersion": 24, "snapshot": undefined, "style": "dark", "tags": Array [], diff --git a/public/app/features/dashboard/state/DashboardMigrator.test.ts b/public/app/features/dashboard/state/DashboardMigrator.test.ts index 7a5876a3f1b..a0174d293b0 100644 --- a/public/app/features/dashboard/state/DashboardMigrator.test.ts +++ b/public/app/features/dashboard/state/DashboardMigrator.test.ts @@ -111,6 +111,10 @@ describe('DashboardModel', () => { expect(table.styles[1].thresholds[1]).toBe('300'); }); + it('table type should be deprecated', () => { + expect(table.type).toBe('table-old'); + }); + it('graph grid to yaxes options', () => { expect(graph.yaxes[0].min).toBe(1); expect(graph.yaxes[0].max).toBe(10); @@ -128,7 +132,7 @@ describe('DashboardModel', () => { }); it('dashboard schema version should be set to latest', () => { - expect(model.schemaVersion).toBe(23); + expect(model.schemaVersion).toBe(24); }); it('graph thresholds should be migrated', () => { diff --git a/public/app/features/dashboard/state/DashboardMigrator.ts b/public/app/features/dashboard/state/DashboardMigrator.ts index f806ffc9002..352b4ecfa8f 100644 --- a/public/app/features/dashboard/state/DashboardMigrator.ts +++ b/public/app/features/dashboard/state/DashboardMigrator.ts @@ -32,7 +32,7 @@ export class DashboardMigrator { let i, j, k, n; const oldVersion = this.dashboard.schemaVersion; const panelUpgrades = []; - this.dashboard.schemaVersion = 23; + this.dashboard.schemaVersion = 24; if (oldVersion === this.dashboard.schemaVersion) { return; @@ -508,6 +508,22 @@ export class DashboardMigrator { } } + if (oldVersion < 24) { + // 7.0 + // - migrate existing tables to 'table-old' + panelUpgrades.push((panel: any) => { + const wasAngularTable = panel.type === 'table'; + if (wasAngularTable && !panel.styles) { + return; // styles are missing so assumes default settings + } + const wasReactTable = panel.table === 'table2'; + if (!wasAngularTable || wasReactTable) { + return; + } + panel.type = wasAngularTable ? 'table-old' : 'table'; + }); + } + if (panelUpgrades.length === 0) { return; } diff --git a/public/app/features/plugins/built_in_plugins.ts b/public/app/features/plugins/built_in_plugins.ts index 78058438ebe..a6df27ed728 100644 --- a/public/app/features/plugins/built_in_plugins.ts +++ b/public/app/features/plugins/built_in_plugins.ts @@ -44,7 +44,7 @@ import * as alertListPanel from 'app/plugins/panel/alertlist/module'; import * as annoListPanel from 'app/plugins/panel/annolist/module'; import * as heatmapPanel from 'app/plugins/panel/heatmap/module'; import * as tablePanel from 'app/plugins/panel/table/module'; -import * as table2Panel from 'app/plugins/panel/table2/module'; +import * as oldTablePanel from 'app/plugins/panel/table-old/module'; import * as singlestatPanel from 'app/plugins/panel/singlestat/module'; import * as singlestatPanel2 from 'app/plugins/panel/stat/module'; import * as gettingStartedPanel from 'app/plugins/panel/gettingstarted/module'; @@ -84,7 +84,7 @@ const builtInPlugins: any = { 'app/plugins/panel/annolist/module': annoListPanel, 'app/plugins/panel/heatmap/module': heatmapPanel, 'app/plugins/panel/table/module': tablePanel, - 'app/plugins/panel/table2/module': table2Panel, + 'app/plugins/panel/table-old/module': oldTablePanel, 'app/plugins/panel/news/module': newsPanel, 'app/plugins/panel/singlestat/module': singlestatPanel, 'app/plugins/panel/stat/module': singlestatPanel2, diff --git a/public/app/plugins/panel/table2/README.md b/public/app/plugins/panel/table-old/README.md similarity index 75% rename from public/app/plugins/panel/table2/README.md rename to public/app/plugins/panel/table-old/README.md index 98f2c13f75c..854e0fbbfd9 100644 --- a/public/app/plugins/panel/table2/README.md +++ b/public/app/plugins/panel/table-old/README.md @@ -6,4 +6,4 @@ The table panel is very flexible, supporting both multiple modes for time series Check out the [Table Panel Showcase in the Grafana Playground](http://play.grafana.org/dashboard/db/table-panel-showcase) or read more about it here: -[http://docs.grafana.org/reference/table_panel/](http://docs.grafana.org/reference/table_panel/) +[https://grafana.com/docs/grafana/latest/features/panels/table_panel/](https://grafana.com/docs/grafana/latest/features/panels/table_panel/) diff --git a/public/app/plugins/panel/table/column_options.html b/public/app/plugins/panel/table-old/column_options.html similarity index 100% rename from public/app/plugins/panel/table/column_options.html rename to public/app/plugins/panel/table-old/column_options.html diff --git a/public/app/plugins/panel/table/column_options.ts b/public/app/plugins/panel/table-old/column_options.ts similarity index 100% rename from public/app/plugins/panel/table/column_options.ts rename to public/app/plugins/panel/table-old/column_options.ts diff --git a/public/app/plugins/panel/table/editor.html b/public/app/plugins/panel/table-old/editor.html similarity index 100% rename from public/app/plugins/panel/table/editor.html rename to public/app/plugins/panel/table-old/editor.html diff --git a/public/app/plugins/panel/table/editor.ts b/public/app/plugins/panel/table-old/editor.ts similarity index 100% rename from public/app/plugins/panel/table/editor.ts rename to public/app/plugins/panel/table-old/editor.ts diff --git a/public/app/plugins/panel/table2/img/icn-table-panel.svg b/public/app/plugins/panel/table-old/img/icn-table-panel.svg similarity index 100% rename from public/app/plugins/panel/table2/img/icn-table-panel.svg rename to public/app/plugins/panel/table-old/img/icn-table-panel.svg diff --git a/public/app/plugins/panel/table/module.html b/public/app/plugins/panel/table-old/module.html similarity index 100% rename from public/app/plugins/panel/table/module.html rename to public/app/plugins/panel/table-old/module.html diff --git a/public/app/plugins/panel/table/module.ts b/public/app/plugins/panel/table-old/module.ts similarity index 100% rename from public/app/plugins/panel/table/module.ts rename to public/app/plugins/panel/table-old/module.ts diff --git a/public/app/plugins/panel/table2/plugin.json b/public/app/plugins/panel/table-old/plugin.json similarity index 66% rename from public/app/plugins/panel/table2/plugin.json rename to public/app/plugins/panel/table-old/plugin.json index 4855b3880f7..b5c927d9431 100644 --- a/public/app/plugins/panel/table2/plugin.json +++ b/public/app/plugins/panel/table-old/plugin.json @@ -1,10 +1,12 @@ { "type": "panel", - "name": "React Table", - "id": "table2", - "state": "alpha", + "name": "Table (old)", + "id": "table-old", + + "state": "deprecated", "info": { + "description": "Table Panel for Grafana", "author": { "name": "Grafana Project", "url": "https://grafana.com" diff --git a/public/app/plugins/panel/table/renderer.ts b/public/app/plugins/panel/table-old/renderer.ts similarity index 100% rename from public/app/plugins/panel/table/renderer.ts rename to public/app/plugins/panel/table-old/renderer.ts diff --git a/public/app/plugins/panel/table/specs/renderer.test.ts b/public/app/plugins/panel/table-old/specs/renderer.test.ts similarity index 100% rename from public/app/plugins/panel/table/specs/renderer.test.ts rename to public/app/plugins/panel/table-old/specs/renderer.test.ts diff --git a/public/app/plugins/panel/table/specs/transformers.test.ts b/public/app/plugins/panel/table-old/specs/transformers.test.ts similarity index 100% rename from public/app/plugins/panel/table/specs/transformers.test.ts rename to public/app/plugins/panel/table-old/specs/transformers.test.ts diff --git a/public/app/plugins/panel/table/transformers.ts b/public/app/plugins/panel/table-old/transformers.ts similarity index 100% rename from public/app/plugins/panel/table/transformers.ts rename to public/app/plugins/panel/table-old/transformers.ts diff --git a/public/app/plugins/panel/table-old/types.ts b/public/app/plugins/panel/table-old/types.ts new file mode 100644 index 00000000000..21c49166de0 --- /dev/null +++ b/public/app/plugins/panel/table-old/types.ts @@ -0,0 +1,42 @@ +import TableModel from 'app/core/table_model'; +import { Column } from '@grafana/data'; + +export interface TableTransform { + description: string; + getColumns(data?: any): any[]; + transform(data: any, panel: any, model: TableModel): void; +} + +export interface ColumnRender extends Column { + title: string; + style: ColumnStyle; + hidden: boolean; +} + +export interface TableRenderModel { + columns: ColumnRender[]; + rows: any[][]; +} + +export interface ColumnStyle { + pattern: string; + + alias?: string; + colorMode?: 'cell' | 'value'; + colors?: any[]; + decimals?: number; + thresholds?: any[]; + type?: 'date' | 'number' | 'string' | 'hidden'; + unit?: string; + dateFormat?: string; + sanitize?: boolean; // not used in react + mappingType?: any; + valueMaps?: any; + rangeMaps?: any; + align?: 'auto' | 'left' | 'center' | 'right'; + link?: any; + linkUrl?: any; + linkTooltip?: any; + linkTargetBlank?: boolean; + preserveFormat?: boolean; +} diff --git a/public/app/plugins/panel/table2/TablePanel.tsx b/public/app/plugins/panel/table/TablePanel.tsx similarity index 100% rename from public/app/plugins/panel/table2/TablePanel.tsx rename to public/app/plugins/panel/table/TablePanel.tsx diff --git a/public/app/plugins/panel/table/migrations.ts b/public/app/plugins/panel/table/migrations.ts new file mode 100644 index 00000000000..6167295eb37 --- /dev/null +++ b/public/app/plugins/panel/table/migrations.ts @@ -0,0 +1,32 @@ +import { PanelModel } from '@grafana/data'; +import { Options } from './types'; + +/** + * At 7.0, the `table` panel was swapped from an angular implementation to a react one. + * The models do not match, so this process will delegate to the old implementation when + * a saved table configuration exists. + */ +export const tableMigrationHandler = (panel: PanelModel): Partial => { + // Table was saved as an angular table, lets just swap to the 'table-old' panel + if (!panel.pluginVersion && (panel as any).columns) { + console.log('Was angular table', panel); + } + + // Nothing changed + return panel.options; +}; + +/** + * This is called when the panel changes from another panel + */ +export const tablePanelChangedHandler = ( + panel: PanelModel> | any, + prevPluginId: string, + prevOptions: any +) => { + // Changing from angular singlestat + if (prevPluginId === 'table-old' && prevOptions.angular) { + console.log('Migrating from angular table', panel); + } + return prevOptions; +}; diff --git a/public/app/plugins/panel/table2/module.tsx b/public/app/plugins/panel/table/module.tsx similarity index 91% rename from public/app/plugins/panel/table2/module.tsx rename to public/app/plugins/panel/table/module.tsx index 786215d4747..3ecadbc1c8a 100644 --- a/public/app/plugins/panel/table2/module.tsx +++ b/public/app/plugins/panel/table/module.tsx @@ -1,8 +1,11 @@ import { PanelPlugin } from '@grafana/data'; import { TablePanel } from './TablePanel'; import { CustomFieldConfig, Options } from './types'; +import { tablePanelChangedHandler, tableMigrationHandler } from './migrations'; export const plugin = new PanelPlugin(TablePanel) + .setPanelChangeHandler(tablePanelChangedHandler) + .setMigrationHandler(tableMigrationHandler) .useFieldConfig({ useCustomConfig: builder => { builder diff --git a/public/app/plugins/panel/table/types.ts b/public/app/plugins/panel/table/types.ts index 21c49166de0..3c1073f4ac3 100644 --- a/public/app/plugins/panel/table/types.ts +++ b/public/app/plugins/panel/table/types.ts @@ -1,42 +1,9 @@ -import TableModel from 'app/core/table_model'; -import { Column } from '@grafana/data'; - -export interface TableTransform { - description: string; - getColumns(data?: any): any[]; - transform(data: any, panel: any, model: TableModel): void; -} - -export interface ColumnRender extends Column { - title: string; - style: ColumnStyle; - hidden: boolean; +export interface Options { + showHeader: boolean; + resizable: boolean; } -export interface TableRenderModel { - columns: ColumnRender[]; - rows: any[][]; -} - -export interface ColumnStyle { - pattern: string; - - alias?: string; - colorMode?: 'cell' | 'value'; - colors?: any[]; - decimals?: number; - thresholds?: any[]; - type?: 'date' | 'number' | 'string' | 'hidden'; - unit?: string; - dateFormat?: string; - sanitize?: boolean; // not used in react - mappingType?: any; - valueMaps?: any; - rangeMaps?: any; - align?: 'auto' | 'left' | 'center' | 'right'; - link?: any; - linkUrl?: any; - linkTooltip?: any; - linkTargetBlank?: boolean; - preserveFormat?: boolean; +export interface CustomFieldConfig { + width: number; + displayMode: string; } diff --git a/public/app/plugins/panel/table2/types.ts b/public/app/plugins/panel/table2/types.ts deleted file mode 100644 index 3c1073f4ac3..00000000000 --- a/public/app/plugins/panel/table2/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface Options { - showHeader: boolean; - resizable: boolean; -} - -export interface CustomFieldConfig { - width: number; - displayMode: string; -}