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 () => {
config.featureToggles.foldersAppPlatformAPI = true;
// Same test as for legacy as right now we always use legacy API for deletes.
const folderUIDs = ['uid1', 'uid2'];
const deleteFolders = useDeleteMultipleFoldersMutationFacade();
await deleteFolders({ folderUIDs });
// Should call deleteFolder for each UID
expect(mockDeleteFolder).toHaveBeenCalledTimes(folderUIDs.length);
expect(mockDeleteFolder).toHaveBeenCalledWith({ name: 'uid1' });
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();
expect(mockDeleteFolderLegacy).toHaveBeenCalledTimes(1);
expect(mockDeleteFolderLegacy).toHaveBeenCalledWith({ folderUIDs });
});
it('uses legacy call when flag is false', async () => {

View File

@ -172,37 +172,41 @@ export function useGetFolderQueryFacade(uid?: string) {
}
export function useDeleteFolderMutationFacade() {
const [deleteFolder] = useDeleteFolderMutation();
const [deleteFolderMutation] = useDeleteFolderMutation();
const [deleteFolderLegacy] = useDeleteFolderMutationLegacy();
const refresh = useRefreshFolders();
const notify = useAppNotification();
return async (folder: FolderDTO) => {
if (config.featureToggles.foldersAppPlatformAPI) {
const result = await deleteFolder({ name: folder.uid });
if (!result.error) {
// 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 });
// Before this was done in backend srv automatically because the old API sent a message wiht 200 request. see
// 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;
} else {
return deleteFolderLegacy(folder);
// TODO right now the app platform backend does not support cascading delete of children so we cannot use it.
const isBackendSupport = false;
if (!(config.featureToggles.foldersAppPlatformAPI && isBackendSupport)) {
return deleteFolderLegacy;
}
return async function deleteFolder(folder: FolderDTO) {
const result = await deleteFolderMutation({ name: folder.uid });
if (!result.error) {
// 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 });
// Before this was done in backend srv automatically because the old API sent a message wiht 200 request. see
// 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() {
const [deleteFolders] = useDeleteFoldersMutationLegacy();
const [deleteFoldersLegacy] = useDeleteFoldersMutationLegacy();
const [deleteFolder] = useDeleteFolderMutation();
const dispatch = useDispatch();
const refresh = useRefreshFolders();
if (!config.featureToggles.foldersAppPlatformAPI) {
return deleteFolders;
// TODO right now the app platform backend does not support cascading delete of children so we cannot use it.
const isBackendSupport = false;
if (!(config.featureToggles.foldersAppPlatformAPI && isBackendSupport)) {
return deleteFoldersLegacy;
}
return async function deleteFolders({ folderUIDs }: DeleteFoldersArgs) {