mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Datasource: Move the Delete data source button back to the bottom (#67552)
* - move delete button back to the lower section * - remove the top Delete button * - fix e2e tests
This commit is contained in:
parent
8516e63937
commit
ba8bba78fc
@ -2595,9 +2595,6 @@ exports[`better eslint`] = {
|
|||||||
"public/app/features/datasources/components/BasicSettings.tsx:5381": [
|
"public/app/features/datasources/components/BasicSettings.tsx:5381": [
|
||||||
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
|
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
|
||||||
],
|
],
|
||||||
"public/app/features/datasources/components/ButtonRow.tsx:5381": [
|
|
||||||
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
|
|
||||||
],
|
|
||||||
"public/app/features/datasources/components/DataSourceReadOnlyMessage.tsx:5381": [
|
"public/app/features/datasources/components/DataSourceReadOnlyMessage.tsx:5381": [
|
||||||
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
|
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
|
||||||
],
|
],
|
||||||
|
@ -20,7 +20,7 @@ export const Pages = {
|
|||||||
name: 'Data source settings page name input field',
|
name: 'Data source settings page name input field',
|
||||||
delete: 'Data source settings page Delete button',
|
delete: 'Data source settings page Delete button',
|
||||||
readOnly: 'Data source settings page read only message',
|
readOnly: 'Data source settings page read only message',
|
||||||
saveAndTest: 'Data source settings page Save and Test button',
|
saveAndTest: 'data-testid Data source settings page Save and Test button',
|
||||||
alert: 'Data source settings page Alert',
|
alert: 'Data source settings page Alert',
|
||||||
},
|
},
|
||||||
DataSources: {
|
DataSources: {
|
||||||
|
@ -8,6 +8,8 @@ import { ButtonRow, Props } from './ButtonRow';
|
|||||||
const setup = (propOverrides?: object) => {
|
const setup = (propOverrides?: object) => {
|
||||||
const props: Props = {
|
const props: Props = {
|
||||||
canSave: false,
|
canSave: false,
|
||||||
|
canDelete: true,
|
||||||
|
onDelete: jest.fn(),
|
||||||
onSubmit: jest.fn(),
|
onSubmit: jest.fn(),
|
||||||
onTest: jest.fn(),
|
onTest: jest.fn(),
|
||||||
};
|
};
|
||||||
@ -21,11 +23,12 @@ describe('<ButtonRow>', () => {
|
|||||||
it('should render component', () => {
|
it('should render component', () => {
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
|
expect(screen.getByTestId(selectors.pages.DataSource.delete)).toBeInTheDocument();
|
||||||
expect(screen.getByText('Test')).toBeInTheDocument();
|
expect(screen.getByText('Test')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
it('should render save & test', () => {
|
it('should render save & test', () => {
|
||||||
setup({ canSave: true });
|
setup({ canSave: true });
|
||||||
|
|
||||||
expect(screen.getByRole('button', { name: selectors.pages.DataSource.saveAndTest })).toBeInTheDocument();
|
expect(screen.getByTestId(selectors.pages.DataSource.saveAndTest)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -5,20 +5,31 @@ import { Button } from '@grafana/ui';
|
|||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
canSave: boolean;
|
canSave: boolean;
|
||||||
|
canDelete: boolean;
|
||||||
|
onDelete: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
||||||
onSubmit: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
onSubmit: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
||||||
onTest: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
onTest: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ButtonRow({ canSave, onSubmit, onTest }: Props) {
|
export function ButtonRow({ canSave, canDelete, onDelete, onSubmit, onTest }: Props) {
|
||||||
return (
|
return (
|
||||||
<div className="gf-form-button-row">
|
<div className="gf-form-button-row">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="destructive"
|
||||||
|
disabled={!canDelete}
|
||||||
|
onClick={onDelete}
|
||||||
|
data-testid={selectors.pages.DataSource.delete}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
{canSave && (
|
{canSave && (
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
disabled={!canSave}
|
disabled={!canSave}
|
||||||
onClick={onSubmit}
|
onClick={onSubmit}
|
||||||
aria-label={selectors.pages.DataSource.saveAndTest}
|
data-testid={selectors.pages.DataSource.saveAndTest}
|
||||||
>
|
>
|
||||||
Save & test
|
Save & test
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -108,7 +108,7 @@ export function EditDataSourceView({
|
|||||||
onUpdate,
|
onUpdate,
|
||||||
}: ViewProps) {
|
}: ViewProps) {
|
||||||
const { plugin, loadError, testingStatus, loading } = dataSourceSettings;
|
const { plugin, loadError, testingStatus, loading } = dataSourceSettings;
|
||||||
const { readOnly, hasWriteRights } = dataSourceRights;
|
const { readOnly, hasWriteRights, hasDeleteRights } = dataSourceRights;
|
||||||
const hasDataSource = dataSource.id > 0;
|
const hasDataSource = dataSource.id > 0;
|
||||||
|
|
||||||
const dsi = getDataSourceSrv()?.getInstanceSettings(dataSource.uid);
|
const dsi = getDataSourceSrv()?.getInstanceSettings(dataSource.uid);
|
||||||
@ -179,7 +179,13 @@ export function EditDataSourceView({
|
|||||||
|
|
||||||
<DataSourceTestingStatus testingStatus={testingStatus} exploreUrl={exploreUrl} dataSource={dataSource} />
|
<DataSourceTestingStatus testingStatus={testingStatus} exploreUrl={exploreUrl} dataSource={dataSource} />
|
||||||
|
|
||||||
<ButtonRow onSubmit={onSubmit} onTest={onTest} canSave={!readOnly && hasWriteRights} />
|
<ButtonRow
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
onTest={onTest}
|
||||||
|
onDelete={onDelete}
|
||||||
|
canDelete={!readOnly && hasDeleteRights}
|
||||||
|
canSave={!readOnly && hasWriteRights}
|
||||||
|
/>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ import React from 'react';
|
|||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
import { Button, LinkButton, useStyles2 } from '@grafana/ui';
|
import { LinkButton, useStyles2 } from '@grafana/ui';
|
||||||
import { contextSrv } from 'app/core/core';
|
import { contextSrv } from 'app/core/core';
|
||||||
import { AccessControlAction } from 'app/types';
|
import { AccessControlAction } from 'app/types';
|
||||||
|
|
||||||
import { useDataSource, useDataSourceRights, useDeleteLoadedDataSource } from '../state';
|
import { useDataSource } from '../state';
|
||||||
import { trackCreateDashboardClicked, trackExploreClicked } from '../tracking';
|
import { trackCreateDashboardClicked, trackExploreClicked } from '../tracking';
|
||||||
import { constructDataSourceExploreUrl } from '../utils';
|
import { constructDataSourceExploreUrl } from '../utils';
|
||||||
|
|
||||||
@ -26,13 +26,8 @@ interface Props {
|
|||||||
export function EditDataSourceActions({ uid }: Props) {
|
export function EditDataSourceActions({ uid }: Props) {
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const dataSource = useDataSource(uid);
|
const dataSource = useDataSource(uid);
|
||||||
const onDelete = useDeleteLoadedDataSource();
|
|
||||||
|
|
||||||
const { readOnly, hasDeleteRights } = useDataSourceRights(uid);
|
|
||||||
const hasExploreRights = contextSrv.hasPermission(AccessControlAction.DataSourcesExplore);
|
const hasExploreRights = contextSrv.hasPermission(AccessControlAction.DataSourcesExplore);
|
||||||
|
|
||||||
const canDelete = !readOnly && hasDeleteRights;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LinkButton
|
<LinkButton
|
||||||
@ -71,10 +66,6 @@ export function EditDataSourceActions({ uid }: Props) {
|
|||||||
Explore
|
Explore
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Button type="button" variant="destructive" disabled={!canDelete} onClick={onDelete} className={styles.button}>
|
|
||||||
Delete
|
|
||||||
</Button>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user