Folder API: Lock delete action to legacy API (#112102)

* Disable new api for delete

* update test
This commit is contained in:
Andrej Ocenas 2025-10-07 13:48:58 +02:00 committed by GitHub
parent 96b5f63711
commit 48930ceef0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 30 deletions

View File

@ -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 () => {

View File

@ -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) {