Skip to content

Commit daff7f7

Browse files
committed
fix: fix running workflows list not opening when a workflow is run
1 parent f7f9d7d commit daff7f7

File tree

4 files changed

+80
-71
lines changed

4 files changed

+80
-71
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { type RunningWorkflowSummary } from "@squonk/data-manager-client";
2+
3+
import { Box, List, ListItemButton, ListItemText, Typography } from "@mui/material";
4+
import A from "next/link";
5+
6+
import { LocalTime } from "../LocalTime";
7+
8+
export interface RunningWorkflowsListProps {
9+
runningWorkflows: RunningWorkflowSummary[];
10+
}
11+
12+
/**
13+
* MuiList detailing running workflows.
14+
*/
15+
export const RunningWorkflowsList = ({ runningWorkflows }: RunningWorkflowsListProps) => {
16+
if (runningWorkflows.length === 0) {
17+
return (
18+
<Box sx={{ p: 2 }}>
19+
<Typography color="text.secondary" variant="body2">
20+
No workflows currently exist
21+
</Typography>
22+
</Box>
23+
);
24+
}
25+
26+
// Sort by started descending (most recent first)
27+
const sortedRuns = [...runningWorkflows].sort((a, b) => {
28+
if (a.started && b.started) {
29+
return new Date(b.started).getTime() - new Date(a.started).getTime();
30+
}
31+
if (a.started) {
32+
return -1;
33+
}
34+
if (b.started) {
35+
return 1;
36+
}
37+
return 0;
38+
});
39+
40+
return (
41+
<List dense component="ul">
42+
{sortedRuns.map((rw) => (
43+
<ListItemButton
44+
component={A}
45+
href={{ pathname: "/results/workflow/[workflowId]", query: { workflowId: rw.id } }}
46+
key={rw.id}
47+
>
48+
<ListItemText
49+
primary={rw.name}
50+
secondary={<>{!!rw.started && <LocalTime utcTimestamp={rw.started} />}</>}
51+
slotProps={{ primary: { variant: "body1" } }}
52+
/>
53+
</ListItemButton>
54+
))}
55+
</List>
56+
);
57+
};

src/components/runCards/WorkflowCard/WorkflowCard.tsx

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
import { type WorkflowSummary } from "@squonk/data-manager-client";
1+
import { type RunningWorkflowSummary, type WorkflowSummary } from "@squonk/data-manager-client";
22

3-
import { Box, List, ListItemButton, ListItemText, Typography } from "@mui/material";
4-
import A from "next/link";
3+
import { Typography } from "@mui/material";
54

65
import { useCurrentProjectId } from "../../../hooks/projectHooks";
76
import { BaseCard } from "../../BaseCard";
8-
import { LocalTime } from "../../LocalTime";
7+
import { RunningWorkflowsList } from "../RunningWorkflowsList";
98
import { RunWorkflowButton } from "./RunWorkflowButton";
109

11-
export interface WorkflowRunListItem {
12-
id: string;
13-
name: string;
14-
version?: string;
15-
started?: string;
16-
}
17-
1810
export interface WorkflowCardProps {
1911
workflow: WorkflowSummary;
20-
runningWorkflows?: WorkflowRunListItem[];
12+
runningWorkflows?: RunningWorkflowSummary[];
2113
}
2214

