mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* reword button to Create a new data source The previous wording included the name of the data source, which made it difficult for the doc team to refer to it. This allows the doc team to refer to this button in an obvious way. * "Create a"-> "Add" * update tests
37 lines
1002 B
TypeScript
37 lines
1002 B
TypeScript
import React, { useCallback } from 'react';
|
|
|
|
import { DataSourcePluginMeta } from '@grafana/data';
|
|
import { Button } from '@grafana/ui';
|
|
import { useDataSourcesRoutes, addDataSource } from 'app/features/datasources/state';
|
|
import { useDispatch } from 'app/types';
|
|
|
|
import { isDataSourceEditor } from '../../permissions';
|
|
import { CatalogPlugin } from '../../types';
|
|
|
|
type Props = {
|
|
plugin: CatalogPlugin;
|
|
};
|
|
|
|
export function GetStartedWithDataSource({ plugin }: Props): React.ReactElement | null {
|
|
const dispatch = useDispatch();
|
|
const dataSourcesRoutes = useDataSourcesRoutes();
|
|
const onAddDataSource = useCallback(() => {
|
|
const meta = {
|
|
name: plugin.name,
|
|
id: plugin.id,
|
|
} as DataSourcePluginMeta;
|
|
|
|
dispatch(addDataSource(meta, dataSourcesRoutes.Edit));
|
|
}, [dispatch, plugin, dataSourcesRoutes]);
|
|
|
|
if (!isDataSourceEditor()) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Button variant="primary" onClick={onAddDataSource}>
|
|
Add new data source
|
|
</Button>
|
|
);
|
|
}
|