Skip to content

Commit 310ebd6

Browse files
ammont82machacekondra
authored andcommitted
Upload RVTools file to source in the UI
Signed-off-by: Montse Ortega <mortegag@redhat.com>
1 parent 53a4f7c commit 310ebd6

File tree

8 files changed

+116
-50
lines changed

8 files changed

+116
-50
lines changed

fec.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = {
7474
'./UpdateInventory': path.resolve(__dirname, 'node_modules/@migration-planner-ui/api-client/dist/models/UpdateInventory.js'),
7575
'./Assessment': path.resolve(__dirname, 'node_modules/@migration-planner-ui/api-client/dist/models/Assessment.js'),
7676
'./AssessmentForm': path.resolve(__dirname, 'node_modules/@migration-planner-ui/api-client/dist/models/AssessmentForm.js'),
77-
77+
'./AssessmentApi': path.resolve(__dirname, 'node_modules/@migration-planner-ui/api-client/dist/apis/AssessmentApi.js'),
7878

7979
},
8080
},

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
},
2929
"dependencies": {
3030
"@emotion/css": "^11.13.0",
31-
"@migration-planner-ui/agent-client": "^0.0.14",
32-
"@migration-planner-ui/api-client": "^0.0.14",
33-
"@migration-planner-ui/ioc": "^0.0.14",
31+
"@migration-planner-ui/agent-client": "^0.0.15",
32+
"@migration-planner-ui/api-client": "^0.0.15",
33+
"@migration-planner-ui/ioc": "^0.0.15",
3434
"@patternfly/react-charts": "7.4.1",
3535
"@patternfly/react-core": "^5.4.1",
3636
"@patternfly/react-table": "^5.4.1",

src/migration-wizard/contexts/discovery-sources/@types/DiscoverySources.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ declare namespace DiscoverySources {
3737
updateInventory: (sourceId: string, jsonValue: string) => void;
3838
isUpdatingInventory: boolean;
3939
errorUpdatingInventory?: Error;
40+
uploadRvtoolsFile: (sourceId: string, file: Blob) => Promise<void>;
41+
isUploadingRvtoolsFile: boolean;
42+
errorUploadingRvtoolsFile?: Error;
4043
downloadSourceUrl?: string;
4144
setDownloadUrl?: (url: string) => void;
4245
sourceCreatedId?: string;

src/migration-wizard/contexts/discovery-sources/Provider.tsx

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,27 @@ export const Provider: React.FC<PropsWithChildren> = (props) => {
6161
) => {
6262
try {
6363
// Build the sourceCreate object conditionally
64-
const sourceCreate: any = { name };
64+
const sourceCreate: {
65+
name: string;
66+
sshPublicKey?: string;
67+
proxy?: {
68+
httpUrl?: string;
69+
httpsUrl?: string;
70+
noProxy?: string;
71+
};
72+
} = { name };
6573

6674
// Only include sshPublicKey if it has a value
6775
if (sshPublicKey && sshPublicKey.trim()) {
6876
sourceCreate.sshPublicKey = sshPublicKey;
6977
}
7078

7179
// Only include proxy if at least one proxy field has a value
72-
const proxyFields: any = {};
80+
const proxyFields: {
81+
httpUrl?: string;
82+
httpsUrl?: string;
83+
noProxy?: string;
84+
} = {};
7385
if (httpProxy && httpProxy.trim()) {
7486
proxyFields.httpUrl = httpProxy;
7587
}
@@ -225,6 +237,15 @@ export const Provider: React.FC<PropsWithChildren> = (props) => {
225237
},
226238
);
227239

240+
const [uploadRvtoolsFileState, uploadRvtoolsFile] = useAsyncFn(
241+
async (sourceId: string, file: Blob): Promise<void> => {
242+
await sourceApi.uploadRvtoolsFile({
243+
id: sourceId,
244+
file: file,
245+
});
246+
},
247+
);
248+
228249
const setDownloadUrl = useCallback((url: string) => {
229250
setDownloadSourceUrl(url);
230251
}, []);
@@ -241,16 +262,27 @@ export const Provider: React.FC<PropsWithChildren> = (props) => {
241262
httpsProxy: string,
242263
noProxy: string,
243264
): Promise<void> => {
244-
// Build the sourceCreate object conditionally
245-
const sourceUpdate: any = {};
265+
// Build the sourceUpdate object conditionally
266+
const sourceUpdate: {
267+
sshPublicKey?: string;
268+
proxy?: {
269+
httpUrl?: string;
270+
httpsUrl?: string;
271+
noProxy?: string;
272+
};
273+
} = {};
246274

247275
// Only include sshPublicKey if it has a value
248276
if (sshPublicKey && sshPublicKey.trim()) {
249277
sourceUpdate.sshPublicKey = sshPublicKey;
250278
}
251279

252280
// Only include proxy if at least one proxy field has a value
253-
const proxyFields: any = {};
281+
const proxyFields: {
282+
httpUrl?: string;
283+
httpsUrl?: string;
284+
noProxy?: string;
285+
} = {};
254286
if (httpProxy && httpProxy.trim()) {
255287
proxyFields.httpUrl = httpProxy;
256288
}
@@ -319,6 +351,9 @@ export const Provider: React.FC<PropsWithChildren> = (props) => {
319351
updateInventory,
320352
isUpdatingInventory: updateInventoryState.loading,
321353
errorUpdatingInventory: updateInventoryState.error,
354+
uploadRvtoolsFile,
355+
isUploadingRvtoolsFile: uploadRvtoolsFileState.loading,
356+
errorUploadingRvtoolsFile: uploadRvtoolsFileState.error,
322357
};
323358

324359
return <Context.Provider value={ctx}>{children}</Context.Provider>;

src/migration-wizard/steps/connect/sources-table/actions/UploadInventoryAction.tsx

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { useCallback, useEffect, useState } from 'react';
2-
import { Tooltip, Button, Icon, Modal } from '@patternfly/react-core';
1+
import React, { useCallback } from 'react';
2+
3+
import { Button, Icon, Tooltip } from '@patternfly/react-core';
34
import { UploadIcon } from '@patternfly/react-icons';
45

56
interface UploadInventoryProps {
@@ -20,7 +21,7 @@ export const UploadInventoryAction: React.FC<UploadInventoryProps> = ({
2021
const handleUploadSource = useCallback(() => {
2122
const input = document.createElement('input');
2223
input.type = 'file';
23-
input.accept = '.json';
24+
input.accept = '.json,.xlsx';
2425
input.style.visibility = 'hidden';
2526

2627
input.onchange = async (event: Event) => {
@@ -36,23 +37,49 @@ export const UploadInventoryAction: React.FC<UploadInventoryProps> = ({
3637
return;
3738
}
3839

40+
const fileExtension = file.name.toLowerCase().split('.').pop();
41+
3942
try {
40-
const content = await file.text();
41-
try {
42-
await discoverySourcesContext.updateInventory(
43-
sourceId,
44-
JSON.parse(content),
45-
);
46-
onUploadResult?.('Discovery file uploaded successfully', false);
47-
} catch (error) {
43+
if (fileExtension === 'json') {
44+
// Handle JSON file
45+
const content = await file.text();
46+
try {
47+
await discoverySourcesContext.updateInventory(
48+
sourceId,
49+
JSON.parse(content),
50+
);
51+
onUploadResult?.('Discovery file uploaded successfully', false);
52+
} catch (error) {
53+
onUploadResult?.(
54+
error?.message || 'Failed to update inventory',
55+
true,
56+
);
57+
}
58+
} else if (fileExtension === 'xlsx') {
59+
// Handle Excel file
60+
try {
61+
// Convert File to Blob for the upload
62+
// Use a generic content type that the API accepts
63+
const blob = new Blob([file], {
64+
type: 'application/octet-stream',
65+
});
66+
await discoverySourcesContext.uploadRvtoolsFile(sourceId, blob);
67+
onUploadResult?.('RVTools file uploaded successfully', false);
68+
} catch (error) {
69+
onUploadResult?.(
70+
error?.message || 'Failed to upload RVTools file',
71+
true,
72+
);
73+
}
74+
} else {
4875
onUploadResult?.(
49-
error?.message || 'Failed to update inventory',
76+
'Unsupported file format. Please upload a JSON or Excel (.xlsx) file.',
5077
true,
5178
);
5279
}
5380
} catch (err) {
5481
onUploadResult?.(
55-
'Failed to import inventory. Please check the file format.',
82+
'Failed to import file. Please check the file format.',
5683
true,
5784
);
5885
} finally {
@@ -72,10 +99,10 @@ export const UploadInventoryAction: React.FC<UploadInventoryProps> = ({
7299
onClick={handleUploadSource}
73100
style={{ padding: 0, marginTop: '5px' }}
74101
>
75-
Upload discovery file
102+
Upload discovery file (JSON/Excel)
76103
</Button>
77104
) : (
78-
<Tooltip content="Upload">
105+
<Tooltip content="Upload JSON or Excel file">
79106
<Button variant="plain" onClick={handleUploadSource}>
80107
<Icon size="md" isInline>
81108
<UploadIcon />

webpack.standalone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ module.exports = {
108108
'./UpdateInventory': path.resolve(__dirname, 'node_modules/@migration-planner-ui/api-client/dist/models/UpdateInventory.js'),
109109
'./Assessment': path.resolve(__dirname, 'node_modules/@migration-planner-ui/api-client/dist/models/Assessment.js'),
110110
'./AssessmentForm': path.resolve(__dirname, 'node_modules/@migration-planner-ui/api-client/dist/models/AssessmentForm.js'),
111+
'./AssessmentApi': path.resolve(__dirname, 'node_modules/@migration-planner-ui/api-client/dist/apis/AssessmentApi.js'),
111112
'@redhat-cloud-services/frontend-components/useChrome': path.resolve(__dirname, 'src/standalone-mocks/useChrome-mock.ts'),
112113
'@redhat-cloud-services/frontend-components/InvalidObject': path.resolve(__dirname, 'src/standalone-mocks/frontend-components-mock.tsx'),
113114
'@redhat-cloud-services/frontend-components/PageHeader': path.resolve(__dirname, 'src/standalone-mocks/frontend-components-mock.tsx'),

yarn.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -768,20 +768,20 @@
768768
resolved "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz"
769769
integrity sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==
770770

771-
"@migration-planner-ui/agent-client@^0.0.14":
772-
version "0.0.14"
773-
resolved "https://registry.npmjs.org/@migration-planner-ui/agent-client/-/agent-client-0.0.14.tgz"
774-
integrity sha512-X8DFUFCAbki0jNs0g9VWDjiSQsQ+7n7PqBZt5eP73/keaVorrHXwtyxlcCpRMnrOCW1VR5hoM2eWyYyl9CZaTg==
775-
776-
"@migration-planner-ui/api-client@^0.0.14":
777-
version "0.0.14"
778-
resolved "https://registry.npmjs.org/@migration-planner-ui/api-client/-/api-client-0.0.14.tgz"
779-
integrity sha512-8uxH4kUzeaR5aK6dfOHJ/7RoXbxfDlzvOhxkYHznXQKw7eCLkJOBjG4MxYfKOpHHyrVlJLvT7IacFs7aPwTsvQ==
780-
781-
"@migration-planner-ui/ioc@^0.0.14":
782-
version "0.0.14"
783-
resolved "https://registry.npmjs.org/@migration-planner-ui/ioc/-/ioc-0.0.14.tgz"
784-
integrity sha512-6NSHEPbm8c7B7TmVDtZ17TmpZhsWbnr7AzUJbzANn7VHSlKZGEZPLNzxdtQIDm0Vyajcf6OzKpPn0mx03XE2MQ==
771+
"@migration-planner-ui/agent-client@^0.0.15":
772+
version "0.0.15"
773+
resolved "https://registry.npmjs.org/@migration-planner-ui/agent-client/-/agent-client-0.0.15.tgz"
774+
integrity sha512-4HJinnrmPUz9wuuQjKzpe/fAn9c9Sle5Ev3gZj7mPfFFcvPe/ujp2YGqv4GVhREJ0VufatPKRqP7hYJI3x7mWg==
775+
776+
"@migration-planner-ui/api-client@^0.0.15":
777+
version "0.0.15"
778+
resolved "https://registry.npmjs.org/@migration-planner-ui/api-client/-/api-client-0.0.15.tgz"
779+
integrity sha512-rTthj9mDTF9lTGQUD1QeN69DRDjkk5QGEgPMl635H/kfLOuamMnS1etxKkJuEC9QDfb1Z3WBF+kF09LBU7Fzgg==
780+
781+
"@migration-planner-ui/ioc@^0.0.15":
782+
version "0.0.15"
783+
resolved "https://registry.npmjs.org/@migration-planner-ui/ioc/-/ioc-0.0.15.tgz"
784+
integrity sha512-f48IXdW2hZMAOVZegMlGwGNdsAqyy93pH2fTI78tghgcyHG5yZaXSdD93evU0NtEkfu2E3SbYBOiy5Wdfhl1nw==
785785

786786
"@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1":
787787
version "5.1.1-v1"

0 commit comments

Comments
 (0)