Datasource: add button to navigate to explore from settings (#36119)

Fixes #13737
This commit is contained in:
Tharun Rajendran
2021-08-23 20:53:49 +05:30
committed by GitHub
parent ef8e95ac7f
commit 2156980edb
4 changed files with 32 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ const setup = (propOverrides?: object) => {
onSubmit: jest.fn(), onSubmit: jest.fn(),
onDelete: jest.fn(), onDelete: jest.fn(),
onTest: jest.fn(), onTest: jest.fn(),
exploreUrl: '/explore',
}; };
Object.assign(props, propOverrides); Object.assign(props, propOverrides);

View File

@@ -5,18 +5,22 @@ import config from 'app/core/config';
import { Button, LinkButton } from '@grafana/ui'; import { Button, LinkButton } from '@grafana/ui';
export interface Props { export interface Props {
exploreUrl: string;
isReadOnly: boolean; isReadOnly: boolean;
onDelete: () => void; onDelete: () => void;
onSubmit: (event: any) => void; onSubmit: (event: any) => void;
onTest: (event: any) => void; onTest: (event: any) => void;
} }
const ButtonRow: FC<Props> = ({ isReadOnly, onDelete, onSubmit, onTest }) => { const ButtonRow: FC<Props> = ({ isReadOnly, onDelete, onSubmit, onTest, exploreUrl }) => {
return ( return (
<div className="gf-form-button-row"> <div className="gf-form-button-row">
<LinkButton variant="secondary" fill="outline" href={`${config.appSubUrl}/datasources`}> <LinkButton variant="secondary" fill="solid" href={`${config.appSubUrl}/datasources`}>
Back Back
</LinkButton> </LinkButton>
<LinkButton variant="secondary" fill="solid" href={exploreUrl}>
Explore
</LinkButton>
<Button <Button
type="button" type="button"
variant="destructive" variant="destructive"

View File

@@ -20,7 +20,7 @@ import { getNavModel } from 'app/core/selectors/navModel';
// Types // Types
import { StoreState } from 'app/types/'; import { StoreState } from 'app/types/';
import { DataSourceSettings } from '@grafana/data'; import { DataSourceSettings, urlUtil } from '@grafana/data';
import { Alert, Button, LinkButton } from '@grafana/ui'; import { Alert, Button, LinkButton } from '@grafana/ui';
import { getDataSourceLoadingNav, buildNavModel, getDataSourceNav } from '../state/navModel'; import { getDataSourceLoadingNav, buildNavModel, getDataSourceNav } from '../state/navModel';
import { PluginStateInfo } from 'app/features/plugins/PluginStateInfo'; import { PluginStateInfo } from 'app/features/plugins/PluginStateInfo';
@@ -149,6 +149,13 @@ export class DataSourceSettingsPage extends PureComponent<Props> {
return this.props.dataSource.id > 0; return this.props.dataSource.id > 0;
} }
onNavigateToExplore() {
const { dataSource } = this.props;
const exploreState = JSON.stringify({ datasource: dataSource.name, context: 'explore' });
const url = urlUtil.renderUrl('/explore', { left: exploreState });
return url;
}
renderLoadError(loadError: any) { renderLoadError(loadError: any) {
let showDelete = false; let showDelete = false;
let msg = loadError.toString(); let msg = loadError.toString();
@@ -269,6 +276,7 @@ export class DataSourceSettingsPage extends PureComponent<Props> {
isReadOnly={this.isReadOnly()} isReadOnly={this.isReadOnly()}
onDelete={this.onDelete} onDelete={this.onDelete}
onTest={(event) => this.onTest(event)} onTest={(event) => this.onTest(event)}
exploreUrl={this.onNavigateToExplore()}
/> />
</form> </form>
); );

View File

@@ -5,12 +5,19 @@ exports[`Render should render component 1`] = `
className="gf-form-button-row" className="gf-form-button-row"
> >
<LinkButton <LinkButton
fill="outline" fill="solid"
href="/datasources" href="/datasources"
variant="secondary" variant="secondary"
> >
Back Back
</LinkButton> </LinkButton>
<LinkButton
fill="solid"
href="/explore"
variant="secondary"
>
Explore
</LinkButton>
<Button <Button
aria-label="Data source settings page Delete button" aria-label="Data source settings page Delete button"
disabled={true} disabled={true}
@@ -35,12 +42,19 @@ exports[`Render should render with buttons enabled 1`] = `
className="gf-form-button-row" className="gf-form-button-row"
> >
<LinkButton <LinkButton
fill="outline" fill="solid"
href="/datasources" href="/datasources"
variant="secondary" variant="secondary"
> >
Back Back
</LinkButton> </LinkButton>
<LinkButton
fill="solid"
href="/explore"
variant="secondary"
>
Explore
</LinkButton>
<Button <Button
aria-label="Data source settings page Delete button" aria-label="Data source settings page Delete button"
disabled={false} disabled={false}