Skip to content

Commit

Permalink
[ui-storageBrowser] Update create new files based on new public api
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhibhatg committed Nov 4, 2024
1 parent 87c2821 commit f8521c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -33,10 +34,6 @@ export const mkdir = async (folderName: string, path: string): Promise<void> =>
await post(MAKE_DIRECTORY_API_URL, { name: folderName, path: path });
};

export const touch = async (fileName: string, path: string): Promise<void> => {
await post(TOUCH_API_URL, { name: fileName, path: path });
};

export const rename = async (src_path: string, dest_path: string): Promise<void> => {
await post(RENAME_API_URL, { src_path: src_path, dest_path: dest_path });
};

0 comments on commit f8521c5

Please sign in to comment.