Skip to content

Commit

Permalink
HPCC-29615 ECL Watch v9 fix invalid display of no ecl for a query
Browse files Browse the repository at this point in the history
Fix issues where displaying ECL for empty query resulted in errors or
incorrect content

Signed-off-by: Jeremy Clements <[email protected]>
  • Loading branch information
jeclrsg committed Jul 12, 2023
1 parent 88cd80d commit dc3da54
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions esp/src/src-react/components/SourceEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react";
import { CommandBar, ContextualMenuItemType, ICommandBarItemProps, useTheme } from "@fluentui/react";
import { useConst, useOnEvent } from "@fluentui/react-hooks";
import { Editor, ECLEditor, XMLEditor, JSONEditor } from "@hpcc-js/codemirror";
import { Workunit } from "@hpcc-js/comms";
import nlsHPCC from "src/nlsHPCC";
import { HolyGrail } from "../layouts/HolyGrail";
import { AutosizeHpccJSComponent } from "../layouts/HpccJSAdapter";
Expand Down Expand Up @@ -219,25 +220,34 @@ export const ECLSourceEditor: React.FunctionComponent<ECLSourceEditorProps> = ({

interface FetchEditor {
url: string;
wuid?: string;
readonly?: boolean;
mode?: "ecl" | "xml" | "text";
}

export const FetchEditor: React.FunctionComponent<FetchEditor> = ({
url,
wuid,
readonly = true,
mode = "text"
}) => {

const [text, setText] = React.useState("");

React.useEffect(() => {
fetch(url).then(response => {
return response.text();
}).then(content => {
setText(content);
});
}, [url]);
if (wuid) {
const wu = Workunit.attach({ baseUrl: "" }, wuid);
wu.fetchQuery().then(function (query) {
setText(query?.Text ?? "");
});
} else {
fetch(url).then(response => {
return response.text();
}).then(content => {
setText(content);
});
}
}, [url, wuid]);

return <SourceEditor text={text} readonly={readonly} mode={mode}></SourceEditor>;
};
Expand Down
2 changes: 1 addition & 1 deletion esp/src/src-react/components/WorkunitDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const WorkunitDetails: React.FunctionComponent<WorkunitDetailsProps> = ({
</PivotItem>
<PivotItem headerText={nlsHPCC.Helpers} itemKey="helpers" itemCount={workunit?.HelpersCount} style={pivotItemStyle(size, 0)}>
{state ?
<FetchEditor mode={queryParams?.mode as any} url={queryParams?.src as string} /> :
<FetchEditor mode={queryParams?.mode as any} url={queryParams?.src as string} wuid={queryParams?.mode?.toLowerCase() === "ecl" ? wuid : ""} /> :
<Helpers wuid={wuid} />
}
</PivotItem>
Expand Down
2 changes: 1 addition & 1 deletion esp/src/src/ECLArchiveWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ECLArchiveWidget {

const wu = Workunit.attach({ baseUrl: "" }, params.Wuid);
wu.fetchQuery().then(function (query) {
context.editor.text(query.Text);
context.editor.text(query?.Text ?? "");
if (!wu.HasArchiveQuery) {
context.archiveViewer
.addWidget(context.editor)
Expand Down

0 comments on commit dc3da54

Please sign in to comment.