Skip to content

Commit c13647a

Browse files
adamgerhantKeavon
andauthored
Fix regression where tooltip node descriptions in the graph stopped showing (#3639)
* Fix tooltips * Convert DefinitionIdentifier to string in JavaScript * Code review --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent c60ddcf commit c13647a

10 files changed

Lines changed: 47 additions & 51 deletions

File tree

editor/src/messages/frontend/frontend_message.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::utility_types::{DocumentDetails, MouseCursorIcon, OpenDocument};
22
use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
33
use crate::messages::input_mapper::utility_types::misc::ActionShortcut;
44
use crate::messages::layout::utility_types::widget_prelude::*;
5-
use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier;
65
use crate::messages::portfolio::document::node_graph::utility_types::{
76
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, NodeGraphErrorDiagnostic, Transform,
87
};
@@ -61,7 +60,7 @@ pub enum FrontendMessage {
6160
// Send prefix: Send global, static data to the frontend that is never updated
6261
SendUIMetadata {
6362
#[serde(rename = "nodeDescriptions")]
64-
node_descriptions: Vec<(DefinitionIdentifier, String)>,
63+
node_descriptions: Vec<(String, String)>,
6564
#[serde(rename = "nodeTypes")]
6665
node_types: Vec<FrontendNodeType>,
6766
},

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,23 @@ impl DefinitionIdentifier {
8080
}),
8181
}
8282
}
83+
84+
pub fn serialized(&self) -> String {
85+
match self {
86+
DefinitionIdentifier::ProtoNode(id) => format!("PROTONODE:{}", id.as_str()),
87+
DefinitionIdentifier::Network(data) => format!("NETWORK:{}", data),
88+
}
89+
}
8390
}
8491

8592
impl From<Value> for DefinitionIdentifier {
8693
fn from(value: Value) -> Self {
87-
match value {
88-
Value::Object(mut map) => {
89-
let ty = map.remove("type").unwrap().as_str().unwrap().to_owned();
94+
let s = value.as_str().expect("DefinitionIdentifier value must be a string");
9095

91-
match ty.as_ref() {
92-
"Network" => {
93-
let data = map.remove("data").unwrap().as_str().unwrap().to_owned();
94-
DefinitionIdentifier::Network(data)
95-
}
96-
"ProtoNode" => {
97-
let value = map.remove("data").unwrap();
98-
let proto: ProtoNodeIdentifier = serde_json::from_value(value).unwrap();
99-
DefinitionIdentifier::ProtoNode(proto)
100-
}
101-
_ => panic!("Unknown `DefinitionIdentifier` type: {:?}", ty),
102-
}
103-
}
104-
105-
_ => panic!("Expected a JSON object to convert to `DefinitionIdentifier`"),
96+
match s.split_once(':') {
97+
Some(("PROTONODE", data)) => DefinitionIdentifier::ProtoNode(ProtoNodeIdentifier::with_owned_string(data.to_string())),
98+
Some(("NETWORK", data)) => DefinitionIdentifier::Network(data.to_string()),
99+
other => panic!("Unknown `DefinitionIdentifier` type. Found `{other:?}`."),
106100
}
107101
}
108102
}
@@ -2621,7 +2615,7 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
26212615
name = identifier.implementation_name_from_identifier()
26222616
}
26232617
FrontendNodeType {
2624-
identifier: identifier.clone(),
2618+
identifier: identifier.serialized(),
26252619
name,
26262620
category: definition.category.to_string(),
26272621
input_types,
@@ -2630,10 +2624,15 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
26302624
.collect()
26312625
}
26322626

2633-
pub fn collect_node_descriptions() -> Vec<(DefinitionIdentifier, String)> {
2627+
pub fn collect_node_descriptions() -> Vec<(String, String)> {
26342628
DOCUMENT_NODE_TYPES
26352629
.iter()
2636-
.map(|(identifier, definition)| (identifier.clone(), if definition.description != "TODO" { definition.description.to_string() } else { String::new() }))
2630+
.map(|(identifier, definition)| {
2631+
(
2632+
identifier.serialized(),
2633+
if definition.description != "TODO" { definition.description.to_string() } else { String::new() },
2634+
)
2635+
})
26372636
.collect()
26382637
}
26392638

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,7 +2599,7 @@ impl NodeGraphMessageHandler {
25992599
.node_metadata(&node_id, breadcrumb_network_path)
26002600
.is_some_and(|node_metadata| node_metadata.persistent_metadata.is_layer()),
26012601
can_be_layer: network_interface.is_eligible_to_be_layer(&node_id, breadcrumb_network_path),
2602-
reference: network_interface.reference(&node_id, breadcrumb_network_path),
2602+
reference: network_interface.reference(&node_id, breadcrumb_network_path).map(|reference| reference.serialized()),
26032603
display_name: network_interface.display_name(&node_id, breadcrumb_network_path),
26042604
implementation_name: network_interface.implementation_name(&node_id, breadcrumb_network_path),
26052605
primary_input,
@@ -2715,16 +2715,12 @@ impl NodeGraphMessageHandler {
27152715
}
27162716
});
27172717

