-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0ad77f
commit e64138c
Showing
6 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,41 @@ | ||
import React from 'react' | ||
import { ContentBlock, Code } from '../ui' | ||
import TaskGraph from './task-ui/TaskGraph' | ||
|
||
type Props = { | ||
state?: object | ||
state: State | ||
} | ||
|
||
type State = { | ||
ui?: TaskComponent[] | ||
[key: string]: any | ||
} | ||
|
||
type TaskComponent = { | ||
component: string | ||
path: string | ||
} | ||
|
||
function renderComponent(def: TaskComponent, state: State) { | ||
switch(def.component) { | ||
case 'ui.cowait.io/task-graph': | ||
return <TaskGraph graph={state[def.path]} /> | ||
default: | ||
throw new Error(`Unknown Task Component ${def.component}`) | ||
} | ||
} | ||
|
||
export const TaskState: React.FC<Props> = ({ state }) => { | ||
if (!state) { | ||
return null | ||
} | ||
const components = state.ui || [] | ||
|
||
return <ContentBlock> | ||
<h4>State</h4> | ||
<Code language="json">{JSON.stringify(state, null, 4)}</Code> | ||
{components.map(c => renderComponent(c, state))} | ||
</ContentBlock> | ||
// <Code language="json">{JSON.stringify(state, null, 4)}</Code> | ||
} | ||
|
||
export default TaskState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import _ from 'lodash' | ||
import React from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { RootState } from '../../../store' | ||
import DagreGraph from 'dagre-d3-react' | ||
import styled from 'styled-components' | ||
|
||
const DagStyle = styled.div` | ||
.nodes { | ||
fill: darkgray; | ||
cursor: pointer; | ||
} | ||
// status colors | ||
.nodes .work { fill: #82b332; } | ||
.nodes .done { fill: green; } | ||
.nodes .fail { fill: red; } | ||
.nodes .stop { fill: orange; } | ||
.nodes text { | ||
fill: white; | ||
} | ||
path { | ||
stroke: white; | ||
fill: white; | ||
stroke-width: 3px; | ||
} | ||
` | ||
|
||
type Props = { | ||
graph: TaskGraph | ||
} | ||
|
||
type TaskGraph = { | ||
[id: string]: TaskNode, | ||
} | ||
|
||
type TaskNode = { | ||
id: string | ||
task: string | ||
depends_on: string[] | ||
task_id?: string | ||
} | ||
|
||
type d3Link = { | ||
source: string | ||
target: string | ||
class?: string | ||
label?: string | ||
config?: object | ||
} | ||
|
||
export const TaskGraph: React.FC<Props> = ({ graph }) => { | ||
const tasks = useSelector((state: RootState) => state.tasks.items) | ||
let nodes = _.map(graph, node => { | ||
if (node.task_id && tasks[node.task_id]) { | ||
let task = tasks[node.task_id] | ||
return { | ||
id: node.id, | ||
label: task.id, | ||
class: task.status, | ||
} | ||
} | ||
return { | ||
id: node.id, | ||
label: node.task, | ||
class: 'pending', | ||
} | ||
}) | ||
let links: d3Link[] = [] | ||
_.each(graph, node => { | ||
_.each(node.depends_on, edge => { | ||
links.push({ | ||
source: edge, | ||
target: node.id, | ||
}) | ||
}) | ||
}) | ||
return <DagStyle> | ||
<DagreGraph | ||
nodes={nodes} | ||
links={links} | ||
config={{ | ||
rankdir: 'LR', | ||
align: 'UL', | ||
ranker: 'tight-tree' | ||
}} | ||
width='100%' | ||
height='500' | ||
animate={100} | ||
shape='rect' | ||
zoomable | ||
onNodeClick={(e: any) => console.log(e)} | ||
/> | ||
</DagStyle> | ||
} | ||
|
||
export default TaskGraph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters