Skip to content

Commit 970aefd

Browse files
littlecherroSanjeevani19
authored andcommitted
DHFPROD-10274: Step Card in Flow Needs In-Progress Indicator
1 parent 4f3b2ac commit 970aefd

File tree

3 files changed

+73
-27
lines changed

3 files changed

+73
-27
lines changed

marklogic-data-hub-central/ui/src/components/flows/flow-panel/step-card.test.tsx

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Router} from "react-router";
33
import {render, fireEvent} from "@testing-library/react";
44
import userEvent from "@testing-library/user-event";
55
import "@testing-library/jest-dom/extend-expect";
6-
import StepCard, {Props} from "./step-card";
6+
import StepCard from "./step-card";
77
import data from "../../../assets/mock-data/curation/flows.data";
88
import {createMemoryHistory} from "history";
99
const history = createMemoryHistory();
@@ -12,7 +12,24 @@ import sourceFormatOptions from "@config/formats.config";
1212
const step = data.flows.data[0].steps[1];
1313
const flow = data.flows.data[0];
1414

15-
const defaultProps: Props = {
15+
const runningFlow = {
16+
name: "testFlow",
17+
steps: [
18+
{
19+
"stepId": "Mapping1-mapping",
20+
"stepName": "Mapping1",
21+
"stepDefinitionType": "mapping",
22+
"stepNumber": "2",
23+
"targetFormat": "json",
24+
"targetEntityType": "http://example.org/Customer-0.0.1/Customer",
25+
},
26+
],
27+
description: "testFlow",
28+
};
29+
30+
const emptyFlow = {name: "", steps: []};
31+
32+
const defaultProps = runningFlow => ({
1633
step: step,
1734
flow: flow,
1835
openFilePicker: jest.fn(),
@@ -32,16 +49,16 @@ const defaultProps: Props = {
3249
setShowUploadError: jest.fn(),
3350
sourceFormatOptions: sourceFormatOptions,
3451
runningStep: undefined,
35-
flowRunning: {name: "", steps: []},
52+
flowRunning: runningFlow,
3653
showUploadError: "",
3754
uploadError: "",
38-
};
55+
});
3956

4057
describe("Flow Card test suite", () => {
4158
it("links for steps lead to correct path", async () => {
4259
const {getByLabelText} = render(
4360
<Router history={history}>
44-
<StepCard {...defaultProps} />
61+
<StepCard {...defaultProps(emptyFlow)} />
4562
</Router>,
4663
);
4764
const flowName = flow.name;
@@ -56,7 +73,7 @@ describe("Flow Card test suite", () => {
5673
const newStep = flow.steps[0];
5774
const {getByLabelText} = render(
5875
<Router history={history}>
59-
<StepCard {...defaultProps} step={newStep} />
76+
<StepCard {...defaultProps(emptyFlow)} step={newStep} />
6077
</Router>,
6178
);
6279
const flowName = flow.name;
@@ -67,10 +84,35 @@ describe("Flow Card test suite", () => {
6784
expect(getByLabelText(`${flowName}-${newStep.stepNumber}-cardlink`).firstChild?.href).toBe(pathname);
6885
});
6986

87+
it("displays clock icon when a step is running", async () => {
88+
const {getByTestId} = render(
89+
<Router history={history}>
90+
<StepCard
91+
{...defaultProps(runningFlow)}
92+
latestJobData={{
93+
[flow.name]: [
94+
{
95+
"stepId": "Mapping1-mapping",
96+
"stepName": "Mapping1",
97+
"stepDefinitionType": "mapping",
98+
"stepNumber": "2",
99+
"targetFormat": "json",
100+
"targetEntityType": "http://example.org/Customer-0.0.1/Customer",
101+
"lastRunStatus": "completed step 2",
102+
},
103+
],
104+
}}
105+
/>
106+
</Router>,
107+
);
108+
const stepName = step.stepName;
109+
expect(getByTestId(`running-${stepName}`)).toBeInTheDocument();
110+
});
111+
70112
it("reorder flow buttons can be focused and pressed by keyboard", async () => {
71113
const {getByLabelText} = render(
72114
<Router history={history}>
73-
<StepCard {...defaultProps} />
115+
<StepCard {...defaultProps(emptyFlow)} />
74116
</Router>,
75117
);
76118
const rightArrowButton = getByLabelText("rightArrow-" + step.stepName);

marklogic-data-hub-central/ui/src/components/flows/flow-panel/step-card.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ const StepCard: React.FC<Props> = ({
6767
let stepDefinitionType = step.stepDefinitionType ? step.stepDefinitionType.toLowerCase() : "";
6868
let stepDefinitionTypeTitle = StepDefinitionTypeTitles[stepDefinitionType];
6969
let stepWithJobDetail =
70-
latestJobData && latestJobData[flow.name] && latestJobData[flow.name]
71-
? latestJobData[flow.name].find(el => el.stepId === step.stepId)
72-
: null;
70+
latestJobData && latestJobData[flow.name] ? latestJobData[flow.name].find(el => el.stepId === step.stepId) : null;
7371

7472
const reorderFlowKeyDownHandler = (event, index, flowName, direction) => {
7573
if (event.key === "Enter") {
@@ -106,23 +104,23 @@ const StepCard: React.FC<Props> = ({
106104
return result !== undefined;
107105
};
108106

109-
const lastRunResponse = (step, flow) => {
107+
const lastRunResponse = (_step, _flow) => {
110108
let stepEndTime;
111-
if (step.stepEndTime) {
112-
stepEndTime = new Date(step.stepEndTime).toLocaleString();
109+
if (_step.stepEndTime) {
110+
stepEndTime = new Date(_step.stepEndTime).toLocaleString();
113111
}
114112

115-
const flowLastRun = latestJobData[flow];
113+
const flowLastRun = latestJobData[_flow];
116114

117115
let canceled = flowLastRun?.some(function (stepObj) {
118116
return stepObj.lastRunStatus?.includes("canceled");
119117
});
120118

121-
if (!step.lastRunStatus && !canceled) {
119+
if (!_step.lastRunStatus && !canceled) {
122120
return null;
123121
}
124122

125-
if (isRunning(flow.name, step.stepNumber)) {
123+
if (isRunning(_flow, _step.stepId)) {
126124
return (
127125
<HCTooltip text={RunToolTips.stepRunning} id="running-tooltip" placement="bottom">
128126
<span tabIndex={0}>
@@ -132,13 +130,13 @@ const StepCard: React.FC<Props> = ({
132130
icon={faClock}
133131
className={styles.runningIcon}
134132
size="lg"
135-
data-testid={`running-${step.stepName}`}
133+
data-testid={`running-${_step.stepName}`}
136134
/>
137135
</i>
138136
</span>
139137
</HCTooltip>
140138
);
141-
} else if (step.lastRunStatus?.includes("canceled") || (!step.lastRunStatus && canceled)) {
139+
} else if (_step.lastRunStatus?.includes("canceled") || (!_step.lastRunStatus && canceled)) {
142140
return (
143141
<span>
144142
<HCTooltip text={RunToolTips.stepCanceled(stepEndTime)} id="canceled-tooltip" placement="bottom">
@@ -150,7 +148,7 @@ const StepCard: React.FC<Props> = ({
150148
</HCTooltip>
151149
</span>
152150
);
153-
} else if (step.lastRunStatus?.includes("completed step")) {
151+
} else if (_step.lastRunStatus?.includes("completed step")) {
154152
return (
155153
<span>
156154
<HCTooltip text={RunToolTips.stepCompleted(stepEndTime)} id="success-tooltip" placement="bottom">
@@ -161,14 +159,14 @@ const StepCard: React.FC<Props> = ({
161159
icon={faCheckCircle}
162160
className={styles.successfulRun}
163161
size="lg"
164-
data-testid={`check-circle-${step.stepName}`}
162+
data-testid={`check-circle-${_step.stepName}`}
165163
/>
166164
</i>
167165
</span>
168166
</HCTooltip>
169167
</span>
170168
);
171-
} else if (step.lastRunStatus?.includes("completed with errors step")) {
169+
} else if (_step.lastRunStatus?.includes("completed with errors step")) {
172170
return (
173171
<span>
174172
<HCTooltip

marklogic-data-hub-central/ui/src/pages/Run.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,24 @@ const Run = props => {
238238
const _stepsRunning = flow?.steps?.filter(step => {
239239
return stepNumbers.includes(step.stepNumber);
240240
});
241-
flow && _stepsRunning ? setFlowRunning({...flow, steps: _stepsRunning}) : setFlowRunning(InitialFlow);
241+
flow && _stepsRunning
242+
? setFlowRunning({...flow, steps: _stepsRunning, description: flowName})
243+
: setFlowRunning(InitialFlow);
242244
};
243245

244-
const finishRun = (flowName: string) => {
246+
const finishRun = () => {
245247
setIsLoading(false);
246248
let InitialFlowAux = {...InitialFlow};
247-
InitialFlowAux.description = flowName;
248249
setFlowRunning(InitialFlowAux);
249250
};
250251

252+
const handleStepRun = (isRunning: boolean, stepId) => {
253+
if (!isRunning) {
254+
finishRun();
255+
}
256+
setIsStepRunning(isRunning);
257+
};
258+
251259
const runFlowSteps = async (flowName: string, steps: Step[], formData: any) => {
252260
setIsStepRunning(true);
253261
const stepNames: string[] = steps.map(step => {
@@ -295,7 +303,6 @@ const Run = props => {
295303
}
296304
});
297305
}, pollConfig.interval);
298-
finishRun(flowName);
299306
}
300307
} catch (error) {
301308
console.error("Error running step", error);
@@ -348,7 +355,6 @@ const Run = props => {
348355
setRunEnded({flowId: flowName, stepId: step.stepNumber});
349356
});
350357
}, pollConfig.interval);
351-
finishRun(flowName);
352358
}
353359
} catch (error) {
354360
console.error("Error running step", error);
@@ -445,7 +451,7 @@ const Run = props => {
445451
{openJobResponse && (
446452
<JobResponse
447453
setUserCanStopFlow={setUserCanStopFlow}
448-
setIsStepRunning={setIsStepRunning}
454+
setIsStepRunning={handleStepRun}
449455
stopRun={stopRun}
450456
jobId={jobId}
451457
setOpenJobResponse={setOpenJobResponse}

0 commit comments

Comments
 (0)