-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Query Editor Header component (#38)
* Add Query Editor Header component * Prepare release 0.0.43
- Loading branch information
1 parent
b837365
commit 901601b
Showing
8 changed files
with
529 additions
and
242 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 |
---|---|---|
|
@@ -7,4 +7,5 @@ cypress/videos/ | |
dist/ | ||
compiled/ | ||
yarn-error.log | ||
.idea/ | ||
.idea/ | ||
.DS_Store |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@grafana/aws-sdk", | ||
"version": "0.0.42", | ||
"version": "0.0.43", | ||
"description": "Common AWS features for grafana", | ||
"main": "dist/index.js", | ||
"publishConfig": { | ||
|
@@ -26,11 +26,15 @@ | |
"repository": "github:grafana/grafana-aws-sdk-react", | ||
"author": "Grafana Labs <[email protected]> (https://grafana.com)", | ||
"license": "Apache-2.0", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"@grafana/async-query-data": "0.1.4", | ||
"@grafana/experimental": "1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@grafana/data": "9.2.3", | ||
"@grafana/toolkit": "9.2.3", | ||
"@grafana/ui": "9.2.3", | ||
"@grafana/data": "9.3.2", | ||
"@grafana/runtime": "9.3.2", | ||
"@grafana/toolkit": "9.3.2", | ||
"@grafana/ui": "9.3.2", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@testing-library/jest-dom": "5.16.5", | ||
"@testing-library/react": "12.1.5", | ||
|
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,38 @@ | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { mockQuery } from './__mocks__/query'; | ||
import { Props as QueryEditorHeaderProps, QueryEditorHeader } from './QueryEditorHeader'; | ||
import { DataQuery, DataSourceApi, DataSourceJsonData } from '@grafana/data'; | ||
import { RunQueryButtons } from '@grafana/async-query-data'; | ||
import { Button } from '@grafana/ui'; | ||
|
||
const props: QueryEditorHeaderProps<DataSourceApi, DataQuery, DataSourceJsonData> = { | ||
query: mockQuery, | ||
onChange: jest.fn(), | ||
onRunQuery: jest.fn(), | ||
enableRunButton: false, | ||
datasource: {} as DataSourceApi, | ||
}; | ||
jest.mock('@grafana/async-query-data', () => ({ | ||
RunQueryButtons: jest.fn(() => <div>Buttons</div>), | ||
})); | ||
jest.mock('@grafana/ui', () => ({ | ||
...jest.requireActual('@grafana/ui'), | ||
Button: jest.fn(() => <div>Button</div>), | ||
})); | ||
|
||
describe('QueryEditorHeader', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('should display RunQueryButtons if showAsyncQueryButtons prop is true', async () => { | ||
render(<QueryEditorHeader {...props} showAsyncQueryButtons={true} />); | ||
expect(RunQueryButtons).toHaveBeenCalled(); | ||
}); | ||
it('should display the run button if showAsyncQueryButtons prop is false', async () => { | ||
render(<QueryEditorHeader {...props} showAsyncQueryButtons={false} />); | ||
expect(Button).toHaveBeenCalled(); | ||
expect(RunQueryButtons).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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,61 @@ | ||
import React from 'react'; | ||
|
||
import { DataQuery, DataSourceApi, DataSourceJsonData, LoadingState, QueryEditorProps } from '@grafana/data'; | ||
import { EditorHeader, FlexItem } from '@grafana/experimental'; | ||
import { Button } from '@grafana/ui'; | ||
import { RunQueryButtons } from '@grafana/async-query-data'; | ||
|
||
export interface Props< | ||
Datasource extends DataSourceApi<TQuery, JsonData>, | ||
TQuery extends DataQuery, | ||
JsonData extends DataSourceJsonData | ||
> extends QueryEditorProps<Datasource, TQuery, JsonData> { | ||
showAsyncQueryButtons?: boolean; | ||
extraHeaderElementLeft?: JSX.Element; | ||
extraHeaderElementRight?: JSX.Element; | ||
enableRunButton: boolean; | ||
cancel?: (target: TQuery) => void; | ||
onRunQuery: () => void; | ||
} | ||
|
||
export function QueryEditorHeader< | ||
Datasource extends DataSourceApi<TQuery, JsonData>, | ||
TQuery extends DataQuery, | ||
JsonData extends DataSourceJsonData | ||
>({ | ||
query, | ||
showAsyncQueryButtons, | ||
extraHeaderElementLeft, | ||
extraHeaderElementRight, | ||
enableRunButton, | ||
onRunQuery, | ||
data, | ||
cancel, | ||
}: Props<Datasource, TQuery, JsonData>): JSX.Element { | ||
return ( | ||
<EditorHeader> | ||
{extraHeaderElementLeft} | ||
<FlexItem grow={1} /> | ||
{showAsyncQueryButtons ? ( | ||
<RunQueryButtons | ||
onRunQuery={onRunQuery} | ||
enableRun={enableRunButton} | ||
query={query} | ||
onCancelQuery={cancel} | ||
state={data?.state} | ||
/> | ||
) : ( | ||
<Button | ||
variant={enableRunButton ? 'primary' : 'secondary'} | ||
size="sm" | ||
onClick={onRunQuery} | ||
icon={data?.state === LoadingState.Loading ? 'fa fa-spinner' : undefined} | ||
disabled={data?.state === LoadingState.Loading} | ||
> | ||
Run query | ||
</Button> | ||
)} | ||
{extraHeaderElementRight} | ||
</EditorHeader> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { QueryCodeEditor } from './QueryCodeEditor'; | ||
export { QueryEditorHeader } from './QueryEditorHeader'; | ||
export { FormatSelect } from './FormatSelect'; | ||
export { FillValueSelect, FillValueOptions } from './FillValueSelect'; |
Oops, something went wrong.