From 742686bab19318a2a0d98a8a80f2b165d939d761 Mon Sep 17 00:00:00 2001 From: Ivan Ortega Alba Date: Wed, 10 Aug 2022 09:43:09 +0200 Subject: [PATCH] Library Panels: Use UIDs to list Dashboards using a panel (#53477) --- .../components/DeleteLibraryPanelModal/reducer.ts | 4 ++-- .../OpenLibraryPanelModal/OpenLibraryPanelModal.tsx | 4 ++-- public/app/features/library-panels/state/api.ts | 7 ++++--- public/app/features/library-panels/types.ts | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/public/app/features/library-panels/components/DeleteLibraryPanelModal/reducer.ts b/public/app/features/library-panels/components/DeleteLibraryPanelModal/reducer.ts index 0f019572df4..0dd9029dec1 100644 --- a/public/app/features/library-panels/components/DeleteLibraryPanelModal/reducer.ts +++ b/public/app/features/library-panels/components/DeleteLibraryPanelModal/reducer.ts @@ -2,7 +2,7 @@ import { createAction } from '@reduxjs/toolkit'; import { AnyAction } from 'redux'; import { LoadingState } from '@grafana/data'; -import { DashboardSearchHit } from 'app/features/search/types'; +import { DashboardSearchItem } from 'app/features/search/types'; export interface DeleteLibraryPanelModalState { loadingState: LoadingState; @@ -14,7 +14,7 @@ export const initialDeleteLibraryPanelModalState: DeleteLibraryPanelModalState = dashboardTitles: [], }; -export const searchCompleted = createAction<{ dashboards: DashboardSearchHit[] }>( +export const searchCompleted = createAction<{ dashboards: DashboardSearchItem[] }>( 'libraryPanels/delete/searchCompleted' ); diff --git a/public/app/features/library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal.tsx b/public/app/features/library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal.tsx index ab43e2a1500..608dfc3e5f1 100644 --- a/public/app/features/library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal.tsx +++ b/public/app/features/library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal.tsx @@ -6,7 +6,7 @@ import { GrafanaTheme2, SelectableValue, urlUtil } from '@grafana/data'; import { locationService } from '@grafana/runtime'; 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 { LibraryElementDTO } from '../../types'; @@ -19,7 +19,7 @@ export function OpenLibraryPanelModal({ libraryPanel, onDismiss }: OpenLibraryPa const styles = useStyles2(getStyles); const [loading, setLoading] = useState(false); const [connected, setConnected] = useState(0); - const [option, setOption] = useState | undefined>(undefined); + const [option, setOption] = useState | undefined>(undefined); useEffect(() => { const getConnected = async () => { const connectedDashboards = await getLibraryPanelConnectedDashboards(libraryPanel.uid); diff --git a/public/app/features/library-panels/state/api.ts b/public/app/features/library-panels/state/api.ts index 8ea659de250..9dd20b464c5 100644 --- a/public/app/features/library-panels/state/api.ts +++ b/public/app/features/library-panels/state/api.ts @@ -1,7 +1,7 @@ import { lastValueFrom } from 'rxjs'; import { getBackendSrv } from '../../../core/services/backend_srv'; -import { DashboardSearchHit } from '../../search/types'; +import { DashboardSearchItem } from '../../search/types'; import { LibraryElementConnectionDTO, LibraryElementDTO, @@ -101,12 +101,13 @@ export async function getLibraryPanelConnectedDashboards( return result; } -export async function getConnectedDashboards(uid: string): Promise { +export async function getConnectedDashboards(uid: string): Promise { const connections = await getLibraryPanelConnectedDashboards(uid); if (connections.length === 0) { 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; } diff --git a/public/app/features/library-panels/types.ts b/public/app/features/library-panels/types.ts index 8991ce02872..e66669ca42f 100644 --- a/public/app/features/library-panels/types.ts +++ b/public/app/features/library-panels/types.ts @@ -17,6 +17,7 @@ export interface LibraryElementConnectionDTO { kind: LibraryElementConnectionKind; elementId: number; connectionId: number; + connectionUid: string; created: string; createdBy: LibraryElementDTOMetaUser; }