mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
Library Panels: Fix issue when deleting library panels from folder view (#70413)
This commit is contained in:
parent
cd8e5dc140
commit
a83a040f35
@ -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 }
|
||||
@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user