Library Panels: Use UIDs to list Dashboards using a panel (#53477)

This commit is contained in:
Ivan Ortega Alba
2022-08-10 09:43:09 +02:00
committed by GitHub
parent e3c50f0cd6
commit 742686bab1
4 changed files with 9 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ import { createAction } from '@reduxjs/toolkit';
import { AnyAction } from 'redux'; import { AnyAction } from 'redux';
import { LoadingState } from '@grafana/data'; import { LoadingState } from '@grafana/data';
import { DashboardSearchHit } from 'app/features/search/types'; import { DashboardSearchItem } from 'app/features/search/types';
export interface DeleteLibraryPanelModalState { export interface DeleteLibraryPanelModalState {
loadingState: LoadingState; loadingState: LoadingState;
@@ -14,7 +14,7 @@ export const initialDeleteLibraryPanelModalState: DeleteLibraryPanelModalState =
dashboardTitles: [], dashboardTitles: [],
}; };
export const searchCompleted = createAction<{ dashboards: DashboardSearchHit[] }>( export const searchCompleted = createAction<{ dashboards: DashboardSearchItem[] }>(
'libraryPanels/delete/searchCompleted' 'libraryPanels/delete/searchCompleted'
); );

View File

@@ -6,7 +6,7 @@ import { GrafanaTheme2, SelectableValue, urlUtil } from '@grafana/data';
import { locationService } from '@grafana/runtime'; import { locationService } from '@grafana/runtime';
import { AsyncSelect, Button, Modal, useStyles2 } from '@grafana/ui'; import { AsyncSelect, Button, Modal, useStyles2 } from '@grafana/ui';
import { DashboardSearchHit } from '../../../search/types'; import { DashboardSearchItem } from '../../../search/types';
import { getConnectedDashboards, getLibraryPanelConnectedDashboards } from '../../state/api'; import { getConnectedDashboards, getLibraryPanelConnectedDashboards } from '../../state/api';
import { LibraryElementDTO } from '../../types'; import { LibraryElementDTO } from '../../types';
@@ -19,7 +19,7 @@ export function OpenLibraryPanelModal({ libraryPanel, onDismiss }: OpenLibraryPa
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [connected, setConnected] = useState(0); const [connected, setConnected] = useState(0);
const [option, setOption] = useState<SelectableValue<DashboardSearchHit> | undefined>(undefined); const [option, setOption] = useState<SelectableValue<DashboardSearchItem> | undefined>(undefined);
useEffect(() => { useEffect(() => {
const getConnected = async () => { const getConnected = async () => {
const connectedDashboards = await getLibraryPanelConnectedDashboards(libraryPanel.uid); const connectedDashboards = await getLibraryPanelConnectedDashboards(libraryPanel.uid);

View File

@@ -1,7 +1,7 @@
import { lastValueFrom } from 'rxjs'; import { lastValueFrom } from 'rxjs';
import { getBackendSrv } from '../../../core/services/backend_srv'; import { getBackendSrv } from '../../../core/services/backend_srv';
import { DashboardSearchHit } from '../../search/types'; import { DashboardSearchItem } from '../../search/types';
import { import {
LibraryElementConnectionDTO, LibraryElementConnectionDTO,
LibraryElementDTO, LibraryElementDTO,
@@ -101,12 +101,13 @@ export async function getLibraryPanelConnectedDashboards(
return result; return result;
} }
export async function getConnectedDashboards(uid: string): Promise<DashboardSearchHit[]> { export async function getConnectedDashboards(uid: string): Promise<DashboardSearchItem[]> {
const connections = await getLibraryPanelConnectedDashboards(uid); const connections = await getLibraryPanelConnectedDashboards(uid);
if (connections.length === 0) { if (connections.length === 0) {
return []; return [];
} }
const searchHits = await getBackendSrv().search({ dashboardIds: connections.map((c) => c.connectionId) }); const searchHits = await getBackendSrv().search({ dashboardUIDs: connections.map((c) => c.connectionUid) });
return searchHits; return searchHits;
} }

View File

@@ -17,6 +17,7 @@ export interface LibraryElementConnectionDTO {
kind: LibraryElementConnectionKind; kind: LibraryElementConnectionKind;
elementId: number; elementId: number;
connectionId: number; connectionId: number;
connectionUid: string;
created: string; created: string;
createdBy: LibraryElementDTOMetaUser; createdBy: LibraryElementDTOMetaUser;
} }