fix(canvas): Multiple fixes for drag-drop, undo/redo, and code generation
Drag-drop fixes: - Fix Objective default data: use nested 'source' object with extractor_id/output_name - Fix Constraint default data: use 'type' field (not constraint_type), 'threshold' (not limit) Undo/Redo fixes: - Remove dependency on isDirty flag (which is always false due to auto-save) - Record snapshots based on actual spec changes via deep comparison Code generation improvements: - Update system prompt to support multiple extractor types: * OP2-based extractors for FEA results (stress, displacement, frequency) * Expression-based extractors for NX model values (dimensions, volumes) * Computed extractors for derived values (no FEA needed) - Claude will now choose appropriate signature based on user's description
This commit is contained in:
@@ -104,18 +104,24 @@ function getDefaultNodeData(type: AddableNodeType, position: { x: number; y: num
|
||||
name: `objective_${timestamp}`,
|
||||
direction: 'minimize',
|
||||
weight: 1.0,
|
||||
source_extractor_id: null,
|
||||
source_output: null,
|
||||
// Source is required - use placeholder that user must configure
|
||||
source: {
|
||||
extractor_id: 'ext_001', // Placeholder - user needs to configure
|
||||
output_name: 'value',
|
||||
},
|
||||
canvas_position: position,
|
||||
};
|
||||
case 'constraint':
|
||||
return {
|
||||
name: `constraint_${timestamp}`,
|
||||
constraint_type: 'hard', // Must be 'hard' or 'soft'
|
||||
type: 'hard', // Must be 'hard' or 'soft' (field is 'type' not 'constraint_type')
|
||||
operator: '<=',
|
||||
limit: 1.0,
|
||||
source_extractor_id: null,
|
||||
source_output: null,
|
||||
threshold: 1.0, // Field is 'threshold' not 'limit'
|
||||
// Source is required
|
||||
source: {
|
||||
extractor_id: 'ext_001', // Placeholder - user needs to configure
|
||||
output_name: 'value',
|
||||
},
|
||||
enabled: true,
|
||||
canvas_position: position,
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useUndoRedo, UndoRedoResult } from './useUndoRedo';
|
||||
import { useSpecStore, useSpec, useSpecIsDirty } from './useSpecStore';
|
||||
import { useSpecStore, useSpec } from './useSpecStore';
|
||||
import { AtomizerSpec } from '../types/atomizer-spec';
|
||||
|
||||
const STORAGE_KEY_PREFIX = 'atomizer-spec-history-';
|
||||
@@ -28,7 +28,6 @@ export interface SpecUndoRedoResult extends UndoRedoResult<AtomizerSpec | null>
|
||||
|
||||
export function useSpecUndoRedo(): SpecUndoRedoResult {
|
||||
const spec = useSpec();
|
||||
const isDirty = useSpecIsDirty();
|
||||
const studyId = useSpecStore((state) => state.studyId);
|
||||
const lastSpecRef = useRef<AtomizerSpec | null>(null);
|
||||
|
||||
@@ -56,13 +55,21 @@ export function useSpecUndoRedo(): SpecUndoRedoResult {
|
||||
},
|
||||
});
|
||||
|
||||
// Record snapshot when spec changes (and is dirty)
|
||||
// Record snapshot when spec changes
|
||||
// Note: We removed the isDirty check because with auto-save, isDirty is always false
|
||||
// after the API call completes. Instead, we compare the spec directly.
|
||||
useEffect(() => {
|
||||
if (spec && isDirty && spec !== lastSpecRef.current) {
|
||||
lastSpecRef.current = spec;
|
||||
undoRedo.recordSnapshot();
|
||||
if (spec && spec !== lastSpecRef.current) {
|
||||
// Deep compare to avoid recording duplicate snapshots
|
||||
const specStr = JSON.stringify(spec);
|
||||
const lastStr = lastSpecRef.current ? JSON.stringify(lastSpecRef.current) : '';
|
||||
|
||||
if (specStr !== lastStr) {
|
||||
lastSpecRef.current = spec;
|
||||
undoRedo.recordSnapshot();
|
||||
}
|
||||
}
|
||||
}, [spec, isDirty, undoRedo]);
|
||||
}, [spec, undoRedo]);
|
||||
|
||||
// Clear history when study changes
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user