-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from jakemoresca/action-pane
Action pane
- Loading branch information
Showing
12 changed files
with
454 additions
and
41 deletions.
There are no files selected for viewing
147 changes: 120 additions & 27 deletions
147
actionFlow.editor/src/components/controls/property-field.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 |
---|---|---|
@@ -1,32 +1,125 @@ | ||
import { ChangeEvent } from "react"; | ||
import { NodePropertyDefinition, NodePropertyType } from "../left-pane/NodeProperties"; | ||
import { Label, TextInput } from "flowbite-react"; | ||
import { | ||
NodePropertyDefinition, | ||
NodePropertyType, | ||
} from "../left-pane/NodeProperties"; | ||
import { Label, Select, Textarea, TextInput } from "flowbite-react"; | ||
import TableProperties from "./table-properties"; | ||
import { getNodeColumnDefinition, toTableProperties } from "@/modules/nodes/node-column-definition-provider"; | ||
import { | ||
getNodeColumnDefinition, | ||
toTableProperties, | ||
} from "@/modules/nodes/node-column-definition-provider"; | ||
|
||
export type PropertyFieldData = { | ||
nodeType: string | ||
properties: Record<string, any>; | ||
propertyDefinition: NodePropertyDefinition | ||
handlePropertyChange?: (event: ChangeEvent<HTMLInputElement>) => void | ||
}; | ||
|
||
export default function PropertyField({ nodeType, properties, propertyDefinition, handlePropertyChange }: PropertyFieldData) { | ||
|
||
switch(propertyDefinition.propertyType) { | ||
case NodePropertyType.Label: | ||
return <Label htmlFor="label" value={properties[propertyDefinition.propertyName]} /> | ||
|
||
case NodePropertyType.TextField: | ||
return <TextInput name={propertyDefinition.propertyName} type="text" placeholder={propertyDefinition.propertyLabel} value={properties[propertyDefinition.propertyName]} onChange={handlePropertyChange} /> | ||
|
||
case NodePropertyType.NumberField: | ||
return <TextInput name={propertyDefinition.propertyName} type="number" placeholder={propertyDefinition.propertyLabel} value={properties[propertyDefinition.propertyName]} onChange={handlePropertyChange} /> | ||
|
||
case NodePropertyType.Properties: | ||
const nodeColumnDefinitions = getNodeColumnDefinition(nodeType, propertyDefinition.propertyName); | ||
const tableProperties = toTableProperties(properties, "variables"); | ||
return <TableProperties columnDefinitions={nodeColumnDefinitions} properties={tableProperties} handlePropertyChange={handlePropertyChange} /> | ||
} | ||
nodeType: string; | ||
properties: Record<string, any>; | ||
propertyDefinition: NodePropertyDefinition; | ||
handlePropertyChange?: (event: ChangeEvent) => void; | ||
}; | ||
|
||
export default function PropertyField({ | ||
nodeType, | ||
properties, | ||
propertyDefinition, | ||
handlePropertyChange, | ||
}: PropertyFieldData) { | ||
|
||
const value = getValue(properties, propertyDefinition); | ||
|
||
switch (propertyDefinition.propertyType) { | ||
case NodePropertyType.Label: | ||
return ( | ||
<Label | ||
htmlFor="label" | ||
value={value} | ||
/> | ||
); | ||
|
||
case NodePropertyType.TextField: | ||
return ( | ||
<TextInput | ||
name={propertyDefinition.propertyName} | ||
type="text" | ||
placeholder={propertyDefinition.propertyLabel} | ||
value={value} | ||
onChange={handlePropertyChange} | ||
/> | ||
); | ||
|
||
case NodePropertyType.NumberField: | ||
return ( | ||
<TextInput | ||
name={propertyDefinition.propertyName} | ||
type="number" | ||
placeholder={propertyDefinition.propertyLabel} | ||
value={value} | ||
onChange={handlePropertyChange} | ||
/> | ||
); | ||
|
||
case NodePropertyType.Properties: | ||
const nodeColumnDefinitions = getNodeColumnDefinition( | ||
nodeType, | ||
propertyDefinition.propertyName | ||
); | ||
const tableProperties = toTableProperties( | ||
properties, | ||
propertyDefinition.propertyName | ||
); | ||
return ( | ||
<TableProperties | ||
columnDefinitions={nodeColumnDefinitions} | ||
properties={tableProperties} | ||
handlePropertyChange={handlePropertyChange} | ||
/> | ||
); | ||
|
||
case NodePropertyType.List: | ||
return ( | ||
<Select | ||
name={propertyDefinition.propertyName} | ||
onChange={handlePropertyChange} | ||
value={value} | ||
> | ||
{propertyDefinition.propertySources?.map((x, index) => { | ||
return ( | ||
<option | ||
key={`${propertyDefinition.propertyName}_source_${index}`} | ||
> | ||
{x} | ||
</option> | ||
); | ||
})} | ||
</Select> | ||
); | ||
|
||
case NodePropertyType.TextArea: | ||
return ( | ||
<Textarea | ||
name={propertyDefinition.propertyName} | ||
placeholder={propertyDefinition.propertyLabel} | ||
rows={4} | ||
value={value} | ||
/> | ||
); | ||
} | ||
|
||
} | ||
|
||
function getValue(properties: Record<string, any>, propertyDefinition: NodePropertyDefinition) { | ||
const propertyDefinitionValueSource = propertyDefinition.propertyName; | ||
|
||
if(propertyDefinitionValueSource.includes(".")) { | ||
const valuePropertyPaths = propertyDefinitionValueSource.split("."); | ||
let propertySource = properties; | ||
let value; | ||
|
||
for (let index = 0; index < valuePropertyPaths.length; index++) { | ||
value = propertySource[valuePropertyPaths[index]]; | ||
propertySource = value; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
return properties[propertyDefinitionValueSource]; | ||
} |
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
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
29 changes: 29 additions & 0 deletions
29
actionFlow.editor/src/components/nodes/ControlFlowNode.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,29 @@ | ||
import type { Node, NodeProps } from "@xyflow/react"; | ||
import { Handle, Position } from "@xyflow/react"; | ||
import { NodeBase } from "@xyflow/system"; | ||
import ConditionSection from "./ConditionSection"; | ||
import { BaseNodeData } from "./BaseNode"; | ||
|
||
export type ControlFlowNodeData = BaseNodeData & { | ||
conditions?: ControlFlowConditionsData; | ||
}; | ||
|
||
export type ControlFlowConditionsData = { | ||
expressions?: string; | ||
} | ||
|
||
export type ControlFlowNode = NodeBase & Node<ControlFlowNodeData>; | ||
|
||
export default function ControlFlowNode({ id, data }: NodeProps<ControlFlowNode>) { | ||
return ( | ||
<div className="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"> | ||
<Handle type="target" position={Position.Top} id={`node_${id}_top`} /> | ||
<h5 className="text-xs font-bold dark:text-white">{data.label}</h5> | ||
|
||
<ConditionSection condition={data.conditions?.expressions} /> | ||
|
||
<Handle type="source" position={Position.Bottom} id={`node_${id}_bottom`} /> | ||
<Handle type="source" position={Position.Right} id={`node_${id}_right`} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { Node, NodeProps } from "@xyflow/react"; | ||
import { Handle, Position } from "@xyflow/react"; | ||
import { NodeBase } from "@xyflow/system"; | ||
import ConditionSection from "./ConditionSection"; | ||
import { BaseNodeData } from "./BaseNode"; | ||
|
||
export type ForLoopNodeData = BaseNodeData & { | ||
initializerVariable?: string; | ||
initialValue?: string; | ||
loopCondition?: string; | ||
iterator?: string; | ||
}; | ||
|
||
export type ForLoopNode = NodeBase & Node<ForLoopNodeData>; | ||
|
||
export default function ForLoopNode({ id, data }: NodeProps<ForLoopNode>) { | ||
|
||
const loopString = `For (${data.initializerVariable} = ${data.initialValue}; ${data.loopCondition}; ${data.iterator})`; | ||
|
||
return ( | ||
<div className="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"> | ||
<Handle type="target" position={Position.Top} id={`node_${id}_top`} /> | ||
<h5 className="text-xs font-bold dark:text-white">{data.label}</h5> | ||
|
||
<ConditionSection condition={data.condition} /> | ||
|
||
<ul role="list" className="text-gray-500 dark:text-gray-400"> | ||
<li className="flex space-x-2 rtl:space-x-reverse items-center"> | ||
<span className="leading-tight text-xs">{loopString}</span> | ||
</li> | ||
</ul> | ||
|
||
<Handle type="source" position={Position.Bottom} id={`node_${id}_bottom`} /> | ||
<Handle type="source" position={Position.Right} id={`node_${id}_right`} /> | ||
</div> | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
actionFlow.editor/src/components/nodes/SendHttpCallNode.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,32 @@ | ||
import type { Node, NodeProps } from "@xyflow/react"; | ||
import { Handle, Position } from "@xyflow/react"; | ||
import { NodeBase } from "@xyflow/system"; | ||
import ConditionSection from "./ConditionSection"; | ||
import { BaseNodeData } from "./BaseNode"; | ||
|
||
export type SendHttpCallNodeData = BaseNodeData & { | ||
headers?: Record<string, string>; | ||
url?: string; | ||
method?: string; | ||
body?: string; | ||
resultVariable?: string; | ||
}; | ||
export type SendHttpCallNode = NodeBase & Node<SendHttpCallNodeData>; | ||
|
||
export default function SendHttpCallNode({ id, data }: NodeProps<SendHttpCallNode>) { | ||
return ( | ||
<div className="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"> | ||
<Handle type="target" position={Position.Top} id={`node_${id}_top`} /> | ||
<h5 className="text-xs font-bold dark:text-white">{data.label}</h5> | ||
|
||
<ConditionSection condition={data.condition} /> | ||
<ul role="list" className="text-gray-500 dark:text-gray-400"> | ||
<li className="flex space-x-2 rtl:space-x-reverse items-center"> | ||
<span className="leading-tight text-xs">{data.url}</span> | ||
</li> | ||
</ul> | ||
|
||
<Handle type="source" position={Position.Bottom} id={`node_${id}_bottom`} /> | ||
</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
Oops, something went wrong.