Skip to content

Commit 656da83

Browse files
ramprasadagarwalathithyaaselvam
authored andcommitted
[ui-storagebrowser] refactor action component to extend for trash actions (#4023)
1 parent 616640e commit 656da83

38 files changed

+243
-176
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
16+
1617
@use 'variables' as vars;
1718
@use 'mixins';
1819

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
5656
filePath.split('/').pop() !== '' ? (filePath.split('/').pop() ?? '') : filePath.split('://')[0];
5757

5858
const { t } = i18nReact.useTranslation();
59+
5960
const {
6061
data: fileStats,
6162
loading,
@@ -111,17 +112,17 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
111112
setFilePath(fileSystem.user_home_directory);
112113
}}
113114
className="hue-storage-browser__home-bar-btns"
114-
data-event={''}
115-
title={'home'}
115+
data-event=""
116+
title={t('Home')}
116117
icon={<HomeIcon />}
117118
>
118119
{t('Home')}
119120
</BorderlessButton>
120121
<BorderlessButton
121122
onClick={() => reloadData()}
122123
className="hue-storage-browser__home-bar-btns"
123-
data-event={''}
124-
title={'Refresh'}
124+
data-event=""
125+
title={t('Refresh')}
125126
icon={<RefreshIcon />}
126127
>
127128
{t('Refresh')}
@@ -143,7 +144,7 @@ const StorageBrowserTab = ({ fileSystem, testId }: StorageBrowserTabProps): JSX.
143144
<StorageDirectoryPage
144145
fileStats={fileStats}
145146
onFilePathChange={setFilePath}
146-
config={fileSystem.config}
147+
fileSystem={fileSystem}
147148
/>
148149
)}
149150
{fileStats?.type === BrowserViewType.file && !loading && (
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@ import React from 'react';
22
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
33
import '@testing-library/jest-dom';
44
import CreateAndUploadAction from './CreateAndUploadAction';
5-
import { CREATE_DIRECTORY_API_URL, CREATE_FILE_API_URL } from '../../api';
5+
import { CREATE_DIRECTORY_API_URL, CREATE_FILE_API_URL } from '../../../api';
66

77
const mockSave = jest.fn();
8-
jest.mock('../../../../utils/hooks/useSaveData/useSaveData', () => ({
8+
jest.mock('../../../../../utils/hooks/useSaveData/useSaveData', () => ({
99
__esModule: true,
1010
default: jest.fn(() => ({
1111
save: mockSave
1212
}))
1313
}));
1414

15-
jest.mock('../../../../utils/huePubSub', () => ({
15+
jest.mock('../../../../../utils/huePubSub', () => ({
1616
__esModule: true,
1717
publish: jest.fn()
1818
}));
1919

2020
describe('CreateAndUploadAction', () => {
2121
const currentPath = '/some/path';
22-
const onSuccessfulAction = jest.fn();
22+
const onActionSuccess = jest.fn();
23+
const onActionError = jest.fn();
2324
const setLoadingFiles = jest.fn();
2425
const mockFilesUpload = jest.fn();
2526

2627
beforeEach(() => {
2728
render(
2829
<CreateAndUploadAction
2930
currentPath={currentPath}
30-
onSuccessfulAction={onSuccessfulAction}
31+
onActionSuccess={onActionSuccess}
3132
setLoadingFiles={setLoadingFiles}
3233
onFilesUpload={mockFilesUpload}
34+
onActionError={onActionError}
3335
/>
3436
);
3537
});

desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/CreateAndUploadAction/CreateAndUploadAction.tsx renamed to desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageDirectoryActions/CreateAndUpload/CreateAndUploadAction.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ import DropDownIcon from '@cloudera/cuix-core/icons/react/DropdownIcon';
2424
import ImportIcon from '@cloudera/cuix-core/icons/react/ImportIcon';
2525
import { PrimaryButton } from 'cuix/dist/components/Button';
2626

27-
import { i18nReact } from '../../../../utils/i18nReact';
28-
import huePubSub from '../../../../utils/huePubSub';
29-
import { CREATE_DIRECTORY_API_URL, CREATE_FILE_API_URL } from '../../api';
30-
import { FileStats } from '../../types';
31-
import useSaveData from '../../../../utils/hooks/useSaveData/useSaveData';
32-
import InputModal from '../../../../reactComponents/InputModal/InputModal';
27+
import { i18nReact } from '../../../../../utils/i18nReact';
28+
import { CREATE_DIRECTORY_API_URL, CREATE_FILE_API_URL } from '../../../api';
29+
import { FileStats } from '../../../types';
30+
import useSaveData from '../../../../../utils/hooks/useSaveData/useSaveData';
31+
import InputModal from '../../../../../reactComponents/InputModal/InputModal';
3332
import './CreateAndUploadAction.scss';
34-
import DragAndDrop from '../../../../reactComponents/DragAndDrop/DragAndDrop';
33+
import DragAndDrop from '../../../../../reactComponents/DragAndDrop/DragAndDrop';
3534

3635
interface CreateAndUploadActionProps {
3736
currentPath: FileStats['path'];
38-
onSuccessfulAction: () => void;
37+
onActionSuccess: () => void;
3938
setLoadingFiles: (value: boolean) => void;
4039
onFilesUpload: (files: File[]) => void;
40+
onActionError: (error: Error) => void;
4141
}
4242

4343
enum ActionType {
@@ -48,9 +48,10 @@ enum ActionType {
4848

4949
const CreateAndUploadAction = ({
5050
currentPath,
51-
onSuccessfulAction,
51+
onActionSuccess,
5252
setLoadingFiles,
53-
onFilesUpload
53+
onFilesUpload,
54+
onActionError
5455
}: CreateAndUploadActionProps): JSX.Element => {
5556
const { t } = i18nReact.useTranslation();
5657

@@ -66,19 +67,13 @@ const CreateAndUploadAction = ({
6667
};
6768

6869
const onApiSuccess = () => {
69-
setLoadingFiles(false);
7070
onModalClose();
71-
onSuccessfulAction();
72-
};
73-
74-
const onApiError = (error: Error) => {
75-
setLoadingFiles(false);
76-
huePubSub.publish('hue.error', error);
71+
onActionSuccess();
7772
};
7873

7974
const { save, loading } = useSaveData(undefined, {
8075
onSuccess: onApiSuccess,
81-
onError: onApiError
76+
onError: onActionError
8277
});
8378

8479
const onActionClick = (action: ActionType) => () => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { render, fireEvent, waitFor } from '@testing-library/react';
1919
import '@testing-library/jest-dom';
2020
import userEvent from '@testing-library/user-event';
2121
import ChangeOwnerAndGroupModal from './ChangeOwnerAndGroupModal';
22-
import { StorageDirectoryTableData } from '../../../types';
22+
import { StorageDirectoryTableData } from '../../../../types';
2323

2424
const mockFiles: StorageDirectoryTableData[] = [
2525
{
@@ -36,7 +36,7 @@ const mockFiles: StorageDirectoryTableData[] = [
3636
];
3737

3838
const mockSave = jest.fn();
39-
jest.mock('../../../../../utils/hooks/useSaveData/useSaveData', () => ({
39+
jest.mock('../../../../../../utils/hooks/useSaveData/useSaveData', () => ({
4040
__esModule: true,
4141
default: jest.fn(() => ({
4242
save: mockSave,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import React, { useEffect, useMemo, useState } from 'react';
1818
import Modal from 'cuix/dist/components/Modal';
19-
import { i18nReact } from '../../../../../utils/i18nReact';
20-
import useSaveData from '../../../../../utils/hooks/useSaveData/useSaveData';
19+
import { i18nReact } from '../../../../../../utils/i18nReact';
20+
import useSaveData from '../../../../../../utils/hooks/useSaveData/useSaveData';
2121
import { Checkbox, Input, Select } from 'antd';
22-
import { ListDirectory, StorageDirectoryTableData } from '../../../types';
23-
import { BULK_CHANGE_OWNER_API_URL } from '../../../api';
22+
import { ListDirectory, StorageDirectoryTableData } from '../../../../types';
23+
import { BULK_CHANGE_OWNER_API_URL } from '../../../../api';
2424
import './ChangeOwnerAndGroupModal.scss';
2525

2626
interface ChangeOwnerAndGroupModalProps {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import React from 'react';
1818
import { render, fireEvent, waitFor } from '@testing-library/react';
1919
import '@testing-library/jest-dom';
2020
import ChangePermissionModal from './ChangePermissionModal';
21-
import { StorageDirectoryTableData } from '../../../types';
21+
import { StorageDirectoryTableData } from '../../../../types';
2222

2323
const mockFiles: StorageDirectoryTableData[] = [
2424
{
@@ -35,7 +35,7 @@ const mockFiles: StorageDirectoryTableData[] = [
3535
];
3636

3737
const mockSave = jest.fn();
38-
jest.mock('../../../../../utils/hooks/useSaveData/useSaveData', () => ({
38+
jest.mock('../../../../../../utils/hooks/useSaveData/useSaveData', () => ({
3939
__esModule: true,
4040
default: jest.fn(() => ({
4141
save: mockSave,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import React, { useState } from 'react';
1818
import Modal from 'cuix/dist/components/Modal';
19-
import { i18nReact } from '../../../../../utils/i18nReact';
20-
import useSaveData from '../../../../../utils/hooks/useSaveData/useSaveData';
19+
import { i18nReact } from '../../../../../../utils/i18nReact';
20+
import useSaveData from '../../../../../../utils/hooks/useSaveData/useSaveData';
2121
import { Checkbox, Table } from 'antd';
22-
import { StorageDirectoryTableData } from '../../../types';
23-
import { BULK_CHANGE_PERMISSION_API_URL } from '../../../api';
22+
import { StorageDirectoryTableData } from '../../../../types';
23+
import { BULK_CHANGE_PERMISSION_API_URL } from '../../../../api';
2424
import { getInitialPermissions, Permission } from './ChangePermissionModal.util';
2525

2626
import './ChangePermissionModal.scss';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// limitations under the License.
1616

1717
import { getInitialPermissions } from './ChangePermissionModal.util';
18-
import { StorageDirectoryTableData } from '../../../types';
18+
import { StorageDirectoryTableData } from '../../../../types';
1919

2020
describe('getInitialPermissions', () => {
2121
const mockFiles: StorageDirectoryTableData[] = [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
import { StorageDirectoryTableData } from '../../../types';
17+
import { StorageDirectoryTableData } from '../../../../types';
1818

1919
interface entityPermission {
2020
read: boolean;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import React from 'react';
1818
import { render, fireEvent, waitFor } from '@testing-library/react';
1919
import '@testing-library/jest-dom';
2020
import CompressionModal from './CompressionModal';
21-
import { StorageDirectoryTableData } from '../../../types';
21+
import { StorageDirectoryTableData } from '../../../../types';
2222

2323
const mockFiles: StorageDirectoryTableData[] = [
2424
{
@@ -46,7 +46,7 @@ const mockFiles: StorageDirectoryTableData[] = [
4646
];
4747

4848
const mockSave = jest.fn();
49-
jest.mock('../../../../../utils/hooks/useSaveData/useSaveData', () => ({
49+
jest.mock('../../../../../../utils/hooks/useSaveData/useSaveData', () => ({
5050
__esModule: true,
5151
default: jest.fn(() => ({
5252
save: mockSave,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
import React, { useState } from 'react';
1818
import Modal from 'cuix/dist/components/Modal';
19-
import { i18nReact } from '../../../../../utils/i18nReact';
20-
import useSaveData from '../../../../../utils/hooks/useSaveData/useSaveData';
21-
import { StorageDirectoryTableData } from '../../../types';
22-
import { COMPRESS_API_URL } from '../../../api';
19+
import { i18nReact } from '../../../../../../utils/i18nReact';
20+
import useSaveData from '../../../../../../utils/hooks/useSaveData/useSaveData';
21+
import { StorageDirectoryTableData } from '../../../../types';
22+
import { COMPRESS_API_URL } from '../../../../api';
2323
import { Input } from 'antd';
2424

2525
import './CompressionModal.scss';
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1+
// Licensed to Cloudera, Inc. under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. Cloudera, Inc. licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
117
import React from 'react';
218
import { render, fireEvent } from '@testing-library/react';
319
import '@testing-library/jest-dom';
420
import DeletionModal from './DeletionModal';
5-
import { StorageDirectoryTableData } from '../../../types';
6-
import { BULK_DELETION_API_URL, DELETION_API_URL } from '../../../api';
21+
import { StorageDirectoryTableData } from '../../../../types';
22+
import { BULK_DELETION_API_URL, DELETION_API_URL } from '../../../../api';
723

824
const mockFiles: StorageDirectoryTableData[] = [
925
{
@@ -31,7 +47,7 @@ const mockFiles: StorageDirectoryTableData[] = [
3147
];
3248

3349
const mockSave = jest.fn();
34-
jest.mock('../../../../../utils/hooks/useSaveData/useSaveData', () => ({
50+
jest.mock('../../../../../../utils/hooks/useSaveData/useSaveData', () => ({
3551
__esModule: true,
3652
default: jest.fn(() => ({
3753
save: mockSave,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
import React from 'react';
1818
import Modal from 'cuix/dist/components/Modal';
19-
import { i18nReact } from '../../../../../utils/i18nReact';
20-
import useSaveData from '../../../../../utils/hooks/useSaveData/useSaveData';
21-
import { StorageDirectoryTableData } from '../../../types';
22-
import { BULK_DELETION_API_URL, DELETION_API_URL } from '../../../api';
19+
import { i18nReact } from '../../../../../../utils/i18nReact';
20+
import useSaveData from '../../../../../../utils/hooks/useSaveData/useSaveData';
21+
import { StorageDirectoryTableData } from '../../../../types';
22+
import { BULK_DELETION_API_URL, DELETION_API_URL } from '../../../../api';
2323

2424
interface DeletionModalProps {
2525
isOpen?: boolean;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import React from 'react';
1818
import { render, fireEvent, waitFor } from '@testing-library/react';
1919
import '@testing-library/jest-dom';
2020
import ExtractAction from './ExtractionModal';
21-
import { StorageDirectoryTableData } from '../../../types';
21+
import { StorageDirectoryTableData } from '../../../../types';
2222

2323
const mockFile: StorageDirectoryTableData = {
2424
name: 'archive.zip',
@@ -34,7 +34,7 @@ const mockFile: StorageDirectoryTableData = {
3434

3535
const mockSave = jest.fn();
3636
let mockLoading = false;
37-
jest.mock('../../../../../utils/hooks/useSaveData/useSaveData', () => ({
37+
jest.mock('../../../../../../utils/hooks/useSaveData/useSaveData', () => ({
3838
__esModule: true,
3939
default: jest.fn(() => ({
4040
save: mockSave,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
import React from 'react';
1818
import Modal from 'cuix/dist/components/Modal';
19-
import { i18nReact } from '../../../../../utils/i18nReact';
20-
import useSaveData from '../../../../../utils/hooks/useSaveData/useSaveData';
21-
import { StorageDirectoryTableData } from '../../../types';
22-
import { EXTRACT_API_URL } from '../../../api';
19+
import { i18nReact } from '../../../../../../utils/i18nReact';
20+
import useSaveData from '../../../../../../utils/hooks/useSaveData/useSaveData';
21+
import { StorageDirectoryTableData } from '../../../../types';
22+
import { EXTRACT_API_URL } from '../../../../api';
2323

2424
interface ExtractActionProps {
2525
currentPath: string;

0 commit comments

Comments
 (0)