-
-
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 context to non-visual mode (#245)
* ft Add context to non-visual mode * Update CHANGELOG.md * Add code editor suggestions * Add panel options migration for editor mode --------- Co-authored-by: Mikhail Volkov <[email protected]> Co-authored-by: asimonok <[email protected]>
- Loading branch information
1 parent
b3b3b68
commit 81fac77
Showing
7 changed files
with
163 additions
and
37 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
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
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
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
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