-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Custom Values Editor * Revert container name * Add throwing error during custom code execution * Add CodeEditor disabled option * Formatting * Fix tests, update defaults for Values Editors * Update Provisioning and Editor * Update Custom to JavaScript * Formatting --------- Co-authored-by: Mikhail <[email protected]>
- Loading branch information
1 parent
f678dc0
commit 422da82
Showing
23 changed files
with
1,109 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ datasources: | |
orgId: 1 | ||
version: 1 | ||
editable: true | ||
jsonData: | ||
codeEditorEnabled: true |
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,84 @@ | ||
import React from 'react'; | ||
import { DataSourceSettings } from '@grafana/data'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { TestIds } from '../../constants'; | ||
import { StaticDataSourceOptions } from '../../types'; | ||
import { ConfigEditor } from './ConfigEditor'; | ||
|
||
/** | ||
* Override Options | ||
*/ | ||
interface OverrideOptions { | ||
[key: string]: unknown; | ||
jsonData?: object; | ||
secureJsonData?: object | null; | ||
} | ||
|
||
/** | ||
* Configuration Options | ||
*/ | ||
const getOptions = ({ | ||
jsonData = {}, | ||
secureJsonData = {}, | ||
...overrideOptions | ||
}: OverrideOptions = {}): DataSourceSettings<StaticDataSourceOptions, any> => ({ | ||
id: 1, | ||
orgId: 2, | ||
name: '', | ||
typeLogoUrl: '', | ||
type: '', | ||
uid: '', | ||
typeName: '', | ||
access: '', | ||
url: '', | ||
user: '', | ||
database: '', | ||
basicAuth: false, | ||
basicAuthUser: '', | ||
isDefault: false, | ||
secureJsonFields: {}, | ||
readOnly: false, | ||
withCredentials: false, | ||
...overrideOptions, | ||
jsonData: { | ||
codeEditorEnabled: false, | ||
...jsonData, | ||
}, | ||
secureJsonData: { | ||
apiKey: '', | ||
...secureJsonData, | ||
}, | ||
}); | ||
|
||
/** | ||
* Config Editor | ||
*/ | ||
describe('ConfigEditor', () => { | ||
const onChange = jest.fn(); | ||
|
||
beforeEach(() => { | ||
onChange.mockReset(); | ||
}); | ||
|
||
/** | ||
* Code Editor | ||
*/ | ||
describe('Code Editor Enabled', () => { | ||
it('Should change code editor enabled value', () => { | ||
let appliedOptions = getOptions({ jsonData: { codeEditorEnabled: false } }); | ||
const onChange = jest.fn((options) => (appliedOptions = options)); | ||
|
||
const { rerender } = render(<ConfigEditor options={appliedOptions} onOptionsChange={onChange} />); | ||
|
||
expect(screen.getByTestId(TestIds.configEditor.codeEditorEnabledContainer)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(TestIds.configEditor.codeEditorEnabledOption('false'))).toBeChecked(); | ||
|
||
fireEvent.click(screen.getByLabelText(TestIds.configEditor.codeEditorEnabledOption('true'))); | ||
|
||
rerender(<ConfigEditor options={appliedOptions} onOptionsChange={onChange} />); | ||
|
||
expect(screen.getByLabelText(TestIds.configEditor.codeEditorEnabledOption('false'))).not.toBeChecked(); | ||
expect(screen.getByLabelText(TestIds.configEditor.codeEditorEnabledOption('true'))).toBeChecked(); | ||
}); | ||
}); | ||
}); |
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,44 @@ | ||
import React, { useCallback } from 'react'; | ||
import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; | ||
import { FieldSet, InlineField, InlineFieldRow, RadioButtonGroup } from '@grafana/ui'; | ||
import { CodeEditorEnabledOptions, TestIds } from '../../constants'; | ||
import { StaticDataSourceOptions } from '../../types'; | ||
|
||
/** | ||
* Editor Properties | ||
*/ | ||
interface Props extends DataSourcePluginOptionsEditorProps<StaticDataSourceOptions> {} | ||
|
||
/** | ||
* Config Editor | ||
*/ | ||
export const ConfigEditor: React.FC<Props> = ({ options, onOptionsChange }) => { | ||
/** | ||
* Code Editor Enabled Change | ||
*/ | ||
const onChangeCodeEditorEnabled = useCallback( | ||
(value: boolean) => { | ||
onOptionsChange({ | ||
...options, | ||
jsonData: { | ||
codeEditorEnabled: value, | ||
}, | ||
}); | ||
}, | ||
[onOptionsChange, options] | ||
); | ||
|
||
return ( | ||
<FieldSet data-testid={TestIds.configEditor.root}> | ||
<InlineFieldRow> | ||
<InlineField label="Code Editor" labelWidth={14} data-testid={TestIds.configEditor.codeEditorEnabledContainer}> | ||
<RadioButtonGroup | ||
options={CodeEditorEnabledOptions} | ||
value={options.jsonData.codeEditorEnabled || false} | ||
onChange={onChangeCodeEditorEnabled} | ||
/> | ||
</InlineField> | ||
</InlineFieldRow> | ||
</FieldSet> | ||
); | ||
}; |
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 @@ | ||
export * from './ConfigEditor'; |
Oops, something went wrong.