diff --git a/esp/src/package-lock.json b/esp/src/package-lock.json index c77045112ff..ed4f6e4aed6 100644 --- a/esp/src/package-lock.json +++ b/esp/src/package-lock.json @@ -18,7 +18,7 @@ "@hpcc-js/chart": "2.81.9", "@hpcc-js/codemirror": "2.61.1", "@hpcc-js/common": "2.71.14", - "@hpcc-js/comms": "2.87.0", + "@hpcc-js/comms": "2.88.0", "@hpcc-js/dataflow": "8.1.6", "@hpcc-js/eclwatch": "2.73.33", "@hpcc-js/graph": "2.85.10", @@ -1841,9 +1841,9 @@ } }, "node_modules/@hpcc-js/comms": { - "version": "2.87.0", - "resolved": "https://registry.npmjs.org/@hpcc-js/comms/-/comms-2.87.0.tgz", - "integrity": "sha512-ZEAu/i96kces6nKZOBMbtkgZalRIMYH9gxvRdOg+URK1vTQ6g/RnO6MKxc0BG73ttCMbWVP6Un1XxRAa/sb2Vw==", + "version": "2.88.0", + "resolved": "https://registry.npmjs.org/@hpcc-js/comms/-/comms-2.88.0.tgz", + "integrity": "sha512-Rd+9Ys+DM4Nn++q/V5A5NlXGGaVr8Ww6s06ZmuQVVqbezsRHe6bWlf2HX2y8WFRSRnUVfW38elFjcluowB+1lg==", "dependencies": { "@hpcc-js/ddl-shim": "^2.20.6", "@hpcc-js/util": "^2.50.6", diff --git a/esp/src/package.json b/esp/src/package.json index cc9421ec6a4..080897eb0cc 100644 --- a/esp/src/package.json +++ b/esp/src/package.json @@ -44,7 +44,7 @@ "@hpcc-js/chart": "2.81.9", "@hpcc-js/codemirror": "2.61.1", "@hpcc-js/common": "2.71.14", - "@hpcc-js/comms": "2.87.0", + "@hpcc-js/comms": "2.88.0", "@hpcc-js/dataflow": "8.1.6", "@hpcc-js/eclwatch": "2.73.33", "@hpcc-js/graph": "2.85.10", diff --git a/esp/src/src-react/components/forms/RenameFile.tsx b/esp/src/src-react/components/forms/RenameFile.tsx index 61b88e75d27..eeedfba61a3 100644 --- a/esp/src/src-react/components/forms/RenameFile.tsx +++ b/esp/src/src-react/components/forms/RenameFile.tsx @@ -1,14 +1,17 @@ import * as React from "react"; import { Checkbox, DefaultButton, mergeStyleSets, PrimaryButton, Stack, TextField, } from "@fluentui/react"; +import { useConst } from "@fluentui/react-hooks"; import { useForm, Controller } from "react-hook-form"; +import { FileSprayService, FileSprayStates } 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 { replaceUrl } from "../../util/history"; +import { pushUrl, replaceUrl } from "../../util/history"; import * as FormStyles from "./landing-zone/styles"; +const logger = scopedLogger("src-react/components/forms/RenameFile.tsx"); + interface RenameFileFormValues { - dstname: string; targetRenameFile?: { name: string }[], @@ -16,7 +19,6 @@ interface RenameFileFormValues { } const defaultValues: RenameFileFormValues = { - dstname: "", overwrite: false }; @@ -38,42 +40,61 @@ export const RenameFile: React.FunctionComponent = ({ const { handleSubmit, control, reset } = useForm({ defaultValues }); + const service = useConst(() => new FileSprayService({ baseUrl: "" })); + const closeForm = React.useCallback(() => { setShowForm(false); }, [setShowForm]); const onSubmit = React.useCallback(() => { handleSubmit( - (data, evt) => { - if (logicalFiles?.length > 0) { - if (logicalFiles?.length === 1) { - const request = { ...data, srcname: logicalFiles[0] }; - FileSpray.Rename({ request: request }).then(response => { - closeForm(); + async (data, evt) => { + const renameRequests = []; + const getDfuWuRequests = []; + + logicalFiles.forEach((logicalFile, idx) => { + const request = { ...data, srcname: logicalFile, dstname: data.targetRenameFile[idx].name, DFUServerQueue: "" }; + renameRequests.push(service.Rename(request)); + }); + + const renameResponses = await Promise.all(renameRequests); + renameResponses.forEach(response => { + const wuid = response?.wuid ?? null; + if (wuid) { + getDfuWuRequests.push(service.GetDFUWorkunit({ wuid })); + } + }); + + const getDfuWuResponses = await Promise.all(getDfuWuRequests); + getDfuWuResponses.forEach(response => { + const State = response?.result?.State ?? FileSprayStates.unknown; + const ID = response?.result?.ID; + + if (State === FileSprayStates.failed) { + logger.error(response?.result?.SummaryMessage ?? ""); + if (getDfuWuResponses.length === 1 && ID) { + pushUrl(`/dfuworkunits/${ID}`); + } + } else if (ID) { + if (getDfuWuResponses.length === 1) { if (window.location.hash.match(/#\/files\//) === null) { - if (refreshGrid) refreshGrid(true); + pushUrl(`/dfuworkunits/${ID}`); } else { - replaceUrl(`/files/${data.dstname}`); + replaceUrl(`/dfuworkunits/${ID}`); } - }); - } else { - logicalFiles.forEach((logicalFile, idx) => { - const request = { ...data, srcname: logicalFile, dstname: data.targetRenameFile[idx].name }; - const requests = []; - requests.push(FileSpray.Rename({ request: request })); - Promise.all(requests).then(_ => { - closeForm(); - if (refreshGrid) refreshGrid(true); - }); - }); + } else { + window.setTimeout(function () { window.open(`#/dfuworkunits/${ID}`); }, 0); + } } - } + }); + closeForm(); + if (refreshGrid) refreshGrid(true); }, err => { console.log(err); } )(); - }, [closeForm, handleSubmit, logicalFiles, refreshGrid]); + }, [closeForm, handleSubmit, logicalFiles, refreshGrid, service]); const componentStyles = mergeStyleSets( FormStyles.componentStyles, @@ -85,17 +106,12 @@ export const RenameFile: React.FunctionComponent = ({ ); React.useEffect(() => { - if (logicalFiles.length === 1) { - const newValues = { ...defaultValues, dstname: logicalFiles[0] }; - reset(newValues); - } else if (logicalFiles.length > 1) { - const _files = []; - logicalFiles.forEach(file => { - _files.push({ name: file }); - }); - const newValues = { ...defaultValues, targetRenameFile: _files }; - reset(newValues); - } + const _files = []; + logicalFiles.forEach(file => { + _files.push({ name: file }); + }); + const newValues = { ...defaultValues, targetRenameFile: _files }; + reset(newValues); }, [logicalFiles, reset]); return = ({ {logicalFiles?.length === 1 &&