-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add panel options migration for editor mode
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { EditorMode } from './constants'; | ||
import { getMigratedOptions } from './migration'; | ||
import { PanelOptions } from './types'; | ||
|
||
describe('Migrations', () => { | ||
it('Should return panel options', () => { | ||
const options: Partial<PanelOptions> = { | ||
editorMode: EditorMode.VISUAL, | ||
}; | ||
|
||
expect( | ||
getMigratedOptions({ | ||
options: options, | ||
} as any) | ||
).toEqual(options); | ||
}); | ||
|
||
describe('5.2.0', () => { | ||
it('Should set code to editor mode if not defined', () => { | ||
expect( | ||
getMigratedOptions({ | ||
options: {}, | ||
} as any) | ||
).toEqual({ | ||
editorMode: EditorMode.CODE, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { PanelModel } from '@grafana/data'; | ||
|
||
import { EditorMode } from './constants'; | ||
import { PanelOptions } from './types'; | ||
|
||
/** | ||
* Outdated Panel Options | ||
*/ | ||
interface OutdatedPanelOptions extends Omit<PanelOptions, 'editorMode'> { | ||
/** | ||
* Editor Mode introduced in 5.2.0 | ||
*/ | ||
editorMode?: EditorMode; | ||
} | ||
|
||
/** | ||
* Get Migrated Options | ||
* | ||
* @param panel | ||
*/ | ||
export const getMigratedOptions = (panel: PanelModel<OutdatedPanelOptions>): PanelOptions => { | ||
const { ...options } = panel.options; | ||
|
||
/** | ||
* Set code editor mode if not defined | ||
*/ | ||
if (!options.editorMode) { | ||
options.editorMode = EditorMode.CODE; | ||
} | ||
|
||
return options; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters