Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update auto size code editor #263

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/components/EchartsEditor/EchartsEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StandardEditorProps } from '@grafana/data';
import { getTemplateSrv } from '@grafana/runtime';
import { CodeEditor, CodeEditorSuggestionItem, CodeEditorSuggestionItemKind } from '@grafana/ui';
import { AutosizeCodeEditor } from '@volkovlabs/components';
import type * as monacoType from 'monaco-editor/esm/vs/editor/editor.api';
import React from 'react';

Expand Down Expand Up @@ -81,7 +82,6 @@ export const EchartsEditor: React.FC<Props> = ({ value, onChange, context, item
if (item.id === Editor.THEME) {
return {
language: CodeLanguage.JSON,
height: context.options?.themeEditor.height,
};
}

Expand All @@ -91,7 +91,6 @@ export const EchartsEditor: React.FC<Props> = ({ value, onChange, context, item
if (item.id === Editor.VISUALCODE) {
return {
language: CodeLanguage.JAVASCRIPT,
height: context.options?.visualEditor.codeHeight,
getSuggestions,
};
}
Expand All @@ -101,19 +100,17 @@ export const EchartsEditor: React.FC<Props> = ({ value, onChange, context, item
*/
return {
language: CodeLanguage.JAVASCRIPT,
height: context.options?.editor.height,
getSuggestions,
};
};

return (
<div data-testid={TEST_IDS.editor.root}>
<CodeEditor
<AutosizeCodeEditor
language={CodeLanguage.JAVASCRIPT}
showLineNumbers={true}
showMiniMap={value.length > 100}
value={value}
height={context.options?.editor.height}
onBlur={onChange}
onSave={onChange}
monacoOptions={monacoOptions}
Expand Down
5 changes: 2 additions & 3 deletions src/constants/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ return {
export const DEFAULT_OPTIONS: PanelOptions = {
getOption: GET_OPTION,
renderer: Renderer.CANVAS,
themeEditor: { name: Theme.DEFAULT, config: '{}', height: 400 },
editor: { height: 600, format: Format.AUTO },
themeEditor: { name: Theme.DEFAULT, config: '{}' },
editor: { format: Format.AUTO },
map: Map.NONE,
baidu: {
key: '',
Expand All @@ -123,6 +123,5 @@ export const DEFAULT_OPTIONS: PanelOptions = {
dataset: [],
series: [],
code: VISUAL_EDITOR_CODE,
codeHeight: 600,
},
};
2 changes: 0 additions & 2 deletions src/module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe('plugin', () => {
* Inputs
*/
expect(builder.addCustomEditor).toHaveBeenCalled();
expect(builder.addSliderInput).toHaveBeenCalled();
expect(builder.addRadio).toHaveBeenCalled();
expect(builder.addTextInput).toHaveBeenCalled();
});
Expand Down Expand Up @@ -105,7 +104,6 @@ describe('plugin', () => {

plugin['optionsSupplier'](builder);

expect(shownSliderInputPaths).toEqual(expect.arrayContaining(['themeEditor.height']));
expect(shownEditorPaths).toEqual(expect.arrayContaining(['themeEditor.config']));
});
});
Expand Down
54 changes: 10 additions & 44 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,6 @@ export const plugin = new PanelPlugin<PanelOptions>(EchartsPanel)
category: ['Visual Editor'],
showIf: isVisualEditor,
})
.addSliderInput({
path: 'visualEditor.codeHeight',
name: 'Height, px',
defaultValue: DEFAULT_OPTIONS.visualEditor.codeHeight,
settings: {
min: 100,
max: 2000,
},
category: ['Visual Editor'],
showIf: isVisualEditor,
})
.addCustomEditor({
id: Editor.VISUALCODE,
path: 'visualEditor.code',
Expand All @@ -169,17 +158,6 @@ export const plugin = new PanelPlugin<PanelOptions>(EchartsPanel)
* Code Editor
*/
builder
.addSliderInput({
path: 'editor.height',
name: 'Height, px',
defaultValue: DEFAULT_OPTIONS.editor.height,
settings: {
min: 100,
max: 2000,
},
category: ['Code'],
showIf: isCodeEditor,
})
.addRadio({
path: 'editor.format',
name: 'Formatting',
Expand All @@ -204,28 +182,16 @@ export const plugin = new PanelPlugin<PanelOptions>(EchartsPanel)
/**
* Theme
*/
builder
.addSliderInput({
path: 'themeEditor.height',
name: 'Height, px',
defaultValue: DEFAULT_OPTIONS.themeEditor.height,
settings: {
min: 100,
max: 2000,
},
category: ['Theme'],
showIf: (config) => config.themeEditor.name === Theme.CUSTOM,
})
.addCustomEditor({
id: Editor.THEME,
path: 'themeEditor.config',
name: 'Configuration',
description: 'Custom Theme from the Theme Builder.',
defaultValue: DEFAULT_OPTIONS.themeEditor.config,
editor: EchartsEditor,
category: ['Theme'],
showIf: (config) => config.themeEditor.name === Theme.CUSTOM,
});
builder.addCustomEditor({
id: Editor.THEME,
path: 'themeEditor.config',
name: 'Configuration',
description: 'Custom Theme from the Theme Builder.',
defaultValue: DEFAULT_OPTIONS.themeEditor.config,
editor: EchartsEditor,
category: ['Theme'],
showIf: (config) => config.themeEditor.name === Theme.CUSTOM,
});

return builder;
})
Expand Down
7 changes: 0 additions & 7 deletions src/types/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import { Format } from '../constants';
* Editor Options
*/
export interface EditorOptions {
/**
* Height
*
* @type {number}
*/
height: number;

/**
* Format
*
Expand Down
7 changes: 0 additions & 7 deletions src/types/theme-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ export interface ThemeEditorOptions {
*/
name: Theme;

/**
* Height
*
* @type {number}
*/
height: number;

/**
* Config
*
Expand Down
7 changes: 0 additions & 7 deletions src/types/visual-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,6 @@ export interface VisualEditorOptions {
* @type {string}
*/
code: string;

/**
* Code Height
*
* @type {number}
*/
codeHeight: number;
}

/**
Expand Down
Loading