Skip to content

Commit

Permalink
Merge pull request #16803 from GordonSmith/HPCC-28749-DESPAY_ERROR_RPT
Browse files Browse the repository at this point in the history
HPCC-28749 Despray action does not report errors

Reviewed-By: Jeremy Clements <jeremy.clements@lexisnexisrisk.com>
Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Merged-by: Gavin Halliday <ghalliday@hpccsystems.com>
  • Loading branch information
ghalliday committed Jan 5, 2023
2 parents c39ccda + a1d11e4 commit b6fad94
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
27 changes: 16 additions & 11 deletions esp/src/src-react/components/forms/DesprayFile.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import * as React from "react";
import { Checkbox, DefaultButton, mergeStyleSets, PrimaryButton, Stack, TextField, } from "@fluentui/react";
import { useForm, Controller } from "react-hook-form";
import { FileSpray, FileSprayService } from "@hpcc-js/comms";
import { scopedLogger } from "@hpcc-js/util";
import nlsHPCC from "src/nlsHPCC";
import * as FileSpray from "src/FileSpray";
import { MessageBox } from "../../layouts/MessageBox";
import { TargetDropzoneTextField, TargetFolderTextField, TargetServerTextField } from "./Fields";
import * as FormStyles from "./landing-zone/styles";

const logger = scopedLogger("src-react/components/forms/DesprayFile.tsx");

const myFileSprayService = new FileSprayService({ baseUrl: "" });

interface DesprayFileFormValues {
destGroup: string;
destIP: string;
Expand Down Expand Up @@ -71,26 +76,26 @@ export const DesprayFile: React.FunctionComponent<DesprayFileProps> = ({
...data,
destPath: [data.destPath, data.sourceLogicalName].join(pathSep),
sourceLogicalName: logicalFiles[0]
};
FileSpray.Despray({ request: request }).then(response => {
} as FileSpray.Despray;
myFileSprayService.Despray(request).then(response => {
closeForm();
reset(defaultValues);
if (refreshGrid) refreshGrid(true);
});
}).catch(err => logger.error(err));
} else {
const requests = [];
logicalFiles.forEach((logicalFile, idx) => {
const request = {
...data,
sourceLogicalName: logicalFile,
destPath: [data.destPath, data.targetName[idx].name].join(pathSep),
};
const requests = [];
requests.push(FileSpray.Despray({ request: request }));
Promise.all(requests).then(_ => {
closeForm();
if (refreshGrid) refreshGrid(true);
});
} as FileSpray.Despray;
requests.push(myFileSprayService.Despray(request));
});
Promise.all(requests).then(_ => {
closeForm();
if (refreshGrid) refreshGrid(true);
}).catch(err => logger.error(err));
}
}
},
Expand Down
28 changes: 16 additions & 12 deletions esp/src/src-react/components/forms/Fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,24 @@ const AsyncDropdown: React.FunctionComponent<AsyncDropdownProps> = ({
}
return [];
}, [options, required]);

const [selectedItem, setSelectedItem] = React.useState<IDropdownOption>();
React.useEffect(() => {
setSelectedItem(selOptions?.find(row => row.key === selectedKey) ?? selOptions[0]);
}, [selectedKey, selOptions]);
const [selectedIdx, setSelectedIdx] = React.useState<number>();

const controlledChange = React.useCallback((event: React.FormEvent<HTMLDivElement>, item: IDropdownOption, idx: number): void => {
React.useEffect(() => {
const item = selOptions?.find(row => row.key === selectedKey) ?? selOptions[0];
setSelectedItem(item);
onChange(event, item, idx);
}, [onChange]);
setSelectedIdx(selOptions.indexOf(selectedItem));
}, [selectedKey, selOptions, onChange, selectedItem]);

React.useEffect(() => {
if (selectedItem !== undefined) {
onChange(undefined, selectedItem, selectedIdx);
}
}, [onChange, selectedItem, selectedIdx]);

return options === undefined ?
<DropdownBase label={label} options={[]} placeholder={nlsHPCC.loadingMessage} disabled={true} /> :
<DropdownBase label={label} options={selOptions} selectedKey={selectedItem?.key} onChange={controlledChange} placeholder={placeholder} disabled={disabled} required={required} errorMessage={errorMessage} className={className} />;
<DropdownBase label={label} options={selOptions} selectedKey={selectedItem?.key} onChange={(_, item: IDropdownOption) => setSelectedItem(item)} placeholder={placeholder} disabled={disabled} required={required} errorMessage={errorMessage} className={className} />;
};

