MCPcopy
hub / github.com/StructuredLabs/preswald / DynamicComponents

Function DynamicComponents

frontend/src/components/DynamicComponents.jsx:388–453  ·  view source on GitHub ↗
({ components, onComponentUpdate })

Source from the content-addressed store, hash-verified

386);
387
388const DynamicComponents = ({ components, onComponentUpdate }) => {
389 useEffect(() => {
390 extractKeyProps.reset();
391 }, []);
392
393 console.log('[DynamicComponents] Rendering with components:', components);
394
395 if (!components?.rows) {
396 console.warn('[DynamicComponents] No components or invalid structure received');
397 return null;
398 }
399
400 const handleUpdate = (componentId, value) => {
401 console.log(`[DynamicComponents] Component update triggered:`, {
402 componentId,
403 value,
404 timestamp: new Date().toISOString(),
405 });
406 onComponentUpdate(componentId, value);
407 };
408
409 const renderRow = (row, rowIndex) => {
410 if (!Array.isArray(row)) {
411 console.warn(`[DynamicComponents] Invalid row at index ${rowIndex}`);
412 return null;
413 }
414
415 return (
416 <div key={`row-${rowIndex}`} className="dynamiccomponent-row">
417 {row.map((component, index) => {
418 if (!component) return null;
419
420 const componentKey = component.id || `component-${index}`;
421 const isSeparator = component.type === 'separator';
422
423 return (
424 <React.Fragment key={componentKey}>
425 <div
426 className={cn(isSeparator ? 'w-full' : 'dynamiccomponent-component')}
427 style={!isSeparator ? { flex: component.flex || 1 } : undefined}
428 >
429 <ErrorBoundary>
430 <MemoizedComponent
431 component={component}
432 index={index}
433 handleUpdate={handleUpdate}
434 extractKeyProps={extractKeyProps}
435 />
436 </ErrorBoundary>
437 </div>
438 {index < row.length - 1 && !isSeparator && (
439 <div className="dynamiccomponent-separator" />
440 )}
441 </React.Fragment>
442 );
443 })}
444 </div>
445 );

Callers

nothing calls this directly

Calls 2

renderRowFunction · 0.85
resetMethod · 0.80

Tested by

no test coverage detected