Skip to content

Commit

Permalink
[ui-storageBrowser] Update create new folders 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 f8521c5 commit 04f2d2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@ 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 {
file_system: string;
user_home_directory: string;
}

export const mkdir = async (folderName: string, path: string): Promise<void> => {
await post(MAKE_DIRECTORY_API_URL, { name: folderName, 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 04f2d2a

Please sign in to comment.