Skip to content

Commit 3541e39

Browse files
authored
Fix task title color, fetch and update logs in GUI (#122)
This PR fixes a few GUI issues: - fix missing state for title color. - fetch and update logs in GUI
1 parent f382f47 commit 3541e39

File tree

3 files changed

+62
-23
lines changed

3 files changed

+62
-23
lines changed

aiida_workgraph/web/backend/app/workgraph.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ async def read_workgraph(id: int):
6262
get_node_inputs,
6363
get_node_outputs,
6464
)
65-
from aiida.cmdline.utils.common import get_workchain_report
6665
from aiida.orm.utils.serialize import deserialize_unsafe
6766
from aiida_workgraph.utils import get_parent_workgraphs, get_processes_latest
6867

@@ -80,12 +79,11 @@ async def read_workgraph(id: int):
8079
"inputs": get_node_inputs(id),
8180
"outputs": get_node_outputs(id),
8281
}
83-
report = get_workchain_report(node, "REPORT")
82+
8483
parent_workgraphs = get_parent_workgraphs(id)
8584
parent_workgraphs.reverse()
8685
processes_info = get_processes_latest(id)
8786
content["summary"] = summary
88-
content["logs"] = report.splitlines()
8987
content["parent_workgraphs"] = parent_workgraphs
9088
content["processes_info"] = processes_info
9189
return content
@@ -104,6 +102,19 @@ async def read_workgraph_tasks_state(id: int):
104102
raise HTTPException(status_code=404, detail=f"Workgraph {id} not found")
105103

106104

105+
@router.get("/api/workgraph-logs/{id}")
106+
async def read_workgraph_logs(id: int):
107+
from aiida.cmdline.utils.common import get_workchain_report
108+
109+
try:
110+
node = orm.load_node(id)
111+
report = get_workchain_report(node, "REPORT")
112+
logs = report.splitlines()
113+
return logs
114+
except KeyError:
115+
raise HTTPException(status_code=404, detail=f"Workgraph {id} not found")
116+
117+
107118
# Route for pausing a workgraph item
108119
@router.post("/api/workgraph/pause/{id}")
109120
async def pause_workgraph(

aiida_workgraph/web/frontend/src/components/WorkGraphItem.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function useRete<T extends { destroy(): void }>(
7474

7575
function WorkGraphGraph() {
7676
const { pk } = useParams();
77-
const [workgraphData, setWorktreeData] = useState({ summary: {}, nodes: {}, links: [], logs: [], pk: [] });
77+
const [workgraphData, setWorktreeData] = useState({ summary: {}, nodes: {}, links: [], pk: [] });
7878
const [ref, editor] = useRete(createEditor, workgraphData);
7979
const [selectedNode, setSelectedNode] = useState({ metadata: [], executor: '' });
8080
const [showNodeDetails, setShowNodeDetails] = useState(false);
@@ -111,20 +111,24 @@ function WorkGraphGraph() {
111111
if (nodeName && nodeName in stateData) {
112112
const nodeState = stateData[nodeName].state;
113113
if (nodeState === 'FINISHED') {
114-
titleElement.style.background = 'green';
114+
titleElement.style.background = 'green';
115115
} else if (nodeState === 'RUNNING') {
116-
titleElement.style.background = 'orange';
116+
titleElement.style.background = 'orange';
117117
} else if (nodeState === 'CREATED') {
118-
titleElement.style.background = 'blue';
118+
titleElement.style.background = 'blue';
119+
} else if (nodeState === 'PLANNED') {
120+
titleElement.style.background = 'gray';
119121
} else if (nodeState === 'WAITING') {
120-
titleElement.style.background = 'purple'; // Change to the desired color for "waiting"
122+
titleElement.style.background = 'purple'; // Change to the desired color for "waiting"
121123
} else if (nodeState === 'KILLED') {
122-
titleElement.style.background = 'red'; // Change to the desired color for "killed"
123-
// } else if (nodeState === 'PAUSED') {
124-
// titleElement.style.background = 'purple'; // Change to the desired color for "paused"
124+
titleElement.style.background = 'pink'; // Change to the desired color for "killed"
125+
} else if (nodeState === 'PAUSED') {
126+
titleElement.style.background = 'yellow'; // Change to the desired color for "paused"
127+
} else if (nodeState === 'FAILED') {
128+
titleElement.style.background = 'red'; // Change to the desired color for "failed"
125129
} else {
126-
// Handle any other states or provide a default color
127-
titleElement.style.background = 'gray'; // Change to the desired default color
130+
// Handle any other states or provide a default color
131+
titleElement.style.background = 'lightblue'; // Change to the desired default color
128132
}
129133
}
130134
}
@@ -253,7 +257,7 @@ function WorkGraphGraph() {
253257
<Button onClick={() => setSelectedView('Time')}>Time</Button>
254258
</TopMenu>
255259
{selectedView === 'Summary' && <WorktreeSummary summary={workgraphData.summary} />}
256-
{selectedView === 'Log' && <WorkGraphLog logs={workgraphData.logs} />}
260+
{selectedView === 'Log' && <WorkGraphLog id={pk} />}
257261
{selectedView === 'Time' && <NodeDurationGraph id={pk}/>}
258262
<EditorWrapper visible={selectedView === 'Editor'}>
259263
<WorkGraphIndicator parentWorktrees={workgraphHierarchy} />

aiida_workgraph/web/frontend/src/components/WorkGraphLog.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// WorkGraphLog.js
22
import styled from "styled-components";
3+
import { useEffect, useState } from "react";
34

45

56
export const WorktreeLogStyle = styled.div`
@@ -24,18 +25,41 @@ export const WorktreeLogStyle = styled.div`
2425
}
2526
`;
2627

27-
function WorkGraphLog({ logs }) {
28+
function WorkGraphLog({ id }) {
29+
const [fetchedLogs, setFetchedLogs] = useState([]);
30+
31+
useEffect(() => {
32+
fetchLogs(); // Fetch logs immediately
33+
34+
const interval = setInterval(() => {
35+
fetchLogs();
36+
}, 4000);
37+
38+
return () => {
39+
clearInterval(interval);
40+
};
41+
}, []);
42+
43+
const fetchLogs = async () => {
44+
try {
45+
const response = await fetch(`http://localhost:8000/api/workgraph-logs/${id}`);
46+
const data = await response.json();
47+
setFetchedLogs(data);
48+
} catch (error) {
49+
console.error("Error fetching logs:", error);
50+
}
51+
};
52+
2853
return (
2954
<WorktreeLogStyle>
30-
31-
<div className="log-section">
32-
<h3>Log Information</h3>
33-
<div className="log-content">
34-
{logs.map((log, index) => (
35-
<div key={index}>{log}</div>
36-
))}
55+
<div className="log-section">
56+
<h3>Log Information</h3>
57+
<div className="log-content">
58+
{fetchedLogs.map((log, index) => (
59+
<div key={index}>{log}</div>
60+
))}
61+
</div>
3762
</div>
38-
</div>
3963
</WorktreeLogStyle>
4064
);
4165
}

0 commit comments

Comments
 (0)