@@ -22,20 +22,15 @@ import BucketIcon from '@cloudera/cuix-core/icons/react/BucketIcon';
2222
2323import PathBrowser from '../../../../reactComponents/FileChooser/PathBrowser/PathBrowser' ;
2424import StorageBrowserTable from '../StorageBrowserTable/StorageBrowserTable' ;
25- import { VIEWFILES_API_URl } from '../../../../reactComponents/FileChooser/api' ;
26- import {
27- BrowserViewType ,
28- PathAndFileData ,
29- SortOrder
30- } from '../../../../reactComponents/FileChooser/types' ;
31- import { DEFAULT_PAGE_SIZE } from '../../../../utils/constants/storageBrowser' ;
25+ import { FILE_STATS_API_URL } from '../../../../reactComponents/FileChooser/api' ;
26+ import { BrowserViewType , FileStats } from '../../../../reactComponents/FileChooser/types' ;
3227import useLoadData from '../../../../utils/hooks/useLoadData' ;
3328
3429import './StorageBrowserTabContent.scss' ;
3530import StorageFilePage from '../../StorageFilePage/StorageFilePage' ;
3631
3732interface StorageBrowserTabContentProps {
38- user_home_dir : string ;
33+ homeDir : string ;
3934 testId ?: string ;
4035}
4136
@@ -44,31 +39,19 @@ const defaultProps = {
4439} ;
4540
4641const StorageBrowserTabContent = ( {
47- user_home_dir ,
42+ homeDir ,
4843 testId
4944} : StorageBrowserTabContentProps ) : JSX . Element => {
50- const [ filePath , setFilePath ] = useState < string > ( user_home_dir ) ;
51- const [ pageSize , setPageSize ] = useState < number > ( DEFAULT_PAGE_SIZE ) ;
52- const [ pageNumber , setPageNumber ] = useState < number > ( 1 ) ;
53- const [ sortByColumn , setSortByColumn ] = useState < string > ( '' ) ;
54- const [ sortOrder , setSortOrder ] = useState < SortOrder > ( SortOrder . NONE ) ;
55- const [ searchTerm , setSearchTerm ] = useState < string > ( '' ) ;
45+ const [ filePath , setFilePath ] = useState < string > ( homeDir ) ;
46+ const fileName = filePath ?. split ( '/' ) ?. pop ( ) ?? '' ;
5647
5748 const { t } = i18nReact . useTranslation ( ) ;
5849
59- const {
60- data : filesData ,
61- loading,
62- reloadData
63- } = useLoadData < PathAndFileData > ( `${ VIEWFILES_API_URl } ${ filePath } ` , {
50+ const { data : fileStats , loading } = useLoadData < FileStats > ( FILE_STATS_API_URL , {
6451 params : {
65- pagesize : pageSize . toString ( ) ,
66- pagenum : pageNumber . toString ( ) ,
67- filter : searchTerm ,
68- sortby : sortByColumn ,
69- descending : sortOrder === SortOrder . DSC ? 'true' : 'false'
52+ path : filePath
7053 } ,
71- skip : filePath === '' || filePath === undefined
54+ skip : ! filePath
7255 } ) ;
7356
7457 return (
@@ -77,7 +60,7 @@ const StorageBrowserTabContent = ({
7760 < div className = "hue-storage-browser__title-bar" data-testid = { `${ testId } -title-bar` } >
7861 < BucketIcon className = "hue-storage-browser__icon" data-testid = { `${ testId } -icon` } />
7962 < h3 className = "hue-storage-browser__folder-name" data-testid = { `${ testId } -folder-namer` } >
80- { filesData ?. path ?. split ( '/' ) . pop ( ) }
63+ { fileName }
8164 </ h3 >
8265 </ div >
8366 < div
@@ -92,23 +75,11 @@ const StorageBrowserTabContent = ({
9275 showIcon = { false }
9376 />
9477 </ div >
95- { filesData ?. type === BrowserViewType . file ? (
96- < StorageFilePage fileData = { filesData } />
97- ) : (
98- < StorageBrowserTable
99- filesData = { filesData }
100- pageSize = { pageSize }
101- onFilepathChange = { setFilePath }
102- onPageSizeChange = { setPageSize }
103- onPageNumberChange = { setPageNumber }
104- onSortByColumnChange = { setSortByColumn }
105- onSortOrderChange = { setSortOrder }
106- onSearch = { setSearchTerm }
107- sortByColumn = { sortByColumn }
108- sortOrder = { sortOrder }
109- refetchData = { reloadData }
110- filePath = { filePath }
111- />
78+ { fileStats ?. type === BrowserViewType . dir && (
79+ < StorageBrowserTable fileStats = { fileStats } onFilePathChange = { setFilePath } />
80+ ) }
81+ { fileStats ?. type === BrowserViewType . file && (
82+ < StorageFilePage fileName = { fileName } fileStats = { fileStats } />
11283 ) }
11384 </ div >
11485 </ Spin >
0 commit comments