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

This commit is contained in:
Joao Silva 2023-06-21 18:59:59 +09:00 committed by GitHub
parent cd8e5dc140
commit a83a040f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 1 deletions

View File

@ -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,
});
});
});
});
});
});

View File

@ -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 (