Skip to content

Commit

Permalink
[v10.0.x] Library Panels: Fix issue when deleting library panels from…
Browse files Browse the repository at this point in the history
… folder view (grafana#70942)

Library Panels: Fix issue when deleting library panels from folder view (grafana#70413)

(cherry picked from commit a83a040)

Co-authored-by: Joao Silva <[email protected]>
  • Loading branch information
1 parent ff35f2e commit b2bbe10
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<LibraryPanelsSearchProps> = {},
searchResult: LibraryElementsSearchResult = { elements: [], perPage: 40, page: 1, totalCount: 0 }
Expand Down Expand Up @@ -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,
});
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit b2bbe10

Please sign in to comment.