Saved Queries: Remove datasource autoselection when opening (#111967)
* Saved Queries: Remove datasource autoselection when opening * Remove auto filtering on query save
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ReactElement } from 'react';
|
||||
|
||||
import { AnnotationQuery, CoreApp, DataSourceApi, DataSourceInstanceSettings } from '@grafana/data';
|
||||
import { AnnotationQuery, CoreApp, DataSourceApi } from '@grafana/data';
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
import { Stack } from '@grafana/ui';
|
||||
import { useQueryLibraryContext } from 'app/features/explore/QueryLibrary/QueryLibraryContext';
|
||||
@@ -11,25 +11,17 @@ interface Props {
|
||||
children: ReactElement;
|
||||
annotation: AnnotationQuery<DataQuery>;
|
||||
datasource: DataSourceApi;
|
||||
datasourceInstanceSettings: DataSourceInstanceSettings;
|
||||
onQueryReplace: (query: DataQuery) => void;
|
||||
}
|
||||
|
||||
export function AnnotationQueryEditorActionsWrapper({
|
||||
children,
|
||||
annotation,
|
||||
datasource,
|
||||
datasourceInstanceSettings,
|
||||
onQueryReplace,
|
||||
}: Props) {
|
||||
export function AnnotationQueryEditorActionsWrapper({ children, annotation, datasource, onQueryReplace }: Props) {
|
||||
const { renderSavedQueryButtons } = useQueryLibraryContext();
|
||||
|
||||
const savedQueryButtons = renderSavedQueryButtons(
|
||||
getDataQueryFromAnnotationForSavedQueries(annotation, datasource),
|
||||
CoreApp.Dashboard,
|
||||
undefined,
|
||||
onQueryReplace,
|
||||
datasourceInstanceSettings?.name ? [datasourceInstanceSettings.name] : []
|
||||
onQueryReplace
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -310,7 +310,6 @@ export default class StandardAnnotationQueryEditor extends PureComponent<Props,
|
||||
<AnnotationQueryEditorActionsWrapper
|
||||
annotation={annotation}
|
||||
datasource={datasource}
|
||||
datasourceInstanceSettings={datasourceInstanceSettings}
|
||||
onQueryReplace={this.onQueryReplace}
|
||||
>
|
||||
<QueryEditor
|
||||
|
||||
@@ -406,7 +406,6 @@ export function PanelDataQueriesTabRendered({ model }: SceneComponentProps<Panel
|
||||
icon="plus"
|
||||
onClick={() =>
|
||||
openQueryLibraryDrawer({
|
||||
datasourceFilters: getDatasourceNames(datasource, queries),
|
||||
onSelectQuery: onSelectQueryFromLibrary,
|
||||
options: {
|
||||
context: CoreApp.PanelEditor,
|
||||
@@ -434,16 +433,6 @@ export function PanelDataQueriesTabRendered({ model }: SceneComponentProps<Panel
|
||||
);
|
||||
}
|
||||
|
||||
function getDatasourceNames(datasource: DataSourceApi, queries: DataQuery[]): string[] {
|
||||
if (datasource.uid === '-- Mixed --') {
|
||||
// If datasource is mixed, the datasource UID is on the query. Here we map the UIDs to datasource names.
|
||||
const dsSrv = getDataSourceSrv();
|
||||
return queries.map((ds) => dsSrv.getInstanceSettings(ds.datasource)?.name).filter((name) => name !== undefined);
|
||||
} else {
|
||||
return [datasource.name];
|
||||
}
|
||||
}
|
||||
|
||||
interface QueriesTabProps extends PanelDataTabHeaderProps {
|
||||
model: PanelDataQueriesTab;
|
||||
}
|
||||
|
||||
@@ -4,14 +4,9 @@ import { CoreApp, GrafanaTheme2 } from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { Trans, t } from '@grafana/i18n';
|
||||
import { ToolbarButton, useTheme2 } from '@grafana/ui';
|
||||
import { useSelector } from 'app/types/store';
|
||||
|
||||
import { createDatasourcesList } from '../../core/utils/richHistory';
|
||||
import { MIXED_DATASOURCE_NAME } from '../../plugins/datasource/mixed/MixedDataSource';
|
||||
|
||||
import { useQueryLibraryContext } from './QueryLibrary/QueryLibraryContext';
|
||||
import { type OnSelectQueryType } from './QueryLibrary/types';
|
||||
import { selectExploreDSMaps } from './state/selectors';
|
||||
|
||||
type Props = {
|
||||
addQueryRowButtonDisabled?: boolean;
|
||||
@@ -45,17 +40,6 @@ export function SecondaryActions({
|
||||
}: Props) {
|
||||
const theme = useTheme2();
|
||||
const styles = getStyles(theme);
|
||||
const exploreActiveDS = useSelector(selectExploreDSMaps);
|
||||
|
||||
// Prefill the query library filter with the dataSource.
|
||||
// Get current dataSource that is open. As this is only used in Explore we get it from Explore state.
|
||||
const listOfDatasources = createDatasourcesList();
|
||||
const activeDatasources = exploreActiveDS.dsToExplore
|
||||
.map((eDs) => {
|
||||
return listOfDatasources.find((ds) => ds.uid === eDs.datasource?.uid)?.name;
|
||||
})
|
||||
.filter((name): name is string => !!name && name !== MIXED_DATASOURCE_NAME);
|
||||
|
||||
const { queryLibraryEnabled, openDrawer: openQueryLibraryDrawer } = useQueryLibraryContext();
|
||||
|
||||
return (
|
||||
@@ -78,7 +62,6 @@ export function SecondaryActions({
|
||||
variant="canvas"
|
||||
onClick={() =>
|
||||
openQueryLibraryDrawer({
|
||||
datasourceFilters: activeDatasources,
|
||||
onSelectQuery: onSelectQueryFromLibrary,
|
||||
options: { context: CoreApp.Explore },
|
||||
})
|
||||
|
||||
@@ -592,13 +592,7 @@ function SavedQueryButtons(props: {
|
||||
datasourceFilters: string[];
|
||||
}) {
|
||||
const { renderSavedQueryButtons } = useQueryLibraryContext();
|
||||
return renderSavedQueryButtons(
|
||||
props.query,
|
||||
props.app,
|
||||
props.onUpdateSuccess,
|
||||
props.onSelectQuery,
|
||||
props.datasourceFilters
|
||||
);
|
||||
return renderSavedQueryButtons(props.query, props.app, props.onUpdateSuccess, props.onSelectQuery);
|
||||
}
|
||||
|
||||
// Will render editing header only if query library is enabled
|
||||
|
||||
Reference in New Issue
Block a user