Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ serde_json = { workspace = true, optional = true }


# --- Dependencies for diagram feature
jsonschema = { version = "0.62", default-features = false, optional = true }
schemars = { workspace = true, optional = true }
serde_with = { workspace = true, optional = true }
cel-interpreter = { version = "0.9.0", features = ["json"], optional = true }
Expand Down Expand Up @@ -152,6 +153,7 @@ json = [
single_threaded_async = ["dep:async-task"]
diagram = [
"json",
"dep:jsonschema",
"dep:cel-interpreter",
"dep:semver",
"dep:serde_with",
Expand Down
2 changes: 1 addition & 1 deletion diagram-editor/dist.hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
04431de9d34dd48519d8e1a7d3b846e91743f9021e023ad7427ac3b12492dd24
d07f108c826cdf7d99e8b793b7fbdd106c6bf37b70729f98470f34a7d7c8f770
46 changes: 44 additions & 2 deletions diagram-editor/frontend/api.preprocessed.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,13 @@
"type": "string"
},
"config": true,
"config_bindings": {
"additionalProperties": {
"type": "string"
},
"description": "JSON pointers within config linked to properties of the enclosing template.",
"type": "object"
},
"display_text": {
"description": "Override for text that should be displayed for an operation within an\neditor.",
"type": [
Expand Down Expand Up @@ -1872,6 +1879,13 @@
"config": {
"description": "Configured data to pass into the function that `run` refers to. This will\nbe passed in as a keyword argument named `config`."
},
"config_bindings": {
"additionalProperties": {
"type": "string"
},
"description": "JSON pointers within config linked to properties of the enclosing template.",
"type": "object"
},
"display_text": {
"description": "Override for text that should be displayed for an operation within an\neditor.",
"type": [
Expand Down Expand Up @@ -2061,8 +2075,12 @@
{
"description": "Connect the request to a registered section.\n\n```\n# crossflow::Diagram::from_json_str(r#\"\n{\n \"version\": \"0.1.0\",\n \"start\": \"section_op\",\n \"ops\": {\n \"section_op\": {\n \"type\": \"section\",\n \"builder\": \"my_section_builder\",\n \"connect\": {\n \"my_section_output\": { \"builtin\": \"terminate\" }\n }\n }\n }\n}\n# \"#)?;\n# Ok::<_, serde_json::Error>(())\n```\n\nCustom sections can also be created via templates\n```\n# crossflow::Diagram::from_json_str(r#\"\n{\n \"version\": \"0.1.0\",\n \"templates\": {\n \"my_template\": {\n \"inputs\": [\"section_input\"],\n \"outputs\": [\"section_output\"],\n \"buffers\": [],\n \"ops\": {\n \"section_input\": {\n \"type\": \"node\",\n \"builder\": \"my_node\",\n \"next\": \"section_output\"\n }\n }\n }\n },\n \"start\": \"section_op\",\n \"ops\": {\n \"section_op\": {\n \"type\": \"section\",\n \"template\": \"my_template\",\n \"connect\": {\n \"section_output\": { \"builtin\": \"terminate\" }\n }\n }\n }\n}\n# \"#)?;\n# Ok::<_, serde_json::Error>(())\n```",
"properties": {
"config": {
"default": null
"config": true,
"config_bindings": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"connect": {
"additionalProperties": {
Expand Down Expand Up @@ -2104,6 +2122,23 @@
"buffers": {
"$ref": "#/$defs/InputRemapping"
},
"config_schema": {
"anyOf": [
{
"$ref": "#/$defs/Schema"
},
{
"type": "null"
}
]
},
"input_schemas": {
"additionalProperties": {
"$ref": "#/$defs/Schema"
},
"description": "JSON Schemas for the template's exposed input ports.",
"type": "object"
},
"inputs": {
"$ref": "#/$defs/InputRemapping"
},
Expand All @@ -2114,6 +2149,13 @@
"description": "Operations that define the behavior of the section.",
"type": "object"
},
"output_schemas": {
"additionalProperties": {
"$ref": "#/$defs/Schema"
},
"description": "JSON Schemas for the template's exposed output ports.",
"type": "object"
},
"outputs": {
"default": [],
"description": "These are the outputs that the section is exposing so you can connect\nthem into siblings of the section.",
Expand Down
40 changes: 20 additions & 20 deletions diagram-editor/frontend/command-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CommandPanelProps {
exportDisabledReason?: string;
isDirty: boolean;
scriptNodeBinding?: ScriptNodeEnvironmentBinding;
templatePanel?: React.ReactNode;
}

const VisuallyHiddenInput = styled('input')({
Expand All @@ -43,6 +44,7 @@ function CommandPanel({
exportDisabledReason,
isDirty,
scriptNodeBinding,
templatePanel,
}: CommandPanelProps) {
const theme = useTheme();
const [openEditTemplatesDialog, setOpenEditTemplatesDialog] =
Expand Down Expand Up @@ -88,34 +90,31 @@ function CommandPanel({
</Button>
</Tooltip>
)}
{editorMode.mode === EditorMode.Normal && (
<Tooltip title="Script Environment Manager">
<Button
onClick={() => toggleTab('environments')}
sx={
openSidePanel && sidePanelTab === 'environments'
? { backgroundColor: theme.palette.primary.light }
: undefined
}
>
<MaterialSymbol symbol="code" />
</Button>
</Tooltip>
)}
{editorMode.mode === EditorMode.Normal && (
<Tooltip title="Diagram properties">
{(
[
['environments', 'Script Environment Manager', 'code'],
[
'properties',
editorMode.mode === EditorMode.Template
? 'Template settings'
: 'Diagram properties',
'info',
],
] as const
).map(([tab, title, symbol]) => (
<Tooltip key={tab} title={title}>
<Button
onClick={() => toggleTab('properties')}
onClick={() => toggleTab(tab)}
sx={
openSidePanel && sidePanelTab === 'properties'
openSidePanel && sidePanelTab === tab
? { backgroundColor: theme.palette.primary.light }
: undefined
}
>
<MaterialSymbol symbol="info" />
<MaterialSymbol symbol={symbol} />
</Button>
</Tooltip>
)}
))}
{editorMode.mode === EditorMode.Normal && (
<Tooltip title="Templates">
<Button onClick={() => setOpenEditTemplatesDialog(true)}>
Expand Down Expand Up @@ -170,6 +169,7 @@ function CommandPanel({
runRequestJson={runRequestJson}
onRunRequestJsonChange={setRunRequestJson}
scriptNodeBinding={scriptNodeBinding}
templatePanel={templatePanel}
/>
</>
);
Expand Down
85 changes: 72 additions & 13 deletions diagram-editor/frontend/diagram-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ import {
useDiagramProperties,
} from './diagram-properties-provider';
import { useDiagramSidePanel } from './diagram-side-panel-controller';
import { getEditPopoverPositionForNode } from './diagram-side-panel-layout';
import {
getEditPopoverPositionForNode,
MinimumVisibleCanvasWidth,
} from './diagram-side-panel-layout';
import {
clearDraftWorkspace,
type DraftWorkspaceContent,
Expand All @@ -69,6 +72,7 @@ import { ExportDiagramDialog } from './export-diagram-dialog';
import { EditEdgeForm, EditNodeForm } from './forms';
import EditScopeForm from './forms/edit-scope-form';
import type { ScriptNodeEnvironmentBinding } from './forms/script-environment-workspace';
import TemplatePanel from './forms/template-panel';
import { useScriptEnvironmentNavigation } from './forms/use-script-environment-navigation';
import {
type InteractionVisualizationContext,
Expand All @@ -83,6 +87,7 @@ import { NodeManager, NodeManagerProvider } from './node-manager';
import {
type DiagramEditorNode,
isBuiltinNode,
isOperationNode,
MaterialSymbol,
NODE_TYPES,
type OperationNode,
Expand All @@ -97,6 +102,7 @@ import type { Diagram } from './types/api';
import { useBeforeUnloadWarning } from './use-before-unload-warning';
import { useDraftPagehideFlush } from './use-draft-pagehide-flush';
import { EdgesProvider } from './use-edges';
import { useDiagramSidePanelWidth } from './use-responsive-edit-popover-position';
import { autoLayout } from './utils/auto-layout';
import { isRemoveChange } from './utils/change';
import { prepareConnection } from './utils/compatibility';
Expand All @@ -119,12 +125,17 @@ import {
} from './utils/load-diagram';
import { joinNamespaces, ROOT_NAMESPACE } from './utils/namespace';
import { updateOperationIds } from './utils/operation-id';

const NonCapturingPopoverContainer = ({
children,
}: {
children: React.ReactNode;
}) => <>{children}</>;
import { updateTemplateSchema } from './utils/update-template-schema';

// Keep canvas clicks available while giving MUI a real modal root to restore
// focus and accessibility when a nested select or field menu closes.
const canvasPopover = {
hideBackdrop: true,
sx: {
pointerEvents: 'none',
'& .MuiPopover-paper': { pointerEvents: 'auto' },
},
} as const;

interface EditingEdge {
sourceNode: DiagramEditorNode;
Expand Down Expand Up @@ -415,6 +426,7 @@ function DiagramEditor() {
const {
state: sidePanelState,
restoreState: restoreSidePanel,
showTab,
finishEnvironmentEdit,
requestEnvironmentLeave,
} = useDiagramSidePanel();
Expand All @@ -424,6 +436,7 @@ function DiagramEditor() {
width: sidePanelWidth,
tab: sidePanelTab,
} = sidePanelState;
const drawerWidth = useDiagramSidePanelWidth(sidePanelOpen);
const [viewport, setViewport] = React.useState<Viewport>({
x: 0,
y: 0,
Expand All @@ -444,6 +457,7 @@ function DiagramEditor() {
if (!template) {
throw new Error(`template ${newMode.templateId} not found`);
}
showTab('properties');
const graph = loadTemplate(template);
const changes = autoLayout(graph.nodes, graph.edges, LAYOUT_OPTIONS);
// using callback form so that `nodes` and `edges` don't need to be part of dependencies.
Expand All @@ -466,7 +480,7 @@ function DiagramEditor() {

setEditorMode(newMode);
},
[templates],
[templates, showTab],
);

const handleEdgeChanges = React.useCallback(
Expand Down Expand Up @@ -1589,22 +1603,69 @@ function DiagramEditor() {
}
isDirty={isDirty}
scriptNodeBinding={scriptNodeBinding}
templatePanel={
editorMode.mode === EditorMode.Template && (
<TemplatePanel
templateId={editorMode.templateId}
onChangeSchema={(config_schema, rename) => {
const edit = updateTemplateSchema(
editorMode.templateId,
config_schema,
rename,
nodes,
savedNodes.current,
templates,
transientEditorDrafts.operationConfigs,
);
if (typeof edit === 'string') {
if (!rename) showErrorToast(edit);
return edit;
}
savedNodes.current = edit.main;
setNodes(edit.edited);
setTemplates(edit.templates);
}}
/>
)
}
/>
{editorMode.mode === EditorMode.Template && (
<Fab
color="primary"
aria-label="Save"
sx={{ position: 'absolute', right: 64, bottom: 64 }}
sx={{
position: 'absolute',
right: `min(${drawerWidth + 64}px, calc(100% - ${MinimumVisibleCanvasWidth}px))`,
bottom: 64,
transition: theme.transitions.create([
'right',
'box-shadow',
'background-color',
]),
}}
onClick={() => {
const unfinished = nodes.find(
(node) =>
`${node.type}:${node.id}:config` in
transientEditorDrafts.operationConfigs,
);
if (unfinished && isOperationNode(unfinished)) {
showErrorToast(
`Finish editing the config for "${unfinished.data.opId}" before saving.`,
);
return;
}
const exportedTemplate = exportTemplate(
registry,
nodeManager,
edges,
templates[editorMode.templateId],
);
setTemplates((prev) => ({
...prev,
[editorMode.templateId]: exportedTemplate,
}));
closeAllPopovers();
updateEditorModeAction({ mode: EditorMode.Normal });
}}
>
Expand All @@ -1617,8 +1678,7 @@ function DiagramEditor() {
onClose={closeAllPopovers}
anchorReference="anchorPosition"
anchorPosition={addOperationPopover.popOverPosition}
// use a custom component to prevent the popover from creating an invisible element that blocks clicks
component={NonCapturingPopoverContainer}
{...canvasPopover}
>
{addOperationPopover.sourceConnection ? (
<CompatibleAddOperation
Expand Down Expand Up @@ -1680,8 +1740,7 @@ function DiagramEditor() {
}
setEditOpFormPopoverProps({ open: false });
}}
// use a custom component to prevent the popover from creating an invisible element that blocks clicks
component={NonCapturingPopoverContainer}
{...canvasPopover}
>
{editingNodeId && renderEditForm(editingNodeId)}
{editingEdge && (
Expand Down
Loading
Loading