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

pull/53503/head
Ivan Ortega Alba 3 years ago committed by GitHub
parent e3c50f0cd6
commit 742686bab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      public/app/features/library-panels/components/DeleteLibraryPanelModal/reducer.ts
  2. 4
      public/app/features/library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal.tsx
  3. 7
      public/app/features/library-panels/state/api.ts
  4. 1
      public/app/features/library-panels/types.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'
);

@ -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<SelectableValue<DashboardSearchHit> | undefined>(undefined);
const [option, setOption] = useState<SelectableValue<DashboardSearchItem> | undefined>(undefined);
useEffect(() => {
const getConnected = async () => {
const connectedDashboards = await getLibraryPanelConnectedDashboards(libraryPanel.uid);

@ -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<DashboardSearchHit[]> {
export async function getConnectedDashboards(uid: string): Promise<DashboardSearchItem[]> {
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;
}

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

Loading…
Cancel
Save