2023-04-20 18:11:13 +08:00
|
|
|
import React from 'react';
|
2023-04-19 21:08:09 +08:00
|
|
|
|
|
|
|
|
import { DataSourceInstanceSettings, DataSourceRef } from '@grafana/data';
|
|
|
|
|
|
|
|
|
|
import { DataSourceCard } from './DataSourceCard';
|
2023-04-20 18:11:13 +08:00
|
|
|
import { isDataSourceMatch, useGetDatasources } from './utils';
|
2023-04-19 21:08:09 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Component props description for the {@link DataSourceList}
|
|
|
|
|
*
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
|
|
|
|
export interface DataSourceListProps {
|
|
|
|
|
className?: string;
|
|
|
|
|
onChange: (ds: DataSourceInstanceSettings) => void;
|
2023-04-20 18:11:13 +08:00
|
|
|
current: DataSourceRef | DataSourceInstanceSettings | string | null | undefined;
|
|
|
|
|
/** Would be nicer if these parameters were part of a filtering object */
|
2023-04-19 21:08:09 +08:00
|
|
|
tracing?: boolean;
|
|
|
|
|
mixed?: boolean;
|
|
|
|
|
dashboard?: boolean;
|
|
|
|
|
metrics?: boolean;
|
|
|
|
|
type?: string | string[];
|
|
|
|
|
annotations?: boolean;
|
|
|
|
|
variables?: boolean;
|
|
|
|
|
alerting?: boolean;
|
|
|
|
|
pluginId?: string;
|
|
|
|
|
/** If true,we show only DSs with logs; and if true, pluginId shouldnt be passed in */
|
|
|
|
|
logs?: boolean;
|
|
|
|
|
width?: number;
|
|
|
|
|
inputId?: string;
|
|
|
|
|
filter?: (dataSource: DataSourceInstanceSettings) => boolean;
|
|
|
|
|
onClear?: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 18:11:13 +08:00
|
|
|
export function DataSourceList(props: DataSourceListProps) {
|
|
|
|
|
const { className, current, onChange } = props;
|
|
|
|
|
// QUESTION: Should we use data from the Redux store as admin DS view does?
|
|
|
|
|
const dataSources = useGetDatasources({
|
|
|
|
|
alerting: props.alerting,
|
|
|
|
|
annotations: props.annotations,
|
|
|
|
|
dashboard: props.dashboard,
|
|
|
|
|
logs: props.logs,
|
|
|
|
|
metrics: props.metrics,
|
|
|
|
|
mixed: props.mixed,
|
|
|
|
|
pluginId: props.pluginId,
|
|
|
|
|
tracing: props.tracing,
|
|
|
|
|
type: props.type,
|
|
|
|
|
variables: props.variables,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={className}>
|
|
|
|
|
{dataSources
|
|
|
|
|
.filter((ds) => (props.filter ? props.filter(ds) : true))
|
|
|
|
|
.map((ds) => (
|
2023-04-19 21:08:09 +08:00
|
|
|
<DataSourceCard
|
|
|
|
|
key={ds.uid}
|
|
|
|
|
ds={ds}
|
2023-04-20 18:11:13 +08:00
|
|
|
onClick={() => onChange(ds)}
|
2023-04-19 21:08:09 +08:00
|
|
|
selected={!!isDataSourceMatch(ds, current)}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2023-04-20 18:11:13 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
2023-04-19 21:08:09 +08:00
|
|
|
}
|