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 f1634d3c440..58f7141d1ba 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,7 @@ import { i18nReact } from '../../../../utils/i18nReact'; import huePubSub from '../../../../utils/huePubSub'; import useDebounce from '../../../../utils/useDebounce'; -import { mkdir, touch } from '../../../../reactComponents/FileChooser/api'; +import { mkdir, CREATE_FILE_API_URL } from '../../../../reactComponents/FileChooser/api'; import { StorageBrowserTableData, SortOrder, @@ -44,6 +44,7 @@ import Pagination from '../../../../reactComponents/Pagination/Pagination'; import StorageBrowserActions from '../StorageBrowserActions/StorageBrowserActions'; import InputModal from '../../InputModal/InputModal'; import formatBytes from '../../../../utils/formatBytes'; +import useSaveData from '../../../../utils/hooks/useSaveData'; import './StorageBrowserTable.scss'; import { formatTimestamp } from '../../../../utils/dateTimeUtils'; @@ -255,19 +256,18 @@ const StorageBrowserTable = ({ }); }; + const { error: createFileError, save: saveCreateFile } = useSaveData(CREATE_FILE_API_URL); + const handleCreateNewFile = (fileName: string) => { - setLoadingFiles(true); - touch(fileName, filePath) - .then(() => { - refetchData(); - }) - .catch(error => { - huePubSub.publish('hue.error', error); - setShowNewFileModal(false); - }) - .finally(() => { - setLoadingFiles(false); - }); + saveCreateFile( + { path: filePath, name: fileName }, + { + onSuccess: () => refetchData(), + onError: () => { + huePubSub.publish('hue.error', createFileError); + } + } + ); }; const handleSearch = useCallback( diff --git a/desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts b/desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts index 32855e1f797..822dbf9f563 100644 --- a/desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts +++ b/desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts @@ -21,7 +21,8 @@ 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'; -const TOUCH_API_URL = '/api/v1/storage/touch'; + +export const CREATE_FILE_API_URL = '/api/v1/storage/create/file/'; const RENAME_API_URL = '/api/v1/storage/rename'; export interface ApiFileSystem { @@ -33,10 +34,6 @@ export const mkdir = async (folderName: string, path: string): Promise => await post(MAKE_DIRECTORY_API_URL, { name: folderName, path: path }); }; -export const touch = async (fileName: string, path: string): Promise => { - await post(TOUCH_API_URL, { name: fileName, 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 }); };