const autoSelectDropdown = (selectedKey?: string, required?: boolean) => selectedKey === undefined && !required;
Expand Down Expand Up @@ -353,7 +357,7 @@ export interface TargetDropzoneTextFieldProps extends Omit<AsyncDropdownProps, "

export const TargetDropzoneTextField: React.FunctionComponent<TargetDropzoneTextFieldProps> = (props) => {

const [targetDropzones, setTargetDropzones] = React.useState<IDropdownOption[]>();
const [targetDropzones, setTargetDropzones] = React.useState<IDropdownOption[] | undefined>();

React.useEffect(() => {
TpDropZoneQuery({}).then(({ TpDropZoneQueryResponse }) => {
Expand All @@ -363,7 +367,7 @@ export const TargetDropzoneTextField: React.FunctionComponent<TargetDropzoneText
text: row.Name,
path: row.Path
};
}) || []);
}));
}).catch(err => logger.error(err));
}, []);

Expand All @@ -376,7 +380,7 @@ export interface TargetServerTextFieldProps extends Omit<AsyncDropdownProps, "op

export const TargetServerTextField: React.FunctionComponent<TargetServerTextFieldProps> = (props) => {

const [targetServers, setTargetServers] = React.useState<IDropdownOption[]>();
const [targetServers, setTargetServers] = React.useState<IDropdownOption[] | undefined>();

React.useEffect(() => {
TpDropZoneQuery({ Name: "" }).then(response => {
Expand All @@ -387,7 +391,7 @@ export const TargetServerTextField: React.FunctionComponent<TargetServerTextFiel
text: n.Netaddress,
OS: n.OS
};
}) || []);
}));
}).catch(err => logger.error(err));
}, [props.selectedKey, props.dropzone]);

Expand Down
22 changes: 12 additions & 10 deletions esp/src/src-react/components/forms/landing-zone/FileListForm.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * as React from "react";
import { Checkbox, DefaultButton, keyframes, mergeStyleSets, PrimaryButton, Stack } from "@fluentui/react";
import { ProgressRingDotsIcon } from "@fluentui/react-icons-mdl2";
import { FileSprayService } from "@hpcc-js/comms";
import { scopedLogger } from "@hpcc-js/util";
import { useForm, Controller } from "react-hook-form";
import { TargetDropzoneTextField, TargetFolderTextField, TargetServerTextLinkedField } from "../Fields";
import * as FileSpray from "src/FileSpray";
import { joinPath } from "src/Utility";
import nlsHPCC from "src/nlsHPCC";
import { MessageBox } from "../../../layouts/MessageBox";
import * as FormStyles from "./styles";

const logger = scopedLogger("src-react/components/forms/landing-zone/FileListForm.tsx");

const myFileSprayService = new FileSprayService({ baseUrl: "" });

interface FileListFormValues {
dropzone: string;
machines: string;
Expand Down Expand Up @@ -94,15 +99,12 @@ export const FileListForm: React.FunctionComponent<FileListFormProps> = ({
uploadFiles(folderPath, selection);
} else {
const fileNames = selection.map(file => file["name"]);
FileSpray.FileList({
request: {
DropZoneName: data.dropzone,
Netaddr: machine,
Path: folderPath
}
}).then(({ FileListResponse }) => {
myFileSprayService.FileList({
Netaddr: machine,
Path: folderPath
}).then((response) => {
let fileName = "";
FileListResponse?.files?.PhysicalFileStruct.forEach(file => {
response?.files?.PhysicalFileStruct.forEach(file => {
if (fileNames.indexOf(file.name) > -1) {
fileName = file.name;
return;
Expand All @@ -113,7 +115,7 @@ export const FileListForm: React.FunctionComponent<FileListFormProps> = ({
} else {
alert(nlsHPCC.OverwriteMessage + "\n" + fileNames.join("\n"));
}
});
}).catch(err => logger.error(err));
}

},
Expand Down

0 comments on commit b6fad94

Please sign in to comment.