2315
/**
@@ -26,63 +18,20 @@ export interface WorkflowCardProps {
2618
*/
2719
export const WorkflowCard = ({ workflow, runningWorkflows = [] }: WorkflowCardProps) => {
2820
const { projectId } = useCurrentProjectId();
29-
const hasRunning = runningWorkflows.length > 0;
30-
31-
// Sort by started descending (most recent first)
32-
const sortedRuns = [...runningWorkflows].sort((a, b) => {
33-
if (a.started && b.started) {
34-
return new Date(b.started).getTime() - new Date(a.started).getTime();
35-
}
36-
if (a.started) {
37-
return -1;
38-
}
39-
if (b.started) {
40-
return 1;
41-
}
42-
return 0;
43-
});
4421

4522
return (
4623
<BaseCard
4724
accentColor="#f1c40f"
48-
actions={() => (
25+
actions={({ setExpanded }) => (
4926
<RunWorkflowButton
5027
disabled={!projectId}
5128
name={workflow.workflow_name ?? workflow.name}
5229
projectId={projectId ?? ""}
5330
workflowId={workflow.id}
31+
onLaunch={() => setExpanded(true)}
5432
/>
5533
)}
56-
collapsed={
57-
hasRunning ? (
58-
<List dense component="ul">
59-
{sortedRuns.map((rw) => (
60-
<ListItemButton
61-
component={A}
62-
href={{ pathname: "/results/workflow/[workflowId]", query: { workflowId: rw.id } }}
63-
key={rw.id}
64-
>
65-
<ListItemText
66-
primary={rw.name}
67-
secondary={
68-
<>
69-
<span style={{ marginRight: 8 }}>version: {rw.version ?? "n/a"}</span>
70-
{!!rw.started && <LocalTime utcTimestamp={rw.started} />}
71-
</>
72-
}
73-
slotProps={{ primary: { variant: "body1" } }}
74-
/>
75-
</ListItemButton>
76-
))}
77-
</List>
78-
) : (
79-
<Box sx={{ p: 2 }}>
80-
<Typography color="text.secondary" variant="body2">
81-
No workflows currently exist
82-
</Typography>
83-
</Box>
84-
)
85-
}
34+
collapsed={<RunningWorkflowsList runningWorkflows={runningWorkflows} />}
8635
header={{
8736
subtitle: workflow.name,
8837
avatar: workflow.name[0],

src/components/runCards/WorkflowCard/WorkflowModal.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ export interface WorkflowModalProps {
1616
projectId: string;
1717
open: boolean;
1818
onClose: () => void;
19-
onLaunch?: (instanceId: string) => void;
19+
onLaunch?: (runningWorkflowId: string) => void;
2020
}
2121

2222
/**
2323
* Modal for running a workflow instance. Fetches workflow details and displays the correct form.
2424
*/
25-
export const WorkflowModal = ({ workflowId, projectId, open, onClose }: WorkflowModalProps) => {
25+
export const WorkflowModal = ({
26+
workflowId,
27+
projectId,
28+
open,
29+
onClose,
30+
onLaunch,
31+
}: WorkflowModalProps) => {
2632
const { enqueueError, enqueueSnackbar } = useEnqueueError<DmError>();
2733

2834
const { data: workflow } = useGetWorkflow(workflowId);
@@ -45,17 +51,19 @@ export const WorkflowModal = ({ workflowId, projectId, open, onClose }: Workflow
4551

4652
const handleSubmit = async () => {
4753
try {
48-
workflow?.id &&
49-
(await runWorkflow({
54+
if (workflow?.id) {
55+
const { id } = await runWorkflow({
5056
workflowId: workflow.id,
5157
data: {
5258
as_name: nameState,
5359
debug,
5460
project_id: projectId,
5561
variables: JSON.stringify({ ...optionsFormData, ...inputsData }),
5662
},
57-
}));
58-
enqueueSnackbar("Workflow instance started successfully", { variant: "success" });
63+
});
64+
enqueueSnackbar("Workflow instance started successfully", { variant: "success" });
65+
onLaunch && onLaunch(id);
66+
}
5967
} catch (error) {
6068
enqueueError(error);
6169
} finally {

src/pages/run.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ import { CenterLoader } from "../components/CenterLoader";
1616
import { ApplicationCard } from "../components/runCards/ApplicationCard";
1717
import { JobCard } from "../components/runCards/JobCard";
1818
import { TEST_JOB_ID } from "../components/runCards/TestJob/jobId";
19-
import {
20-
WorkflowCard,
21-
type WorkflowRunListItem,
22-
} from "../components/runCards/WorkflowCard/WorkflowCard";
19+
import { WorkflowCard } from "../components/runCards/WorkflowCard/WorkflowCard";
2320
import { SearchTextField } from "../components/SearchTextField";
2421
import { AS_ROLES, DM_ROLES } from "../constants/auth";
2522
import { useCurrentProject, useIsUserAdminOrEditorOfCurrentProject } from "../hooks/projectHooks";
@@ -148,9 +145,7 @@ const Run = () => {
148145
const workflowCards = Object.entries(filteredAndGroupedWorkflows).map(
149146
([name, workflowGroup]) => {
150147
// Find all runs for this workflow definition
151-
const runs: WorkflowRunListItem[] = runningWorkflows
152-
.filter((rw) => rw.workflow.id === workflowGroup[0].id)
153-
.map((rw) => ({ id: rw.id, name: rw.name }));
148+
const runs = runningWorkflows.filter((rw) => rw.workflow.id === workflowGroup[0].id);
154149

155150
return (
156151
<Grid key={name} size={{ md: 3, sm: 6, xs: 12 }}>

0 commit comments

Comments
 (0)