2718-
let Some(reference) = network_interface.reference(&node_id, &[]) else {
2719-
log::error!("Could not get reference for layer {node_id} in update_layer_panel");
2720-
continue;
2721-
};
2722-
27232718
let clippable = layer.can_be_clipped(network_interface.document_metadata());
27242719

27252720
let data = LayerPanelEntry {
27262721
id: node_id,
2727-
reference,
2722+
implementation_name: network_interface.implementation_name(&node_id, &[]),
2723+
icon_name: network_interface.is_artboard(&node_id, &[]).then(|| "Artboard".to_string()),
27282724
alias: network_interface.display_name(&node_id, &[]),
27292725
in_selected_network: selection_network_path.is_empty(),
27302726
children_allowed,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::document_node_definitions::DefinitionIdentifier;
21
use glam::{DVec2, IVec2};
32
use graph_craft::document::NodeId;
43
use graph_craft::document::value::TaggedValue;
@@ -79,7 +78,7 @@ pub struct FrontendNode {
7978
pub is_layer: bool,
8079
#[serde(rename = "canBeLayer")]
8180
pub can_be_layer: bool,
82-
pub reference: Option<DefinitionIdentifier>,
81+
pub reference: Option<String>,
8382
#[serde(rename = "displayName")]
8483
pub display_name: String,
8584
#[serde(rename = "implementationName")]
@@ -104,7 +103,7 @@ pub struct FrontendNode {
104103

105104
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
106105
pub struct FrontendNodeType {
107-
pub identifier: DefinitionIdentifier,
106+
pub identifier: String,
108107
pub name: String,
109108
pub category: String,
110109
#[serde(rename = "inputTypes")]

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
22
use super::network_interface::NodeNetworkInterface;
3-
use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier;
43
use crate::messages::tool::common_functionality::graph_modification_utils;
54
use glam::DVec2;
65
use graph_craft::document::{NodeId, NodeNetwork};
@@ -35,7 +34,10 @@ impl serde::Serialize for JsRawBuffer {
3534
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, specta::Type)]
3635
pub struct LayerPanelEntry {
3736
pub id: NodeId,
38-
pub reference: DefinitionIdentifier,
37+
#[serde(rename = "implementationName")]
38+
pub implementation_name: String,
39+
#[serde(rename = "iconName")]
40+
pub icon_name: Option<String>,
3941
pub alias: String,
4042
#[serde(rename = "inSelectedNetwork")]
4143
pub in_selected_network: bool,

frontend/src/components/floating-menus/NodeCatalog.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script lang="ts">
22
import { createEventDispatcher, getContext, onMount } from "svelte";
33
4-
import type { DefinitionIdentifier, FrontendNodeType } from "@graphite/messages";
4+
import type { FrontendNodeType } from "@graphite/messages";
55
import type { NodeGraphState } from "@graphite/state-providers/node-graph";
66
77
import LayoutCol from "@graphite/components/layout/LayoutCol.svelte";
88
import TextButton from "@graphite/components/widgets/buttons/TextButton.svelte";
99
import TextInput from "@graphite/components/widgets/inputs/TextInput.svelte";
1010
import TextLabel from "@graphite/components/widgets/labels/TextLabel.svelte";
1111
12-
const dispatch = createEventDispatcher<{ selectNodeType: DefinitionIdentifier }>();
12+
const dispatch = createEventDispatcher<{ selectNodeType: string }>();
1313
const nodeGraph = getContext<NodeGraphState>("nodeGraph");
1414
1515
// Content
@@ -125,7 +125,7 @@
125125
{disabled}
126126
label={nodeType.name}
127127
tooltipLabel={nodeType.name}
128-
tooltipDescription={$nodeGraph.nodeDescriptions.get(nodeType.identifier)}
128+
tooltipDescription={nodeType.identifier ? $nodeGraph.nodeDescriptions.get(nodeType.identifier) : undefined}
129129
action={() => dispatch("selectNodeType", nodeType.identifier)}
130130
/>
131131
{/each}

frontend/src/components/panels/Layers.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,15 @@
644644
{@html $nodeGraph.thumbnails.get(listing.entry.id)}
645645
{/if}
646646
</div>
647-
{#if listing.entry.reference.type === "Network" && listing.entry.reference.data === "Artboard"}
648-
<IconLabel icon="Artboard" class="layer-type-icon" tooltipLabel="Artboard" />
647+
{#if listing.entry.iconName}
648+
<IconLabel icon={listing.entry.iconName} class="layer-type-icon" tooltipLabel="Artboard" />
649649
{/if}
650650
<LayoutRow class="layer-name" on:dblclick={() => onEditLayerName(listing)}>
651651
<input
652652
data-text-input
653653
type="text"
654654
value={listing.entry.alias}
655-
placeholder={listing.entry.reference.data}
655+
placeholder={listing.entry.implementationName}
656656
disabled={!listing.editingName}
657657
on:blur={() => onEditLayerNameDeselect(listing)}
658658
on:keydown={(e) => e.key === "Escape" && onEditLayerNameDeselect(listing)}

frontend/src/components/views/Graph.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { fade } from "svelte/transition";
55
66
import type { Editor } from "@graphite/editor";
7-
import type { DefinitionIdentifier, FrontendGraphInput, FrontendGraphOutput, FrontendNode } from "@graphite/messages";
7+
import type { FrontendGraphInput, FrontendGraphOutput, FrontendNode } from "@graphite/messages";
88
import type { NodeGraphState } from "@graphite/state-providers/node-graph";
99
1010
import NodeCatalog from "@graphite/components/floating-menus/NodeCatalog.svelte";
@@ -100,7 +100,7 @@
100100
return sparse;
101101
}
102102
103-
function createNode(identifier: DefinitionIdentifier) {
103+
function createNode(identifier: string) {
104104
if ($nodeGraph.contextMenuInformation === undefined) return;
105105
106106
editor.handle.createNode(identifier, $nodeGraph.contextMenuInformation.contextMenuCoordinates.x, $nodeGraph.contextMenuInformation.contextMenuCoordinates.y);
@@ -481,7 +481,7 @@
481481
{@const layerAreaWidth = $nodeGraph.layerWidths.get(node.id) || 8}
482482
{@const layerChainWidth = $nodeGraph.chainWidths.get(node.id) || 0}
483483
{@const hasLeftInputWire = $nodeGraph.hasLeftInputWire.get(node.id) || false}
484-
{@const description = (node.reference && $nodeGraph.nodeDescriptions.get(node.reference)) || undefined}
484+
{@const description = node.reference ? $nodeGraph.nodeDescriptions.get(node.reference) : undefined}
485485
<div
486486
class="layer"
487487
class:selected={$nodeGraph.selected.includes(node.id)}
@@ -634,7 +634,7 @@
634634
.map(([_, node], nodeIndex) => ({ node, nodeIndex })) as { node, nodeIndex } (nodeIndex)}
635635
{@const exposedInputsOutputs = zipWithUndefined(node.exposedInputs, node.exposedOutputs)}
636636
{@const clipPathId = String(Math.random()).substring(2)}
637-
{@const description = (node.reference && $nodeGraph.nodeDescriptions.get(node.reference)) || undefined}
637+
{@const description = node.reference ? $nodeGraph.nodeDescriptions.get(node.reference) : undefined}
638638
<div
639639
class="node"
640640
class:selected={$nodeGraph.selected.includes(node.id)}

frontend/src/messages.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class UpdateNodeGraphTransform extends JsMessage {
102102

103103
export class SendUIMetadata extends JsMessage {
104104
@Transform(({ obj }) => new Map(obj.nodeDescriptions))
105-
readonly nodeDescriptions!: Map<DefinitionIdentifier, string>;
105+
readonly nodeDescriptions!: Map<string, string>;
106106

107107
readonly nodeTypes!: FrontendNodeType[];
108108
}
@@ -220,7 +220,7 @@ export class FrontendNode {
220220

221221
readonly canBeLayer!: boolean;
222222

223-
readonly reference!: DefinitionIdentifier | undefined;
223+
readonly reference!: string | undefined;
224224

225225
readonly displayName!: string;
226226

@@ -251,7 +251,7 @@ export class FrontendNode {
251251
}
252252

253253
export class FrontendNodeType {
254-
readonly identifier!: DefinitionIdentifier;
254+
readonly identifier!: string;
255255

256256
readonly name!: string;
257257

@@ -834,7 +834,9 @@ export class UpdateDocumentLayerDetails extends JsMessage {
834834
export class LayerPanelEntry {
835835
id!: bigint;
836836

837-
reference!: DefinitionIdentifier;
837+
implementationName!: string;
838+
839+
iconName!: IconName | undefined;
838840

839841
alias!: string;
840842

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
type FrontendNode,
1010
type FrontendNodeType,
1111
type WirePath,
12-
type DefinitionIdentifier,
1312
ClearAllNodeGraphWires,
1413
SendUIMetadata,
1514
UpdateBox,
@@ -45,7 +44,7 @@ export function createNodeGraphState(editor: Editor) {
4544
/// The index is the exposed input index. The exports have a first key value of u32::MAX.
4645
wires: new Map<bigint, Map<number, WirePath>>(),
4746
wirePathInProgress: undefined as WirePath | undefined,
48-
nodeDescriptions: new Map<DefinitionIdentifier, string>(),
47+
nodeDescriptions: new Map<string, string>(),
4948
nodeTypes: [] as FrontendNodeType[],
5049
thumbnails: new Map<bigint, string>(),
5150
selected: [] as bigint[],

0 commit comments

Comments
 (0)