Skip to content

Commit b14f682

Browse files
committed
rendering morph data in html in the NodeCard
transition state change of morphs of a polynode and refreshing visualization
1 parent 961d9ec commit b14f682

3 files changed

Lines changed: 100 additions & 6 deletions

File tree

nodebook-base/frontend/src/App.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,29 @@ function App({ onLogout, onGoToDashboard, user }: AppProps) {
153153
if (!activeGraphId) return;
154154

155155
try {
156+
console.log(`[App] Changing morph for node ${nodeId} to ${morphId}`);
157+
156158
const response = await authenticatedFetch(`/api/graphs/${activeGraphId}/nodes/${nodeId}/morph`, {
157159
method: 'POST',
158160
body: JSON.stringify({ morphId })
159161
});
160162

163+
console.log(`[App] Morph change response:`, { status: response.status, ok: response.ok });
164+
161165
if (response.ok) {
166+
const result = await response.json();
167+
console.log(`[App] Morph change successful:`, result);
168+
162169
// Refresh the graph data to show the updated morph
163-
await loadGraphData(activeGraphId);
170+
fetchGraph(activeGraphId);
164171
} else {
165-
throw new Error('Failed to change morph');
172+
const errorText = await response.text();
173+
console.error(`[App] Morph change failed:`, { status: response.status, error: errorText });
174+
throw new Error(`Failed to change morph: ${response.status} ${errorText}`);
166175
}
167176
} catch (error) {
168-
console.error('Error changing morph:', error);
169-
alert('Failed to change morph. See console for details.');
177+
console.error('[App] Error changing morph:', error);
178+
alert(`Failed to change morph: ${error.message}`);
170179
}
171180
};
172181
const [isWordNetLoading, setIsWordNetLoading] = useState(false);

nodebook-base/frontend/src/NodeCard.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,47 @@
236236
color: #007bff;
237237
font-size: 0.8rem;
238238
font-style: italic;
239+
}
240+
241+
/* Morph data display */
242+
.node-morph-data {
243+
margin: 1rem 0;
244+
padding: 1rem;
245+
background-color: #f8f9fa;
246+
border: 1px solid #e9ecef;
247+
border-radius: 6px;
248+
}
249+
250+
.node-morph-data h4 {
251+
margin: 0 0 0.75rem 0;
252+
color: #495057;
253+
font-size: 1rem;
254+
font-weight: 600;
255+
}
256+
257+
.node-morph-data h5 {
258+
margin: 0.5rem 0 0.25rem 0;
259+
color: #6c757d;
260+
font-size: 0.875rem;
261+
font-weight: 500;
262+
}
263+
264+
.morph-attributes ul,
265+
.morph-relations ul {
266+
margin: 0;
267+
padding-left: 1.25rem;
268+
list-style-type: disc;
269+
}
270+
271+
.morph-attributes li,
272+
.morph-relations li {
273+
margin: 0.25rem 0;
274+
font-size: 0.875rem;
275+
line-height: 1.4;
276+
}
277+
278+
.morph-attributes strong,
279+
.morph-relations strong {
280+
color: #495057;
281+
font-weight: 500;
239282
}

nodebook-base/frontend/src/NodeCard.tsx

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,18 @@ export function NodeCard({ node, allNodes, allRelations, attributes, isActive, o
163163

164164
setIsChangingMorph(true);
165165
try {
166+
console.log(`[NodeCard] Changing morph for node ${node.id} to ${morphId}`);
167+
166168
// Update the node's nbh property locally for immediate UI update
167169
node.nbh = morphId;
168170

169171
// Notify parent component to handle the API call and refresh graph data
170172
await onMorphChange(node.id, morphId);
173+
174+
console.log(`[NodeCard] Morph change completed successfully`);
171175
} catch (error) {
172-
console.error('Error changing morph:', error);
173-
alert('Failed to change morph. See console for details.');
176+
console.error('[NodeCard] Error changing morph:', error);
177+
alert(`Failed to change morph: ${error.message}`);
174178
} finally {
175179
setIsChangingMorph(false);
176180
}
@@ -273,6 +277,44 @@ export function NodeCard({ node, allNodes, allRelations, attributes, isActive, o
273277
/>
274278
</div>
275279

280+
{/* HTML display of relations and attributes for current morph */}
281+
{!isPublic && (filteredRelations.length > 0 || filteredAttributes.length > 0) && (
282+
<div className="node-morph-data">
283+
<h4>Current Morph Data</h4>
284+
285+
{filteredAttributes.length > 0 && (
286+
<div className="morph-attributes">
287+
<h5>Attributes:</h5>
288+
<ul>
289+
{filteredAttributes.map(attr => (
290+
<li key={attr.id}>
291+
<strong>{attr.name}:</strong> {attr.value}
292+
{attr.unit && <span> {attr.unit}</span>}
293+
</li>
294+
))}
295+
</ul>
296+
</div>
297+
)}
298+
299+
{filteredRelations.length > 0 && (
300+
<div className="morph-relations">
301+
<h5>Relations:</h5>
302+
<ul>
303+
{filteredRelations.map(rel => {
304+
const otherNodeId = rel.source_id === node.id ? rel.target_id : rel.source_id;
305+
const otherNode = allNodes.find(n => n.id === otherNodeId);
306+
return (
307+
<li key={rel.id}>
308+
<strong>{rel.name}</strong>{otherNode?.name || otherNodeId}
309+
</li>
310+
);
311+
})}
312+
</ul>
313+
</div>
314+
)}
315+
</div>
316+
)}
317+
276318
{node.description && (
277319
<div className="node-description">
278320
<ReactMarkdown remarkPlugins={[remarkGfm]}>{node.description}</ReactMarkdown>

0 commit comments

Comments
 (0)