Skip to content

Commit 1458186

Browse files
[ui-storagebrowser] converts snakecase keys to camel in useLoadData hook (#4011)
1 parent cce0bae commit 1458186

File tree

18 files changed

+520
-126
lines changed

18 files changed

+520
-126
lines changed

apps/filebrowser/src/filebrowser/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def get_all_filesystems(request):
165165
user_home_dir = fs_home_dir_mapping[fs](request.user)
166166
config = _get_config(fs, request)
167167

168-
filesystems.append({'file_system': fs, 'user_home_directory': user_home_dir, 'config': config})
168+
filesystems.append({'name': fs, 'user_home_directory': user_home_dir, 'config': config})
169169

170170
return JsonResponse(filesystems, safe=False)
171171

apps/filebrowser/src/filebrowser/api_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,8 @@ def test_get_all_filesystems_without_hdfs(self):
748748

749749
assert response.status_code == 200
750750
assert response_data == [
751-
{'file_system': 's3a', 'user_home_directory': 's3a://test-bucket/test-user-home-dir/', 'config': {}},
752-
{'file_system': 'ofs', 'user_home_directory': 'ofs://', 'config': {}},
751+
{'name': 's3a', 'user_home_directory': 's3a://test-bucket/test-user-home-dir/', 'config': {}},
752+
{'name': 'ofs', 'user_home_directory': 'ofs://', 'config': {}},
753753
]
754754

755755
def test_get_all_filesystems_success(self):
@@ -776,7 +776,7 @@ def test_get_all_filesystems_success(self):
776776
assert response.status_code == 200
777777
assert response_data == [
778778
{
779-
'file_system': 'hdfs',
779+
'name': 'hdfs',
780780
'user_home_directory': '/user/test-user',
781781
'config': {
782782
'is_trash_enabled': False,
@@ -787,8 +787,8 @@ def test_get_all_filesystems_success(self):
787787
'supergroup': 'test-supergroup',
788788
},
789789
},
790-
{'file_system': 's3a', 'user_home_directory': 's3a://test-bucket/test-user-home-dir/', 'config': {}},
791-
{'file_system': 'ofs', 'user_home_directory': 'ofs://', 'config': {}},
790+
{'name': 's3a', 'user_home_directory': 's3a://test-bucket/test-user-home-dir/', 'config': {}},
791+
{'name': 'ofs', 'user_home_directory': 'ofs://', 'config': {}},
792792
]
793793

794794

desktop/core/src/desktop/js/apps/admin/ServerLogs/ServerLogsTab.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import useLoadData from '../../../utils/hooks/useLoadData/useLoadData';
2424

2525
const mockData = jest.fn().mockReturnValue({
2626
logs: ['Log entry 1', 'Log entry 2'],
27-
hue_hostname: 'test-hostname'
27+
hueHostname: 'test-hostname'
2828
});
2929

3030
const emptyMockData = jest.fn().mockReturnValue({
3131
logs: [],
32-
hue_hostname: 'test-hostname'
32+
hueHostname: 'test-hostname'
3333
});
3434

3535
jest.mock('../../../utils/hooks/useLoadData/useLoadData');

desktop/core/src/desktop/js/apps/admin/ServerLogs/ServerLogsTab.tsx

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,25 @@
1515
// limitations under the License.
1616

1717
import React, { useState } from 'react';
18-
import { Spin, Alert } from 'antd';
18+
import { Alert } from 'antd';
1919
import ServerLogsHeader from './ServerLogsHeader';
2020
import { i18nReact } from '../../../utils/i18nReact';
2121
import useLoadData from '../../../utils/hooks/useLoadData/useLoadData';
22+
import LoadingErrorWrapper from '../../../reactComponents/LoadingErrorWrapper/LoadingErrorWrapper';
2223
import HighlightText from '../Components/HighlightText';
2324
import { SERVER_LOGS_API_URL } from '../Components/utils';
2425
import './ServerLogsTab.scss';
2526

2627
interface ServerLogsData {
2728
logs: string[];
28-
hue_hostname: string;
29+
hueHostname: string;
2930
}
3031

3132
const ServerLogs: React.FC = (): JSX.Element => {
3233
const [filter, setFilter] = useState<string>('');
3334
const [wrapLogs, setWrapLogs] = useState(true);
3435
const { t } = i18nReact.useTranslation();
35-
const {
36-
data: logsData,
37-
loading,
38-
error
39-
} = useLoadData<ServerLogsData>(SERVER_LOGS_API_URL, {
36+
const { data, loading, error } = useLoadData<ServerLogsData>(SERVER_LOGS_API_URL, {
4037
params: {
4138
reverse: true
4239
}
@@ -54,35 +51,31 @@ const ServerLogs: React.FC = (): JSX.Element => {
5451
);
5552
}
5653

54+
const isEmptyLogs = !data?.logs || !data?.logs?.some(log => log.length);
55+
5756
return (
5857
<div className="hue-server-logs-component">
59-
<Spin spinning={loading}>
60-
{!loading && (
61-
<>
62-
<ServerLogsHeader
63-
onFilterChange={setFilter}
64-
onWrapLogsChange={setWrapLogs}
65-
hostName={logsData?.hue_hostname ?? ''}
66-
/>
67-
{logsData && (logsData.logs.length === 0 || logsData.logs[0] === '') && (
68-
<pre className="server__no-logs-found">No logs found!</pre>
69-
)}
70-
71-
{logsData && logsData.logs.length > 0 && logsData.logs[0] !== '' && (
72-
<div className="server__display-logs">
73-
{logsData.logs.map((line, index) => (
74-
<div
75-
className={`server__log-line ${wrapLogs ? 'server__log-line--wrap' : ''}`}
76-
key={'logs_' + index}
77-
>
78-
<HighlightText text={line} searchValue={filter} />
79-
</div>
80-
))}
58+
<LoadingErrorWrapper loading={loading} errors={[]}>
59+
<ServerLogsHeader
60+
onFilterChange={setFilter}
61+
onWrapLogsChange={setWrapLogs}
62+
hostName={data?.hueHostname ?? ''}
63+
/>
64+
{isEmptyLogs ? (
65+
<pre className="server__no-logs-found">No logs found!</pre>
66+
) : (
67+
<div className="server__display-logs">
68+
{data.logs.map((line, index) => (
69+
<div
70+
className={`server__log-line ${wrapLogs ? 'server__log-line--wrap' : ''}`}
71+
key={'logs_' + index}
72+
>
73+
<HighlightText text={line} searchValue={filter} />
8174
</div>
82-
)}
83-
</>
75+
))}
76+
</div>
8477
)}
85-
</Spin>
78+
</LoadingErrorWrapper>
8679
</div>
8780
);
8881
};

desktop/core/src/desktop/js/apps/storageBrowser/StorageBrowserPage.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ const StorageBrowserPage = (): JSX.Element => {
5555
<Tabs
5656
className="hue-storage-browser__tab"
5757
destroyInactiveTabPane
58-
defaultActiveKey={urlFileSystem ?? data?.[0]?.file_system}
59-
items={data?.map(fs => ({
60-
label: fs.file_system.toUpperCase(),
61-
key: fs.file_system,
62-
children: <StorageBrowserTab fileSystem={fs} />
58+
defaultActiveKey={urlFileSystem ?? data?.[0]?.name}
59+
items={data?.map(fileSystem => ({
60+
label: fileSystem.name.toUpperCase(),
61+
key: fileSystem.name,
62+
children: <StorageBrowserTab fileSystem={fileSystem} />
6363
}))}
6464
/>
6565
</LoadingErrorWrapper>

desktop/core/src/desktop/js/apps/storageBrowser/StorageBrowserTab/StorageBrowserTab.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import BucketIcon from '@cloudera/cuix-core/icons/react/BucketIcon';
2222
import PathBrowser from '../../../reactComponents/PathBrowser/PathBrowser';
2323
import StorageDirectoryPage from '../StorageDirectoryPage/StorageDirectoryPage';
2424
import { FILE_STATS_API_URL, TRASH_PATH } from '../api';
25-
import { BrowserViewType, FileStats, FileSystem, TrashPath } from '../types';
25+
import { BrowserViewType, FileStats, FileSystem, TrashData } from '../types';
2626
import useLoadData from '../../../utils/hooks/useLoadData/useLoadData';
2727
import { BorderlessButton } from 'cuix/dist/components/Button';
2828

@@ -52,7 +52,7 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
5252
const urlFilePath = decodeURIComponent(urlSearchParams.get('path') ?? '');
5353
const { fileSystem: urlFileSystem } = getFileSystemAndPath(urlFilePath);
5454
const initialFilePath =
55-
urlFileSystem === fileSystem.file_system ? urlFilePath : fileSystem.user_home_directory;
55+
urlFileSystem === fileSystem.name ? urlFilePath : fileSystem.userHomeDirectory;
5656

5757
const [filePath, setFilePath] = useState<string>(initialFilePath);
5858
const fileName =
@@ -61,21 +61,21 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
6161
const { t } = i18nReact.useTranslation();
6262

6363
const {
64-
data: trashPath,
64+
data: trashData,
6565
loading: trashLoading,
6666
reloadData: onTrashPathReload
67-
} = useLoadData<TrashPath>(TRASH_PATH, {
68-
params: { path: fileSystem.user_home_directory },
69-
skip: !fileSystem.config?.is_trash_enabled || !fileSystem.user_home_directory
67+
} = useLoadData<TrashData>(TRASH_PATH, {
68+
params: { path: fileSystem.userHomeDirectory },
69+
skip: !fileSystem.config?.isTrashEnabled || !fileSystem.userHomeDirectory
7070
});
7171

7272
const onTrashClick = async () => {
7373
const latestTrashData = await onTrashPathReload();
74-
setFilePath(latestTrashData?.trash_path ?? '');
74+
setFilePath(latestTrashData?.trashPath ?? '');
7575
};
7676

7777
const reloadTrashPath = () => {
78-
if (trashPath?.trash_path) {
78+
if (trashData?.trashPath) {
7979
return;
8080
}
8181
onTrashPathReload();
@@ -108,12 +108,12 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
108108
enabled: error?.response?.status === 404,
109109
message: t('Error: Path "{{path}}" not found.', { path: filePath }),
110110
action: t('Go to home directory'),
111-
onClick: () => setFilePath(fileSystem.user_home_directory)
111+
onClick: () => setFilePath(fileSystem.userHomeDirectory)
112112
},
113113
{
114114
enabled: !!error && error?.response?.status !== 404,
115115
message: t('An error occurred while fetching filesystem "{{fileSystem}}".', {
116-
fileSystem: fileSystem.file_system.toUpperCase()
116+
fileSystem: fileSystem.name.toUpperCase()
117117
}),
118118
action: t('Retry'),
119119
onClick: reloadData
@@ -135,7 +135,7 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
135135
<div className="hue-storage-browser__home-bar-right">
136136
<BorderlessButton
137137
onClick={() => {
138-
setFilePath(fileSystem.user_home_directory);
138+
setFilePath(fileSystem.userHomeDirectory);
139139
}}
140140
className="hue-storage-browser__home-bar-btns"
141141
data-event=""
@@ -144,14 +144,14 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
144144
>
145145
{t('Home')}
146146
</BorderlessButton>
147-
{fileSystem.config?.is_trash_enabled && (
147+
{fileSystem.config?.isTrashEnabled && (
148148
<BorderlessButton
149149
onClick={onTrashClick}
150150
className="hue-path-browser__home-btn"
151151
data-event=""
152152
title={t('Trash')}
153153
icon={<DeleteIcon />}
154-
disabled={!trashPath?.trash_path}
154+
disabled={!trashData?.trashPath}
155155
>
156156
{t('Trash')}
157157
</BorderlessButton>
@@ -167,7 +167,7 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
167167
</BorderlessButton>
168168
</div>
169169
</div>
170-
{!!inTrash(filePath) && fileSystem.file_system === 'hdfs' && (
170+
{!!inTrash(filePath) && fileSystem.name === 'hdfs' && (
171171
<Alert
172172
type="warning"
173173
message={t(

desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageDirectoryActions/FileAndFolder/FileAndFolderActions.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import ConfigureIcon from '@cloudera/cuix-core/icons/react/ConfigureIcon';
3535
import { i18nReact } from '../../../../../utils/i18nReact';
3636
import huePubSub from '../../../../../utils/huePubSub';
3737
import './FileAndFolderActions.scss';
38-
import { FileStats, FileSystem, StorageDirectoryTableData } from '../../../types';
38+
import { FileStats, HDFSFileSystemConfig, StorageDirectoryTableData } from '../../../types';
3939
import { ActionType, getEnabledActions } from './FileAndFolderActions.util';
4040
import MoveCopyModal from './MoveCopyModal/MoveCopyModal';
4141
import RenameModal from './RenameModal/RenameModal';
@@ -48,8 +48,16 @@ import { DOWNLOAD_API_URL } from '../../../api';
4848
import ChangeOwnerAndGroupModal from './ChangeOwnerAndGroupModal/ChangeOwnerAndGroupModal';
4949
import ChangePermissionModal from './ChangePermissionModal/ChangePermissionModal';
5050

51+
interface ActionConfig {
52+
isTrashEnabled: HDFSFileSystemConfig['isTrashEnabled'];
53+
isHdfsSuperuser: HDFSFileSystemConfig['isHdfsSuperuser'];
54+
groups: HDFSFileSystemConfig['groups'];
55+
supergroup: HDFSFileSystemConfig['supergroup'];
56+
users: HDFSFileSystemConfig['users'];
57+
superuser: HDFSFileSystemConfig['superuser'];
58+
}
5159
interface StorageBrowserRowActionsProps {
52-
config: FileSystem['config'];
60+
config: ActionConfig;
5361
currentPath: FileStats['path'];
5462
selectedFiles: StorageDirectoryTableData[];
5563
onActionSuccess: () => void;
@@ -105,7 +113,7 @@ const FileAndFolderActions = ({
105113
};
106114

107115
const actionItems: MenuItemType[] = useMemo(() => {
108-
const enabledActions = getEnabledActions(t, selectedFiles, config?.is_hdfs_superuser);
116+
const enabledActions = getEnabledActions(t, selectedFiles, config?.isHdfsSuperuser);
109117
return enabledActions.map(action => ({
110118
key: String(action.type),
111119
label: t(action.label),
@@ -163,7 +171,7 @@ const FileAndFolderActions = ({
163171
)}
164172
{selectedAction === ActionType.Delete && !!selectedFiles.length && (
165173
<DeletionModal
166-
isTrashEnabled={config?.is_trash_enabled}
174+
isTrashEnabled={config?.isTrashEnabled}
167175
files={selectedFiles}
168176
onSuccess={onApiSuccess}
169177
onError={onActionError}

desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageDirectoryActions/FileAndFolder/SummaryModal/SummaryModal.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface SummaryModalProps {
3636
const SummaryModal = ({ isOpen = true, onClose, path }: SummaryModalProps): JSX.Element => {
3737
const { t } = i18nReact.useTranslation();
3838

39-
const { data: responseSummary, loading } = useLoadData<ContentSummary>(CONTENT_SUMMARY_API_URL, {
39+
const { data, loading } = useLoadData<ContentSummary>(CONTENT_SUMMARY_API_URL, {
4040
params: { path: path },
4141
onError: error => {
4242
huePubSub.publish('hue.error', error);
@@ -48,31 +48,31 @@ const SummaryModal = ({ isOpen = true, onClose, path }: SummaryModalProps): JSX.
4848
{
4949
key: 'diskspaceConsumed',
5050
label: t('Diskspace Consumed'),
51-
value: formatBytes(responseSummary?.spaceConsumed)
51+
value: formatBytes(data?.spaceConsumed)
5252
},
53-
{ key: 'bytesUsed', label: t('Bytes Used'), value: formatBytes(responseSummary?.length) },
53+
{ key: 'bytesUsed', label: t('Bytes Used'), value: formatBytes(data?.length) },
5454
{
5555
key: 'namespaceQuota',
5656
label: t('Namespace Quota'),
57-
value: formatBytes(responseSummary?.quota)
57+
value: formatBytes(data?.quota)
5858
},
5959
{
6060
key: 'diskspaceQuota',
6161
label: t('Diskspace Quota'),
62-
value: formatBytes(responseSummary?.spaceQuota)
62+
value: formatBytes(data?.spaceQuota)
6363
},
6464
{
6565
key: 'replicationFactor',
6666
label: t('Replication Factor'),
67-
value: responseSummary?.replication
67+
value: data?.replication
6868
},
6969
{ key: 'blank', label: '', value: '' },
7070
{
7171
key: 'numberOfDirectories',
7272
label: t('Number of Directories'),
73-
value: responseSummary?.directoryCount
73+
value: data?.directoryCount
7474
},
75-
{ key: 'numberOfFiles', label: t('Number of Files'), value: responseSummary?.fileCount }
75+
{ key: 'numberOfFiles', label: t('Number of Files'), value: data?.fileCount }
7676
];
7777

7878
const shortendPath =

desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageDirectoryPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ const StorageDirectoryPage = ({
303303
...rowSelection
304304
}}
305305
scroll={{ y: tableBodyHeight }}
306-
data-testid={`${testId}`}
306+
data-testid={testId}
307307
locale={locale}
308308
{...restProps}
309309
/>
310310

311-
{filesData?.page && filesData?.page?.total_pages > 0 && (
311+
{filesData?.page && filesData?.page?.totalPages > 0 && (
312312
<Pagination
313313
setPageSize={setPageSize}
314314
pageSize={pageSize}

desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ const StorageFilePage = ({ fileName, fileStats, onReload }: StorageFilePageProps
118118
!inTrash(fileStats.path);
119119

120120
const pageStats = {
121-
page_number: pageNumber,
122-
total_pages: Math.ceil(fileStats.size / pageSize),
123-
page_size: 0,
124-
total_size: 0
121+
pageNumber: pageNumber,
122+
totalPages: Math.ceil(fileStats.size / pageSize),
123+
pageSize: 0,
124+
totalSize: 0
125125
};
126126

127127
const errorConfig = [
@@ -208,7 +208,7 @@ const StorageFilePage = ({ fileName, fileStats, onReload }: StorageFilePageProps
208208
readOnly={!isEditing}
209209
className="preview__textarea"
210210
/>
211-
{!loadingPreview && pageStats.total_pages > 1 && (
211+
{pageStats.totalPages > 1 && (
212212
<Pagination setPageNumber={setPageNumber} pageStats={pageStats} />
213213
)}
214214
</div>

0 commit comments

Comments
 (0)