-
Notifications
You must be signed in to change notification settings - Fork 6
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
38bb051
commit c04b0d7
Showing
8 changed files
with
250 additions
and
12 deletions.
There are no files selected for viewing
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,67 @@ | ||
import { parse } from 'yaml' | ||
|
||
import { PipelineGraph } from '../../src/pipeline-graph' | ||
import { NodeContent } from '../../src/types/node-content' | ||
import { ContainerNode } from '../../src/types/nodes' | ||
import { yaml2Nodes } from './parser/yaml2AnyNodes' | ||
import { pipeline } from './sample-data/pipeline' | ||
|
||
import './sample-data/pipeline-data' | ||
|
||
import React from 'react' | ||
|
||
import { CanvasProvider } from '../../src/context/canvas-provider' | ||
import { CanvasControls } from './canvas/CanvasControls' | ||
import { SimpleParallelGroupNodeContent } from './nodes-simple/simple-parallel-group-node' | ||
import { SimpleSerialGroupContentNode } from './nodes-simple/simple-stage-node' | ||
import { SimpleStepNode } from './nodes-simple/simple-step-node' | ||
import { ContentNodeTypes } from './types/content-node-types' | ||
|
||
const nodes: NodeContent[] = [ | ||
{ | ||
type: ContentNodeTypes.step, | ||
containerType: ContainerNode.leaf, | ||
component: SimpleStepNode | ||
}, | ||
{ | ||
type: ContentNodeTypes.parallel, | ||
containerType: ContainerNode.parallel, | ||
component: SimpleParallelGroupNodeContent | ||
}, | ||
{ | ||
type: ContentNodeTypes.serial, | ||
containerType: ContainerNode.serial, | ||
component: SimpleSerialGroupContentNode | ||
}, | ||
{ | ||
type: ContentNodeTypes.stage, | ||
containerType: ContainerNode.serial, | ||
component: SimpleSerialGroupContentNode | ||
} | ||
] | ||
|
||
const yamlObject = parse(pipeline) | ||
const plData = yaml2Nodes(yamlObject, {}) | ||
|
||
function Example4() { | ||
return ( | ||
<div | ||
style={{ | ||
position: 'relative', | ||
left: '5vw', | ||
top: '10vh', | ||
height: '80vh', | ||
width: '90vw', | ||
overflow: 'hidden', | ||
border: '1px solid gray' | ||
}} | ||
> | ||
<CanvasProvider> | ||
<PipelineGraph data={plData} nodes={nodes} onSelect={() => {}} onAdd={() => {}} onDelete={() => {}} /> | ||
<CanvasControls /> | ||
</CanvasProvider> | ||
</div> | ||
) | ||
} | ||
|
||
export default Example4 |
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
31 changes: 31 additions & 0 deletions
31
packages/pipeline-graph/examples/src/nodes-simple/simple-parallel-group-node.tsx
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,31 @@ | ||
import React from 'react' | ||
|
||
import { ParallelNodeInternalType } from '../../../src/types/nodes-internal' | ||
|
||
export interface ParallelGroupContentNodeDataType { | ||
yamlPath: string | ||
name: string | ||
} | ||
|
||
export function SimpleParallelGroupNodeContent(props: { | ||
node: ParallelNodeInternalType<ParallelGroupContentNodeDataType> | ||
children: React.ReactElement | ||
}) { | ||
const { children } = props | ||
|
||
return ( | ||
<div> | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
inset: 0, | ||
zIndex: -1, | ||
border: '1px dashed #454545', | ||
borderRadius: '6px', | ||
background: 'rgba(152, 150, 172, 0.01)' | ||
}} | ||
/> | ||
{children} | ||
</div> | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/pipeline-graph/examples/src/nodes-simple/simple-serial-group-node.tsx
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,31 @@ | ||
import React from 'react' | ||
|
||
import { SerialNodeInternalType } from '../../../src/types/nodes-internal' | ||
|
||
export interface SerialGroupContentNodeDataType { | ||
yamlPath: string | ||
name: string | ||
} | ||
|
||
export function SimpleSerialGroupNodeContent(props: { | ||
node: SerialNodeInternalType<SerialGroupContentNodeDataType> | ||
children: React.ReactElement | ||
}) { | ||
const { children } = props | ||
|
||
return ( | ||
<div> | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
inset: 0, | ||
zIndex: -1, | ||
border: '1px dashed #454545', | ||
borderRadius: '6px', | ||
background: 'rgba(152, 150, 172, 0.01)' | ||
}} | ||
/> | ||
{children} | ||
</div> | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/pipeline-graph/examples/src/nodes-simple/simple-stage-node.tsx
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,31 @@ | ||
import React from 'react' | ||
|
||
import { SerialNodeInternalType } from '../../../src/types/nodes-internal' | ||
|
||
export interface StageNodeContentType { | ||
yamlPath: string | ||
name: string | ||
} | ||
|
||
export function SimpleSerialGroupContentNode(props: { | ||
node: SerialNodeInternalType<StageNodeContentType> | ||
children: React.ReactElement | ||
}) { | ||
const { children } = props | ||
|
||
return ( | ||
<div> | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
inset: 0, | ||
zIndex: -1, | ||
border: '1px dashed #454545', | ||
borderRadius: '6px', | ||
background: 'rgba(152, 150, 172, 0.01)' | ||
}} | ||
/> | ||
{children} | ||
</div> | ||
) | ||
} |
60 changes: 60 additions & 0 deletions
60
packages/pipeline-graph/examples/src/nodes-simple/simple-step-node.tsx
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,60 @@ | ||
import React, { useEffect, useRef, useState } from 'react' | ||
|
||
import { useGraphContext } from '../../../src/context/graph-provider' | ||
import { LeafNodeInternalType } from '../../../src/types/nodes-internal' | ||
|
||
export interface StepNodeDataType { | ||
yamlPath: string | ||
name: string | ||
icon?: React.ReactElement | ||
} | ||
|
||
export function SimpleStepNode(props: { node: LeafNodeInternalType<StepNodeDataType> }) { | ||
const { rerender } = useGraphContext() | ||
const { node } = props | ||
const data = node.data as StepNodeDataType | ||
|
||
const increment = useRef(Math.random() * 2) | ||
const size = useRef({ x: 150, y: 150 }) | ||
|
||
const [_, setRerender] = useState(1) | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
if (size.current.x > 200) increment.current = -Math.abs(increment.current) | ||
if (size.current.x < 100) increment.current = Math.abs(increment.current) | ||
|
||
size.current = { x: size.current.x + increment.current, y: size.current.y + increment.current } | ||
rerender() | ||
}, 33) | ||
|
||
setRerender(prev => prev + 1) | ||
return () => clearInterval(interval) | ||
}, []) | ||
|
||
const style: React.CSSProperties = { | ||
height: size.current.x + 'px', | ||
width: size.current.y + 'px', | ||
boxSizing: 'border-box', | ||
border: '1px solid #454545', | ||
borderRadius: '6px', | ||
wordBreak: 'break-all', | ||
fontSize: '11px', | ||
fontFamily: 'Verdana', | ||
background: 'linear-gradient(-47deg, rgba(152, 150, 172, 0.05) 0%, rgba(177, 177, 177, 0.15) 100%)', | ||
overflow: 'hidden' | ||
} | ||
|
||
const name = data?.name ?? 'Step' | ||
|
||
return ( | ||
<div title={name} style={style}> | ||
<div>{data?.icon}</div> | ||
<div style={{ margin: '10px' }} className={'node-text'}> | ||
<span>{name}</span> | ||
<br /> | ||
<span className={'node-text'}>{props.node.path}</span> | ||
</div> | ||
</div> | ||
) | ||
} |
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