2. Add relationships and a non-gesture editing path
The connectors describe the sequence in which steps were added. Moving a card changes its geometry, not that sequence. Edge identity comes from its two endpoint IDs, so it remains attached when either endpoint moves.
A canvas cannot be the only way to edit the plan. The labelled buttons below it use the same selected-step state as tapping a node. Movement and removal are ordinary reducers, so someone who cannot perform a precise drag can still arrange the plan.
Replace only the screen; state, card and shells stay shared:
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use fission::op::{Fill, LineCap, LineJoin, Stroke};
use crate::card::InspectionStepCard;
use crate::state::{
InspectionCanvasState, EditInspectionCanvas, edit_inspection_canvas,
SelectInspectionStep, select_inspection_step,
};
fission_component! {
pub App<InspectionCanvasState> {
state {
title: String = String::new(),
detail: String = String::new(),
invalid: bool = false,
}
}
view(draft, state, cx) {
let tokens = &cx.view.env().theme.tokens;
let edit = with_reducer!(cx.build, EditInspectionCanvas, edit_inspection_canvas);
let selected = state.selected_step.into_iter().collect::<std::collections::BTreeSet<_>>();
let nodes = state.steps.iter().map(|step| {
let mut node = InfiniteCanvasNode::new(
step.id,
step.bounds,
Widget::from(InspectionStepCard::new(
step.title.clone(),
step.detail.clone(),
state.selected_step == Some(step.id),
)).id(WidgetId::explicit(&format!("{}.card", step.key))),
);
node.resizable = false;
node
}).collect::<Vec<_>>();
let edges = state.steps.windows(2).map(|pair| {
InfiniteCanvasEdge {
id: CanvasEdgeId::explicit(&format!("{}-to-{}", pair[0].key, pair[1].key)),
from: CanvasEdgeEndpoint::Node { node: pair[0].id, anchor: CanvasNodeAnchor::Right },
to: CanvasEdgeEndpoint::Node { node: pair[1].id, anchor: CanvasNodeAnchor::Left },
route: CanvasEdgeRoute::Straight,
stroke: Stroke {
fill: Fill::Solid(tokens.colors.primary),
width: 2.0,
dash_array: None,
dash_offset: 0.0,
line_cap: LineCap::Round,
line_join: LineJoin::Round,
trim: None,
},
start_marker: None,
end_marker: None,
label: Some(CanvasEdgeLabel::new(Text::new(cx.tr("canvas.next")))),
}
}).collect::<Vec<_>>();
} =>
Container(SafeArea(child: Scroll(child:
Container(Column(gap: tokens.spacing.m, children: [
Text(cx.tr("canvas.title")).size(tokens.typography.heading1_size),
Text(cx.tr("canvas.description")),
TextInput(label: Some(cx.tr("canvas.new_title").into()), bind: draft.title,
required: true, semantics_identifier: "canvas.draft.title".to_string()),
TextInput(label: Some(cx.tr("canvas.new_detail").into()), bind: draft.detail,
required: true, semantics_identifier: "canvas.draft.detail".to_string()),
Button(
child: Text(cx.tr("canvas.add")),
key: "add-step",
on_press: reduce {
if state.add_step(draft.title.clone(), draft.detail.clone()) {
draft.title.clear();
draft.detail.clear();
draft.invalid = false;
} else { draft.invalid = true; }
},
).semantics_identifier("canvas.add-step"),
if draft.invalid { Text(cx.tr("canvas.invalid")).color(tokens.colors.error) },
Container(
if state.steps.is_empty() {
EmptyState(title: cx.tr("canvas.empty"),
description: Some(cx.tr("canvas.empty_help")))
} else {
InfiniteCanvas(
id: Some(WidgetId::explicit("inspection.plan")),
nodes: nodes,
edges: edges,
selected_nodes: selected,
selection_policy: CanvasSelectionPolicy::Single,
grid: Some(CanvasGrid::lines(32.0, tokens.colors.border, 1.0)),
min_scale: 0.25,
max_scale: 3.0,
actions: InfiniteCanvasActions {
on_selection_change: Some(edit.clone()),
on_node_move: Some(edit),
..Default::default()
},
)
}
).height(360.0).border(tokens.colors.border, 1.0),
if let Some(step) = state.steps.iter().find(|step| Some(step.id) == state.selected_step) {
Column(gap: tokens.spacing.s, children: [
Text(step.title.clone()).weight(tokens.typography.font_weight_semibold),
Text(step.detail.clone()),
])
},
Text(cx.tr("canvas.step_list")).weight(tokens.typography.font_weight_semibold),
Row(gap: tokens.spacing.s, wrap: ir_op::FlexWrap::Wrap, children: [
for step in &state.steps {
Button(
child: Text(step.title.clone()),
key: step.key.clone(),
variant: if state.selected_step == Some(step.id) {
ButtonVariant::Primary
} else {
ButtonVariant::Outline
},
on_press: with_reducer!(
cx.build, SelectInspectionStep(step.id), select_inspection_step
),
).id(WidgetId::explicit(&format!("{}.select", step.key)))
},
]),
if state.selected_step.is_some() {
Row(gap: tokens.spacing.s, wrap: ir_op::FlexWrap::Wrap, children: [
Button(child: Text(cx.tr("canvas.left")), key: "move-left",
on_press: reduce { state.move_selected(-32.0, 0.0); }),
Button(child: Text(cx.tr("canvas.right")), key: "move-right",
on_press: reduce { state.move_selected(32.0, 0.0); }),
Button(child: Text(cx.tr("canvas.up")), key: "move-up",
on_press: reduce { state.move_selected(0.0, -32.0); }),
Button(child: Text(cx.tr("canvas.down")), key: "move-down",
on_press: reduce { state.move_selected(0.0, 32.0); }),
Button(child: Text(cx.tr("canvas.remove")), key: "remove-step",
on_press: reduce { state.remove_selected(); }),
])
},
]))
.padding_all(tokens.spacing.l)
.width_length(Length::percent(100.0))
.max_width(1040.0),
)))
.height_length(Length::vh(100.0))
}
{"id":"fission-tabs-1"}
Add three steps again. Select the second using its labelled button and move it with the direction controls. The connectors should still join the same steps. Remove the first step and check that the remaining titles, selection and IDs do not shift onto another record. Add a new step: it must receive a new identity, not inherit the removed node's identity.
Show the app previewHide the app preview
Show the app preview
Hide the app preview