Skip to content

Commit

Permalink
HPCC-31920 ECL Watch v9 fix error deleting last subfile
Browse files Browse the repository at this point in the history
Fixes an issue in ECL Watch v9 where attempting to delete the last
subfile of a superfile would cause the subfile to not be properly
removed and an exception to be logged.

Signed-off-by: Jeremy Clements <[email protected]>
  • Loading branch information
jeclrsg committed Jun 26, 2024
1 parent 5223d6f commit 54b03f4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
4 changes: 2 additions & 2 deletions esp/src/src-react/components/FileDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export const FileDetails: React.FunctionComponent<FileDetailsProps> = ({
}) => {
const [file] = useFile(cluster, logicalFile);
React.useEffect(() => {
if (file?.NodeGroup && cluster === undefined) {
if (file?.NodeGroup && cluster === undefined && !file?.isSuperfile) {
replaceUrl(`/files/${file.NodeGroup}/${logicalFile}`);
}
}, [cluster, file?.NodeGroup, logicalFile]);
}, [cluster, file?.NodeGroup, file?.isSuperfile, logicalFile]);
const [defFile] = useDefFile(cluster, logicalFile, WsDfu.DFUDefFileFormat.def);
const [xmlFile] = useDefFile(cluster, logicalFile, WsDfu.DFUDefFileFormat.xml);

Expand Down
2 changes: 1 addition & 1 deletion esp/src/src-react/components/LogicalFileSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const LogicalFileSummary: React.FunctionComponent<LogicalFileSummaryProps
<TableGroup fields={{
"Wuid": { label: nlsHPCC.Workunit, type: "link", value: file?.Wuid, href: `#/${isDFUWorkunit ? "dfu" : ""}workunits/${file?.Wuid}`, readonly: true, },
"Owner": { label: nlsHPCC.Owner, type: "string", value: file?.Owner, readonly: true },
"SuperOwner": { label: nlsHPCC.SuperFile, type: "links", links: file?.Superfiles?.DFULogicalFile?.map(row => ({ label: "", type: "link", value: row.Name, href: `#/files/${row.Name}` })) },
"SuperOwner": { label: nlsHPCC.SuperFile, type: "links", links: file?.Superfiles?.DFULogicalFile?.map(row => ({ label: "", type: "link", value: row.Name, href: `#/files/${row.NodeGroup !== null ? row.NodeGroup : undefined}/${row.Name}` })) },
"NodeGroup": { label: nlsHPCC.ClusterName, type: "string", value: file?.NodeGroup, readonly: true },
"Description": { label: nlsHPCC.Description, type: "string", value: description },
"JobName": { label: nlsHPCC.JobName, type: "string", value: file?.JobName, readonly: true },
Expand Down
34 changes: 22 additions & 12 deletions esp/src/src-react/components/SubFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import nlsHPCC from "src/nlsHPCC";
import { QuerySortItem } from "src/store/Store";
import * as WsDfu from "src/WsDfu";
import { useConfirm } from "../hooks/confirm";
import { useFile } from "../hooks/file";
import { useFile, useSubfiles } from "../hooks/file";
import { FluentGrid, useCopyButtons, useFluentStoreState, FluentColumns } from "./controls/Grid";
import { ShortVerticalDivider } from "./Common";
import { pushUrl } from "../util/history";
import { pushUrl, replaceUrl } from "../util/history";

const defaultUIState = {
hasSelection: false,
Expand All @@ -28,7 +28,8 @@ export const SubFiles: React.FunctionComponent<SubFilesProps> = ({
sort = defaultSort
}) => {

const [file, , , refresh] = useFile(cluster, logicalFile);
const [file] = useFile(cluster, logicalFile);
const [subfiles, refreshSubfiles] = useSubfiles(cluster, logicalFile);
const [uiState, setUIState] = React.useState({ ...defaultUIState });
const [data, setData] = React.useState<any[]>([]);
const {
Expand Down Expand Up @@ -101,26 +102,35 @@ export const SubFiles: React.FunctionComponent<SubFilesProps> = ({
message: nlsHPCC.RemoveSubfiles2,
items: selection.map(item => item.Name),
onSubmit: React.useCallback(() => {
WsDfu.SuperfileAction("remove", file.Name, selection, false).then(() => refresh());
}, [file, refresh, selection])
WsDfu.SuperfileAction("remove", file.Name, selection, false).then(() => {
refreshSubfiles();
if (file.subfiles.Item.length - 1 === 0) {
replaceUrl(`/files/${file.Name}`);
}
});
}, [file, refreshSubfiles, selection])
});

React.useEffect(() => {
const subfiles = [];
const files = [];
const promises = [];

file?.subfiles?.Item.forEach(item => {
subfiles?.Item.forEach(item => {
const logicalFile = ESPLogicalFile.Get("", item);
promises.push(logicalFile.getInfo2({
onAfterSend: function (response) {
}
}));
subfiles.push(logicalFile);
});
Promise.all(promises).then(logicalFiles => {
setData(subfiles);
files.push(logicalFile);
});
}, [file?.subfiles]);
if (promises.length) {
Promise.all(promises).then(logicalFiles => {
setData(files);
});
} else {
setData(files);
}
}, [file, subfiles]);

const buttons = React.useMemo((): ICommandBarItemProps[] => [
{
Expand Down
2 changes: 1 addition & 1 deletion esp/src/src-react/components/SuperFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const SuperFiles: React.FunctionComponent<SuperFilesProps> = ({
label: nlsHPCC.Name,
sortable: true,
formatter: (name, row) => {
return <Link href={`#/files/${cluster}/${name}`}>{name}</Link>;
return <Link href={`#/files/${row.NodeGroup !== null ? row.NodeGroup : undefined}/${name}`}>{name}</Link>;
}
}
};
Expand Down
22 changes: 21 additions & 1 deletion esp/src/src-react/hooks/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useFile(cluster: string, name: string): [LogicalFile, boolean, n
const [count, increment] = useCounter();

React.useEffect(() => {
const file = LogicalFile.attach({ baseUrl: "" }, cluster, name);
const file = LogicalFile.attach({ baseUrl: "" }, cluster === "undefined" ? undefined : cluster, name);
let active = true;
let handle;
const fetchInfo = singletonDebounce(file, "fetchInfo");
Expand Down Expand Up @@ -87,3 +87,23 @@ export function useFileHistory(cluster: string, name: string): [WsDfu.Origin[],

return [history, eraseHistory, increment];
}

export function useSubfiles(cluster: string, name: string): [WsDfu.subfiles, () => void] {

const [file] = useFile(cluster, name);
const [subfiles, setSubfiles] = React.useState<WsDfu.subfiles>({ Item: [] });
const [count, increment] = useCounter();

React.useEffect(() => {
if (file) {
file.fetchInfo()
.then(response => {
setSubfiles(response.subfiles ?? { Item: [] });
})
.catch(err => logger.error(err))
;
}
}, [file, count]);

return [subfiles, increment];
}

0 comments on commit 54b03f4

Please sign in to comment.