mirror of https://github.com/grafana/grafana.git
Folder API: Lock delete action to legacy API (#112102)
* Disable new api for delete * update test
This commit is contained in:
parent
96b5f63711
commit
48930ceef0
|
@ -166,23 +166,14 @@ describe('useDeleteMultipleFoldersMutationFacade', () => {
|
||||||
|
|
||||||
it('deletes multiple folders and publishes success alert', async () => {
|
it('deletes multiple folders and publishes success alert', async () => {
|
||||||
config.featureToggles.foldersAppPlatformAPI = true;
|
config.featureToggles.foldersAppPlatformAPI = true;
|
||||||
|
// Same test as for legacy as right now we always use legacy API for deletes.
|
||||||
const folderUIDs = ['uid1', 'uid2'];
|
const folderUIDs = ['uid1', 'uid2'];
|
||||||
const deleteFolders = useDeleteMultipleFoldersMutationFacade();
|
const deleteFolders = useDeleteMultipleFoldersMutationFacade();
|
||||||
await deleteFolders({ folderUIDs });
|
await deleteFolders({ folderUIDs });
|
||||||
|
|
||||||
// Should call deleteFolder for each UID
|
// Should call deleteFolder for each UID
|
||||||
expect(mockDeleteFolder).toHaveBeenCalledTimes(folderUIDs.length);
|
expect(mockDeleteFolderLegacy).toHaveBeenCalledTimes(1);
|
||||||
expect(mockDeleteFolder).toHaveBeenCalledWith({ name: 'uid1' });
|
expect(mockDeleteFolderLegacy).toHaveBeenCalledWith({ folderUIDs });
|
||||||
expect(mockDeleteFolder).toHaveBeenCalledWith({ name: 'uid2' });
|
|
||||||
|
|
||||||
// Should publish success alert
|
|
||||||
expect(publishMockFn).toHaveBeenCalledWith({
|
|
||||||
type: AppEvents.alertSuccess.name,
|
|
||||||
payload: ['Folder deleted'],
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should dispatch refreshParents
|
|
||||||
expect(dispatchMockFn).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses legacy call when flag is false', async () => {
|
it('uses legacy call when flag is false', async () => {
|
||||||
|
|
|
@ -172,37 +172,41 @@ export function useGetFolderQueryFacade(uid?: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useDeleteFolderMutationFacade() {
|
export function useDeleteFolderMutationFacade() {
|
||||||
const [deleteFolder] = useDeleteFolderMutation();
|
const [deleteFolderMutation] = useDeleteFolderMutation();
|
||||||
const [deleteFolderLegacy] = useDeleteFolderMutationLegacy();
|
const [deleteFolderLegacy] = useDeleteFolderMutationLegacy();
|
||||||
const refresh = useRefreshFolders();
|
const refresh = useRefreshFolders();
|
||||||
const notify = useAppNotification();
|
const notify = useAppNotification();
|
||||||
|
|
||||||
return async (folder: FolderDTO) => {
|
// TODO right now the app platform backend does not support cascading delete of children so we cannot use it.
|
||||||
if (config.featureToggles.foldersAppPlatformAPI) {
|
const isBackendSupport = false;
|
||||||
const result = await deleteFolder({ name: folder.uid });
|
if (!(config.featureToggles.foldersAppPlatformAPI && isBackendSupport)) {
|
||||||
if (!result.error) {
|
return deleteFolderLegacy;
|
||||||
// we could do this in the enhanceEndpoint method, but we would also need to change the args as we need parentUID
|
}
|
||||||
// here and so it seemed easier to do it here.
|
|
||||||
refresh({ childrenOf: folder.parentUid });
|
return async function deleteFolder(folder: FolderDTO) {
|
||||||
// Before this was done in backend srv automatically because the old API sent a message wiht 200 request. see
|
const result = await deleteFolderMutation({ name: folder.uid });
|
||||||
// public/app/core/services/backend_srv.ts#L341-L361. New API does not do that so we do it here.
|
if (!result.error) {
|
||||||
notify.success(t('folders.api.folder-deleted-success', 'Folder deleted'));
|
// we could do this in the enhanceEndpoint method, but we would also need to change the args as we need parentUID
|
||||||
}
|
// here and so it seemed easier to do it here.
|
||||||
return result;
|
refresh({ childrenOf: folder.parentUid });
|
||||||
} else {
|
// Before this was done in backend srv automatically because the old API sent a message wiht 200 request. see
|
||||||
return deleteFolderLegacy(folder);
|
// public/app/core/services/backend_srv.ts#L341-L361. New API does not do that so we do it here.
|
||||||
|
notify.success(t('folders.api.folder-deleted-success', 'Folder deleted'));
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useDeleteMultipleFoldersMutationFacade() {
|
export function useDeleteMultipleFoldersMutationFacade() {
|
||||||
const [deleteFolders] = useDeleteFoldersMutationLegacy();
|
const [deleteFoldersLegacy] = useDeleteFoldersMutationLegacy();
|
||||||
const [deleteFolder] = useDeleteFolderMutation();
|
const [deleteFolder] = useDeleteFolderMutation();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const refresh = useRefreshFolders();
|
const refresh = useRefreshFolders();
|
||||||
|
|
||||||
if (!config.featureToggles.foldersAppPlatformAPI) {
|
// TODO right now the app platform backend does not support cascading delete of children so we cannot use it.
|
||||||
return deleteFolders;
|
const isBackendSupport = false;
|
||||||
|
if (!(config.featureToggles.foldersAppPlatformAPI && isBackendSupport)) {
|
||||||
|
return deleteFoldersLegacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
return async function deleteFolders({ folderUIDs }: DeleteFoldersArgs) {
|
return async function deleteFolders({ folderUIDs }: DeleteFoldersArgs) {
|
||||||
|
|
Loading…
Reference in New Issue