diff --git a/desktop/core/src/desktop/js/apps/storageBrowser/StorageBrowserPage/StorageBrowserTable/StorageBrowserTable.tsx b/desktop/core/src/desktop/js/apps/storageBrowser/StorageBrowserPage/StorageBrowserTable/StorageBrowserTable.tsx index 58f7141d1ba..f89577f6fe2 100644 --- a/desktop/core/src/desktop/js/apps/storageBrowser/StorageBrowserPage/StorageBrowserTable/StorageBrowserTable.tsx +++ b/desktop/core/src/desktop/js/apps/storageBrowser/StorageBrowserPage/StorageBrowserTable/StorageBrowserTable.tsx @@ -34,7 +34,10 @@ import { i18nReact } from '../../../../utils/i18nReact'; import huePubSub from '../../../../utils/huePubSub'; import useDebounce from '../../../../utils/useDebounce'; -import { mkdir, CREATE_FILE_API_URL } from '../../../../reactComponents/FileChooser/api'; +import { + CREATE_DIRECTORY_API_URL, + CREATE_FILE_API_URL +} from '../../../../reactComponents/FileChooser/api'; import { StorageBrowserTableData, SortOrder, @@ -241,19 +244,19 @@ const StorageBrowserTable = ({ onPageNumberChange(nextPageNumber === 0 ? numPages : nextPageNumber); }; + const { error: createFolderError, save: saveCreateFolder } = + useSaveData(CREATE_DIRECTORY_API_URL); + const handleCreateNewFolder = (folderName: string) => { - setLoadingFiles(true); - mkdir(folderName, filePath) - .then(() => { - refetchData(); - }) - .catch(error => { - huePubSub.publish('hue.error', error); - setShowNewFolderModal(false); - }) - .finally(() => { - setLoadingFiles(false); - }); + saveCreateFolder( + { path: filePath, name: folderName }, + { + onSuccess: () => refetchData(), + onError: () => { + huePubSub.publish('hue.error', createFolderError); + } + } + ); }; const { error: createFileError, save: saveCreateFile } = useSaveData(CREATE_FILE_API_URL); diff --git a/desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts b/desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts index 822dbf9f563..64735682fbc 100644 --- a/desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts +++ b/desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts @@ -20,9 +20,9 @@ export const DOWNLOAD_API_URL = '/filebrowser/download='; export const FILESYSTEMS_API_URL = '/api/v1/storage/filesystems'; export const SAVE_FILE_API_URL = '/filebrowser/save'; export const VIEWFILES_API_URl = '/api/v1/storage/view='; -const MAKE_DIRECTORY_API_URL = '/api/v1/storage/mkdir'; export const CREATE_FILE_API_URL = '/api/v1/storage/create/file/'; +export const CREATE_DIRECTORY_API_URL = '/api/v1/storage/create/directory/'; const RENAME_API_URL = '/api/v1/storage/rename'; export interface ApiFileSystem { @@ -30,10 +30,6 @@ export interface ApiFileSystem { user_home_directory: string; } -export const mkdir = async (folderName: string, path: string): Promise => { - await post(MAKE_DIRECTORY_API_URL, { name: folderName, path: path }); -}; - export const rename = async (src_path: string, dest_path: string): Promise => { await post(RENAME_API_URL, { src_path: src_path, dest_path: dest_path }); };