From a83a040f351bb20941af48211bf49dbac28a377f Mon Sep 17 00:00:00 2001 From: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com> Date: Wed, 21 Jun 2023 18:59:59 +0900 Subject: [PATCH] Library Panels: Fix issue when deleting library panels from folder view (#70413) --- .../LibraryPanelsSearch.test.tsx | 52 +++++++++++++++++++ .../LibraryPanelsView/LibraryPanelsView.tsx | 11 +++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/public/app/features/library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch.test.tsx b/public/app/features/library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch.test.tsx index 3adc501b882..a2cf52e73a5 100644 --- a/public/app/features/library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch.test.tsx +++ b/public/app/features/library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch.test.tsx @@ -40,6 +40,8 @@ jest.mock('debounce-promise', () => { return debounce; }); +jest.spyOn(api, 'getConnectedDashboards').mockResolvedValue([]); +jest.spyOn(api, 'deleteLibraryPanel').mockResolvedValue({ message: 'success' }); async function getTestContext( propOverrides: Partial = {}, searchResult: LibraryElementsSearchResult = { elements: [], perPage: 40, page: 1, totalCount: 0 } @@ -319,4 +321,54 @@ describe('LibraryPanelsSearch', () => { expect(within(card()).getByLabelText(/delete button on panel type card/i)).toBeInTheDocument(); }); }); + + describe('when mounted with showSecondaryActions and a specific folder', () => { + describe('and user deletes a panel', () => { + it('should call api with correct params', async () => { + const { getLibraryPanelsSpy } = await getTestContext( + { showSecondaryActions: true, currentFolderUID: 'wfTJJL5Wz' }, + { + elements: [ + { + name: 'Library Panel Name', + uid: 'uid', + description: 'Library Panel Description', + folderUid: 'wfTJJL5Wz', + model: { type: 'timeseries', title: 'A title' } as Panel, + type: 'timeseries', + version: 1, + meta: { + folderName: 'General', + folderUid: '', + connectedDashboards: 0, + created: '2021-01-01 12:00:00', + createdBy: { id: 1, name: 'Admin', avatarUrl: '' }, + updated: '2021-01-01 12:00:00', + updatedBy: { id: 1, name: 'Admin', avatarUrl: '' }, + }, + }, + ], + perPage: 40, + page: 1, + totalCount: 1, + } + ); + + await userEvent.click(screen.getByLabelText(/delete button on panel type card/i)); + await waitFor(() => expect(screen.getByText('Do you want to delete this panel?')).toBeInTheDocument()); + await userEvent.click(screen.getByRole('button', { name: 'Delete' })); + + await waitFor(() => { + expect(getLibraryPanelsSpy).toHaveBeenCalledWith({ + searchString: '', + folderFilterUIDs: ['wfTJJL5Wz'], + page: 1, + typeFilter: [], + sortDirection: undefined, + perPage: 40, + }); + }); + }); + }); + }); }); diff --git a/public/app/features/library-panels/components/LibraryPanelsView/LibraryPanelsView.tsx b/public/app/features/library-panels/components/LibraryPanelsView/LibraryPanelsView.tsx index 25877436cb0..c34855dbc52 100644 --- a/public/app/features/library-panels/components/LibraryPanelsView/LibraryPanelsView.tsx +++ b/public/app/features/library-panels/components/LibraryPanelsView/LibraryPanelsView.tsx @@ -61,7 +61,16 @@ export const LibraryPanelsView = ({ [searchString, sortDirection, panelFilter, folderFilter, page, asyncDispatch] ); const onDelete = ({ uid }: LibraryElementDTO) => - asyncDispatch(deleteLibraryPanel(uid, { searchString, page, perPage })); + asyncDispatch( + deleteLibraryPanel(uid, { + searchString, + sortDirection, + panelFilter, + folderFilterUIDs: folderFilter, + page, + perPage, + }) + ); const onPageChange = (page: number) => asyncDispatch(changePage({ page })); return (