Skip to content

Commit 599cb97

Browse files
committed
Code review
1 parent 19405fe commit 599cb97

6 files changed

Lines changed: 48 additions & 59 deletions

File tree

editor/src/messages/frontend/frontend_message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::utility_types::{DocumentDetails, MouseCursorIcon, OpenDocument};
22
use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
33
use crate::messages::layout::utility_types::widget_prelude::*;
44
use crate::messages::portfolio::document::node_graph::utility_types::{
5-
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, NodeGraphError, Transform,
5+
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, NodeGraphErrorDiagnostic, Transform,
66
};
77
use crate::messages::portfolio::document::utility_types::nodes::{JsRawBuffer, LayerPanelEntry, RawBuffer};
88
use crate::messages::portfolio::document::utility_types::wires::{WirePath, WirePathUpdate};
@@ -289,8 +289,8 @@ pub enum FrontendMessage {
289289
UpdateNodeGraphNodes {
290290
nodes: Vec<FrontendNode>,
291291
},
292-
UpdateNodeGraphError {
293-
error: Option<NodeGraphError>,
292+
UpdateNodeGraphErrorDiagnostic {
293+
error: Option<NodeGraphErrorDiagnostic>,
294294
},
295295
UpdateVisibleNodes {
296296
nodes: Vec<NodeId>,

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::messages::layout::utility_types::widget_prelude::*;
66
use crate::messages::portfolio::document::document_message_handler::navigation_controls;
77
use crate::messages::portfolio::document::graph_operation::utility_types::ModifyInputsContext;
88
use crate::messages::portfolio::document::node_graph::document_node_definitions::NodePropertiesContext;
9-
use crate::messages::portfolio::document::node_graph::utility_types::{ContextMenuData, Direction, FrontendGraphDataType, NodeGraphError};
9+
use crate::messages::portfolio::document::node_graph::utility_types::{ContextMenuData, Direction, FrontendGraphDataType, NodeGraphErrorDiagnostic};
1010
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
1111
use crate::messages::portfolio::document::utility_types::misc::GroupFolderType;
1212
use crate::messages::portfolio::document::utility_types::network_interface::{
@@ -798,9 +798,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
798798
DVec2::new(appear_right_of_mouse, appear_above_mouse) / network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport.matrix2.x_axis.x
799799
};
800800

801-
let context_menu_coordinates = node_graph_point + node_graph_shift;
802801
self.context_menu = Some(ContextMenuInformation {
803-
context_menu_coordinates: context_menu_coordinates.into(),
802+
context_menu_coordinates: (node_graph_point + node_graph_shift).into(),
804803
context_menu_data,
805804
});
806805

@@ -1224,10 +1223,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
12241223
let node_graph_shift = DVec2::new(appear_right_of_mouse, appear_above_mouse) / network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport.matrix2.x_axis.x;
12251224

12261225
let compatible_type = network_interface.output_type(&output_connector, selection_network_path).add_node_string();
1227-
let context_menu_coordinates = point + node_graph_shift;
12281226

12291227
self.context_menu = Some(ContextMenuInformation {
1230-
context_menu_coordinates: context_menu_coordinates.into(),
1228+
context_menu_coordinates: (point + node_graph_shift).into(),
12311229
context_menu_data: ContextMenuData::CreateNode { compatible_type },
12321230
});
12331231

@@ -1652,7 +1650,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
16521650
responses.add(NodeGraphMessage::UpdateVisibleNodes);
16531651

16541652
let error = self.node_graph_error(network_interface, breadcrumb_network_path);
1655-
responses.add(FrontendMessage::UpdateNodeGraphError { error });
1653+
responses.add(FrontendMessage::UpdateNodeGraphErrorDiagnostic { error });
16561654
let (layer_widths, chain_widths, has_left_input_wire) = network_interface.collect_layer_widths(breadcrumb_network_path);
16571655

16581656
responses.add(NodeGraphMessage::UpdateImportsExports);
@@ -2596,26 +2594,27 @@ impl NodeGraphMessageHandler {
25962594
Some(subgraph_names)
25972595
}
25982596

2599-
fn node_graph_error(&self, network_interface: &mut NodeNetworkInterface, breadcrumb_network_path: &[NodeId]) -> Option<NodeGraphError> {
2597+
fn node_graph_error(&self, network_interface: &mut NodeNetworkInterface, breadcrumb_network_path: &[NodeId]) -> Option<NodeGraphErrorDiagnostic> {
26002598
let graph_error = network_interface
26012599
.resolved_types
26022600
.node_graph_errors
26032601
.iter()
2604-
.filter(|error| error.node_path.starts_with(breadcrumb_network_path) && error.node_path.len() > breadcrumb_network_path.len())
2605-
.next()?;
2602+
.find(|error| error.node_path.starts_with(breadcrumb_network_path) && error.node_path.len() > breadcrumb_network_path.len())?;
26062603
let error = if graph_error.node_path.len() == breadcrumb_network_path.len() + 1 {
26072604
format!("{:?}", graph_error.error)
26082605
} else {
26092606
"Node graph type error within this node".to_string()
26102607
};
26112608
let error_node = graph_error.node_path[breadcrumb_network_path.len()];
2609+
26122610
let mut position = network_interface.position(&error_node, breadcrumb_network_path)?;
26132611
// Convert to graph space
26142612
position *= 24;
26152613
if network_interface.is_layer(&error_node, breadcrumb_network_path) {
26162614
position += IVec2::new(12, -12)
26172615
}
2618-
Some(NodeGraphError { position: position.into(), error })
2616+
2617+
Some(NodeGraphErrorDiagnostic { position: position.into(), error })
26192618
}
26202619

26212620
fn update_layer_panel(network_interface: &NodeNetworkInterface, selection_network_path: &[NodeId], collapsed: &CollapsedLayers, layers_panel_open: bool, responses: &mut VecDeque<Message>) {

editor/src/messages/portfolio/document/node_graph/utility_types.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ pub struct FrontendNode {
9090
pub primary_output: Option<FrontendGraphOutput>,
9191
#[serde(rename = "exposedOutputs")]
9292
pub exposed_outputs: Vec<FrontendGraphOutput>,
93-
#[serde(rename = "primaryOutputConnectedToLayer")]
94-
pub primary_output_connected_to_layer: bool,
9593
#[serde(rename = "primaryInputConnectedToLayer")]
9694
pub primary_input_connected_to_layer: bool,
95+
#[serde(rename = "primaryOutputConnectedToLayer")]
96+
pub primary_output_connected_to_layer: bool,
9797
pub position: IVec2,
98+
pub previewed: bool,
9899
pub visible: bool,
99100
pub locked: bool,
100-
pub previewed: bool,
101101
}
102102

103103
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
@@ -156,12 +156,12 @@ pub struct BoxSelection {
156156
#[serde(tag = "type", content = "data")]
157157
pub enum ContextMenuData {
158158
ModifyNode {
159+
#[serde(rename = "nodeId")]
160+
node_id: NodeId,
159161
#[serde(rename = "canBeLayer")]
160162
can_be_layer: bool,
161163
#[serde(rename = "currentlyIsNode")]
162164
currently_is_node: bool,
163-
#[serde(rename = "nodeId")]
164-
node_id: NodeId,
165165
},
166166
CreateNode {
167167
#[serde(rename = "compatibleType")]
@@ -179,7 +179,7 @@ pub struct ContextMenuInformation {
179179
}
180180

181181
#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize, specta::Type)]
182-
pub struct NodeGraphError {
182+
pub struct NodeGraphErrorDiagnostic {
183183
pub position: FrontendXY,
184184
pub error: String,
185185
}
@@ -208,7 +208,7 @@ pub enum Direction {
208208
Right,
209209
}
210210

211-
/// Stores node graph coordinates which are then transformed in svelte based on the node graph transform
211+
/// Stores node graph coordinates which are then transformed in Svelte based on the node graph transform
212212
#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize, specta::Type)]
213213
pub struct FrontendXY {
214214
pub x: i32,
@@ -223,6 +223,6 @@ impl From<DVec2> for FrontendXY {
223223

224224
impl From<IVec2> for FrontendXY {
225225
fn from(v: IVec2) -> Self {
226-
FrontendXY { x: v.x as i32, y: v.y as i32 }
226+
FrontendXY { x: v.x, y: v.y }
227227
}
228228
}

frontend/src/components/views/Graph.svelte

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@
212212
top: `${$nodeGraph.contextMenuInformation.contextMenuCoordinates.y * $nodeGraph.transform.scale + $nodeGraph.transform.y}px`,
213213
}}
214214
>
215-
{#if $nodeGraph.contextMenuInformation.contextMenuData.type == "CreateNode"}
215+
{#if $nodeGraph.contextMenuInformation.contextMenuData.type === "CreateNode"}
216216
<NodeCatalog initialSearchTerm={$nodeGraph.contextMenuInformation.contextMenuData.data.compatibleType || ""} on:selectNodeType={(e) => createNode(e.detail)} />
217-
{:else if $nodeGraph.contextMenuInformation.contextMenuData.type == "ModifyNode"}
217+
{:else if $nodeGraph.contextMenuInformation.contextMenuData.type === "ModifyNode"}
218218
<LayoutRow class="toggle-layer-or-node">
219219
<TextLabel>Display as</TextLabel>
220220
<RadioInput
@@ -223,12 +223,16 @@
223223
{
224224
value: "node",
225225
label: "Node",
226-
action: () => editor.handle.setToNodeOrLayer($nodeGraph.contextMenuInformation.contextMenuData.data.nodeId, false),
226+
action: () =>
227+
$nodeGraph.contextMenuInformation?.contextMenuData.type === "ModifyNode" &&
228+
editor.handle.setToNodeOrLayer($nodeGraph.contextMenuInformation.contextMenuData.data.nodeId, false),
227229
},
228230
{
229231
value: "layer",
230232
label: "Layer",
231-
action: () => editor.handle.setToNodeOrLayer($nodeGraph.contextMenuInformation.contextMenuData.data.nodeId, true),
233+
action: () =>
234+
$nodeGraph.contextMenuInformation?.contextMenuData.type === "ModifyNode" &&
235+
editor.handle.setToNodeOrLayer($nodeGraph.contextMenuInformation.contextMenuData.data.nodeId, true),
232236
},
233237
]}
234238
disabled={!$nodeGraph.contextMenuInformation.contextMenuData.data.canBeLayer}
@@ -244,20 +248,12 @@
244248

245249
{#if $nodeGraph.error}
246250
<div class="node-error-container" style:transform-origin="0 0" style:transform={`translate(${$nodeGraph.transform.x}px, ${$nodeGraph.transform.y}px) scale(${$nodeGraph.transform.scale})`}>
247-
<span
248-
class="node-error faded"
249-
style={`left: ${$nodeGraph.error.position.x}px;
250-
top: ${$nodeGraph.error.position.y}px;`}
251-
transition:fade={FADE_TRANSITION}
252-
data-node-error>{$nodeGraph.error.error}</span
253-
>
254-
<span
255-
class="node-error hover"
256-
style={`left: ${$nodeGraph.error.position.x}px;
257-
top: ${$nodeGraph.error.position.y}px;`}
258-
transition:fade={FADE_TRANSITION}
259-
data-node-error>{$nodeGraph.error.error}</span
260-
>
251+
<span class="node-error faded" style:left={`${$nodeGraph.error.position.x}px`} style:top={`${$nodeGraph.error.position.y}px`} transition:fade={FADE_TRANSITION}>
252+
{$nodeGraph.error.error}
253+
</span>
254+
<span class="node-error hover" style:left={`${$nodeGraph.error.position.x}px`} style:top={`${$nodeGraph.error.position.y}px`} transition:fade={FADE_TRANSITION}>
255+
{$nodeGraph.error.error}
256+
</span>
261257
</div>
262258
{/if}
263259

@@ -337,7 +333,7 @@
337333
style:--offset-left={($nodeGraph.updateImportsExports.importPosition.x - 8) / 24}
338334
style:--offset-top={($nodeGraph.updateImportsExports.importPosition.y - 8) / 24 + index}
339335
>
340-
{#if editingNameImportIndex == index}
336+
{#if editingNameImportIndex === index}
341337
<input
342338
class="import-text-input"
343339
type="text"
@@ -449,7 +445,7 @@
449445
{/if}
450446
{/each}
451447

452-
{#if $nodeGraph.updateImportsExports.addImportExport == true}
448+
{#if $nodeGraph.updateImportsExports.addImportExport}
453449
<div
454450
class="plus"
455451
style:--offset-left={($nodeGraph.updateImportsExports.importPosition.x - 12) / 24}
@@ -657,10 +653,6 @@
657653
title={`${node.displayName}\n\n${description || ""}`.trim() + (editor.handle.inDevelopmentMode() ? `\n\nNode ID: ${node.id}` : "")}
658654
data-node={node.id}
659655
>
660-
{#if node.errors}
661-
<span class="node-error faded" transition:fade={FADE_TRANSITION} title="" data-node-error>{node.errors}</span>
662-
<span class="node-error hover" transition:fade={FADE_TRANSITION} title="" data-node-error>{node.errors}</span>
663-
{/if}
664656
<!-- Primary row -->
665657
<div class="primary" class:in-selected-network={$nodeGraph.inSelectedNetwork} class:no-secondary-section={exposedInputsOutputs.length === 0}>
666658
<IconLabel icon={nodeIcon(node.reference)} />

frontend/src/messages.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ export class UpdateClickTargets extends JsMessage {
3333
readonly clickTargets!: FrontendClickTargets | undefined;
3434
}
3535

36-
export class UpdateContextMenuInformation extends JsMessage {
37-
readonly contextMenuInformation!: ContextMenuInformation | undefined;
38-
}
39-
4036
export class UpdateImportsExports extends JsMessage {
4137
readonly imports!: (FrontendGraphOutput | undefined)[];
4238

@@ -81,7 +77,7 @@ export class UpdateNodeGraphNodes extends JsMessage {
8177
readonly nodes!: FrontendNode[];
8278
}
8379

84-
export class UpdateNodeGraphError extends JsMessage {
80+
export class UpdateNodeGraphErrorDiagnostic extends JsMessage {
8581
readonly error!: NodeGraphError | undefined;
8682
}
8783

@@ -172,6 +168,10 @@ export type ContextMenuInformation = {
172168
contextMenuData: { type: "CreateNode"; data: { compatibleType: string | undefined } } | { type: "ModifyNode"; data: { canBeLayer: boolean; currentlyIsNode: boolean; nodeId: bigint } };
173169
};
174170

171+
export class UpdateContextMenuInformation extends JsMessage {
172+
readonly contextMenuInformation!: ContextMenuInformation | undefined;
173+
}
174+
175175
export type FrontendGraphDataType = "General" | "Number" | "Artboard" | "Graphic" | "Raster" | "Vector" | "Color" | "Invalid";
176176

177177
export class FrontendGraphInput {
@@ -201,12 +201,12 @@ export class FrontendGraphOutput {
201201
}
202202

203203
export class FrontendNode {
204+
readonly id!: bigint;
205+
204206
readonly isLayer!: boolean;
205207

206208
readonly canBeLayer!: boolean;
207209

208-
readonly id!: bigint;
209-
210210
readonly reference!: string | undefined;
211211

212212
readonly displayName!: string;
@@ -232,9 +232,7 @@ export class FrontendNode {
232232

233233
readonly visible!: boolean;
234234

235-
readonly unlocked!: boolean;
236-
237-
readonly errors!: string | undefined;
235+
readonly locked!: boolean;
238236
}
239237

240238
export class FrontendNodeType {
@@ -1696,7 +1694,7 @@ export const messageMakers: Record<string, MessageMaker> = {
16961694
UpdateMouseCursor,
16971695
UpdateNodeGraphControlBarLayout,
16981696
UpdateNodeGraphNodes,
1699-
UpdateNodeGraphError,
1697+
UpdateNodeGraphErrorDiagnostic,
17001698
UpdateNodeGraphSelection,
17011699
UpdateNodeGraphTransform,
17021700
UpdateNodeGraphWires,

frontend/src/state-providers/node-graph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
UpdateNodeGraphTransform,
2727
UpdateNodeThumbnail,
2828
UpdateWirePathInProgress,
29-
UpdateNodeGraphError,
29+
UpdateNodeGraphErrorDiagnostic,
3030
} from "@graphite/messages";
3131

3232
export function createNodeGraphState(editor: Editor) {
@@ -121,9 +121,9 @@ export function createNodeGraphState(editor: Editor) {
121121
return state;
122122
});
123123
});
124-
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphError, (updateNodeGraphError) => {
124+
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphErrorDiagnostic, (updateNodeGraphErrorDiagnostic) => {
125125
update((state) => {
126-
state.error = updateNodeGraphError.error;
126+
state.error = updateNodeGraphErrorDiagnostic.error;
127127
return state;
128128
});
129129
});

0 commit comments

Comments
 (0)